1 const char parsers_rcs[] = "$Id: parsers.c,v 1.6 2001/05/26 13:39:32 jongfoster 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.6 2001/05/26 13:39:32 jongfoster
45 * Only crunches Content-Length header if applying RE filtering.
46 * Without this fix, Microsoft Windows Update wouldn't work.
48 * Revision 1.5 2001/05/26 00:28:36 jongfoster
49 * Automatic reloading of config file.
50 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
51 * Most of the global variables have been moved to a new
52 * struct configuration_spec, accessed through csp->config->globalname
53 * Most of the globals remaining are used by the Win32 GUI.
55 * Revision 1.4 2001/05/22 18:46:04 oes
57 * - Enabled filtering banners by size rather than URL
58 * by adding patterns that replace all standard banner
59 * sizes with the "Junkbuster" gif to the re_filterfile
61 * - Enabled filtering WebBugs by providing a pattern
62 * which kills all 1x1 images
64 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
65 * which is selected by the (nonstandard and therefore
66 * capital) letter 'U' in the option string.
67 * It causes the quantifiers to be ungreedy by default.
68 * Appending a ? turns back to greedy (!).
70 * - Added a new interceptor ijb-send-banner, which
71 * sends back the "Junkbuster" gif. Without imagelist or
72 * MSIE detection support, or if tinygif = 1, or the
73 * URL isn't recognized as an imageurl, a lame HTML
74 * explanation is sent instead.
76 * - Added new feature, which permits blocking remote
77 * script redirects and firing back a local redirect
79 * The feature is conditionally compiled, i.e. it
80 * can be disabled with --disable-fast-redirects,
81 * plus it must be activated by a "fast-redirects"
82 * line in the config file, has its own log level
83 * and of course wants to be displayed by show-proxy-args
84 * Note: Boy, all the #ifdefs in 1001 locations and
85 * all the fumbling with configure.in and acconfig.h
86 * were *way* more work than the feature itself :-(
88 * - Because a generic redirect template was needed for
89 * this, tinygif = 3 now uses the same.
91 * - Moved GIFs, and other static HTTP response templates
96 * - Removed some >400 CRs again (Jon, you really worked
99 * Revision 1.3 2001/05/20 01:21:20 jongfoster
100 * Version 2.9.4 checkin.
101 * - Merged popupfile and cookiefile, and added control over PCRS
102 * filtering, in new "permissionsfile".
103 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
104 * file error you now get a message box (in the Win32 GUI) rather
105 * than the program exiting with no explanation.
106 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
108 * - Removed tabs from "config"
109 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
110 * - Bumped up version number.
112 * Revision 1.2 2001/05/17 23:02:36 oes
113 * - Made referrer option accept 'L' as a substitute for 'ยง'
115 * Revision 1.1.1.1 2001/05/15 13:59:01 oes
116 * Initial import of version 2.9.3 source tree
119 *********************************************************************/
125 #include <sys/types.h>
139 #include "showargs.h"
143 #include "jbsockets.h"
144 #include "miscutil.h"
146 const char parsers_h_rcs[] = PARSERS_H_VERSION;
148 /* Fix a problem with Solaris. There should be no effect on other
150 * Solaris's isspace() is a macro which uses it's argument directly
151 * as an array index. Therefore we need to make sure that high-bit
152 * characters generate +ve values, and ideally we also want to make
153 * the argument match the declared parameter type of "int".
155 * Why did they write a character function that can't take a simple
156 * "char" argument? Doh!
158 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
159 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
162 const struct parsers client_patterns[] = {
163 { "referer:", 8, client_referrer },
164 { "user-agent:", 11, client_uagent },
165 { "ua-", 3, client_ua },
166 { "from:", 5, client_from },
167 { "cookie:", 7, client_send_cookie },
168 { "x-forwarded-for:", 16, client_x_forwarded },
169 { "proxy-connection:", 17, crumble },
171 { "Accept-Encoding: gzip", 21, crumble },
172 #endif /* def DENY_GZIP */
173 #if defined(DETECT_MSIE_IMAGES)
174 { "Accept:", 7, client_accept },
175 #endif /* defined(DETECT_MSIE_IMAGES) */
177 { "Host:", 5, client_host },
178 #endif /* def FORCE_LOAD */
179 /* { "if-modified-since:", 18, crumble }, */
183 const struct interceptors intercept_patterns[] = {
184 { "show-proxy-args", 14, show_proxy_args },
185 { "ijb-send-banner", 14, ijb_send_banner },
187 { "ij-untrusted-url", 15, ij_untrusted_url },
188 #endif /* def TRUST_FILES */
192 const struct parsers server_patterns[] = {
193 { "set-cookie:", 11, server_set_cookie },
194 { "connection:", 11, crumble },
195 #if defined(PCRS) || defined(KILLPOPUPS)
196 { "Content-Type:", 13, content_type },
197 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
199 { "Content-Length:", 15, content_length },
200 #endif /* def PCRS */
205 void (* const add_client_headers[])(struct client_state *) = {
207 client_x_forwarded_adder,
213 void (* const add_server_headers[])(struct client_state *) = {
218 /*********************************************************************
220 * Function : flush_socket
222 * Description : Write any pending "buffered" content.
225 * 1 : fd = file descriptor of the socket to read
226 * 2 : csp = Current client state (buffers, headers, etc...)
228 * Returns : On success, the number of bytes written are returned (zero
229 * indicates nothing was written). On error, -1 is returned,
230 * and errno is set appropriately. If count is zero and the
231 * file descriptor refers to a regular file, 0 will be
232 * returned without causing any other effect. For a special
233 * file, the results are not portable.
235 *********************************************************************/
236 int flush_socket(int fd, struct client_state *csp)
238 struct iob *iob = csp->iob;
239 int n = iob->eod - iob->cur;
246 n = write_socket(fd, iob->cur, n);
247 iob->eod = iob->cur = iob->buf;
253 /*********************************************************************
255 * Function : add_to_iob
257 * Description : Add content to the buffered page.
260 * 1 : csp = Current client state (buffers, headers, etc...)
261 * 2 : buf = holds the content to be added to the page
262 * 3 : n = number of bytes to be added
264 * Returns : Number of bytes in the content buffer.
266 *********************************************************************/
267 int add_to_iob(struct client_state *csp, char *buf, int n)
269 struct iob *iob = csp->iob;
273 have = iob->eod - iob->cur;
282 if ((p = (char *)malloc(need + 1)) == NULL)
284 log_error(LOG_LEVEL_ERROR, "malloc() iob failed: %E");
290 /* there is something in the buffer - save it */
291 memcpy(p, iob->cur, have);
293 /* replace the buffer with the new space */
297 /* point to the end of the data */
302 /* the buffer is empty, free it and reinitialize */
307 /* copy the new data into the iob buffer */
310 /* point to the end of the data */
313 /* null terminate == cheap insurance */
316 /* set the pointers to the new values */
325 /*********************************************************************
327 * Function : get_header
329 * Description : This (odd) routine will parse the csp->iob
332 * 1 : csp = Current client state (buffers, headers, etc...)
334 * Returns : Any one of the following:
336 * 1) a pointer to a dynamically allocated string that contains a header line
337 * 2) NULL indicating that the end of the header was reached
338 * 3) "" indicating that the end of the iob was reached before finding
339 * a complete header line.
341 *********************************************************************/
342 char *get_header(struct client_state *csp)
348 if ((iob->cur == NULL)
349 || ((p = strchr(iob->cur, '\n')) == NULL))
351 return(""); /* couldn't find a complete header */
356 ret = strdup(iob->cur);
360 if ((q = strchr(ret, '\r'))) *q = '\0';
362 /* is this a blank linke (i.e. the end of the header) ? */
374 /*********************************************************************
378 * Description : Append a string into a specified string list.
381 * 1 : h = pointer to list 'dummy' header
382 * 2 : s = string to add to the list
386 *********************************************************************/
387 void enlist(struct list *h, const char *s)
389 struct list *n = (struct list *)malloc(sizeof(*n));
412 /*********************************************************************
414 * Function : destroy_list
416 * Description : Destroy a string list (opposite of enlist)
419 * 1 : h = pointer to list 'dummy' header
423 *********************************************************************/
424 void destroy_list(struct list *h)
428 for (p = h->next; p ; p = n)
435 memset(h, '\0', sizeof(*h));
440 /*********************************************************************
442 * Function : list_to_text
444 * Description : "Flaten" a string list into 1 long \r\n delimited string.
447 * 1 : h = pointer to list 'dummy' header
449 * Returns : NULL on malloc error, else new long string.
451 *********************************************************************/
452 static char *list_to_text(struct list *h)
461 for (p = h->next; p ; p = p->next)
465 size += strlen(p->str) + 2;
469 if ((ret = (char *)malloc(size + 1)) == NULL)
478 for (p = h->next; p ; p = p->next)
484 *s++ = '\r'; *s++ = '\n';
493 /*********************************************************************
497 * Description : add, delete or modify lines in the HTTP header streams.
498 * On entry, it receives a linked list of headers space
499 * that was allocated dynamically (both the list nodes
500 * and the header contents).
502 * As a side effect it frees the space used by the original
506 * 1 : pats = list of patterns to match against headers
507 * 2 : more_headers = list of functions to add more
508 * headers (client or server)
509 * 3 : csp = Current client state (buffers, headers, etc...)
511 * Returns : Single pointer to a fully formed header.
513 *********************************************************************/
514 char *sed(const struct parsers pats[], void (* const more_headers[])(struct client_state *), struct client_state *csp)
517 const struct parsers *v;
521 for (v = pats; v->str ; v++)
523 for (p = csp->headers->next; p ; p = p->next)
525 if (v == pats) log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
530 log_error(LOG_LEVEL_ERROR, "NULL header");
532 else if (strncmpic(p->str, v->str, v->len) == 0)
534 hdr = v->parser(v, p->str, csp);
541 /* place any additional headers on the csp->headers list */
542 for (f = more_headers; *f ; f++)
547 /* add the blank line at the end of the header */
548 enlist(csp->headers, "");
550 hdr = list_to_text(csp->headers);
557 /*********************************************************************
559 * Function : free_http_request
561 * Description : Freez a http_request structure
564 * 1 : http = points to a http_request structure to free
568 *********************************************************************/
569 void free_http_request(struct http_request *http)
574 freez(http->hostport);
581 /*********************************************************************
583 * Function : parse_http_request
585 * Description : Parse out the host and port from the URL. Find the
586 * hostname & path, port (if ':'), and/or password (if '@')
589 * 1 : req = URL (or is it URI?) to break down
590 * 2 : http = pointer to the http structure to hold elements
591 * 3 : csp = Current client state (buffers, headers, etc...)
595 *********************************************************************/
596 void parse_http_request(char *req, struct http_request *http, struct client_state *csp)
598 char *buf, *v[10], *url, *p;
601 memset(http, '\0', sizeof(*http));
603 http->cmd = strdup(req);
607 n = ssplit(buf, " \r\n", v, SZ(v), 1, 1);
611 /* this could be a CONNECT request */
612 if (strcmpic(v[0], "connect") == 0)
615 http->gpc = strdup(v[0]);
616 http->hostport = strdup(v[1]);
617 http->ver = strdup(v[2]);
622 /* This next line is a little ugly, but it simplifies the if statement below. */
623 /* Basically if using webDAV, we want the OR condition to use these too. */
627 * These are the headers as defined in RFC2518 to add webDAV support
630 #define OR_WEBDAV || \
631 (0 == strcmpic(v[0], "propfind")) || \
632 (0 == strcmpic(v[0], "proppatch")) || \
633 (0 == strcmpic(v[0], "move")) || \
634 (0 == strcmpic(v[0], "copy")) || \
635 (0 == strcmpic(v[0], "mkcol")) || \
636 (0 == strcmpic(v[0], "lock")) || \
637 (0 == strcmpic(v[0], "unlock"))
639 #else /* No webDAV support is enabled. Provide an empty OR_WEBDAV macro. */
645 /* or it could be a GET or a POST (possibly webDAV too) */
646 if ((strcmpic(v[0], "get") == 0) ||
647 (strcmpic(v[0], "head") == 0) OR_WEBDAV ||
648 (strcmpic(v[0], "post") == 0))
651 http->gpc = strdup(v[0]);
653 http->ver = strdup(v[2]);
655 if (strncmpic(url, "http://", 7) == 0)
659 else if (strncmpic(url, "https://", 8) == 0)
668 if (url && (p = strchr(url, '/')))
670 http->path = strdup(p);
672 http->hostport = strdup(url);
680 if (http->hostport == NULL)
682 free_http_request(http);
686 buf = strdup(http->hostport);
689 /* check if url contains password */
690 n = ssplit(buf, "@", v, SZ(v), 1, 1);
693 char * newbuf = NULL;
694 newbuf = strdup(v[1]);
699 n = ssplit(buf, ":", v, SZ(v), 1, 1);
703 http->host = strdup(v[0]);
709 http->host = strdup(v[0]);
710 http->port = atoi(v[1]);
715 if (http->host == NULL)
717 free_http_request(http);
720 if (http->path == NULL)
722 http->path = strdup("");
728 /* here begins the family of parser functions that reformat header lines */
731 /*********************************************************************
735 * Description : This is called if a header matches a pattern to "crunch"
738 * 1 : v = Pointer to parsers structure, which basically holds
739 * headers (client or server) that we want to "crunch"
740 * 2 : s = header (from sed) to "crunch"
741 * 3 : csp = Current client state (buffers, headers, etc...)
743 * Returns : Always NULL.
745 *********************************************************************/
746 char *crumble(const struct parsers *v, char *s, struct client_state *csp)
748 log_error(LOG_LEVEL_HEADER, "crunch!");
754 #if defined(PCRS) || defined(KILLPOPUPS)
756 /*********************************************************************
758 * Function : content_type
760 * Description : Is this a text/* or javascript MIME Type?
764 * 2 : s = header string we are "considering"
765 * 3 : csp = Current client state (buffers, headers, etc...)
767 * Returns : A duplicate string pointer to this header (ie. pass thru)
769 *********************************************************************/
770 char *content_type(const struct parsers *v, char *s, struct client_state *csp)
772 if (strstr (s, " text/") || strstr (s, "application/x-javascript"))
780 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
784 /*********************************************************************
786 * Function : content_length
788 * Description : Crunch Content-Length header if & only if we are
789 * filtering this page through PCRS.
793 * 2 : s = header string we are "considering"
794 * 3 : csp = Current client state (buffers, headers, etc...)
796 * Returns : A duplicate string pointer to this header (ie. pass thru)
798 *********************************************************************/
799 char *content_length(const struct parsers *v, char *s, struct client_state *csp)
801 if (((csp->permissions & PERMIT_RE_FILTER) != 0) && csp->is_text)
803 log_error(LOG_LEVEL_HEADER, "crunch!");
812 #endif /* def PCRS */
815 /*********************************************************************
817 * Function : client_referrer
819 * Description : Handle the "referer" config setting properly.
824 * 2 : s = header (from sed) to "crunch"
825 * 3 : csp = Current client state (buffers, headers, etc...)
827 * Returns : NULL if crunched, or a malloc'ed string with the original
830 *********************************************************************/
831 char *client_referrer(const struct parsers *v, char *s, struct client_state *csp)
834 /* Since the referrer can include the prefix even
835 * even if the request itself is non-forced, we must
836 * clean it unconditionally
838 strclean(s, FORCE_PREFIX);
839 #endif /* def FORCE_LOAD */
841 csp->referrer = strdup(s);
843 if (csp->config->referrer == NULL)
845 log_error(LOG_LEVEL_HEADER, "crunch!");
849 if (*csp->config->referrer == '.')
854 if (*csp->config->referrer == '@')
856 if (csp->permissions & PERMIT_COOKIE_READ)
862 log_error(LOG_LEVEL_HEADER, "crunch!");
868 * New option ยง or L: Forge a referer as http://[hostname:port of REQUEST]/
869 * to fool stupid checks for in-site links
872 if (*csp->config->referrer == 'ยง' || *csp->config->referrer == 'L')
874 if (csp->permissions & PERMIT_COOKIE_READ)
880 log_error(LOG_LEVEL_HEADER, "crunch+forge!");
881 s = strsav(NULL, "Referer: ");
882 s = strsav(s, "http://");
883 s = strsav(s, csp->http->hostport);
889 log_error(LOG_LEVEL_HEADER, "modified");
891 s = strsav( NULL, "Referer: " );
892 s = strsav( s, csp->config->referrer );
898 /*********************************************************************
900 * Function : client_uagent
902 * Description : Handle the "user-agent" config setting properly.
907 * 2 : s = header (from sed) to "crunch"
908 * 3 : csp = Current client state (buffers, headers, etc...)
910 * Returns : A malloc'ed pointer to the default agent, or
911 * a malloc'ed string pointer to this header (ie. pass thru).
913 *********************************************************************/
914 char *client_uagent(const struct parsers *v, char *s, struct client_state *csp)
916 #ifdef DETECT_MSIE_IMAGES
917 if (strstr (s, "MSIE "))
919 /* This is Microsoft Internet Explorer.
920 * Enable auto-detect.
922 csp->accept_types |= ACCEPT_TYPE_IS_MSIE;
924 #endif /* def DETECT_MSIE_IMAGES */
926 if (csp->config->uagent == NULL)
928 log_error(LOG_LEVEL_HEADER, "default");
929 return(strdup(DEFAULT_USER_AGENT));
932 if (*csp->config->uagent == '.')
937 if (*csp->config->uagent == '@')
939 if (csp->permissions & PERMIT_COOKIE_READ)
945 log_error(LOG_LEVEL_HEADER, "default");
946 return(strdup(DEFAULT_USER_AGENT));
950 log_error(LOG_LEVEL_HEADER, "modified");
952 s = strsav( NULL, "User-Agent: " );
953 s = strsav( s, csp->config->uagent );
959 /*********************************************************************
961 * Function : client_ua
963 * Description : Handle "ua-" headers properly. Called from `sed'.
967 * 2 : s = header (from sed) to "crunch"
968 * 3 : csp = Current client state (buffers, headers, etc...)
970 * Returns : NULL if crunched, or a malloc'ed string to original header
972 *********************************************************************/
973 char *client_ua(const struct parsers *v, char *s, struct client_state *csp)
975 if (csp->config->uagent == NULL)
977 log_error(LOG_LEVEL_HEADER, "crunch!");
981 if (*csp->config->uagent == '.')
986 if (*csp->config->uagent == '@')
988 if (csp->permissions & PERMIT_COOKIE_READ)
994 log_error(LOG_LEVEL_HEADER, "crunch!");
999 log_error(LOG_LEVEL_HEADER, "crunch!");
1005 /*********************************************************************
1007 * Function : client_from
1009 * Description : Handle the "from" config setting properly.
1010 * Called from `sed'.
1014 * 2 : s = header (from sed) to "crunch"
1015 * 3 : csp = Current client state (buffers, headers, etc...)
1017 * Returns : NULL if crunched, or a malloc'ed string to
1018 * modified/original header.
1020 *********************************************************************/
1021 char *client_from(const struct parsers *v, char *s, struct client_state *csp)
1023 /* if not set, zap it */
1024 if (csp->config->from == NULL)
1026 log_error(LOG_LEVEL_HEADER, "crunch!");
1030 if (*csp->config->from == '.')
1035 log_error(LOG_LEVEL_HEADER, " modified");
1037 s = strsav( NULL, "From: " );
1038 s = strsav( s, csp->config->from );
1044 /*********************************************************************
1046 * Function : client_send_cookie
1048 * Description : Handle the "cookie" header properly. Called from `sed'.
1049 * If cookie is accepted, add it to the cookie_list,
1050 * else we crunch it. Mmmmmmmmmmm ... cookie ......
1053 * 1 : v = pattern of cookie `sed' found matching
1054 * 2 : s = header (from sed) to "crunch"
1055 * 3 : csp = Current client state (buffers, headers, etc...)
1057 * Returns : Always NULL.
1059 *********************************************************************/
1060 char *client_send_cookie(const struct parsers *v, char *s, struct client_state *csp)
1062 if (csp->permissions & PERMIT_COOKIE_READ)
1064 enlist(csp->cookie_list, s + v->len + 1);
1068 log_error(LOG_LEVEL_HEADER, " crunch!");
1072 * Always return NULL here. The cookie header
1073 * will be sent at the end of the header.
1080 /*********************************************************************
1082 * Function : client_x_forwarded
1084 * Description : Handle the "x-forwarded-for" config setting properly,
1085 * also used in the add_client_headers list. Called from `sed'.
1089 * 2 : s = header (from sed) to "crunch"
1090 * 3 : csp = Current client state (buffers, headers, etc...)
1092 * Returns : Always NULL.
1094 *********************************************************************/
1095 char *client_x_forwarded(const struct parsers *v, char *s, struct client_state *csp)
1097 if (csp->config->add_forwarded)
1099 csp->x_forwarded = strdup(s);
1103 * Always return NULL, since this information
1104 * will be sent at the end of the header.
1111 #if defined(DETECT_MSIE_IMAGES)
1112 /*********************************************************************
1114 * Function : client_accept
1116 * Description : Detect whether the client wants HTML or an image.
1117 * Clients do not always make this information available
1118 * in a sane way. Always passes the header through
1119 * the proxy unchanged.
1123 * 2 : s = Header string. Null terminated.
1124 * 3 : csp = Current client state (buffers, headers, etc...)
1126 * Returns : Duplicate of argument s.
1128 *********************************************************************/
1129 char *client_accept(const struct parsers *v, char *s, struct client_state *csp)
1131 #ifdef DETECT_MSIE_IMAGES
1132 if (strstr (s, "image/gif"))
1134 /* Client will accept HTML. If this seems counterintuitive,
1137 csp->accept_types |= ACCEPT_TYPE_MSIE_HTML;
1141 csp->accept_types |= ACCEPT_TYPE_MSIE_IMAGE;
1143 #endif /* def DETECT_MSIE_IMAGES */
1148 #endif /* defined(DETECT_MSIE_IMAGES) */
1152 /* the following functions add headers directly to the header list */
1155 /*********************************************************************
1157 * Function : client_cookie_adder
1159 * Description : Used in the add_client_headers list. Called from `sed'.
1162 * 1 : csp = Current client state (buffers, headers, etc...)
1166 *********************************************************************/
1167 void client_cookie_adder(struct client_state *csp)
1173 for (l = csp->cookie_list->next; l ; l = l->next)
1177 tmp = strsav(tmp, "; ");
1179 tmp = strsav(tmp, l->str);
1182 for (l = csp->config->wafer_list->next; l ; l = l->next)
1186 tmp = strsav(tmp, "; ");
1189 if ((e = cookie_encode(l->str)))
1191 tmp = strsav(tmp, e);
1200 ret = strdup("Cookie: ");
1201 ret = strsav(ret, tmp);
1202 log_error(LOG_LEVEL_HEADER, "addh: %s", ret);
1203 enlist(csp->headers, ret);
1211 /*********************************************************************
1213 * Function : client_xtra_adder
1215 * Description : Used in the add_client_headers list. Called from `sed'.
1218 * 1 : csp = Current client state (buffers, headers, etc...)
1222 *********************************************************************/
1223 void client_xtra_adder(struct client_state *csp)
1227 for (l = csp->config->xtra_list->next; l ; l = l->next)
1229 log_error(LOG_LEVEL_HEADER, "addh: %s", l->str);
1230 enlist(csp->headers, l->str);
1236 /*********************************************************************
1238 * Function : client_x_forwarded_adder
1240 * Description : Used in the add_client_headers list. Called from `sed'.
1243 * 1 : csp = Current client state (buffers, headers, etc...)
1247 *********************************************************************/
1248 void client_x_forwarded_adder(struct client_state *csp)
1252 if (csp->config->add_forwarded == 0)
1257 if (csp->x_forwarded)
1259 p = strsav(p, csp->x_forwarded);
1260 p = strsav(p, ", ");
1261 p = strsav(p, csp->ip_addr_str);
1265 p = strsav(p, "X-Forwarded-For: ");
1266 p = strsav(p, csp->ip_addr_str);
1269 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1270 enlist(csp->headers, p);
1275 /*********************************************************************
1277 * Function : server_set_cookie
1279 * Description : Handle the server "cookie" header properly.
1280 * Log cookie to the jar file. Then "crunch" it,
1281 * or accept it. Called from `sed'.
1284 * 1 : v = parser pattern that matched this header
1285 * 2 : s = header that matched this pattern
1286 * 3 : csp = Current client state (buffers, headers, etc...)
1288 * Returns : `crumble' or a newly malloc'ed string.
1290 *********************************************************************/
1291 char *server_set_cookie(const struct parsers *v, char *s, struct client_state *csp)
1294 if (csp->config->jar)
1296 fprintf(csp->config->jar, "%s\t%s\n", csp->http->host, (s + v->len + 1));
1298 #endif /* def JAR_FILES */
1300 if (!(csp->permissions & PERMIT_COOKIE_SET))
1302 return(crumble(v, s, csp));
1311 /*********************************************************************
1313 * Function : client_host
1315 * Description : Clean the FORCE_PREFIX out of the 'host' http
1316 * header, if we use force
1320 * 2 : s = header (from sed) to clean
1321 * 3 : csp = Current client state (buffers, headers, etc...)
1323 * Returns : A malloc'ed pointer to the cleaned host header
1325 *********************************************************************/
1326 char *client_host(const struct parsers *v, char *s, struct client_state *csp)
1328 char *cleanhost = strdup(s);
1331 strclean(cleanhost, FORCE_PREFIX);
1335 #endif /* def FORCE_LOAD */
1339 /*********************************************************************
1341 * Function : strclean
1343 * Description : In-Situ-Eliminate all occurances of substring in
1347 * 1 : string = string to clean
1348 * 2 : substring = substring to eliminate
1350 * Returns : Number of eliminations
1352 *********************************************************************/
1353 int strclean(const char *string, const char *substring)
1355 int hits = 0, len = strlen(substring);
1358 while((pos = strstr(string, substring)))
1365 while (*p++ != '\0');
1372 #endif /* def FORCE_LOAD */