# HG changeset patch # User Olaf Wintermann # Date 1485275788 -3600 # Node ID 36cd2e280386cb8b919303cc81cb61c47c663965 # Parent 6394ce09889a034431106176463061a80dff94e6# Parent 85320d8b5d5c3302ef6e562828069703941be585 merge diff -r 85320d8b5d5c -r 36cd2e280386 src/server/daemon/httprequest.c --- a/src/server/daemon/httprequest.c Sat Jan 21 17:05:23 2017 +0100 +++ b/src/server/daemon/httprequest.c Tue Jan 24 17:36:28 2017 +0100 @@ -89,7 +89,7 @@ int handle_request(HTTPRequest *request, threadpool_t *thrpool) { // handle nsapi request - + // create pool pool_handle_t *pool = pool_create(); diff -r 85320d8b5d5c -r 36cd2e280386 src/server/daemon/webserver.c --- a/src/server/daemon/webserver.c Sat Jan 21 17:05:23 2017 +0100 +++ b/src/server/daemon/webserver.c Tue Jan 24 17:36:28 2017 +0100 @@ -48,6 +48,8 @@ #include "../util/io.h" #include "../util/util.h" +#include "../safs/common.h" + #include "func.h" #include "config.h" #include "configmanager.h" @@ -103,6 +105,9 @@ fclose(pidfile); free(pid_file_path); + // init SAFs + common_saf_init(); + // set global vars conf_global_vars_s *vars = conf_getglobals(); diff -r 85320d8b5d5c -r 36cd2e280386 src/server/daemon/ws-fn.c --- a/src/server/daemon/ws-fn.c Sat Jan 21 17:05:23 2017 +0100 +++ b/src/server/daemon/ws-fn.c Tue Jan 24 17:36:28 2017 +0100 @@ -67,6 +67,7 @@ { "find-index", find_index, NULL, NULL, 0}, { "dir-redirect", dir_redirect, NULL, NULL, 0}, { "print-message", print_message, NULL, NULL, 0}, + { "set-variable", set_variable, NULL, NULL, 0}, { "common-log", common_log, NULL, NULL, 0}, { "send-cgi", send_cgi, NULL, NULL, 0}, {NULL, NULL, NULL, NULL, 0} diff -r 85320d8b5d5c -r 36cd2e280386 src/server/safs/common.c --- a/src/server/safs/common.c Sat Jan 21 17:05:23 2017 +0100 +++ b/src/server/safs/common.c Tue Jan 24 17:36:28 2017 +0100 @@ -31,12 +31,147 @@ #include "../daemon/httprequest.h" #include "../daemon/log.h" +#include "../util/pblock.h" +#include "../util/util.h" +#include "../../ucx/map.h" + +static UcxMap *var_names; + +enum SAFVarNames { + COMMONSAF_INSERT_CLIENT = 0, + COMMONSAF_INSERT_VARS, + COMMONSAF_INSERT_REQPB, + COMMONSAF_INSERT_HEADERS, + COMMONSAF_INSERT_SRVHDRS, + COMMONSAF_SET_CLIENT, + COMMONSAF_SET_VARS, + COMMONSAF_SET_REQPB, + COMMONSAF_SET_HEADERS, + COMMONSAF_SET_SRVHDRS, + COMMONSAF_REMOVE_CLIENT, + COMMONSAF_REMOVE_VARS, + COMMONSAF_REMOVE_REQPB, + COMMONSAF_REMOVE_HEADERS, + COMMONSAF_REMOVE_SRVHDRS, + COMMONSAF_ABORT, + COMMONSAF_NOACTION, + COMMONSAF_ERROR, + COMMONSAF_ESCAPE, + COMMONSAF_FIND_PATHINFO_FORWARD, + COMMONSAF_HTTP_DOWNGRADE, + COMMONSAF_HTTP_UPGRADE, + COMMONSAF_KEEP_ALIVE, + COMMONSAF_NAME, + COMMONSAF_SENTHDRS, + COMMONSAF_STOP, + COMMONSAF_URL +}; + +#define COMMONSAF_RET_DEF 0 +#define COMMONSAF_RET_NOACTION 1 +#define COMMONSAF_RET_STOP 2 +#define COMMONSAF_REQ_ABORTED -1 +#define COMMONSAF_RET_ERROR -2 + +void common_saf_init() { + var_names = ucx_map_new(12); + + 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); + + 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); + + 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); + + 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); +} + int print_message(pblock *pb, Session *sn, Request *rq) { char *msg = pblock_findval("msg", pb); if(msg) { - printf("%s\n", msg); log_ereport(LOG_INFORM, "%s", msg); } return REQ_NOACTION; } + + +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_ABORT: return COMMONSAF_REQ_ABORTED; + case COMMONSAF_ERROR: { + return COMMONSAF_REQ_ABORTED; + } + case COMMONSAF_ESCAPE: break; + case COMMONSAF_FIND_PATHINFO_FORWARD: break; + case COMMONSAF_HTTP_DOWNGRADE: break; + case COMMONSAF_HTTP_UPGRADE: break; + case COMMONSAF_KEEP_ALIVE: { + rq->rq_attr.keep_alive = util_getboolean(var, 0); + break; + } + case COMMONSAF_NAME: break; + case COMMONSAF_SENTHDRS: break; + case COMMONSAF_STOP: return COMMONSAF_RET_STOP; + case COMMONSAF_URL: break; + } + return COMMONSAF_RET_DEF; +} + +int set_variable(pblock *pb, Session *sn, Request *rq) { + int ret = REQ_NOACTION; + int set = 0; + + for(int i=0;ihsize;i++) { + pb_entry *entry = pb->ht[i]; + while(entry) { + int r = set_var(sn, rq, entry->param->name, entry->param->value); + switch(r) { + default: + case COMMONSAF_RET_DEF: break; + case COMMONSAF_RET_NOACTION: set = 1; ret = REQ_NOACTION; break; + case COMMONSAF_RET_STOP: set = 1; ret = REQ_PROCEED; break; + case COMMONSAF_REQ_ABORTED: ret = set ? ret : REQ_ABORTED; break; + case COMMONSAF_RET_ERROR: return REQ_ABORTED; + } + entry = entry->next; + } + } + + return ret; +} diff -r 85320d8b5d5c -r 36cd2e280386 src/server/safs/common.h --- a/src/server/safs/common.h Sat Jan 21 17:05:23 2017 +0100 +++ b/src/server/safs/common.h Tue Jan 24 17:36:28 2017 +0100 @@ -35,8 +35,12 @@ extern "C" { #endif +void common_saf_init(); + int print_message(pblock *pb, Session *sn, Request *rq); +int set_variable(pblock *pb, Session *sn, Request *rq); + #ifdef __cplusplus }