1 const char parsers_rcs[] = "$Id: parsers.c,v 2.4 2003/01/26 20:24:26 david__schmidt 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.4 2003/01/26 20:24:26 david__schmidt
44 * Updated activity console instrumentation locations
46 * Revision 2.3 2002/12/28 03:58:19 david__schmidt
47 * Initial drop of dashboard instrumentation - enabled with
48 * --enable-activity-console
50 * Revision 2.2 2002/11/10 04:20:38 hal9
51 * Fix typo: supressed -> suppressed
53 * Revision 2.1 2002/09/11 11:23:59 oes
54 * Fixed logging of cookies: Killed incoming cookies now logged; incoming/outgoing cookies now distinguished in log
56 * Revision 2.0 2002/06/04 14:34:21 jongfoster
57 * Moving source files to src/
59 * Revision 1.56 2002/05/12 15:34:22 jongfoster
60 * Fixing typo in a comment
62 * Revision 1.55 2002/05/08 16:01:07 oes
63 * Optimized add_to_iob:
64 * - Use realloc instead of malloc(), memcpy(), free()
65 * - Expand to powers of two if possible, to get
66 * O(log n) reallocs instead of O(n).
67 * - Moved check for buffer limit here from chat
68 * - Report failure via returncode
70 * Revision 1.54 2002/04/02 15:03:16 oes
73 * Revision 1.53 2002/03/26 22:29:55 swa
74 * we have a new homepage!
76 * Revision 1.52 2002/03/24 13:25:43 swa
77 * name change related issues
79 * Revision 1.51 2002/03/13 00:27:05 jongfoster
82 * Revision 1.50 2002/03/12 01:45:35 oes
83 * More verbose logging
85 * Revision 1.49 2002/03/09 20:03:52 jongfoster
86 * - Making various functions return int rather than size_t.
87 * (Undoing a recent change). Since size_t is unsigned on
88 * Windows, functions like read_socket that return -1 on
89 * error cannot return a size_t.
91 * THIS WAS A MAJOR BUG - it caused frequent, unpredictable
92 * crashes, and also frequently caused JB to jump to 100%
93 * CPU and stay there. (Because it thought it had just
94 * read ((unsigned)-1) == 4Gb of data...)
96 * - The signature of write_socket has changed, it now simply
97 * returns success=0/failure=nonzero.
99 * - Trying to get rid of a few warnings --with-debug on
100 * Windows, I've introduced a new type "jb_socket". This is
101 * used for the socket file descriptors. On Windows, this
102 * is SOCKET (a typedef for unsigned). Everywhere else, it's
103 * an int. The error value can't be -1 any more, so it's
104 * now JB_INVALID_SOCKET (which is -1 on UNIX, and in
105 * Windows it maps to the #define INVALID_SOCKET.)
107 * - The signature of bind_port has changed.
109 * Revision 1.48 2002/03/07 03:46:53 oes
110 * Fixed compiler warnings etc
112 * Revision 1.47 2002/02/20 23:15:13 jongfoster
113 * Parsing functions now handle out-of-memory gracefully by returning
116 * Revision 1.46 2002/01/17 21:03:47 jongfoster
117 * Moving all our URL and URL pattern parsing code to urlmatch.c.
119 * Revision 1.45 2002/01/09 14:33:03 oes
120 * Added support for localtime_r.
122 * Revision 1.44 2001/12/14 01:22:54 steudten
123 * Remove 'user:pass@' from 'proto://user:pass@host' for the
124 * new added header 'Host: ..'. (See Req ID 491818)
126 * Revision 1.43 2001/11/23 00:26:38 jongfoster
127 * Fixing two really stupid errors in my previous commit
129 * Revision 1.42 2001/11/22 21:59:30 jongfoster
130 * Adding code to handle +no-cookies-keep
132 * Revision 1.41 2001/11/05 23:43:05 steudten
133 * Add time+date to log files.
135 * Revision 1.40 2001/10/26 20:13:09 jongfoster
136 * ctype.h is needed in Windows, too.
138 * Revision 1.39 2001/10/26 17:40:04 oes
139 * Introduced get_header_value()
140 * Removed http->user_agent, csp->referrer and csp->accept_types
141 * Removed client_accept()
143 * Revision 1.38 2001/10/25 03:40:48 david__schmidt
144 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
145 * threads to call select() simultaneously. So, it's time to do a real, live,
146 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
147 * (native). Both versions will work, but using __OS2__ offers multi-threading.
149 * Revision 1.37 2001/10/23 21:36:02 jongfoster
150 * Documenting sed()'s error behaviou (doc change only)
152 * Revision 1.36 2001/10/13 12:51:51 joergs
153 * Removed client_host, (was only required for the old 2.0.2-11 http://noijb.
154 * force-load), instead crumble Host: and add it (again) in client_host_adder
155 * (in case we get a HTTP/1.0 request without Host: header and forward it to
156 * a HTTP/1.1 server/proxy).
158 * Revision 1.35 2001/10/09 22:39:21 jongfoster
159 * assert.h is also required under Win32, so moving out of #ifndef _WIN32
162 * Revision 1.34 2001/10/07 18:50:55 oes
163 * Added server_content_encoding, renamed server_transfer_encoding
165 * Revision 1.33 2001/10/07 18:04:49 oes
166 * Changed server_http11 to server_http and its pattern to "HTTP".
167 * Additional functionality: it now saves the HTTP status into
168 * csp->http->status and sets CT_TABOO for Status 206 (partial range)
170 * Revision 1.32 2001/10/07 15:43:28 oes
171 * Removed FEATURE_DENY_GZIP and replaced it with client_accept_encoding,
172 * client_te and client_accept_encoding_adder, triggered by the new
173 * +no-compression action. For HTTP/1.1 the Accept-Encoding header is
174 * changed to allow only identity and chunked, and the TE header is
175 * crunched. For HTTP/1.0, Accept-Encoding is crunched.
177 * parse_http_request no longer does anything than parsing. The rewriting
178 * of http->cmd and version mangling are gone. It now also recognizes
179 * the put and delete methods and saves the url in http->url. Removed
182 * renamed content_type and content_length to have the server_ prefix
184 * server_content_type now only works if csp->content_type != CT_TABOO
186 * added server_transfer_encoding, which
187 * - Sets CT_TABOO to prohibit filtering if encoding compresses
188 * - Raises the CSP_FLAG_CHUNKED flag if Encoding is "chunked"
189 * - Change from "chunked" to "identity" if body was chunked
190 * but has been de-chunked for filtering.
192 * added server_content_md5 which crunches any Content-MD5 headers
193 * if the body was modified.
195 * made server_http11 conditional on +downgrade action
197 * Replaced 6 boolean members of csp with one bitmap (csp->flags)
199 * Revision 1.31 2001/10/05 14:25:02 oes
200 * Crumble Keep-Alive from Server
202 * Revision 1.30 2001/09/29 12:56:03 joergs
203 * IJB now changes HTTP/1.1 to HTTP/1.0 in requests and answers.
205 * Revision 1.29 2001/09/24 21:09:24 jongfoster
206 * Fixing 2 memory leaks that Guy spotted, where the paramater to
207 * enlist() was not being free()d.
209 * Revision 1.28 2001/09/22 16:32:28 jongfoster
210 * Removing unused #includes.
212 * Revision 1.27 2001/09/20 15:45:25 steudten
214 * add casting from size_t to int for printf()
215 * remove local variable shadow s2
217 * Revision 1.26 2001/09/16 17:05:14 jongfoster
218 * Removing unused #include showarg.h
220 * Revision 1.25 2001/09/16 13:21:27 jongfoster
221 * Changes to use new list functions.
223 * Revision 1.24 2001/09/13 23:05:50 jongfoster
224 * Changing the string paramater to the header parsers a "const".
226 * Revision 1.23 2001/09/12 18:08:19 steudten
228 * In parse_http_request() header rewriting miss the host value, so
229 * from http://www.mydomain.com the result was just " / " not
230 * http://www.mydomain.com/ in case we forward.
232 * Revision 1.22 2001/09/10 10:58:53 oes
233 * Silenced compiler warnings
235 * Revision 1.21 2001/07/31 14:46:00 oes
236 * - Persistant connections now suppressed
237 * - sed() no longer appends empty header to csp->headers
239 * Revision 1.20 2001/07/30 22:08:36 jongfoster
240 * Tidying up #defines:
241 * - All feature #defines are now of the form FEATURE_xxx
242 * - Permanently turned off WIN_GUI_EDIT
243 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
245 * Revision 1.19 2001/07/25 17:21:54 oes
246 * client_uagent now saves copy of User-Agent: header value
248 * Revision 1.18 2001/07/13 14:02:46 oes
249 * - Included fix to repair broken HTTP requests that
250 * don't contain a path, not even '/'.
251 * - Removed all #ifdef PCRS
252 * - content_type now always inspected and classified as
253 * text, gif or other.
254 * - formatting / comments
256 * Revision 1.17 2001/06/29 21:45:41 oes
257 * Indentation, CRLF->LF, Tab-> Space
259 * Revision 1.16 2001/06/29 13:32:42 oes
261 * - Adapted free_http_request
262 * - Removed logentry from cancelled commit
264 * Revision 1.15 2001/06/03 19:12:38 oes
265 * deleted const struct interceptors
267 * Revision 1.14 2001/06/01 18:49:17 jongfoster
268 * Replaced "list_share" with "list" - the tiny memory gain was not
269 * worth the extra complexity.
271 * Revision 1.13 2001/05/31 21:30:33 jongfoster
272 * Removed list code - it's now in list.[ch]
273 * Renamed "permission" to "action", and changed many features
274 * to use the actions file rather than the global config.
276 * Revision 1.12 2001/05/31 17:33:13 oes
280 * Revision 1.11 2001/05/29 20:11:19 joergs
281 * '/ * inside comment' warning removed.
283 * Revision 1.10 2001/05/29 09:50:24 jongfoster
284 * Unified blocklist/imagelist/permissionslist.
285 * File format is still under discussion, but the internal changes
288 * Also modified interceptor behaviour:
289 * - We now intercept all URLs beginning with one of the following
290 * prefixes (and *only* these prefixes):
292 * * http://ijbswa.sf.net/config/
293 * * http://ijbswa.sourceforge.net/config/
294 * - New interceptors "home page" - go to http://i.j.b/ to see it.
295 * - Internal changes so that intercepted and fast redirect pages
296 * are not replaced with an image.
297 * - Interceptors now have the option to send a binary page direct
298 * to the client. (i.e. ijb-send-banner uses this)
299 * - Implemented show-url-info interceptor. (Which is why I needed
300 * the above interceptors changes - a typical URL is
301 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
302 * The previous mechanism would not have intercepted that, and
303 * if it had been intercepted then it then it would have replaced
306 * Revision 1.9 2001/05/28 17:26:33 jongfoster
307 * Fixing segfault if last header was crunched.
308 * Fixing Windows build (snprintf() is _snprintf() under Win32, but we
309 * can use the cross-platform sprintf() instead.)
311 * Revision 1.8 2001/05/27 22:17:04 oes
313 * - re_process_buffer no longer writes the modified buffer
314 * to the client, which was very ugly. It now returns the
315 * buffer, which it is then written by chat.
317 * - content_length now adjusts the Content-Length: header
318 * for modified documents rather than crunch()ing it.
319 * (Length info in csp->content_length, which is 0 for
320 * unmodified documents)
322 * - For this to work, sed() is called twice when filtering.
324 * Revision 1.7 2001/05/27 13:19:06 oes
325 * Patched Joergs solution for the content-length in.
327 * Revision 1.6 2001/05/26 13:39:32 jongfoster
328 * Only crunches Content-Length header if applying RE filtering.
329 * Without this fix, Microsoft Windows Update wouldn't work.
331 * Revision 1.5 2001/05/26 00:28:36 jongfoster
332 * Automatic reloading of config file.
333 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
334 * Most of the global variables have been moved to a new
335 * struct configuration_spec, accessed through csp->config->globalname
336 * Most of the globals remaining are used by the Win32 GUI.
338 * Revision 1.4 2001/05/22 18:46:04 oes
340 * - Enabled filtering banners by size rather than URL
341 * by adding patterns that replace all standard banner
342 * sizes with the "Junkbuster" gif to the re_filterfile
344 * - Enabled filtering WebBugs by providing a pattern
345 * which kills all 1x1 images
347 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
348 * which is selected by the (nonstandard and therefore
349 * capital) letter 'U' in the option string.
350 * It causes the quantifiers to be ungreedy by default.
351 * Appending a ? turns back to greedy (!).
353 * - Added a new interceptor ijb-send-banner, which
354 * sends back the "Junkbuster" gif. Without imagelist or
355 * MSIE detection support, or if tinygif = 1, or the
356 * URL isn't recognized as an imageurl, a lame HTML
357 * explanation is sent instead.
359 * - Added new feature, which permits blocking remote
360 * script redirects and firing back a local redirect
362 * The feature is conditionally compiled, i.e. it
363 * can be disabled with --disable-fast-redirects,
364 * plus it must be activated by a "fast-redirects"
365 * line in the config file, has its own log level
366 * and of course wants to be displayed by show-proxy-args
367 * Note: Boy, all the #ifdefs in 1001 locations and
368 * all the fumbling with configure.in and acconfig.h
369 * were *way* more work than the feature itself :-(
371 * - Because a generic redirect template was needed for
372 * this, tinygif = 3 now uses the same.
374 * - Moved GIFs, and other static HTTP response templates
379 * - Removed some >400 CRs again (Jon, you really worked
382 * Revision 1.3 2001/05/20 01:21:20 jongfoster
383 * Version 2.9.4 checkin.
384 * - Merged popupfile and cookiefile, and added control over PCRS
385 * filtering, in new "permissionsfile".
386 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
387 * file error you now get a message box (in the Win32 GUI) rather
388 * than the program exiting with no explanation.
389 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
391 * - Removed tabs from "config"
392 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
393 * - Bumped up version number.
395 * Revision 1.2 2001/05/17 23:02:36 oes
396 * - Made referrer option accept 'L' as a substitute for '§'
398 * Revision 1.1.1.1 2001/05/15 13:59:01 oes
399 * Initial import of version 2.9.3 source tree
402 *********************************************************************/
409 #include <sys/types.h>
417 #if !defined(_WIN32) && !defined(__OS2__)
424 /* jcc.h is for mutex semapores only */
425 #endif /* def OSX_DARWIN */
432 #include "jbsockets.h"
433 #include "miscutil.h"
435 #ifdef FEATURE_ACTIVITY_CONSOLE
437 #endif /* def FEATURE_ACTIVITY_CONSOLE */
439 const char parsers_h_rcs[] = PARSERS_H_VERSION;
441 /* Fix a problem with Solaris. There should be no effect on other
443 * Solaris's isspace() is a macro which uses it's argument directly
444 * as an array index. Therefore we need to make sure that high-bit
445 * characters generate +ve values, and ideally we also want to make
446 * the argument match the declared parameter type of "int".
448 * Why did they write a character function that can't take a simple
449 * "char" argument? Doh!
451 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
452 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
455 const struct parsers client_patterns[] = {
456 { "referer:", 8, client_referrer },
457 { "user-agent:", 11, client_uagent },
458 { "ua-", 3, client_ua },
459 { "from:", 5, client_from },
460 { "cookie:", 7, client_send_cookie },
461 { "x-forwarded-for:", 16, client_x_forwarded },
462 { "Accept-Encoding:", 16, client_accept_encoding },
463 { "TE:", 3, client_te },
464 { "Host:", 5, crumble },
465 /* { "if-modified-since:", 18, crumble }, */
466 { "Keep-Alive:", 11, crumble },
467 { "connection:", 11, crumble },
468 { "proxy-connection:", 17, crumble },
473 const struct parsers server_patterns[] = {
474 { "HTTP", 4, server_http },
475 { "set-cookie:", 11, server_set_cookie },
476 { "connection:", 11, crumble },
477 { "Content-Type:", 13, server_content_type },
478 { "Content-Length:", 15, server_content_length },
479 { "Content-MD5:", 12, server_content_md5 },
480 { "Content-Encoding:", 17, server_content_encoding },
481 { "Transfer-Encoding:", 18, server_transfer_coding },
482 { "Keep-Alive:", 11, crumble },
487 const add_header_func_ptr add_client_headers[] = {
490 client_x_forwarded_adder,
492 client_accept_encoding_adder,
493 connection_close_adder,
498 const add_header_func_ptr add_server_headers[] = {
499 connection_close_adder,
504 /*********************************************************************
506 * Function : flush_socket
508 * Description : Write any pending "buffered" content.
511 * 1 : fd = file descriptor of the socket to read
512 * 2 : csp = Current client state (buffers, headers, etc...)
514 * Returns : On success, the number of bytes written are returned (zero
515 * indicates nothing was written). On error, -1 is returned,
516 * and errno is set appropriately. If count is zero and the
517 * file descriptor refers to a regular file, 0 will be
518 * returned without causing any other effect. For a special
519 * file, the results are not portable.
521 *********************************************************************/
522 int flush_socket(jb_socket fd, struct client_state *csp)
524 struct iob *iob = csp->iob;
525 int len = iob->eod - iob->cur;
532 if (write_socket(fd, iob->cur, (size_t)len))
536 iob->eod = iob->cur = iob->buf;
542 /*********************************************************************
544 * Function : add_to_iob
546 * Description : Add content to the buffered page, expanding the
547 * buffer if necessary.
550 * 1 : csp = Current client state (buffers, headers, etc...)
551 * 2 : buf = holds the content to be added to the page
552 * 3 : n = number of bytes to be added
554 * Returns : JB_ERR_OK on success, JB_ERR_MEMORY if out-of-memory
555 * or buffer limit reached.
557 *********************************************************************/
558 jb_err add_to_iob(struct client_state *csp, char *buf, int n)
560 struct iob *iob = csp->iob;
561 size_t used, offset, need, want;
564 if (n <= 0) return JB_ERR_OK;
566 used = iob->eod - iob->buf;
567 offset = iob->cur - iob->buf;
571 * If the buffer can't hold the new data, extend it first.
572 * Use the next power of two if possible, else use the actual need.
574 if (need > csp->config->buffer_limit)
576 log_error(LOG_LEVEL_ERROR, "Buffer limit reached while extending the buffer (iob)");
577 return JB_ERR_MEMORY;
580 if (need > iob->size)
582 for (want = csp->iob->size ? csp->iob->size : 512; want <= need;) want *= 2;
584 if (want <= csp->config->buffer_limit && NULL != (p = (char *)realloc(iob->buf, want)))
588 else if (NULL != (p = (char *)realloc(iob->buf, need)))
594 log_error(LOG_LEVEL_ERROR, "Extending the buffer (iob) failed: %E");
595 return JB_ERR_MEMORY;
598 /* Update the iob pointers */
599 iob->cur = p + offset;
604 /* copy the new data into the iob buffer */
605 memcpy(iob->eod, buf, (size_t)n);
607 /* point to the end of the data */
610 /* null terminate == cheap insurance */
618 /*********************************************************************
620 * Function : get_header
622 * Description : This (odd) routine will parse the csp->iob
625 * 1 : csp = Current client state (buffers, headers, etc...)
627 * Returns : Any one of the following:
629 * 1) a pointer to a dynamically allocated string that contains a header line
630 * 2) NULL indicating that the end of the header was reached
631 * 3) "" indicating that the end of the iob was reached before finding
632 * a complete header line.
634 *********************************************************************/
635 char *get_header(struct client_state *csp)
641 if ((iob->cur == NULL)
642 || ((p = strchr(iob->cur, '\n')) == NULL))
644 return(""); /* couldn't find a complete header */
649 ret = strdup(iob->cur);
652 /* FIXME No way to handle error properly */
653 log_error(LOG_LEVEL_FATAL, "Out of memory in get_header()");
658 if ((q = strchr(ret, '\r')) != NULL) *q = '\0';
660 /* is this a blank line (i.e. the end of the header) ? */
672 /*********************************************************************
674 * Function : get_header_value
676 * Description : Get the value of a given header from a chained list
677 * of header lines or return NULL if no such header is
678 * present in the list.
681 * 1 : header_list = pointer to list
682 * 2 : header_name = string with name of header to look for.
683 * Trailing colon required, capitalization
686 * Returns : NULL if not found, else value of header
688 *********************************************************************/
689 char *get_header_value(const struct list *header_list, const char *header_name)
691 struct list_entry *cur_entry;
697 length = strlen(header_name);
699 for (cur_entry = header_list->first; cur_entry ; cur_entry = cur_entry->next)
703 if (!strncmpic(cur_entry->str, header_name, length))
706 * Found: return pointer to start of value
708 ret = (char *) (cur_entry->str + length);
709 while (*ret && ijb_isspace(*ret)) ret++;
722 /*********************************************************************
726 * Description : add, delete or modify lines in the HTTP header streams.
727 * On entry, it receives a linked list of headers space
728 * that was allocated dynamically (both the list nodes
729 * and the header contents).
731 * As a side effect it frees the space used by the original
735 * 1 : pats = list of patterns to match against headers
736 * 2 : more_headers = list of functions to add more
737 * headers (client or server)
738 * 3 : csp = Current client state (buffers, headers, etc...)
740 * Returns : Single pointer to a fully formed header, or NULL
741 * on out-of-memory error.
743 *********************************************************************/
744 char *sed(const struct parsers pats[],
745 const add_header_func_ptr more_headers[],
746 struct client_state *csp)
748 struct list_entry *p;
749 const struct parsers *v;
750 const add_header_func_ptr *f;
751 jb_err err = JB_ERR_OK;
753 for (v = pats; (err == JB_ERR_OK) && (v->str != NULL) ; v++)
755 for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL) ; p = p->next)
757 /* Header crunch()ed in previous run? -> ignore */
758 if (p->str == NULL) continue;
760 if (v == pats) log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
762 if (strncmpic(p->str, v->str, v->len) == 0)
764 err = v->parser(csp, (char **)&(p->str));
769 /* place any additional headers on the csp->headers list */
770 for (f = more_headers; (err == JB_ERR_OK) && (*f) ; f++)
775 if (err != JB_ERR_OK)
780 return list_to_text(csp->headers);
784 /* here begins the family of parser functions that reformat header lines */
787 /*********************************************************************
791 * Description : This is called if a header matches a pattern to "crunch"
794 * 1 : csp = Current client state (buffers, headers, etc...)
795 * 2 : header = On input, pointer to header to modify.
796 * On output, pointer to the modified header, or NULL
797 * to remove the header. This function frees the
798 * original string if necessary.
800 * Returns : JB_ERR_OK on success, or
801 * JB_ERR_MEMORY on out-of-memory error.
803 *********************************************************************/
804 jb_err crumble(struct client_state *csp, char **header)
806 log_error(LOG_LEVEL_HEADER, "crunch!");
812 /*********************************************************************
814 * Function : server_content_type
816 * Description : Set the content-type for filterable types (text/.*,
817 * javascript and image/gif) unless filtering has been
818 * forbidden (CT_TABOO) while parsing earlier headers.
821 * 1 : csp = Current client state (buffers, headers, etc...)
822 * 2 : header = On input, pointer to header to modify.
823 * On output, pointer to the modified header, or NULL
824 * to remove the header. This function frees the
825 * original string if necessary.
827 * Returns : JB_ERR_OK on success, or
828 * JB_ERR_MEMORY on out-of-memory error.
830 *********************************************************************/
831 jb_err server_content_type(struct client_state *csp, char **header)
833 if (csp->content_type != CT_TABOO)
835 if (strstr(*header, " text/")
836 || strstr(*header, "application/x-javascript"))
837 csp->content_type = CT_TEXT;
838 else if (strstr(*header, " image/gif"))
839 csp->content_type = CT_GIF;
841 csp->content_type = 0;
848 /*********************************************************************
850 * Function : server_transfer_coding
852 * Description : - Prohibit filtering (CT_TABOO) if transfer coding compresses
853 * - Raise the CSP_FLAG_CHUNKED flag if coding is "chunked"
854 * - Change from "chunked" to "identity" if body was chunked
855 * but has been de-chunked for filtering.
858 * 1 : csp = Current client state (buffers, headers, etc...)
859 * 2 : header = On input, pointer to header to modify.
860 * On output, pointer to the modified header, or NULL
861 * to remove the header. This function frees the
862 * original string if necessary.
864 * Returns : JB_ERR_OK on success, or
865 * JB_ERR_MEMORY on out-of-memory error.
867 *********************************************************************/
868 jb_err server_transfer_coding(struct client_state *csp, char **header)
871 * Turn off pcrs and gif filtering if body compressed
873 if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
875 csp->content_type = CT_TABOO;
879 * Raise flag if body chunked
881 if (strstr(*header, "chunked"))
883 csp->flags |= CSP_FLAG_CHUNKED;
886 * If the body was modified, it has been
887 * de-chunked first, so adjust the header:
889 if (csp->flags & CSP_FLAG_MODIFIED)
892 *header = strdup("Transfer-Encoding: identity");
893 return (header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
901 /*********************************************************************
903 * Function : server_content_encoding
905 * Description : Prohibit filtering (CT_TABOO) if content encoding compresses
908 * 1 : csp = Current client state (buffers, headers, etc...)
909 * 2 : header = On input, pointer to header to modify.
910 * On output, pointer to the modified header, or NULL
911 * to remove the header. This function frees the
912 * original string if necessary.
914 * Returns : JB_ERR_OK on success, or
915 * JB_ERR_MEMORY on out-of-memory error.
917 *********************************************************************/
918 jb_err server_content_encoding(struct client_state *csp, char **header)
921 * Turn off pcrs and gif filtering if body compressed
923 if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
925 csp->content_type = CT_TABOO;
933 /*********************************************************************
935 * Function : server_content_length
937 * Description : Adjust Content-Length header if we modified
941 * 1 : csp = Current client state (buffers, headers, etc...)
942 * 2 : header = On input, pointer to header to modify.
943 * On output, pointer to the modified header, or NULL
944 * to remove the header. This function frees the
945 * original string if necessary.
947 * Returns : JB_ERR_OK on success, or
948 * JB_ERR_MEMORY on out-of-memory error.
950 *********************************************************************/
951 jb_err server_content_length(struct client_state *csp, char **header)
953 if (csp->content_length != 0) /* Content length has been modified */
956 *header = (char *) zalloc(100);
959 return JB_ERR_MEMORY;
962 sprintf(*header, "Content-Length: %d", (int) csp->content_length);
964 log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", (int) csp->content_length);
971 /*********************************************************************
973 * Function : server_content_md5
975 * Description : Crumble any Content-MD5 headers if the document was
976 * modified. FIXME: Should we re-compute instead?
979 * 1 : csp = Current client state (buffers, headers, etc...)
980 * 2 : header = On input, pointer to header to modify.
981 * On output, pointer to the modified header, or NULL
982 * to remove the header. This function frees the
983 * original string if necessary.
985 * Returns : JB_ERR_OK on success, or
986 * JB_ERR_MEMORY on out-of-memory error.
988 *********************************************************************/
989 jb_err server_content_md5(struct client_state *csp, char **header)
991 if (csp->flags & CSP_FLAG_MODIFIED)
993 log_error(LOG_LEVEL_HEADER, "Crunching Content-MD5");
1001 /*********************************************************************
1003 * Function : client_accept_encoding
1005 * Description : Rewrite the client's Accept-Encoding header so that
1006 * if doesn't allow compression, if the action applies.
1007 * Note: For HTTP/1.0 the absence of the header is enough.
1010 * 1 : csp = Current client state (buffers, headers, etc...)
1011 * 2 : header = On input, pointer to header to modify.
1012 * On output, pointer to the modified header, or NULL
1013 * to remove the header. This function frees the
1014 * original string if necessary.
1016 * Returns : JB_ERR_OK on success, or
1017 * JB_ERR_MEMORY on out-of-memory error.
1019 *********************************************************************/
1020 jb_err client_accept_encoding(struct client_state *csp, char **header)
1022 if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1024 log_error(LOG_LEVEL_HEADER, "Suppressed offer to compress content");
1027 if (!strcmpic(csp->http->ver, "HTTP/1.1"))
1029 *header = strdup("Accept-Encoding: identity;q=1.0, *;q=0");
1030 if (*header == NULL)
1032 return JB_ERR_MEMORY;
1041 /*********************************************************************
1043 * Function : client_te
1045 * Description : Rewrite the client's TE header so that
1046 * if doesn't allow compression, if the action applies.
1049 * 1 : csp = Current client state (buffers, headers, etc...)
1050 * 2 : header = On input, pointer to header to modify.
1051 * On output, pointer to the modified header, or NULL
1052 * to remove the header. This function frees the
1053 * original string if necessary.
1055 * Returns : JB_ERR_OK on success, or
1056 * JB_ERR_MEMORY on out-of-memory error.
1058 *********************************************************************/
1059 jb_err client_te(struct client_state *csp, char **header)
1061 if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1064 log_error(LOG_LEVEL_HEADER, "Suppressed offer to compress transfer");
1070 /*********************************************************************
1072 * Function : client_referrer
1074 * Description : Handle the "referer" config setting properly.
1075 * Called from `sed'.
1078 * 1 : csp = Current client state (buffers, headers, etc...)
1079 * 2 : header = On input, pointer to header to modify.
1080 * On output, pointer to the modified header, or NULL
1081 * to remove the header. This function frees the
1082 * original string if necessary.
1084 * Returns : JB_ERR_OK on success, or
1085 * JB_ERR_MEMORY on out-of-memory error.
1087 *********************************************************************/
1088 jb_err client_referrer(struct client_state *csp, char **header)
1092 #ifdef FEATURE_FORCE_LOAD
1093 /* Since the referrer can include the prefix even
1094 * even if the request itself is non-forced, we must
1095 * clean it unconditionally
1097 strclean(*header, FORCE_PREFIX);
1098 #endif /* def FEATURE_FORCE_LOAD */
1101 * Are we sending referer?
1103 if ((csp->action->flags & ACTION_HIDE_REFERER) == 0)
1110 newval = csp->action->string[ACTION_STRING_REFERER];
1112 #ifdef FEATURE_ACTIVITY_CONSOLE
1113 /* Otherwise, we're doing something with the referer. */
1114 accumulate_stats(STATS_REFERER, 1);
1115 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1117 if ((newval == NULL) || (0 == strcmpic(newval, "block")) )
1122 log_error(LOG_LEVEL_HEADER, "crunch!");
1125 else if (0 == strncmpic(newval, "http://", 7))
1128 * We have a specific (fixed) referer we want to send.
1130 log_error(LOG_LEVEL_HEADER, "modified");
1132 *header = strdup("Referer: ");
1133 string_append(header, newval);
1135 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1140 * Forge a referer as http://[hostname:port of REQUEST]/
1141 * to fool stupid checks for in-site links
1143 if (0 != strcmpic(newval, "forge"))
1146 * Invalid choice - but forge is probably the best default.
1148 log_error(LOG_LEVEL_ERROR, "Bad parameter: +referer{%s}", newval);
1151 *header = strdup("Referer: http://");
1152 string_append(header, csp->http->hostport);
1153 string_append(header, "/");
1154 log_error(LOG_LEVEL_HEADER, "crunch+forge to %s", *header);
1156 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1161 /*********************************************************************
1163 * Function : client_uagent
1165 * Description : Handle the "user-agent" config setting properly
1166 * and remember its original value to enable browser
1167 * bug workarounds. Called from `sed'.
1170 * 1 : csp = Current client state (buffers, headers, etc...)
1171 * 2 : header = On input, pointer to header to modify.
1172 * On output, pointer to the modified header, or NULL
1173 * to remove the header. This function frees the
1174 * original string if necessary.
1176 * Returns : JB_ERR_OK on success, or
1177 * JB_ERR_MEMORY on out-of-memory error.
1179 *********************************************************************/
1180 jb_err client_uagent(struct client_state *csp, char **header)
1184 if ((csp->action->flags & ACTION_HIDE_USER_AGENT) == 0)
1189 newval = csp->action->string[ACTION_STRING_USER_AGENT];
1195 log_error(LOG_LEVEL_HEADER, "modified");
1198 *header = strdup("User-Agent: ");
1199 string_append(header, newval);
1201 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1205 /*********************************************************************
1207 * Function : client_ua
1209 * Description : Handle "ua-" headers properly. Called from `sed'.
1212 * 1 : csp = Current client state (buffers, headers, etc...)
1213 * 2 : header = On input, pointer to header to modify.
1214 * On output, pointer to the modified header, or NULL
1215 * to remove the header. This function frees the
1216 * original string if necessary.
1218 * Returns : JB_ERR_OK on success, or
1219 * JB_ERR_MEMORY on out-of-memory error.
1221 *********************************************************************/
1222 jb_err client_ua(struct client_state *csp, char **header)
1224 if ((csp->action->flags & ACTION_HIDE_USER_AGENT) != 0)
1226 #ifdef FEATURE_ACTIVITY_CONSOLE
1227 accumulate_stats(STATS_CLIENT_UA, 1);
1228 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1229 log_error(LOG_LEVEL_HEADER, "crunch!");
1237 /*********************************************************************
1239 * Function : client_from
1241 * Description : Handle the "from" config setting properly.
1242 * Called from `sed'.
1245 * 1 : csp = Current client state (buffers, headers, etc...)
1246 * 2 : header = On input, pointer to header to modify.
1247 * On output, pointer to the modified header, or NULL
1248 * to remove the header. This function frees the
1249 * original string if necessary.
1251 * Returns : JB_ERR_OK on success, or
1252 * JB_ERR_MEMORY on out-of-memory error.
1254 *********************************************************************/
1255 jb_err client_from(struct client_state *csp, char **header)
1259 if ((csp->action->flags & ACTION_HIDE_FROM) == 0)
1264 #ifdef FEATURE_ACTIVITY_CONSOLE
1265 /* Otherwise, we're doing something with it. */
1266 accumulate_stats(STATS_CLIENT_FROM, 1);
1267 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1270 newval = csp->action->string[ACTION_STRING_FROM];
1273 * Are we blocking the e-mail address?
1275 if ((newval == NULL) || (0 == strcmpic(newval, "block")) )
1277 log_error(LOG_LEVEL_HEADER, "crunch!");
1281 log_error(LOG_LEVEL_HEADER, " modified");
1283 *header = strdup("From: ");
1284 string_append(header, newval);
1286 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1290 /*********************************************************************
1292 * Function : client_send_cookie
1294 * Description : Handle the "cookie" header properly. Called from `sed'.
1295 * If cookie is accepted, add it to the cookie_list,
1296 * else we crunch it. Mmmmmmmmmmm ... cookie ......
1299 * 1 : csp = Current client state (buffers, headers, etc...)
1300 * 2 : header = On input, pointer to header to modify.
1301 * On output, pointer to the modified header, or NULL
1302 * to remove the header. This function frees the
1303 * original string if necessary.
1305 * Returns : JB_ERR_OK on success, or
1306 * JB_ERR_MEMORY on out-of-memory error.
1308 *********************************************************************/
1309 jb_err client_send_cookie(struct client_state *csp, char **header)
1311 jb_err result = JB_ERR_OK;
1313 if ((csp->action->flags & ACTION_NO_COOKIE_READ) == 0)
1315 /* strlen("cookie: ") == 8 */
1316 result = enlist(csp->cookie_list, *header + 8);
1320 log_error(LOG_LEVEL_HEADER, "Crunched outgoing cookie -- yum!");
1324 * Always remove the cookie here. The cookie header
1325 * will be sent at the end of the header.
1333 /*********************************************************************
1335 * Function : client_x_forwarded
1337 * Description : Handle the "x-forwarded-for" config setting properly,
1338 * also used in the add_client_headers list. Called from `sed'.
1341 * 1 : csp = Current client state (buffers, headers, etc...)
1342 * 2 : header = On input, pointer to header to modify.
1343 * On output, pointer to the modified header, or NULL
1344 * to remove the header. This function frees the
1345 * original string if necessary.
1347 * Returns : JB_ERR_OK on success, or
1348 * JB_ERR_MEMORY on out-of-memory error.
1350 *********************************************************************/
1351 jb_err client_x_forwarded(struct client_state *csp, char **header)
1353 if ((csp->action->flags & ACTION_HIDE_FORWARDED) == 0)
1355 /* Save it so we can re-add it later */
1356 freez(csp->x_forwarded);
1357 csp->x_forwarded = *header;
1360 * Always set *header = NULL, since this information
1361 * will be sent at the end of the header.
1368 #ifdef FEATURE_ACTIVITY_CONSOLE
1369 accumulate_stats(STATS_CLIENT_X_FORWARDED, 1);
1370 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1371 log_error(LOG_LEVEL_HEADER, " crunch!");
1377 /* the following functions add headers directly to the header list */
1379 /*********************************************************************
1381 * Function : client_host_adder
1383 * Description : (re)adds the host header. Called from `sed'.
1386 * 1 : csp = Current client state (buffers, headers, etc...)
1388 * Returns : JB_ERR_OK on success, or
1389 * JB_ERR_MEMORY on out-of-memory error.
1391 *********************************************************************/
1392 jb_err client_host_adder(struct client_state *csp)
1398 if ( !csp->http->hostport || !*(csp->http->hostport))
1403 p = strdup("Host: ");
1405 ** remove 'user:pass@' from 'proto://user:pass@host'
1407 if ( (pos = strchr( csp->http->hostport, '@')) != NULL )
1409 string_append(&p, pos+1);
1413 string_append(&p, csp->http->hostport);
1418 return JB_ERR_MEMORY;
1421 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1423 err = enlist(csp->headers, p);
1431 /*********************************************************************
1433 * Function : client_cookie_adder
1435 * Description : Used in the add_client_headers list. Called from `sed'.
1438 * 1 : csp = Current client state (buffers, headers, etc...)
1440 * Returns : JB_ERR_OK on success, or
1441 * JB_ERR_MEMORY on out-of-memory error.
1443 *********************************************************************/
1444 jb_err client_cookie_adder(struct client_state *csp)
1446 struct list_entry *lst;
1448 struct list_entry *list1 = csp->cookie_list->first;
1449 struct list_entry *list2 = csp->action->multi[ACTION_MULTI_WAFER]->first;
1450 int first_cookie = 1;
1453 if ((list1 == NULL) && (list2 == NULL))
1459 tmp = strdup("Cookie: ");
1461 for (lst = list1; lst ; lst = lst->next)
1469 string_append(&tmp, "; ");
1471 string_append(&tmp, lst->str);
1474 for (lst = list2; lst ; lst = lst->next)
1482 string_append(&tmp, "; ");
1484 string_join(&tmp, cookie_encode(lst->str));
1489 return JB_ERR_MEMORY;
1492 log_error(LOG_LEVEL_HEADER, "addh: %s", tmp);
1493 err = enlist(csp->headers, tmp);
1499 /*********************************************************************
1501 * Function : client_accept_encoding_adder
1503 * Description : Add an Accept-Encoding header to the client's request
1504 * that disables compression if the action applies, and
1505 * the header is not already there. Called from `sed'.
1506 * Note: For HTTP/1.0, the absence of the header is enough.
1509 * 1 : csp = Current client state (buffers, headers, etc...)
1511 * Returns : JB_ERR_OK on success, or
1512 * JB_ERR_MEMORY on out-of-memory error.
1514 *********************************************************************/
1515 jb_err client_accept_encoding_adder(struct client_state *csp)
1517 if ( ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1518 && (!strcmpic(csp->http->ver, "HTTP/1.1")) )
1520 return enlist_unique(csp->headers, "Accept-Encoding: identity;q=1.0, *;q=0", 16);
1527 /*********************************************************************
1529 * Function : client_xtra_adder
1531 * Description : Used in the add_client_headers list. Called from `sed'.
1534 * 1 : csp = Current client state (buffers, headers, etc...)
1536 * Returns : JB_ERR_OK on success, or
1537 * JB_ERR_MEMORY on out-of-memory error.
1539 *********************************************************************/
1540 jb_err client_xtra_adder(struct client_state *csp)
1542 struct list_entry *lst;
1545 for (lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]->first;
1546 lst ; lst = lst->next)
1548 log_error(LOG_LEVEL_HEADER, "addh: %s", lst->str);
1549 err = enlist(csp->headers, lst->str);
1561 /*********************************************************************
1563 * Function : client_x_forwarded_adder
1565 * Description : Used in the add_client_headers list. Called from `sed'.
1568 * 1 : csp = Current client state (buffers, headers, etc...)
1570 * Returns : JB_ERR_OK on success, or
1571 * JB_ERR_MEMORY on out-of-memory error.
1573 *********************************************************************/
1574 jb_err client_x_forwarded_adder(struct client_state *csp)
1579 if ((csp->action->flags & ACTION_HIDE_FORWARDED) != 0)
1584 if (csp->x_forwarded)
1586 p = strdup(csp->x_forwarded);
1587 string_append(&p, ", ");
1591 p = strdup("X-Forwarded-For: ");
1593 string_append(&p, csp->ip_addr_str);
1597 return JB_ERR_MEMORY;
1600 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1601 err = enlist(csp->headers, p);
1608 /*********************************************************************
1610 * Function : connection_close_adder
1612 * Description : Adds a "Connection: close" header to csp->headers
1613 * as a temporary fix for the needed but missing HTTP/1.1
1614 * support. Called from `sed'.
1615 * FIXME: This whole function shouldn't be neccessary!
1618 * 1 : csp = Current client state (buffers, headers, etc...)
1620 * Returns : JB_ERR_OK on success, or
1621 * JB_ERR_MEMORY on out-of-memory error.
1623 *********************************************************************/
1624 jb_err connection_close_adder(struct client_state *csp)
1626 return enlist(csp->headers, "Connection: close");
1630 /*********************************************************************
1632 * Function : server_http
1634 * Description : - Save the HTTP Status into csp->http->status
1635 * - Set CT_TABOO to prevent filtering if the answer
1636 * is a partial range (HTTP status 206)
1637 * - Rewrite HTTP/1.1 answers to HTTP/1.0 if +downgrade
1641 * 1 : csp = Current client state (buffers, headers, etc...)
1642 * 2 : header = On input, pointer to header to modify.
1643 * On output, pointer to the modified header, or NULL
1644 * to remove the header. This function frees the
1645 * original string if necessary.
1647 * Returns : JB_ERR_OK on success, or
1648 * JB_ERR_MEMORY on out-of-memory error.
1650 *********************************************************************/
1651 jb_err server_http(struct client_state *csp, char **header)
1653 sscanf(*header, "HTTP/%*d.%*d %d", &(csp->http->status));
1654 if (csp->http->status == 206)
1656 csp->content_type = CT_TABOO;
1659 if ((csp->action->flags & ACTION_DOWNGRADE) != 0)
1662 log_error(LOG_LEVEL_HEADER, "Downgraded answer to HTTP/1.0");
1669 /*********************************************************************
1671 * Function : server_set_cookie
1673 * Description : Handle the server "cookie" header properly.
1674 * Log cookie to the jar file. Then "crunch" it,
1675 * or accept it. Called from `sed'.
1678 * 1 : csp = Current client state (buffers, headers, etc...)
1679 * 2 : header = On input, pointer to header to modify.
1680 * On output, pointer to the modified header, or NULL
1681 * to remove the header. This function frees the
1682 * original string if necessary.
1684 * Returns : JB_ERR_OK on success, or
1685 * JB_ERR_MEMORY on out-of-memory error.
1687 *********************************************************************/
1688 jb_err server_set_cookie(struct client_state *csp, char **header)
1690 #ifdef FEATURE_COOKIE_JAR
1691 if (csp->config->jar)
1694 * Write timestamp into outbuf.
1696 * Complex because not all OSs have tm_gmtoff or
1697 * the %z field in strftime()
1699 char tempbuf[ BUFFER_SIZE ];
1703 #ifdef HAVE_LOCALTIME_R
1704 tm_now = *localtime_r(&now, &tm_now);
1706 pthread_mutex_lock(&localtime_mutex);
1707 tm_now = *localtime (&now);
1708 pthread_mutex_unlock(&localtime_mutex);
1710 tm_now = *localtime (&now);
1712 strftime(tempbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1714 /* strlen("set-cookie: ") = 12 */
1715 fprintf(csp->config->jar, "%s %s\t%s\n", tempbuf, csp->http->host, *header + 12);
1717 #endif /* def FEATURE_COOKIE_JAR */
1719 if ((csp->action->flags & ACTION_NO_COOKIE_SET) != 0)
1721 log_error(LOG_LEVEL_HEADER, "Crunched incoming cookie -- yum!");
1722 #ifdef FEATURE_ACTIVITY_CONSOLE
1723 accumulate_stats(STATS_COOKIE, 1);
1724 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1725 return crumble(csp, header);
1727 else if ((csp->action->flags & ACTION_NO_COOKIE_KEEP) != 0)
1729 /* Flag whether or not to log a message */
1732 /* A variable to store the tag we're working on */
1735 /* Skip "Set-Cookie:" (11 characters) in header */
1736 cur_tag = *header + 11;
1738 /* skip whitespace between "Set-Cookie:" and value */
1739 while (*cur_tag && ijb_isspace(*cur_tag))
1744 /* Loop through each tag in the cookie */
1748 char *next_tag = strchr(cur_tag, ';');
1749 if (next_tag != NULL)
1751 /* Skip the ';' character itself */
1754 /* skip whitespace ";" and start of tag */
1755 while (*next_tag && ijb_isspace(*next_tag))
1762 /* "Next tag" is the end of the string */
1763 next_tag = cur_tag + strlen(cur_tag);
1766 /* Is this the "Expires" tag? */
1767 if (strncmpic(cur_tag, "expires=", 8) == 0)
1769 /* Delete the tag by copying the rest of the string over it.
1770 * (Note that we cannot just use "strcpy(cur_tag, next_tag)",
1771 * since the behaviour of strcpy is undefined for overlapping
1774 memmove(cur_tag, next_tag, strlen(next_tag) + 1);
1776 /* That changed the header, need to issue a log message */
1779 /* Note that the next tag has now been moved to *cur_tag,
1780 * so we do not need to update the cur_tag pointer.
1785 /* Move on to next cookie tag */
1792 log_error(LOG_LEVEL_HEADER, "Changed cookie to a temporary one.");
1800 #ifdef FEATURE_FORCE_LOAD
1801 /*********************************************************************
1803 * Function : strclean
1805 * Description : In-Situ-Eliminate all occurances of substring in
1809 * 1 : string = string to clean
1810 * 2 : substring = substring to eliminate
1812 * Returns : Number of eliminations
1814 *********************************************************************/
1815 int strclean(const char *string, const char *substring)
1817 int hits = 0, len = strlen(substring);
1820 while((pos = strstr(string, substring)) != NULL)
1827 while (*p++ != '\0');
1834 #endif /* def FEATURE_FORCE_LOAD */