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