1 const char parsers_rcs[] = "$Id: parsers.c,v 2.6 2003/10/02 19:41:23 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.6 2003/10/02 19:41:23 david__schmidt
44 * Updated header debug logging to show the header text that is
45 * being crunched; refactored functions in parsers.c to have a
46 * single, common exit point
48 * Revision 2.5 2003/09/25 01:44:33 david__schmidt
49 * Resyncing HEAD with v_3_0_branch for two OSX fixes:
50 * Making thread IDs look sane in the logfile for Mach kernels,
51 * and fixing multithreading crashes due to thread-unsafe
55 * Revision 2.4 2003/01/26 20:24:26 david__schmidt
56 * Updated activity console instrumentation locations
58 * Revision 2.3 2002/12/28 03:58:19 david__schmidt
59 * Initial drop of dashboard instrumentation - enabled with
60 * --enable-activity-console
62 * Revision 2.2 2002/11/10 04:20:38 hal9
63 * Fix typo: supressed -> suppressed
65 * Revision 2.1 2002/09/11 11:23:59 oes
66 * Fixed logging of cookies: Killed incoming cookies now logged; incoming/outgoing cookies now distinguished in log
68 * Revision 2.0 2002/06/04 14:34:21 jongfoster
69 * Moving source files to src/
71 * Revision 1.56 2002/05/12 15:34:22 jongfoster
72 * Fixing typo in a comment
74 * Revision 1.55 2002/05/08 16:01:07 oes
75 * Optimized add_to_iob:
76 * - Use realloc instead of malloc(), memcpy(), free()
77 * - Expand to powers of two if possible, to get
78 * O(log n) reallocs instead of O(n).
79 * - Moved check for buffer limit here from chat
80 * - Report failure via returncode
82 * Revision 1.54 2002/04/02 15:03:16 oes
85 * Revision 1.53 2002/03/26 22:29:55 swa
86 * we have a new homepage!
88 * Revision 1.52 2002/03/24 13:25:43 swa
89 * name change related issues
91 * Revision 1.51 2002/03/13 00:27:05 jongfoster
94 * Revision 1.50 2002/03/12 01:45:35 oes
95 * More verbose logging
97 * Revision 1.49 2002/03/09 20:03:52 jongfoster
98 * - Making various functions return int rather than size_t.
99 * (Undoing a recent change). Since size_t is unsigned on
100 * Windows, functions like read_socket that return -1 on
101 * error cannot return a size_t.
103 * THIS WAS A MAJOR BUG - it caused frequent, unpredictable
104 * crashes, and also frequently caused JB to jump to 100%
105 * CPU and stay there. (Because it thought it had just
106 * read ((unsigned)-1) == 4Gb of data...)
108 * - The signature of write_socket has changed, it now simply
109 * returns success=0/failure=nonzero.
111 * - Trying to get rid of a few warnings --with-debug on
112 * Windows, I've introduced a new type "jb_socket". This is
113 * used for the socket file descriptors. On Windows, this
114 * is SOCKET (a typedef for unsigned). Everywhere else, it's
115 * an int. The error value can't be -1 any more, so it's
116 * now JB_INVALID_SOCKET (which is -1 on UNIX, and in
117 * Windows it maps to the #define INVALID_SOCKET.)
119 * - The signature of bind_port has changed.
121 * Revision 1.48 2002/03/07 03:46:53 oes
122 * Fixed compiler warnings etc
124 * Revision 1.47 2002/02/20 23:15:13 jongfoster
125 * Parsing functions now handle out-of-memory gracefully by returning
128 * Revision 1.46 2002/01/17 21:03:47 jongfoster
129 * Moving all our URL and URL pattern parsing code to urlmatch.c.
131 * Revision 1.45 2002/01/09 14:33:03 oes
132 * Added support for localtime_r.
134 * Revision 1.44 2001/12/14 01:22:54 steudten
135 * Remove 'user:pass@' from 'proto://user:pass@host' for the
136 * new added header 'Host: ..'. (See Req ID 491818)
138 * Revision 1.43 2001/11/23 00:26:38 jongfoster
139 * Fixing two really stupid errors in my previous commit
141 * Revision 1.42 2001/11/22 21:59:30 jongfoster
142 * Adding code to handle +no-cookies-keep
144 * Revision 1.41 2001/11/05 23:43:05 steudten
145 * Add time+date to log files.
147 * Revision 1.40 2001/10/26 20:13:09 jongfoster
148 * ctype.h is needed in Windows, too.
150 * Revision 1.39 2001/10/26 17:40:04 oes
151 * Introduced get_header_value()
152 * Removed http->user_agent, csp->referrer and csp->accept_types
153 * Removed client_accept()
155 * Revision 1.38 2001/10/25 03:40:48 david__schmidt
156 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
157 * threads to call select() simultaneously. So, it's time to do a real, live,
158 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
159 * (native). Both versions will work, but using __OS2__ offers multi-threading.
161 * Revision 1.37 2001/10/23 21:36:02 jongfoster
162 * Documenting sed()'s error behaviou (doc change only)
164 * Revision 1.36 2001/10/13 12:51:51 joergs
165 * Removed client_host, (was only required for the old 2.0.2-11 http://noijb.
166 * force-load), instead crumble Host: and add it (again) in client_host_adder
167 * (in case we get a HTTP/1.0 request without Host: header and forward it to
168 * a HTTP/1.1 server/proxy).
170 * Revision 1.35 2001/10/09 22:39:21 jongfoster
171 * assert.h is also required under Win32, so moving out of #ifndef _WIN32
174 * Revision 1.34 2001/10/07 18:50:55 oes
175 * Added server_content_encoding, renamed server_transfer_encoding
177 * Revision 1.33 2001/10/07 18:04:49 oes
178 * Changed server_http11 to server_http and its pattern to "HTTP".
179 * Additional functionality: it now saves the HTTP status into
180 * csp->http->status and sets CT_TABOO for Status 206 (partial range)
182 * Revision 1.32 2001/10/07 15:43:28 oes
183 * Removed FEATURE_DENY_GZIP and replaced it with client_accept_encoding,
184 * client_te and client_accept_encoding_adder, triggered by the new
185 * +no-compression action. For HTTP/1.1 the Accept-Encoding header is
186 * changed to allow only identity and chunked, and the TE header is
187 * crunched. For HTTP/1.0, Accept-Encoding is crunched.
189 * parse_http_request no longer does anything than parsing. The rewriting
190 * of http->cmd and version mangling are gone. It now also recognizes
191 * the put and delete methods and saves the url in http->url. Removed
194 * renamed content_type and content_length to have the server_ prefix
196 * server_content_type now only works if csp->content_type != CT_TABOO
198 * added server_transfer_encoding, which
199 * - Sets CT_TABOO to prohibit filtering if encoding compresses
200 * - Raises the CSP_FLAG_CHUNKED flag if Encoding is "chunked"
201 * - Change from "chunked" to "identity" if body was chunked
202 * but has been de-chunked for filtering.
204 * added server_content_md5 which crunches any Content-MD5 headers
205 * if the body was modified.
207 * made server_http11 conditional on +downgrade action
209 * Replaced 6 boolean members of csp with one bitmap (csp->flags)
211 * Revision 1.31 2001/10/05 14:25:02 oes
212 * Crumble Keep-Alive from Server
214 * Revision 1.30 2001/09/29 12:56:03 joergs
215 * IJB now changes HTTP/1.1 to HTTP/1.0 in requests and answers.
217 * Revision 1.29 2001/09/24 21:09:24 jongfoster
218 * Fixing 2 memory leaks that Guy spotted, where the paramater to
219 * enlist() was not being free()d.
221 * Revision 1.28 2001/09/22 16:32:28 jongfoster
222 * Removing unused #includes.
224 * Revision 1.27 2001/09/20 15:45:25 steudten
226 * add casting from size_t to int for printf()
227 * remove local variable shadow s2
229 * Revision 1.26 2001/09/16 17:05:14 jongfoster
230 * Removing unused #include showarg.h
232 * Revision 1.25 2001/09/16 13:21:27 jongfoster
233 * Changes to use new list functions.
235 * Revision 1.24 2001/09/13 23:05:50 jongfoster
236 * Changing the string paramater to the header parsers a "const".
238 * Revision 1.23 2001/09/12 18:08:19 steudten
240 * In parse_http_request() header rewriting miss the host value, so
241 * from http://www.mydomain.com the result was just " / " not
242 * http://www.mydomain.com/ in case we forward.
244 * Revision 1.22 2001/09/10 10:58:53 oes
245 * Silenced compiler warnings
247 * Revision 1.21 2001/07/31 14:46:00 oes
248 * - Persistant connections now suppressed
249 * - sed() no longer appends empty header to csp->headers
251 * Revision 1.20 2001/07/30 22:08:36 jongfoster
252 * Tidying up #defines:
253 * - All feature #defines are now of the form FEATURE_xxx
254 * - Permanently turned off WIN_GUI_EDIT
255 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
257 * Revision 1.19 2001/07/25 17:21:54 oes
258 * client_uagent now saves copy of User-Agent: header value
260 * Revision 1.18 2001/07/13 14:02:46 oes
261 * - Included fix to repair broken HTTP requests that
262 * don't contain a path, not even '/'.
263 * - Removed all #ifdef PCRS
264 * - content_type now always inspected and classified as
265 * text, gif or other.
266 * - formatting / comments
268 * Revision 1.17 2001/06/29 21:45:41 oes
269 * Indentation, CRLF->LF, Tab-> Space
271 * Revision 1.16 2001/06/29 13:32:42 oes
273 * - Adapted free_http_request
274 * - Removed logentry from cancelled commit
276 * Revision 1.15 2001/06/03 19:12:38 oes
277 * deleted const struct interceptors
279 * Revision 1.14 2001/06/01 18:49:17 jongfoster
280 * Replaced "list_share" with "list" - the tiny memory gain was not
281 * worth the extra complexity.
283 * Revision 1.13 2001/05/31 21:30:33 jongfoster
284 * Removed list code - it's now in list.[ch]
285 * Renamed "permission" to "action", and changed many features
286 * to use the actions file rather than the global config.
288 * Revision 1.12 2001/05/31 17:33:13 oes
292 * Revision 1.11 2001/05/29 20:11:19 joergs
293 * '/ * inside comment' warning removed.
295 * Revision 1.10 2001/05/29 09:50:24 jongfoster
296 * Unified blocklist/imagelist/permissionslist.
297 * File format is still under discussion, but the internal changes
300 * Also modified interceptor behaviour:
301 * - We now intercept all URLs beginning with one of the following
302 * prefixes (and *only* these prefixes):
304 * * http://ijbswa.sf.net/config/
305 * * http://ijbswa.sourceforge.net/config/
306 * - New interceptors "home page" - go to http://i.j.b/ to see it.
307 * - Internal changes so that intercepted and fast redirect pages
308 * are not replaced with an image.
309 * - Interceptors now have the option to send a binary page direct
310 * to the client. (i.e. ijb-send-banner uses this)
311 * - Implemented show-url-info interceptor. (Which is why I needed
312 * the above interceptors changes - a typical URL is
313 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
314 * The previous mechanism would not have intercepted that, and
315 * if it had been intercepted then it then it would have replaced
318 * Revision 1.9 2001/05/28 17:26:33 jongfoster
319 * Fixing segfault if last header was crunched.
320 * Fixing Windows build (snprintf() is _snprintf() under Win32, but we
321 * can use the cross-platform sprintf() instead.)
323 * Revision 1.8 2001/05/27 22:17:04 oes
325 * - re_process_buffer no longer writes the modified buffer
326 * to the client, which was very ugly. It now returns the
327 * buffer, which it is then written by chat.
329 * - content_length now adjusts the Content-Length: header
330 * for modified documents rather than crunch()ing it.
331 * (Length info in csp->content_length, which is 0 for
332 * unmodified documents)
334 * - For this to work, sed() is called twice when filtering.
336 * Revision 1.7 2001/05/27 13:19:06 oes
337 * Patched Joergs solution for the content-length in.
339 * Revision 1.6 2001/05/26 13:39:32 jongfoster
340 * Only crunches Content-Length header if applying RE filtering.
341 * Without this fix, Microsoft Windows Update wouldn't work.
343 * Revision 1.5 2001/05/26 00:28:36 jongfoster
344 * Automatic reloading of config file.
345 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
346 * Most of the global variables have been moved to a new
347 * struct configuration_spec, accessed through csp->config->globalname
348 * Most of the globals remaining are used by the Win32 GUI.
350 * Revision 1.4 2001/05/22 18:46:04 oes
352 * - Enabled filtering banners by size rather than URL
353 * by adding patterns that replace all standard banner
354 * sizes with the "Junkbuster" gif to the re_filterfile
356 * - Enabled filtering WebBugs by providing a pattern
357 * which kills all 1x1 images
359 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
360 * which is selected by the (nonstandard and therefore
361 * capital) letter 'U' in the option string.
362 * It causes the quantifiers to be ungreedy by default.
363 * Appending a ? turns back to greedy (!).
365 * - Added a new interceptor ijb-send-banner, which
366 * sends back the "Junkbuster" gif. Without imagelist or
367 * MSIE detection support, or if tinygif = 1, or the
368 * URL isn't recognized as an imageurl, a lame HTML
369 * explanation is sent instead.
371 * - Added new feature, which permits blocking remote
372 * script redirects and firing back a local redirect
374 * The feature is conditionally compiled, i.e. it
375 * can be disabled with --disable-fast-redirects,
376 * plus it must be activated by a "fast-redirects"
377 * line in the config file, has its own log level
378 * and of course wants to be displayed by show-proxy-args
379 * Note: Boy, all the #ifdefs in 1001 locations and
380 * all the fumbling with configure.in and acconfig.h
381 * were *way* more work than the feature itself :-(
383 * - Because a generic redirect template was needed for
384 * this, tinygif = 3 now uses the same.
386 * - Moved GIFs, and other static HTTP response templates
391 * - Removed some >400 CRs again (Jon, you really worked
394 * Revision 1.3 2001/05/20 01:21:20 jongfoster
395 * Version 2.9.4 checkin.
396 * - Merged popupfile and cookiefile, and added control over PCRS
397 * filtering, in new "permissionsfile".
398 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
399 * file error you now get a message box (in the Win32 GUI) rather
400 * than the program exiting with no explanation.
401 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
403 * - Removed tabs from "config"
404 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
405 * - Bumped up version number.
407 * Revision 1.2 2001/05/17 23:02:36 oes
408 * - Made referrer option accept 'L' as a substitute for '§'
410 * Revision 1.1.1.1 2001/05/15 13:59:01 oes
411 * Initial import of version 2.9.3 source tree
414 *********************************************************************/
421 #include <sys/types.h>
429 #if !defined(_WIN32) && !defined(__OS2__)
436 /* jcc.h is for mutex semapores only */
437 #endif /* def OSX_DARWIN */
444 #include "jbsockets.h"
445 #include "miscutil.h"
447 #ifdef FEATURE_ACTIVITY_CONSOLE
449 #endif /* def FEATURE_ACTIVITY_CONSOLE */
451 const char parsers_h_rcs[] = PARSERS_H_VERSION;
453 /* Fix a problem with Solaris. There should be no effect on other
455 * Solaris's isspace() is a macro which uses it's argument directly
456 * as an array index. Therefore we need to make sure that high-bit
457 * characters generate +ve values, and ideally we also want to make
458 * the argument match the declared parameter type of "int".
460 * Why did they write a character function that can't take a simple
461 * "char" argument? Doh!
463 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
464 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
467 const struct parsers client_patterns[] = {
468 { "referer:", 8, client_referrer },
469 { "user-agent:", 11, client_uagent },
470 { "ua-", 3, client_ua },
471 { "from:", 5, client_from },
472 { "cookie:", 7, client_send_cookie },
473 { "x-forwarded-for:", 16, client_x_forwarded },
474 { "Accept-Encoding:", 16, client_accept_encoding },
475 { "TE:", 3, client_te },
476 { "Host:", 5, crumble },
477 /* { "if-modified-since:", 18, crumble }, */
478 { "Keep-Alive:", 11, crumble },
479 { "connection:", 11, crumble },
480 { "proxy-connection:", 17, crumble },
485 const struct parsers server_patterns[] = {
486 { "HTTP", 4, server_http },
487 { "set-cookie:", 11, server_set_cookie },
488 { "connection:", 11, crumble },
489 { "Content-Type:", 13, server_content_type },
490 { "Content-Length:", 15, server_content_length },
491 { "Content-MD5:", 12, server_content_md5 },
492 { "Content-Encoding:", 17, server_content_encoding },
493 { "Transfer-Encoding:", 18, server_transfer_coding },
494 { "Keep-Alive:", 11, crumble },
499 const add_header_func_ptr add_client_headers[] = {
502 client_x_forwarded_adder,
504 client_accept_encoding_adder,
505 connection_close_adder,
510 const add_header_func_ptr add_server_headers[] = {
511 connection_close_adder,
516 /*********************************************************************
518 * Function : flush_socket
520 * Description : Write any pending "buffered" content.
523 * 1 : fd = file descriptor of the socket to read
524 * 2 : csp = Current client state (buffers, headers, etc...)
526 * Returns : On success, the number of bytes written are returned (zero
527 * indicates nothing was written). On error, -1 is returned,
528 * and errno is set appropriately. If count is zero and the
529 * file descriptor refers to a regular file, 0 will be
530 * returned without causing any other effect. For a special
531 * file, the results are not portable.
533 *********************************************************************/
534 int flush_socket(jb_socket fd, struct client_state *csp)
536 struct iob *iob = csp->iob;
537 int len = iob->eod - iob->cur;
544 if (write_socket(fd, iob->cur, (size_t)len))
548 iob->eod = iob->cur = iob->buf;
554 /*********************************************************************
556 * Function : add_to_iob
558 * Description : Add content to the buffered page, expanding the
559 * buffer if necessary.
562 * 1 : csp = Current client state (buffers, headers, etc...)
563 * 2 : buf = holds the content to be added to the page
564 * 3 : n = number of bytes to be added
566 * Returns : JB_ERR_OK on success, JB_ERR_MEMORY if out-of-memory
567 * or buffer limit reached.
569 *********************************************************************/
570 jb_err add_to_iob(struct client_state *csp, char *buf, int n)
572 struct iob *iob = csp->iob;
573 size_t used, offset, need, want;
576 if (n <= 0) return JB_ERR_OK;
578 used = iob->eod - iob->buf;
579 offset = iob->cur - iob->buf;
583 * If the buffer can't hold the new data, extend it first.
584 * Use the next power of two if possible, else use the actual need.
586 if (need > csp->config->buffer_limit)
588 log_error(LOG_LEVEL_ERROR, "Buffer limit reached while extending the buffer (iob)");
589 return JB_ERR_MEMORY;
592 if (need > iob->size)
594 for (want = csp->iob->size ? csp->iob->size : 512; want <= need;) want *= 2;
596 if (want <= csp->config->buffer_limit && NULL != (p = (char *)realloc(iob->buf, want)))
600 else if (NULL != (p = (char *)realloc(iob->buf, need)))
606 log_error(LOG_LEVEL_ERROR, "Extending the buffer (iob) failed: %E");
607 return JB_ERR_MEMORY;
610 /* Update the iob pointers */
611 iob->cur = p + offset;
616 /* copy the new data into the iob buffer */
617 memcpy(iob->eod, buf, (size_t)n);
619 /* point to the end of the data */
622 /* null terminate == cheap insurance */
630 /*********************************************************************
632 * Function : get_header
634 * Description : This (odd) routine will parse the csp->iob
637 * 1 : csp = Current client state (buffers, headers, etc...)
639 * Returns : Any one of the following:
641 * 1) a pointer to a dynamically allocated string that contains a header line
642 * 2) NULL indicating that the end of the header was reached
643 * 3) "" indicating that the end of the iob was reached before finding
644 * a complete header line.
646 *********************************************************************/
647 char *get_header(struct client_state *csp)
653 if ((iob->cur == NULL)
654 || ((p = strchr(iob->cur, '\n')) == NULL))
656 return(""); /* couldn't find a complete header */
661 ret = strdup(iob->cur);
664 /* FIXME No way to handle error properly */
665 log_error(LOG_LEVEL_FATAL, "Out of memory in get_header()");
670 if ((q = strchr(ret, '\r')) != NULL) *q = '\0';
672 /* is this a blank line (i.e. the end of the header) ? */
684 /*********************************************************************
686 * Function : get_header_value
688 * Description : Get the value of a given header from a chained list
689 * of header lines or return NULL if no such header is
690 * present in the list.
693 * 1 : header_list = pointer to list
694 * 2 : header_name = string with name of header to look for.
695 * Trailing colon required, capitalization
698 * Returns : NULL if not found, else value of header
700 *********************************************************************/
701 char *get_header_value(const struct list *header_list, const char *header_name)
703 struct list_entry *cur_entry;
709 length = strlen(header_name);
711 for (cur_entry = header_list->first; cur_entry ; cur_entry = cur_entry->next)
715 if (!strncmpic(cur_entry->str, header_name, length))
718 * Found: return pointer to start of value
720 ret = (char *) (cur_entry->str + length);
721 while (*ret && ijb_isspace(*ret)) ret++;
734 /*********************************************************************
738 * Description : add, delete or modify lines in the HTTP header streams.
739 * On entry, it receives a linked list of headers space
740 * that was allocated dynamically (both the list nodes
741 * and the header contents).
743 * As a side effect it frees the space used by the original
747 * 1 : pats = list of patterns to match against headers
748 * 2 : more_headers = list of functions to add more
749 * headers (client or server)
750 * 3 : csp = Current client state (buffers, headers, etc...)
752 * Returns : Single pointer to a fully formed header, or NULL
753 * on out-of-memory error.
755 *********************************************************************/
756 char *sed(const struct parsers pats[],
757 const add_header_func_ptr more_headers[],
758 struct client_state *csp)
760 struct list_entry *p;
761 const struct parsers *v;
762 const add_header_func_ptr *f;
763 jb_err err = JB_ERR_OK;
765 for (v = pats; (err == JB_ERR_OK) && (v->str != NULL) ; v++)
767 for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL) ; p = p->next)
769 /* Header crunch()ed in previous run? -> ignore */
770 if (p->str == NULL) continue;
772 if (v == pats) log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
774 if (strncmpic(p->str, v->str, v->len) == 0)
776 err = v->parser(csp, (char **)&(p->str));
781 /* place any additional headers on the csp->headers list */
782 for (f = more_headers; (err == JB_ERR_OK) && (*f) ; f++)
787 if (err != JB_ERR_OK)
792 return list_to_text(csp->headers);
796 /* here begins the family of parser functions that reformat header lines */
799 /*********************************************************************
803 * Description : This is called if a header matches a pattern to "crunch"
806 * 1 : csp = Current client state (buffers, headers, etc...)
807 * 2 : header = On input, pointer to header to modify.
808 * On output, pointer to the modified header, or NULL
809 * to remove the header. This function frees the
810 * original string if necessary.
812 * Returns : JB_ERR_OK on success, or
813 * JB_ERR_MEMORY on out-of-memory error.
815 *********************************************************************/
816 jb_err crumble(struct client_state *csp, char **header)
818 log_error(LOG_LEVEL_HEADER, "crunch: %s",*header);
824 /*********************************************************************
826 * Function : server_content_type
828 * Description : Set the content-type for filterable types (text/.*,
829 * javascript and image/gif) unless filtering has been
830 * forbidden (CT_TABOO) while parsing earlier headers.
833 * 1 : csp = Current client state (buffers, headers, etc...)
834 * 2 : header = On input, pointer to header to modify.
835 * On output, pointer to the modified header, or NULL
836 * to remove the header. This function frees the
837 * original string if necessary.
839 * Returns : JB_ERR_OK on success, or
840 * JB_ERR_MEMORY on out-of-memory error.
842 *********************************************************************/
843 jb_err server_content_type(struct client_state *csp, char **header)
845 if (csp->content_type != CT_TABOO)
847 if (strstr(*header, " text/")
848 || strstr(*header, "application/x-javascript"))
849 csp->content_type = CT_TEXT;
850 else if (strstr(*header, " image/gif"))
851 csp->content_type = CT_GIF;
852 else if (strstr(*header, " image/jpeg"))
853 csp->content_type = CT_JPEG;
855 csp->content_type = 0;
862 /*********************************************************************
864 * Function : server_transfer_coding
866 * Description : - Prohibit filtering (CT_TABOO) if transfer coding compresses
867 * - Raise the CSP_FLAG_CHUNKED flag if coding is "chunked"
868 * - Change from "chunked" to "identity" if body was chunked
869 * but has been de-chunked for filtering.
872 * 1 : csp = Current client state (buffers, headers, etc...)
873 * 2 : header = On input, pointer to header to modify.
874 * On output, pointer to the modified header, or NULL
875 * to remove the header. This function frees the
876 * original string if necessary.
878 * Returns : JB_ERR_OK on success, or
879 * JB_ERR_MEMORY on out-of-memory error.
881 *********************************************************************/
882 jb_err server_transfer_coding(struct client_state *csp, char **header)
885 * Turn off pcrs and gif filtering if body compressed
887 if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
889 csp->content_type = CT_TABOO;
893 * Raise flag if body chunked
895 if (strstr(*header, "chunked"))
897 csp->flags |= CSP_FLAG_CHUNKED;
900 * If the body was modified, it has been
901 * de-chunked first, so adjust the header:
903 if (csp->flags & CSP_FLAG_MODIFIED)
906 *header = strdup("Transfer-Encoding: identity");
907 return (header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
915 /*********************************************************************
917 * Function : server_content_encoding
919 * Description : Prohibit filtering (CT_TABOO) if content encoding compresses
922 * 1 : csp = Current client state (buffers, headers, etc...)
923 * 2 : header = On input, pointer to header to modify.
924 * On output, pointer to the modified header, or NULL
925 * to remove the header. This function frees the
926 * original string if necessary.
928 * Returns : JB_ERR_OK on success, or
929 * JB_ERR_MEMORY on out-of-memory error.
931 *********************************************************************/
932 jb_err server_content_encoding(struct client_state *csp, char **header)
935 * Turn off pcrs and gif filtering if body compressed
937 if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
939 csp->content_type = CT_TABOO;
947 /*********************************************************************
949 * Function : server_content_length
951 * Description : Adjust Content-Length header if we modified
955 * 1 : csp = Current client state (buffers, headers, etc...)
956 * 2 : header = On input, pointer to header to modify.
957 * On output, pointer to the modified header, or NULL
958 * to remove the header. This function frees the
959 * original string if necessary.
961 * Returns : JB_ERR_OK on success, or
962 * JB_ERR_MEMORY on out-of-memory error.
964 *********************************************************************/
965 jb_err server_content_length(struct client_state *csp, char **header)
967 if (csp->content_length != 0) /* Content length has been modified */
970 *header = (char *) zalloc(100);
973 return JB_ERR_MEMORY;
976 sprintf(*header, "Content-Length: %d", (int) csp->content_length);
978 log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", (int) csp->content_length);
985 /*********************************************************************
987 * Function : server_content_md5
989 * Description : Crumble any Content-MD5 headers if the document was
990 * modified. FIXME: Should we re-compute instead?
993 * 1 : csp = Current client state (buffers, headers, etc...)
994 * 2 : header = On input, pointer to header to modify.
995 * On output, pointer to the modified header, or NULL
996 * to remove the header. This function frees the
997 * original string if necessary.
999 * Returns : JB_ERR_OK on success, or
1000 * JB_ERR_MEMORY on out-of-memory error.
1002 *********************************************************************/
1003 jb_err server_content_md5(struct client_state *csp, char **header)
1005 if (csp->flags & CSP_FLAG_MODIFIED)
1007 log_error(LOG_LEVEL_HEADER, "Crunching Content-MD5: %s", *header);
1015 /*********************************************************************
1017 * Function : client_accept_encoding
1019 * Description : Rewrite the client's Accept-Encoding header so that
1020 * if doesn't allow compression, if the action applies.
1021 * Note: For HTTP/1.0 the absence of the header is enough.
1024 * 1 : csp = Current client state (buffers, headers, etc...)
1025 * 2 : header = On input, pointer to header to modify.
1026 * On output, pointer to the modified header, or NULL
1027 * to remove the header. This function frees the
1028 * original string if necessary.
1030 * Returns : JB_ERR_OK on success, or
1031 * JB_ERR_MEMORY on out-of-memory error.
1033 *********************************************************************/
1034 jb_err client_accept_encoding(struct client_state *csp, char **header)
1036 if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1038 log_error(LOG_LEVEL_HEADER, "Suppressed offer to compress content");
1041 if (!strcmpic(csp->http->ver, "HTTP/1.1"))
1043 *header = strdup("Accept-Encoding: identity;q=1.0, *;q=0");
1044 if (*header == NULL)
1046 return JB_ERR_MEMORY;
1055 /*********************************************************************
1057 * Function : client_te
1059 * Description : Rewrite the client's TE header so that
1060 * if doesn't allow compression, if the action applies.
1063 * 1 : csp = Current client state (buffers, headers, etc...)
1064 * 2 : header = On input, pointer to header to modify.
1065 * On output, pointer to the modified header, or NULL
1066 * to remove the header. This function frees the
1067 * original string if necessary.
1069 * Returns : JB_ERR_OK on success, or
1070 * JB_ERR_MEMORY on out-of-memory error.
1072 *********************************************************************/
1073 jb_err client_te(struct client_state *csp, char **header)
1075 if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1078 log_error(LOG_LEVEL_HEADER, "Suppressed offer to compress transfer");
1084 /*********************************************************************
1086 * Function : client_referrer
1088 * Description : Handle the "referer" config setting properly.
1089 * Called from `sed'.
1092 * 1 : csp = Current client state (buffers, headers, etc...)
1093 * 2 : header = On input, pointer to header to modify.
1094 * On output, pointer to the modified header, or NULL
1095 * to remove the header. This function frees the
1096 * original string if necessary.
1098 * Returns : JB_ERR_OK on success, or
1099 * JB_ERR_MEMORY on out-of-memory error.
1101 *********************************************************************/
1102 jb_err client_referrer(struct client_state *csp, char **header)
1105 jb_err err = JB_ERR_OK;
1107 #ifdef FEATURE_FORCE_LOAD
1108 /* Since the referrer can include the prefix even
1109 * even if the request itself is non-forced, we must
1110 * clean it unconditionally
1112 strclean(*header, FORCE_PREFIX);
1113 #endif /* def FEATURE_FORCE_LOAD */
1116 * As long as we're not blocking the referer...
1118 if ((csp->action->flags & ACTION_HIDE_REFERER) != 0)
1121 newval = csp->action->string[ACTION_STRING_REFERER];
1123 #ifdef FEATURE_ACTIVITY_CONSOLE
1124 /* We are doing something with the referer. */
1125 accumulate_stats(STATS_REFERER, 1);
1126 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1129 * Note that each clause needs to freez the header pointer;
1130 * but everybody needs to use it for logging purposes before
1131 * it gets freed, so always free it just after logging it.
1133 if ((newval == NULL) || (0 == strcmpic(newval, "block")) )
1138 log_error(LOG_LEVEL_HEADER, "crunch: %s", *header);
1142 else if (0 == strncmpic(newval, "http://", 7))
1145 * We have a specific (fixed) referer we want to send.
1147 log_error(LOG_LEVEL_HEADER, "modified: %s", *header);
1149 *header = strdup("Referer: ");
1150 if (NULL == *header)
1151 err = JB_ERR_MEMORY;
1153 err = string_append(header, newval);
1158 * Forge a referer as http://[hostname:port of REQUEST]/
1159 * to fool stupid checks for in-site links
1161 if (0 != strcmpic(newval, "forge"))
1164 * Invalid choice - but forge is probably the best default.
1166 log_error(LOG_LEVEL_ERROR, "Bad parameter: +referer{%s}", newval);
1169 log_error(LOG_LEVEL_HEADER, "crunch+forge: %s", *header);
1171 *header = strdup("Referer: http://");
1172 if (NULL == *header)
1173 err = JB_ERR_MEMORY;
1176 err = string_append(header, csp->http->hostport);
1177 err = string_append(header, "/");
1178 if (JB_ERR_OK == err)
1179 log_error(LOG_LEVEL_HEADER, "crunch+forged to: %s", *header);
1187 /*********************************************************************
1189 * Function : client_uagent
1191 * Description : Handle the "user-agent" config setting properly
1192 * and remember its original value to enable browser
1193 * bug workarounds. Called from `sed'.
1196 * 1 : csp = Current client state (buffers, headers, etc...)
1197 * 2 : header = On input, pointer to header to modify.
1198 * On output, pointer to the modified header, or NULL
1199 * to remove the header. This function frees the
1200 * original string if necessary.
1202 * Returns : JB_ERR_OK on success, or
1203 * JB_ERR_MEMORY on out-of-memory error.
1205 *********************************************************************/
1206 jb_err client_uagent(struct client_state *csp, char **header)
1209 jb_err err = JB_ERR_OK;
1212 * As long as we don't want to hide user-agent...
1214 if ((csp->action->flags & ACTION_HIDE_USER_AGENT) != 0)
1216 newval = csp->action->string[ACTION_STRING_USER_AGENT];
1219 log_error(LOG_LEVEL_HEADER, "modified: %s", *header);
1222 *header = strdup("User-Agent: ");
1223 err = string_append(header, newval);
1231 /*********************************************************************
1233 * Function : client_ua
1235 * Description : Handle "ua-" headers properly. Called from `sed'.
1238 * 1 : csp = Current client state (buffers, headers, etc...)
1239 * 2 : header = On input, pointer to header to modify.
1240 * On output, pointer to the modified header, or NULL
1241 * to remove the header. This function frees the
1242 * original string if necessary.
1244 * Returns : JB_ERR_OK on success, or
1245 * JB_ERR_MEMORY on out-of-memory error.
1247 *********************************************************************/
1248 jb_err client_ua(struct client_state *csp, char **header)
1250 if ((csp->action->flags & ACTION_HIDE_USER_AGENT) != 0)
1252 #ifdef FEATURE_ACTIVITY_CONSOLE
1253 accumulate_stats(STATS_CLIENT_UA, 1);
1254 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1255 log_error(LOG_LEVEL_HEADER, "crunch: %s", *header);
1263 /*********************************************************************
1265 * Function : client_from
1267 * Description : Handle the "from" config setting properly.
1268 * Called from `sed'.
1271 * 1 : csp = Current client state (buffers, headers, etc...)
1272 * 2 : header = On input, pointer to header to modify.
1273 * On output, pointer to the modified header, or NULL
1274 * to remove the header. This function frees the
1275 * original string if necessary.
1277 * Returns : JB_ERR_OK on success, or
1278 * JB_ERR_MEMORY on out-of-memory error.
1280 *********************************************************************/
1281 jb_err client_from(struct client_state *csp, char **header)
1284 jb_err err = JB_ERR_OK;
1287 * As long as we should handle the "from" setting...
1289 if ((csp->action->flags & ACTION_HIDE_FROM) != 0)
1291 #ifdef FEATURE_ACTIVITY_CONSOLE
1292 /* We're doing something with it. */
1293 accumulate_stats(STATS_CLIENT_FROM, 1);
1294 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1296 newval = csp->action->string[ACTION_STRING_FROM];
1299 * Are we blocking the e-mail address?
1301 if ((NULL == newval) || (0 == strcmpic(newval, "block")) )
1303 log_error(LOG_LEVEL_HEADER, "crunch: %s", *header);
1308 log_error(LOG_LEVEL_HEADER, "modified: %s", *header);
1310 *header = strdup("From: ");
1311 err = string_append(header, newval);
1318 /*********************************************************************
1320 * Function : client_send_cookie
1322 * Description : Handle the "cookie" header properly. Called from `sed'.
1323 * If cookie is accepted, add it to the cookie_list,
1324 * else we crunch it. Mmmmmmmmmmm ... cookie ......
1327 * 1 : csp = Current client state (buffers, headers, etc...)
1328 * 2 : header = On input, pointer to header to modify.
1329 * On output, pointer to the modified header, or NULL
1330 * to remove the header. This function frees the
1331 * original string if necessary.
1333 * Returns : JB_ERR_OK on success, or
1334 * JB_ERR_MEMORY on out-of-memory error.
1336 *********************************************************************/
1337 jb_err client_send_cookie(struct client_state *csp, char **header)
1339 jb_err err = JB_ERR_OK;
1341 if ((csp->action->flags & ACTION_NO_COOKIE_READ) == 0)
1343 /* strlen("cookie: ") == 8 */
1344 err = enlist(csp->cookie_list, *header + 8);
1348 log_error(LOG_LEVEL_HEADER, "Crunched cookie: %s", *header);
1352 * Always remove the cookie here. The cookie header
1353 * will be sent at the end of the header.
1361 /*********************************************************************
1363 * Function : client_x_forwarded
1365 * Description : Handle the "x-forwarded-for" config setting properly,
1366 * also used in the add_client_headers list. Called from `sed'.
1369 * 1 : csp = Current client state (buffers, headers, etc...)
1370 * 2 : header = On input, pointer to header to modify.
1371 * On output, pointer to the modified header, or NULL
1372 * to remove the header. This function frees the
1373 * original string if necessary.
1375 * Returns : JB_ERR_OK on success, or
1376 * JB_ERR_MEMORY on out-of-memory error.
1378 *********************************************************************/
1379 jb_err client_x_forwarded(struct client_state *csp, char **header)
1381 if ((csp->action->flags & ACTION_HIDE_FORWARDED) == 0)
1383 /* Save it so we can re-add it later */
1384 freez(csp->x_forwarded);
1385 csp->x_forwarded = *header;
1388 * Always set *header = NULL, since this information
1389 * will be sent at the end of the header.
1395 #ifdef FEATURE_ACTIVITY_CONSOLE
1396 accumulate_stats(STATS_CLIENT_X_FORWARDED, 1);
1397 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1398 log_error(LOG_LEVEL_HEADER, "crunch: %s", *header);
1405 /* the following functions add headers directly to the header list */
1407 /*********************************************************************
1409 * Function : client_host_adder
1411 * Description : (re)adds the host header. Called from `sed'.
1414 * 1 : csp = Current client state (buffers, headers, etc...)
1416 * Returns : JB_ERR_OK on success, or
1417 * JB_ERR_MEMORY on out-of-memory error.
1419 *********************************************************************/
1420 jb_err client_host_adder(struct client_state *csp)
1424 jb_err err = JB_ERR_OK;
1426 if ( csp->http->hostport && *(csp->http->hostport))
1428 p = strdup("Host: ");
1432 * remove 'user:pass@' from 'proto://user:pass@host'
1434 if ( (pos = strchr( csp->http->hostport, '@')) != NULL )
1436 string_append(&p, pos+1);
1440 string_append(&p, csp->http->hostport);
1443 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1445 err = enlist(csp->headers, p);
1451 err = JB_ERR_MEMORY;
1458 /*********************************************************************
1460 * Function : client_cookie_adder
1462 * Description : Used in the add_client_headers list. Called from `sed'.
1465 * 1 : csp = Current client state (buffers, headers, etc...)
1467 * Returns : JB_ERR_OK on success, or
1468 * JB_ERR_MEMORY on out-of-memory error.
1470 *********************************************************************/
1471 jb_err client_cookie_adder(struct client_state *csp)
1473 struct list_entry *lst;
1475 struct list_entry *list1 = csp->cookie_list->first;
1476 struct list_entry *list2 = csp->action->multi[ACTION_MULTI_WAFER]->first;
1477 int first_cookie = 1;
1478 jb_err err = JB_ERR_OK;
1480 if ((list1 != NULL) || (list2 != NULL))
1482 tmp = strdup("Cookie: ");
1485 for (lst = list1; lst ; lst = lst->next)
1493 string_append(&tmp, "; ");
1495 string_append(&tmp, lst->str);
1498 for (lst = list2; lst ; lst = lst->next)
1506 string_append(&tmp, "; ");
1508 string_join(&tmp, cookie_encode(lst->str));
1510 log_error(LOG_LEVEL_HEADER, "addh: %s", tmp);
1511 err = enlist(csp->headers, tmp);
1516 err = JB_ERR_MEMORY;
1523 /*********************************************************************
1525 * Function : client_accept_encoding_adder
1527 * Description : Add an Accept-Encoding header to the client's request
1528 * that disables compression if the action applies, and
1529 * the header is not already there. Called from `sed'.
1530 * Note: For HTTP/1.0, the absence of the header is enough.
1533 * 1 : csp = Current client state (buffers, headers, etc...)
1535 * Returns : JB_ERR_OK on success, or
1536 * JB_ERR_MEMORY on out-of-memory error.
1538 *********************************************************************/
1539 jb_err client_accept_encoding_adder(struct client_state *csp)
1541 if ( ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1542 && (!strcmpic(csp->http->ver, "HTTP/1.1")) )
1544 return enlist_unique(csp->headers, "Accept-Encoding: identity;q=1.0, *;q=0", 16);
1551 /*********************************************************************
1553 * Function : client_xtra_adder
1555 * Description : Used in the add_client_headers list. Called from `sed'.
1558 * 1 : csp = Current client state (buffers, headers, etc...)
1560 * Returns : JB_ERR_OK on success, or
1561 * JB_ERR_MEMORY on out-of-memory error.
1563 *********************************************************************/
1564 jb_err client_xtra_adder(struct client_state *csp)
1566 struct list_entry *lst;
1569 for (lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]->first;
1570 lst ; lst = lst->next)
1572 log_error(LOG_LEVEL_HEADER, "addh: %s", lst->str);
1573 err = enlist(csp->headers, lst->str);
1585 /*********************************************************************
1587 * Function : client_x_forwarded_adder
1589 * Description : Used in the add_client_headers list. Called from `sed'.
1592 * 1 : csp = Current client state (buffers, headers, etc...)
1594 * Returns : JB_ERR_OK on success, or
1595 * JB_ERR_MEMORY on out-of-memory error.
1597 *********************************************************************/
1598 jb_err client_x_forwarded_adder(struct client_state *csp)
1601 jb_err err = JB_ERR_OK;
1603 if (0 == (csp->action->flags & ACTION_HIDE_FORWARDED))
1606 if (csp->x_forwarded)
1608 p = strdup(csp->x_forwarded);
1609 err = string_append(&p, ", ");
1613 p = strdup("X-Forwarded-For: ");
1615 err = string_append(&p, csp->ip_addr_str);
1619 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1620 err = enlist(csp->headers, p);
1628 /*********************************************************************
1630 * Function : connection_close_adder
1632 * Description : Adds a "Connection: close" header to csp->headers
1633 * as a temporary fix for the needed but missing HTTP/1.1
1634 * support. Called from `sed'.
1635 * FIXME: This whole function shouldn't be neccessary!
1638 * 1 : csp = Current client state (buffers, headers, etc...)
1640 * Returns : JB_ERR_OK on success, or
1641 * JB_ERR_MEMORY on out-of-memory error.
1643 *********************************************************************/
1644 jb_err connection_close_adder(struct client_state *csp)
1646 return enlist(csp->headers, "Connection: close");
1650 /*********************************************************************
1652 * Function : server_http
1654 * Description : - Save the HTTP Status into csp->http->status
1655 * - Set CT_TABOO to prevent filtering if the answer
1656 * is a partial range (HTTP status 206)
1657 * - Rewrite HTTP/1.1 answers to HTTP/1.0 if +downgrade
1661 * 1 : csp = Current client state (buffers, headers, etc...)
1662 * 2 : header = On input, pointer to header to modify.
1663 * On output, pointer to the modified header, or NULL
1664 * to remove the header. This function frees the
1665 * original string if necessary.
1667 * Returns : JB_ERR_OK on success, or
1668 * JB_ERR_MEMORY on out-of-memory error.
1670 *********************************************************************/
1671 jb_err server_http(struct client_state *csp, char **header)
1673 sscanf(*header, "HTTP/%*d.%*d %d", &(csp->http->status));
1674 if (csp->http->status == 206)
1676 csp->content_type = CT_TABOO;
1679 if ((csp->action->flags & ACTION_DOWNGRADE) != 0)
1682 log_error(LOG_LEVEL_HEADER, "Downgraded answer to HTTP/1.0");
1689 /*********************************************************************
1691 * Function : server_set_cookie
1693 * Description : Handle the server "cookie" header properly.
1694 * Log cookie to the jar file. Then "crunch" it,
1695 * or accept it. Called from `sed'.
1698 * 1 : csp = Current client state (buffers, headers, etc...)
1699 * 2 : header = On input, pointer to header to modify.
1700 * On output, pointer to the modified header, or NULL
1701 * to remove the header. This function frees the
1702 * original string if necessary.
1704 * Returns : JB_ERR_OK on success, or
1705 * JB_ERR_MEMORY on out-of-memory error.
1707 *********************************************************************/
1708 jb_err server_set_cookie(struct client_state *csp, char **header)
1710 jb_err err = JB_ERR_OK;
1712 #ifdef FEATURE_COOKIE_JAR
1713 if (csp->config->jar)
1716 * Write timestamp into outbuf.
1718 * Complex because not all OSs have tm_gmtoff or
1719 * the %z field in strftime()
1721 char tempbuf[ BUFFER_SIZE ];
1725 #ifdef HAVE_LOCALTIME_R
1726 tm_now = *localtime_r(&now, &tm_now);
1728 pthread_mutex_lock(&localtime_mutex);
1729 tm_now = *localtime (&now);
1730 pthread_mutex_unlock(&localtime_mutex);
1732 tm_now = *localtime (&now);
1734 strftime(tempbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1736 /* strlen("set-cookie: ") = 12 */
1737 fprintf(csp->config->jar, "%s %s\t%s\n", tempbuf, csp->http->host, *header + 12);
1739 #endif /* def FEATURE_COOKIE_JAR */
1741 if ((csp->action->flags & ACTION_NO_COOKIE_SET) != 0)
1743 log_error(LOG_LEVEL_HEADER, "Crunched incoming cookie -- yum!");
1744 #ifdef FEATURE_ACTIVITY_CONSOLE
1745 accumulate_stats(STATS_COOKIE, 1);
1746 #endif /* def FEATURE_ACTIVITY_CONSOLE */
1747 err = crumble(csp, header);
1749 else if ((csp->action->flags & ACTION_NO_COOKIE_KEEP) != 0)
1751 /* Flag whether or not to log a message */
1754 /* A variable to store the tag we're working on */
1757 /* Skip "Set-Cookie:" (11 characters) in header */
1758 cur_tag = *header + 11;
1760 /* skip whitespace between "Set-Cookie:" and value */
1761 while (*cur_tag && ijb_isspace(*cur_tag))
1766 /* Loop through each tag in the cookie */
1770 char *next_tag = strchr(cur_tag, ';');
1771 if (next_tag != NULL)
1773 /* Skip the ';' character itself */
1776 /* skip whitespace ";" and start of tag */
1777 while (*next_tag && ijb_isspace(*next_tag))
1784 /* "Next tag" is the end of the string */
1785 next_tag = cur_tag + strlen(cur_tag);
1788 /* Is this the "Expires" tag? */
1789 if (strncmpic(cur_tag, "expires=", 8) == 0)
1791 /* Delete the tag by copying the rest of the string over it.
1792 * (Note that we cannot just use "strcpy(cur_tag, next_tag)",
1793 * since the behaviour of strcpy is undefined for overlapping
1796 memmove(cur_tag, next_tag, strlen(next_tag) + 1);
1798 /* That changed the header, need to issue a log message */
1801 /* Note that the next tag has now been moved to *cur_tag,
1802 * so we do not need to update the cur_tag pointer.
1807 /* Move on to next cookie tag */
1814 log_error(LOG_LEVEL_HEADER, "Changed cookie to a temporary one.");
1822 #ifdef FEATURE_FORCE_LOAD
1823 /*********************************************************************
1825 * Function : strclean
1827 * Description : In-Situ-Eliminate all occurances of substring in
1831 * 1 : string = string to clean
1832 * 2 : substring = substring to eliminate
1834 * Returns : Number of eliminations
1836 *********************************************************************/
1837 int strclean(const char *string, const char *substring)
1839 int hits = 0, len = strlen(substring);
1842 while((pos = strstr(string, substring)) != NULL)
1849 while (*p++ != '\0');
1856 #endif /* def FEATURE_FORCE_LOAD */