72 #define COMMONSAF_RET_STOP 2 |
73 #define COMMONSAF_RET_STOP 2 |
73 #define COMMONSAF_REQ_ABORTED -1 |
74 #define COMMONSAF_REQ_ABORTED -1 |
74 #define COMMONSAF_RET_ERROR -2 |
75 #define COMMONSAF_RET_ERROR -2 |
75 |
76 |
76 void common_saf_init() { |
77 void common_saf_init() { |
77 var_names = ucx_map_new(32); |
78 var_names = cxHashMapCreate(cxDefaultAllocator, 32); |
78 |
79 |
79 ucx_map_cstr_put(var_names, "insert-client", (intptr_t)COMMONSAF_INSERT_CLIENT); |
80 cxMapPut(var_names, cx_hash_key_str("insert-client"), (void*)(intptr_t)COMMONSAF_INSERT_CLIENT); |
80 ucx_map_cstr_put(var_names, "insert-vars", (intptr_t)COMMONSAF_INSERT_VARS); |
81 cxMapPut(var_names, cx_hash_key_str("insert-vars"), (void*)(intptr_t)COMMONSAF_INSERT_VARS); |
81 ucx_map_cstr_put(var_names, "insert-reqpb", (intptr_t)COMMONSAF_INSERT_REQPB); |
82 cxMapPut(var_names, cx_hash_key_str("insert-reqpb"), (void*)(intptr_t)COMMONSAF_INSERT_REQPB); |
82 ucx_map_cstr_put(var_names, "insert-headers", (intptr_t)COMMONSAF_INSERT_HEADERS); |
83 cxMapPut(var_names, cx_hash_key_str("insert-headers"), (void*)(intptr_t)COMMONSAF_INSERT_HEADERS); |
83 ucx_map_cstr_put(var_names, "insert-srvhdrs", (intptr_t)COMMONSAF_INSERT_SRVHDRS); |
84 cxMapPut(var_names, cx_hash_key_str("insert-srvhdrs"), (void*)(intptr_t)COMMONSAF_INSERT_SRVHDRS); |
84 |
85 |
85 ucx_map_cstr_put(var_names, "set-client", (intptr_t)COMMONSAF_SET_CLIENT); |
86 cxMapPut(var_names, cx_hash_key_str("set-client"), (void*)(intptr_t)COMMONSAF_SET_CLIENT); |
86 ucx_map_cstr_put(var_names, "set-vars", (intptr_t)COMMONSAF_SET_VARS); |
87 cxMapPut(var_names, cx_hash_key_str("set-vars"), (void*)(intptr_t)COMMONSAF_SET_VARS); |
87 ucx_map_cstr_put(var_names, "set-reqpb", (intptr_t)COMMONSAF_SET_REQPB); |
88 cxMapPut(var_names, cx_hash_key_str("set-reqpb"), (void*)(intptr_t)COMMONSAF_SET_REQPB); |
88 ucx_map_cstr_put(var_names, "set-headers", (intptr_t)COMMONSAF_SET_HEADERS); |
89 cxMapPut(var_names, cx_hash_key_str("set-headers"), (void*)(intptr_t)COMMONSAF_SET_HEADERS); |
89 ucx_map_cstr_put(var_names, "set-srvhdrs", (intptr_t)COMMONSAF_SET_SRVHDRS); |
90 cxMapPut(var_names, cx_hash_key_str("set-srvhdrs"), (void*)(intptr_t)COMMONSAF_SET_SRVHDRS); |
90 |
91 |
91 ucx_map_cstr_put(var_names, "remove-client", (intptr_t)COMMONSAF_REMOVE_CLIENT); |
92 cxMapPut(var_names, cx_hash_key_str("remove-client"), (void*)(intptr_t)COMMONSAF_REMOVE_CLIENT); |
92 ucx_map_cstr_put(var_names, "remove-vars", (intptr_t)COMMONSAF_REMOVE_VARS); |
93 cxMapPut(var_names, cx_hash_key_str("remove-vars"), (void*)(intptr_t)COMMONSAF_REMOVE_VARS); |
93 ucx_map_cstr_put(var_names, "remove-reqpb", (intptr_t)COMMONSAF_REMOVE_REQPB); |
94 cxMapPut(var_names, cx_hash_key_str("remove-reqpb"), (void*)(intptr_t)COMMONSAF_REMOVE_REQPB); |
94 ucx_map_cstr_put(var_names, "remove-headers", (intptr_t)COMMONSAF_REMOVE_HEADERS); |
95 cxMapPut(var_names, cx_hash_key_str("remove-headers"), (void*)(intptr_t)COMMONSAF_REMOVE_HEADERS); |
95 ucx_map_cstr_put(var_names, "remove-srvhdrs", (intptr_t)COMMONSAF_REMOVE_SRVHDRS); |
96 cxMapPut(var_names, cx_hash_key_str("remove-srvhdrs"), (void*)(intptr_t)COMMONSAF_REMOVE_SRVHDRS); |
96 |
97 |
97 ucx_map_cstr_put(var_names, "abort", (intptr_t)COMMONSAF_ABORT); |
98 cxMapPut(var_names, cx_hash_key_str("abort"), (void*)(intptr_t)COMMONSAF_ABORT); |
98 ucx_map_cstr_put(var_names, "noaction", (intptr_t)COMMONSAF_NOACTION); |
99 cxMapPut(var_names, cx_hash_key_str("noaction"), (void*)(intptr_t)COMMONSAF_NOACTION); |
99 ucx_map_cstr_put(var_names, "error", (intptr_t)COMMONSAF_ERROR); |
100 cxMapPut(var_names, cx_hash_key_str("error"), (void*)(intptr_t)COMMONSAF_ERROR); |
100 ucx_map_cstr_put(var_names, "escape", (intptr_t)COMMONSAF_ESCAPE); |
101 cxMapPut(var_names, cx_hash_key_str("escape"), (void*)(intptr_t)COMMONSAF_ESCAPE); |
101 ucx_map_cstr_put(var_names, "find-pathinfo-forward", (intptr_t)COMMONSAF_FIND_PATHINFO_FORWARD); |
102 cxMapPut(var_names, cx_hash_key_str("find-pathinfo-forward"), (void*)(intptr_t)COMMONSAF_FIND_PATHINFO_FORWARD); |
102 ucx_map_cstr_put(var_names, "http-downgrade", (intptr_t)COMMONSAF_HTTP_DOWNGRADE); |
103 cxMapPut(var_names, cx_hash_key_str("http-downgrade"), (void*)(intptr_t)COMMONSAF_HTTP_DOWNGRADE); |
103 ucx_map_cstr_put(var_names, "http-upgrade", (intptr_t)COMMONSAF_HTTP_UPGRADE); |
104 cxMapPut(var_names, cx_hash_key_str("http-upgrade"), (void*)(intptr_t)COMMONSAF_HTTP_UPGRADE); |
104 ucx_map_cstr_put(var_names, "keep-alive", (intptr_t)COMMONSAF_KEEP_ALIVE); |
105 cxMapPut(var_names, cx_hash_key_str("keep-alive"), (void*)(intptr_t)COMMONSAF_KEEP_ALIVE); |
105 ucx_map_cstr_put(var_names, "name", (intptr_t)COMMONSAF_NAME); |
106 cxMapPut(var_names, cx_hash_key_str("name"), (void*)(intptr_t)COMMONSAF_NAME); |
106 } |
107 } |
107 |
108 |
108 int print_message(pblock *pb, Session *sn, Request *rq) { |
109 int print_message(pblock *pb, Session *sn, Request *rq) { |
109 char *msg = pblock_findval("msg", pb); |
110 char *msg = pblock_findval("msg", pb); |
110 if(msg) { |
111 if(msg) { |
141 // TODO |
142 // TODO |
142 } |
143 } |
143 pblock_nvlinsert(n.ptr, n.length, v.ptr, v.length, pb); |
144 pblock_nvlinsert(n.ptr, n.length, v.ptr, v.length, pb); |
144 } |
145 } |
145 |
146 |
146 static int set_var(Session *sn, Request *rq, char *var, char *value) { |
147 static int set_var(Session *sn, Request *rq, const char *var, char *value) { |
147 intptr_t v = (intptr_t)ucx_map_cstr_get(var_names, var); |
148 intptr_t v = (intptr_t)cxMapGet(var_names, cx_hash_key_str(var)); |
148 switch(v) { |
149 switch(v) { |
149 default: break; |
150 default: break; |
150 case COMMONSAF_INSERT_CLIENT: var_set(value, sn->client, TRUE); break; |
151 case COMMONSAF_INSERT_CLIENT: var_set(value, sn->client, TRUE); break; |
151 case COMMONSAF_INSERT_VARS: var_set(value, rq->vars, TRUE); break; |
152 case COMMONSAF_INSERT_VARS: var_set(value, rq->vars, TRUE); break; |
152 case COMMONSAF_INSERT_REQPB: var_set(value, rq->reqpb, TRUE); break; |
153 case COMMONSAF_INSERT_REQPB: var_set(value, rq->reqpb, TRUE); break; |