Tue, 24 Jan 2017 23:19:48 +0100
adds pblock operations to set-variable saf
src/server/safs/common.c | file | annotate | diff | comparison | revisions |
--- a/src/server/safs/common.c Tue Jan 24 17:36:28 2017 +0100 +++ b/src/server/safs/common.c Tue Jan 24 23:19:48 2017 +0100 @@ -38,7 +38,7 @@ static UcxMap *var_names; enum SAFVarNames { - COMMONSAF_INSERT_CLIENT = 0, + COMMONSAF_INSERT_CLIENT = 1, COMMONSAF_INSERT_VARS, COMMONSAF_INSERT_REQPB, COMMONSAF_INSERT_HEADERS, @@ -74,7 +74,7 @@ #define COMMONSAF_RET_ERROR -2 void common_saf_init() { - var_names = ucx_map_new(12); + var_names = ucx_map_new(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); @@ -114,25 +114,53 @@ return REQ_NOACTION; } +static void var_set(char *value, pblock *pb, WSBool insert) { + sstr_t n; + sstr_t v; + v.ptr = NULL; + + n.ptr = value; + int i; + int len = strlen(value); + for(i=1;i<len;i++) { + if(value[i] == '=') { + n.length = i; + v = sstrsubs(sstrn(value, len), i + 1); + break; + } + } + if(!v.ptr || v.length == 0) { + log_ereport( + LOG_MISCONFIG, + "set-variable: string '%s' has not name=value format", + value); + return; + } + + if(!insert) { + // TODO + } + 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); switch(v) { default: break; - case COMMONSAF_INSERT_CLIENT: break; - case COMMONSAF_INSERT_VARS: break; - case COMMONSAF_INSERT_REQPB: break; - case COMMONSAF_INSERT_HEADERS: break; - case COMMONSAF_INSERT_SRVHDRS: break; - case COMMONSAF_SET_CLIENT: break; - case COMMONSAF_SET_VARS: break; - case COMMONSAF_SET_REQPB: break; - case COMMONSAF_SET_HEADERS: break; - case COMMONSAF_SET_SRVHDRS: break; - case COMMONSAF_REMOVE_CLIENT: break; - case COMMONSAF_REMOVE_VARS: break; - case COMMONSAF_REMOVE_HEADERS: break; - case COMMONSAF_REMOVE_SRVHDRS: break; + case COMMONSAF_INSERT_CLIENT: var_set(value, sn->client, TRUE); break; + case COMMONSAF_INSERT_VARS: var_set(value, rq->vars, TRUE); break; + case COMMONSAF_INSERT_REQPB: var_set(value, rq->reqpb, TRUE); break; + case COMMONSAF_INSERT_HEADERS: var_set(value, rq->headers, TRUE); break; + case COMMONSAF_INSERT_SRVHDRS: var_set(value, rq->srvhdrs, TRUE); break; + case COMMONSAF_SET_CLIENT: var_set(value, sn->client, FALSE); break; + case COMMONSAF_SET_VARS: var_set(value, rq->vars, FALSE); break; + case COMMONSAF_SET_REQPB: var_set(value, rq->reqpb, FALSE); break; + case COMMONSAF_SET_HEADERS: var_set(value, rq->headers, FALSE); break; + case COMMONSAF_SET_SRVHDRS: var_set(value, rq->srvhdrs, FALSE); break; + case COMMONSAF_REMOVE_CLIENT: pblock_remove(value, sn->client); break; + case COMMONSAF_REMOVE_VARS: pblock_remove(value, rq->vars); break; + case COMMONSAF_REMOVE_HEADERS: pblock_remove(value, rq->headers);break; + case COMMONSAF_REMOVE_SRVHDRS: pblock_remove(value, rq->srvhdrs); break; case COMMONSAF_ABORT: return COMMONSAF_REQ_ABORTED; case COMMONSAF_ERROR: { return COMMONSAF_REQ_ABORTED;