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 #ifndef BASE_UTIL_H |
|
35 #define BASE_UTIL_H |
|
36 |
|
37 #include "netsite.h" |
|
38 |
|
39 #ifndef NOINTNSAPI |
|
40 #define INTNSAPI |
|
41 #endif /* !NOINTNSAPI */ |
|
42 |
|
43 /* |
|
44 * util.h: A hodge podge of utility functions and standard functions which |
|
45 * are unavailable on certain systems |
|
46 * |
|
47 * Rob McCool |
|
48 */ |
|
49 |
|
50 /* Needed for various reentrant functions */ |
|
51 #define DEF_CTIMEBUF 26 |
|
52 #define DEF_ERRBUF 256 |
|
53 #define DEF_PWBUF 1024 |
|
54 |
|
55 #ifndef BASE_BUFFER_H |
|
56 //include "buffer.h" /* filebuf for getline */ |
|
57 #endif /* !BASE_BUFFER_H */ |
|
58 |
|
59 /* |
|
60 * UTIL_ITOA_SIZE is the minimum size for buffers passed to util_itoa(). |
|
61 */ |
|
62 #define UTIL_ITOA_SIZE 12 |
|
63 |
|
64 /* |
|
65 * UTIL_I64TOA_SIZE is the minimum size for buffers passed to util_i64toa(). |
|
66 */ |
|
67 #define UTIL_I64TOA_SIZE 21 |
|
68 |
|
69 /* --- Begin common function prototypes --- */ |
|
70 |
|
71 #ifdef INTNSAPI |
|
72 |
|
73 NSPR_BEGIN_EXTERN_C |
|
74 |
|
75 NSAPI_PUBLIC |
|
76 int INTutil_init_PRNetAddr(PRNetAddr * naddr, char * ipstr, int iplen, int type); |
|
77 |
|
78 NSAPI_PUBLIC |
|
79 int INTutil_getline(filebuffer *buf, int lineno, int maxlen, char *l); |
|
80 |
|
81 NSAPI_PUBLIC char **INTutil_env_create(char **env, int n, int *pos); |
|
82 |
|
83 NSAPI_PUBLIC char *INTutil_env_str(const char *name, const char *value); |
|
84 |
|
85 NSAPI_PUBLIC void INTutil_env_replace(char **env, const char *name, const char *value); |
|
86 |
|
87 NSAPI_PUBLIC void INTutil_env_free(char **env); |
|
88 |
|
89 NSAPI_PUBLIC char **INTutil_env_copy(char **src, char **dst); |
|
90 |
|
91 NSAPI_PUBLIC char *INTutil_env_find(char **env, const char *name); |
|
92 |
|
93 NSAPI_PUBLIC char **util_argv_parse(const char *cmdline); |
|
94 |
|
95 NSAPI_PUBLIC char *INTutil_hostname(void); |
|
96 |
|
97 NSAPI_PUBLIC int INTutil_chdir2path(char *path); |
|
98 |
|
99 NSAPI_PUBLIC int INTutil_chdir(const char *path); |
|
100 |
|
101 NSAPI_PUBLIC char *INTutil_getcwd(void); |
|
102 |
|
103 NSAPI_PUBLIC int INTutil_is_mozilla(char *ua, char *major, char *minor); |
|
104 |
|
105 NSAPI_PUBLIC int INTutil_is_url(const char *url); |
|
106 |
|
107 NSAPI_PUBLIC int INTutil_mstr2num(const char *s); |
|
108 |
|
109 NSAPI_PUBLIC int INTutil_later_than(const struct tm *lms, const char *ims); |
|
110 |
|
111 NSAPI_PUBLIC int INTutil_time_equal(const struct tm *lms, const char *ims); |
|
112 |
|
113 NSAPI_PUBLIC int INTutil_str_time_equal(const char *t1, const char *t2); |
|
114 |
|
115 NSAPI_PUBLIC int INTutil_uri_is_evil(const char *t); |
|
116 |
|
117 NSAPI_PUBLIC int INTutil_uri_is_evil_internal(const char *t, int, int); |
|
118 |
|
119 NSAPI_PUBLIC void INTutil_uri_parse(char *uri); |
|
120 |
|
121 #ifdef XP_WIN32 |
|
122 NSAPI_PUBLIC int INTutil_uri_unescape_and_normalize(pool_handle_t *pool, char *s, char *unnormalized); |
|
123 #endif /* XP_WIN32 */ |
|
124 |
|
125 NSAPI_PUBLIC void INTutil_uri_normalize_slashes(char *s); |
|
126 |
|
127 NSAPI_PUBLIC void INTutil_uri_unescape (char *s); |
|
128 |
|
129 NSAPI_PUBLIC int INTutil_uri_unescape_strict (char *s); |
|
130 |
|
131 NSAPI_PUBLIC int INTutil_uri_unescape_plus (const char *src, char *trg, int len); |
|
132 |
|
133 NSAPI_PUBLIC char *INTutil_uri_escape(char *d, const char *s); |
|
134 |
|
135 NSAPI_PUBLIC char *INTutil_uri_strip_params(char *uri); |
|
136 |
|
137 NSAPI_PUBLIC char* util_canonicalize_uri(pool_handle_t *pool, const char *uri, int len, int *pcanonlen); |
|
138 |
|
139 NSAPI_PUBLIC char* util_canonicalize_redirect(pool_handle_t *pool, const char *baseUri, const char *newUri); |
|
140 |
|
141 NSAPI_PUBLIC char *INTutil_url_escape(char *d, const char *s); |
|
142 |
|
143 NSAPI_PUBLIC char *INTutil_sh_escape(char *s); |
|
144 |
|
145 NSAPI_PUBLIC int INTutil_mime_separator(char *sep); |
|
146 |
|
147 NSAPI_PUBLIC int INTutil_itoa(int i, char *a); |
|
148 |
|
149 NSAPI_PUBLIC int INTutil_i64toa(PRInt64 i, char *a); |
|
150 |
|
151 |
|
152 NSAPI_PUBLIC |
|
153 int INTutil_vsprintf(char *s, register const char *fmt, va_list args); |
|
154 |
|
155 NSAPI_PUBLIC int INTutil_sprintf(char *s, const char *fmt, ...); |
|
156 |
|
157 NSAPI_PUBLIC int INTutil_vsnprintf(char *s, int n, register const char *fmt, |
|
158 va_list args); |
|
159 |
|
160 NSAPI_PUBLIC int INTutil_snprintf(char *s, int n, const char *fmt, ...); |
|
161 |
|
162 NSAPI_PUBLIC int util_strlftime(char *dst, size_t dstsize, const char *format, const struct tm *t); |
|
163 |
|
164 NSAPI_PUBLIC int INTutil_strftime(char *s, const char *format, const struct tm *t); |
|
165 |
|
166 NSAPI_PUBLIC char *INTutil_strtok(char *s1, const char *s2, char **lasts); |
|
167 |
|
168 NSAPI_PUBLIC struct tm *INTutil_localtime(const time_t *clock, struct tm *res); |
|
169 |
|
170 NSAPI_PUBLIC char *INTutil_ctime(const time_t *clock, char *buf, int buflen); |
|
171 |
|
172 NSAPI_PUBLIC char *INTutil_strerror(int errnum, char *msg, int buflen); |
|
173 |
|
174 NSAPI_PUBLIC struct tm *INTutil_gmtime(const time_t *clock, struct tm *res); |
|
175 |
|
176 NSAPI_PUBLIC char *INTutil_asctime(const struct tm *tm,char *buf, int buflen); |
|
177 |
|
178 NSAPI_PUBLIC char *INTutil_cookie_find(char *cookie, const char *name); |
|
179 |
|
180 NSAPI_PUBLIC char *INTutil_cookie_next(char *cookie, char **name, char **value); |
|
181 |
|
182 NSAPI_PUBLIC char *INTutil_cookie_next_av_pair(char *cookie, char **name, char **value); |
|
183 |
|
184 NSAPI_PUBLIC void INTutil_random(void *buf, size_t sz); |
|
185 |
|
186 NSAPI_PUBLIC PRBool INTutil_format_http_version(const char *v, int *protv_num, char *buffer, int size); |
|
187 |
|
188 NSAPI_PUBLIC int INTutil_getboolean(const char *v, int def); |
|
189 NSAPI_PUBLIC PRIntervalTime INTutil_getinterval(const char *v, PRIntervalTime def); |
|
190 |
|
191 #ifdef NEED_STRCASECMP |
|
192 NSAPI_PUBLIC int INTutil_strcasecmp(const char *one, const char *two); |
|
193 #endif /* NEED_STRCASECMP */ |
|
194 |
|
195 #ifdef NEED_STRNCASECMP |
|
196 NSAPI_PUBLIC int INTutil_strncasecmp(const char *one, const char *two, int n); |
|
197 #endif /* NEED_STRNCASECMP */ |
|
198 |
|
199 NSAPI_PUBLIC char *INTutil_strcasestr(char *str, const char *substr); |
|
200 |
|
201 NSAPI_PUBLIC size_t util_strlcpy(char *dst, const char *src, size_t dstsize); |
|
202 |
|
203 NSAPI_PUBLIC size_t util_strlcat(char *dst, const char *src, size_t dstsize); |
|
204 |
|
205 NSAPI_PUBLIC char *INTutil_uuencode(const char *src, int len); |
|
206 |
|
207 NSAPI_PUBLIC char *INTutil_uudecode(const char *src); |
|
208 |
|
209 NSAPI_PUBLIC char *util_strlower(char *s); |
|
210 |
|
211 NSAPI_PUBLIC char *util_decrement_string(char *s); |
|
212 |
|
213 NSAPI_PUBLIC PRInt64 util_atoi64(const char *a); |
|
214 |
|
215 NSAPI_PUBLIC char *util_html_escape(const char *s); |
|
216 |
|
217 NSAPI_PUBLIC int util_qtoi(const char *q, const char **p); |
|
218 |
|
219 /* --- End common function prototypes --- */ |
|
220 |
|
221 /* --- Begin Unix-only function prototypes --- */ |
|
222 |
|
223 #ifdef XP_UNIX |
|
224 |
|
225 NSAPI_PUBLIC int INTutil_can_exec(struct stat *finfo, uid_t uid, gid_t gid); |
|
226 |
|
227 NSAPI_PUBLIC |
|
228 struct passwd *INTutil_getpwnam(const char *name, struct passwd *result, |
|
229 char *buffer, int buflen); |
|
230 |
|
231 NSAPI_PUBLIC |
|
232 struct passwd *INTutil_getpwuid(uid_t uid, struct passwd *result, |
|
233 char *buffer, int buflen); |
|
234 |
|
235 NSAPI_PUBLIC pid_t INTutil_waitpid(pid_t pid, int *statptr, int options); |
|
236 |
|
237 #endif /* XP_UNIX */ |
|
238 |
|
239 /* --- End Unix-only function prototypes --- */ |
|
240 |
|
241 /* --- Begin Windows-only function prototypes --- */ |
|
242 |
|
243 #ifdef XP_WIN32 |
|
244 |
|
245 NSAPI_PUBLIC |
|
246 VOID INTutil_delete_directory(char *FileName, BOOL delete_directory); |
|
247 |
|
248 #endif /* XP_WIN32 */ |
|
249 |
|
250 /* --- End Windows-only function prototypes --- */ |
|
251 |
|
252 NSPR_END_EXTERN_C |
|
253 |
|
254 #ifdef __cplusplus |
|
255 |
|
256 NSAPI_PUBLIC char *util_host_port_suffix(char *h); |
|
257 |
|
258 NSAPI_PUBLIC const char *util_host_port_suffix(const char *h); |
|
259 |
|
260 #endif |
|
261 |
|
262 #define util_init_PRNetAddr INTutil_init_PRNetAddr |
|
263 #define util_getline INTutil_getline |
|
264 #define util_env_create INTutil_env_create |
|
265 #define util_env_str INTutil_env_str |
|
266 #define util_env_replace INTutil_env_replace |
|
267 #define util_env_free INTutil_env_free |
|
268 #define util_env_copy INTutil_env_copy |
|
269 #define util_env_find INTutil_env_find |
|
270 #define util_hostname INTutil_hostname |
|
271 #define util_chdir2path INTutil_chdir2path |
|
272 #define util_chdir INTutil_chdir |
|
273 #define util_getcwd INTutil_getcwd |
|
274 #define util_is_mozilla INTutil_is_mozilla |
|
275 #define util_is_url INTutil_is_url |
|
276 #define util_mstr2num INTutil_mstr2num |
|
277 #define util_later_than INTutil_later_than |
|
278 #define util_time_equal INTutil_time_equal |
|
279 #define util_str_time_equal INTutil_str_time_equal |
|
280 #define util_uri_is_evil INTutil_uri_is_evil |
|
281 #define util_uri_is_evil_internal INTutil_uri_is_evil_internal |
|
282 #define util_uri_parse INTutil_uri_parse |
|
283 #ifdef XP_WIN32 |
|
284 #define util_uri_unescape_and_normalize INTutil_uri_unescape_and_normalize |
|
285 #endif /* XP_WIN32 */ |
|
286 #define util_uri_normalize_slashes INTutil_uri_normalize_slashes |
|
287 #define util_uri_unescape INTutil_uri_unescape |
|
288 #define util_uri_unescape_strict INTutil_uri_unescape_strict |
|
289 #define util_uri_unescape_plus INTutil_uri_unescape_plus |
|
290 |
|
291 #define util_uri_escape INTutil_uri_escape |
|
292 #define util_uri_strip_params INTutil_uri_strip_params |
|
293 #define util_url_escape INTutil_url_escape |
|
294 #define util_sh_escape INTutil_sh_escape |
|
295 #define util_mime_separator INTutil_mime_separator |
|
296 #define util_itoa INTutil_itoa |
|
297 #define util_i64toa INTutil_i64toa |
|
298 #define util_vsprintf INTutil_vsprintf |
|
299 #define util_sprintf INTutil_sprintf |
|
300 #define util_vsnprintf INTutil_vsnprintf |
|
301 #define util_snprintf INTutil_snprintf |
|
302 #define util_strftime INTutil_strftime |
|
303 #define util_strcasecmp INTutil_strcasecmp |
|
304 #define util_strncasecmp INTutil_strncasecmp |
|
305 #define util_strcasestr INTutil_strcasestr |
|
306 #define util_strtok INTutil_strtok |
|
307 #define util_localtime INTutil_localtime |
|
308 #define util_ctime INTutil_ctime |
|
309 #define util_strerror INTutil_strerror |
|
310 #define util_gmtime INTutil_gmtime |
|
311 #define util_asctime INTutil_asctime |
|
312 #define util_uuencode INTutil_uuencode |
|
313 #define util_uudecode INTutil_uudecode |
|
314 |
|
315 #ifdef XP_UNIX |
|
316 #define util_can_exec INTutil_can_exec |
|
317 #define util_getpwnam INTutil_getpwnam |
|
318 #define util_getpwuid INTutil_getpwuid |
|
319 #define util_waitpid INTutil_waitpid |
|
320 #endif /* XP_UNIX */ |
|
321 |
|
322 #ifdef XP_WIN32 |
|
323 #define util_delete_directory INTutil_delete_directory |
|
324 #endif /* XP_WIN32 */ |
|
325 |
|
326 #ifdef NEED_STRCASECMP |
|
327 #define util_strcasecmp INTutil_strcasecmp |
|
328 #define strcasecmp INTutil_strcasecmp |
|
329 #endif /* NEED_STRCASECMP */ |
|
330 |
|
331 #ifdef NEED_STRINGS_H /* usually for strcasecmp */ |
|
332 #include <strings.h> |
|
333 #endif |
|
334 |
|
335 #ifdef NEED_STRNCASECMP |
|
336 #define util_strncasecmp INTutil_strncasecmp |
|
337 #define strncasecmp INTutil_strncasecmp |
|
338 #endif /* NEED_STRNCASECMP */ |
|
339 |
|
340 #define util_cookie_find INTutil_cookie_find |
|
341 #define util_cookie_next INTutil_cookie_next |
|
342 #define util_cookie_next_av_pair INTutil_cookie_next_av_pair |
|
343 |
|
344 #define util_random INTutil_random |
|
345 #define util_format_http_version INTutil_format_http_version |
|
346 #define util_getboolean INTutil_getboolean |
|
347 #define util_getinterval INTutil_getinterval |
|
348 |
|
349 #ifdef XP_WIN32 |
|
350 void set_fullpathname(PRBool b); |
|
351 #endif /* XP_WIN32 */ |
|
352 #endif /* INTNSAPI */ |
|
353 |
|
354 #endif /* !BASE_UTIL_H */ |
|
355 |
|
356 |
|