Sun, 17 Aug 2014 15:15:32 +0200
added ldap group support
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 | ||
62
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
62 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
63 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
64 | /* ------------------------------ _uudecode ------------------------------- */ |
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 | static const unsigned char pr2six[256] = { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
67 | 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
|
68 | 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
|
69 | 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
|
70 | 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
|
71 | 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
|
72 | 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
|
73 | 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
|
74 | 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
|
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 |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
78 | }; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
79 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
80 | /** 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
|
81 | 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
|
82 | register char *bufin = bufcoded; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
83 | register int nprbytes; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
84 | size_t nbytesdecoded; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
85 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
86 | /* Find the length */ |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
87 | nprbytes = (int) codedbytes; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
88 | while(pr2six[(int)(bufin[nprbytes-1])] >= 64) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
89 | nprbytes--; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
90 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
91 | nbytesdecoded = ((nprbytes+3)/4) * 3; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
92 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
93 | while (nprbytes > 0) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
94 | *(bufout++) = (unsigned char) |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
95 | (pr2six[(int)(*bufin)] << 2 | pr2six[(int)bufin[1]] >> 4); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
96 | *(bufout++) = (unsigned char) |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
97 | (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
|
98 | *(bufout++) = (unsigned char) |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
99 | (pr2six[(int)bufin[2]] << 6 | pr2six[(int)bufin[3]]); |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
100 | bufin += 4; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
101 | nprbytes -= 4; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
102 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
103 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
104 | if(nprbytes & 03) { |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
105 | if(pr2six[(int)bufin[-2]] > 63) |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
106 | nbytesdecoded -= 2; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
107 | else |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
108 | nbytesdecoded -= 1; |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
109 | } |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
110 | |
c47e081b6c0f
added keyfile based authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
111 | return nbytesdecoded; |
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 | |
77 | 114 | |
115 | /* --------------------------- util_env_create ---------------------------- */ | |
116 | ||
117 | ||
118 | NSAPI_PUBLIC char **util_env_create(char **env, int n, int *pos) | |
119 | { | |
120 | int x; | |
121 | ||
122 | if(!env) { | |
123 | *pos = 0; | |
124 | return (char **) MALLOC((n + 1)*sizeof(char *)); | |
125 | } | |
126 | else { | |
127 | for(x = 0; (env[x]); x++); | |
128 | env = (char **) REALLOC(env, (n + x + 1)*(sizeof(char *))); | |
129 | *pos = x; | |
130 | return env; | |
131 | } | |
132 | } | |
133 | ||
134 | ||
135 | /* ---------------------------- util_env_free ----------------------------- */ | |
136 | ||
137 | ||
138 | NSAPI_PUBLIC void util_env_free(char **env) | |
139 | { | |
140 | register char **ep = env; | |
141 | ||
142 | for(ep = env; *ep; ep++) | |
143 | FREE(*ep); | |
144 | FREE(env); | |
145 | } | |
146 | ||
147 | /* ----------------------------- util_env_str ----------------------------- */ | |
148 | ||
149 | ||
150 | NSAPI_PUBLIC char *util_env_str(const char *name, const char *value) { | |
151 | char *t; | |
152 | ||
153 | t = (char *) MALLOC(strlen(name)+strlen(value)+2); /* 2: '=' and '\0' */ | |
154 | ||
155 | sprintf(t, "%s=%s", name, value); | |
156 | ||
157 | return t; | |
158 | } | |
159 | ||
160 | ||
161 | /* --------------------------- util_env_replace --------------------------- */ | |
162 | ||
163 | ||
164 | NSAPI_PUBLIC void util_env_replace(char **env, const char *name, const char *value) | |
165 | { | |
166 | int x, y, z; | |
167 | char *i; | |
168 | ||
169 | for(x = 0; env[x]; x++) { | |
170 | i = strchr(env[x], '='); | |
171 | *i = '\0'; | |
172 | if(!strcmp(env[x], name)) { | |
173 | y = strlen(env[x]); | |
174 | z = strlen(value); | |
175 | ||
176 | env[x] = (char *) REALLOC(env[x], y + z + 2); | |
177 | util_sprintf(&env[x][y], "=%s", value); | |
178 | return; | |
179 | } | |
180 | *i = '='; | |
1 | 181 | } |
77 | 182 | } |
183 | ||
184 | ||
185 | /* ---------------------------- util_env_find ----------------------------- */ | |
186 | ||
187 | ||
188 | NSAPI_PUBLIC char *util_env_find(char **env, const char *name) | |
189 | { | |
190 | char *i; | |
191 | int x, r; | |
192 | ||
193 | for(x = 0; env[x]; x++) { | |
194 | i = strchr(env[x], '='); | |
195 | *i = '\0'; | |
196 | r = !strcmp(env[x], name); | |
197 | *i = '='; | |
198 | if(r) | |
199 | return i + 1; | |
1 | 200 | } |
77 | 201 | return NULL; |
202 | } | |
203 | ||
204 | ||
205 | /* ---------------------------- util_env_copy ----------------------------- */ | |
206 | ||
207 | ||
208 | NSAPI_PUBLIC char **util_env_copy(char **src, char **dst) | |
209 | { | |
210 | char **src_ptr; | |
211 | int src_cnt; | |
212 | int index; | |
213 | ||
214 | if (!src) | |
215 | return NULL; | |
216 | ||
217 | for (src_cnt = 0, src_ptr = src; *src_ptr; src_ptr++, src_cnt++); | |
218 | ||
219 | if (!src_cnt) | |
220 | return NULL; | |
221 | ||
222 | dst = util_env_create(dst, src_cnt, &index); | |
223 | ||
224 | for (src_ptr = src; *src_ptr; index++, src_ptr++) | |
225 | dst[index] = STRDUP(*src_ptr); | |
226 | dst[index] = NULL; | |
227 | ||
228 | return dst; | |
1 | 229 | } |
77 | 230 | |
231 | /* ----------------------------- util_sprintf ----------------------------- */ | |
232 | ||
233 | NSAPI_PUBLIC int util_vsnprintf(char *s, int n, register const char *fmt, | |
234 | va_list args) | |
235 | { | |
236 | return vsnprintf(s, n, fmt, args); | |
237 | } | |
238 | ||
239 | NSAPI_PUBLIC int util_snprintf(char *s, int n, const char *fmt, ...) | |
240 | { | |
241 | va_list args; | |
242 | va_start(args, fmt); | |
243 | return vsnprintf(s, n, fmt, args); | |
244 | } | |
245 | ||
246 | NSAPI_PUBLIC int util_vsprintf(char *s, register const char *fmt, va_list args) | |
247 | { | |
248 | return vsprintf(s, fmt, args); | |
249 | } | |
250 | ||
251 | NSAPI_PUBLIC int util_sprintf(char *s, const char *fmt, ...) | |
252 | { | |
253 | va_list args; | |
254 | va_start(args, fmt); | |
255 | return vsprintf(s, fmt, args); | |
256 | } | |
257 | ||
258 | // TODO: asprintf | |
259 | ||
1 | 260 | |
81
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
261 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
262 | /* -------------------------- util_uri_unescape --------------------------- */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
263 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
264 | NSAPI_PUBLIC void util_uri_unescape(char *s) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
265 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
266 | char *t, *u; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
267 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
268 | for(t = s, u = s; *t; ++t, ++u) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
269 | if((*t == '%') && t[1] && t[2]) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
270 | *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
|
271 | (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
|
272 | t += 2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
273 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
274 | else |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
275 | if(u != t) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
276 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
277 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
278 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
279 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
280 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
281 | /* |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
282 | * Same as util_uri_unescape, but returns success/failure |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
283 | */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
284 | NSAPI_PUBLIC int util_uri_unescape_strict(char *s) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
285 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
286 | char *t, *u, t1, t2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
287 | int rv = 1; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
288 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
289 | for(t = s, u = s; *t; ++t, ++u) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
290 | if (*t == '%') { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
291 | t1 = t[1] & 0xdf; /* [a-f] -> [A-F] */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
292 | 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
|
293 | rv = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
294 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
295 | t2 = t[2] & 0xdf; /* [a-f] -> [A-F] */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
296 | 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
|
297 | rv = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
298 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
299 | *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
|
300 | (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
|
301 | t += 2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
302 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
303 | else if (u != t) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
304 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
305 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
306 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
307 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
308 | return rv; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
309 | } |
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 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
312 | NSAPI_PUBLIC int |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
313 | 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
|
314 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
315 | const char *t = src; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
316 | char *u = trg == NULL ? (char *)src : trg; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
317 | int rlen = 0; |
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 | if (len == -1) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
320 | len = strlen (src); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
321 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
322 | for( ; len && *t; ++t, ++u, len--, rlen++) |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
323 | { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
324 | if((*t == '%') && t[1] && t[2]) |
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 | *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
|
327 | (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
|
328 | t += 2; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
329 | len-= 2; |
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 | else |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
332 | if (*t == '+') |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
333 | *u = ' '; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
334 | else |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
335 | *u = *t; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
336 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
337 | *u = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
338 | return rlen; |
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 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
341 | |
1 | 342 | NSAPI_PUBLIC int INTutil_getboolean(const char *v, int def) { |
343 | if(v[0] == 'T' || v[0] == 't') { | |
344 | return 1; | |
345 | } | |
346 | if(v[0] == 'F' || v[0] == 'f') { | |
347 | return 0; | |
348 | } | |
349 | return def; | |
350 | } | |
351 | ||
352 | ||
353 | /* ------------------------------ util_itoa ------------------------------- */ | |
354 | /* | |
355 | NSAPI_PUBLIC int util_itoa(int i, char *a) | |
356 | { | |
357 | int len = util_i64toa(i, a); | |
358 | ||
359 | PR_ASSERT(len < UTIL_ITOA_SIZE); | |
360 | ||
361 | return len; | |
362 | } | |
363 | */ | |
364 | NSAPI_PUBLIC int INTutil_itoa(int i, char *a) { | |
365 | return INTutil_i64toa(i, a); | |
366 | } | |
367 | ||
368 | ||
369 | /* ----------------------------- util_i64toa ------------------------------ */ | |
370 | ||
371 | /* | |
372 | * Assumption: Reversing the digits will be faster in the general case | |
373 | * than doing a log10 or some nasty trick to find the # of digits. | |
374 | */ | |
375 | ||
24
1a7853a4257e
removed some NSPR dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
376 | NSAPI_PUBLIC int INTutil_i64toa(int64_t i, char *a) |
1 | 377 | { |
378 | register int x, y, p; | |
379 | register char c; | |
380 | int negative; | |
381 | ||
382 | negative = 0; | |
383 | if(i < 0) { | |
384 | *a++ = '-'; | |
385 | negative = 1; | |
386 | i = -i; | |
387 | } | |
388 | p = 0; | |
389 | while(i > 9) { | |
390 | a[p++] = (i%10) + '0'; | |
391 | i /= 10; | |
392 | } | |
393 | a[p++] = i + '0'; | |
394 | ||
395 | if(p > 1) { | |
396 | for(x = 0, y = p - 1; x < y; ++x, --y) { | |
397 | c = a[x]; | |
398 | a[x] = a[y]; | |
399 | a[y] = c; | |
400 | } | |
401 | } | |
402 | a[p] = '\0'; | |
403 | ||
404 | //PR_ASSERT(p + negative < UTIL_I64TOA_SIZE); | |
405 | ||
406 | return p + negative; | |
407 | } | |
47
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
408 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
409 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
410 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
411 | #ifndef XP_WIN32 |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
412 | NSAPI_PUBLIC struct passwd * |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
413 | 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
|
414 | int buflen) |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
415 | { |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
416 | struct passwd *rv; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
417 | |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
418 | #if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(OSX) |
47
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
419 | errno = getpwnam_r(name, result, buffer, buflen, &rv); |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
420 | if (errno != 0) |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
421 | rv = NULL; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
422 | #else |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
423 | rv = getpwnam_r(name, result, buffer, buflen); |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
424 | #endif |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
425 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
426 | return rv; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
427 | } |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
428 | #endif |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
429 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
430 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
431 | #ifndef XP_WIN32 |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
432 | NSAPI_PUBLIC struct passwd * |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
433 | 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
|
434 | { |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
435 | struct passwd *rv; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
436 | |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
437 | #if defined(AIX) || defined(LINUX) || defined(HPUX) || defined(OSX) |
47
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
438 | errno = getpwuid_r(uid, result, buffer, buflen, &rv); |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
439 | if (errno != 0) |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
440 | rv = NULL; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
441 | #else |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
442 | rv = getpwuid_r(uid, result, buffer, buflen); |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
443 | #endif |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
444 | |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
445 | return rv; |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
446 | } |
ce9790523346
server can change uid
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
447 | #endif |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
448 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
449 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
450 | 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
|
451 | switch(errno_value) { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
452 | case 0: { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
453 | return 200; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
454 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
455 | case EACCES: { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
456 | return 403; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
457 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
458 | case ENOENT: { |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
459 | return 404; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
460 | break; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
461 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
462 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
463 | return 500; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
47
diff
changeset
|
464 | } |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
465 | |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
466 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
467 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
468 | NSAPI_PUBLIC |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
469 | 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
|
470 | sstr_t parent = sstr(path); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
471 | sstr_t child = sstr(ch); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
472 | sstr_t newstr; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
473 | sstr_t s; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
474 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
475 | s.length = 0; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
476 | s.ptr = NULL; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
477 | newstr.length = parent.length + child.length; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
478 | if(parent.ptr[parent.length - 1] != '/') { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
479 | s = sstrn("/", 1); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
480 | newstr.length++; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
481 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
482 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
483 | newstr.ptr = pool_malloc(pool, newstr.length + 1); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
484 | if(!newstr.ptr) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
485 | // TODO: error |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
486 | newstr.length = 0; |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
487 | return newstr; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
488 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
489 | if(s.length == 1) { |
91 | 490 | newstr = sstrncat(newstr, 3, parent, s, child); |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
491 | } else { |
91 | 492 | newstr = sstrncat(newstr, 2, parent, child); |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
493 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
494 | newstr.ptr[newstr.length] = '\0'; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
495 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
496 | return newstr; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
497 | } |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
498 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
499 | 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
|
500 | int i; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
501 | 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
|
502 | char c = path.ptr[i]; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
503 | if(c == '/') { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
504 | path.ptr[i] = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
505 | path.length = i; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
506 | break; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
507 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
508 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
509 | if(i < 0) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
510 | path.ptr = NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
511 | path.length = 0; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
512 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
513 | return path; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
62
diff
changeset
|
514 | } |
81
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
515 | |
96
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
516 | 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
|
517 | // concat path |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
518 | sstr_t translated_path; |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
519 | translated_path.length = root.length + path.length; |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
520 | translated_path.ptr = alloca(translated_path.length); |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
521 | |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
522 | translated_path = sstrncat(translated_path, 2, root, path); |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
523 | |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
524 | // add path to specified pblock |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
525 | pblock_kvinsert( |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
526 | pb_key_ppath, |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
527 | translated_path.ptr, |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
528 | translated_path.length, |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
529 | vars); |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
530 | } |
0185b13bf41f
added document-root and pfx2dir nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
91
diff
changeset
|
531 | |
81
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
532 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
533 | // new - code in parts from params.cpp |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
534 | 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
|
535 | pblock *pb = pblock_create_pool(pool, 32); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
536 | if(!pb) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
537 | return NULL; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
538 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
539 | if(!query || !(*query)) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
540 | return pb; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
541 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
542 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
543 | int loopFlag = 1; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
544 | int nl = 0; // size of the name substring |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
545 | int vl = 0; // size of the value substring |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
546 | int state = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
547 | const char *np = query; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
548 | const char *vp = NULL; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
549 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
550 | while (loopFlag) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
551 | char delim = *query++; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
552 | switch (delim) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
553 | case '&': |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
554 | case '\0': { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
555 | if(!delim) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
556 | loopFlag = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
557 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
558 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
559 | state = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
560 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
561 | if(nl > 0) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
562 | util_uri_unescape_plus(np, NULL, nl); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
563 | util_uri_unescape_plus(vp, NULL, vl); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
564 | pblock_nvlinsert(np, nl, vp, vl, pb); |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
565 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
566 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
567 | nl = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
568 | vl = 0; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
569 | vp = NULL; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
570 | np = query; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
571 | break; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
572 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
573 | case '=': { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
574 | state = 1; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
575 | vp = query; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
576 | break; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
577 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
578 | default: { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
579 | if(state) { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
580 | vl++; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
581 | } else { |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
582 | nl++; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
583 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
584 | } |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
585 | } /* switch */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
586 | } /* while */ |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
587 | |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
588 | return pb; |
d25825f37967
preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
589 | } |
91 | 590 | |
591 | // TODO: remove | |
592 | sstr_t sstrdup_mp(UcxMempool *pool, sstr_t s) { | |
593 | sstr_t newstring; | |
594 | newstring.ptr = (char*)ucx_mempool_malloc(pool, s.length + 1); | |
595 | if (newstring.ptr != NULL) { | |
596 | newstring.length = s.length; | |
597 | newstring.ptr[newstring.length] = 0; | |
598 | ||
599 | memcpy(newstring.ptr, s.ptr, s.length); | |
600 | } | |
601 | ||
602 | return newstring; | |
603 | } |