Update action list and version.
[privoxy.git] / filters.h
1 #ifndef FILTERS_H_INCLUDED
2 #define FILTERS_H_INCLUDED
3 #define FILTERS_H_VERSION "$Id: filters.h,v 1.25 2007/01/12 15:36:44 fabiankeil Exp $"
4 /*********************************************************************
5  *
6  * File        :  $Source: /cvsroot/ijbswa/current/filters.h,v $
7  *
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'
14  *
15  * Copyright   :  Written by and Copyright (C) 2001, 2004 the SourceForge
16  *                Privoxy team. http://www.privoxy.org/
17  *
18  *                Based on the Internet Junkbuster originally written
19  *                by and Copyright (C) 1997 Anonymous Coders and 
20  *                Junkbusters Corporation.  http://www.junkbusters.com
21  *
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.
27  *
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.
33  *
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.
39  *
40  * Revisions   :
41  *    $Log: filters.h,v $
42  *    Revision 1.25  2007/01/12 15:36:44  fabiankeil
43  *    Mark *csp as immutable for is_untrusted_url()
44  *    and is_imageurl(). Closes FR 1237736.
45  *
46  *    Revision 1.24  2006/12/29 18:30:46  fabiankeil
47  *    Fixed gcc43 conversion warnings,
48  *    changed sprintf calls to snprintf.
49  *
50  *    Revision 1.23  2006/11/28 15:19:43  fabiankeil
51  *    Implemented +redirect{s@foo@bar@} to generate
52  *    a redirect based on a rewritten version of the
53  *    original URL.
54  *
55  *    Revision 1.22  2006/07/18 14:48:46  david__schmidt
56  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
57  *    with what was really the latest development (the v_3_0_branch branch)
58  *
59  *    Revision 1.20.2.2  2004/10/03 12:53:32  david__schmidt
60  *    Add the ability to check jpeg images for invalid
61  *    lengths of comment blocks.  Defensive strategy
62  *    against the exploit:
63  *       Microsoft Security Bulletin MS04-028
64  *       Buffer Overrun in JPEG Processing (GDI+) Could
65  *       Allow Code Execution (833987)
66  *    Enabled with +inspect-jpegs in actions files.
67  *
68  *    Revision 1.20.2.1  2002/09/25 14:51:51  oes
69  *    Added basic support for OPTIONS and TRACE HTTP methods:
70  *    New function direct_response which handles OPTIONS and
71  *    TRACE requests whose Max-Forwards header field is zero.
72  *
73  *    Revision 1.20  2002/04/02 14:56:16  oes
74  *    Bugfix: is_untrusted_url() and trust_url() now depend on FEATURE_TRUST, not FEATURE_COOKIE_JAR
75  *
76  *    Revision 1.19  2002/03/26 22:29:54  swa
77  *    we have a new homepage!
78  *
79  *    Revision 1.18  2002/03/25 22:12:45  oes
80  *    Added fix for undefined INADDR_NONE on Solaris by Bart Schelstraete
81  *
82  *    Revision 1.17  2002/03/24 13:25:43  swa
83  *    name change related issues
84  *
85  *    Revision 1.16  2002/01/17 21:01:02  jongfoster
86  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
87  *
88  *    Revision 1.15  2001/10/10 16:44:16  oes
89  *    Added match_portlist function
90  *
91  *    Revision 1.14  2001/10/07 15:41:40  oes
92  *    Added prototype for remove_chunked_transfer_coding
93  *
94  *    Revision 1.13  2001/07/30 22:08:36  jongfoster
95  *    Tidying up #defines:
96  *    - All feature #defines are now of the form FEATURE_xxx
97  *    - Permanently turned off WIN_GUI_EDIT
98  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
99  *
100  *    Revision 1.12  2001/07/29 19:01:11  jongfoster
101  *    Changed _FILENAME_H to FILENAME_H_INCLUDED.
102  *    Added forward declarations for needed structures.
103  *
104  *    Revision 1.11  2001/07/13 14:00:18  oes
105  *     - Introduced gif_deanimate_response
106  *     - Renamed re_process_buffer to pcrs_filter_response
107  *     - Removed all #ifdef PCRS
108  *
109  *    Revision 1.10  2001/06/29 13:29:01  oes
110  *    Cleaned up and updated to reflect the changesin
111  *    filters.c
112  *
113  *    Revision 1.9  2001/06/07 23:10:53  jongfoster
114  *    Replacing struct gateway with struct forward_spec
115  *
116  *    Revision 1.8  2001/06/03 19:12:00  oes
117  *    extracted-CGI relevant stuff
118  *
119  *    Revision 1.7  2001/05/31 21:21:30  jongfoster
120  *    Permissionsfile / actions file changes:
121  *    - Changed "permission" to "action" throughout
122  *    - changes to file format to allow string parameters
123  *    - Moved helper functions to actions.c
124  *
125  *    Revision 1.6  2001/05/29 09:50:24  jongfoster
126  *    Unified blocklist/imagelist/permissionslist.
127  *    File format is still under discussion, but the internal changes
128  *    are (mostly) done.
129  *
130  *    Also modified interceptor behaviour:
131  *    - We now intercept all URLs beginning with one of the following
132  *      prefixes (and *only* these prefixes):
133  *        * http://i.j.b/
134  *        * http://ijbswa.sf.net/config/
135  *        * http://ijbswa.sourceforge.net/config/
136  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
137  *    - Internal changes so that intercepted and fast redirect pages
138  *      are not replaced with an image.
139  *    - Interceptors now have the option to send a binary page direct
140  *      to the client. (i.e. ijb-send-banner uses this)
141  *    - Implemented show-url-info interceptor.  (Which is why I needed
142  *      the above interceptors changes - a typical URL is
143  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
144  *      The previous mechanism would not have intercepted that, and
145  *      if it had been intercepted then it then it would have replaced
146  *      it with an image.)
147  *
148  *    Revision 1.5  2001/05/27 22:17:04  oes
149  *
150  *    - re_process_buffer no longer writes the modified buffer
151  *      to the client, which was very ugly. It now returns the
152  *      buffer, which it is then written by chat.
153  *
154  *    - content_length now adjusts the Content-Length: header
155  *      for modified documents rather than crunch()ing it.
156  *      (Length info in csp->content_length, which is 0 for
157  *      unmodified documents)
158  *
159  *    - For this to work, sed() is called twice when filtering.
160  *
161  *    Revision 1.4  2001/05/26 15:26:15  jongfoster
162  *    ACL feature now provides more security by immediately dropping
163  *    connections from untrusted hosts.
164  *
165  *    Revision 1.3  2001/05/22 18:46:04  oes
166  *
167  *    - Enabled filtering banners by size rather than URL
168  *      by adding patterns that replace all standard banner
169  *      sizes with the "Junkbuster" gif to the re_filterfile
170  *
171  *    - Enabled filtering WebBugs by providing a pattern
172  *      which kills all 1x1 images
173  *
174  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
175  *      which is selected by the (nonstandard and therefore
176  *      capital) letter 'U' in the option string.
177  *      It causes the quantifiers to be ungreedy by default.
178  *      Appending a ? turns back to greedy (!).
179  *
180  *    - Added a new interceptor ijb-send-banner, which
181  *      sends back the "Junkbuster" gif. Without imagelist or
182  *      MSIE detection support, or if tinygif = 1, or the
183  *      URL isn't recognized as an imageurl, a lame HTML
184  *      explanation is sent instead.
185  *
186  *    - Added new feature, which permits blocking remote
187  *      script redirects and firing back a local redirect
188  *      to the browser.
189  *      The feature is conditionally compiled, i.e. it
190  *      can be disabled with --disable-fast-redirects,
191  *      plus it must be activated by a "fast-redirects"
192  *      line in the config file, has its own log level
193  *      and of course wants to be displayed by show-proxy-args
194  *      Note: Boy, all the #ifdefs in 1001 locations and
195  *      all the fumbling with configure.in and acconfig.h
196  *      were *way* more work than the feature itself :-(
197  *
198  *    - Because a generic redirect template was needed for
199  *      this, tinygif = 3 now uses the same.
200  *
201  *    - Moved GIFs, and other static HTTP response templates
202  *      to project.h
203  *
204  *    - Some minor fixes
205  *
206  *    - Removed some >400 CRs again (Jon, you really worked
207  *      a lot! ;-)
208  *
209  *    Revision 1.2  2001/05/20 01:21:20  jongfoster
210  *    Version 2.9.4 checkin.
211  *    - Merged popupfile and cookiefile, and added control over PCRS
212  *      filtering, in new "permissionsfile".
213  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
214  *      file error you now get a message box (in the Win32 GUI) rather
215  *      than the program exiting with no explanation.
216  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
217  *      skipping.
218  *    - Removed tabs from "config"
219  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
220  *    - Bumped up version number.
221  *
222  *    Revision 1.1.1.1  2001/05/15 13:58:52  oes
223  *    Initial import of version 2.9.3 source tree
224  *
225  *
226  *********************************************************************/
227 \f
228
229 #include "project.h"
230
231 #ifdef __cplusplus
232 extern "C" {
233 #endif
234
235
236 struct access_control_addr;
237 struct client_state;
238 struct http_request;
239 struct http_response;
240 struct current_action_spec;
241 struct url_actions;
242 struct url_spec;
243
244
245 /*
246  * ACL checking
247  */
248 #ifdef FEATURE_ACL
249 extern int block_acl(struct access_control_addr *dst, struct client_state *csp);
250 extern int acl_addr(const char *aspec, struct access_control_addr *aca);
251 #endif /* def FEATURE_ACL */
252 extern int match_portlist(const char *portlist, int port);
253
254 /*
255  * Interceptors
256  */
257 extern struct http_response *block_url(struct client_state *csp);
258 extern struct http_response *redirect_url(struct client_state *csp);
259 #ifdef FEATURE_TRUST
260 extern struct http_response *trust_url(struct client_state *csp);
261 #endif /* def FEATURE_TRUST */
262
263 /*
264  * Request inspectors
265  */
266 #ifdef FEATURE_TRUST
267 extern int is_untrusted_url(const struct client_state *csp);
268 #endif /* def FEATURE_TRUST */
269 #ifdef FEATURE_IMAGE_BLOCKING
270 extern int is_imageurl(const struct client_state *csp);
271 #endif /* def FEATURE_IMAGE_BLOCKING */
272
273 /*
274  * Determining applicable actions
275  */
276 extern void url_actions(struct http_request *http, 
277                         struct client_state *csp);
278 extern void apply_url_actions(struct current_action_spec *action, 
279                               struct http_request *http, 
280                               struct url_actions *b);
281 /*
282  * Determining parent proxies
283  */
284 extern const struct forward_spec *forward_url(struct http_request *http, struct client_state *csp);
285
286 /*
287  * Content modification
288  */
289 extern char *pcrs_filter_response(struct client_state *csp);
290 extern char *gif_deanimate_response(struct client_state *csp);
291 extern char *jpeg_inspect_response(struct client_state *csp);
292 extern size_t remove_chunked_transfer_coding(char *buffer, const size_t size);
293 extern char *execute_single_pcrs_command(char *subject, const char *pcrs_command, int *hits);
294 extern char *rewrite_url(char *old_url, const char *pcrs_command);
295 extern char *get_last_url(char *subject, const char *redirect_mode);
296
297 /*
298  * Handling Max-Forwards:
299  */
300 extern struct http_response *direct_response( struct client_state *csp);
301
302
303 /*
304  * Solaris fix:
305  */
306 #ifndef INADDR_NONE
307 #define INADDR_NONE -1
308 #endif     
309
310 /* 
311  * Revision control strings from this header and associated .c file
312  */
313 extern const char filters_rcs[];
314 extern const char filters_h_rcs[];
315
316 #ifdef __cplusplus
317 } /* extern "C" */
318 #endif
319
320 #endif /* ndef FILTERS_H_INCLUDED */
321
322 /*
323   Local Variables:
324   tab-width: 3
325   end:
326 */