1 const char parsers_rcs[] = "$Id: parsers.c,v 1.56.2.1 2002/09/25 14:52:45 oes Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/Attic/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 1.56.2.1 2002/09/25 14:52:45 oes
44 * Added basic support for OPTIONS and TRACE HTTP methods:
45 * - New parser function client_max_forwards which decrements
46 * the Max-Forwards HTTP header field of OPTIONS and TRACE
47 * requests by one before forwarding
48 * - New parser function client_host which extracts the host
49 * and port information from the HTTP header field if the
50 * request URI was not absolute
51 * - Don't crumble and re-add the Host: header, but only generate
52 * and append if missing
54 * Revision 1.56 2002/05/12 15:34:22 jongfoster
55 * Fixing typo in a comment
57 * Revision 1.55 2002/05/08 16:01:07 oes
58 * Optimized add_to_iob:
59 * - Use realloc instead of malloc(), memcpy(), free()
60 * - Expand to powers of two if possible, to get
61 * O(log n) reallocs instead of O(n).
62 * - Moved check for buffer limit here from chat
63 * - Report failure via returncode
65 * Revision 1.54 2002/04/02 15:03:16 oes
68 * Revision 1.53 2002/03/26 22:29:55 swa
69 * we have a new homepage!
71 * Revision 1.52 2002/03/24 13:25:43 swa
72 * name change related issues
74 * Revision 1.51 2002/03/13 00:27:05 jongfoster
77 * Revision 1.50 2002/03/12 01:45:35 oes
78 * More verbose logging
80 * Revision 1.49 2002/03/09 20:03:52 jongfoster
81 * - Making various functions return int rather than size_t.
82 * (Undoing a recent change). Since size_t is unsigned on
83 * Windows, functions like read_socket that return -1 on
84 * error cannot return a size_t.
86 * THIS WAS A MAJOR BUG - it caused frequent, unpredictable
87 * crashes, and also frequently caused JB to jump to 100%
88 * CPU and stay there. (Because it thought it had just
89 * read ((unsigned)-1) == 4Gb of data...)
91 * - The signature of write_socket has changed, it now simply
92 * returns success=0/failure=nonzero.
94 * - Trying to get rid of a few warnings --with-debug on
95 * Windows, I've introduced a new type "jb_socket". This is
96 * used for the socket file descriptors. On Windows, this
97 * is SOCKET (a typedef for unsigned). Everywhere else, it's
98 * an int. The error value can't be -1 any more, so it's
99 * now JB_INVALID_SOCKET (which is -1 on UNIX, and in
100 * Windows it maps to the #define INVALID_SOCKET.)
102 * - The signature of bind_port has changed.
104 * Revision 1.48 2002/03/07 03:46:53 oes
105 * Fixed compiler warnings etc
107 * Revision 1.47 2002/02/20 23:15:13 jongfoster
108 * Parsing functions now handle out-of-memory gracefully by returning
111 * Revision 1.46 2002/01/17 21:03:47 jongfoster
112 * Moving all our URL and URL pattern parsing code to urlmatch.c.
114 * Revision 1.45 2002/01/09 14:33:03 oes
115 * Added support for localtime_r.
117 * Revision 1.44 2001/12/14 01:22:54 steudten
118 * Remove 'user:pass@' from 'proto://user:pass@host' for the
119 * new added header 'Host: ..'. (See Req ID 491818)
121 * Revision 1.43 2001/11/23 00:26:38 jongfoster
122 * Fixing two really stupid errors in my previous commit
124 * Revision 1.42 2001/11/22 21:59:30 jongfoster
125 * Adding code to handle +no-cookies-keep
127 * Revision 1.41 2001/11/05 23:43:05 steudten
128 * Add time+date to log files.
130 * Revision 1.40 2001/10/26 20:13:09 jongfoster
131 * ctype.h is needed in Windows, too.
133 * Revision 1.39 2001/10/26 17:40:04 oes
134 * Introduced get_header_value()
135 * Removed http->user_agent, csp->referrer and csp->accept_types
136 * Removed client_accept()
138 * Revision 1.38 2001/10/25 03:40:48 david__schmidt
139 * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
140 * threads to call select() simultaneously. So, it's time to do a real, live,
141 * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
142 * (native). Both versions will work, but using __OS2__ offers multi-threading.
144 * Revision 1.37 2001/10/23 21:36:02 jongfoster
145 * Documenting sed()'s error behaviou (doc change only)
147 * Revision 1.36 2001/10/13 12:51:51 joergs
148 * Removed client_host, (was only required for the old 2.0.2-11 http://noijb.
149 * force-load), instead crumble Host: and add it (again) in client_host_adder
150 * (in case we get a HTTP/1.0 request without Host: header and forward it to
151 * a HTTP/1.1 server/proxy).
153 * Revision 1.35 2001/10/09 22:39:21 jongfoster
154 * assert.h is also required under Win32, so moving out of #ifndef _WIN32
157 * Revision 1.34 2001/10/07 18:50:55 oes
158 * Added server_content_encoding, renamed server_transfer_encoding
160 * Revision 1.33 2001/10/07 18:04:49 oes
161 * Changed server_http11 to server_http and its pattern to "HTTP".
162 * Additional functionality: it now saves the HTTP status into
163 * csp->http->status and sets CT_TABOO for Status 206 (partial range)
165 * Revision 1.32 2001/10/07 15:43:28 oes
166 * Removed FEATURE_DENY_GZIP and replaced it with client_accept_encoding,
167 * client_te and client_accept_encoding_adder, triggered by the new
168 * +no-compression action. For HTTP/1.1 the Accept-Encoding header is
169 * changed to allow only identity and chunked, and the TE header is
170 * crunched. For HTTP/1.0, Accept-Encoding is crunched.
172 * parse_http_request no longer does anything than parsing. The rewriting
173 * of http->cmd and version mangling are gone. It now also recognizes
174 * the put and delete methods and saves the url in http->url. Removed
177 * renamed content_type and content_length to have the server_ prefix
179 * server_content_type now only works if csp->content_type != CT_TABOO
181 * added server_transfer_encoding, which
182 * - Sets CT_TABOO to prohibit filtering if encoding compresses
183 * - Raises the CSP_FLAG_CHUNKED flag if Encoding is "chunked"
184 * - Change from "chunked" to "identity" if body was chunked
185 * but has been de-chunked for filtering.
187 * added server_content_md5 which crunches any Content-MD5 headers
188 * if the body was modified.
190 * made server_http11 conditional on +downgrade action
192 * Replaced 6 boolean members of csp with one bitmap (csp->flags)
194 * Revision 1.31 2001/10/05 14:25:02 oes
195 * Crumble Keep-Alive from Server
197 * Revision 1.30 2001/09/29 12:56:03 joergs
198 * IJB now changes HTTP/1.1 to HTTP/1.0 in requests and answers.
200 * Revision 1.29 2001/09/24 21:09:24 jongfoster
201 * Fixing 2 memory leaks that Guy spotted, where the paramater to
202 * enlist() was not being free()d.
204 * Revision 1.28 2001/09/22 16:32:28 jongfoster
205 * Removing unused #includes.
207 * Revision 1.27 2001/09/20 15:45:25 steudten
209 * add casting from size_t to int for printf()
210 * remove local variable shadow s2
212 * Revision 1.26 2001/09/16 17:05:14 jongfoster
213 * Removing unused #include showarg.h
215 * Revision 1.25 2001/09/16 13:21:27 jongfoster
216 * Changes to use new list functions.
218 * Revision 1.24 2001/09/13 23:05:50 jongfoster
219 * Changing the string paramater to the header parsers a "const".
221 * Revision 1.23 2001/09/12 18:08:19 steudten
223 * In parse_http_request() header rewriting miss the host value, so
224 * from http://www.mydomain.com the result was just " / " not
225 * http://www.mydomain.com/ in case we forward.
227 * Revision 1.22 2001/09/10 10:58:53 oes
228 * Silenced compiler warnings
230 * Revision 1.21 2001/07/31 14:46:00 oes
231 * - Persistant connections now suppressed
232 * - sed() no longer appends empty header to csp->headers
234 * Revision 1.20 2001/07/30 22:08:36 jongfoster
235 * Tidying up #defines:
236 * - All feature #defines are now of the form FEATURE_xxx
237 * - Permanently turned off WIN_GUI_EDIT
238 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
240 * Revision 1.19 2001/07/25 17:21:54 oes
241 * client_uagent now saves copy of User-Agent: header value
243 * Revision 1.18 2001/07/13 14:02:46 oes
244 * - Included fix to repair broken HTTP requests that
245 * don't contain a path, not even '/'.
246 * - Removed all #ifdef PCRS
247 * - content_type now always inspected and classified as
248 * text, gif or other.
249 * - formatting / comments
251 * Revision 1.17 2001/06/29 21:45:41 oes
252 * Indentation, CRLF->LF, Tab-> Space
254 * Revision 1.16 2001/06/29 13:32:42 oes
256 * - Adapted free_http_request
257 * - Removed logentry from cancelled commit
259 * Revision 1.15 2001/06/03 19:12:38 oes
260 * deleted const struct interceptors
262 * Revision 1.14 2001/06/01 18:49:17 jongfoster
263 * Replaced "list_share" with "list" - the tiny memory gain was not
264 * worth the extra complexity.
266 * Revision 1.13 2001/05/31 21:30:33 jongfoster
267 * Removed list code - it's now in list.[ch]
268 * Renamed "permission" to "action", and changed many features
269 * to use the actions file rather than the global config.
271 * Revision 1.12 2001/05/31 17:33:13 oes
275 * Revision 1.11 2001/05/29 20:11:19 joergs
276 * '/ * inside comment' warning removed.
278 * Revision 1.10 2001/05/29 09:50:24 jongfoster
279 * Unified blocklist/imagelist/permissionslist.
280 * File format is still under discussion, but the internal changes
283 * Also modified interceptor behaviour:
284 * - We now intercept all URLs beginning with one of the following
285 * prefixes (and *only* these prefixes):
287 * * http://ijbswa.sf.net/config/
288 * * http://ijbswa.sourceforge.net/config/
289 * - New interceptors "home page" - go to http://i.j.b/ to see it.
290 * - Internal changes so that intercepted and fast redirect pages
291 * are not replaced with an image.
292 * - Interceptors now have the option to send a binary page direct
293 * to the client. (i.e. ijb-send-banner uses this)
294 * - Implemented show-url-info interceptor. (Which is why I needed
295 * the above interceptors changes - a typical URL is
296 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
297 * The previous mechanism would not have intercepted that, and
298 * if it had been intercepted then it then it would have replaced
301 * Revision 1.9 2001/05/28 17:26:33 jongfoster
302 * Fixing segfault if last header was crunched.
303 * Fixing Windows build (snprintf() is _snprintf() under Win32, but we
304 * can use the cross-platform sprintf() instead.)
306 * Revision 1.8 2001/05/27 22:17:04 oes
308 * - re_process_buffer no longer writes the modified buffer
309 * to the client, which was very ugly. It now returns the
310 * buffer, which it is then written by chat.
312 * - content_length now adjusts the Content-Length: header
313 * for modified documents rather than crunch()ing it.
314 * (Length info in csp->content_length, which is 0 for
315 * unmodified documents)
317 * - For this to work, sed() is called twice when filtering.
319 * Revision 1.7 2001/05/27 13:19:06 oes
320 * Patched Joergs solution for the content-length in.
322 * Revision 1.6 2001/05/26 13:39:32 jongfoster
323 * Only crunches Content-Length header if applying RE filtering.
324 * Without this fix, Microsoft Windows Update wouldn't work.
326 * Revision 1.5 2001/05/26 00:28:36 jongfoster
327 * Automatic reloading of config file.
328 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
329 * Most of the global variables have been moved to a new
330 * struct configuration_spec, accessed through csp->config->globalname
331 * Most of the globals remaining are used by the Win32 GUI.
333 * Revision 1.4 2001/05/22 18:46:04 oes
335 * - Enabled filtering banners by size rather than URL
336 * by adding patterns that replace all standard banner
337 * sizes with the "Junkbuster" gif to the re_filterfile
339 * - Enabled filtering WebBugs by providing a pattern
340 * which kills all 1x1 images
342 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
343 * which is selected by the (nonstandard and therefore
344 * capital) letter 'U' in the option string.
345 * It causes the quantifiers to be ungreedy by default.
346 * Appending a ? turns back to greedy (!).
348 * - Added a new interceptor ijb-send-banner, which
349 * sends back the "Junkbuster" gif. Without imagelist or
350 * MSIE detection support, or if tinygif = 1, or the
351 * URL isn't recognized as an imageurl, a lame HTML
352 * explanation is sent instead.
354 * - Added new feature, which permits blocking remote
355 * script redirects and firing back a local redirect
357 * The feature is conditionally compiled, i.e. it
358 * can be disabled with --disable-fast-redirects,
359 * plus it must be activated by a "fast-redirects"
360 * line in the config file, has its own log level
361 * and of course wants to be displayed by show-proxy-args
362 * Note: Boy, all the #ifdefs in 1001 locations and
363 * all the fumbling with configure.in and acconfig.h
364 * were *way* more work than the feature itself :-(
366 * - Because a generic redirect template was needed for
367 * this, tinygif = 3 now uses the same.
369 * - Moved GIFs, and other static HTTP response templates
374 * - Removed some >400 CRs again (Jon, you really worked
377 * Revision 1.3 2001/05/20 01:21:20 jongfoster
378 * Version 2.9.4 checkin.
379 * - Merged popupfile and cookiefile, and added control over PCRS
380 * filtering, in new "permissionsfile".
381 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
382 * file error you now get a message box (in the Win32 GUI) rather
383 * than the program exiting with no explanation.
384 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
386 * - Removed tabs from "config"
387 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
388 * - Bumped up version number.
390 * Revision 1.2 2001/05/17 23:02:36 oes
391 * - Made referrer option accept 'L' as a substitute for '§'
393 * Revision 1.1.1.1 2001/05/15 13:59:01 oes
394 * Initial import of version 2.9.3 source tree
397 *********************************************************************/
404 #include <sys/types.h>
412 #if !defined(_WIN32) && !defined(__OS2__)
422 #include "jbsockets.h"
423 #include "miscutil.h"
426 const char parsers_h_rcs[] = PARSERS_H_VERSION;
428 /* Fix a problem with Solaris. There should be no effect on other
430 * Solaris's isspace() is a macro which uses it's argument directly
431 * as an array index. Therefore we need to make sure that high-bit
432 * characters generate +ve values, and ideally we also want to make
433 * the argument match the declared parameter type of "int".
435 * Why did they write a character function that can't take a simple
436 * "char" argument? Doh!
438 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
439 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
442 const struct parsers client_patterns[] = {
443 { "referer:", 8, client_referrer },
444 { "user-agent:", 11, client_uagent },
445 { "ua-", 3, client_ua },
446 { "from:", 5, client_from },
447 { "cookie:", 7, client_send_cookie },
448 { "x-forwarded-for:", 16, client_x_forwarded },
449 { "Accept-Encoding:", 16, client_accept_encoding },
450 { "TE:", 3, client_te },
451 { "Host:", 5, client_host },
452 /* { "if-modified-since:", 18, crumble }, */
453 { "Keep-Alive:", 11, crumble },
454 { "connection:", 11, crumble },
455 { "proxy-connection:", 17, crumble },
456 { "max-forwards:", 13, client_max_forwards },
461 const struct parsers server_patterns[] = {
462 { "HTTP", 4, server_http },
463 { "set-cookie:", 11, server_set_cookie },
464 { "connection:", 11, crumble },
465 { "Content-Type:", 13, server_content_type },
466 { "Content-Length:", 15, server_content_length },
467 { "Content-MD5:", 12, server_content_md5 },
468 { "Content-Encoding:", 17, server_content_encoding },
469 { "Transfer-Encoding:", 18, server_transfer_coding },
470 { "Keep-Alive:", 11, crumble },
475 const add_header_func_ptr add_client_headers[] = {
478 client_x_forwarded_adder,
480 client_accept_encoding_adder,
481 connection_close_adder,
486 const add_header_func_ptr add_server_headers[] = {
487 connection_close_adder,
492 /*********************************************************************
494 * Function : flush_socket
496 * Description : Write any pending "buffered" content.
499 * 1 : fd = file descriptor of the socket to read
500 * 2 : csp = Current client state (buffers, headers, etc...)
502 * Returns : On success, the number of bytes written are returned (zero
503 * indicates nothing was written). On error, -1 is returned,
504 * and errno is set appropriately. If count is zero and the
505 * file descriptor refers to a regular file, 0 will be
506 * returned without causing any other effect. For a special
507 * file, the results are not portable.
509 *********************************************************************/
510 int flush_socket(jb_socket fd, struct client_state *csp)
512 struct iob *iob = csp->iob;
513 int len = iob->eod - iob->cur;
520 if (write_socket(fd, iob->cur, (size_t)len))
524 iob->eod = iob->cur = iob->buf;
530 /*********************************************************************
532 * Function : add_to_iob
534 * Description : Add content to the buffered page, expanding the
535 * buffer if necessary.
538 * 1 : csp = Current client state (buffers, headers, etc...)
539 * 2 : buf = holds the content to be added to the page
540 * 3 : n = number of bytes to be added
542 * Returns : JB_ERR_OK on success, JB_ERR_MEMORY if out-of-memory
543 * or buffer limit reached.
545 *********************************************************************/
546 jb_err add_to_iob(struct client_state *csp, char *buf, int n)
548 struct iob *iob = csp->iob;
549 size_t used, offset, need, want;
552 if (n <= 0) return JB_ERR_OK;
554 used = iob->eod - iob->buf;
555 offset = iob->cur - iob->buf;
559 * If the buffer can't hold the new data, extend it first.
560 * Use the next power of two if possible, else use the actual need.
562 if (need > csp->config->buffer_limit)
564 log_error(LOG_LEVEL_ERROR, "Buffer limit reached while extending the buffer (iob)");
565 return JB_ERR_MEMORY;
568 if (need > iob->size)
570 for (want = csp->iob->size ? csp->iob->size : 512; want <= need;) want *= 2;
572 if (want <= csp->config->buffer_limit && NULL != (p = (char *)realloc(iob->buf, want)))
576 else if (NULL != (p = (char *)realloc(iob->buf, need)))
582 log_error(LOG_LEVEL_ERROR, "Extending the buffer (iob) failed: %E");
583 return JB_ERR_MEMORY;
586 /* Update the iob pointers */
587 iob->cur = p + offset;
592 /* copy the new data into the iob buffer */
593 memcpy(iob->eod, buf, (size_t)n);
595 /* point to the end of the data */
598 /* null terminate == cheap insurance */
606 /*********************************************************************
608 * Function : get_header
610 * Description : This (odd) routine will parse the csp->iob
613 * 1 : csp = Current client state (buffers, headers, etc...)
615 * Returns : Any one of the following:
617 * 1) a pointer to a dynamically allocated string that contains a header line
618 * 2) NULL indicating that the end of the header was reached
619 * 3) "" indicating that the end of the iob was reached before finding
620 * a complete header line.
622 *********************************************************************/
623 char *get_header(struct client_state *csp)
629 if ((iob->cur == NULL)
630 || ((p = strchr(iob->cur, '\n')) == NULL))
632 return(""); /* couldn't find a complete header */
637 ret = strdup(iob->cur);
640 /* FIXME No way to handle error properly */
641 log_error(LOG_LEVEL_FATAL, "Out of memory in get_header()");
646 if ((q = strchr(ret, '\r')) != NULL) *q = '\0';
648 /* is this a blank line (i.e. the end of the header) ? */
660 /*********************************************************************
662 * Function : get_header_value
664 * Description : Get the value of a given header from a chained list
665 * of header lines or return NULL if no such header is
666 * present in the list.
669 * 1 : header_list = pointer to list
670 * 2 : header_name = string with name of header to look for.
671 * Trailing colon required, capitalization
674 * Returns : NULL if not found, else value of header
676 *********************************************************************/
677 char *get_header_value(const struct list *header_list, const char *header_name)
679 struct list_entry *cur_entry;
685 length = strlen(header_name);
687 for (cur_entry = header_list->first; cur_entry ; cur_entry = cur_entry->next)
691 if (!strncmpic(cur_entry->str, header_name, length))
694 * Found: return pointer to start of value
696 ret = (char *) (cur_entry->str + length);
697 while (*ret && ijb_isspace(*ret)) ret++;
710 /*********************************************************************
714 * Description : add, delete or modify lines in the HTTP header streams.
715 * On entry, it receives a linked list of headers space
716 * that was allocated dynamically (both the list nodes
717 * and the header contents).
719 * As a side effect it frees the space used by the original
723 * 1 : pats = list of patterns to match against headers
724 * 2 : more_headers = list of functions to add more
725 * headers (client or server)
726 * 3 : csp = Current client state (buffers, headers, etc...)
728 * Returns : Single pointer to a fully formed header, or NULL
729 * on out-of-memory error.
731 *********************************************************************/
732 char *sed(const struct parsers pats[],
733 const add_header_func_ptr more_headers[],
734 struct client_state *csp)
736 struct list_entry *p;
737 const struct parsers *v;
738 const add_header_func_ptr *f;
739 jb_err err = JB_ERR_OK;
741 for (v = pats; (err == JB_ERR_OK) && (v->str != NULL) ; v++)
743 for (p = csp->headers->first; (err == JB_ERR_OK) && (p != NULL) ; p = p->next)
745 /* Header crunch()ed in previous run? -> ignore */
746 if (p->str == NULL) continue;
748 if (v == pats) log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
750 if (strncmpic(p->str, v->str, v->len) == 0)
752 err = v->parser(csp, (char **)&(p->str));
757 /* place any additional headers on the csp->headers list */
758 for (f = more_headers; (err == JB_ERR_OK) && (*f) ; f++)
763 if (err != JB_ERR_OK)
768 return list_to_text(csp->headers);
772 /* here begins the family of parser functions that reformat header lines */
775 /*********************************************************************
779 * Description : This is called if a header matches a pattern to "crunch"
782 * 1 : csp = Current client state (buffers, headers, etc...)
783 * 2 : header = On input, pointer to header to modify.
784 * On output, pointer to the modified header, or NULL
785 * to remove the header. This function frees the
786 * original string if necessary.
788 * Returns : JB_ERR_OK on success, or
789 * JB_ERR_MEMORY on out-of-memory error.
791 *********************************************************************/
792 jb_err crumble(struct client_state *csp, char **header)
794 log_error(LOG_LEVEL_HEADER, "crunch!");
800 /*********************************************************************
802 * Function : server_content_type
804 * Description : Set the content-type for filterable types (text/.*,
805 * javascript and image/gif) unless filtering has been
806 * forbidden (CT_TABOO) while parsing earlier headers.
809 * 1 : csp = Current client state (buffers, headers, etc...)
810 * 2 : header = On input, pointer to header to modify.
811 * On output, pointer to the modified header, or NULL
812 * to remove the header. This function frees the
813 * original string if necessary.
815 * Returns : JB_ERR_OK on success, or
816 * JB_ERR_MEMORY on out-of-memory error.
818 *********************************************************************/
819 jb_err server_content_type(struct client_state *csp, char **header)
821 if (csp->content_type != CT_TABOO)
823 if (strstr(*header, " text/")
824 || strstr(*header, "application/x-javascript"))
825 csp->content_type = CT_TEXT;
826 else if (strstr(*header, " image/gif"))
827 csp->content_type = CT_GIF;
829 csp->content_type = 0;
836 /*********************************************************************
838 * Function : server_transfer_coding
840 * Description : - Prohibit filtering (CT_TABOO) if transfer coding compresses
841 * - Raise the CSP_FLAG_CHUNKED flag if coding is "chunked"
842 * - Change from "chunked" to "identity" if body was chunked
843 * but has been de-chunked for filtering.
846 * 1 : csp = Current client state (buffers, headers, etc...)
847 * 2 : header = On input, pointer to header to modify.
848 * On output, pointer to the modified header, or NULL
849 * to remove the header. This function frees the
850 * original string if necessary.
852 * Returns : JB_ERR_OK on success, or
853 * JB_ERR_MEMORY on out-of-memory error.
855 *********************************************************************/
856 jb_err server_transfer_coding(struct client_state *csp, char **header)
859 * Turn off pcrs and gif filtering if body compressed
861 if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
863 csp->content_type = CT_TABOO;
867 * Raise flag if body chunked
869 if (strstr(*header, "chunked"))
871 csp->flags |= CSP_FLAG_CHUNKED;
874 * If the body was modified, it has been
875 * de-chunked first, so adjust the header:
877 if (csp->flags & CSP_FLAG_MODIFIED)
880 *header = strdup("Transfer-Encoding: identity");
881 return (header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
889 /*********************************************************************
891 * Function : server_content_encoding
893 * Description : Prohibit filtering (CT_TABOO) if content encoding compresses
896 * 1 : csp = Current client state (buffers, headers, etc...)
897 * 2 : header = On input, pointer to header to modify.
898 * On output, pointer to the modified header, or NULL
899 * to remove the header. This function frees the
900 * original string if necessary.
902 * Returns : JB_ERR_OK on success, or
903 * JB_ERR_MEMORY on out-of-memory error.
905 *********************************************************************/
906 jb_err server_content_encoding(struct client_state *csp, char **header)
909 * Turn off pcrs and gif filtering if body compressed
911 if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate"))
913 csp->content_type = CT_TABOO;
921 /*********************************************************************
923 * Function : server_content_length
925 * Description : Adjust Content-Length header if we modified
929 * 1 : csp = Current client state (buffers, headers, etc...)
930 * 2 : header = On input, pointer to header to modify.
931 * On output, pointer to the modified header, or NULL
932 * to remove the header. This function frees the
933 * original string if necessary.
935 * Returns : JB_ERR_OK on success, or
936 * JB_ERR_MEMORY on out-of-memory error.
938 *********************************************************************/
939 jb_err server_content_length(struct client_state *csp, char **header)
941 if (csp->content_length != 0) /* Content length has been modified */
944 *header = (char *) zalloc(100);
947 return JB_ERR_MEMORY;
950 sprintf(*header, "Content-Length: %d", (int) csp->content_length);
952 log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", (int) csp->content_length);
959 /*********************************************************************
961 * Function : server_content_md5
963 * Description : Crumble any Content-MD5 headers if the document was
964 * modified. FIXME: Should we re-compute instead?
967 * 1 : csp = Current client state (buffers, headers, etc...)
968 * 2 : header = On input, pointer to header to modify.
969 * On output, pointer to the modified header, or NULL
970 * to remove the header. This function frees the
971 * original string if necessary.
973 * Returns : JB_ERR_OK on success, or
974 * JB_ERR_MEMORY on out-of-memory error.
976 *********************************************************************/
977 jb_err server_content_md5(struct client_state *csp, char **header)
979 if (csp->flags & CSP_FLAG_MODIFIED)
981 log_error(LOG_LEVEL_HEADER, "Crunching Content-MD5");
989 /*********************************************************************
991 * Function : client_accept_encoding
993 * Description : Rewrite the client's Accept-Encoding header so that
994 * if doesn't allow compression, if the action applies.
995 * Note: For HTTP/1.0 the absence of the header is enough.
998 * 1 : csp = Current client state (buffers, headers, etc...)
999 * 2 : header = On input, pointer to header to modify.
1000 * On output, pointer to the modified header, or NULL
1001 * to remove the header. This function frees the
1002 * original string if necessary.
1004 * Returns : JB_ERR_OK on success, or
1005 * JB_ERR_MEMORY on out-of-memory error.
1007 *********************************************************************/
1008 jb_err client_accept_encoding(struct client_state *csp, char **header)
1010 if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1012 log_error(LOG_LEVEL_HEADER, "Supressed offer to compress content");
1015 if (!strcmpic(csp->http->ver, "HTTP/1.1"))
1017 *header = strdup("Accept-Encoding: identity;q=1.0, *;q=0");
1018 if (*header == NULL)
1020 return JB_ERR_MEMORY;
1029 /*********************************************************************
1031 * Function : client_te
1033 * Description : Rewrite the client's TE header so that
1034 * if doesn't allow compression, if the action applies.
1037 * 1 : csp = Current client state (buffers, headers, etc...)
1038 * 2 : header = On input, pointer to header to modify.
1039 * On output, pointer to the modified header, or NULL
1040 * to remove the header. This function frees the
1041 * original string if necessary.
1043 * Returns : JB_ERR_OK on success, or
1044 * JB_ERR_MEMORY on out-of-memory error.
1046 *********************************************************************/
1047 jb_err client_te(struct client_state *csp, char **header)
1049 if ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1052 log_error(LOG_LEVEL_HEADER, "Supressed offer to compress transfer");
1058 /*********************************************************************
1060 * Function : client_referrer
1062 * Description : Handle the "referer" config setting properly.
1063 * Called from `sed'.
1066 * 1 : csp = Current client state (buffers, headers, etc...)
1067 * 2 : header = On input, pointer to header to modify.
1068 * On output, pointer to the modified header, or NULL
1069 * to remove the header. This function frees the
1070 * original string if necessary.
1072 * Returns : JB_ERR_OK on success, or
1073 * JB_ERR_MEMORY on out-of-memory error.
1075 *********************************************************************/
1076 jb_err client_referrer(struct client_state *csp, char **header)
1080 #ifdef FEATURE_FORCE_LOAD
1081 /* Since the referrer can include the prefix even
1082 * even if the request itself is non-forced, we must
1083 * clean it unconditionally
1085 strclean(*header, FORCE_PREFIX);
1086 #endif /* def FEATURE_FORCE_LOAD */
1089 * Are we sending referer?
1091 if ((csp->action->flags & ACTION_HIDE_REFERER) == 0)
1098 newval = csp->action->string[ACTION_STRING_REFERER];
1100 if ((newval == NULL) || (0 == strcmpic(newval, "block")) )
1105 log_error(LOG_LEVEL_HEADER, "crunch!");
1108 else if (0 == strncmpic(newval, "http://", 7))
1111 * We have a specific (fixed) referer we want to send.
1113 log_error(LOG_LEVEL_HEADER, "modified");
1115 *header = strdup("Referer: ");
1116 string_append(header, newval);
1118 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1123 * Forge a referer as http://[hostname:port of REQUEST]/
1124 * to fool stupid checks for in-site links
1126 if (0 != strcmpic(newval, "forge"))
1129 * Invalid choice - but forge is probably the best default.
1131 log_error(LOG_LEVEL_ERROR, "Bad parameter: +referer{%s}", newval);
1134 *header = strdup("Referer: http://");
1135 string_append(header, csp->http->hostport);
1136 string_append(header, "/");
1137 log_error(LOG_LEVEL_HEADER, "crunch+forge to %s", *header);
1139 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1144 /*********************************************************************
1146 * Function : client_uagent
1148 * Description : Handle the "user-agent" config setting properly
1149 * and remember its original value to enable browser
1150 * bug workarounds. Called from `sed'.
1153 * 1 : csp = Current client state (buffers, headers, etc...)
1154 * 2 : header = On input, pointer to header to modify.
1155 * On output, pointer to the modified header, or NULL
1156 * to remove the header. This function frees the
1157 * original string if necessary.
1159 * Returns : JB_ERR_OK on success, or
1160 * JB_ERR_MEMORY on out-of-memory error.
1162 *********************************************************************/
1163 jb_err client_uagent(struct client_state *csp, char **header)
1167 if ((csp->action->flags & ACTION_HIDE_USER_AGENT) == 0)
1172 newval = csp->action->string[ACTION_STRING_USER_AGENT];
1178 log_error(LOG_LEVEL_HEADER, "modified");
1181 *header = strdup("User-Agent: ");
1182 string_append(header, newval);
1184 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1188 /*********************************************************************
1190 * Function : client_ua
1192 * Description : Handle "ua-" headers properly. Called from `sed'.
1195 * 1 : csp = Current client state (buffers, headers, etc...)
1196 * 2 : header = On input, pointer to header to modify.
1197 * On output, pointer to the modified header, or NULL
1198 * to remove the header. This function frees the
1199 * original string if necessary.
1201 * Returns : JB_ERR_OK on success, or
1202 * JB_ERR_MEMORY on out-of-memory error.
1204 *********************************************************************/
1205 jb_err client_ua(struct client_state *csp, char **header)
1207 if ((csp->action->flags & ACTION_HIDE_USER_AGENT) != 0)
1209 log_error(LOG_LEVEL_HEADER, "crunch!");
1217 /*********************************************************************
1219 * Function : client_from
1221 * Description : Handle the "from" config setting properly.
1222 * Called from `sed'.
1225 * 1 : csp = Current client state (buffers, headers, etc...)
1226 * 2 : header = On input, pointer to header to modify.
1227 * On output, pointer to the modified header, or NULL
1228 * to remove the header. This function frees the
1229 * original string if necessary.
1231 * Returns : JB_ERR_OK on success, or
1232 * JB_ERR_MEMORY on out-of-memory error.
1234 *********************************************************************/
1235 jb_err client_from(struct client_state *csp, char **header)
1239 if ((csp->action->flags & ACTION_HIDE_FROM) == 0)
1246 newval = csp->action->string[ACTION_STRING_FROM];
1249 * Are we blocking the e-mail address?
1251 if ((newval == NULL) || (0 == strcmpic(newval, "block")) )
1253 log_error(LOG_LEVEL_HEADER, "crunch!");
1257 log_error(LOG_LEVEL_HEADER, " modified");
1259 *header = strdup("From: ");
1260 string_append(header, newval);
1262 return (*header == NULL) ? JB_ERR_MEMORY : JB_ERR_OK;
1266 /*********************************************************************
1268 * Function : client_send_cookie
1270 * Description : Handle the "cookie" header properly. Called from `sed'.
1271 * If cookie is accepted, add it to the cookie_list,
1272 * else we crunch it. Mmmmmmmmmmm ... cookie ......
1275 * 1 : csp = Current client state (buffers, headers, etc...)
1276 * 2 : header = On input, pointer to header to modify.
1277 * On output, pointer to the modified header, or NULL
1278 * to remove the header. This function frees the
1279 * original string if necessary.
1281 * Returns : JB_ERR_OK on success, or
1282 * JB_ERR_MEMORY on out-of-memory error.
1284 *********************************************************************/
1285 jb_err client_send_cookie(struct client_state *csp, char **header)
1287 jb_err result = JB_ERR_OK;
1289 if ((csp->action->flags & ACTION_NO_COOKIE_READ) == 0)
1291 /* strlen("cookie: ") == 8 */
1292 result = enlist(csp->cookie_list, *header + 8);
1296 log_error(LOG_LEVEL_HEADER, "Crunched outgoing cookie -- yum!");
1300 * Always remove the cookie here. The cookie header
1301 * will be sent at the end of the header.
1309 /*********************************************************************
1311 * Function : client_x_forwarded
1313 * Description : Handle the "x-forwarded-for" config setting properly,
1314 * also used in the add_client_headers list. Called from `sed'.
1317 * 1 : csp = Current client state (buffers, headers, etc...)
1318 * 2 : header = On input, pointer to header to modify.
1319 * On output, pointer to the modified header, or NULL
1320 * to remove the header. This function frees the
1321 * original string if necessary.
1323 * Returns : JB_ERR_OK on success, or
1324 * JB_ERR_MEMORY on out-of-memory error.
1326 *********************************************************************/
1327 jb_err client_x_forwarded(struct client_state *csp, char **header)
1329 if ((csp->action->flags & ACTION_HIDE_FORWARDED) == 0)
1331 /* Save it so we can re-add it later */
1332 freez(csp->x_forwarded);
1333 csp->x_forwarded = *header;
1336 * Always set *header = NULL, since this information
1337 * will be sent at the end of the header.
1344 log_error(LOG_LEVEL_HEADER, " crunch!");
1351 /*********************************************************************
1353 * Function : client_max_forwards
1355 * Description : If the HTTP method is OPTIONS or TRACE, subtract one
1356 * from the value of the Max-Forwards header field.
1359 * 1 : csp = Current client state (buffers, headers, etc...)
1360 * 2 : header = On input, pointer to header to modify.
1361 * On output, pointer to the modified header, or NULL
1362 * to remove the header. This function frees the
1363 * original string if necessary.
1365 * Returns : JB_ERR_OK on success, or
1366 * JB_ERR_MEMORY on out-of-memory error.
1368 *********************************************************************/
1369 jb_err client_max_forwards(struct client_state *csp, char **header)
1371 unsigned int max_forwards;
1373 if ((0 == strcmpic(csp->http->gpc, "trace"))
1374 || (0 == strcmpic(csp->http->gpc, "options")))
1376 if (1 == sscanf(*header, "Max-Forwards: %u", &max_forwards))
1378 if (max_forwards-- >= 1)
1380 sprintf(*header, "Max-Forwards: %u", max_forwards);
1381 log_error(LOG_LEVEL_HEADER, "Max forwards of %s request now %d", csp->http->gpc, max_forwards);
1385 log_error(LOG_LEVEL_ERROR, "Non-intercepted %s request with Max-Forwards zero!", csp->http->gpc);
1394 /*********************************************************************
1396 * Function : client_host
1398 * Description : If the request URI did not contain host and
1399 * port information, parse and evaluate the Host
1403 * 1 : csp = Current client state (buffers, headers, etc...)
1404 * 2 : header = On input, pointer to header to modify.
1405 * On output, pointer to the modified header, or NULL
1406 * to remove the header. This function frees the
1407 * original string if necessary.
1409 * Returns : JB_ERR_OK on success, or
1410 * JB_ERR_MEMORY on out-of-memory error.
1412 *********************************************************************/
1413 jb_err client_host(struct client_state *csp, char **header)
1417 if (!csp->http->hostport || (*csp->http->hostport == '*') ||
1418 *csp->http->hostport == ' ' || *csp->http->hostport == '\0')
1421 if (NULL == (p = strdup((*header)+6)))
1423 return JB_ERR_MEMORY;
1426 if (NULL == (q = strdup(p)))
1429 return JB_ERR_MEMORY;
1432 freez(csp->http->hostport);
1433 csp->http->hostport = p;
1434 freez(csp->http->host);
1435 csp->http->host = q;
1436 q = strchr(csp->http->host, ':');
1439 /* Terminate hostname and evaluate port string */
1441 csp->http->port = atoi(q);
1445 csp->http->port = csp->http->ssl ? 443 : 80;
1448 log_error(LOG_LEVEL_HEADER, "New host and port from Host field: %s = %s:%d",
1449 csp->http->hostport, csp->http->host, csp->http->port);
1456 /* the following functions add headers directly to the header list */
1458 /*********************************************************************
1460 * Function : client_host_adder
1462 * Description : Adds the Host: header field if it is missing.
1463 * Called from `sed'.
1466 * 1 : csp = Current client state (buffers, headers, etc...)
1468 * Returns : JB_ERR_OK on success, or
1469 * JB_ERR_MEMORY on out-of-memory error.
1471 *********************************************************************/
1472 jb_err client_host_adder(struct client_state *csp)
1477 if ( !csp->http->hostport || !*(csp->http->hostport))
1483 * remove 'user:pass@' from 'proto://user:pass@host'
1485 if ( (p = strchr( csp->http->hostport, '@')) != NULL )
1491 p = csp->http->hostport;
1494 log_error(LOG_LEVEL_HEADER, "addh-unique: Host: %s", p);
1495 err = enlist_unique_header(csp->headers, "Host", p);
1501 /*********************************************************************
1503 * Function : client_cookie_adder
1505 * Description : Used in the add_client_headers list. Called from `sed'.
1508 * 1 : csp = Current client state (buffers, headers, etc...)
1510 * Returns : JB_ERR_OK on success, or
1511 * JB_ERR_MEMORY on out-of-memory error.
1513 *********************************************************************/
1514 jb_err client_cookie_adder(struct client_state *csp)
1516 struct list_entry *lst;
1518 struct list_entry *list1 = csp->cookie_list->first;
1519 struct list_entry *list2 = csp->action->multi[ACTION_MULTI_WAFER]->first;
1520 int first_cookie = 1;
1523 if ((list1 == NULL) && (list2 == NULL))
1529 tmp = strdup("Cookie: ");
1531 for (lst = list1; lst ; lst = lst->next)
1539 string_append(&tmp, "; ");
1541 string_append(&tmp, lst->str);
1544 for (lst = list2; lst ; lst = lst->next)
1552 string_append(&tmp, "; ");
1554 string_join(&tmp, cookie_encode(lst->str));
1559 return JB_ERR_MEMORY;
1562 log_error(LOG_LEVEL_HEADER, "addh: %s", tmp);
1563 err = enlist(csp->headers, tmp);
1569 /*********************************************************************
1571 * Function : client_accept_encoding_adder
1573 * Description : Add an Accept-Encoding header to the client's request
1574 * that disables compression if the action applies, and
1575 * the header is not already there. Called from `sed'.
1576 * Note: For HTTP/1.0, the absence of the header is enough.
1579 * 1 : csp = Current client state (buffers, headers, etc...)
1581 * Returns : JB_ERR_OK on success, or
1582 * JB_ERR_MEMORY on out-of-memory error.
1584 *********************************************************************/
1585 jb_err client_accept_encoding_adder(struct client_state *csp)
1587 if ( ((csp->action->flags & ACTION_NO_COMPRESSION) != 0)
1588 && (!strcmpic(csp->http->ver, "HTTP/1.1")) )
1590 return enlist_unique(csp->headers, "Accept-Encoding: identity;q=1.0, *;q=0", 16);
1597 /*********************************************************************
1599 * Function : client_xtra_adder
1601 * Description : Used in the add_client_headers list. Called from `sed'.
1604 * 1 : csp = Current client state (buffers, headers, etc...)
1606 * Returns : JB_ERR_OK on success, or
1607 * JB_ERR_MEMORY on out-of-memory error.
1609 *********************************************************************/
1610 jb_err client_xtra_adder(struct client_state *csp)
1612 struct list_entry *lst;
1615 for (lst = csp->action->multi[ACTION_MULTI_ADD_HEADER]->first;
1616 lst ; lst = lst->next)
1618 log_error(LOG_LEVEL_HEADER, "addh: %s", lst->str);
1619 err = enlist(csp->headers, lst->str);
1631 /*********************************************************************
1633 * Function : client_x_forwarded_adder
1635 * Description : Used in the add_client_headers list. Called from `sed'.
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 client_x_forwarded_adder(struct client_state *csp)
1649 if ((csp->action->flags & ACTION_HIDE_FORWARDED) != 0)
1654 if (csp->x_forwarded)
1656 p = strdup(csp->x_forwarded);
1657 string_append(&p, ", ");
1661 p = strdup("X-Forwarded-For: ");
1663 string_append(&p, csp->ip_addr_str);
1667 return JB_ERR_MEMORY;
1670 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1671 err = enlist(csp->headers, p);
1678 /*********************************************************************
1680 * Function : connection_close_adder
1682 * Description : Adds a "Connection: close" header to csp->headers
1683 * as a temporary fix for the needed but missing HTTP/1.1
1684 * support. Called from `sed'.
1685 * FIXME: This whole function shouldn't be neccessary!
1688 * 1 : csp = Current client state (buffers, headers, etc...)
1690 * Returns : JB_ERR_OK on success, or
1691 * JB_ERR_MEMORY on out-of-memory error.
1693 *********************************************************************/
1694 jb_err connection_close_adder(struct client_state *csp)
1696 return enlist(csp->headers, "Connection: close");
1700 /*********************************************************************
1702 * Function : server_http
1704 * Description : - Save the HTTP Status into csp->http->status
1705 * - Set CT_TABOO to prevent filtering if the answer
1706 * is a partial range (HTTP status 206)
1707 * - Rewrite HTTP/1.1 answers to HTTP/1.0 if +downgrade
1711 * 1 : csp = Current client state (buffers, headers, etc...)
1712 * 2 : header = On input, pointer to header to modify.
1713 * On output, pointer to the modified header, or NULL
1714 * to remove the header. This function frees the
1715 * original string if necessary.
1717 * Returns : JB_ERR_OK on success, or
1718 * JB_ERR_MEMORY on out-of-memory error.
1720 *********************************************************************/
1721 jb_err server_http(struct client_state *csp, char **header)
1723 sscanf(*header, "HTTP/%*d.%*d %d", &(csp->http->status));
1724 if (csp->http->status == 206)
1726 csp->content_type = CT_TABOO;
1729 if ((csp->action->flags & ACTION_DOWNGRADE) != 0)
1732 log_error(LOG_LEVEL_HEADER, "Downgraded answer to HTTP/1.0");
1739 /*********************************************************************
1741 * Function : server_set_cookie
1743 * Description : Handle the server "cookie" header properly.
1744 * Log cookie to the jar file. Then "crunch" it,
1745 * or accept it. Called from `sed'.
1748 * 1 : csp = Current client state (buffers, headers, etc...)
1749 * 2 : header = On input, pointer to header to modify.
1750 * On output, pointer to the modified header, or NULL
1751 * to remove the header. This function frees the
1752 * original string if necessary.
1754 * Returns : JB_ERR_OK on success, or
1755 * JB_ERR_MEMORY on out-of-memory error.
1757 *********************************************************************/
1758 jb_err server_set_cookie(struct client_state *csp, char **header)
1760 #ifdef FEATURE_COOKIE_JAR
1761 if (csp->config->jar)
1764 * Write timestamp into outbuf.
1766 * Complex because not all OSs have tm_gmtoff or
1767 * the %z field in strftime()
1769 char tempbuf[ BUFFER_SIZE ];
1773 #ifdef HAVE_LOCALTIME_R
1774 tm_now = *localtime_r(&now, &tm_now);
1776 tm_now = *localtime (&now);
1778 strftime(tempbuf, BUFFER_SIZE-6, "%b %d %H:%M:%S ", &tm_now);
1780 /* strlen("set-cookie: ") = 12 */
1781 fprintf(csp->config->jar, "%s %s\t%s\n", tempbuf, csp->http->host, *header + 12);
1783 #endif /* def FEATURE_COOKIE_JAR */
1785 if ((csp->action->flags & ACTION_NO_COOKIE_SET) != 0)
1787 log_error(LOG_LEVEL_HEADER, "Crunched incoming cookie -- yum!");
1788 return crumble(csp, header);
1790 else if ((csp->action->flags & ACTION_NO_COOKIE_KEEP) != 0)
1792 /* Flag whether or not to log a message */
1795 /* A variable to store the tag we're working on */
1798 /* Skip "Set-Cookie:" (11 characters) in header */
1799 cur_tag = *header + 11;
1801 /* skip whitespace between "Set-Cookie:" and value */
1802 while (*cur_tag && ijb_isspace(*cur_tag))
1807 /* Loop through each tag in the cookie */
1811 char *next_tag = strchr(cur_tag, ';');
1812 if (next_tag != NULL)
1814 /* Skip the ';' character itself */
1817 /* skip whitespace ";" and start of tag */
1818 while (*next_tag && ijb_isspace(*next_tag))
1825 /* "Next tag" is the end of the string */
1826 next_tag = cur_tag + strlen(cur_tag);
1829 /* Is this the "Expires" tag? */
1830 if (strncmpic(cur_tag, "expires=", 8) == 0)
1832 /* Delete the tag by copying the rest of the string over it.
1833 * (Note that we cannot just use "strcpy(cur_tag, next_tag)",
1834 * since the behaviour of strcpy is undefined for overlapping
1837 memmove(cur_tag, next_tag, strlen(next_tag) + 1);
1839 /* That changed the header, need to issue a log message */
1842 /* Note that the next tag has now been moved to *cur_tag,
1843 * so we do not need to update the cur_tag pointer.
1848 /* Move on to next cookie tag */
1855 log_error(LOG_LEVEL_HEADER, "Changed cookie to a temporary one.");
1863 #ifdef FEATURE_FORCE_LOAD
1864 /*********************************************************************
1866 * Function : strclean
1868 * Description : In-Situ-Eliminate all occurances of substring in
1872 * 1 : string = string to clean
1873 * 2 : substring = substring to eliminate
1875 * Returns : Number of eliminations
1877 *********************************************************************/
1878 int strclean(const char *string, const char *substring)
1880 int hits = 0, len = strlen(substring);
1883 while((pos = strstr(string, substring)) != NULL)
1890 while (*p++ != '\0');
1897 #endif /* def FEATURE_FORCE_LOAD */