src/server/safs/common.c

Fri, 12 Jan 2018 17:54:52 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 12 Jan 2018 17:54:52 +0100
branch
aio
changeset 188
0e6a05c779e0
parent 157
a0c8e752490d
child 160
389bd0e1ffa9
permissions
-rw-r--r--

using non-blocking IO for SSL_accept

37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "common.h"
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "../daemon/httprequest.h"
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "../daemon/log.h"
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
154
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
34 #include "../util/pblock.h"
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
35 #include "../util/util.h"
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
36 #include "../../ucx/map.h"
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
37
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
38 static UcxMap *var_names;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
39
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
40 enum SAFVarNames {
157
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
41 COMMONSAF_INSERT_CLIENT = 1,
154
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
42 COMMONSAF_INSERT_VARS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
43 COMMONSAF_INSERT_REQPB,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
44 COMMONSAF_INSERT_HEADERS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
45 COMMONSAF_INSERT_SRVHDRS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
46 COMMONSAF_SET_CLIENT,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
47 COMMONSAF_SET_VARS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
48 COMMONSAF_SET_REQPB,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
49 COMMONSAF_SET_HEADERS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
50 COMMONSAF_SET_SRVHDRS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
51 COMMONSAF_REMOVE_CLIENT,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
52 COMMONSAF_REMOVE_VARS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
53 COMMONSAF_REMOVE_REQPB,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
54 COMMONSAF_REMOVE_HEADERS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
55 COMMONSAF_REMOVE_SRVHDRS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
56 COMMONSAF_ABORT,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
57 COMMONSAF_NOACTION,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
58 COMMONSAF_ERROR,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
59 COMMONSAF_ESCAPE,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
60 COMMONSAF_FIND_PATHINFO_FORWARD,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
61 COMMONSAF_HTTP_DOWNGRADE,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
62 COMMONSAF_HTTP_UPGRADE,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
63 COMMONSAF_KEEP_ALIVE,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
64 COMMONSAF_NAME,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
65 COMMONSAF_SENTHDRS,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
66 COMMONSAF_STOP,
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
67 COMMONSAF_URL
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
68 };
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
69
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
70 #define COMMONSAF_RET_DEF 0
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
71 #define COMMONSAF_RET_NOACTION 1
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
72 #define COMMONSAF_RET_STOP 2
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
73 #define COMMONSAF_REQ_ABORTED -1
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
74 #define COMMONSAF_RET_ERROR -2
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
75
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
76 void common_saf_init() {
157
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
77 var_names = ucx_map_new(32);
154
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
78
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
79 ucx_map_cstr_put(var_names, "insert-client", (intptr_t)COMMONSAF_INSERT_CLIENT);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
80 ucx_map_cstr_put(var_names, "insert-vars", (intptr_t)COMMONSAF_INSERT_VARS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
81 ucx_map_cstr_put(var_names, "insert-reqpb", (intptr_t)COMMONSAF_INSERT_REQPB);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
82 ucx_map_cstr_put(var_names, "insert-headers", (intptr_t)COMMONSAF_INSERT_HEADERS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
83 ucx_map_cstr_put(var_names, "insert-srvhdrs", (intptr_t)COMMONSAF_INSERT_SRVHDRS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
84
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
85 ucx_map_cstr_put(var_names, "set-client", (intptr_t)COMMONSAF_SET_CLIENT);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
86 ucx_map_cstr_put(var_names, "set-vars", (intptr_t)COMMONSAF_SET_VARS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
87 ucx_map_cstr_put(var_names, "set-reqpb", (intptr_t)COMMONSAF_SET_REQPB);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
88 ucx_map_cstr_put(var_names, "set-headers", (intptr_t)COMMONSAF_SET_HEADERS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
89 ucx_map_cstr_put(var_names, "set-srvhdrs", (intptr_t)COMMONSAF_SET_SRVHDRS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
90
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
91 ucx_map_cstr_put(var_names, "remove-client", (intptr_t)COMMONSAF_REMOVE_CLIENT);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
92 ucx_map_cstr_put(var_names, "remove-vars", (intptr_t)COMMONSAF_REMOVE_VARS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
93 ucx_map_cstr_put(var_names, "remove-reqpb", (intptr_t)COMMONSAF_REMOVE_REQPB);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
94 ucx_map_cstr_put(var_names, "remove-headers", (intptr_t)COMMONSAF_REMOVE_HEADERS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
95 ucx_map_cstr_put(var_names, "remove-srvhdrs", (intptr_t)COMMONSAF_REMOVE_SRVHDRS);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
96
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
97 ucx_map_cstr_put(var_names, "abort", (intptr_t)COMMONSAF_ABORT);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
98 ucx_map_cstr_put(var_names, "noaction", (intptr_t)COMMONSAF_NOACTION);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
99 ucx_map_cstr_put(var_names, "error", (intptr_t)COMMONSAF_ERROR);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
100 ucx_map_cstr_put(var_names, "escape", (intptr_t)COMMONSAF_ESCAPE);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
101 ucx_map_cstr_put(var_names, "find-pathinfo-forward", (intptr_t)COMMONSAF_FIND_PATHINFO_FORWARD);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
102 ucx_map_cstr_put(var_names, "http-downgrade", (intptr_t)COMMONSAF_HTTP_DOWNGRADE);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
103 ucx_map_cstr_put(var_names, "http-upgrade", (intptr_t)COMMONSAF_HTTP_UPGRADE);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
104 ucx_map_cstr_put(var_names, "keep-alive", (intptr_t)COMMONSAF_KEEP_ALIVE);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
105 ucx_map_cstr_put(var_names, "name", (intptr_t)COMMONSAF_NAME);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
106 }
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
107
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 int print_message(pblock *pb, Session *sn, Request *rq) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 char *msg = pblock_findval("msg", pb);
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 if(msg) {
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
111 log_ereport(LOG_INFORM, "%s", msg);
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 return REQ_NOACTION;
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
154
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
116
157
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
117 static void var_set(char *value, pblock *pb, WSBool insert) {
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
118 sstr_t n;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
119 sstr_t v;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
120 v.ptr = NULL;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
121
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
122 n.ptr = value;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
123 int i;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
124 int len = strlen(value);
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
125 for(i=1;i<len;i++) {
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
126 if(value[i] == '=') {
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
127 n.length = i;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
128 v = sstrsubs(sstrn(value, len), i + 1);
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
129 break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
130 }
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
131 }
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
132 if(!v.ptr || v.length == 0) {
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
133 log_ereport(
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
134 LOG_MISCONFIG,
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
135 "set-variable: string '%s' has not name=value format",
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
136 value);
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
137 return;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
138 }
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
139
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
140 if(!insert) {
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
141 // TODO
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
142 }
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
143 pblock_nvlinsert(n.ptr, n.length, v.ptr, v.length, pb);
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
144 }
154
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
145
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
146 static int set_var(Session *sn, Request *rq, char *var, char *value) {
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
147 intptr_t v = (intptr_t)ucx_map_cstr_get(var_names, var);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
148 switch(v) {
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
149 default: break;
157
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
150 case COMMONSAF_INSERT_CLIENT: var_set(value, sn->client, TRUE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
151 case COMMONSAF_INSERT_VARS: var_set(value, rq->vars, TRUE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
152 case COMMONSAF_INSERT_REQPB: var_set(value, rq->reqpb, TRUE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
153 case COMMONSAF_INSERT_HEADERS: var_set(value, rq->headers, TRUE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
154 case COMMONSAF_INSERT_SRVHDRS: var_set(value, rq->srvhdrs, TRUE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
155 case COMMONSAF_SET_CLIENT: var_set(value, sn->client, FALSE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
156 case COMMONSAF_SET_VARS: var_set(value, rq->vars, FALSE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
157 case COMMONSAF_SET_REQPB: var_set(value, rq->reqpb, FALSE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
158 case COMMONSAF_SET_HEADERS: var_set(value, rq->headers, FALSE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
159 case COMMONSAF_SET_SRVHDRS: var_set(value, rq->srvhdrs, FALSE); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
160 case COMMONSAF_REMOVE_CLIENT: pblock_remove(value, sn->client); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
161 case COMMONSAF_REMOVE_VARS: pblock_remove(value, rq->vars); break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
162 case COMMONSAF_REMOVE_HEADERS: pblock_remove(value, rq->headers);break;
a0c8e752490d adds pblock operations to set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 154
diff changeset
163 case COMMONSAF_REMOVE_SRVHDRS: pblock_remove(value, rq->srvhdrs); break;
154
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
164 case COMMONSAF_ABORT: return COMMONSAF_REQ_ABORTED;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
165 case COMMONSAF_ERROR: {
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
166 return COMMONSAF_REQ_ABORTED;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
167 }
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
168 case COMMONSAF_ESCAPE: break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
169 case COMMONSAF_FIND_PATHINFO_FORWARD: break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
170 case COMMONSAF_HTTP_DOWNGRADE: break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
171 case COMMONSAF_HTTP_UPGRADE: break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
172 case COMMONSAF_KEEP_ALIVE: {
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
173 rq->rq_attr.keep_alive = util_getboolean(var, 0);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
174 break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
175 }
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
176 case COMMONSAF_NAME: break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
177 case COMMONSAF_SENTHDRS: break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
178 case COMMONSAF_STOP: return COMMONSAF_RET_STOP;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
179 case COMMONSAF_URL: break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
180 }
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
181 return COMMONSAF_RET_DEF;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
182 }
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
183
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
184 int set_variable(pblock *pb, Session *sn, Request *rq) {
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
185 int ret = REQ_NOACTION;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
186 int set = 0;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
187
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
188 for(int i=0;i<pb->hsize;i++) {
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
189 pb_entry *entry = pb->ht[i];
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
190 while(entry) {
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
191 int r = set_var(sn, rq, entry->param->name, entry->param->value);
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
192 switch(r) {
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
193 default:
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
194 case COMMONSAF_RET_DEF: break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
195 case COMMONSAF_RET_NOACTION: set = 1; ret = REQ_NOACTION; break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
196 case COMMONSAF_RET_STOP: set = 1; ret = REQ_PROCEED; break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
197 case COMMONSAF_REQ_ABORTED: ret = set ? ret : REQ_ABORTED; break;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
198 case COMMONSAF_RET_ERROR: return REQ_ABORTED;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
199 }
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
200 entry = entry->next;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
201 }
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
202 }
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
203
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
204 return ret;
6394ce09889a adds set-variable saf
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
205 }

mercurial