src/server/safs/common.c

changeset 415
d938228c382e
parent 254
4784c14aa639
child 490
d218607f5a7e
--- a/src/server/safs/common.c	Wed Nov 02 19:19:01 2022 +0100
+++ b/src/server/safs/common.c	Sun Nov 06 15:53:32 2022 +0100
@@ -33,9 +33,10 @@
 
 #include "../util/pblock.h"
 #include "../util/util.h"
-#include <ucx/map.h>
+#include <cx/map.h>
+#include <cx/hash_map.h>
 
-static UcxMap *var_names;
+static CxMap *var_names;
 
 enum SAFVarNames {
     COMMONSAF_INSERT_CLIENT = 1,
@@ -74,35 +75,35 @@
 #define COMMONSAF_RET_ERROR -2
 
 void common_saf_init() {
-    var_names = ucx_map_new(32);
+    var_names = cxHashMapCreate(cxDefaultAllocator, 32);
     
-    ucx_map_cstr_put(var_names, "insert-client", (intptr_t)COMMONSAF_INSERT_CLIENT);
-    ucx_map_cstr_put(var_names, "insert-vars", (intptr_t)COMMONSAF_INSERT_VARS);
-    ucx_map_cstr_put(var_names, "insert-reqpb", (intptr_t)COMMONSAF_INSERT_REQPB);
-    ucx_map_cstr_put(var_names, "insert-headers", (intptr_t)COMMONSAF_INSERT_HEADERS);
-    ucx_map_cstr_put(var_names, "insert-srvhdrs", (intptr_t)COMMONSAF_INSERT_SRVHDRS);
+    cxMapPut(var_names, cx_hash_key_str("insert-client"), (void*)(intptr_t)COMMONSAF_INSERT_CLIENT);
+    cxMapPut(var_names, cx_hash_key_str("insert-vars"), (void*)(intptr_t)COMMONSAF_INSERT_VARS);
+    cxMapPut(var_names, cx_hash_key_str("insert-reqpb"), (void*)(intptr_t)COMMONSAF_INSERT_REQPB);
+    cxMapPut(var_names, cx_hash_key_str("insert-headers"), (void*)(intptr_t)COMMONSAF_INSERT_HEADERS);
+    cxMapPut(var_names, cx_hash_key_str("insert-srvhdrs"), (void*)(intptr_t)COMMONSAF_INSERT_SRVHDRS);
     
-    ucx_map_cstr_put(var_names, "set-client", (intptr_t)COMMONSAF_SET_CLIENT);
-    ucx_map_cstr_put(var_names, "set-vars", (intptr_t)COMMONSAF_SET_VARS);
-    ucx_map_cstr_put(var_names, "set-reqpb", (intptr_t)COMMONSAF_SET_REQPB);
-    ucx_map_cstr_put(var_names, "set-headers", (intptr_t)COMMONSAF_SET_HEADERS);
-    ucx_map_cstr_put(var_names, "set-srvhdrs", (intptr_t)COMMONSAF_SET_SRVHDRS);
+    cxMapPut(var_names, cx_hash_key_str("set-client"), (void*)(intptr_t)COMMONSAF_SET_CLIENT);
+    cxMapPut(var_names, cx_hash_key_str("set-vars"), (void*)(intptr_t)COMMONSAF_SET_VARS);
+    cxMapPut(var_names, cx_hash_key_str("set-reqpb"), (void*)(intptr_t)COMMONSAF_SET_REQPB);
+    cxMapPut(var_names, cx_hash_key_str("set-headers"), (void*)(intptr_t)COMMONSAF_SET_HEADERS);
+    cxMapPut(var_names, cx_hash_key_str("set-srvhdrs"), (void*)(intptr_t)COMMONSAF_SET_SRVHDRS);
     
-    ucx_map_cstr_put(var_names, "remove-client", (intptr_t)COMMONSAF_REMOVE_CLIENT);
-    ucx_map_cstr_put(var_names, "remove-vars", (intptr_t)COMMONSAF_REMOVE_VARS);
-    ucx_map_cstr_put(var_names, "remove-reqpb", (intptr_t)COMMONSAF_REMOVE_REQPB);
-    ucx_map_cstr_put(var_names, "remove-headers", (intptr_t)COMMONSAF_REMOVE_HEADERS);
-    ucx_map_cstr_put(var_names, "remove-srvhdrs", (intptr_t)COMMONSAF_REMOVE_SRVHDRS);
+    cxMapPut(var_names, cx_hash_key_str("remove-client"), (void*)(intptr_t)COMMONSAF_REMOVE_CLIENT);
+    cxMapPut(var_names, cx_hash_key_str("remove-vars"), (void*)(intptr_t)COMMONSAF_REMOVE_VARS);
+    cxMapPut(var_names, cx_hash_key_str("remove-reqpb"), (void*)(intptr_t)COMMONSAF_REMOVE_REQPB);
+    cxMapPut(var_names, cx_hash_key_str("remove-headers"), (void*)(intptr_t)COMMONSAF_REMOVE_HEADERS);
+    cxMapPut(var_names, cx_hash_key_str("remove-srvhdrs"), (void*)(intptr_t)COMMONSAF_REMOVE_SRVHDRS);
     
-    ucx_map_cstr_put(var_names, "abort", (intptr_t)COMMONSAF_ABORT);
-    ucx_map_cstr_put(var_names, "noaction", (intptr_t)COMMONSAF_NOACTION);
-    ucx_map_cstr_put(var_names, "error", (intptr_t)COMMONSAF_ERROR);
-    ucx_map_cstr_put(var_names, "escape", (intptr_t)COMMONSAF_ESCAPE);
-    ucx_map_cstr_put(var_names, "find-pathinfo-forward", (intptr_t)COMMONSAF_FIND_PATHINFO_FORWARD);
-    ucx_map_cstr_put(var_names, "http-downgrade", (intptr_t)COMMONSAF_HTTP_DOWNGRADE);
-    ucx_map_cstr_put(var_names, "http-upgrade", (intptr_t)COMMONSAF_HTTP_UPGRADE);
-    ucx_map_cstr_put(var_names, "keep-alive", (intptr_t)COMMONSAF_KEEP_ALIVE);
-    ucx_map_cstr_put(var_names, "name", (intptr_t)COMMONSAF_NAME);
+    cxMapPut(var_names, cx_hash_key_str("abort"), (void*)(intptr_t)COMMONSAF_ABORT);
+    cxMapPut(var_names, cx_hash_key_str("noaction"), (void*)(intptr_t)COMMONSAF_NOACTION);
+    cxMapPut(var_names, cx_hash_key_str("error"), (void*)(intptr_t)COMMONSAF_ERROR);
+    cxMapPut(var_names, cx_hash_key_str("escape"), (void*)(intptr_t)COMMONSAF_ESCAPE);
+    cxMapPut(var_names, cx_hash_key_str("find-pathinfo-forward"), (void*)(intptr_t)COMMONSAF_FIND_PATHINFO_FORWARD);
+    cxMapPut(var_names, cx_hash_key_str("http-downgrade"), (void*)(intptr_t)COMMONSAF_HTTP_DOWNGRADE);
+    cxMapPut(var_names, cx_hash_key_str("http-upgrade"), (void*)(intptr_t)COMMONSAF_HTTP_UPGRADE);
+    cxMapPut(var_names, cx_hash_key_str("keep-alive"), (void*)(intptr_t)COMMONSAF_KEEP_ALIVE);
+    cxMapPut(var_names, cx_hash_key_str("name"), (void*)(intptr_t)COMMONSAF_NAME);
 }
 
 int print_message(pblock *pb, Session *sn, Request *rq) {
@@ -115,8 +116,8 @@
 }
 
 static void var_set(char *value, pblock *pb, WSBool insert) {
-    sstr_t n;
-    sstr_t v;
+    cxstring n;
+    cxstring v;
     v.ptr = NULL;
     
     n.ptr = value;
@@ -125,7 +126,7 @@
     for(i=1;i<len;i++) {
         if(value[i] == '=') {
             n.length = i;
-            v = sstrsubs(sstrn(value, len), i + 1);
+            v = cx_strsubs(cx_strn(value, len), i + 1);
             break;
         }
     }
@@ -143,8 +144,8 @@
     pblock_nvlinsert(n.ptr, n.length, v.ptr, v.length, pb);
 }
 
-static int set_var(Session *sn, Request *rq, char *var, char *value) {
-    intptr_t v = (intptr_t)ucx_map_cstr_get(var_names, var);
+static int set_var(Session *sn, Request *rq, const char *var, char *value) {
+    intptr_t v = (intptr_t)cxMapGet(var_names, cx_hash_key_str(var));
     switch(v) {
         default: break;
         case COMMONSAF_INSERT_CLIENT: var_set(value, sn->client, TRUE); break;
@@ -184,7 +185,7 @@
                 return COMMONSAF_RET_ERROR;
             }
             
-            char *msg = isnum ? NULL : sstrtrim(sstr(value + i)).ptr;
+            const char *msg = isnum ? NULL : cx_strtrim(cx_str(value + i)).ptr;
             protocol_status(sn, rq, (int)status, msg);
             
             return COMMONSAF_REQ_ABORTED;

mercurial