1 const char parsers_rcs[] = "$Id: parsers.c,v 1.4 2001/05/22 18:46: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', `match', `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.4 2001/05/22 18:46:04 oes
46 * - Enabled filtering banners by size rather than URL
47 * by adding patterns that replace all standard banner
48 * sizes with the "Junkbuster" gif to the re_filterfile
50 * - Enabled filtering WebBugs by providing a pattern
51 * which kills all 1x1 images
53 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
54 * which is selected by the (nonstandard and therefore
55 * capital) letter 'U' in the option string.
56 * It causes the quantifiers to be ungreedy by default.
57 * Appending a ? turns back to greedy (!).
59 * - Added a new interceptor ijb-send-banner, which
60 * sends back the "Junkbuster" gif. Without imagelist or
61 * MSIE detection support, or if tinygif = 1, or the
62 * URL isn't recognized as an imageurl, a lame HTML
63 * explanation is sent instead.
65 * - Added new feature, which permits blocking remote
66 * script redirects and firing back a local redirect
68 * The feature is conditionally compiled, i.e. it
69 * can be disabled with --disable-fast-redirects,
70 * plus it must be activated by a "fast-redirects"
71 * line in the config file, has its own log level
72 * and of course wants to be displayed by show-proxy-args
73 * Note: Boy, all the #ifdefs in 1001 locations and
74 * all the fumbling with configure.in and acconfig.h
75 * were *way* more work than the feature itself :-(
77 * - Because a generic redirect template was needed for
78 * this, tinygif = 3 now uses the same.
80 * - Moved GIFs, and other static HTTP response templates
85 * - Removed some >400 CRs again (Jon, you really worked
88 * Revision 1.3 2001/05/20 01:21:20 jongfoster
89 * Version 2.9.4 checkin.
90 * - Merged popupfile and cookiefile, and added control over PCRS
91 * filtering, in new "permissionsfile".
92 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
93 * file error you now get a message box (in the Win32 GUI) rather
94 * than the program exiting with no explanation.
95 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
97 * - Removed tabs from "config"
98 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
99 * - Bumped up version number.
101 * Revision 1.2 2001/05/17 23:02:36 oes
102 * - Made referrer option accept 'L' as a substitute for 'ยง'
104 * Revision 1.1.1.1 2001/05/15 13:59:01 oes
105 * Initial import of version 2.9.3 source tree
108 *********************************************************************/
114 #include <sys/types.h>
128 #include "showargs.h"
132 #include "jbsockets.h"
133 #include "miscutil.h"
135 const char parsers_h_rcs[] = PARSERS_H_VERSION;
137 /* Fix a problem with Solaris. There should be no effect on other
139 * Solaris's isspace() is a macro which uses it's argument directly
140 * as an array index. Therefore we need to make sure that high-bit
141 * characters generate +ve values, and ideally we also want to make
142 * the argument match the declared parameter type of "int".
144 * Why did they write a character function that can't take a simple
145 * "char" argument? Doh!
147 #define ijb_isupper(__X) isupper((int)(unsigned char)(__X))
148 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
151 const struct parsers client_patterns[] = {
152 { "referer:", 8, client_referrer },
153 { "user-agent:", 11, client_uagent },
154 { "ua-", 3, client_ua },
155 { "from:", 5, client_from },
156 { "cookie:", 7, client_send_cookie },
157 { "x-forwarded-for:", 16, client_x_forwarded },
158 { "proxy-connection:", 17, crumble },
160 { "Accept-Encoding: gzip", 21, crumble },
161 #endif /* def DENY_GZIP */
162 #if defined(DETECT_MSIE_IMAGES)
163 { "Accept:", 7, client_accept },
164 #endif /* defined(DETECT_MSIE_IMAGES) */
166 { "Host:", 5, client_host },
167 #endif /* def FORCE_LOAD */
168 /* { "if-modified-since:", 18, crumble }, */
172 const struct interceptors intercept_patterns[] = {
173 { "show-proxy-args", 14, show_proxy_args },
174 { "ijb-send-banner", 14, ijb_send_banner },
176 { "ij-untrusted-url", 15, ij_untrusted_url },
177 #endif /* def TRUST_FILES */
181 const struct parsers server_patterns[] = {
182 { "set-cookie:", 11, server_set_cookie },
183 { "connection:", 11, crumble },
184 #if defined(PCRS) || defined(KILLPOPUPS)
185 { "Content-Type:", 13, content_type },
186 { "Content-Length:", 15, crumble },
187 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
192 void (* const add_client_headers[])(struct client_state *) = {
194 client_x_forwarded_adder,
200 void (* const add_server_headers[])(struct client_state *) = {
205 /*********************************************************************
209 * Description : Do a `strncmpic' on every pattern in pats.
212 * 1 : buf = a string to match to a list of patterns
213 * 2 : pats = list of strings to compare against buf.
215 * Returns : Return the matching "struct parsers *",
216 * or NULL if no pattern matches.
218 *********************************************************************/
219 static const struct parsers *match(char *buf, const struct parsers *pats)
221 const struct parsers *v;
226 log_error(LOG_LEVEL_ERROR, "NULL parameter to match()");
230 for (v = pats; v->str ; v++)
232 if (strncmpic(buf, v->str, v->len) == 0)
242 /*********************************************************************
244 * Function : flush_socket
246 * Description : Write any pending "buffered" content.
249 * 1 : fd = file descriptor of the socket to read
250 * 2 : csp = Current client state (buffers, headers, etc...)
252 * Returns : On success, the number of bytes written are returned (zero
253 * indicates nothing was written). On error, -1 is returned,
254 * and errno is set appropriately. If count is zero and the
255 * file descriptor refers to a regular file, 0 will be
256 * returned without causing any other effect. For a special
257 * file, the results are not portable.
259 *********************************************************************/
260 int flush_socket(int fd, struct client_state *csp)
262 struct iob *iob = csp->iob;
263 int n = iob->eod - iob->cur;
270 n = write_socket(fd, iob->cur, n);
271 iob->eod = iob->cur = iob->buf;
277 /*********************************************************************
279 * Function : add_to_iob
281 * Description : Add content to the buffered page.
284 * 1 : csp = Current client state (buffers, headers, etc...)
285 * 2 : buf = holds the content to be added to the page
286 * 3 : n = number of bytes to be added
288 * Returns : Number of bytes in the content buffer.
290 *********************************************************************/
291 int add_to_iob(struct client_state *csp, char *buf, int n)
293 struct iob *iob = csp->iob;
297 have = iob->eod - iob->cur;
306 if ((p = (char *)malloc(need + 1)) == NULL)
308 log_error(LOG_LEVEL_ERROR, "malloc() iob failed: %E");
314 /* there is something in the buffer - save it */
315 memcpy(p, iob->cur, have);
317 /* replace the buffer with the new space */
321 /* point to the end of the data */
326 /* the buffer is empty, free it and reinitialize */
331 /* copy the new data into the iob buffer */
334 /* point to the end of the data */
337 /* null terminate == cheap insurance */
340 /* set the pointers to the new values */
349 /*********************************************************************
351 * Function : get_header
353 * Description : This (odd) routine will parse the csp->iob
356 * 1 : csp = Current client state (buffers, headers, etc...)
358 * Returns : Any one of the following:
360 * 1) a pointer to a dynamically allocated string that contains a header line
361 * 2) NULL indicating that the end of the header was reached
362 * 3) "" indicating that the end of the iob was reached before finding
363 * a complete header line.
365 *********************************************************************/
366 char *get_header(struct client_state *csp)
372 if ((iob->cur == NULL)
373 || ((p = strchr(iob->cur, '\n')) == NULL))
375 return(""); /* couldn't find a complete header */
380 ret = strdup(iob->cur);
384 if ((q = strchr(ret, '\r'))) *q = '\0';
386 /* is this a blank linke (i.e. the end of the header) ? */
398 /*********************************************************************
402 * Description : Append a string into a specified string list.
405 * 1 : h = pointer to list 'dummy' header
406 * 2 : s = string to add to the list
410 *********************************************************************/
411 void enlist(struct list *h, const char *s)
413 struct list *n = (struct list *)malloc(sizeof(*n));
436 /*********************************************************************
438 * Function : destroy_list
440 * Description : Destroy a string list (opposite of enlist)
443 * 1 : h = pointer to list 'dummy' header
447 *********************************************************************/
448 void destroy_list(struct list *h)
452 for (p = h->next; p ; p = n)
459 memset(h, '\0', sizeof(*h));
464 /*********************************************************************
466 * Function : list_to_text
468 * Description : "Flaten" a string list into 1 long \r\n delimited string.
471 * 1 : h = pointer to list 'dummy' header
473 * Returns : NULL on malloc error, else new long string.
475 *********************************************************************/
476 static char *list_to_text(struct list *h)
485 for (p = h->next; p ; p = p->next)
489 size += strlen(p->str) + 2;
493 if ((ret = (char *)malloc(size + 1)) == NULL)
502 for (p = h->next; p ; p = p->next)
508 *s++ = '\r'; *s++ = '\n';
517 /*********************************************************************
521 * Description : add, delete or modify lines in the HTTP header streams.
522 * On entry, it receives a linked list of headers space
523 * that was allocated dynamically (both the list nodes
524 * and the header contents).
526 * As a side effect it frees the space used by the original
530 * 1 : pats = list of patterns to match against headers
531 * 2 : more_headers = list of functions to add more
532 * headers (client or server)
533 * 3 : csp = Current client state (buffers, headers, etc...)
535 * Returns : Single pointer to a fully formed header.
537 *********************************************************************/
538 char *sed(const struct parsers pats[], void (* const more_headers[])(struct client_state *), struct client_state *csp)
541 const struct parsers *v;
545 for (p = csp->headers->next; p ; p = p->next)
547 log_error(LOG_LEVEL_HEADER, "scan: %s", p->str);
549 if ((v = match(p->str, pats)))
551 hdr = v->parser(v, p->str, csp);
558 /* place any additional headers on the csp->headers list */
559 for (f = more_headers; *f ; f++)
564 /* add the blank line at the end of the header */
565 enlist(csp->headers, "");
567 hdr = list_to_text(csp->headers);
574 /*********************************************************************
576 * Function : free_http_request
578 * Description : Freez a http_request structure
581 * 1 : http = points to a http_request structure to free
585 *********************************************************************/
586 void free_http_request(struct http_request *http)
591 freez(http->hostport);
598 /*********************************************************************
600 * Function : parse_http_request
602 * Description : Parse out the host and port from the URL. Find the
603 * hostname & path, port (if ':'), and/or password (if '@')
606 * 1 : req = URL (or is it URI?) to break down
607 * 2 : http = pointer to the http structure to hold elements
608 * 3 : csp = Current client state (buffers, headers, etc...)
612 *********************************************************************/
613 void parse_http_request(char *req, struct http_request *http, struct client_state *csp)
615 char *buf, *v[10], *url, *p;
618 memset(http, '\0', sizeof(*http));
620 http->cmd = strdup(req);
624 n = ssplit(buf, " \r\n", v, SZ(v), 1, 1);
628 /* this could be a CONNECT request */
629 if (strcmpic(v[0], "connect") == 0)
632 http->gpc = strdup(v[0]);
633 http->hostport = strdup(v[1]);
634 http->ver = strdup(v[2]);
639 /* This next line is a little ugly, but it simplifies the if statement below. */
640 /* Basically if using webDAV, we want the OR condition to use these too. */
644 * These are the headers as defined in RFC2518 to add webDAV support
647 #define OR_WEBDAV || \
648 (0 == strcmpic(v[0], "propfind")) || \
649 (0 == strcmpic(v[0], "proppatch")) || \
650 (0 == strcmpic(v[0], "move")) || \
651 (0 == strcmpic(v[0], "copy")) || \
652 (0 == strcmpic(v[0], "mkcol")) || \
653 (0 == strcmpic(v[0], "lock")) || \
654 (0 == strcmpic(v[0], "unlock"))
656 #else /* No webDAV support is enabled. Provide an empty OR_WEBDAV macro. */
662 /* or it could be a GET or a POST (possibly webDAV too) */
663 if ((strcmpic(v[0], "get") == 0) ||
664 (strcmpic(v[0], "head") == 0) OR_WEBDAV ||
665 (strcmpic(v[0], "post") == 0))
668 http->gpc = strdup(v[0]);
670 http->ver = strdup(v[2]);
672 if (strncmpic(url, "http://", 7) == 0)
676 else if (strncmpic(url, "https://", 8) == 0)
685 if (url && (p = strchr(url, '/')))
687 http->path = strdup(p);
689 http->hostport = strdup(url);
697 if (http->hostport == NULL)
699 free_http_request(http);
703 buf = strdup(http->hostport);
706 /* check if url contains password */
707 n = ssplit(buf, "@", v, SZ(v), 1, 1);
710 char * newbuf = NULL;
711 newbuf = strdup(v[1]);
716 n = ssplit(buf, ":", v, SZ(v), 1, 1);
720 http->host = strdup(v[0]);
726 http->host = strdup(v[0]);
727 http->port = atoi(v[1]);
732 if (http->host == NULL)
734 free_http_request(http);
737 if (http->path == NULL)
739 http->path = strdup("");
745 /* here begins the family of parser functions that reformat header lines */
748 /*********************************************************************
752 * Description : This is called if a header matches a pattern to "crunch"
755 * 1 : v = Pointer to parsers structure, which basically holds
756 * headers (client or server) that we want to "crunch"
757 * 2 : s = header (from sed) to "crunch"
758 * 3 : csp = Current client state (buffers, headers, etc...)
760 * Returns : Always NULL.
762 *********************************************************************/
763 char *crumble(const struct parsers *v, char *s, struct client_state *csp)
765 log_error(LOG_LEVEL_HEADER, "crunch!");
771 #if defined(PCRS) || defined(KILLPOPUPS)
773 /*********************************************************************
775 * Function : content_type
777 * Description : Is this a text/* or javascript MIME Type?
781 * 2 : s = header string we are "considering"
782 * 3 : csp = Current client state (buffers, headers, etc...)
784 * Returns : A duplicate string pointer to this header (ie. pass thru)
786 *********************************************************************/
787 char *content_type(const struct parsers *v, char *s, struct client_state *csp)
789 if (strstr (s, " text/") || strstr (s, "application/x-javascript"))
798 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
801 /*********************************************************************
803 * Function : client_referrer
805 * Description : Handle the "referer" config setting properly.
810 * 2 : s = header (from sed) to "crunch"
811 * 3 : csp = Current client state (buffers, headers, etc...)
813 * Returns : NULL if crunched, or a malloc'ed string with the original
816 *********************************************************************/
817 char *client_referrer(const struct parsers *v, char *s, struct client_state *csp)
820 /* Since the referrer can include the prefix even
821 * even if the request itself is non-forced, we must
822 * clean it unconditionally
824 strclean(s, FORCE_PREFIX);
825 #endif /* def FORCE_LOAD */
827 csp->referrer = strdup(s);
829 if (csp->config->referrer == NULL)
831 log_error(LOG_LEVEL_HEADER, "crunch!");
835 if (*csp->config->referrer == '.')
840 if (*csp->config->referrer == '@')
842 if (csp->permissions & PERMIT_COOKIE_READ)
848 log_error(LOG_LEVEL_HEADER, "crunch!");
854 * New option ยง or L: Forge a referer as http://[hostname:port of REQUEST]/
855 * to fool stupid checks for in-site links
858 if (*csp->config->referrer == 'ยง' || *csp->config->referrer == 'L')
860 if (csp->permissions & PERMIT_COOKIE_READ)
866 log_error(LOG_LEVEL_HEADER, "crunch+forge!");
867 s = strsav(NULL, "Referer: ");
868 s = strsav(s, "http://");
869 s = strsav(s, csp->http->hostport);
875 log_error(LOG_LEVEL_HEADER, "modified");
877 s = strsav( NULL, "Referer: " );
878 s = strsav( s, csp->config->referrer );
884 /*********************************************************************
886 * Function : client_uagent
888 * Description : Handle the "user-agent" config setting properly.
893 * 2 : s = header (from sed) to "crunch"
894 * 3 : csp = Current client state (buffers, headers, etc...)
896 * Returns : A malloc'ed pointer to the default agent, or
897 * a malloc'ed string pointer to this header (ie. pass thru).
899 *********************************************************************/
900 char *client_uagent(const struct parsers *v, char *s, struct client_state *csp)
902 #ifdef DETECT_MSIE_IMAGES
903 if (strstr (s, "MSIE "))
905 /* This is Microsoft Internet Explorer.
906 * Enable auto-detect.
908 csp->accept_types |= ACCEPT_TYPE_IS_MSIE;
910 #endif /* def DETECT_MSIE_IMAGES */
912 if (csp->config->uagent == NULL)
914 log_error(LOG_LEVEL_HEADER, "default");
915 return(strdup(DEFAULT_USER_AGENT));
918 if (*csp->config->uagent == '.')
923 if (*csp->config->uagent == '@')
925 if (csp->permissions & PERMIT_COOKIE_READ)
931 log_error(LOG_LEVEL_HEADER, "default");
932 return(strdup(DEFAULT_USER_AGENT));
936 log_error(LOG_LEVEL_HEADER, "modified");
938 s = strsav( NULL, "User-Agent: " );
939 s = strsav( s, csp->config->uagent );
945 /*********************************************************************
947 * Function : client_ua
949 * Description : Handle "ua-" headers properly. Called from `sed'.
953 * 2 : s = header (from sed) to "crunch"
954 * 3 : csp = Current client state (buffers, headers, etc...)
956 * Returns : NULL if crunched, or a malloc'ed string to original header
958 *********************************************************************/
959 char *client_ua(const struct parsers *v, char *s, struct client_state *csp)
961 if (csp->config->uagent == NULL)
963 log_error(LOG_LEVEL_HEADER, "crunch!");
967 if (*csp->config->uagent == '.')
972 if (*csp->config->uagent == '@')
974 if (csp->permissions & PERMIT_COOKIE_READ)
980 log_error(LOG_LEVEL_HEADER, "crunch!");
985 log_error(LOG_LEVEL_HEADER, "crunch!");
991 /*********************************************************************
993 * Function : client_from
995 * Description : Handle the "from" config setting properly.
1000 * 2 : s = header (from sed) to "crunch"
1001 * 3 : csp = Current client state (buffers, headers, etc...)
1003 * Returns : NULL if crunched, or a malloc'ed string to
1004 * modified/original header.
1006 *********************************************************************/
1007 char *client_from(const struct parsers *v, char *s, struct client_state *csp)
1009 /* if not set, zap it */
1010 if (csp->config->from == NULL)
1012 log_error(LOG_LEVEL_HEADER, "crunch!");
1016 if (*csp->config->from == '.')
1021 log_error(LOG_LEVEL_HEADER, " modified");
1023 s = strsav( NULL, "From: " );
1024 s = strsav( s, csp->config->from );
1030 /*********************************************************************
1032 * Function : client_send_cookie
1034 * Description : Handle the "cookie" header properly. Called from `sed'.
1035 * If cookie is accepted, add it to the cookie_list,
1036 * else we crunch it. Mmmmmmmmmmm ... cookie ......
1039 * 1 : v = pattern of cookie `sed' found matching
1040 * 2 : s = header (from sed) to "crunch"
1041 * 3 : csp = Current client state (buffers, headers, etc...)
1043 * Returns : Always NULL.
1045 *********************************************************************/
1046 char *client_send_cookie(const struct parsers *v, char *s, struct client_state *csp)
1048 if (csp->permissions & PERMIT_COOKIE_READ)
1050 enlist(csp->cookie_list, s + v->len + 1);
1054 log_error(LOG_LEVEL_HEADER, " crunch!");
1058 * Always return NULL here. The cookie header
1059 * will be sent at the end of the header.
1066 /*********************************************************************
1068 * Function : client_x_forwarded
1070 * Description : Handle the "x-forwarded-for" config setting properly,
1071 * also used in the add_client_headers list. Called from `sed'.
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_x_forwarded(const struct parsers *v, char *s, struct client_state *csp)
1083 if (csp->config->add_forwarded)
1085 csp->x_forwarded = strdup(s);
1089 * Always return NULL, since this information
1090 * will be sent at the end of the header.
1097 #if defined(DETECT_MSIE_IMAGES)
1098 /*********************************************************************
1100 * Function : client_accept
1102 * Description : Detect whether the client wants HTML or an image.
1103 * Clients do not always make this information available
1104 * in a sane way. Always passes the header through
1105 * the proxy unchanged.
1109 * 2 : s = Header string. Null terminated.
1110 * 3 : csp = Current client state (buffers, headers, etc...)
1112 * Returns : Duplicate of argument s.
1114 *********************************************************************/
1115 char *client_accept(const struct parsers *v, char *s, struct client_state *csp)
1117 #ifdef DETECT_MSIE_IMAGES
1118 if (strstr (s, "image/gif"))
1120 /* Client will accept HTML. If this seems counterintuitive,
1123 csp->accept_types |= ACCEPT_TYPE_MSIE_HTML;
1127 csp->accept_types |= ACCEPT_TYPE_MSIE_IMAGE;
1129 #endif /* def DETECT_MSIE_IMAGES */
1134 #endif /* defined(DETECT_MSIE_IMAGES) */
1138 /* the following functions add headers directly to the header list */
1141 /*********************************************************************
1143 * Function : client_cookie_adder
1145 * Description : Used in the add_client_headers list. Called from `sed'.
1148 * 1 : csp = Current client state (buffers, headers, etc...)
1152 *********************************************************************/
1153 void client_cookie_adder(struct client_state *csp)
1159 for (l = csp->cookie_list->next; l ; l = l->next)
1163 tmp = strsav(tmp, "; ");
1165 tmp = strsav(tmp, l->str);
1168 for (l = csp->config->wafer_list->next; l ; l = l->next)
1172 tmp = strsav(tmp, "; ");
1175 if ((e = cookie_encode(l->str)))
1177 tmp = strsav(tmp, e);
1186 ret = strdup("Cookie: ");
1187 ret = strsav(ret, tmp);
1188 log_error(LOG_LEVEL_HEADER, "addh: %s", ret);
1189 enlist(csp->headers, ret);
1197 /*********************************************************************
1199 * Function : client_xtra_adder
1201 * Description : Used in the add_client_headers list. Called from `sed'.
1204 * 1 : csp = Current client state (buffers, headers, etc...)
1208 *********************************************************************/
1209 void client_xtra_adder(struct client_state *csp)
1213 for (l = csp->config->xtra_list->next; l ; l = l->next)
1215 log_error(LOG_LEVEL_HEADER, "addh: %s", l->str);
1216 enlist(csp->headers, l->str);
1222 /*********************************************************************
1224 * Function : client_x_forwarded_adder
1226 * Description : Used in the add_client_headers list. Called from `sed'.
1229 * 1 : csp = Current client state (buffers, headers, etc...)
1233 *********************************************************************/
1234 void client_x_forwarded_adder(struct client_state *csp)
1238 if (csp->config->add_forwarded == 0)
\r
1243 if (csp->x_forwarded)
1245 p = strsav(p, csp->x_forwarded);
1246 p = strsav(p, ", ");
1247 p = strsav(p, csp->ip_addr_str);
1251 p = strsav(p, "X-Forwarded-For: ");
1252 p = strsav(p, csp->ip_addr_str);
1255 log_error(LOG_LEVEL_HEADER, "addh: %s", p);
1256 enlist(csp->headers, p);
1261 /*********************************************************************
1263 * Function : server_set_cookie
1265 * Description : Handle the server "cookie" header properly.
1266 * Log cookie to the jar file. Then "crunch" it,
1267 * or accept it. Called from `sed'.
1270 * 1 : v = parser pattern that matched this header
1271 * 2 : s = header that matched this pattern
1272 * 3 : csp = Current client state (buffers, headers, etc...)
1274 * Returns : `crumble' or a newly malloc'ed string.
1276 *********************************************************************/
1277 char *server_set_cookie(const struct parsers *v, char *s, struct client_state *csp)
1280 if (csp->config->jar)
1282 fprintf(csp->config->jar, "%s\t%s\n", csp->http->host, (s + v->len + 1));
1284 #endif /* def JAR_FILES */
1286 if (!(csp->permissions & PERMIT_COOKIE_SET))
1288 return(crumble(v, s, csp));
1297 /*********************************************************************
1299 * Function : client_host
1301 * Description : Clean the FORCE_PREFIX out of the 'host' http
1302 * header, if we use force
1306 * 2 : s = header (from sed) to clean
1307 * 3 : csp = Current client state (buffers, headers, etc...)
1309 * Returns : A malloc'ed pointer to the cleaned host header
1311 *********************************************************************/
1312 char *client_host(const struct parsers *v, char *s, struct client_state *csp)
1314 char *cleanhost = strdup(s);
1317 strclean(cleanhost, FORCE_PREFIX);
1321 #endif /* def FORCE_LOAD */
1325 /*********************************************************************
1327 * Function : strclean
1329 * Description : In-Situ-Eliminate all occurances of substring in
1333 * 1 : string = string to clean
1334 * 2 : substring = substring to eliminate
1336 * Returns : Number of eliminations
1338 *********************************************************************/
1339 int strclean(const char *string, const char *substring)
1341 int hits = 0, len = strlen(substring);
1344 while((pos = strstr(string, substring)))
1351 while (*p++ != '\0');
1358 #endif /* def FORCE_LOAD */