1 const char parsers_rcs[] = "$Id: parsers.c,v 2.2 2002/11/10 04:20:38 hal9 Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/src/parsers.c,v $
6 * Purpose : Declares functions to parse/crunch headers and pages.
7 * Functions declared include:
8 * `add_to_iob', `client_cookie_adder', `client_from',
9 * `client_referrer', `client_send_cookie', `client_ua',
10 * `client_uagent', `client_x_forwarded',
11 * `client_x_forwarded_adder', `client_xtra_adder',
12 * `content_type', `crumble', `destroy_list', `enlist',
13 * `flush_socket', ``get_header', `sed',
14 * and `server_set_cookie'.
16 * Copyright : Written by and Copyright (C) 2001 the SourceForge
17 * Privoxy team. http://www.privoxy.org/
19 * Based on the Internet Junkbuster originally written
20 * by and Copyright (C) 1997 Anonymous Coders and
21 * Junkbusters Corporation. http://www.junkbusters.com
23 * This program is free software; you can redistribute it
24 * and/or modify it under the terms of the GNU General
25 * Public License as published by the Free Software
26 * Foundation; either version 2 of the License, or (at
27 * your option) any later version.
29 * This program is distributed in the hope that it will
30 * be useful, but WITHOUT ANY WARRANTY; without even the
31 * implied warranty of MERCHANTABILITY or FITNESS FOR A
32 * PARTICULAR PURPOSE. See the GNU General Public
33 * License for more details.
35 * The GNU General Public License should be included with
36 * this file. If not, you can view it at
37 * http://www.gnu.org/copyleft/gpl.html
38 * or write to the Free Software Foundation, Inc., 59
39 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43 * Revision 2.2 2002/11/10 04:20:38 hal9
44 * Fix typo: supressed -> suppressed
46 * Revision 2.1 2002/09/11 11:23:59 oes
47 * Fixed logging of cookies: Killed incoming cookies now logged; incoming/outgoing cookies now distinguished in log
49 * Revision 2.0 2002/06/04 14:34:21 jongfoster
50 * Moving source files to src/
52 * Revision 1.56 2002/05/12 15:34:22 jongfoster
53 * Fixing typo in a comment
55 * Revision 1.55 2002/05/08 16:01:07 oes
56 * Optimized add_to_iob:
57 * - Use realloc instead of malloc(), memcpy(), free()
58 * - Expand to powers of two if possible, to get
59 * O(log n) reallocs instead of O(n).
60 * - Moved check for buffer limit here from chat
61 * - Report failure via returncode
63 * Revision 1.54 2002/04/02 15:03:16 oes
66 * Revision 1.53 2002/03/26 22:29:55 swa
67 * we have a new homepage!
69 * Revision 1.52 2002/03/24 13:25:43 swa
70 * name change related issues
72 * Revision 1.51 2002/03/13 00:27:05 jongfoster
75 * Revision 1.50 2002/03/12 01:45:35 oes
76 * More verbose logging
78 * Revision 1.49 2002/03/09 20:03:52 jongfoster
79 * - Making various functions return int rather than size_t.
80 * (Undoing a recent change). Since size_t is unsigned on
81 * Windows, functions like read_socket that return -1 on
82 * error cannot return a size_t.
84 * THIS WAS A MAJOR BUG - it caused frequent, unpredictable
85 * crashes, and also frequently caused JB to jump to 100%
86 * CPU and stay there. (Because it thought it had just
87 * read ((unsigned)-1) == 4Gb of data...)
89 * - The signature of write_socket has changed, it now simply
90 * returns success=0/failure=nonzero.
92 * - Trying to get rid of a few warnings --with-debug on
93 * Windows, I've introduced a new type "jb_socket". This is
94 * used for the socket file descriptors. On Windows, this
95 * is SOCKET (a typedef for unsigned). Everywhere else, it's
96 * an int. The error value can't be -1 any more, so it's
97 * now JB_INVALID_SOCKET (which is -1 on UNIX, and in
98 * Windows it maps to the #define INVALID_SOCKET.)
100 * - The signature of bind_port has changed.
102 * Revision 1.48 2002/03/07 03:46:53 oes
103 * Fixed compiler warnings etc
105 * Revision 1.47 2002/02/20 23:15:13 jongfoster
106 * Parsing functions now handle out-of-memory gracefully by returning
109 * Revision 1.46 2002/01/17 21:03:47 jongfoster
110 * Moving all our URL and URL pattern parsing code to urlmatch.c.
112 * Revision 1.45 2002/01/09 14:33:03 oes
113 * Added support for localtime_r.
115 * Revision 1.44 2001/12/14 01:22:54 steudten
116 * Remove 'user:pass@' from 'proto://user:pass@host' for the
117 * new added header 'Host: ..'. (See Req ID 491818)
119 * Revision 1.43 2001/11/23 00:26:38 jongfoster
120 * Fixing two really stupid errors in my previous commit
122 * Revision 1.42 2001/11/22 21:59:30 jongfoster
123 * Adding code to handle +no-cookies-keep
125 * Revision 1.41 2001/11/05 23:43:05 steudten
126 * Add time+date to log files.
128 * Revision 1.40 2001/10/26 20:13:09 jongfoster
129 * ctype.h is needed in Windows, too.
131 * Revision 1.39 2001/10/26 17:40:04 oes
132 * Introduced get_header_value()
133 * Removed http->user_agent, csp->referrer and csp->accept_types
134 * Removed client_accept()
136 * Revision 1.38 2001/10/25 03:40:48 david__schmidt
137 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
138 * threads to call select() simultaneously. So, it's time to do a real, live,
139 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
140 * (native). Both versions will work, but using __OS2__ offers multi-threading.
142 * Revision 1.37 2001/10/23 21:36:02 jongfoster
143 * Documenting sed()'s error behaviou (doc change only)
145 * Revision 1.36 2001/10/13 12:51:51 joergs
146 * Removed client_host, (was only required for the old 2.0.2-11 http://noijb.
147 * force-load), instead crumble Host: and add it (again) in client_host_adder
148 * (in case we get a HTTP/1.0 request without Host: header and forward it to
149 * a HTTP/1.1 server/proxy).
151 * Revision 1.35 2001/10/09 22:39:21 jongfoster
152 * assert.h is also required under Win32, so moving out of #ifndef _WIN32
155 * Revision 1.34 2001/10/07 18:50:55 oes
156 * Added server_content_encoding, renamed server_transfer_encoding
158 * Revision 1.33 2001/10/07 18:04:49 oes
159 * Changed server_http11 to server_http and its pattern to "HTTP".
160 * Additional functionality: it now saves the HTTP status into
161 * csp->http->status and sets CT_TABOO for Status 206 (partial range)
163 * Revision 1.32 2001/10/07 15:43:28 oes
164 * Removed FEATURE_DENY_GZIP and replaced it with client_accept_encoding,
165 * client_te and client_accept_encoding_adder, triggered by the new
166 * +no-compression action. For HTTP/1.1 the Accept-Encoding header is
167 * changed to allow only identity and chunked, and the TE header is
168 * crunched. For HTTP/1.0, Accept-Encoding is crunched.
170 * parse_http_request no longer does anything than parsing. The rewriting
171 * of http->cmd and version mangling are gone. It now also recognizes
172 * the put and delete methods and saves the url in http->url. Removed
175 * renamed content_type and content_length to have the server_ prefix
177 * server_content_type now only works if csp->content_type != CT_TABOO
179 * added server_transfer_encoding, which
180 * - Sets CT_TABOO to prohibit filtering if encoding compresses
181 * - Raises the CSP_FLAG_CHUNKED flag if Encoding is "chunked"
182 * - Change from "chunked" to "identity" if body was chunked
183 * but has been de-chunked for filtering.
185 * added server_content_md5 which crunches any Content-MD5 headers
186 * if the body was modified.
188 * made server_http11 conditional on +downgrade action
190 * Replaced 6 boolean members of csp with one bitmap (csp->flags)
192 * Revision 1.31 2001/10/05 14:25:02 oes
193 * Crumble Keep-Alive from Server
195 * Revision 1.30 2001/09/29 12:56:03 joergs
196 * IJB now changes HTTP/1.1 to HTTP/1.0 in requests and answers.
198 * Revision 1.29 2001/09/24 21:09:24 jongfoster
199 * Fixing 2 memory leaks that Guy spotted, where the paramater to
200 * enlist() was not being free()d.
202 * Revision 1.28 2001/09/22 16:32:28 jongfoster
203 * Removing unused #includes.
205 * Revision 1.27 2001/09/20 15:45:25 steudten
207 * add casting from size_t to int for printf()
208 * remove local variable shadow s2
210 * Revision 1.26 2001/09/16 17:05:14 jongfoster
211 * Removing unused #include showarg.h
213 * Revision 1.25 2001/09/16 13:21:27 jongfoster
214 * Changes to use new list functions.
216 * Revision 1.24 2001/09/13 23:05:50 jongfoster
217 * Changing the string paramater to the header parsers a "const".
219 * Revision 1.23 2001/09/12 18:08:19 steudten
221 * In parse_http_request() header rewriting miss the host value, so
222 * from http://www.mydomain.com the result was just " / " not
223 * http://www.mydomain.com/ in case we forward.
225 * Revision 1.22 2001/09/10 10:58:53 oes
226 * Silenced compiler warnings
228 * Revision 1.21 2001/07/31 14:46:00 oes
229 * - Persistant connections now suppressed
230 * - sed() no longer appends empty header to csp->headers
232 * Revision 1.20 2001/07/30 22:08:36 jongfoster
233 * Tidying up #defines:
234 * - All feature #defines are now of the form FEATURE_xxx
235 * - Permanently turned off WIN_GUI_EDIT
236 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
238 * Revision 1.19 2001/07/25 17:21:54 oes
239 * client_uagent now saves copy of User-Agent: header value
241 * Revision 1.18 2001/07/13 14:02:46 oes
242 * - Included fix to repair broken HTTP requests that
243 * don't contain a path, not even '/'.
244 * - Removed all #ifdef PCRS
245 * - content_type now always inspected and classified as
246 * text, gif or other.
247 * - formatting / comments
249 * Revision 1.17 2001/06/29 21:45:41 oes
250 * Indentation, CRLF->LF, Tab-> Space
252 * Revision 1.16 2001/06/29 13:32:42 oes
254 * - Adapted free_http_request
255 * - Removed logentry from cancelled commit
257 * Revision 1.15 2001/06/03 19:12:38 oes
258 * deleted const struct interceptors
260 * Revision 1.14 2001/06/01 18:49:17 jongfoster
261 * Replaced "list_share" with "list" - the tiny memory gain was not
262 * worth the extra complexity.
264 * Revision 1.13 2001/05/31 21:30:33 jongfoster
265 * Removed list code - it's now in list.[ch]
266 * Renamed "permission" to "action", and changed many features
267 * to use the actions file rather than the global config.
269 * Revision 1.12 2001/05/31 17:33:13 oes
273 * Revision 1.11 2001/05/29 20:11:19 joergs
274 * '/ * inside comment' warning removed.
276 * Revision 1.10 2001/05/29 09:50:24 jongfoster
277 * Unified blocklist/imagelist/permissionslist.
278 * File format is still under discussion, but the internal changes
281 * Also modified interceptor behaviour:
282 * - We now intercept all URLs beginning with one of the following
283 * prefixes (and *only* these prefixes):
285 * * http://ijbswa.sf.net/config/
286 * * http://ijbswa.sourceforge.net/config/
287 * - New interceptors "home page" - go to http://i.j.b/ to see it.
288 * - Internal changes so that intercepted and fast redirect pages
289 * are not replaced with an image.
290 * - Interceptors now have the option to send a binary page direct
291 * to the client. (i.e. ijb-send-banner uses this)
292 * - Implemented show-url-info interceptor. (Which is why I needed
293 * the above interceptors changes - a typical URL is
294 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
295 * The previous mechanism would not have intercepted that, and
296 * if it had been intercepted then it then it would have replaced
299 * Revision 1.9 2001/05/28 17:26:33 jongfoster
300 * Fixing segfault if last header was crunched.
301 * Fixing Windows build (snprintf() is _snprintf() under Win32, but we
302 * can use the cross-platform sprintf() instead.)
304 * Revision 1.8 2001/05/27 22:17:04 oes
306 * - re_process_buffer no longer writes the modified buffer
307 * to the client, which was very ugly. It now returns the
308 * buffer, which it is then written by chat.
310 * - content_length now adjusts the Content-Length: header
311 * for modified documents rather than crunch()ing it.
312 * (Length info in csp->content_length, which is 0 for
313 * unmodified documents)
315 * - For this to work, sed() is called twice when filtering.
317 * Revision 1.7 2001/05/27 13:19:06 oes
318 * Patched Joergs solution for the content-length in.
320 * Revision 1.6 2001/05/26 13:39:32 jongfoster
321 * Only crunches Content-Length header if applying RE filtering.
322 * Without this fix, Microsoft Windows Update wouldn't work.
324 * Revision 1.5 2001/05/26 00:28:36 jongfoster
325 * Automatic reloading of config file.
326 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
327 * Most of the global variables have been moved to a new
328 * struct configuration_spec, accessed through csp->config->globalname
329 * Most of the globals remaining are used by the Win32 GUI.
331 * Revision 1.4 2001/05/22 18:46:04 oes
333 * - Enabled filtering banners by size rather than URL
334 * by adding patterns that replace all standard banner
335 * sizes with the "Junkbuster" gif to the re_filterfile
337 * - Enabled filtering WebBugs by providing a pattern
338 * which kills all 1x1 images
340 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
341 * which is selected by the (nonstandard and therefore
342 * capital) letter 'U' in the option string.
343 * It causes the quantifiers to be ungreedy by default.
344 * Appending a ? turns back to greedy (!).
346 * - Added a new interceptor ijb-send-banner, which
347 * sends back the "Junkbuster" gif. Without imagelist or
348 * MSIE detection support, or if tinygif = 1, or the
349 * URL isn't recognized as an imageurl, a lame HTML
350 * explanation is sent instead.
352 * - Added new feature, which permits blocking remote
353 * script redirects and firing back a local redirect
355 * The feature is conditionally compiled, i.e. it
356 * can be disabled with --disable-fast-redirects,
357 * plus it must be activated by a "fast-redirects"
358 * line in the config file, has its own log level
359 * and of course wants to be displayed by show-proxy-args
360 * Note: Boy, all the #ifdefs in 1001 locations and
361 * all the fumbling with configure.in and acconfig.h
362 * were *way* more work than the feature itself :-(
364 * - Because a generic redirect template was needed for
365 * this, tinygif = 3 now uses the same.
367 * - Moved GIFs, and other static HTTP response templates
372 * - Removed some >400 CRs again (Jon, you really worked
375 * Revision 1.3 2001/05/20 01:21:20 jongfoster
376 * Version 2.9.4 checkin.
377 * - Merged popupfile and cookiefile, and added control over PCRS
378 * filtering, in new "permissionsfile".
379 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
380 * file error you now get a message box (in the Win32 GUI) rather
381 * than the program exiting with no explanation.
382 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
384 * - Removed tabs from "config"
385 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
386 * - Bumped up version number.
388 * Revision 1.2 2001/05/17 23:02:36 oes
389 * - Made referrer option accept 'L' as a substitute for '§'
391 * Revision 1.1.1.1 2001/05/15 13:59:01 oes
392 * Initial import of version 2.9.3 source tree
395 *********************************************************************/
402 #include <sys/types.h>
410 #if !defined(_WIN32) && !defined(__OS2__)
420 #include "jbsockets.h"
421 #include "miscutil.h"
423 #ifdef FEATURE_ACTIVITY_CONSOLE
425 #endif /* def FEATURE_ACTIVITY_CONSOLE */
427 const char parsers_h_rcs[] = PARSERS_H_VERSION;
429 /* Fix a problem with Solaris. There should be no effect on other
431 * Solaris's isspace() is a macro which uses it's argument directly
432 * as an array index. Therefore we need to make sure that high-bit
433 * characters generate +ve values, and ideally we also want to make
434 * the argument match the declared parameter type of "int".
436 * Why did they write a character function that can't take a simple
437 * "char" argument? Doh!
439 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
440 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
443 const struct parsers client_patterns[] = {
444 { "referer:", 8, client_referrer },
445 { "user-agent:", 11, client_uagent },
446 { "ua-", 3, client_ua },
447 { "from:", 5, client_from },
448 { "cookie:", 7, client_send_cookie },
449 { "x-forwarded-for:", 16, client_x_forwarded },
450 { "Accept-Encoding:", 16, client_accept_encoding },
451 { "TE:", 3, client_te },
452 { "Host:", 5, crumble },
453 /* { "if-modified-since:", 18, crumble }, */
454 { "Keep-Alive:", 11, crumble },
455 { "connection:", 11, crumble },
456 { "proxy-connection:", 17, crumble },
461 const struct parsers server_patterns[] = {
462 { "HTTP", 4, server_http },
463 { "set-cookie:", 11, server_set_cookie },
464 { "connection:", 11, crumble },
465 { "Content-Type:", 13, server_content_type },
466 { "Content-Length:", 15, server_content_length },
467 { "Content-MD5:", 12, server_content_md5 },
468 { "Content-Encoding:", 17, server_content_encoding },
469 { "Transfer-Encoding:", 18, server_transfer_coding },
470 { "Keep-Alive:", 11, crumble },
475 const add_header_func_ptr add_client_headers[] = {
478 client_x_forwarded_adder,
480 client_accept_encoding_adder,
481 connection_close_adder,
486 const add_header_func_ptr add_server_headers[] = {
487 connection_close_adder,
492 /*********************************************************************
494 * Function : flush_socket
496 * Description : Write any pending "buffered" content.
499 * 1 : fd = file descriptor of the socket to read
500 * 2 : csp = Current client state (buffers, headers, etc...)
502 * Returns : On success, the number of bytes written are returned (zero
503 * indicates nothing was written). On error, -1 is returned,
504 * and errno is set appropriately. If count is zero and the
505 * file descriptor refers to a regular file, 0 will be
506 * returned without causing any other effect. For a special
507 * file, the results are not portable.
509 *********************************************************************/
510 int flush_socket(jb_socket fd, struct client_state *csp)
512 struct iob *iob = csp->iob;
513 int len = iob->eod - iob->cur;
520 if (write_socket(fd, iob->cur, (size_t)len))
524 iob->eod = iob->cur = iob->buf;
530 /*********************************************************************
532 * Function : add_to_iob
534 * Description : Add content to the buffered page, expanding the
535 * buffer if necessary.
538 * 1 : csp = Current client state (buffers, headers, etc...)
539 * 2 : buf = holds the content to be added to the page
540 * 3 : n = number of bytes to be added
542 * Returns : JB_ERR_OK on success, JB_ERR_MEMORY if out-of-memory
543 * or buffer limit reached.
545 *********************************************************************/
546 jb_err add_to_iob(struct client_state *csp, char *buf, int n)
548 struct iob *iob = csp->iob;
549 size_t used, offset, need, want;
552 if (n <= 0) return JB_ERR_OK;
554 used = iob->eod - iob->buf;
555 offset = iob->cur - iob->buf;
559 * If the buffer can't hold the new data, extend it first.
560 * Use the next power of two if possible, else use the actual need.
562 if (need > csp->config->buffer_limit)
564 log_error(LOG_LEVEL_ERROR, "Buffer limit reached while extending the buffer (iob)");
565 return JB_ERR_MEMORY;
568 if (need > iob->size)
570 for (want = csp->iob->size ? csp->iob->size : 512; want <= need;) want *= 2;
572 if (want <= csp->config->buffer_limit && NULL != (p = (char *)realloc(iob->buf, want)))
576 else if (NULL != (p = (char *)realloc(iob->buf, need)))
582 log_error(LOG_LEVEL_ERROR, "Extending the buffer (iob) failed: %E");
583 return JB_ERR_MEMORY;
586 /* Update the iob pointers */
587 iob->cur = p + offset;
592 /* copy the new data into the iob buffer */
593 memcpy(iob->eod, buf, (size_t)n);
595 /* point to the end of the data */
598 /* null terminate == cheap insurance */
606 /*********************************************************************
608 * Function : get_header
610 * Description : This (odd) routine will parse the csp->iob
613 * 1 : csp = Current client state (buffers, headers, etc...)
615 * Returns : Any one of the following:
617 * 1) a pointer to a dynamically allocated string that contains a header line
618 * 2) NULL indicating that the end of the header was reached
619 * 3) "" indicating that the end of the iob was reached before finding
620 * a complete header line.
622 *********************************************************************/
623 char *get_header(struct client_state *csp)
629 if ((iob->cur == NULL)
630 || ((p = strchr(iob->cur, '\n')) == NULL))
632 return(""); /* couldn't find a complete header */
637 ret = strdup(iob->cur);
640 /* FIXME No way to handle error properly */
641 log_error(LOG_LEVEL_FATAL, "Out of memory in get_header()");
646 if ((q = strchr(ret, '\r')) != NULL) *q = '\0';
648 /* is this a blank line (i.e. the end of the header) ? */
660 /*********************************************************************
662 * Function : get_header_value
664 * Description : Get the value of a given header from a chained list
665 * of header lines or return NULL if no such header is
666 * present in the list.
669 * 1 : header_list = pointer to list
670 * 2 : header_name = string with name of header to look for.
671 * Trailing colon required, capitalization
674 * Returns : NULL if not found, else value of header
676 *********************************************************************/
677 char *get_header_value(const struct list *header_list, const char *header_name)
679 struct list_entry *cur_entry;
685 length = strlen(header_name);
687 for (cur_entry = header_list->first; cur_entry ; cur_entry = cur_entry->next)
691 if (!strncmpic(cur_entry->str, header_name, length))
694 * Found: return pointer to start of value
696 ret = (char *) (cur_entry->str + length);
697 while (*ret && ijb_isspace(*ret)) ret++;
710 /*********************************************************************
714 * Description : add, delete or modify lines in the HTTP header streams.
715 * On entry, it receives a linked list of headers space
716 * that was allocated dynamically (both the list nodes
717 * and the header contents).
719 * As a side effect it frees the space used by the original
723 * 1 : pats = list of patterns to match against headers
724 * 2 : more_headers = list of functions to add more
725 * headers (client or server)
726 * 3 : csp = Current client state (buffers, headers, etc...)
728 * Returns : Single pointer to a fully formed header, or NULL
729 * on out-of-memory error.
731 *********************************************************************/
732 char *sed(const struct parsers pats[],
733 const add_header_func_ptr more_headers[],
734 struct client_state *csp)
736 struct list_entry *p;
737 const struct parsers *v;
738 const add_header_func_ptr *f;
739 jb_err err = JB_ERR_OK;
741 for (v = pats; (err == JB_ERR_OK) && (v->str != NULL) ; v++)
743 for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL) ; p = p->next)
745 /* Header crunch()ed in previous run? -> ignore */
746 if (p->str == NULL) continue;
748 if (v == pats) log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
750 if (strncmpic(p->str, v->str, v->len) == 0)
752 err = v->parser(csp, (char **)&(p->str));
757 /* place any additional headers on the csp->headers list */
758 for (f = more_headers; (err == JB_ERR_OK) && (*f) ; f++)
763 if (err != JB_ERR_OK)
768 return list_to_text(csp->headers);
772 /* here begins the family of parser functions that reformat header lines */
775 /*********************************************************************
779 * Description : This is called if a header matches a pattern to "crunch"
782 * 1 : csp = Current client state (buffers, headers, etc...)
783 * 2 : header = On input, pointer to header to modify.
784 * On output, pointer to the modified header, or NULL
785 * to remove the header. This function frees the
786 * original string if necessary.
788 * Returns : JB_ERR_OK on success, or
789 * JB_ERR_MEMORY on out-of-memory error.
791 *********************************************************************/
792 jb_err crumble(struct client_state *csp, char **header)
794 log_error(LOG_LEVEL_HEADER, "crunch!");
800 /*********************************************************************
802 * Function : server_content_type
804 * Description : Set the content-type for filterable types (text/.*,
805 * javascript and image/gif) unless filtering has been
806 * forbidden (CT_TABOO) while parsing earlier headers.
809 * 1 : csp = Current client state (buffers, headers, etc...)
810 * 2 : header = On input, pointer to header to modify.
811 * On output, pointer to the modified header, or NULL
812 * to remove the header. This function frees the
813 * original string if necessary.
815 * Returns : JB_ERR_OK on success, or
816 * JB_ERR_MEMORY on out-of-memory error.
818 *********************************************************************/
819 jb_err server_content_type(struct client_state *csp, char **header)
821 if (csp->content_type != CT_TABOO)
823 if (strstr(*header, " text/")
824 || strstr(*header, "application/x-javascript"))
825 csp->content_type = CT_TEXT;
826 else if (strstr(*header, " image/gif"))
827 csp->content_type = CT_GIF;
829 csp->content_type = 0;
836 /*********************************************************************
838 * Function : server_transfer_coding
840 * Description : - Prohibit filtering (CT_TABOO) if transfer coding compresses
841 * - Raise the CSP_FLAG_CHUNKED flag if coding is "chunked"
842 * - Change from "chunked" to "identity" if body was chunked
843 * but has been de-chunked for filtering.
846 * 1 : csp = Current client state (buffers, headers, etc...)
847 * 2 : header = On input, pointer to header to modify.
848 * On output, pointer to the modified header, or NULL
849 * to remove the header. This function frees the
850 * original string if necessary.
852 * Returns : JB_ERR_OK on success, or
853 * JB_ERR_MEMORY on out-of-memory error.
855 *********************************************************************/
856 jb_err server_transfer_coding(struct client_state *csp, char **header)
859 * Turn off pcrs and gif filtering if body compressed
861 if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
863 csp->content_type = CT_TABOO;
867 * Raise flag if body chunked
869 if (strstr(*header, "chunked"))
871 csp->flags |= CSP_FLAG_CHUNKED;
874 * If the body was modified, it has been
875 * de-chunked first, so adjust the header:
877 if (csp->flags & CSP_FLAG_MODIFIED)
880 *header = strdup("Transfer-Encoding: identity");
881 return (header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
889 /*********************************************************************
891 * Function : server_content_encoding
893 * Description : Prohibit filtering (CT_TABOO) if content encoding compresses
896 * 1 : csp = Current client state (buffers, headers, etc...)
897 * 2 : header = On input, pointer to header to modify.
898 * On output, pointer to the modified header, or NULL
899 * to remove the header. This function frees the
900 * original string if necessary.
902 * Returns : JB_ERR_OK on success, or
903 * JB_ERR_MEMORY on out-of-memory error.
905 *********************************************************************/
906 jb_err server_content_encoding(struct client_state *csp, char **header)
909 * Turn off pcrs and gif filtering if body compressed
911 if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
913 csp->content_type = CT_TABOO;
921 /*********************************************************************
923 * Function : server_content_length
925 * Description : Adjust Content-Length header if we modified
929 * 1 : csp = Current client state (buffers, headers, etc...)
930 * 2 : header = On input, pointer to header to modify.
931 * On output, pointer to the modified header, or NULL
932 * to remove the header. This function frees the
933 * original string if necessary.
935 * Returns : JB_ERR_OK on success, or
936 * JB_ERR_MEMORY on out-of-memory error.
938 *********************************************************************/
939 jb_err server_content_length(struct client_state *csp, char **header)
941 if (csp->content_length != 0) /* Content length has been modified */
944 *header = (char *) zalloc(100);
947 return JB_ERR_MEMORY;
950 sprintf(*header, "Content-Length: %d", (int) csp->content_length);
952 log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", (int) csp->content_length);
959 /*********************************************************************
961 * Function : server_content_md5
963 * Description : Crumble any Content-MD5 headers if the document was
964 * modified. FIXME: Should we re-compute instead?
967 * 1 : csp = Current client state (buffers, headers, etc...)
968 * 2 : header = On input, pointer to header to modify.
969 * On output, pointer to the modified header, or NULL
970 * to remove the header. This function frees the
971 * original string if necessary.
973 * Returns : JB_ERR_OK on success, or
974 * JB_ERR_MEMORY on out-of-memory error.
976 *********************************************************************/
977 jb_err server_content_md5(struct client_state *csp, char **header)
979 if (csp->flags & CSP_FLAG_MODIFIED)
981 log_error(LOG_LEVEL_HEADER, "Crunching Content-MD5");
989 /*********************************************************************
991 * Function : client_accept_encoding
993 * Description : Rewrite the client's Accept-Encoding header so that
994 * if doesn't allow compression, if the action applies.
995 * Note: For HTTP/1.0 the absence of the header is enough.
998 * 1 : csp = Current client state (buffers, headers, etc...)
999 * 2 : header = On input, pointer to header to modify.
1000 * On output, pointer to the modified header, or NULL
1001 * to remove the header. This function frees the
1002 * original string if necessary.
1004 * Returns : JB_ERR_OK on success, or
1005 * JB_ERR_MEMORY on out-of-memory error.
1007 *********************************************************************/
1008 jb_err client_accept_encoding(struct client_state *csp, char **header)
1010 if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1012 log_error(LOG_LEVEL_HEADER, "Suppressed offer to compress content");
1015 if (!strcmpic(csp->http->ver, "HTTP/1.1"))
1017 *header = strdup("Accept-Encoding: identity;q=1.0, *;q=0");
1018 if (*header == NULL)
1020 return JB_ERR_MEMORY;
1029 /*********************************************************************
1031 * Function : client_te
1033 * Description : Rewrite the client's TE header so that
1034 * if doesn't allow compression, if the action applies.
1037 * 1 : csp = Current client state (buffers, headers, etc...)
1038 * 2 : header = On input, pointer to header to modify.
1039 * On output, pointer to the modified header, or NULL
1040 * to remove the header. This function frees the
1041 * original string if necessary.
1043 * Returns : JB_ERR_OK on success, or
1044 * JB_ERR_MEMORY on out-of-memory error.
1046 *********************************************************************/
1047 jb_err client_te(struct client_state *csp, char **header)
1049 if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1052 log_error(LOG_LEVEL_HEADER, "Suppressed offer to compress transfer");
1058 /*********************************************************************
1060 * Function : client_referrer
1062 * Description : Handle the "referer" config setting properly.
1063 * Called from `sed'.
1066 * 1 : csp = Current client state (buffers, headers, etc...)
1067 * 2 : header = On input, pointer to header to modify.
1068 * On output, pointer to the modified header, or NULL
1069 * to remove the header. This function frees the
1070 * original string if necessary.
1072 * Returns : JB_ERR_OK on success, or
1073 * JB_ERR_MEMORY on out-of-memory error.
1075 *********************************************************************/
1076 jb_err client_referrer(struct client_state *csp, char **header)
1080 #ifdef FEATURE_FORCE_LOAD
1081 /* Since the referrer can include the prefix even
1082 * even if the request itself is non-forced, we must
1083 * clean it unconditionally
1085 strclean(*header, FORCE_PREFIX);
1086 #endif /* def FEATURE_FORCE_LOAD */
1089 * Are we sending referer?
1091 if ((csp->action->flags & ACTION_HIDE_REFERER) == 0)
1098 newval = csp->action->string[ACTION_STRING_REFERER];
1100 if ((newval == NULL) || (0 == strcmpic(newval, "block")) )
1105 #ifdef FEATURE_ACTIVITY_CONSOLE
1106 accumulate_stats(STATS_REFERER, 1);
1107 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1108 log_error(LOG_LEVEL_HEADER, "crunch!");
1111 else if (0 == strncmpic(newval, "http://", 7))
1114 * We have a specific (fixed) referer we want to send.
1116 log_error(LOG_LEVEL_HEADER, "modified");
1118 *header = strdup("Referer: ");
1119 string_append(header, newval);
1121 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1126 * Forge a referer as http://[hostname:port of REQUEST]/
1127 * to fool stupid checks for in-site links
1129 if (0 != strcmpic(newval, "forge"))
1132 * Invalid choice - but forge is probably the best default.
1134 log_error(LOG_LEVEL_ERROR, "Bad parameter: +referer{%s}", newval);
1137 *header = strdup("Referer: http://");
1138 string_append(header, csp->http->hostport);
1139 string_append(header, "/");
1140 log_error(LOG_LEVEL_HEADER, "crunch+forge to %s", *header);
1142 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1147 /*********************************************************************
1149 * Function : client_uagent
1151 * Description : Handle the "user-agent" config setting properly
1152 * and remember its original value to enable browser
1153 * bug workarounds. Called from `sed'.
1156 * 1 : csp = Current client state (buffers, headers, etc...)
1157 * 2 : header = On input, pointer to header to modify.
1158 * On output, pointer to the modified header, or NULL
1159 * to remove the header. This function frees the
1160 * original string if necessary.
1162 * Returns : JB_ERR_OK on success, or
1163 * JB_ERR_MEMORY on out-of-memory error.
1165 *********************************************************************/
1166 jb_err client_uagent(struct client_state *csp, char **header)
1170 if ((csp->action->flags & ACTION_HIDE_USER_AGENT) == 0)
1175 newval = csp->action->string[ACTION_STRING_USER_AGENT];
1181 log_error(LOG_LEVEL_HEADER, "modified");
1184 *header = strdup("User-Agent: ");
1185 string_append(header, newval);
1187 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1191 /*********************************************************************
1193 * Function : client_ua
1195 * Description : Handle "ua-" headers properly. Called from `sed'.
1198 * 1 : csp = Current client state (buffers, headers, etc...)
1199 * 2 : header = On input, pointer to header to modify.
1200 * On output, pointer to the modified header, or NULL
1201 * to remove the header. This function frees the
1202 * original string if necessary.
1204 * Returns : JB_ERR_OK on success, or
1205 * JB_ERR_MEMORY on out-of-memory error.
1207 *********************************************************************/
1208 jb_err client_ua(struct client_state *csp, char **header)
1210 if ((csp->action->flags & ACTION_HIDE_USER_AGENT) != 0)
1212 #ifdef FEATURE_ACTIVITY_CONSOLE
1213 accumulate_stats(STATS_CLIENT_UA, 1);
1214 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1215 log_error(LOG_LEVEL_HEADER, "crunch!");
1223 /*********************************************************************
1225 * Function : client_from
1227 * Description : Handle the "from" config setting properly.
1228 * Called from `sed'.
1231 * 1 : csp = Current client state (buffers, headers, etc...)
1232 * 2 : header = On input, pointer to header to modify.
1233 * On output, pointer to the modified header, or NULL
1234 * to remove the header. This function frees the
1235 * original string if necessary.
1237 * Returns : JB_ERR_OK on success, or
1238 * JB_ERR_MEMORY on out-of-memory error.
1240 *********************************************************************/
1241 jb_err client_from(struct client_state *csp, char **header)
1245 if ((csp->action->flags & ACTION_HIDE_FROM) == 0)
1252 newval = csp->action->string[ACTION_STRING_FROM];
1255 * Are we blocking the e-mail address?
1257 if ((newval == NULL) || (0 == strcmpic(newval, "block")) )
1259 #ifdef FEATURE_ACTIVITY_CONSOLE
1260 accumulate_stats(STATS_CLIENT_FROM, 1);
1261 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1262 log_error(LOG_LEVEL_HEADER, "crunch!");
1266 log_error(LOG_LEVEL_HEADER, " modified");
1268 *header = strdup("From: ");
1269 string_append(header, newval);
1271 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1275 /*********************************************************************
1277 * Function : client_send_cookie
1279 * Description : Handle the "cookie" header properly. Called from `sed'.
1280 * If cookie is accepted, add it to the cookie_list,
1281 * else we crunch it. Mmmmmmmmmmm ... cookie ......
1284 * 1 : csp = Current client state (buffers, headers, etc...)
1285 * 2 : header = On input, pointer to header to modify.
1286 * On output, pointer to the modified header, or NULL
1287 * to remove the header. This function frees the
1288 * original string if necessary.
1290 * Returns : JB_ERR_OK on success, or
1291 * JB_ERR_MEMORY on out-of-memory error.
1293 *********************************************************************/
1294 jb_err client_send_cookie(struct client_state *csp, char **header)
1296 jb_err result = JB_ERR_OK;
1298 if ((csp->action->flags & ACTION_NO_COOKIE_READ) == 0)
1300 /* strlen("cookie: ") == 8 */
1301 result = enlist(csp->cookie_list, *header + 8);
1305 log_error(LOG_LEVEL_HEADER, "Crunched outgoing cookie -- yum!");
1309 * Always remove the cookie here. The cookie header
1310 * will be sent at the end of the header.
1318 /*********************************************************************
1320 * Function : client_x_forwarded
1322 * Description : Handle the "x-forwarded-for" config setting properly,
1323 * also used in the add_client_headers list. Called from `sed'.
1326 * 1 : csp = Current client state (buffers, headers, etc...)
1327 * 2 : header = On input, pointer to header to modify.
1328 * On output, pointer to the modified header, or NULL
1329 * to remove the header. This function frees the
1330 * original string if necessary.
1332 * Returns : JB_ERR_OK on success, or
1333 * JB_ERR_MEMORY on out-of-memory error.
1335 *********************************************************************/
1336 jb_err client_x_forwarded(struct client_state *csp, char **header)
1338 if ((csp->action->flags & ACTION_HIDE_FORWARDED) == 0)
1340 /* Save it so we can re-add it later */
1341 freez(csp->x_forwarded);
1342 csp->x_forwarded = *header;
1345 * Always set *header = NULL, since this information
1346 * will be sent at the end of the header.
1353 #ifdef FEATURE_ACTIVITY_CONSOLE
1354 accumulate_stats(STATS_CLIENT_X_FORWARDED, 1);
1355 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1356 log_error(LOG_LEVEL_HEADER, " crunch!");
1362 /* the following functions add headers directly to the header list */
1364 /*********************************************************************
1366 * Function : client_host_adder
1368 * Description : (re)adds the host header. Called from `sed'.
1371 * 1 : csp = Current client state (buffers, headers, etc...)
1373 * Returns : JB_ERR_OK on success, or
1374 * JB_ERR_MEMORY on out-of-memory error.
1376 *********************************************************************/
1377 jb_err client_host_adder(struct client_state *csp)
1383 if ( !csp->http->hostport || !*(csp->http->hostport))
1388 p = strdup("Host: ");
1390 ** remove 'user:pass@' from 'proto://user:pass@host'
1392 if ( (pos = strchr( csp->http->hostport, '@')) != NULL )
1394 string_append(&p, pos+1);
1398 string_append(&p, csp->http->hostport);
1403 return JB_ERR_MEMORY;
1406 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1408 err = enlist(csp->headers, p);
1416 /*********************************************************************
1418 * Function : client_cookie_adder
1420 * Description : Used in the add_client_headers list. Called from `sed'.
1423 * 1 : csp = Current client state (buffers, headers, etc...)
1425 * Returns : JB_ERR_OK on success, or
1426 * JB_ERR_MEMORY on out-of-memory error.
1428 *********************************************************************/
1429 jb_err client_cookie_adder(struct client_state *csp)
1431 struct list_entry *lst;
1433 struct list_entry *list1 = csp->cookie_list->first;
1434 struct list_entry *list2 = csp->action->multi[ACTION_MULTI_WAFER]->first;
1435 int first_cookie = 1;
1438 if ((list1 == NULL) && (list2 == NULL))
1444 tmp = strdup("Cookie: ");
1446 for (lst = list1; lst ; lst = lst->next)
1454 string_append(&tmp, "; ");
1456 string_append(&tmp, lst->str);
1459 for (lst = list2; lst ; lst = lst->next)
1467 string_append(&tmp, "; ");
1469 string_join(&tmp, cookie_encode(lst->str));
1474 return JB_ERR_MEMORY;
1477 log_error(LOG_LEVEL_HEADER, "addh: %s", tmp);
1478 err = enlist(csp->headers, tmp);
1484 /*********************************************************************
1486 * Function : client_accept_encoding_adder
1488 * Description : Add an Accept-Encoding header to the client's request
1489 * that disables compression if the action applies, and
1490 * the header is not already there. Called from `sed'.
1491 * Note: For HTTP/1.0, the absence of the header is enough.
1494 * 1 : csp = Current client state (buffers, headers, etc...)
1496 * Returns : JB_ERR_OK on success, or
1497 * JB_ERR_MEMORY on out-of-memory error.
1499 *********************************************************************/
1500 jb_err client_accept_encoding_adder(struct client_state *csp)
1502 if ( ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1503 && (!strcmpic(csp->http->ver, "HTTP/1.1")) )
1505 return enlist_unique(csp->headers, "Accept-Encoding: identity;q=1.0, *;q=0", 16);
1512 /*********************************************************************
1514 * Function : client_xtra_adder
1516 * Description : Used in the add_client_headers list. Called from `sed'.
1519 * 1 : csp = Current client state (buffers, headers, etc...)
1521 * Returns : JB_ERR_OK on success, or
1522 * JB_ERR_MEMORY on out-of-memory error.
1524 *********************************************************************/
1525 jb_err client_xtra_adder(struct client_state *csp)
1527 struct list_entry *lst;
1530 for (lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]->first;
1531 lst ; lst = lst->next)
1533 log_error(LOG_LEVEL_HEADER, "addh: %s", lst->str);
1534 err = enlist(csp->headers, lst->str);
1546 /*********************************************************************
1548 * Function : client_x_forwarded_adder
1550 * Description : Used in the add_client_headers list. Called from `sed'.
1553 * 1 : csp = Current client state (buffers, headers, etc...)
1555 * Returns : JB_ERR_OK on success, or
1556 * JB_ERR_MEMORY on out-of-memory error.
1558 *********************************************************************/
1559 jb_err client_x_forwarded_adder(struct client_state *csp)
1564 if ((csp->action->flags & ACTION_HIDE_FORWARDED) != 0)
1569 if (csp->x_forwarded)
1571 p = strdup(csp->x_forwarded);
1572 string_append(&p, ", ");
1576 p = strdup("X-Forwarded-For: ");
1578 string_append(&p, csp->ip_addr_str);
1582 return JB_ERR_MEMORY;
1585 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1586 err = enlist(csp->headers, p);
1593 /*********************************************************************
1595 * Function : connection_close_adder
1597 * Description : Adds a "Connection: close" header to csp->headers
1598 * as a temporary fix for the needed but missing HTTP/1.1
1599 * support. Called from `sed'.
1600 * FIXME: This whole function shouldn't be neccessary!
1603 * 1 : csp = Current client state (buffers, headers, etc...)
1605 * Returns : JB_ERR_OK on success, or
1606 * JB_ERR_MEMORY on out-of-memory error.
1608 *********************************************************************/
1609 jb_err connection_close_adder(struct client_state *csp)
1611 return enlist(csp->headers, "Connection: close");
1615 /*********************************************************************
1617 * Function : server_http
1619 * Description : - Save the HTTP Status into csp->http->status
1620 * - Set CT_TABOO to prevent filtering if the answer
1621 * is a partial range (HTTP status 206)
1622 * - Rewrite HTTP/1.1 answers to HTTP/1.0 if +downgrade
1626 * 1 : csp = Current client state (buffers, headers, etc...)
1627 * 2 : header = On input, pointer to header to modify.
1628 * On output, pointer to the modified header, or NULL
1629 * to remove the header. This function frees the
1630 * original string if necessary.
1632 * Returns : JB_ERR_OK on success, or
1633 * JB_ERR_MEMORY on out-of-memory error.
1635 *********************************************************************/
1636 jb_err server_http(struct client_state *csp, char **header)
1638 sscanf(*header, "HTTP/%*d.%*d %d", &(csp->http->status));
1639 if (csp->http->status == 206)
1641 csp->content_type = CT_TABOO;
1644 if ((csp->action->flags & ACTION_DOWNGRADE) != 0)
1647 log_error(LOG_LEVEL_HEADER, "Downgraded answer to HTTP/1.0");
1654 /*********************************************************************
1656 * Function : server_set_cookie
1658 * Description : Handle the server "cookie" header properly.
1659 * Log cookie to the jar file. Then "crunch" it,
1660 * or accept it. Called from `sed'.
1663 * 1 : csp = Current client state (buffers, headers, etc...)
1664 * 2 : header = On input, pointer to header to modify.
1665 * On output, pointer to the modified header, or NULL
1666 * to remove the header. This function frees the
1667 * original string if necessary.
1669 * Returns : JB_ERR_OK on success, or
1670 * JB_ERR_MEMORY on out-of-memory error.
1672 *********************************************************************/
1673 jb_err server_set_cookie(struct client_state *csp, char **header)
1675 #ifdef FEATURE_COOKIE_JAR
1676 if (csp->config->jar)
1679 * Write timestamp into outbuf.
1681 * Complex because not all OSs have tm_gmtoff or
1682 * the %z field in strftime()
1684 char tempbuf[ BUFFER_SIZE ];
1688 #ifdef HAVE_LOCALTIME_R
1689 tm_now = *localtime_r(&now, &tm_now);
1691 tm_now = *localtime (&now);
1693 strftime(tempbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1695 /* strlen("set-cookie: ") = 12 */
1696 fprintf(csp->config->jar, "%s %s\t%s\n", tempbuf, csp->http->host, *header + 12);
1698 #endif /* def FEATURE_COOKIE_JAR */
1700 if ((csp->action->flags & ACTION_NO_COOKIE_SET) != 0)
1702 log_error(LOG_LEVEL_HEADER, "Crunched incoming cookie -- yum!");
1703 return crumble(csp, header);
1705 else if ((csp->action->flags & ACTION_NO_COOKIE_KEEP) != 0)
1707 /* Flag whether or not to log a message */
1710 /* A variable to store the tag we're working on */
1713 /* Skip "Set-Cookie:" (11 characters) in header */
1714 cur_tag = *header + 11;
1716 /* skip whitespace between "Set-Cookie:" and value */
1717 while (*cur_tag && ijb_isspace(*cur_tag))
1722 /* Loop through each tag in the cookie */
1726 char *next_tag = strchr(cur_tag, ';');
1727 if (next_tag != NULL)
1729 /* Skip the ';' character itself */
1732 /* skip whitespace ";" and start of tag */
1733 while (*next_tag && ijb_isspace(*next_tag))
1740 /* "Next tag" is the end of the string */
1741 next_tag = cur_tag + strlen(cur_tag);
1744 /* Is this the "Expires" tag? */
1745 if (strncmpic(cur_tag, "expires=", 8) == 0)
1747 /* Delete the tag by copying the rest of the string over it.
1748 * (Note that we cannot just use "strcpy(cur_tag, next_tag)",
1749 * since the behaviour of strcpy is undefined for overlapping
1752 memmove(cur_tag, next_tag, strlen(next_tag) + 1);
1754 /* That changed the header, need to issue a log message */
1757 /* Note that the next tag has now been moved to *cur_tag,
1758 * so we do not need to update the cur_tag pointer.
1763 /* Move on to next cookie tag */
1770 log_error(LOG_LEVEL_HEADER, "Changed cookie to a temporary one.");
1778 #ifdef FEATURE_FORCE_LOAD
1779 /*********************************************************************
1781 * Function : strclean
1783 * Description : In-Situ-Eliminate all occurances of substring in
1787 * 1 : string = string to clean
1788 * 2 : substring = substring to eliminate
1790 * Returns : Number of eliminations
1792 *********************************************************************/
1793 int strclean(const char *string, const char *substring)
1795 int hits = 0, len = strlen(substring);
1798 while((pos = strstr(string, substring)) != NULL)
1805 while (*p++ != '\0');
1812 #endif /* def FEATURE_FORCE_LOAD */