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