Sun, 01 May 2022 10:48:20 +0200
add WebdavNSList <-> string converting functions
1 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2008 Sun Microsystems, Inc. All rights reserved. | |
5 | * | |
6 | * THE BSD LICENSE | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are met: | |
10 | * | |
11 | * Redistributions of source code must retain the above copyright notice, this | |
12 | * list of conditions and the following disclaimer. | |
13 | * Redistributions in binary form must reproduce the above copyright notice, | |
14 | * this list of conditions and the following disclaimer in the documentation | |
15 | * and/or other materials provided with the distribution. | |
16 | * | |
17 | * Neither the name of the nor the names of its contributors may be | |
18 | * used to endorse or promote products derived from this software without | |
19 | * specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER | |
25 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | /* | |
35 | * util.c: A hodge podge of utility functions and standard functions which | |
36 | * are unavailable on certain systems | |
37 | * | |
38 | * Rob McCool | |
39 | */ | |
40 | ||
41 | #ifdef XP_UNIX | |
42 | #include <sys/types.h> | |
43 | #include <sys/wait.h> | |
44 | #include <stdlib.h> | |
45 | #include <unistd.h> | |
46 | #include <limits.h> | |
47 | #include "prthread.h" | |
48 | #endif /* XP_UNIX */ | |
49 | ||
50 | ||
24
1a7853a4257e
removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
51 | //include "nspr.h" |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
52 | #include <errno.h> |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
53 | |
24
1a7853a4257e
removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
54 | #include "../daemon/netsite.h" |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1
diff
changeset
|
55 | #include "../public/nsapi.h" |
91 | 56 | #include <ucx/string.h> |
57 | #include <ucx/mempool.h> | |
1 | 58 | |
96
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
59 | #include "pblock.h" |
1 | 60 | #include "util.h" |
61 | ||
127
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
62 | #include <openssl/bio.h> |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
63 | #include <openssl/buffer.h> |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
64 | #include <openssl/evp.h> |
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
65 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
66 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
67 | /* ------------------------------ _uudecode ------------------------------- */ |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
68 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
69 | static const unsigned char pr2six[256] = { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
70 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
71 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
72 | 52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,1,2,3,4,5,6,7,8,9, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
73 | 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,64,26,27, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
74 | 28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
75 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
76 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
77 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
78 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
79 | 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64, |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
80 | 64,64,64,64,64,64,64,64,64,64,64,64,64 |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
81 | }; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
82 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
83 | /** you MUST reserve at least 2 additional bytes for bufout */ |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
84 | size_t util_base64decode(char *bufcoded, size_t codedbytes, char *bufout) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
85 | register char *bufin = bufcoded; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
86 | register int nprbytes; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
87 | size_t nbytesdecoded; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
88 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
89 | /* Find the length */ |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
90 | nprbytes = (int) codedbytes; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
91 | while(pr2six[(int)(bufin[nprbytes-1])] >= 64) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
92 | nprbytes--; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
93 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
94 | nbytesdecoded = ((nprbytes+3)/4) * 3; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
95 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
96 | while (nprbytes > 0) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
97 | *(bufout++) = (unsigned char) |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
98 | (pr2six[(int)(*bufin)] << 2 | pr2six[(int)bufin[1]] >> 4); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
99 | *(bufout++) = (unsigned char) |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
100 | (pr2six[(int)bufin[1]] << 4 | pr2six[(int)bufin[2]] >> 2); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
101 | *(bufout++) = (unsigned char) |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
102 | (pr2six[(int)bufin[2]] << 6 | pr2six[(int)bufin[3]]); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
103 | bufin += 4; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
104 | nprbytes -= 4; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
105 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
106 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
107 | if(nprbytes & 03) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
108 | if(pr2six[(int)bufin[-2]] > 63) |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
109 | nbytesdecoded -= 2; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
110 | else |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
111 | nbytesdecoded -= 1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
112 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
113 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
114 | return nbytesdecoded; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
115 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
116 | |
127
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
117 | char* util_base64encode(char *in, size_t len) { |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
118 | BIO *b; |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
119 | BIO *e; |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
120 | BUF_MEM *mem; |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
121 | |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
122 | e = BIO_new(BIO_f_base64()); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
123 | b = BIO_new(BIO_s_mem()); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
124 | BIO_set_flags(e, BIO_FLAGS_BASE64_NO_NL); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
125 | |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
126 | e = BIO_push(e, b); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
127 | BIO_write(e, in, len); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
128 | BIO_flush(e); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
129 | |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
130 | BIO_get_mem_ptr(e, &mem); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
131 | char *out = malloc(mem->length + 1); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
132 | memcpy(out, mem->data, mem->length); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
133 | out[mem->length] = '\0'; |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
134 | |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
135 | BIO_free_all(e); |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
136 | |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
137 | return out; |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
138 | } |
84e206063b64
adds minimal websocket implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
119
diff
changeset
|
139 | |
77 | 140 | |
141 | /* --------------------------- util_env_create ---------------------------- */ | |
142 | ||
143 | ||
144 | NSAPI_PUBLIC char **util_env_create(char **env, int n, int *pos) | |
145 | { | |
146 | int x; | |
147 | ||
148 | if(!env) { | |
149 | *pos = 0; | |
150 | return (char **) MALLOC((n + 1)*sizeof(char *)); | |
151 | } | |
152 | else { | |
153 | for(x = 0; (env[x]); x++); | |
154 | env = (char **) REALLOC(env, (n + x + 1)*(sizeof(char *))); | |
155 | *pos = x; | |
156 | return env; | |
157 | } | |
158 | } | |
159 | ||
160 | ||
161 | /* ---------------------------- util_env_free ----------------------------- */ | |
162 | ||
163 | ||
164 | NSAPI_PUBLIC void util_env_free(char **env) | |
165 | { | |
166 | register char **ep = env; | |
167 | ||
168 | for(ep = env; *ep; ep++) | |
169 | FREE(*ep); | |
170 | FREE(env); | |
171 | } | |
172 | ||
173 | /* ----------------------------- util_env_str ----------------------------- */ | |
174 | ||
175 | ||
176 | NSAPI_PUBLIC char *util_env_str(const char *name, const char *value) { | |
177 | char *t; | |
118
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
178 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
179 | size_t len = strlen(name) + strlen(value) + 2; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
180 | t = (char *) MALLOC(len); /* 2: '=' and '\0' */ |
77 | 181 | |
118
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
182 | snprintf(t, len, "%s=%s", name, value); |
77 | 183 | |
184 | return t; | |
185 | } | |
186 | ||
187 | ||
188 | /* --------------------------- util_env_replace --------------------------- */ | |
189 | ||
190 | ||
191 | NSAPI_PUBLIC void util_env_replace(char **env, const char *name, const char *value) | |
192 | { | |
193 | int x, y, z; | |
194 | char *i; | |
195 | ||
196 | for(x = 0; env[x]; x++) { | |
197 | i = strchr(env[x], '='); | |
198 | *i = '\0'; | |
199 | if(!strcmp(env[x], name)) { | |
200 | y = strlen(env[x]); | |
201 | z = strlen(value); | |
202 | ||
203 | env[x] = (char *) REALLOC(env[x], y + z + 2); | |
204 | util_sprintf(&env[x][y], "=%s", value); | |
205 | return; | |
206 | } | |
207 | *i = '='; | |
1 | 208 | } |
77 | 209 | } |
210 | ||
211 | ||
118
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
212 | /* ---------------------------- util_sh_escape ---------------------------- */ |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
213 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
214 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
215 | NSAPI_PUBLIC char *util_sh_escape(char *s) |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
216 | { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
217 | char *ns = (char *) MALLOC(strlen(s) * 2 + 1); /* worst case */ |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
218 | register char *t, *u; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
219 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
220 | for(t = s, u = ns; *t; ++t, ++u) { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
221 | if(strchr("&;`'\"|*?~<>^()[]{}$\\ #!", *t)) |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
222 | *u++ = '\\'; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
223 | *u = *t; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
224 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
225 | *u = '\0'; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
226 | return ns; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
227 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
228 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
114
diff
changeset
|
229 | |
77 | 230 | /* ---------------------------- util_env_find ----------------------------- */ |
231 | ||
232 | ||
233 | NSAPI_PUBLIC char *util_env_find(char **env, const char *name) | |
234 | { | |
235 | char *i; | |
236 | int x, r; | |
237 | ||
238 | for(x = 0; env[x]; x++) { | |
239 | i = strchr(env[x], '='); | |
240 | *i = '\0'; | |
241 | r = !strcmp(env[x], name); | |
242 | *i = '='; | |
243 | if(r) | |
244 | return i + 1; | |
1 | 245 | } |
77 | 246 | return NULL; |
247 | } | |
248 | ||
249 | ||
250 | /* ---------------------------- util_env_copy ----------------------------- */ | |
251 | ||
252 | ||
253 | NSAPI_PUBLIC char **util_env_copy(char **src, char **dst) | |
254 | { | |
255 | char **src_ptr; | |
256 | int src_cnt; | |
257 | int index; | |
258 | ||
259 | if (!src) | |
260 | return NULL; | |
261 | ||
262 | for (src_cnt = 0, src_ptr = src; *src_ptr; src_ptr++, src_cnt++); | |
263 | ||
264 | if (!src_cnt) | |
265 | return NULL; | |
266 | ||
267 | dst = util_env_create(dst, src_cnt, &index); | |
268 | ||
269 | for (src_ptr = src; *src_ptr; index++, src_ptr++) | |
270 | dst[index] = STRDUP(*src_ptr); | |
271 | dst[index] = NULL; | |
272 | ||
273 | return dst; | |
1 | 274 | } |
77 | 275 | |
276 | /* ----------------------------- util_sprintf ----------------------------- */ | |
277 | ||
278 | NSAPI_PUBLIC int util_vsnprintf(char *s, int n, register const char *fmt, | |
279 | va_list args) | |
280 | { | |
281 | return vsnprintf(s, n, fmt, args); | |
282 | } | |
283 | ||
284 | NSAPI_PUBLIC int util_snprintf(char *s, int n, const char *fmt, ...) | |
285 | { | |
286 | va_list args; | |
287 | va_start(args, fmt); | |
288 | return vsnprintf(s, n, fmt, args); | |
289 | } | |
290 | ||
291 | NSAPI_PUBLIC int util_vsprintf(char *s, register const char *fmt, va_list args) | |
292 | { | |
293 | return vsprintf(s, fmt, args); | |
294 | } | |
295 | ||
296 | NSAPI_PUBLIC int util_sprintf(char *s, const char *fmt, ...) | |
297 | { | |
298 | va_list args; | |
299 | va_start(args, fmt); | |
300 | return vsprintf(s, fmt, args); | |
301 | } | |
302 | ||
303 | // TODO: asprintf | |
304 | ||
1 | 305 | |
81
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
306 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
307 | /* -------------------------- util_uri_unescape --------------------------- */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
308 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
309 | NSAPI_PUBLIC void util_uri_unescape(char *s) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
310 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
311 | char *t, *u; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
312 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
313 | for(t = s, u = s; *t; ++t, ++u) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
314 | if((*t == '%') && t[1] && t[2]) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
315 | *u = ((t[1] >= 'A' ? ((t[1] & 0xdf) - 'A')+10 : (t[1] - '0'))*16) + |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
316 | (t[2] >= 'A' ? ((t[2] & 0xdf) - 'A')+10 : (t[2] - '0')); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
317 | t += 2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
318 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
319 | else |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
320 | if(u != t) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
321 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
322 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
323 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
324 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
325 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
326 | /* |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
327 | * Same as util_uri_unescape, but returns success/failure |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
328 | */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
329 | NSAPI_PUBLIC int util_uri_unescape_strict(char *s) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
330 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
331 | char *t, *u, t1, t2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
332 | int rv = 1; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
333 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
334 | for(t = s, u = s; *t; ++t, ++u) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
335 | if (*t == '%') { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
336 | t1 = t[1] & 0xdf; /* [a-f] -> [A-F] */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
337 | if ((t1 < 'A' || t1 > 'F') && (t[1] < '0' || t[1] > '9')) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
338 | rv = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
339 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
340 | t2 = t[2] & 0xdf; /* [a-f] -> [A-F] */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
341 | if ((t2 < 'A' || t2 > 'F') && (t[2] < '0' || t[2] > '9')) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
342 | rv = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
343 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
344 | *u = ((t[1] >= 'A' ? ((t[1] & 0xdf) - 'A')+10 : (t[1] - '0'))*16) + |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
345 | (t[2] >= 'A' ? ((t[2] & 0xdf) - 'A')+10 : (t[2] - '0')); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
346 | t += 2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
347 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
348 | else if (u != t) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
349 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
350 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
351 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
352 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
353 | return rv; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
354 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
355 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
356 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
357 | NSAPI_PUBLIC int |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
358 | util_uri_unescape_plus (const char *src, char *trg, int len) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
359 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
360 | const char *t = src; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
361 | char *u = trg == NULL ? (char *)src : trg; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
362 | int rlen = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
363 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
364 | if (len == -1) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
365 | len = strlen (src); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
366 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
367 | for( ; len && *t; ++t, ++u, len--, rlen++) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
368 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
369 | if((*t == '%') && t[1] && t[2]) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
370 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
371 | *u = ((t[1] >= 'A' ? ((t[1] & 0xdf) - 'A') + 10 : (t[1] - '0')) * 16) + |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
372 | (t[2] >= 'A' ? ((t[2] & 0xdf) - 'A') + 10 : (t[2] - '0')); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
373 | t += 2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
374 | len-= 2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
375 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
376 | else |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
377 | if (*t == '+') |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
378 | *u = ' '; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
379 | else |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
380 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
381 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
382 | *u = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
383 | return rlen; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
384 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
385 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
386 | |
1 | 387 | NSAPI_PUBLIC int INTutil_getboolean(const char *v, int def) { |
388 | if(v[0] == 'T' || v[0] == 't') { | |
389 | return 1; | |
390 | } | |
391 | if(v[0] == 'F' || v[0] == 'f') { | |
392 | return 0; | |
393 | } | |
394 | return def; | |
395 | } | |
396 | ||
256
19259b6c5cf7
replace old server config loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
127
diff
changeset
|
397 | int util_getboolean_s(scstr_t s, int def) { |
106
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
398 | if(s.length == 0) { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
399 | return def; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
400 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
401 | if(s.ptr[0] == 'T' || s.ptr[0] == 't') { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
402 | return 1; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
403 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
404 | if(s.ptr[0] == 'F' || s.ptr[0] == 'f') { |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
405 | return 0; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
406 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
407 | return def; |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
408 | } |
b122f34ddc80
added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
409 | |
282
cfb588e27198
add support for getstat parameter in pg readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
278
diff
changeset
|
410 | NSAPI_PUBLIC int util_strtoint(const char *str, int64_t *value) { |
119
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
411 | char *end; |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
412 | errno = 0; |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
413 | int64_t val = strtoll(str, &end, 0); |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
414 | if(errno == 0) { |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
415 | *value = val; |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
416 | return 1; |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
417 | } else { |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
418 | return 0; |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
419 | } |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
420 | } |
155cbab9eefd
adds support for CGI with request bodies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
118
diff
changeset
|
421 | |
278
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
422 | NSAPI_PUBLIC const char* util_resource_name(const char *url) { |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
423 | scstr_t urlstr = scstr(url); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
424 | if(urlstr.ptr[urlstr.length-1] == '/') { |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
425 | urlstr.length--; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
426 | } |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
427 | scstr_t resname = scstrrchr(urlstr, '/'); |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
428 | if(resname.length > 1) { |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
429 | return resname.ptr+1; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
430 | } else { |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
431 | return url; |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
432 | } |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
433 | } |
38bf7b42b58c
implement pg_vfs_open
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
273
diff
changeset
|
434 | |
285
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
435 | NSAPI_PUBLIC char* util_parent_path(const char *path) { |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
436 | char *name = util_resource_name((char*)path); |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
437 | size_t namelen = strlen(name); |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
438 | size_t pathlen = strlen(path); |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
439 | size_t parentlen = pathlen - namelen; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
440 | char *parent = MALLOC(parentlen + 1); |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
441 | memcpy(parent, path, parentlen); |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
442 | parent[parentlen] = '\0'; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
443 | return parent; |
96e53bd94958
add support for O_CREAT flag in postgresql vfs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
444 | } |
1 | 445 | |
446 | /* ------------------------------ util_itoa ------------------------------- */ | |
447 | /* | |
448 | NSAPI_PUBLIC int util_itoa(int i, char *a) | |
449 | { | |
450 | int len = util_i64toa(i, a); | |
451 | ||
452 | PR_ASSERT(len < UTIL_ITOA_SIZE); | |
453 | ||
454 | return len; | |
455 | } | |
456 | */ | |
457 | NSAPI_PUBLIC int INTutil_itoa(int i, char *a) { | |
458 | return INTutil_i64toa(i, a); | |
459 | } | |
460 | ||
461 | ||
462 | /* ----------------------------- util_i64toa ------------------------------ */ | |
463 | ||
464 | /* | |
465 | * Assumption: Reversing the digits will be faster in the general case | |
466 | * than doing a log10 or some nasty trick to find the # of digits. | |
467 | */ | |
468 | ||
24
1a7853a4257e
removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
469 | NSAPI_PUBLIC int INTutil_i64toa(int64_t i, char *a) |
1 | 470 | { |
471 | register int x, y, p; | |
472 | register char c; | |
473 | int negative; | |
474 | ||
475 | negative = 0; | |
476 | if(i < 0) { | |
477 | *a++ = '-'; | |
478 | negative = 1; | |
479 | i = -i; | |
480 | } | |
481 | p = 0; | |
482 | while(i > 9) { | |
483 | a[p++] = (i%10) + '0'; | |
484 | i /= 10; | |
485 | } | |
486 | a[p++] = i + '0'; | |
487 | ||
488 | if(p > 1) { | |
489 | for(x = 0, y = p - 1; x < y; ++x, --y) { | |
490 | c = a[x]; | |
491 | a[x] = a[y]; | |
492 | a[y] = c; | |
493 | } | |
494 | } | |
495 | a[p] = '\0'; | |
496 | ||
497 | //PR_ASSERT(p + negative < UTIL_I64TOA_SIZE); | |
498 | ||
499 | return p + negative; | |
500 | } | |
47
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
501 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
502 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
503 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
504 | #ifndef XP_WIN32 |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
505 | NSAPI_PUBLIC struct passwd * |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
506 | util_getpwnam(const char *name, struct passwd *result, char *buffer, |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
507 | int buflen) |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
508 | { |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
509 | struct passwd *rv; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
510 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
511 | errno = getpwnam_r(name, result, buffer, buflen, &rv); |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
512 | if (errno != 0) |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
513 | rv = NULL; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
514 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
515 | return rv; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
516 | } |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
517 | #endif |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
518 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
519 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
520 | #ifndef XP_WIN32 |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
521 | NSAPI_PUBLIC struct passwd * |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
522 | util_getpwuid(uid_t uid, struct passwd *result, char *buffer, int buflen) |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
523 | { |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
524 | struct passwd *rv; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
525 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
526 | errno = getpwuid_r(uid, result, buffer, buflen, &rv); |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
527 | if (errno != 0) |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
528 | rv = NULL; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
529 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
530 | return rv; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
531 | } |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
532 | #endif |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
533 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
534 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
535 | NSAPI_PUBLIC int util_errno2status(int errno_value) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
536 | switch(errno_value) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
537 | case 0: { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
538 | return 200; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
539 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
540 | case EACCES: { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
541 | return 403; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
542 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
543 | case ENOENT: { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
544 | return 404; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
545 | break; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
546 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
547 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
548 | return 500; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
549 | } |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
550 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
551 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
552 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
553 | NSAPI_PUBLIC |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
554 | sstr_t util_path_append(pool_handle_t *pool, char *path, char *ch) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
555 | sstr_t parent = sstr(path); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
556 | sstr_t child = sstr(ch); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
557 | sstr_t newstr; |
99 | 558 | |
559 | UcxAllocator a = util_pool_allocator(pool); | |
114
c3a0f1275d71
fixed keep alive bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
560 | if(parent.ptr[parent.length-1] == '/') { |
c3a0f1275d71
fixed keep alive bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
561 | newstr = sstrcat_a(&a, 2, parent, child); |
99 | 562 | } else { |
114
c3a0f1275d71
fixed keep alive bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
113
diff
changeset
|
563 | newstr = sstrcat_a(&a, 3, parent, S("/"), child); |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
564 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
565 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
566 | return newstr; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
567 | } |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
568 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
569 | sstr_t util_path_remove_last(sstr_t path) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
570 | int i; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
571 | for(i=path.length-1;i>=0;i--) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
572 | char c = path.ptr[i]; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
573 | if(c == '/') { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
574 | path.ptr[i] = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
575 | path.length = i; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
576 | break; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
577 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
578 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
579 | if(i < 0) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
580 | path.ptr = NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
581 | path.length = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
582 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
583 | return path; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
584 | } |
81
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
585 | |
96
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
586 | void util_add_ppath(sstr_t root, sstr_t path, pblock *vars) { |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
587 | // concat path |
99 | 588 | size_t length = root.length + path.length; |
589 | char *translated_path = alloca(length); | |
96
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
590 | |
99 | 591 | memcpy(translated_path, root.ptr, root.length); |
592 | memcpy(translated_path + root.length, path.ptr, path.length); | |
593 | ||
96
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
594 | |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
595 | // add path to specified pblock |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
596 | pblock_kvinsert( |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
597 | pb_key_ppath, |
99 | 598 | translated_path, |
599 | length, | |
96
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
600 | vars); |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
601 | } |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
602 | |
81
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
603 | |
99 | 604 | UcxAllocator util_pool_allocator(pool_handle_t *pool) { |
605 | UcxAllocator a; | |
606 | a.malloc = (ucx_allocator_malloc)pool_malloc; | |
607 | a.calloc = (ucx_allocator_calloc)pool_calloc; | |
608 | a.realloc = (ucx_allocator_realloc)pool_realloc; | |
609 | a.free = (ucx_allocator_free)pool_free; | |
610 | a.pool = pool; | |
611 | return a; | |
612 | } | |
613 | ||
614 | ||
102
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
615 | // new - code from params.cpp |
81
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
616 | NSAPI_PUBLIC pblock* util_parse_param(pool_handle_t *pool, char *query) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
617 | pblock *pb = pblock_create_pool(pool, 32); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
618 | if(!pb) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
619 | return NULL; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
620 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
621 | if(!query || !(*query)) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
622 | return pb; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
623 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
624 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
625 | int loopFlag = 1; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
626 | int nl = 0; // size of the name substring |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
627 | int vl = 0; // size of the value substring |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
628 | int state = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
629 | const char *np = query; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
630 | const char *vp = NULL; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
631 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
632 | while (loopFlag) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
633 | char delim = *query++; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
634 | switch (delim) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
635 | case '&': |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
636 | case '\0': { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
637 | if(!delim) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
638 | loopFlag = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
639 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
640 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
641 | state = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
642 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
643 | if(nl > 0) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
644 | util_uri_unescape_plus(np, NULL, nl); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
645 | util_uri_unescape_plus(vp, NULL, vl); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
646 | pblock_nvlinsert(np, nl, vp, vl, pb); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
647 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
648 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
649 | nl = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
650 | vl = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
651 | vp = NULL; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
652 | np = query; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
653 | break; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
654 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
655 | case '=': { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
656 | state = 1; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
657 | vp = query; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
658 | break; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
659 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
660 | default: { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
661 | if(state) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
662 | vl++; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
663 | } else { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
664 | nl++; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
665 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
666 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
667 | } /* switch */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
668 | } /* while */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
669 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
670 | return pb; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
671 | } |
91 | 672 | |
673 | // TODO: remove | |
674 | sstr_t sstrdup_mp(UcxMempool *pool, sstr_t s) { | |
675 | sstr_t newstring; | |
676 | newstring.ptr = (char*)ucx_mempool_malloc(pool, s.length + 1); | |
677 | if (newstring.ptr != NULL) { | |
678 | newstring.length = s.length; | |
679 | newstring.ptr[newstring.length] = 0; | |
680 | ||
681 | memcpy(newstring.ptr, s.ptr, s.length); | |
682 | } | |
683 | ||
684 | return newstring; | |
685 | } | |
102
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
686 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
687 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
688 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
689 | /* ---------------------------- util_mstr2num ----------------------------- */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
690 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
691 | static const int MSTR2NUM_HT_MASK = 0xf; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
692 | |
103
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
693 | struct mstr2num_ht { |
102
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
694 | unsigned ucmstr; // Uppercase 3 character month string in a machine word |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
695 | int mnum; // 0-based month number for this month string |
103
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
696 | }; |
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
697 | |
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
698 | struct mstr2num_ht MSTR2NUM_HT[] = { |
102
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
699 | { 'A' << 16 | 'P' << 8 | 'R', 3 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
700 | { 'S' << 16 | 'E' << 8 | 'P', 8 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
701 | { 'M' << 16 | 'A' << 8 | 'Y', 4 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
702 | { 0, -1 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
703 | { 'M' << 16 | 'A' << 8 | 'R', 2 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
704 | { 'F' << 16 | 'E' << 8 | 'B', 1 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
705 | { 0, -1 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
706 | { 'D' << 16 | 'E' << 8 | 'C', 11 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
707 | { 'O' << 16 | 'C' << 8 | 'T', 9 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
708 | { 'J' << 16 | 'U' << 8 | 'N', 5 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
709 | { 0, -1 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
710 | { 'A' << 16 | 'U' << 8 | 'G', 7 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
711 | { 'J' << 16 | 'A' << 8 | 'N', 0 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
712 | { 'J' << 16 | 'U' << 8 | 'L', 6 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
713 | { 0, -1 }, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
714 | { 'N' << 16 | 'O' << 8 | 'V', 10 } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
715 | }; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
716 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
717 | static inline int _mstr2num(const char *s) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
718 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
719 | const unsigned char *mstr = (const unsigned char *) s; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
720 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
721 | /* |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
722 | * We compute ucmstr (an uppercase 3 character month string stored in a |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
723 | * machine word) and hash (a perfect hash based on the last 2 characters |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
724 | * of the 3 character uppercase month string) from the input string s. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
725 | * Note that each character from the input string is masked by 0xdf; in |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
726 | * ASCII, this has the effect of converting alphabetic characters to |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
727 | * uppercase while 1. not changing any nonalphabetic characters into |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
728 | * alphabetic characters and 2. leaving any nul characters unchanged. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
729 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
730 | * The hash value is used as an index into the MSTR2NUM_HT[] hash table. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
731 | * If the ucmstr at that index matches our computed ucmstr, the mnum at |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
732 | * that index is the 0-based month number corresponding to the input |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
733 | * string. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
734 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
735 | * Note that we never read past the end of the input string and always |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
736 | * return -1 if the input string doesn't begin with a valid 3 character |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
737 | * month string. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
738 | */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
739 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
740 | unsigned char ucmstr0 = mstr[0] & 0xdf; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
741 | unsigned ucmstr = ucmstr0 << 16; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
742 | if (ucmstr0 != '\0') { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
743 | unsigned char ucmstr1 = mstr[1] & 0xdf; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
744 | ucmstr |= ucmstr1 << 8; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
745 | if (ucmstr1 != '\0') { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
746 | unsigned char ucmstr2 = mstr[2] & 0xdf; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
747 | ucmstr |= ucmstr2; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
748 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
749 | unsigned hash = (ucmstr1 >> 2) ^ (ucmstr2 << 1); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
750 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
751 | int i = hash & MSTR2NUM_HT_MASK; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
752 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
753 | if (MSTR2NUM_HT[i].ucmstr == ucmstr) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
754 | return MSTR2NUM_HT[i].mnum; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
755 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
756 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
757 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
758 | return -1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
759 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
760 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
761 | NSAPI_PUBLIC int util_mstr2num(const char *s) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
762 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
763 | return _mstr2num(s); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
764 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
765 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
766 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
767 | /* ------------------------- util_str_time_equal -------------------------- */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
768 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
769 | /* |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
770 | * Function to compare if two time strings are equal |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
771 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
772 | * Acceptable date formats: |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
773 | * Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
774 | * Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
775 | * Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
776 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
777 | * Return 0 if equal, -1 if not equal. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
778 | */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
779 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
780 | static inline const char * _parse_day_month(const char *p, int *day, int *month) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
781 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
782 | *day = 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
783 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
784 | if (*p == ',') { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
785 | // Parse day and month: ", 06 Nov", ", 06-Nov" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
786 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
787 | if (*p == ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
788 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
789 | while (*p >= '0' && *p <= '9') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
790 | *day = *day * 10 + (*p++ - '0'); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
791 | if (*p == ' ' || *p == '-') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
792 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
793 | *month = _mstr2num(p); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
794 | if (*month != -1) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
795 | p += 3; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
796 | } else { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
797 | // Parse month and day: " Nov 6" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
798 | if (*p == ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
799 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
800 | *month = _mstr2num(p); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
801 | if (*month != -1) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
802 | p += 3; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
803 | while (*p == ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
804 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
805 | while (*p >= '0' && *p <= '9') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
806 | *day = *day * 10 + (*p++ - '0'); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
807 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
808 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
809 | return p; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
810 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
811 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
812 | static inline void _parse_year_time(const char *p, int *year, const char ** time) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
813 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
814 | int _year = 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
815 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
816 | if (*p == '-') { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
817 | // Parse year and time: "-94 08:49:37" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
818 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
819 | while (*p >= '0' && *p <= '9') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
820 | _year = _year * 10 + (*p++ - '0'); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
821 | if (_year < 70) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
822 | _year += 2000; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
823 | } else { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
824 | _year += 1900; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
825 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
826 | if (*p == ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
827 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
828 | *time = p; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
829 | } else { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
830 | // Parse year and time or time and year |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
831 | if (*p == ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
832 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
833 | if (p[0] && p[1] && p[2] == ':') { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
834 | // Parse time and year: "08:49:37 1994" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
835 | *time = p; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
836 | p += 3; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
837 | while (*p && *p != ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
838 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
839 | if (*p == ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
840 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
841 | while (*p >= '0' && *p <= '9') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
842 | _year = _year * 10 + (*p++ - '0'); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
843 | } else { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
844 | // Parse year and time: "1994 08:49:37" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
845 | while (*p >= '0' && *p <= '9') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
846 | _year = _year * 10 + (*p++ - '0'); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
847 | if (*p == ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
848 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
849 | *time = p; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
850 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
851 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
852 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
853 | *year = _year; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
854 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
855 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
856 | NSAPI_PUBLIC int util_str_time_equal(const char *t1, const char *t2) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
857 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
858 | // Skip leading whitespace and day of week |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
859 | while (isspace(*t1)) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
860 | t1++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
861 | while (isalpha(*t1)) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
862 | t1++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
863 | while (isspace(*t2)) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
864 | t2++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
865 | while (isalpha(*t2)) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
866 | t2++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
867 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
868 | // Day and month: ", 06 Nov", ", 06-Nov", or " Nov 6" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
869 | int day1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
870 | int month1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
871 | t1 = _parse_day_month(t1, &day1, &month1); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
872 | int day2; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
873 | int month2; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
874 | t2 = _parse_day_month(t2, &day2, &month2); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
875 | if (day1 != day2) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
876 | return -1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
877 | if (month1 != month2) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
878 | return -1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
879 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
880 | // Year and time: " 1994 08:49:37", "-94 08:49:37", or " 08:49:37 1994" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
881 | int year1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
882 | const char *time1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
883 | _parse_year_time(t1, &year1, &time1); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
884 | int year2; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
885 | const char *time2; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
886 | _parse_year_time(t2, &year2, &time2); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
887 | if (year1 != year2) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
888 | return -1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
889 | while (*time1 && *time1 != ' ' && *time1 == *time2) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
890 | time1++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
891 | time2++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
892 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
893 | if (*time2 && *time2 != ' ') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
894 | return -1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
895 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
896 | return 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
897 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
898 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
899 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
900 | /* --------------------------- util_later_than ---------------------------- */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
901 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
902 | static int _time_compare(const struct tm *lms, const char *ims) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
903 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
904 | while (isspace(*ims)) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
905 | ims++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
906 | while (isalpha(*ims)) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
907 | ims++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
908 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
909 | int day; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
910 | int month; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
911 | ims = _parse_day_month(ims, &day, &month); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
912 | if (month == -1) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
913 | return 1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
914 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
915 | int year; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
916 | const char *time; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
917 | _parse_year_time(ims, &year, &time); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
918 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
919 | int rv; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
920 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
921 | rv = (lms->tm_year + 1900) - year; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
922 | if (rv) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
923 | return rv; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
924 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
925 | rv = lms->tm_mon - month; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
926 | if (rv) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
927 | return rv; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
928 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
929 | rv = lms->tm_mday - day; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
930 | if (rv) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
931 | return rv; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
932 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
933 | const char *p = time; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
934 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
935 | int hour = 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
936 | while (*p >= '0' && *p <= '9') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
937 | hour = hour * 10 + (*p++ - '0'); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
938 | if (*p == ':') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
939 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
940 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
941 | rv = lms->tm_hour - hour; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
942 | if (rv) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
943 | return rv; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
944 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
945 | int minutes = 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
946 | while (*p >= '0' && *p <= '9') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
947 | minutes = minutes * 10 + (*p++ - '0'); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
948 | if (*p == ':') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
949 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
950 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
951 | rv = lms->tm_min - minutes; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
952 | if (rv) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
953 | return rv; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
954 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
955 | int seconds = 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
956 | while (*p >= '0' && *p <= '9') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
957 | seconds = seconds * 10 + (*p++ - '0'); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
958 | if (*p == ':') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
959 | p++; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
960 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
961 | rv = lms->tm_sec - seconds; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
962 | if (rv) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
963 | return rv; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
964 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
965 | return 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
966 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
967 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
968 | NSAPI_PUBLIC int util_later_than(const struct tm *lms, const char *ims) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
969 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
970 | /* |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
971 | * Returns 0 if lms later than ims |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
972 | * 0 if ims is malformed |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
973 | * 1 if ims later than lms |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
974 | * 1 if equal |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
975 | */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
976 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
977 | return _time_compare(lms, ims) <= 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
978 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
979 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
980 | NSAPI_PUBLIC int util_time_equal(const struct tm *lms, const char *ims) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
981 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
982 | return _time_compare(lms, ims) == 0; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
983 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
984 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
985 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
986 | NSAPI_PUBLIC struct tm * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
987 | util_gmtime(const time_t *clock, struct tm *res) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
988 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
989 | return gmtime_r(clock, res); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
990 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
99
diff
changeset
|
991 | |
104
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
992 | int util_isdate(char *str) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
993 | sstr_t datestr = sstr(str); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
994 | sstr_t example = S("Sun, 06 Nov 1994 08:49:37 GMT"); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
995 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
996 | if(datestr.length != example.length) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
997 | return 0; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
998 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
999 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1000 | for(int i=0;i<datestr.length;i++) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1001 | char e = example.ptr[i]; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1002 | if(isdigit(e)) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1003 | if(!isdigit(datestr.ptr[i])) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1004 | return 0; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1005 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1006 | } else if(e == ' ') { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1007 | if(datestr.ptr[i] != ' ') { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1008 | return 0; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1009 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1010 | } else if(e == ',') { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1011 | if(datestr.ptr[i] != ',') { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1012 | return 0; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1013 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1014 | } else if(e == ':') { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1015 | if(datestr.ptr[i] != ':') { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1016 | return 0; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1017 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1018 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1019 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1020 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1021 | if(!sstrsuffix(datestr, S("GMT"))) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1022 | return 0; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1023 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1024 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1025 | return 1; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1026 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1027 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1028 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1029 | /* ------------------------- util_mime_separator -------------------------- */ |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1030 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1031 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1032 | NSAPI_PUBLIC int util_mime_separator(char *sep) |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1033 | { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1034 | int size = 35; // documented in nsapi.h |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1035 | int pos = 0; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1036 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1037 | sep[pos++] = CR; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1038 | sep[pos++] = LF; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1039 | sep[pos++] = '-'; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1040 | sep[pos++] = '-'; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1041 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1042 | int r[6]; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1043 | for(int i=0;i<6;i++) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1044 | r[i] = rand() % 10000; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1045 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1046 | pos += snprintf( |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1047 | sep+4, |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1048 | size-4, |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1049 | "X%04x%04x%04x%04x%04x%04xE", |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1050 | r[0], |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1051 | r[1], |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1052 | r[2], |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1053 | r[3], |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1054 | r[4], |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1055 | r[5]); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1056 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1057 | return pos; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
1058 | } |
273
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1059 | |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1060 | |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1061 | /* ------------------------- util_html_escape -------------------------- */ |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1062 | |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1063 | NSAPI_PUBLIC char *util_html_escape(const char *s) |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1064 | { |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1065 | const char *in; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1066 | |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1067 | int len = 0; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1068 | for (in = s; *in; in++) { |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1069 | switch (*in) { |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1070 | case '<': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1071 | len += 4; // < |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1072 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1073 | case '>': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1074 | len += 4; // > |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1075 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1076 | case '&': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1077 | len += 5; // & |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1078 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1079 | case '"': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1080 | len += 6; // " |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1081 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1082 | case '\'': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1083 | len += 6; // ' |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1084 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1085 | case '+': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1086 | len += 5; // + |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1087 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1088 | default: |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1089 | len++; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1090 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1091 | } |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1092 | } |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1093 | |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1094 | char *ns = (char *) MALLOC(len + 1); |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1095 | if (!ns) |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1096 | return ns; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1097 | |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1098 | char *out = ns; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1099 | for (in = s; *in; in++) { |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1100 | switch (*in) { |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1101 | case '<': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1102 | *out++ = '&'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1103 | *out++ = 'l'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1104 | *out++ = 't'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1105 | *out++ = ';'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1106 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1107 | case '>': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1108 | *out++ = '&'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1109 | *out++ = 'g'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1110 | *out++ = 't'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1111 | *out++ = ';'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1112 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1113 | case '&': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1114 | *out++ = '&'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1115 | *out++ = 'a'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1116 | *out++ = 'm'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1117 | *out++ = 'p'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1118 | *out++ = ';'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1119 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1120 | case '"': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1121 | *out++ = '&'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1122 | *out++ = 'q'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1123 | *out++ = 'u'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1124 | *out++ = 'o'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1125 | *out++ = 't'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1126 | *out++ = ';'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1127 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1128 | case '\'': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1129 | *out++ = '&'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1130 | *out++ = 'a'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1131 | *out++ = 'p'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1132 | *out++ = 'o'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1133 | *out++ = 's'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1134 | *out++ = ';'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1135 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1136 | case '+': |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1137 | *out++ = '&'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1138 | *out++ = '#'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1139 | *out++ = '4'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1140 | *out++ = '3'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1141 | *out++ = ';'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1142 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1143 | default: |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1144 | *out++ = *in; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1145 | break; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1146 | } |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1147 | } |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1148 | *out = '\0'; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1149 | |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1150 | return ns; |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1151 | } |
f4eb5d125e58
add util_html_escape implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
1152 |