src/server/daemon/httplistener.c

changeset 415
d938228c382e
parent 398
83234bc3bee9
child 438
22eca559aded
--- a/src/server/daemon/httplistener.c	Wed Nov 02 19:19:01 2022 +0100
+++ b/src/server/daemon/httplistener.c	Sun Nov 06 15:53:32 2022 +0100
@@ -54,7 +54,8 @@
 #include <sys/socket.h>
 #include <unistd.h>
 
-#include <ucx/map.h>
+
+#include <cx/hash_map.h>
 
 #include "../util/atomic.h"
 #include "httplistener.h"
@@ -64,15 +65,16 @@
 #include "configmanager.h"
 #include "log.h"
 
-UcxMap *listener_map = NULL;
+#define LISTENER_MAX_PROTOCOL_TOKENS 1024
+
+CxMap *listener_map = NULL;
 
 int start_all_listener() {
     ServerConfiguration *conf = cfgmgr_get_server_config();
-    UcxList *ls = conf->listeners;
-    while(ls) {
-        HttpListener *listener = ls->data;
+    CxList *ls = conf->listeners;
+    CxIterator iter = cxListIterator(ls, 0);
+    cx_foreach(HttpListener *, listener, iter) {
         http_listener_start(listener);
-        ls = ls->next;
     }
 
     return 0;
@@ -80,10 +82,10 @@
 
 HttpListener* http_listener_create(ListenerConfig *conf) {
     if(listener_map == NULL) {
-        listener_map = ucx_map_new(16);
+        listener_map = cxHashMapCreate(cxDefaultAllocator, 16);
     }
 
-    HttpListener *fl = ucx_map_sstr_get(listener_map, conf->name);
+    HttpListener *fl = cxMapGet(listener_map, cx_hash_key(conf->name.ptr, conf->name.length));
     if(fl == NULL) {
         return http_listener_new(conf);
     }
@@ -108,7 +110,7 @@
     
     // the listener threadpool might be changed
     if(conf->threadpool.ptr != NULL) {
-        newls->threadpool = get_threadpool(conf->threadpool);
+        newls->threadpool = get_threadpool(cx_strcast(conf->threadpool));
     }
     if(newls->threadpool == NULL) {
         newls->threadpool = get_default_threadpool();
@@ -130,7 +132,7 @@
     fl->next = newls;
     
     
-    ucx_map_sstr_put(listener_map, newls->name, newls);
+    cxMapPut(listener_map, cx_hash_key(newls->name.ptr, newls->name.length), newls);
     
     for (int i=0;i<newls->nacceptors;i++) {
         //acceptor_start(newls->acceptors[i]);
@@ -149,10 +151,10 @@
 HttpListener* http_listener_new(ListenerConfig *conf) {
     // TODO: remove
     if(listener_map == NULL) {
-        listener_map = ucx_map_new(16);
+        listener_map = cxHashMapCreate(cxDefaultAllocator, 16);
     }
 
-    HttpListener *fl = ucx_map_sstr_get(listener_map, conf->name);
+    HttpListener *fl = cxMapGet(listener_map, cx_hash_key(conf->name.ptr, conf->name.length));
     if(fl != NULL) {
         return fl;
     }
@@ -165,7 +167,7 @@
     listener->default_vs.vs_name = conf->vs.ptr;
     listener->threadpool = NULL;
     if(conf->threadpool.ptr != NULL) {
-        listener->threadpool = get_threadpool(conf->threadpool);
+        listener->threadpool = get_threadpool(cx_strcast(conf->threadpool));
     }
     if(listener->threadpool == NULL) {
         listener->threadpool = get_default_threadpool();
@@ -191,23 +193,23 @@
                 ctx,
                 SSL_OP_SINGLE_DH_USE | SSL_OP_NO_SSLv3);
         if(conf->disable_proto.ptr) {
-            ssize_t n = 0;
-            sstr_t *plist = sstrsplit(conf->disable_proto, S(","), &n);
+            cxstring *plist = NULL;
+            ssize_t n = cx_strsplit_a(cxDefaultAllocator, conf->disable_proto, cx_str(","), LISTENER_MAX_PROTOCOL_TOKENS, &plist);
             if(plist) {
                 for(int i=0;i<n;i++) {
-                    sstr_t proto = plist[i];
+                    cxstring proto = plist[i];
                     log_ereport(
                             LOG_VERBOSE,
                             "Listener %s: Disable protocol %s",
                             listener->name.ptr,
                             proto.ptr);
-                    if(!sstrcasecmp(sstrtrim(proto), S("SSLv2"))) {
+                    if(!cx_strcasecmp(cx_strtrim(proto), cx_str("SSLv2"))) {
                         SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
-                    } else if(!sstrcasecmp(sstrtrim(proto), S("SSLv3"))) {
+                    } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("SSLv3"))) {
                         SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv3);
-                    } else if(!sstrcasecmp(sstrtrim(proto), S("TLSv1"))) {
+                    } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1"))) {
                         SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1);
-                    } else if(!sstrcasecmp(sstrtrim(proto), S("TLSv1.1"))) {
+                    } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.1"))) {
 #ifdef SSL_OP_NO_TLSv1_1
                         SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_1);
 #else
@@ -216,7 +218,7 @@
                                 "Listener: %s: TLSv1.1 already not supported",
                                 listener->name.ptr);
 #endif
-                    } else if(sstrcasecmp(sstrtrim(proto), S("TLSv1.2"))) {
+                    } else if(cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.2"))) {
 #ifdef SSL_OP_NO_TLSv1_2
                         SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_2);
 #else
@@ -225,7 +227,7 @@
                                 "Listener: %s: TLSv1.2 already not supported",
                                 listener->name.ptr);
 #endif
-                    } else if(sstrcasecmp(sstrtrim(proto), S("TLSv1.3"))) {
+                    } else if(cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.3"))) {
 #ifdef SSL_OP_NO_TLSv1_3
                         SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_3);
 #else
@@ -242,7 +244,6 @@
                                 listener->name.ptr,
                                 proto.ptr);
                     }
-                    free(proto.ptr);
                 }
                 free(plist);
             }
@@ -284,7 +285,7 @@
     }
     
     
-    ucx_map_sstr_put(listener_map, listener->name, listener);
+    cxMapPut(listener_map, cx_hash_key(listener->name.ptr, listener->name.length), listener);
 
     struct sockaddr_in servaddr;   /* server address */
     struct sockaddr_in6 servaddr6;

mercurial