Changing #ifdef _FILENAME_H to FILENAME_H_INCLUDED, to conform to
[privoxy.git] / showargs.c
1 const char showargs_rcs[] = "$Id: showargs.c,v 1.19 2001/07/13 14:11:36 oes Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/showargs.c,v $
5  *
6  * Purpose     :  Contains various utility routines needed to 
7  *                generate the show-proxy-args page.
8  *                FIXME: Is this really stuff for a separate file?
9  *
10  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
11  *                IJBSWA team.  http://ijbswa.sourceforge.net
12  *
13  *                Based on the Internet Junkbuster originally written
14  *                by and Copyright (C) 1997 Anonymous Coders and 
15  *                Junkbusters Corporation.  http://www.junkbusters.com
16  *
17  *                This program is free software; you can redistribute it 
18  *                and/or modify it under the terms of the GNU General
19  *                Public License as published by the Free Software
20  *                Foundation; either version 2 of the License, or (at
21  *                your option) any later version.
22  *
23  *                This program is distributed in the hope that it will
24  *                be useful, but WITHOUT ANY WARRANTY; without even the
25  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
26  *                PARTICULAR PURPOSE.  See the GNU General Public
27  *                License for more details.
28  *
29  *                The GNU General Public License should be included with
30  *                this file.  If not, you can view it at
31  *                http://www.gnu.org/copyleft/gpl.html
32  *                or write to the Free Software Foundation, Inc., 59
33  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
34  *
35  * Revisions   :
36  *    $Log: showargs.c,v $
37  *    Revision 1.19  2001/07/13 14:11:36  oes
38  *     - Included SHOW_RCS for deanimate.*
39  *     - Removed all #ifdef PCRS
40  *
41  *
42  *    Revision 1.18  2001/07/02 02:55:16  iwanttokeepanon
43  *    Apended " on some sites" to the HTML generating function `show_defines' (@ line
44  *    392); since "DENY_GZIP" is not *really* necessary for all PCRS functionallity.
45  *
46  *    Revision 1.17  2001/06/29 21:45:41  oes
47  *    Indentation, CRLF->LF, Tab-> Space
48  *
49  *    Revision 1.16  2001/06/29 13:35:07  oes
50  *    - Adapted
51  *    - Improved comments
52  *    - Removed init_proxy_args
53  *    - Renamed end_proxy_args(csp) to show_rcs(void)
54  *    - Removed logentry from cancelled commit
55  *    - Destroyed support for ndef SPLIT_PROXY_ARGS (Ooops)
56  *    - Separated the #define list into show_defines()
57  *
58  *    Revision 1.15  2001/06/09 10:55:28  jongfoster
59  *    Changing BUFSIZ ==> BUFFER_SIZE
60  *
61  *    Revision 1.14  2001/06/07 23:15:40  jongfoster
62  *    Removing config->proxy_args_gateways
63  *    Missing return statement added to end_proxy_args().
64  *
65  *    Revision 1.13  2001/06/06 09:37:59  sarantis
66  *    Fix misplaced comment start.
67  *
68  *    Revision 1.12  2001/06/04 10:41:52  swa
69  *    show version string of cgi.h and cgi.c
70  *
71  *    Revision 1.11  2001/06/03 11:03:48  oes
72  *    moved stuff to cgi.c
73  *
74  *    Revision 1.10  2001/05/31 21:36:07  jongfoster
75  *    Added RCS for actions.[ch] and list.[ch]
76  *
77  *    Revision 1.9  2001/05/29 23:11:38  oes
78  *
79  *     - Moved strsav() from showargs to miscutil
80  *
81  *    Revision 1.8  2001/05/29 09:50:24  jongfoster
82  *    Unified blocklist/imagelist/permissionslist.
83  *    File format is still under discussion, but the internal changes
84  *    are (mostly) done.
85  *
86  *    Also modified interceptor behaviour:
87  *    - We now intercept all URLs beginning with one of the following
88  *      prefixes (and *only* these prefixes):
89  *        * http://i.j.b/
90  *        * http://ijbswa.sf.net/config/
91  *        * http://ijbswa.sourceforge.net/config/
92  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
93  *    - Internal changes so that intercepted and fast redirect pages
94  *      are not replaced with an image.
95  *    - Interceptors now have the option to send a binary page direct
96  *      to the client. (i.e. ijb-send-banner uses this)
97  *    - Implemented show-url-info interceptor.  (Which is why I needed
98  *      the above interceptors changes - a typical URL is
99  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
100  *      The previous mechanism would not have intercepted that, and
101  *      if it had been intercepted then it then it would have replaced
102  *      it with an image.)
103  *
104  *    Revision 1.7  2001/05/26 00:28:36  jongfoster
105  *    Automatic reloading of config file.
106  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
107  *    Most of the global variables have been moved to a new
108  *    struct configuration_spec, accessed through csp->config->globalname
109  *    Most of the globals remaining are used by the Win32 GUI.
110  *
111  *    Revision 1.6  2001/05/25 22:32:56  jongfoster
112  *    CRLF->LF
113  *
114  *    Revision 1.5  2001/05/22 18:54:49  oes
115  *
116  *    - Enabled filtering banners by size rather than URL
117  *      by adding patterns that replace all standard banner
118  *      sizes with the "Junkbuster" gif to the re_filterfile
119  *
120  *    - Enabled filtering WebBugs by providing a pattern
121  *      which kills all 1x1 images
122  *
123  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
124  *      which is selected by the (nonstandard and therefore
125  *      capital) letter 'U' in the option string.
126  *      It causes the quantifiers to be ungreedy by default.
127  *      Appending a ? turns back to greedy (!).
128  *
129  *    - Added a new interceptor ijb-send-banner, which
130  *      sends back the "Junkbuster" gif. Without imagelist or
131  *      MSIE detection support, or if tinygif = 1, or the
132  *      URL isn't recognized as an imageurl, a lame HTML
133  *      explanation is sent instead.
134  *
135  *    - Added new feature, which permits blocking remote
136  *      script redirects and firing back a local redirect
137  *      to the browser.
138  *      The feature is conditionally compiled, i.e. it
139  *      can be disabled with --disable-fast-redirects,
140  *      plus it must be activated by a "fast-redirects"
141  *      line in the config file, has its own log level
142  *      and of course wants to be displayed by show-proxy-args
143  *      Note: Boy, all the #ifdefs in 1001 locations and
144  *      all the fumbling with configure.in and acconfig.h
145  *      were *way* more work than the feature itself :-(
146  *
147  *    - Because a generic redirect template was needed for
148  *      this, tinygif = 3 now uses the same.
149  *
150  *    - Moved GIFs, and other static HTTP response templates
151  *      to project.h
152  *
153  *    - Some minor fixes
154  *
155  *    - Removed some >400 CRs again (Jon, you really worked
156  *      a lot! ;-)
157  *
158  *    Revision 1.4  2001/05/20 16:44:47  jongfoster
159  *    Removing last hardcoded JunkBusters.com URLs.
160  *
161  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
162  *    Version 2.9.4 checkin.
163  *    - Merged popupfile and cookiefile, and added control over PCRS
164  *      filtering, in new "permissionsfile".
165  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
166  *      file error you now get a message box (in the Win32 GUI) rather
167  *      than the program exiting with no explanation.
168  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
169  *      skipping.
170  *    - Removed tabs from "config"
171  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
172  *    - Bumped up version number.
173  *
174  *    Revision 1.2  2001/05/17 23:01:01  oes
175  *     - Cleaned CRLF's from the sources and related files
176  *
177  *    Revision 1.1.1.1  2001/05/15 13:59:03  oes
178  *    Initial import of version 2.9.3 source tree
179  *
180  *
181  *********************************************************************/
182 \f
183 #include "config.h"
184
185 #include <stdio.h>
186 #include <stdlib.h>
187 #include <sys/types.h>
188 #include <string.h>
189 #include <malloc.h>
190 #include <errno.h>
191
192 #include "project.h"
193 #include "showargs.h"
194 #include "jcc.h"
195 #include "encode.h"
196 #include "parsers.h"
197 #include "errlog.h"
198 #include "miscutil.h"
199 #include "gateway.h"
200
201 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
202
203
204 /*********************************************************************
205  *
206  * Function    :  savearg
207  *
208  * Description :  Called from `load_config'.  It saves each non-empty
209  *                and non-comment line from config into a list.  This
210  *                list is used to create the show-proxy-args page.
211  *
212  * Parameters  :
213  *          1  :  c = config setting that was found
214  *          2  :  o = the setting's argument (if any)
215  *
216  * Returns     :  N/A
217  *
218  *********************************************************************/
219 void savearg(char *c, char *o, struct configuration_spec * config)
220 {
221    char buf[BUFFER_SIZE];
222
223    *buf = '\0';
224
225    if ( ( NULL != c ) && ( '\0' != *c ) )
226    {
227       if ((c = html_encode(c)))
228       {
229          sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
230       }
231       freez(c);
232    }
233    if ( ( NULL != o ) && ( '\0' != *o ) )
234    {
235       if ((o = html_encode(o)))
236       {
237          if (strncmpic(o, "http://", 7) == 0)
238          {
239             strcat(buf, "<a href=\"");
240             strcat(buf, o);
241             strcat(buf, "\">");
242             strcat(buf, o);
243             strcat(buf, "</a>");
244          }
245          else
246          {
247             strcat(buf, o);
248          }
249       }
250       freez(o);
251    }
252
253    strcat(buf, "<br>\n");
254
255    config->proxy_args = strsav(config->proxy_args, buf);
256
257 }
258
259
260 /*********************************************************************
261  *
262  * Function    :  show_rcs
263  *
264  * Description :  Create a string with the rcs info for all sourcefiles
265  *
266  * Parameters  :  None
267  *
268  * Returns     :  string 
269  *
270  *********************************************************************/
271 char *show_rcs(void)
272 {
273    char *b = NULL;
274    char buf[BUFFER_SIZE];
275
276    /* Instead of including *all* dot h's in the project (thus creating a
277     * tremendous amount of dependencies), I will concede to declaring them
278     * as extern's.  This forces the developer to add to this list, but oh well.
279     */
280
281 #define SHOW_RCS(__x)            \
282    {                             \
283       extern const char __x[];   \
284       sprintf(buf, "%s\n", __x); \
285       b = strsav(b, buf);        \
286    }
287
288    /* In alphabetical order */
289    SHOW_RCS(actions_h_rcs)
290    SHOW_RCS(actions_rcs)
291    SHOW_RCS(cgi_h_rcs)
292    SHOW_RCS(cgi_rcs)
293 #ifdef __MINGW32__
294    SHOW_RCS(cygwin_h_rcs)
295 #endif
296    SHOW_RCS(deanimate_h_rcs)
297    SHOW_RCS(deanimate_rcs)
298    SHOW_RCS(encode_h_rcs)
299    SHOW_RCS(encode_rcs)
300    SHOW_RCS(errlog_h_rcs)
301    SHOW_RCS(errlog_rcs)
302    SHOW_RCS(filters_h_rcs)
303    SHOW_RCS(filters_rcs)
304    SHOW_RCS(gateway_h_rcs)
305    SHOW_RCS(gateway_rcs)
306 #ifdef GNU_REGEX
307    SHOW_RCS(gnu_regex_h_rcs)
308    SHOW_RCS(gnu_regex_rcs)
309 #endif /* def GNU_REGEX */
310    SHOW_RCS(jbsockets_h_rcs)
311    SHOW_RCS(jbsockets_rcs)
312    SHOW_RCS(jcc_h_rcs)
313    SHOW_RCS(jcc_rcs)
314 #ifdef KILLPOPUPS
315    SHOW_RCS(killpopup_h_rcs)
316    SHOW_RCS(killpopup_rcs)
317 #endif /* def KILLPOPUPS */
318    SHOW_RCS(list_h_rcs)
319    SHOW_RCS(list_rcs)
320    SHOW_RCS(loadcfg_h_rcs)
321    SHOW_RCS(loadcfg_rcs)
322    SHOW_RCS(loaders_h_rcs)
323    SHOW_RCS(loaders_rcs)
324    SHOW_RCS(miscutil_h_rcs)
325    SHOW_RCS(miscutil_rcs)
326    SHOW_RCS(parsers_h_rcs)
327    SHOW_RCS(parsers_rcs)
328    SHOW_RCS(pcrs_rcs)
329    SHOW_RCS(pcrs_h_rcs)
330    SHOW_RCS(project_h_rcs)
331    SHOW_RCS(showargs_h_rcs)
332    SHOW_RCS(showargs_rcs)
333    SHOW_RCS(ssplit_h_rcs)
334    SHOW_RCS(ssplit_rcs)
335 #ifdef _WIN32
336 #ifndef _WIN_CONSOLE
337    SHOW_RCS(w32log_h_rcs)
338    SHOW_RCS(w32log_rcs)
339    SHOW_RCS(w32res_h_rcs)
340    SHOW_RCS(w32rulesdlg_h_rcs)
341    SHOW_RCS(w32rulesdlg_rcs)
342    SHOW_RCS(w32taskbar_h_rcs)
343    SHOW_RCS(w32taskbar_rcs)
344 #endif /* ndef _WIN_CONSOLE */
345    SHOW_RCS(win32_h_rcs)
346    SHOW_RCS(win32_rcs)
347 #endif /* def _WIN32 */
348
349 #undef SHOW_RCS
350
351    return(b);
352 }
353
354 /*********************************************************************
355  *
356  * Function    :  show_defines
357  *
358  * Description :  Create a string with all conditional #defines used
359  *                when building
360  *
361  * Parameters  :  None
362  *
363  * Returns     :  string 
364  *
365  *********************************************************************/
366 char *show_defines(void)
367 {
368    char *b = NULL;
369
370 #ifdef FEATURE_PTHREAD
371    b = strsav(b, "  <li><code>#define <b>FEATURE_PTHREAD</b></code> - Support POSIX threads.</li>\n");
372 #else
373    b = strsav(b, "  <li><code>#undef <b>FEATURE_PTHREAD</b></code> - No support POSIX threads.</li>\n");
374 #endif
375
376 #ifdef REGEX_GNU
377    b = strsav(b, "  <li><code>#define <b>REGEX_GNU</b></code> - Support for GNU style regular expressions in the path specs.</li>\n");
378 #endif /* def REGEX_GNU */
379
380 #ifdef REGEX_PCRE
381    b = strsav(b, "  <li><code>#define <b>REGEX_PCRE</b></code> - Support for pcre style regular expressions in the path specs.</li>\n");
382 #endif /* def REGEX_PCRE */
383
384 #ifndef REGEX
385    b = strsav(b, "  <li><code>#undef <b>REGEX</b></code> - No support for regular expressions in the path specs.</li>\n");
386 #endif /* ndef REGEX */
387
388 #ifdef STATIC_PCRE
389    b = strsav(b, "  <li><code>#define <b>STATIC_PCRE</b></code> - Using static built-in pcre rather than libpcre.</li>\n");
390 #else /* ifndef STATIC_PCRE */
391    b = strsav(b, "  <li><code>#undef <b>STATIC_PCRE</b></code> - Using libpcre rather than static built-in pcre.</li>\n");
392 #endif /* ndef STATIC_PCRE */
393
394 #ifdef STATIC_PCRS
395    b = strsav(b, "  <li><code>#define <b>STATIC_PCRS</b></code> - Using static built-in pcrs rather than libpcrs.</li>\n");
396 #else /* ifndef STATIC_PCRS */
397    b = strsav(b, "  <li><code>#undef <b>STATIC_PCRS</b></code> - Using libpcrs rather than static built-in pcrs.</li>\n");
398 #endif /* ndef STATIC_PCRS */
399
400 #ifdef TOGGLE
401    b = strsav(b, "  <li><code>#define <b>TOGGLE</b></code> - Allow JunkBuster to be \"disabled\" so it is just a normal non-blocking non-anonymizing proxy.</li>\n");
402 #else /* ifndef TOGGLE */
403    b = strsav(b, "  <li><code>#undef <b>TOGGLE</b></code> - Do not allow JunkBuster to be \"disabled\" so it is just a normal non-blocking non-anonymizing proxy.</li>\n");
404 #endif /* ndef TOGGLE */
405
406 #ifdef FORCE_LOAD
407    b = strsav(b, "  <li><code>#define <b>FORCE_LOAD</b></code> - Enables bypassing filtering for a single page using the prefix \"" FORCE_PREFIX "\".</li>\n");
408 #else /* ifndef FORCE_LOAD */
409    b = strsav(b, "  <li><code>#undef <b>FORCE_LOAD</b></code> - Disables bypassing filtering for a single page.</li>\n");
410 #endif /* ndef FORCE_LOAD */
411
412 #ifdef DENY_GZIP
413    b = strsav(b, "  <li><code>#define <b>DENY_GZIP</b></code> - Prevents requests from being compressed - required for PCRS on some sites.</li>\n");
414 #else /* ifndef DENY_GZIP */
415    b = strsav(b, "  <li><code>#undef <b>DENY_GZIP</b></code> - Allows requests to be compressed if the browser and server support it.</li>\n");
416 #endif /* ndef DENY_GZIP */
417
418 #ifdef STATISTICS
419    b = strsav(b, "  <li><code>#define <b>STATISTICS</b></code> - Enables statistics function.</li>\n");
420 #else /* ifndef STATISTICS */
421    b = strsav(b, "  <li><code>#undef <b>STATISTICS</b></code> - Disables statistics function.</li>\n");
422 #endif /* ndef STATISTICS */
423
424 #ifdef SPLIT_PROXY_ARGS
425    b = strsav(b, "  <li><code>#define <b>SPLIT_PROXY_ARGS</b></code> - Split this page up by placing the configuration files on separate pages.</li>\n");
426 #else /* ifndef SPLIT_PROXY_ARGS */
427    b = strsav(b, "  <li><code>#undef <b>SPLIT_PROXY_ARGS</b></code> - This page contains the text of the configuration files, they are not split onto separate pages.</li>\n");
428 #endif /* ndef SPLIT_PROXY_ARGS */
429
430 #ifdef KILLPOPUPS
431    b = strsav(b, "  <li><code>#define <b>KILLPOPUPS</b></code> - Enables killing JavaScript popups.</li>\n");
432 #else /* ifndef KILLPOPUPS */
433    b = strsav(b, "  <li><code>#undef <b>KILLPOPUPS</b></code> - Disables killing JavaScript popups.</li>\n");
434 #endif /* ndef KILLPOPUPS */
435
436 #ifdef WEBDAV
437    b = strsav(b, "  <li><code>#define <b>WEBDAV</b></code> - Enables support for webDAV - e.g. stops Microsoft Outlook from accessing HotMail e-mail.</li>\n");
438 #else /* ifndef WEBDAV */
439    b = strsav(b, "  <li><code>#undef <b>WEBDAV</b></code> - Disables support for webDAV - e.g. so Microsoft Outlook can access HotMail e-mail.</li>\n");
440 #endif /* ndef WEBDAV */
441
442 #ifdef DETECT_MSIE_IMAGES
443    b = strsav(b, "  <li><code>#define <b>DETECT_MSIE_IMAGES</b></code> - Enables detecting image requests automatically for MSIE.</li>\n");
444 #else /* ifndef DETECT_MSIE_IMAGES */
445    b = strsav(b, "  <li><code>#undef <b>DETECT_MSIE_IMAGES</b></code> - Disables detecting image requests automatically for MSIE.</li>\n");
446 #endif /* ndef DETECT_MSIE_IMAGES */
447
448 #ifdef IMAGE_BLOCKING
449    b = strsav(b, "  <li><code>#define <b>IMAGE_BLOCKING</b></code> - Enables sending \"blocked\" images instead of HTML.</li>\n");
450 #else /* ifndef IMAGE_BLOCKING */
451    b = strsav(b, "  <li><code>#undef <b>IMAGE_BLOCKING</b></code> - Disables sending \"blocked\" images instead of HTML.</li>\n");
452 #endif /* ndef IMAGE_BLOCKING */
453
454 #ifdef ACL_FILES
455    b = strsav(b, "  <li><code>#define <b>ACL_FILES</b></code> - Enables the use of ACL files to control access to the proxy by IP address.</li>\n");
456 #else /* ifndef ACL_FILES */
457    b = strsav(b, "  <li><code>#undef <b>ACL_FILES</b></code> - Disables the use of ACL files to control access to the proxy by IP address.</li>\n");
458 #endif /* ndef ACL_FILES */
459
460 #ifdef TRUST_FILES
461    b = strsav(b, "  <li><code>#define <b>TRUST_FILES</b></code> - Enables the use of trust files.</li>\n");
462 #else /* ifndef TRUST_FILES */
463    b = strsav(b, "  <li><code>#undef <b>TRUST_FILES</b></code> - Disables the use of trust files.</li>\n");
464 #endif /* ndef TRUST_FILES */
465
466 #ifdef JAR_FILES
467    b = strsav(b, "  <li><code>#define <b>JAR_FILES</b></code> - Enables the use of jar files to capture cookies.</li>\n");
468 #else /* ifndef JAR_FILES */
469    b = strsav(b, "  <li><code>#undef <b>JAR_FILES</b></code> - Disables the use of jar files to capture cookies.</li>\n");
470 #endif /* ndef JAR_FILES */
471
472 #ifdef FAST_REDIRECTS
473    b = strsav(b, "  <li><code>#define <b>FAST_REDIRECTS</b></code> - Enables intercepting remote script redirects.</li>\n");
474 #else /* ifndef FAST_REDIRECTS */
475    b = strsav(b, "  <li><code>#undef <b>FAST_REDIRECTS</b></code> - Disables intercepting remote script redirects.</li>\n");
476 #endif /* ndef FAST_REDIRECTS */
477
478    return b;
479 }
480
481
482 /*
483   Local Variables:
484   tab-width: 3
485   end:
486 */