| 79 } |
79 } |
| 80 |
80 |
| 81 void common_saf_init() { |
81 void common_saf_init() { |
| 82 var_names = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); |
82 var_names = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); |
| 83 |
83 |
| 84 cxMapPut(var_names, cx_hash_key_str("insert-client"), (void*)(intptr_t)COMMONSAF_INSERT_CLIENT); |
84 cxMapPut(var_names, "insert-client", (void*)(intptr_t)COMMONSAF_INSERT_CLIENT); |
| 85 cxMapPut(var_names, cx_hash_key_str("insert-vars"), (void*)(intptr_t)COMMONSAF_INSERT_VARS); |
85 cxMapPut(var_names, "insert-vars", (void*)(intptr_t)COMMONSAF_INSERT_VARS); |
| 86 cxMapPut(var_names, cx_hash_key_str("insert-reqpb"), (void*)(intptr_t)COMMONSAF_INSERT_REQPB); |
86 cxMapPut(var_names, "insert-reqpb", (void*)(intptr_t)COMMONSAF_INSERT_REQPB); |
| 87 cxMapPut(var_names, cx_hash_key_str("insert-headers"), (void*)(intptr_t)COMMONSAF_INSERT_HEADERS); |
87 cxMapPut(var_names, "insert-headers", (void*)(intptr_t)COMMONSAF_INSERT_HEADERS); |
| 88 cxMapPut(var_names, cx_hash_key_str("insert-srvhdrs"), (void*)(intptr_t)COMMONSAF_INSERT_SRVHDRS); |
88 cxMapPut(var_names, "insert-srvhdrs", (void*)(intptr_t)COMMONSAF_INSERT_SRVHDRS); |
| 89 |
89 |
| 90 cxMapPut(var_names, cx_hash_key_str("set-client"), (void*)(intptr_t)COMMONSAF_SET_CLIENT); |
90 cxMapPut(var_names, "set-client", (void*)(intptr_t)COMMONSAF_SET_CLIENT); |
| 91 cxMapPut(var_names, cx_hash_key_str("set-vars"), (void*)(intptr_t)COMMONSAF_SET_VARS); |
91 cxMapPut(var_names, "set-vars", (void*)(intptr_t)COMMONSAF_SET_VARS); |
| 92 cxMapPut(var_names, cx_hash_key_str("set-reqpb"), (void*)(intptr_t)COMMONSAF_SET_REQPB); |
92 cxMapPut(var_names, "set-reqpb", (void*)(intptr_t)COMMONSAF_SET_REQPB); |
| 93 cxMapPut(var_names, cx_hash_key_str("set-headers"), (void*)(intptr_t)COMMONSAF_SET_HEADERS); |
93 cxMapPut(var_names, "set-headers", (void*)(intptr_t)COMMONSAF_SET_HEADERS); |
| 94 cxMapPut(var_names, cx_hash_key_str("set-srvhdrs"), (void*)(intptr_t)COMMONSAF_SET_SRVHDRS); |
94 cxMapPut(var_names, "set-srvhdrs", (void*)(intptr_t)COMMONSAF_SET_SRVHDRS); |
| 95 |
95 |
| 96 cxMapPut(var_names, cx_hash_key_str("remove-client"), (void*)(intptr_t)COMMONSAF_REMOVE_CLIENT); |
96 cxMapPut(var_names, "remove-client", (void*)(intptr_t)COMMONSAF_REMOVE_CLIENT); |
| 97 cxMapPut(var_names, cx_hash_key_str("remove-vars"), (void*)(intptr_t)COMMONSAF_REMOVE_VARS); |
97 cxMapPut(var_names, "remove-vars", (void*)(intptr_t)COMMONSAF_REMOVE_VARS); |
| 98 cxMapPut(var_names, cx_hash_key_str("remove-reqpb"), (void*)(intptr_t)COMMONSAF_REMOVE_REQPB); |
98 cxMapPut(var_names, "remove-reqpb", (void*)(intptr_t)COMMONSAF_REMOVE_REQPB); |
| 99 cxMapPut(var_names, cx_hash_key_str("remove-headers"), (void*)(intptr_t)COMMONSAF_REMOVE_HEADERS); |
99 cxMapPut(var_names, "remove-headers", (void*)(intptr_t)COMMONSAF_REMOVE_HEADERS); |
| 100 cxMapPut(var_names, cx_hash_key_str("remove-srvhdrs"), (void*)(intptr_t)COMMONSAF_REMOVE_SRVHDRS); |
100 cxMapPut(var_names, "remove-srvhdrs", (void*)(intptr_t)COMMONSAF_REMOVE_SRVHDRS); |
| 101 |
101 |
| 102 cxMapPut(var_names, cx_hash_key_str("abort"), (void*)(intptr_t)COMMONSAF_ABORT); |
102 cxMapPut(var_names, "abort", (void*)(intptr_t)COMMONSAF_ABORT); |
| 103 cxMapPut(var_names, cx_hash_key_str("noaction"), (void*)(intptr_t)COMMONSAF_NOACTION); |
103 cxMapPut(var_names, "noaction", (void*)(intptr_t)COMMONSAF_NOACTION); |
| 104 cxMapPut(var_names, cx_hash_key_str("error"), (void*)(intptr_t)COMMONSAF_ERROR); |
104 cxMapPut(var_names, "error", (void*)(intptr_t)COMMONSAF_ERROR); |
| 105 cxMapPut(var_names, cx_hash_key_str("escape"), (void*)(intptr_t)COMMONSAF_ESCAPE); |
105 cxMapPut(var_names, "escape", (void*)(intptr_t)COMMONSAF_ESCAPE); |
| 106 cxMapPut(var_names, cx_hash_key_str("find-pathinfo-forward"), (void*)(intptr_t)COMMONSAF_FIND_PATHINFO_FORWARD); |
106 cxMapPut(var_names, "find-pathinfo-forward", (void*)(intptr_t)COMMONSAF_FIND_PATHINFO_FORWARD); |
| 107 cxMapPut(var_names, cx_hash_key_str("http-downgrade"), (void*)(intptr_t)COMMONSAF_HTTP_DOWNGRADE); |
107 cxMapPut(var_names, "http-downgrade", (void*)(intptr_t)COMMONSAF_HTTP_DOWNGRADE); |
| 108 cxMapPut(var_names, cx_hash_key_str("http-upgrade"), (void*)(intptr_t)COMMONSAF_HTTP_UPGRADE); |
108 cxMapPut(var_names, "http-upgrade", (void*)(intptr_t)COMMONSAF_HTTP_UPGRADE); |
| 109 cxMapPut(var_names, cx_hash_key_str("keep-alive"), (void*)(intptr_t)COMMONSAF_KEEP_ALIVE); |
109 cxMapPut(var_names, "keep-alive", (void*)(intptr_t)COMMONSAF_KEEP_ALIVE); |
| 110 cxMapPut(var_names, cx_hash_key_str("name"), (void*)(intptr_t)COMMONSAF_NAME); |
110 cxMapPut(var_names, "name", (void*)(intptr_t)COMMONSAF_NAME); |
| 111 |
111 |
| 112 webserver_atrestart(common_saf_cleanup, NULL); |
112 webserver_atrestart(common_saf_cleanup, NULL); |
| 113 } |
113 } |
| 114 |
114 |
| 115 int print_message(pblock *pb, Session *sn, Request *rq) { |
115 int print_message(pblock *pb, Session *sn, Request *rq) { |
| 149 } |
149 } |
| 150 pblock_nvlinsert(n.ptr, n.length, v.ptr, v.length, pb); |
150 pblock_nvlinsert(n.ptr, n.length, v.ptr, v.length, pb); |
| 151 } |
151 } |
| 152 |
152 |
| 153 static int set_var(Session *sn, Request *rq, const char *var, char *value) { |
153 static int set_var(Session *sn, Request *rq, const char *var, char *value) { |
| 154 intptr_t v = (intptr_t)cxMapGet(var_names, cx_hash_key_str(var)); |
154 intptr_t v = (intptr_t)cxMapGet(var_names, var); |
| 155 switch(v) { |
155 switch(v) { |
| 156 default: break; |
156 default: break; |
| 157 case COMMONSAF_INSERT_CLIENT: var_set(value, sn->client, TRUE); break; |
157 case COMMONSAF_INSERT_CLIENT: var_set(value, sn->client, TRUE); break; |
| 158 case COMMONSAF_INSERT_VARS: var_set(value, rq->vars, TRUE); break; |
158 case COMMONSAF_INSERT_VARS: var_set(value, rq->vars, TRUE); break; |
| 159 case COMMONSAF_INSERT_REQPB: var_set(value, rq->reqpb, TRUE); break; |
159 case COMMONSAF_INSERT_REQPB: var_set(value, rq->reqpb, TRUE); break; |