1 #ifndef PROJECT_H_INCLUDED
2 #define PROJECT_H_INCLUDED
3 #define PROJECT_H_VERSION "$Id: project.h,v 1.52 2002/03/07 03:46:17 oes Exp $"
4 /*********************************************************************
6 * File : $Source: /cvsroot/ijbswa/current/project.h,v $
8 * Purpose : Defines data structures which are widely used in the
9 * project. Does not define any variables or functions
10 * (though it does declare some macros).
12 * Copyright : Written by and Copyright (C) 2001 the SourceForge
13 * IJBSWA team. http://ijbswa.sourceforge.net
15 * Based on the Internet Junkbuster originally written
16 * by and Copyright (C) 1997 Anonymous Coders and
17 * Junkbusters Corporation. http://www.junkbusters.com
19 * This program is free software; you can redistribute it
20 * and/or modify it under the terms of the GNU General
21 * Public License as published by the Free Software
22 * Foundation; either version 2 of the License, or (at
23 * your option) any later version.
25 * This program is distributed in the hope that it will
26 * be useful, but WITHOUT ANY WARRANTY; without even the
27 * implied warranty of MERCHANTABILITY or FITNESS FOR A
28 * PARTICULAR PURPOSE. See the GNU General Public
29 * License for more details.
31 * The GNU General Public License should be included with
32 * this file. If not, you can view it at
33 * http://www.gnu.org/copyleft/gpl.html
34 * or write to the Free Software Foundation, Inc., 59
35 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 * Revision 1.52 2002/03/07 03:46:17 oes
40 * Fixed compiler warnings
42 * Revision 1.51 2002/03/05 04:52:42 oes
43 * Deleted non-errlog debugging code
45 * Revision 1.50 2002/03/04 19:32:07 oes
46 * Changed default port to 8118
48 * Revision 1.49 2002/03/04 18:28:55 oes
49 * Deleted PID_FILE_NAME
51 * Revision 1.48 2002/03/03 14:50:40 oes
52 * Fixed CLF logging: Added ocmd member for client's request to struct http_request
54 * Revision 1.47 2002/02/20 23:15:13 jongfoster
55 * Parsing functions now handle out-of-memory gracefully by returning
58 * Revision 1.46 2002/01/17 21:06:09 jongfoster
59 * Now #defining the URLs of the config interface
61 * Minor changes to struct http_request and struct url_spec due to
62 * standardizing that struct http_request is used to represent a URL, and
63 * struct url_spec is used to represent a URL pattern. (Before, URLs were
64 * represented as seperate variables and a partially-filled-in url_spec).
66 * Revision 1.45 2002/01/09 14:33:27 oes
67 * Added HOSTENT_BUFFER_SIZE
69 * Revision 1.44 2001/12/30 14:07:32 steudten
70 * - Add signal handling (unix)
71 * - Add SIGHUP handler (unix)
72 * - Add creation of pidfile (unix)
73 * - Add action 'top' in rc file (RH)
74 * - Add entry 'SIGNALS' to manpage
75 * - Add exit message to logfile (unix)
77 * Revision 1.43 2001/11/22 21:57:51 jongfoster
78 * Making action_spec->flags into an unsigned long rather than just an
80 * Adding ACTION_NO_COOKIE_KEEP
82 * Revision 1.42 2001/11/05 21:42:41 steudten
83 * Include DBG() macro.
85 * Revision 1.41 2001/10/28 19:12:06 jongfoster
86 * Adding ijb_toupper()
88 * Revision 1.40 2001/10/26 17:40:47 oes
89 * Moved ijb_isspace and ijb_tolower to project.h
90 * Removed http->user_agent, csp->referrer and csp->accept_types
92 * Revision 1.39 2001/10/25 03:45:02 david__schmidt
93 * Adding a (void*) cast to freez() because Visual Age C++ won't expand the
94 * macro when called with a cast; so moving the cast to the macro def'n
95 * seems to both eliminate compiler warnings (on darwin and OS/2, anyway) and
96 * doesn't make macro expansion complain. Hope this works for everyone else
99 * Revision 1.38 2001/10/23 21:19:04 jongfoster
100 * New error-handling support: jb_err type and JB_ERR_xxx constants
101 * CGI functions now return a jb_err, and their parameters map is const.
102 * Support for RUNTIME_FEATUREs to enable/disable config editor
103 * Adding a few comments
105 * Revision 1.37 2001/10/14 22:14:01 jongfoster
106 * Removing name_length field from struct cgi_dispatcher, as this is
107 * now calculated at runtime from the "name" field.
109 * Revision 1.36 2001/10/10 16:45:15 oes
110 * Added LIMIT_CONNECT action and string
111 * Fixed HTTP message line termination
112 * Added CFORBIDDEN HTTP message
114 * Revision 1.35 2001/10/07 18:06:43 oes
115 * Added status member to struct http_request
117 * Revision 1.34 2001/10/07 15:45:25 oes
118 * Added url member to struct http_request and commented all
123 * Added ACTION_DOWNGRADE and ACTION_NO_COMPRESSION
125 * Replaced struct client_state members rejected,
126 * force, active and toggled_on with "flags" bitmap.
128 * Added CSP_FLAG_MODIFIED and CSP_FLAG_CHUNKED
130 * Added buffer_limit to struct configuration_spec
132 * Revision 1.33 2001/09/20 13:30:08 steudten
134 * Make freez() more secure in case of: if (exp) { free(z) ; a=*z }
135 * Last case will set z to NULL in free(z) and thats bad..
137 * Revision 1.32 2001/09/16 23:02:51 jongfoster
140 * Revision 1.31 2001/09/16 13:20:29 jongfoster
141 * Rewrite of list library. Now has seperate header and list_entry
142 * structures. Also added a large sprinking of assert()s to the list
145 * Revision 1.30 2001/09/13 23:52:00 jongfoster
146 * Support for both static and dynamically generated CGI pages
148 * Revision 1.29 2001/09/13 23:29:43 jongfoster
149 * Defining FORWARD_SPEC_INITIALIZER
151 * Revision 1.28 2001/09/13 23:05:50 jongfoster
152 * Changing the string paramater to the header parsers a "const".
154 * Revision 1.27 2001/08/05 16:06:20 jongfoster
155 * Modifiying "struct map" so that there are now separate header and
156 * "map_entry" structures. This means that functions which modify a
157 * map no longer need to return a pointer to the modified map.
158 * Also, it no longer reverses the order of the entries (which may be
159 * important with some advanced template substitutions).
161 * Revision 1.26 2001/07/30 22:08:36 jongfoster
162 * Tidying up #defines:
163 * - All feature #defines are now of the form FEATURE_xxx
164 * - Permanently turned off WIN_GUI_EDIT
165 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
167 * Revision 1.25 2001/07/29 18:43:08 jongfoster
168 * Changing #ifdef _FILENAME_H to FILENAME_H_INCLUDED, to conform to
171 * Revision 1.24 2001/07/25 17:20:27 oes
172 * Introduced http->user_agent
174 * Revision 1.23 2001/07/18 12:32:23 oes
175 * - Added ACTION_STRING_DEANIMATE
176 * - moved #define freez from jcc.h to project.h
178 * Revision 1.22 2001/07/15 17:51:41 jongfoster
179 * Renaming #define STATIC to STATIC_PCRE
181 * Revision 1.21 2001/07/13 14:03:19 oes
182 * - Reorganized regex header inclusion and #defines to
183 * comply to the scheme in configure.in
184 * - Added csp->content_type and its CT_* keys
185 * - Added ACTION_DEANIMATE
186 * - Removed all #ifdef PCRS
188 * Revision 1.20 2001/06/29 21:45:41 oes
189 * Indentation, CRLF->LF, Tab-> Space
191 * Revision 1.19 2001/06/29 13:33:36 oes
192 * - Improved comments
193 * - Introduced http_request.host_ip_addr_str
194 * - Introduced http_response.head_length
195 * - Introduced config.my_ip_addr_str, config.my_hostname,
196 * config.admin_address and config.proxy_info_url
197 * - Removed config.proxy_args_header and config.proxy_args_trailer,
198 * renamed config.proxy_args_invocation to config.proxy_args
199 * - Removed HTML snipplets and GIFs
200 * - Removed logentry from cancelled commit
202 * Revision 1.18 2001/06/09 10:57:39 jongfoster
203 * Adding definition of BUFFER_SIZE.
204 * Changing struct cgi_dispatcher to use "const" strings.
206 * Revision 1.17 2001/06/07 23:15:09 jongfoster
207 * Merging ACL and forward files into config file.
208 * Moving struct gateway members into struct forward_spec
209 * Removing config->proxy_args_gateways
210 * Cosmetic: Adding a few comments
212 * Revision 1.16 2001/06/04 18:31:58 swa
213 * files are now prefixed with either `confdir' or `logdir'.
214 * `make redhat-dist' replaces both entries confdir and logdir
217 * Revision 1.15 2001/06/04 11:28:53 swa
218 * redirect did not work due to missing /
220 * Revision 1.14 2001/06/03 11:03:48 oes
222 * added struct http_response,
223 * changed struct interceptors to struct cgi_dispatcher,
224 * moved HTML stuff to cgi.h
226 * Revision 1.13 2001/06/01 20:05:36 jongfoster
227 * Support for +image-blocker{}: added ACTION_IMAGE_BLOCKER
228 * constant, and removed csp->tinygif.
230 * Revision 1.12 2001/06/01 18:49:17 jongfoster
231 * Replaced "list_share" with "list" - the tiny memory gain was not
232 * worth the extra complexity.
234 * Revision 1.11 2001/06/01 10:32:47 oes
235 * Added constants for anchoring selection bitmap
237 * Revision 1.10 2001/05/31 21:33:53 jongfoster
238 * Changes for new actions file, replacing permissionsfile
239 * and parts of the config file. Also added support for
242 * Revision 1.9 2001/05/31 17:32:31 oes
244 * - Enhanced domain part globbing with infix and prefix asterisk
245 * matching and optional unanchored operation
247 * Revision 1.8 2001/05/29 20:09:15 joergs
248 * HTTP_REDIRECT_TEMPLATE fixed.
250 * Revision 1.7 2001/05/29 09:50:24 jongfoster
251 * Unified blocklist/imagelist/actionslist.
252 * File format is still under discussion, but the internal changes
255 * Also modified interceptor behaviour:
256 * - We now intercept all URLs beginning with one of the following
257 * prefixes (and *only* these prefixes):
259 * * http://ijbswa.sf.net/config/
260 * * http://ijbswa.sourceforge.net/config/
261 * - New interceptors "home page" - go to http://i.j.b/ to see it.
262 * - Internal changes so that intercepted and fast redirect pages
263 * are not replaced with an image.
264 * - Interceptors now have the option to send a binary page direct
265 * to the client. (i.e. ijb-send-banner uses this)
266 * - Implemented show-url-info interceptor. (Which is why I needed
267 * the above interceptors changes - a typical URL is
268 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
269 * The previous mechanism would not have intercepted that, and
270 * if it had been intercepted then it then it would have replaced
273 * Revision 1.6 2001/05/27 22:17:04 oes
275 * - re_process_buffer no longer writes the modified buffer
276 * to the client, which was very ugly. It now returns the
277 * buffer, which it is then written by chat.
279 * - content_length now adjusts the Content-Length: header
280 * for modified documents rather than crunch()ing it.
281 * (Length info in csp->content_length, which is 0 for
282 * unmodified documents)
284 * - For this to work, sed() is called twice when filtering.
286 * Revision 1.5 2001/05/26 00:28:36 jongfoster
287 * Automatic reloading of config file.
288 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
289 * Most of the global variables have been moved to a new
290 * struct configuration_spec, accessed through csp->config->globalname
291 * Most of the globals remaining are used by the Win32 GUI.
293 * Revision 1.4 2001/05/22 18:46:04 oes
295 * - Enabled filtering banners by size rather than URL
296 * by adding patterns that replace all standard banner
297 * sizes with the "Junkbuster" gif to the re_filterfile
299 * - Enabled filtering WebBugs by providing a pattern
300 * which kills all 1x1 images
302 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
303 * which is selected by the (nonstandard and therefore
304 * capital) letter 'U' in the option string.
305 * It causes the quantifiers to be ungreedy by default.
306 * Appending a ? turns back to greedy (!).
308 * - Added a new interceptor ijb-send-banner, which
309 * sends back the "Junkbuster" gif. Without imagelist or
310 * MSIE detection support, or if tinygif = 1, or the
311 * URL isn't recognized as an imageurl, a lame HTML
312 * explanation is sent instead.
314 * - Added new feature, which permits blocking remote
315 * script redirects and firing back a local redirect
317 * The feature is conditionally compiled, i.e. it
318 * can be disabled with --disable-fast-redirects,
319 * plus it must be activated by a "fast-redirects"
320 * line in the config file, has its own log level
321 * and of course wants to be displayed by show-proxy-args
322 * Note: Boy, all the #ifdefs in 1001 locations and
323 * all the fumbling with configure.in and acconfig.h
324 * were *way* more work than the feature itself :-(
326 * - Because a generic redirect template was needed for
327 * this, tinygif = 3 now uses the same.
329 * - Moved GIFs, and other static HTTP response templates
334 * - Removed some >400 CRs again (Jon, you really worked
337 * Revision 1.3 2001/05/20 01:21:20 jongfoster
338 * Version 2.9.4 checkin.
339 * - Merged popupfile and cookiefile, and added control over PCRS
340 * filtering, in new "actionsfile".
341 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
342 * file error you now get a message box (in the Win32 GUI) rather
343 * than the program exiting with no explanation.
344 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
346 * - Removed tabs from "config"
347 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
348 * - Bumped up version number.
350 * Revision 1.2 2001/05/17 23:01:01 oes
351 * - Cleaned CRLF's from the sources and related files
353 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
354 * Initial import of version 2.9.3 source tree
357 *********************************************************************/
360 /* Declare struct FILE for vars and funcs. */
363 /* Need time_t for file_list */
367 * Include appropriate regular expression libraries.
368 * Note that pcrs and pcre (native) are needed for cgi
369 * and are included anyway.
372 #if defined(REGEX_PCRE) || defined (REGEX_GNU)
374 #endif /* defined(REGEX_PCRE) || defined (REGEX_GNU) */
388 #if defined(REGEX_PCRE)
390 # include "pcreposix.h"
392 # include <pcreposix.h>
394 #endif /* defined(REGEX_PCRE) */
396 #if defined(REGEX_GNU)
397 # include "gnu_regex.h"
402 #endif /* def AMIGA */
410 * Error codes. Functions returning these should return a jb_err
412 #define JB_ERR_OK 0 /* Success, no error */
413 #define JB_ERR_MEMORY 1 /* Out of memory */
414 #define JB_ERR_CGI_PARAMS 2 /* Missing or corrupt CGI parameters */
415 #define JB_ERR_FILE 3 /* Error opening, reading or writing a file */
416 #define JB_ERR_PARSE 4 /* Error parsing file */
417 #define JB_ERR_MODIFIED 5 /* File has been modified outside of the */
418 /* CGI actions editor. */
423 * This macro is used to free a pointer that may be NULL
425 #define freez(X) { if(X) { free((void*)X); X = NULL ; } }
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 * Note: Remember to #include <ctype.h> if you use these macros.
437 #define ijb_toupper(__X) toupper((int)(unsigned char)(__X))
438 #define ijb_tolower(__X) tolower((int)(unsigned char)(__X))
439 #define ijb_isspace(__X) isspace((int)(unsigned char)(__X))
442 * Use for statically allocated buffers if you have no other choice.
443 * Remember to check the length of what you write into the buffer
444 * - we don't want any buffer overflows!
446 #define BUFFER_SIZE 5000
449 * Buffer size for capturing struct hostent data in the
450 * gethostby(name|addr)_r library calls. Since we don't
451 * loop over gethostbyname_r, the buffer must be sufficient
452 * to accomodate multiple IN A RRs, as used in DNS round robin
453 * load balancing. W3C's wwwlib uses 1K, so that should be
454 * good enough for us, too.
456 #define HOSTENT_BUFFER_SIZE 1024
459 * So you can say "while (FOREVER) { ...do something... }"
463 /* Default IP and port to listen on */
464 #define HADDR_DEFAULT "127.0.0.1"
465 #define HADDR_PORT 8118
467 /* Forward defs for various structures */
469 /* Need this for struct client_state */
470 struct configuration_spec;
473 /* Generic linked list of strings */
478 struct list_entry *next;
483 struct list_entry *first;
484 struct list_entry *last;
488 /* A map from a string to another string */
494 struct map_entry *next;
499 struct map_entry *first;
500 struct map_entry *last;
506 char *cmd; /* Whole command line: method, URL, Version */
507 char *ocmd; /* Backup of original cmd for CLF logging */
508 char *gpc; /* HTTP method: GET, POST, .. */
509 char *url; /* The URL */
510 char *ver; /* Protocol version */
511 int status; /* HTTP Status */
513 char *host; /* Host part of URL */
514 int port; /* Port of URL or 80 (default) */
515 char *path; /* Path of URL */
516 char *hostport; /* host[:port] */
517 int ssl; /* Flag if protocol is https */
519 char *host_ip_addr_str; /* String with dotted decimal representation
520 * of host's IP. NULL before connect_to() */
522 char *dbuffer; /* Buffer with '\0'-delimited domain name. */
523 char **dvec; /* List of pointers to the strings in dbuffer. */
524 int dcount; /* How many parts to this domain? (length of dvec) */
528 * Response generated by CGI, blocker, or error handler
532 char *status; /* HTTP status (string) */
533 struct list headers[1]; /* List of header lines */
534 char *head; /* Formatted http response head */
535 size_t head_length; /* Length of http response head */
536 char *body; /* HTTP document body */
537 size_t content_length; /* Length of body, REQUIRED if binary body */
538 int is_static; /* Nonzero if the content will never change and
539 * should be cached by the brwoser (e.g. images) */
545 char *spec; /* The string which was parsed to produce this */
546 /* url_spec. Used for debugging or display only. */
548 /* Hostname matching, or dbuffer == NULL to match all hosts */
549 char *dbuffer; /* Buffer with '\0'-delimited domain name. */
550 char **dvec; /* List of pointers to the strings in dbuffer. */
551 int dcount; /* How many parts to this domain? (length of dvec) */
552 int unanchored; /* Bitmap - flags are ANCHOR_LEFT and ANCHOR_RIGHT. */
555 int port; /* The port number, or 0 to match all ports. */
558 char *path; /* The path prefix (if not using regex), or source */
560 int pathlen; /* ==strlen(path). Needed for prefix matching. */
562 regex_t *preg; /* Regex for matching path part */
566 #define URL_SPEC_INITIALIZER { NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL }
567 #else /* ifndef REGEX */
568 #define URL_SPEC_INITIALIZER { NULL, NULL, NULL, 0, 0, 0, NULL, 0 }
569 #endif /* ndef REGEX */
571 /* Constants for host part matching in URLs */
572 #define ANCHOR_LEFT 1
573 #define ANCHOR_RIGHT 2
585 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
586 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
588 /* Keys for csp->content_type */
589 #define CT_TEXT 1 /* Suitable for pcrs filtering */
590 #define CT_GIF 2 /* Suitable for GIF filtering */
591 #define CT_TABOO 3 /* DONT filter */
593 #define ACTION_MASK_ALL (~0U)
595 #define ACTION_MOST_COMPATIBLE 0x00000000UL
597 #define ACTION_BLOCK 0x00000001UL
598 #define ACTION_DEANIMATE 0x00000002UL
599 #define ACTION_DOWNGRADE 0x00000004UL
600 #define ACTION_FAST_REDIRECTS 0x00000008UL
601 #define ACTION_FILTER 0x00000010UL
602 #define ACTION_HIDE_FORWARDED 0x00000020UL
603 #define ACTION_HIDE_FROM 0x00000040UL
604 #define ACTION_HIDE_REFERER 0x00000080UL /* sic - follow HTTP, not English */
605 #define ACTION_HIDE_USER_AGENT 0x00000100UL
606 #define ACTION_IMAGE 0x00000200UL
607 #define ACTION_IMAGE_BLOCKER 0x00000400UL
608 #define ACTION_NO_COMPRESSION 0x00000800UL
609 #define ACTION_NO_COOKIE_KEEP 0x00001000UL
610 #define ACTION_NO_COOKIE_READ 0x00002000UL
611 #define ACTION_NO_COOKIE_SET 0x00004000UL
612 #define ACTION_NO_POPUPS 0x00008000UL
613 #define ACTION_VANILLA_WAFER 0x00010000UL
614 #define ACTION_LIMIT_CONNECT 0x00020000UL
616 #define ACTION_STRING_DEANIMATE 0
617 #define ACTION_STRING_FROM 1
618 #define ACTION_STRING_IMAGE_BLOCKER 2
619 #define ACTION_STRING_REFERER 3
620 #define ACTION_STRING_USER_AGENT 4
621 #define ACTION_STRING_LIMIT_CONNECT 5
622 #define ACTION_STRING_COUNT 6
624 #define ACTION_MULTI_ADD_HEADER 0
625 #define ACTION_MULTI_WAFER 1
626 #define ACTION_MULTI_COUNT 2
629 * This structure contains a list of actions to apply to a URL.
630 * It only contains positive instructions - no "-" options.
631 * It is not used to store the actions list itself, only for
632 * url_actions() to return the current values.
634 struct current_action_spec
636 unsigned long flags; /* a bit set to "1" = add action */
638 /* For those actions that require parameters: */
640 /* each entry is valid if & only if corresponding entry in "add" set. */
641 char * string[ACTION_STRING_COUNT];
644 struct list multi[ACTION_MULTI_COUNT][1];
649 * This structure contains a set of changes to actions.
650 * It can contain both positive and negative instructions.
651 * It is used to store an entry in the actions list.
655 unsigned long mask; /* a bit set to "0" = remove action */
656 unsigned long add; /* a bit set to "1" = add action */
658 /* For those actions that require parameters: */
660 /* each entry is valid if & only if corresponding entry in "add" set. */
661 char * string[ACTION_STRING_COUNT];
663 /* Strings to remove. */
664 struct list multi_remove[ACTION_MULTI_COUNT][1];
666 /* If nonzero, remove *all* strings. */
667 int multi_remove_all[ACTION_MULTI_COUNT];
670 struct list multi_add[ACTION_MULTI_COUNT][1];
674 * This structure is used to store the actions list.
676 * It contains a URL pattern, and the chages to the actions.
677 * It is a linked list.
681 struct url_spec url[1];
683 struct action_spec action[1];
685 struct url_actions * next;
690 * Flags for use in csp->flags
692 #define CSP_FLAG_ACTIVE 0x01 /* Set if this client is processing data.
693 * Cleared when the thread associated with
694 * this structure dies. */
695 #define CSP_FLAG_CHUNKED 0x02 /* Set if the server's reply is in "chunked"
696 * transfer encoding */
697 #define CSP_FLAG_FORCED 0x04 /* Set if this request was enforced, although
698 * it would normally have been blocked. */
699 #define CSP_FLAG_MODIFIED 0x08 /* Set if any modification to the body was done */
700 #define CSP_FLAG_REJECTED 0x10 /* Set if request was blocked. */
701 #define CSP_FLAG_TOGGLED_ON 0x20 /* Set if we are toggled on (FEATURE_TOGGLE) */
704 * The state of a JunkBuster processing thread.
708 /* The proxy's configuration */
709 struct configuration_spec * config;
711 /* The actions to perform on the current request */
712 struct current_action_spec action[1];
714 /* socket to talk to client (web browser) */
717 /* socket to talk to server (web server or proxy) */
720 /* Multi-purpose flag container, see CSP_FLAG_* above */
721 unsigned short int flags;
724 * Client PC's IP address, as reported by the accept()_ function.
725 * Both as string and number
731 /* Our IP address and hostname, i.e. the IP address that
732 the client used to reach us, and the associated hostname,
735 char *my_ip_addr_str;
738 /* The URL that was requested */
739 struct http_request http[1];
741 /* An I/O buffer used for buffering data read from the client */
744 /* List of all headers for this request */
745 struct list headers[1];
747 /* List of all cookies for this request */
748 struct list cookie_list[1];
750 /* MIME-Type key, see CT_* above */
751 unsigned short int content_type;
753 /* The "X-Forwarded-For:" header sent by the client */
756 /* files associated with this client */
757 struct file_list *actions_list;
759 struct file_list *rlist; /* pcrs job file */
760 size_t content_length; /* Length after content modification */
763 struct file_list *tlist; /* trustfile */
764 #endif /* def FEATURE_TRUST */
766 struct client_state *next;
771 * A function to add a header
773 typedef jb_err (*add_header_func_ptr)(struct client_state *);
776 * A function to process a header
778 typedef jb_err (*parser_func_ptr )(struct client_state *, char **);
781 * List of functions to run on a list of headers
787 parser_func_ptr parser;
792 * List of available CGI functions.
794 struct cgi_dispatcher
796 const char * const name;
797 jb_err (* const handler)(struct client_state *csp, struct http_response *rsp, const struct map *parameters);
798 const char * const description;
803 * A data file used by JunkBuster. Kept in a linked list.
808 * this is a pointer to the data structures associated with the file.
809 * Read-only once the structure has been created.
813 /* Normally NULL. When we are finished with file (i.e. when we have
814 * loaded a new one), set to a pointer to an unloader function.
815 * Unloader will be called by sweep() (called from main loop) when
816 * all clients using this file are done. This prevents threading
819 void (*unloader)(void *);
821 /* Used internally by sweep(). Do not access from elsewhere. */
824 /* Following variables allow us to check if file has been changed.
825 * Read-only once the structure has been created.
830 /* Pointer to next entry in the linked list of all "file_list"s.
831 * This linked list is so that sweep() can navigate it.
832 * Since sweep() can remove items from the list, we must be careful
833 * to only access this value from main thread (when we know sweep
836 struct file_list *next;
843 struct url_spec url[1];
845 struct block_spec *next;
847 #endif /* def FEATURE_TRUST */
850 #define SOCKS_NONE 0 /* Don't use a SOCKS server */
851 #define SOCKS_4 40 /* original SOCKS 4 protocol */
852 #define SOCKS_4A 41 /* as modified for hosts w/o external DNS */
856 struct url_spec url[1];
858 /* Connection type - must be a SOCKS_xxx constant */
865 /* Parent HTTP proxy */
869 /* For the linked list */
870 struct forward_spec *next;
872 #define FORWARD_SPEC_INITIALIZER { { URL_SPEC_INITIALIZER }, 0, NULL, 0, NULL, 0, NULL }
875 struct re_filterfile_spec
879 struct list patterns[1];
884 #define ACL_PERMIT 1 /* accept connection request */
885 #define ACL_DENY 2 /* reject connection request */
887 struct access_control_addr
894 struct access_control_list
896 struct access_control_addr src[1];
897 struct access_control_addr dst[1];
900 struct access_control_list *next;
902 #endif /* def FEATURE_ACL */
905 /* Maximum number of loaders (actions, re_filter, ...) */
909 #define RUNTIME_FEATURE_CGI_EDIT_ACTIONS 1
910 #define RUNTIME_FEATURE_CGI_TOGGLE 2
914 * Data loaded from the configuration file.
916 * (Anomaly: toggle is still handled through a global, not this structure)
918 struct configuration_spec
923 /* Features that can be enabled/disabled throuigh the config file */
924 unsigned feature_flags;
930 const char *actions_file;
932 /* The administrator's email address */
935 /* A URL with info on this proxy */
936 char *proxy_info_url;
938 const char *re_filterfile;
940 #ifdef FEATURE_COOKIE_JAR
941 const char * jarfile;
943 #endif /* def FEATURE_COOKIE_JAR */
946 * Port and IP to bind to.
947 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8118
952 /* Size limit for IOB */
956 const char * trustfile;
958 struct list trust_info[1];
959 struct url_spec *trust_list[64];
960 #endif /* def FEATURE_TRUST */
963 struct access_control_list *acl;
964 #endif /* def FEATURE_ACL */
966 struct forward_spec *forward;
968 /* All options from the config file, HTML-formatted */
971 /* the configuration file object. */
972 struct file_list *config_file_list;
974 /* List of loaders */
975 int (*loaders[NLOADERS])(struct client_state *);
977 /* bool, nonzero if we need to bind() to the new port */
982 #define SZ(X) (sizeof(X) / sizeof(*X))
984 #ifdef FEATURE_FORCE_LOAD
985 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
986 #endif /* def FEATURE_FORCE_LOAD */
988 #ifdef FEATURE_NO_GIFS
989 #define BUILTIN_IMAGE_MIMETYPE "image/png"
991 #define BUILTIN_IMAGE_MIMETYPE "image/gif"
992 #endif /* def FEATURE_NO_GIFS */
996 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net"
997 #define REDIRECT_URL HOME_PAGE_URL "/redirect.php?v=" VERSION "&to="
1000 * The "hosts" to intercept and display CGI pages.
1001 * First one is a hostname only, second one can specify host and path.
1004 * 1) Do not specify the http: prefix
1005 * 2) CGI_SITE_2_PATH must not end with /, one will be added automatically.
1006 * 3) CGI_SITE_2_PATH must start with /, unless it is the empty string.
1008 #define CGI_SITE_1_HOST "i.j.b"
1009 #define CGI_SITE_2_HOST "ijbswa.sourceforge.net"
1010 #define CGI_SITE_2_PATH "/config"
1013 * The prefix for CGI pages. Written out in generated HTML.
1014 * INCLUDES the trailing slash.
1016 #define CGI_PREFIX "http://" CGI_SITE_2_HOST CGI_SITE_2_PATH "/"
1019 /* HTTP snipplets */
1020 static const char CSUCCEED[] =
1021 "HTTP/1.0 200 Connection established\n"
1022 "Proxy-Agent: IJ/" VERSION "\r\n\r\n";
1024 static const char CHEADER[] =
1025 "HTTP/1.0 400 Invalid header received from browser\r\n\r\n";
1027 static const char CFORBIDDEN[] =
1028 "HTTP/1.0 403 Connection not allowable\r\nX-Hint: If you read this message interactively, then you know why this happens ,-)\r\n\r\n";
1034 #endif /* ndef PROJECT_H_INCLUDED */