1 const char parsers_rcs[] = "$Id: parsers.c,v 1.8 2001/05/27 22:17:04 oes Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/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', `free_http_request', `get_header',
14 * `list_to_text', `parse_http_request', `sed',
15 * and `server_set_cookie'.
17 * Copyright : Written by and Copyright (C) 2001 the SourceForge
18 * IJBSWA team. http://ijbswa.sourceforge.net
20 * Based on the Internet Junkbuster originally written
21 * by and Copyright (C) 1997 Anonymous Coders and
22 * Junkbusters Corporation. http://www.junkbusters.com
24 * This program is free software; you can redistribute it
25 * and/or modify it under the terms of the GNU General
26 * Public License as published by the Free Software
27 * Foundation; either version 2 of the License, or (at
28 * your option) any later version.
30 * This program is distributed in the hope that it will
31 * be useful, but WITHOUT ANY WARRANTY; without even the
32 * implied warranty of MERCHANTABILITY or FITNESS FOR A
33 * PARTICULAR PURPOSE. See the GNU General Public
34 * License for more details.
36 * The GNU General Public License should be included with
37 * this file. If not, you can view it at
38 * http://www.gnu.org/copyleft/gpl.html
39 * or write to the Free Software Foundation, Inc., 59
40 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
44 * Revision 1.8 2001/05/27 22:17:04 oes
46 * - re_process_buffer no longer writes the modified buffer
47 * to the client, which was very ugly. It now returns the
48 * buffer, which it is then written by chat.
50 * - content_length now adjusts the Content-Length: header
51 * for modified documents rather than crunch()ing it.
52 * (Length info in csp->content_length, which is 0 for
53 * unmodified documents)
55 * - For this to work, sed() is called twice when filtering.
57 * Revision 1.7 2001/05/27 13:19:06 oes
58 * Patched Joergs solution for the content-length in.
60 * Revision 1.6 2001/05/26 13:39:32 jongfoster
61 * Only crunches Content-Length header if applying RE filtering.
62 * Without this fix, Microsoft Windows Update wouldn't work.
64 * Revision 1.5 2001/05/26 00:28:36 jongfoster
65 * Automatic reloading of config file.
66 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
67 * Most of the global variables have been moved to a new
68 * struct configuration_spec, accessed through csp->config->globalname
69 * Most of the globals remaining are used by the Win32 GUI.
71 * Revision 1.4 2001/05/22 18:46:04 oes
73 * - Enabled filtering banners by size rather than URL
74 * by adding patterns that replace all standard banner
75 * sizes with the "Junkbuster" gif to the re_filterfile
77 * - Enabled filtering WebBugs by providing a pattern
78 * which kills all 1x1 images
80 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
81 * which is selected by the (nonstandard and therefore
82 * capital) letter 'U' in the option string.
83 * It causes the quantifiers to be ungreedy by default.
84 * Appending a ? turns back to greedy (!).
86 * - Added a new interceptor ijb-send-banner, which
87 * sends back the "Junkbuster" gif. Without imagelist or
88 * MSIE detection support, or if tinygif = 1, or the
89 * URL isn't recognized as an imageurl, a lame HTML
90 * explanation is sent instead.
92 * - Added new feature, which permits blocking remote
93 * script redirects and firing back a local redirect
95 * The feature is conditionally compiled, i.e. it
96 * can be disabled with --disable-fast-redirects,
97 * plus it must be activated by a "fast-redirects"
98 * line in the config file, has its own log level
99 * and of course wants to be displayed by show-proxy-args
100 * Note: Boy, all the #ifdefs in 1001 locations and
101 * all the fumbling with configure.in and acconfig.h
102 * were *way* more work than the feature itself :-(
104 * - Because a generic redirect template was needed for
105 * this, tinygif = 3 now uses the same.
107 * - Moved GIFs, and other static HTTP response templates
112 * - Removed some >400 CRs again (Jon, you really worked
115 * Revision 1.3 2001/05/20 01:21:20 jongfoster
116 * Version 2.9.4 checkin.
117 * - Merged popupfile and cookiefile, and added control over PCRS
118 * filtering, in new "permissionsfile".
119 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
120 * file error you now get a message box (in the Win32 GUI) rather
121 * than the program exiting with no explanation.
122 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
124 * - Removed tabs from "config"
125 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
126 * - Bumped up version number.
128 * Revision 1.2 2001/05/17 23:02:36 oes
129 * - Made referrer option accept 'L' as a substitute for 'ยง'
131 * Revision 1.1.1.1 2001/05/15 13:59:01 oes
132 * Initial import of version 2.9.3 source tree
135 *********************************************************************/
141 #include <sys/types.h>
155 #include "showargs.h"
159 #include "jbsockets.h"
160 #include "miscutil.h"
162 const char parsers_h_rcs[] = PARSERS_H_VERSION;
164 /* Fix a problem with Solaris. There should be no effect on other
166 * Solaris's isspace() is a macro which uses it's argument directly
167 * as an array index. Therefore we need to make sure that high-bit
168 * characters generate +ve values, and ideally we also want to make
169 * the argument match the declared parameter type of "int".
171 * Why did they write a character function that can't take a simple
172 * "char" argument? Doh!
174 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
175 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
178 const struct parsers client_patterns[] = {
179 { "referer:", 8, client_referrer },
180 { "user-agent:", 11, client_uagent },
181 { "ua-", 3, client_ua },
182 { "from:", 5, client_from },
183 { "cookie:", 7, client_send_cookie },
184 { "x-forwarded-for:", 16, client_x_forwarded },
185 { "proxy-connection:", 17, crumble },
187 { "Accept-Encoding: gzip", 21, crumble },
188 #endif /* def DENY_GZIP */
189 #if defined(DETECT_MSIE_IMAGES)
190 { "Accept:", 7, client_accept },
191 #endif /* defined(DETECT_MSIE_IMAGES) */
193 { "Host:", 5, client_host },
194 #endif /* def FORCE_LOAD */
195 /* { "if-modified-since:", 18, crumble }, */
199 const struct interceptors intercept_patterns[] = {
200 { "show-proxy-args", 14, show_proxy_args },
201 { "ijb-send-banner", 14, ijb_send_banner },
203 { "ij-untrusted-url", 15, ij_untrusted_url },
204 #endif /* def TRUST_FILES */
208 const struct parsers server_patterns[] = {
209 { "set-cookie:", 11, server_set_cookie },
210 { "connection:", 11, crumble },
211 #if defined(PCRS) || defined(KILLPOPUPS)
212 { "Content-Type:", 13, content_type },
213 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
215 { "Content-Length:", 15, content_length },
216 #endif /* def PCRS */
221 void (* const add_client_headers[])(struct client_state *) = {
223 client_x_forwarded_adder,
229 void (* const add_server_headers[])(struct client_state *) = {
234 /*********************************************************************
236 * Function : flush_socket
238 * Description : Write any pending "buffered" content.
241 * 1 : fd = file descriptor of the socket to read
242 * 2 : csp = Current client state (buffers, headers, etc...)
244 * Returns : On success, the number of bytes written are returned (zero
245 * indicates nothing was written). On error, -1 is returned,
246 * and errno is set appropriately. If count is zero and the
247 * file descriptor refers to a regular file, 0 will be
248 * returned without causing any other effect. For a special
249 * file, the results are not portable.
251 *********************************************************************/
252 int flush_socket(int fd, struct client_state *csp)
254 struct iob *iob = csp->iob;
255 int n = iob->eod - iob->cur;
262 n = write_socket(fd, iob->cur, n);
263 iob->eod = iob->cur = iob->buf;
269 /*********************************************************************
271 * Function : add_to_iob
273 * Description : Add content to the buffered page.
276 * 1 : csp = Current client state (buffers, headers, etc...)
277 * 2 : buf = holds the content to be added to the page
278 * 3 : n = number of bytes to be added
280 * Returns : Number of bytes in the content buffer.
282 *********************************************************************/
283 int add_to_iob(struct client_state *csp, char *buf, int n)
285 struct iob *iob = csp->iob;
289 have = iob->eod - iob->cur;
298 if ((p = (char *)malloc(need + 1)) == NULL)
300 log_error(LOG_LEVEL_ERROR, "malloc() iob failed: %E");
306 /* there is something in the buffer - save it */
307 memcpy(p, iob->cur, have);
309 /* replace the buffer with the new space */
313 /* point to the end of the data */
318 /* the buffer is empty, free it and reinitialize */
323 /* copy the new data into the iob buffer */
326 /* point to the end of the data */
329 /* null terminate == cheap insurance */
332 /* set the pointers to the new values */
341 /*********************************************************************
343 * Function : get_header
345 * Description : This (odd) routine will parse the csp->iob
348 * 1 : csp = Current client state (buffers, headers, etc...)
350 * Returns : Any one of the following:
352 * 1) a pointer to a dynamically allocated string that contains a header line
353 * 2) NULL indicating that the end of the header was reached
354 * 3) "" indicating that the end of the iob was reached before finding
355 * a complete header line.
357 *********************************************************************/
358 char *get_header(struct client_state *csp)
364 if ((iob->cur == NULL)
365 || ((p = strchr(iob->cur, '\n')) == NULL))
367 return(""); /* couldn't find a complete header */
372 ret = strdup(iob->cur);
376 if ((q = strchr(ret, '\r'))) *q = '\0';
378 /* is this a blank linke (i.e. the end of the header) ? */
390 /*********************************************************************
394 * Description : Append a string into a specified string list.
397 * 1 : h = pointer to list 'dummy' header
398 * 2 : s = string to add to the list
402 *********************************************************************/
403 void enlist(struct list *h, const char *s)
405 struct list *n = (struct list *)malloc(sizeof(*n));
428 /*********************************************************************
430 * Function : destroy_list
432 * Description : Destroy a string list (opposite of enlist)
435 * 1 : h = pointer to list 'dummy' header
439 *********************************************************************/
440 void destroy_list(struct list *h)
444 for (p = h->next; p ; p = n)
451 memset(h, '\0', sizeof(*h));
456 /*********************************************************************
458 * Function : list_to_text
460 * Description : "Flaten" a string list into 1 long \r\n delimited string.
463 * 1 : h = pointer to list 'dummy' header
465 * Returns : NULL on malloc error, else new long string.
467 *********************************************************************/
468 static char *list_to_text(struct list *h)
477 for (p = h->next; p ; p = p->next)
481 size += strlen(p->str) + 2;
485 if ((ret = (char *)malloc(size + 1)) == NULL)
494 for (p = h->next; p ; p = p->next)
500 *s++ = '\r'; *s++ = '\n';
509 /*********************************************************************
513 * Description : add, delete or modify lines in the HTTP header streams.
514 * On entry, it receives a linked list of headers space
515 * that was allocated dynamically (both the list nodes
516 * and the header contents).
518 * As a side effect it frees the space used by the original
522 * 1 : pats = list of patterns to match against headers
523 * 2 : more_headers = list of functions to add more
524 * headers (client or server)
525 * 3 : csp = Current client state (buffers, headers, etc...)
527 * Returns : Single pointer to a fully formed header.
529 *********************************************************************/
530 char *sed(const struct parsers pats[], void (* const more_headers[])(struct client_state *), struct client_state *csp)
533 const struct parsers *v;
537 for (v = pats; v->str ; v++)
539 for (p = csp->headers->next; p ; p = p->next)
541 /* Header crunch()ed in previous run? -> ignore */
542 if (p->str == NULL) continue;
544 if (v == pats) log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
546 if (strncmpic(p->str, v->str, v->len) == 0)
548 hdr = v->parser(v, p->str, csp);
555 /* place any additional headers on the csp->headers list */
556 for (f = more_headers; *f ; f++)
561 /* add the blank line at the end of the header, if necessary */
562 if ( (csp->headers->last == NULL)
563 || (csp->headers->last->str == NULL)
564 || (*csp->headers->last->str != '\0') )
566 enlist(csp->headers, "");
569 hdr = list_to_text(csp->headers);
576 /*********************************************************************
578 * Function : free_http_request
580 * Description : Freez a http_request structure
583 * 1 : http = points to a http_request structure to free
587 *********************************************************************/
588 void free_http_request(struct http_request *http)
593 freez(http->hostport);
600 /*********************************************************************
602 * Function : parse_http_request
604 * Description : Parse out the host and port from the URL. Find the
605 * hostname & path, port (if ':'), and/or password (if '@')
608 * 1 : req = URL (or is it URI?) to break down
609 * 2 : http = pointer to the http structure to hold elements
610 * 3 : csp = Current client state (buffers, headers, etc...)
614 *********************************************************************/
615 void parse_http_request(char *req, struct http_request *http, struct client_state *csp)
617 char *buf, *v[10], *url, *p;
620 memset(http, '\0', sizeof(*http));
622 http->cmd = strdup(req);
626 n = ssplit(buf, " \r\n", v, SZ(v), 1, 1);
630 /* this could be a CONNECT request */
631 if (strcmpic(v[0], "connect") == 0)
634 http->gpc = strdup(v[0]);
635 http->hostport = strdup(v[1]);
636 http->ver = strdup(v[2]);
641 /* This next line is a little ugly, but it simplifies the if statement below. */
642 /* Basically if using webDAV, we want the OR condition to use these too. */
646 * These are the headers as defined in RFC2518 to add webDAV support
649 #define OR_WEBDAV || \
650 (0 == strcmpic(v[0], "propfind")) || \
651 (0 == strcmpic(v[0], "proppatch")) || \
652 (0 == strcmpic(v[0], "move")) || \
653 (0 == strcmpic(v[0], "copy")) || \
654 (0 == strcmpic(v[0], "mkcol")) || \
655 (0 == strcmpic(v[0], "lock")) || \
656 (0 == strcmpic(v[0], "unlock"))
658 #else /* No webDAV support is enabled. Provide an empty OR_WEBDAV macro. */
664 /* or it could be a GET or a POST (possibly webDAV too) */
665 if ((strcmpic(v[0], "get") == 0) ||
666 (strcmpic(v[0], "head") == 0) OR_WEBDAV ||
667 (strcmpic(v[0], "post") == 0))
670 http->gpc = strdup(v[0]);
672 http->ver = strdup(v[2]);
674 if (strncmpic(url, "http://", 7) == 0)
678 else if (strncmpic(url, "https://", 8) == 0)
687 if (url && (p = strchr(url, '/')))
689 http->path = strdup(p);
691 http->hostport = strdup(url);
699 if (http->hostport == NULL)
701 free_http_request(http);
705 buf = strdup(http->hostport);
708 /* check if url contains password */
709 n = ssplit(buf, "@", v, SZ(v), 1, 1);
712 char * newbuf = NULL;
713 newbuf = strdup(v[1]);
718 n = ssplit(buf, ":", v, SZ(v), 1, 1);
722 http->host = strdup(v[0]);
728 http->host = strdup(v[0]);
729 http->port = atoi(v[1]);
734 if (http->host == NULL)
736 free_http_request(http);
739 if (http->path == NULL)
741 http->path = strdup("");
747 /* here begins the family of parser functions that reformat header lines */
750 /*********************************************************************
754 * Description : This is called if a header matches a pattern to "crunch"
757 * 1 : v = Pointer to parsers structure, which basically holds
758 * headers (client or server) that we want to "crunch"
759 * 2 : s = header (from sed) to "crunch"
760 * 3 : csp = Current client state (buffers, headers, etc...)
762 * Returns : Always NULL.
764 *********************************************************************/
765 char *crumble(const struct parsers *v, char *s, struct client_state *csp)
767 log_error(LOG_LEVEL_HEADER, "crunch!");
773 #if defined(PCRS) || defined(KILLPOPUPS)
775 /*********************************************************************
777 * Function : content_type
779 * Description : Is this a text/* or javascript MIME Type?
783 * 2 : s = header string we are "considering"
784 * 3 : csp = Current client state (buffers, headers, etc...)
786 * Returns : A duplicate string pointer to this header (ie. pass thru)
788 *********************************************************************/
789 char *content_type(const struct parsers *v, char *s, struct client_state *csp)
791 if (strstr (s, " text/") || strstr (s, "application/x-javascript"))
799 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
803 /*********************************************************************
805 * Function : content_length
807 * Description : Crunch Content-Length header if & only if we are
808 * filtering this page through PCRS.
812 * 2 : s = header string we are "considering"
813 * 3 : csp = Current client state (buffers, headers, etc...)
815 * Returns : A duplicate string pointer to this header (ie. pass thru)
817 *********************************************************************/
818 char *content_length(const struct parsers *v, char *s, struct client_state *csp)
820 if (csp->content_length != 0) /* Content has been modified */
822 s = (char *) zalloc(100);
823 sprintf(s, "Content-Length: %d", csp->content_length);
824 log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", csp->content_length);
833 #endif /* def PCRS */
836 /*********************************************************************
838 * Function : client_referrer
840 * Description : Handle the "referer" config setting properly.
845 * 2 : s = header (from sed) to "crunch"
846 * 3 : csp = Current client state (buffers, headers, etc...)
848 * Returns : NULL if crunched, or a malloc'ed string with the original
851 *********************************************************************/
852 char *client_referrer(const struct parsers *v, char *s, struct client_state *csp)
855 /* Since the referrer can include the prefix even
856 * even if the request itself is non-forced, we must
857 * clean it unconditionally
859 strclean(s, FORCE_PREFIX);
860 #endif /* def FORCE_LOAD */
862 csp->referrer = strdup(s);
864 if (csp->config->referrer == NULL)
866 log_error(LOG_LEVEL_HEADER, "crunch!");
870 if (*csp->config->referrer == '.')
875 if (*csp->config->referrer == '@')
877 if (csp->permissions & PERMIT_COOKIE_READ)
883 log_error(LOG_LEVEL_HEADER, "crunch!");
889 * New option ยง or L: Forge a referer as http://[hostname:port of REQUEST]/
890 * to fool stupid checks for in-site links
893 if (*csp->config->referrer == 'ยง' || *csp->config->referrer == 'L')
895 if (csp->permissions & PERMIT_COOKIE_READ)
901 log_error(LOG_LEVEL_HEADER, "crunch+forge!");
902 s = strsav(NULL, "Referer: ");
903 s = strsav(s, "http://");
904 s = strsav(s, csp->http->hostport);
910 log_error(LOG_LEVEL_HEADER, "modified");
912 s = strsav( NULL, "Referer: " );
913 s = strsav( s, csp->config->referrer );
919 /*********************************************************************
921 * Function : client_uagent
923 * Description : Handle the "user-agent" config setting properly.
928 * 2 : s = header (from sed) to "crunch"
929 * 3 : csp = Current client state (buffers, headers, etc...)
931 * Returns : A malloc'ed pointer to the default agent, or
932 * a malloc'ed string pointer to this header (ie. pass thru).
934 *********************************************************************/
935 char *client_uagent(const struct parsers *v, char *s, struct client_state *csp)
937 #ifdef DETECT_MSIE_IMAGES
938 if (strstr (s, "MSIE "))
940 /* This is Microsoft Internet Explorer.
941 * Enable auto-detect.
943 csp->accept_types |= ACCEPT_TYPE_IS_MSIE;
945 #endif /* def DETECT_MSIE_IMAGES */
947 if (csp->config->uagent == NULL)
949 log_error(LOG_LEVEL_HEADER, "default");
950 return(strdup(DEFAULT_USER_AGENT));
953 if (*csp->config->uagent == '.')
958 if (*csp->config->uagent == '@')
960 if (csp->permissions & PERMIT_COOKIE_READ)
966 log_error(LOG_LEVEL_HEADER, "default");
967 return(strdup(DEFAULT_USER_AGENT));
971 log_error(LOG_LEVEL_HEADER, "modified");
973 s = strsav( NULL, "User-Agent: " );
974 s = strsav( s, csp->config->uagent );
980 /*********************************************************************
982 * Function : client_ua
984 * Description : Handle "ua-" headers properly. Called from `sed'.
988 * 2 : s = header (from sed) to "crunch"
989 * 3 : csp = Current client state (buffers, headers, etc...)
991 * Returns : NULL if crunched, or a malloc'ed string to original header
993 *********************************************************************/
994 char *client_ua(const struct parsers *v, char *s, struct client_state *csp)
996 if (csp->config->uagent == NULL)
998 log_error(LOG_LEVEL_HEADER, "crunch!");
1002 if (*csp->config->uagent == '.')
1007 if (*csp->config->uagent == '@')
1009 if (csp->permissions & PERMIT_COOKIE_READ)
1015 log_error(LOG_LEVEL_HEADER, "crunch!");
1020 log_error(LOG_LEVEL_HEADER, "crunch!");
1026 /*********************************************************************
1028 * Function : client_from
1030 * Description : Handle the "from" config setting properly.
1031 * Called from `sed'.
1035 * 2 : s = header (from sed) to "crunch"
1036 * 3 : csp = Current client state (buffers, headers, etc...)
1038 * Returns : NULL if crunched, or a malloc'ed string to
1039 * modified/original header.
1041 *********************************************************************/
1042 char *client_from(const struct parsers *v, char *s, struct client_state *csp)
1044 /* if not set, zap it */
1045 if (csp->config->from == NULL)
1047 log_error(LOG_LEVEL_HEADER, "crunch!");
1051 if (*csp->config->from == '.')
1056 log_error(LOG_LEVEL_HEADER, " modified");
1058 s = strsav( NULL, "From: " );
1059 s = strsav( s, csp->config->from );
1065 /*********************************************************************
1067 * Function : client_send_cookie
1069 * Description : Handle the "cookie" header properly. Called from `sed'.
1070 * If cookie is accepted, add it to the cookie_list,
1071 * else we crunch it. Mmmmmmmmmmm ... cookie ......
1074 * 1 : v = pattern of cookie `sed' found matching
1075 * 2 : s = header (from sed) to "crunch"
1076 * 3 : csp = Current client state (buffers, headers, etc...)
1078 * Returns : Always NULL.
1080 *********************************************************************/
1081 char *client_send_cookie(const struct parsers *v, char *s, struct client_state *csp)
1083 if (csp->permissions & PERMIT_COOKIE_READ)
1085 enlist(csp->cookie_list, s + v->len + 1);
1089 log_error(LOG_LEVEL_HEADER, " crunch!");
1093 * Always return NULL here. The cookie header
1094 * will be sent at the end of the header.
1101 /*********************************************************************
1103 * Function : client_x_forwarded
1105 * Description : Handle the "x-forwarded-for" config setting properly,
1106 * also used in the add_client_headers list. Called from `sed'.
1110 * 2 : s = header (from sed) to "crunch"
1111 * 3 : csp = Current client state (buffers, headers, etc...)
1113 * Returns : Always NULL.
1115 *********************************************************************/
1116 char *client_x_forwarded(const struct parsers *v, char *s, struct client_state *csp)
1118 if (csp->config->add_forwarded)
1120 csp->x_forwarded = strdup(s);
1124 * Always return NULL, since this information
1125 * will be sent at the end of the header.
1132 #if defined(DETECT_MSIE_IMAGES)
1133 /*********************************************************************
1135 * Function : client_accept
1137 * Description : Detect whether the client wants HTML or an image.
1138 * Clients do not always make this information available
1139 * in a sane way. Always passes the header through
1140 * the proxy unchanged.
1144 * 2 : s = Header string. Null terminated.
1145 * 3 : csp = Current client state (buffers, headers, etc...)
1147 * Returns : Duplicate of argument s.
1149 *********************************************************************/
1150 char *client_accept(const struct parsers *v, char *s, struct client_state *csp)
1152 #ifdef DETECT_MSIE_IMAGES
1153 if (strstr (s, "image/gif"))
1155 /* Client will accept HTML. If this seems counterintuitive,
1158 csp->accept_types |= ACCEPT_TYPE_MSIE_HTML;
1162 csp->accept_types |= ACCEPT_TYPE_MSIE_IMAGE;
1164 #endif /* def DETECT_MSIE_IMAGES */
1169 #endif /* defined(DETECT_MSIE_IMAGES) */
1173 /* the following functions add headers directly to the header list */
1176 /*********************************************************************
1178 * Function : client_cookie_adder
1180 * Description : Used in the add_client_headers list. Called from `sed'.
1183 * 1 : csp = Current client state (buffers, headers, etc...)
1187 *********************************************************************/
1188 void client_cookie_adder(struct client_state *csp)
1194 for (l = csp->cookie_list->next; l ; l = l->next)
1198 tmp = strsav(tmp, "; ");
1200 tmp = strsav(tmp, l->str);
1203 for (l = csp->config->wafer_list->next; l ; l = l->next)
1207 tmp = strsav(tmp, "; ");
1210 if ((e = cookie_encode(l->str)))
1212 tmp = strsav(tmp, e);
1221 ret = strdup("Cookie: ");
1222 ret = strsav(ret, tmp);
1223 log_error(LOG_LEVEL_HEADER, "addh: %s", ret);
1224 enlist(csp->headers, ret);
1232 /*********************************************************************
1234 * Function : client_xtra_adder
1236 * Description : Used in the add_client_headers list. Called from `sed'.
1239 * 1 : csp = Current client state (buffers, headers, etc...)
1243 *********************************************************************/
1244 void client_xtra_adder(struct client_state *csp)
1248 for (l = csp->config->xtra_list->next; l ; l = l->next)
1250 log_error(LOG_LEVEL_HEADER, "addh: %s", l->str);
1251 enlist(csp->headers, l->str);
1257 /*********************************************************************
1259 * Function : client_x_forwarded_adder
1261 * Description : Used in the add_client_headers list. Called from `sed'.
1264 * 1 : csp = Current client state (buffers, headers, etc...)
1268 *********************************************************************/
1269 void client_x_forwarded_adder(struct client_state *csp)
1273 if (csp->config->add_forwarded == 0)
1278 if (csp->x_forwarded)
1280 p = strsav(p, csp->x_forwarded);
1281 p = strsav(p, ", ");
1282 p = strsav(p, csp->ip_addr_str);
1286 p = strsav(p, "X-Forwarded-For: ");
1287 p = strsav(p, csp->ip_addr_str);
1290 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1291 enlist(csp->headers, p);
1296 /*********************************************************************
1298 * Function : server_set_cookie
1300 * Description : Handle the server "cookie" header properly.
1301 * Log cookie to the jar file. Then "crunch" it,
1302 * or accept it. Called from `sed'.
1305 * 1 : v = parser pattern that matched this header
1306 * 2 : s = header that matched this pattern
1307 * 3 : csp = Current client state (buffers, headers, etc...)
1309 * Returns : `crumble' or a newly malloc'ed string.
1311 *********************************************************************/
1312 char *server_set_cookie(const struct parsers *v, char *s, struct client_state *csp)
1315 if (csp->config->jar)
1317 fprintf(csp->config->jar, "%s\t%s\n", csp->http->host, (s + v->len + 1));
1319 #endif /* def JAR_FILES */
1321 if (!(csp->permissions & PERMIT_COOKIE_SET))
1323 return(crumble(v, s, csp));
1332 /*********************************************************************
1334 * Function : client_host
1336 * Description : Clean the FORCE_PREFIX out of the 'host' http
1337 * header, if we use force
1341 * 2 : s = header (from sed) to clean
1342 * 3 : csp = Current client state (buffers, headers, etc...)
1344 * Returns : A malloc'ed pointer to the cleaned host header
1346 *********************************************************************/
1347 char *client_host(const struct parsers *v, char *s, struct client_state *csp)
1349 char *cleanhost = strdup(s);
1352 strclean(cleanhost, FORCE_PREFIX);
1356 #endif /* def FORCE_LOAD */
1360 /*********************************************************************
1362 * Function : strclean
1364 * Description : In-Situ-Eliminate all occurances of substring in
1368 * 1 : string = string to clean
1369 * 2 : substring = substring to eliminate
1371 * Returns : Number of eliminations
1373 *********************************************************************/
1374 int strclean(const char *string, const char *substring)
1376 int hits = 0, len = strlen(substring);
1379 while((pos = strstr(string, substring)))
1386 while (*p++ != '\0');
1393 #endif /* def FORCE_LOAD */