1 #ifndef FILTERS_H_INCLUDED
2 #define FILTERS_H_INCLUDED
3 #define FILTERS_H_VERSION "$Id: filters.h,v 1.35 2008/05/03 16:40:45 fabiankeil Exp $"
4 /*********************************************************************
6 * File : $Source: /cvsroot/ijbswa/current/filters.h,v $
8 * Purpose : Declares functions to parse/crunch headers and pages.
9 * Functions declared include:
10 * `acl_addr', `add_stats', `block_acl', `block_imageurl',
11 * `block_url', `url_actions', `filter_popups', `forward_url'
12 * `ij_untrusted_url', `intercept_url', `re_process_buffer',
13 * `show_proxy_args', and `trust_url'
15 * Copyright : Written by and Copyright (C) 2001, 2004 the SourceForge
16 * Privoxy team. http://www.privoxy.org/
18 * Based on the Internet Junkbuster originally written
19 * by and Copyright (C) 1997 Anonymous Coders and
20 * Junkbusters Corporation. http://www.junkbusters.com
22 * This program is free software; you can redistribute it
23 * and/or modify it under the terms of the GNU General
24 * Public License as published by the Free Software
25 * Foundation; either version 2 of the License, or (at
26 * your option) any later version.
28 * This program is distributed in the hope that it will
29 * be useful, but WITHOUT ANY WARRANTY; without even the
30 * implied warranty of MERCHANTABILITY or FITNESS FOR A
31 * PARTICULAR PURPOSE. See the GNU General Public
32 * License for more details.
34 * The GNU General Public License should be included with
35 * this file. If not, you can view it at
36 * http://www.gnu.org/copyleft/gpl.html
37 * or write to the Free Software Foundation, Inc., 59
38 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42 * Revision 1.35 2008/05/03 16:40:45 fabiankeil
43 * Change content_filters_enabled()'s parameter from
44 * csp->action to action so it can be also used in the
45 * CGI code. Don't bother checking if there are filters
46 * loaded, as that's somewhat besides the point.
48 * Revision 1.34 2008/03/02 12:25:25 fabiankeil
49 * Also use shiny new connect_port_is_forbidden() in jcc.c.
51 * Revision 1.33 2008/02/23 16:57:12 fabiankeil
52 * Rename url_actions() to get_url_actions() and let it
53 * use the standard parameter ordering.
55 * Revision 1.32 2008/02/23 16:33:43 fabiankeil
56 * Let forward_url() use the standard parameter ordering
57 * and mark its second parameter immutable.
59 * Revision 1.31 2007/10/19 16:53:28 fabiankeil
60 * Add helper function to check if any content filters are enabled.
62 * Revision 1.30 2007/09/29 10:21:16 fabiankeil
63 * - Move get_filter_function() from jcc.c to filters.c
64 * so the filter functions can be static.
65 * - Don't bother filtering body-less responses.
67 * Revision 1.29 2007/09/28 16:38:55 fabiankeil
68 * - Execute content filters through execute_content_filter().
69 * - Add prepare_for_filtering() so filter functions don't have to
70 * care about de-chunking and decompression. As a side effect this enables
71 * decompression for gif_deanimate_response() and jpeg_inspect_response().
72 * - Change remove_chunked_transfer_coding()'s return type to jb_err.
73 * Some clowns feel like chunking empty responses in which case
74 * (size == 0) is valid but previously would be interpreted as error.
76 * Revision 1.28 2007/09/02 15:31:20 fabiankeil
77 * Move match_portlist() from filter.c to urlmatch.c.
78 * It's used for url matching, not for filtering.
80 * Revision 1.27 2007/04/30 15:02:18 fabiankeil
81 * Introduce dynamic pcrs jobs that can resolve variables.
83 * Revision 1.26 2007/03/13 11:28:43 fabiankeil
84 * - Fix port handling in acl_addr() and use a temporary acl spec
85 * copy so error messages don't contain a truncated version.
86 * - Log size of iob before and after decompression.
88 * Revision 1.25 2007/01/12 15:36:44 fabiankeil
89 * Mark *csp as immutable for is_untrusted_url()
90 * and is_imageurl(). Closes FR 1237736.
92 * Revision 1.24 2006/12/29 18:30:46 fabiankeil
93 * Fixed gcc43 conversion warnings,
94 * changed sprintf calls to snprintf.
96 * Revision 1.23 2006/11/28 15:19:43 fabiankeil
97 * Implemented +redirect{s@foo@bar@} to generate
98 * a redirect based on a rewritten version of the
101 * Revision 1.22 2006/07/18 14:48:46 david__schmidt
102 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
103 * with what was really the latest development (the v_3_0_branch branch)
105 * Revision 1.20.2.2 2004/10/03 12:53:32 david__schmidt
106 * Add the ability to check jpeg images for invalid
107 * lengths of comment blocks. Defensive strategy
108 * against the exploit:
109 * Microsoft Security Bulletin MS04-028
110 * Buffer Overrun in JPEG Processing (GDI+) Could
111 * Allow Code Execution (833987)
112 * Enabled with +inspect-jpegs in actions files.
114 * Revision 1.20.2.1 2002/09/25 14:51:51 oes
115 * Added basic support for OPTIONS and TRACE HTTP methods:
116 * New function direct_response which handles OPTIONS and
117 * TRACE requests whose Max-Forwards header field is zero.
119 * Revision 1.20 2002/04/02 14:56:16 oes
120 * Bugfix: is_untrusted_url() and trust_url() now depend on FEATURE_TRUST, not FEATURE_COOKIE_JAR
122 * Revision 1.19 2002/03/26 22:29:54 swa
123 * we have a new homepage!
125 * Revision 1.18 2002/03/25 22:12:45 oes
126 * Added fix for undefined INADDR_NONE on Solaris by Bart Schelstraete
128 * Revision 1.17 2002/03/24 13:25:43 swa
129 * name change related issues
131 * Revision 1.16 2002/01/17 21:01:02 jongfoster
132 * Moving all our URL and URL pattern parsing code to urlmatch.c.
134 * Revision 1.15 2001/10/10 16:44:16 oes
135 * Added match_portlist function
137 * Revision 1.14 2001/10/07 15:41:40 oes
138 * Added prototype for remove_chunked_transfer_coding
140 * Revision 1.13 2001/07/30 22:08:36 jongfoster
141 * Tidying up #defines:
142 * - All feature #defines are now of the form FEATURE_xxx
143 * - Permanently turned off WIN_GUI_EDIT
144 * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
146 * Revision 1.12 2001/07/29 19:01:11 jongfoster
147 * Changed _FILENAME_H to FILENAME_H_INCLUDED.
148 * Added forward declarations for needed structures.
150 * Revision 1.11 2001/07/13 14:00:18 oes
151 * - Introduced gif_deanimate_response
152 * - Renamed re_process_buffer to pcrs_filter_response
153 * - Removed all #ifdef PCRS
155 * Revision 1.10 2001/06/29 13:29:01 oes
156 * Cleaned up and updated to reflect the changesin
159 * Revision 1.9 2001/06/07 23:10:53 jongfoster
160 * Replacing struct gateway with struct forward_spec
162 * Revision 1.8 2001/06/03 19:12:00 oes
163 * extracted-CGI relevant stuff
165 * Revision 1.7 2001/05/31 21:21:30 jongfoster
166 * Permissionsfile / actions file changes:
167 * - Changed "permission" to "action" throughout
168 * - changes to file format to allow string parameters
169 * - Moved helper functions to actions.c
171 * Revision 1.6 2001/05/29 09:50:24 jongfoster
172 * Unified blocklist/imagelist/permissionslist.
173 * File format is still under discussion, but the internal changes
176 * Also modified interceptor behaviour:
177 * - We now intercept all URLs beginning with one of the following
178 * prefixes (and *only* these prefixes):
180 * * http://ijbswa.sf.net/config/
181 * * http://ijbswa.sourceforge.net/config/
182 * - New interceptors "home page" - go to http://i.j.b/ to see it.
183 * - Internal changes so that intercepted and fast redirect pages
184 * are not replaced with an image.
185 * - Interceptors now have the option to send a binary page direct
186 * to the client. (i.e. ijb-send-banner uses this)
187 * - Implemented show-url-info interceptor. (Which is why I needed
188 * the above interceptors changes - a typical URL is
189 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
190 * The previous mechanism would not have intercepted that, and
191 * if it had been intercepted then it then it would have replaced
194 * Revision 1.5 2001/05/27 22:17:04 oes
196 * - re_process_buffer no longer writes the modified buffer
197 * to the client, which was very ugly. It now returns the
198 * buffer, which it is then written by chat.
200 * - content_length now adjusts the Content-Length: header
201 * for modified documents rather than crunch()ing it.
202 * (Length info in csp->content_length, which is 0 for
203 * unmodified documents)
205 * - For this to work, sed() is called twice when filtering.
207 * Revision 1.4 2001/05/26 15:26:15 jongfoster
208 * ACL feature now provides more security by immediately dropping
209 * connections from untrusted hosts.
211 * Revision 1.3 2001/05/22 18:46:04 oes
213 * - Enabled filtering banners by size rather than URL
214 * by adding patterns that replace all standard banner
215 * sizes with the "Junkbuster" gif to the re_filterfile
217 * - Enabled filtering WebBugs by providing a pattern
218 * which kills all 1x1 images
220 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
221 * which is selected by the (nonstandard and therefore
222 * capital) letter 'U' in the option string.
223 * It causes the quantifiers to be ungreedy by default.
224 * Appending a ? turns back to greedy (!).
226 * - Added a new interceptor ijb-send-banner, which
227 * sends back the "Junkbuster" gif. Without imagelist or
228 * MSIE detection support, or if tinygif = 1, or the
229 * URL isn't recognized as an imageurl, a lame HTML
230 * explanation is sent instead.
232 * - Added new feature, which permits blocking remote
233 * script redirects and firing back a local redirect
235 * The feature is conditionally compiled, i.e. it
236 * can be disabled with --disable-fast-redirects,
237 * plus it must be activated by a "fast-redirects"
238 * line in the config file, has its own log level
239 * and of course wants to be displayed by show-proxy-args
240 * Note: Boy, all the #ifdefs in 1001 locations and
241 * all the fumbling with configure.in and acconfig.h
242 * were *way* more work than the feature itself :-(
244 * - Because a generic redirect template was needed for
245 * this, tinygif = 3 now uses the same.
247 * - Moved GIFs, and other static HTTP response templates
252 * - Removed some >400 CRs again (Jon, you really worked
255 * Revision 1.2 2001/05/20 01:21:20 jongfoster
256 * Version 2.9.4 checkin.
257 * - Merged popupfile and cookiefile, and added control over PCRS
258 * filtering, in new "permissionsfile".
259 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
260 * file error you now get a message box (in the Win32 GUI) rather
261 * than the program exiting with no explanation.
262 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
264 * - Removed tabs from "config"
265 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
266 * - Bumped up version number.
268 * Revision 1.1.1.1 2001/05/15 13:58:52 oes
269 * Initial import of version 2.9.3 source tree
272 *********************************************************************/
282 struct access_control_addr;
285 struct http_response;
286 struct current_action_spec;
295 extern int block_acl(const struct access_control_addr *dst, const struct client_state *csp);
296 extern int acl_addr(const char *aspec, struct access_control_addr *aca);
297 #endif /* def FEATURE_ACL */
302 extern struct http_response *block_url(struct client_state *csp);
303 extern struct http_response *redirect_url(struct client_state *csp);
305 extern struct http_response *trust_url(struct client_state *csp);
306 #endif /* def FEATURE_TRUST */
312 extern int is_untrusted_url(const struct client_state *csp);
313 #endif /* def FEATURE_TRUST */
314 #ifdef FEATURE_IMAGE_BLOCKING
315 extern int is_imageurl(const struct client_state *csp);
316 #endif /* def FEATURE_IMAGE_BLOCKING */
317 extern int connect_port_is_forbidden(const struct client_state *csp);
320 * Determining applicable actions
322 extern void get_url_actions(struct client_state *csp,
323 struct http_request *http);
324 extern void apply_url_actions(struct current_action_spec *action,
325 struct http_request *http,
326 struct url_actions *b);
328 * Determining parent proxies
330 extern const struct forward_spec *forward_url(struct client_state *csp,
331 const struct http_request *http);
334 * Content modification
337 typedef char *(*filter_function_ptr)();
338 extern char *execute_content_filter(struct client_state *csp, filter_function_ptr content_filter);
340 extern filter_function_ptr get_filter_function(struct client_state *csp);
341 extern char *execute_single_pcrs_command(char *subject, const char *pcrs_command, int *hits);
342 extern char *rewrite_url(char *old_url, const char *pcrs_command);
343 extern char *get_last_url(char *subject, const char *redirect_mode);
345 extern pcrs_job *compile_dynamic_pcrs_job_list(const struct client_state *csp, const struct re_filterfile_spec *b);
347 extern int content_filters_enabled(const struct current_action_spec *action);
350 * Handling Max-Forwards:
352 extern struct http_response *direct_response(struct client_state *csp);
359 #define INADDR_NONE -1
363 * Revision control strings from this header and associated .c file
365 extern const char filters_rcs[];
366 extern const char filters_h_rcs[];
372 #endif /* ndef FILTERS_H_INCLUDED */