- Added FEATURE_GRACEFUL_TERMINATION to the
[privoxy.git] / cgisimple.c
1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.42 2006/11/21 15:43:12 fabiankeil Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
5  *
6  * Purpose     :  Simple CGIs to get information about Privoxy's
7  *                status.
8  *                
9  *                Functions declared include:
10  * 
11  *
12  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
13  *                Privoxy team. http://www.privoxy.org/
14  *
15  *                Based on the Internet Junkbuster originally written
16  *                by and Copyright (C) 1997 Anonymous Coders and 
17  *                Junkbusters Corporation.  http://www.junkbusters.com
18  *
19  *                This program is free software; you can redistribute it 
20  *                and/or modify it under the terms of the GNU General
21  *                Public License as published by the Free Software
22  *                Foundation; either version 2 of the License, or (at
23  *                your option) any later version.
24  *
25  *                This program is distributed in the hope that it will
26  *                be useful, but WITHOUT ANY WARRANTY; without even the
27  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
28  *                PARTICULAR PURPOSE.  See the GNU General Public
29  *                License for more details.
30  *
31  *                The GNU General Public License should be included with
32  *                this file.  If not, you can view it at
33  *                http://www.gnu.org/copyleft/gpl.html
34  *                or write to the Free Software Foundation, Inc., 59
35  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
36  *
37  * Revisions   :
38  *    $Log: cgisimple.c,v $
39  *    Revision 1.42  2006/11/21 15:43:12  fabiankeil
40  *    Add special treatment for WIN32 to make sure
41  *    cgi_send_user_manual opens the files in binary mode.
42  *    Fixes BR 1600411 and unbreaks image delivery.
43  *
44  *    Remove outdated comment.
45  *
46  *    Revision 1.41  2006/10/09 19:18:28  roro
47  *    Redirect http://p.p/user-manual (without trailing slash) to
48  *    http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
49  *
50  *    Revision 1.40  2006/09/09 13:05:33  fabiankeil
51  *    Modified cgi_send_user_manual to serve binary
52  *    content without destroying it first. Should also be
53  *    faster now. Added ".jpg" check for Content-Type guessing.
54  *
55  *    Revision 1.39  2006/09/08 09:49:23  fabiankeil
56  *    Deliver documents in the user-manual directory
57  *    with "Content-Type text/css" if their filename
58  *    ends with ".css".
59  *
60  *    Revision 1.38  2006/09/06 18:45:03  fabiankeil
61  *    Incorporate modified version of Roland Rosenfeld's patch to
62  *    optionally access the user-manual via Privoxy. Closes patch 679075.
63  *
64  *    Formatting changed to Privoxy style, added call to
65  *    cgi_error_no_template if the requested file doesn't
66  *    exist and modified check whether or not Privoxy itself
67  *    should serve the manual. Should work cross-platform now.
68  *
69  *    Revision 1.37  2006/07/18 14:48:45  david__schmidt
70  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
71  *    with what was really the latest development (the v_3_0_branch branch)
72  *
73  *    Revision 1.35.2.7  2006/01/29 23:10:56  david__schmidt
74  *    Multiple filter file support
75  *
76  *    Revision 1.35.2.6  2005/07/04 03:13:43  david__schmidt
77  *    Undo some damaging memory leak patches
78  *
79  *    Revision 1.35.2.5  2005/05/07 21:50:55  david__schmidt
80  *    A few memory leaks plugged (mostly on error paths)
81  *
82  *    Revision 1.35.2.4  2005/04/04 02:21:24  david__schmidt
83  *    Another instance of:
84  *    Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
85  *    Thanks to Magnus Holmgren for the patch
86  *
87  *    Revision 1.35.2.3  2003/12/17 16:34:15  oes
88  *     - Prevent line wrap beween "View/Edit" link buttons on status page
89  *     - Some (mostly irrelevant) fixes for Out-of-mem-case handling
90  *
91  *    Revision 1.35.2.2  2003/04/03 13:48:28  oes
92  *    Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
93  *
94  *    Revision 1.35.2.1  2002/07/04 15:02:38  oes
95  *    Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
96  *
97  *    Revision 1.35.2.1  2002/07/01 17:32:04  morcego
98  *    Applying patch from Andreas as provided by Hal on the list.
99  *    Message-ID: <20020701121218.V1606@feenix.burgiss.net>
100  *
101  *    Revision 1.35  2002/05/12 21:44:44  jongfoster
102  *    Adding amiga.[ch] revision information, if on an amiga.
103  *
104  *    Revision 1.34  2002/04/30 12:06:12  oes
105  *    Deleted unused code from default_cgi
106  *
107  *    Revision 1.33  2002/04/30 11:14:52  oes
108  *    Made csp the first parameter in *action_to_html
109  *
110  *    Revision 1.32  2002/04/26 18:29:13  jongfoster
111  *    Fixing this Visual C++ warning:
112  *    cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
113  *
114  *    Revision 1.31  2002/04/26 12:54:36  oes
115  *     - Kill obsolete REDIRECT_URL code
116  *     - Error handling fixes
117  *     - Style sheet related HTML snipplet changes
118  *     - cgi_show_url_info:
119  *       - Matches now in table, actions on single lines,
120  *         linked to help
121  *       - standard.action suppressed
122  *       - Buttons to View and Edit AFs
123  *
124  *    Revision 1.30  2002/04/24 02:18:08  oes
125  *     - show-status is now the starting point for editing
126  *       the actions files, generate list of all AFs with buttons
127  *       for viewing and editing, new look for file list (Jon:
128  *       buttons now aligned ;-P ), view mode now supports multiple
129  *       AFs, name changes, no view links for unspecified files,
130  *       no edit link for standard.action.
131  *
132  *     - Jon's multiple AF patch: cgi_show_url_info now uses all
133  *       AFs and marks the output accordingly
134  *
135  *    Revision 1.29  2002/04/10 13:38:35  oes
136  *    load_template signature changed
137  *
138  *    Revision 1.28  2002/04/07 15:42:12  jongfoster
139  *    Fixing send-banner?type=auto when the image-blocker is
140  *    a redirect to send-banner
141  *
142  *    Revision 1.27  2002/04/05 15:50:48  oes
143  *    added send-stylesheet CGI
144  *
145  *    Revision 1.26  2002/04/04 00:36:36  gliptak
146  *    always use pcre for matching
147  *
148  *    Revision 1.25  2002/04/03 22:28:03  gliptak
149  *    Removed references to gnu_regex
150  *
151  *    Revision 1.24  2002/04/02 16:12:47  oes
152  *    Fix: moving misplaced lines into #ifdef FEATURE_FORCE
153  *
154  *    Revision 1.23  2002/03/26 22:29:54  swa
155  *    we have a new homepage!
156  *
157  *    Revision 1.22  2002/03/24 16:18:15  jongfoster
158  *    Removing old logo
159  *
160  *    Revision 1.21  2002/03/24 15:23:33  jongfoster
161  *    Name changes
162  *
163  *    Revision 1.20  2002/03/24 13:25:43  swa
164  *    name change related issues
165  *
166  *    Revision 1.19  2002/03/16 23:54:06  jongfoster
167  *    Adding graceful termination feature, to help look for memory leaks.
168  *    If you enable this (which, by design, has to be done by hand
169  *    editing config.h) and then go to http://i.j.b/die, then the program
170  *    will exit cleanly after the *next* request.  It should free all the
171  *    memory that was used.
172  *
173  *    Revision 1.18  2002/03/12 01:44:49  oes
174  *    Changed default for "blocked" image from jb logo to checkboard pattern
175  *
176  *    Revision 1.17  2002/03/08 16:43:18  oes
177  *    Added choice beween GIF and PNG built-in images
178  *
179  *    Revision 1.16  2002/03/07 03:48:38  oes
180  *     - Changed built-in images from GIF to PNG
181  *       (with regard to Unisys patent issue)
182  *     - Added a 4x4 pattern PNG which is less intrusive
183  *       than the logo but also clearly marks the deleted banners
184  *
185  *    Revision 1.15  2002/03/06 22:54:35  jongfoster
186  *    Automated function-comment nitpicking.
187  *
188  *    Revision 1.14  2002/03/02 04:14:50  david__schmidt
189  *    Clean up a little CRLF unpleasantness that suddenly appeared
190  *
191  *    Revision 1.13  2002/02/21 00:10:37  jongfoster
192  *    Adding send-banner?type=auto option
193  *
194  *    Revision 1.12  2002/01/23 01:03:32  jongfoster
195  *    Fixing gcc [CygWin] compiler warnings
196  *
197  *    Revision 1.11  2002/01/23 00:01:04  jongfoster
198  *    Adding cgi_transparent_gif() for http://i.j.b/t
199  *    Adding missing html_encode() to many CGI functions.
200  *    Adding urlmatch.[ch] to http://i.j.b/show-version
201  *
202  *    Revision 1.10  2002/01/17 21:10:37  jongfoster
203  *    Changes to cgi_show_url_info to use new matching code from urlmatch.c.
204  *    Also fixing a problem in the same function with improperly quoted URLs
205  *    in output HTML, and adding code to handle https:// URLs correctly.
206  *
207  *    Revision 1.9  2001/11/30 23:09:15  jongfoster
208  *    Now reports on FEATURE_CGI_EDIT_ACTIONS
209  *    Removing FEATURE_DENY_GZIP from template
210  *
211  *    Revision 1.8  2001/11/13 00:14:07  jongfoster
212  *    Fixing stupid bug now I've figured out what || means.
213  *    (It always returns 0 or 1, not one of it's paramaters.)
214  *
215  *    Revision 1.7  2001/10/23 21:48:19  jongfoster
216  *    Cleaning up error handling in CGI functions - they now send back
217  *    a HTML error page and should never cause a FATAL error.  (Fixes one
218  *    potential source of "denial of service" attacks).
219  *
220  *    CGI actions file editor that works and is actually useful.
221  *
222  *    Ability to toggle JunkBuster remotely using a CGI call.
223  *
224  *    You can turn off both the above features in the main configuration
225  *    file, e.g. if you are running a multi-user proxy.
226  *
227  *    Revision 1.6  2001/10/14 22:00:32  jongfoster
228  *    Adding support for a 404 error when an invalid CGI page is requested.
229  *
230  *    Revision 1.5  2001/10/07 15:30:41  oes
231  *    Removed FEATURE_DENY_GZIP
232  *
233  *    Revision 1.4  2001/10/02 15:31:12  oes
234  *    Introduced show-request cgi
235  *
236  *    Revision 1.3  2001/09/22 16:34:44  jongfoster
237  *    Removing unneeded #includes
238  *
239  *    Revision 1.2  2001/09/19 18:01:11  oes
240  *    Fixed comments; cosmetics
241  *
242  *    Revision 1.1  2001/09/16 17:08:54  jongfoster
243  *    Moving simple CGI functions from cgi.c to new file cgisimple.c
244  *
245  *
246  **********************************************************************/
247 \f
248
249 #include "config.h"
250
251 #include <stdio.h>
252 #include <sys/types.h>
253 #include <stdlib.h>
254 #include <ctype.h>
255 #include <string.h>
256 #include <assert.h>
257
258 #ifdef _WIN32
259 #define snprintf _snprintf
260 #endif /* def _WIN32 */
261
262 #include "project.h"
263 #include "cgi.h"
264 #include "cgisimple.h"
265 #include "list.h"
266 #include "encode.h"
267 #include "jcc.h"
268 #include "filters.h"
269 #include "actions.h"
270 #include "miscutil.h"
271 #include "loadcfg.h"
272 #include "parsers.h"
273 #include "urlmatch.h"
274 #include "errlog.h"
275
276 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
277
278
279 static char *show_rcs(void);
280 static jb_err show_defines(struct map *exports);
281
282
283 /*********************************************************************
284  *
285  * Function    :  cgi_default
286  *
287  * Description :  CGI function that is called for the CGI_SITE_1_HOST
288  *                and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
289  *                Boring - only exports the default exports.
290  *               
291  * Parameters  :
292  *          1  :  csp = Current client state (buffers, headers, etc...)
293  *          2  :  rsp = http_response data structure for output
294  *          3  :  parameters = map of cgi parameters
295  *
296  * CGI Parameters : none
297  *
298  * Returns     :  JB_ERR_OK on success
299  *                JB_ERR_MEMORY on out-of-memory
300  *
301  *********************************************************************/
302 jb_err cgi_default(struct client_state *csp,
303                    struct http_response *rsp,
304                    const struct map *parameters)
305 {
306    struct map *exports;
307
308    assert(csp);
309    assert(rsp);
310
311    if (NULL == (exports = default_exports(csp, "")))
312    {
313       return JB_ERR_MEMORY;
314    }
315
316    return template_fill_for_cgi(csp, "default", exports, rsp);
317 }
318
319
320 /*********************************************************************
321  *
322  * Function    :  cgi_error_404
323  *
324  * Description :  CGI function that is called if an unknown action was
325  *                given.
326  *               
327  * Parameters  :
328  *          1  :  csp = Current client state (buffers, headers, etc...)
329  *          2  :  rsp = http_response data structure for output
330  *          3  :  parameters = map of cgi parameters
331  *
332  * CGI Parameters : none
333  *
334  * Returns     :  JB_ERR_OK on success
335  *                JB_ERR_MEMORY on out-of-memory error.  
336  *
337  *********************************************************************/
338 jb_err cgi_error_404(struct client_state *csp,
339                      struct http_response *rsp,
340                      const struct map *parameters)
341 {
342    struct map *exports;
343
344    assert(csp);
345    assert(rsp);
346    assert(parameters);
347
348    if (NULL == (exports = default_exports(csp, NULL)))
349    {
350       return JB_ERR_MEMORY;
351    }
352
353    rsp->status = strdup("404 Privoxy configuration page not found");
354    if (rsp->status == NULL)
355    {
356       free_map(exports);
357       return JB_ERR_MEMORY;
358    }
359
360    return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
361 }
362
363
364 #ifdef FEATURE_GRACEFUL_TERMINATION
365 /*********************************************************************
366  *
367  * Function    :  cgi_die
368  *
369  * Description :  CGI function to shut down Privoxy.
370  *                NOTE: Turning this on in a production build
371  *                would be a BAD idea.  An EXTREMELY BAD idea.
372  *                In short, don't do it.
373  *               
374  * Parameters  :
375  *          1  :  csp = Current client state (buffers, headers, etc...)
376  *          2  :  rsp = http_response data structure for output
377  *          3  :  parameters = map of cgi parameters
378  *
379  * CGI Parameters : none
380  *
381  * Returns     :  JB_ERR_OK on success
382  *                JB_ERR_MEMORY on out-of-memory error.  
383  *
384  *********************************************************************/
385 jb_err cgi_die (struct client_state *csp,
386                 struct http_response *rsp,
387                 const struct map *parameters)
388 {
389    assert(csp);
390    assert(rsp);
391    assert(parameters);
392
393    /* quit */
394    g_terminate = 1;
395
396    /*
397     * I don't really care what gets sent back to the browser.
398     * Take the easy option - "out of memory" page.
399     */
400
401    return JB_ERR_MEMORY;
402 }
403 #endif /* def FEATURE_GRACEFUL_TERMINATION */
404
405
406 /*********************************************************************
407  *
408  * Function    :  cgi_show_request
409  *
410  * Description :  Show the client's request and what sed() would have
411  *                made of it.
412  *               
413  * Parameters  :
414  *          1  :  csp = Current client state (buffers, headers, etc...)
415  *          2  :  rsp = http_response data structure for output
416  *          3  :  parameters = map of cgi parameters
417  *
418  * CGI Parameters : none
419  *
420  * Returns     :  JB_ERR_OK on success
421  *                JB_ERR_MEMORY on out-of-memory error.  
422  *
423  *********************************************************************/
424 jb_err cgi_show_request(struct client_state *csp,
425                         struct http_response *rsp,
426                         const struct map *parameters)
427 {
428    char *p;
429    struct map *exports;
430
431    assert(csp);
432    assert(rsp);
433    assert(parameters);
434
435    if (NULL == (exports = default_exports(csp, "show-request")))
436    {
437       return JB_ERR_MEMORY;
438    }
439    
440    /*
441     * Repair the damage done to the IOB by get_header()
442     */
443    for (p = csp->iob->buf; p < csp->iob->eod; p++)
444    {
445       if (*p == '\0') *p = '\n';
446    }
447
448    /*
449     * Export the original client's request and the one we would
450     * be sending to the server if this wasn't a CGI call
451     */
452
453    if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
454    {
455       free_map(exports);
456       return JB_ERR_MEMORY;
457    }
458
459    if (map(exports, "processed-request", 1, html_encode_and_free_original(
460       sed(client_patterns, add_client_headers, csp)), 0))
461    {
462       free_map(exports);
463       return JB_ERR_MEMORY;
464    }
465
466    return template_fill_for_cgi(csp, "show-request", exports, rsp);
467 }
468
469
470 /*********************************************************************
471  *
472  * Function    :  cgi_send_banner
473  *
474  * Description :  CGI function that returns a banner. 
475  *
476  * Parameters  :
477  *          1  :  csp = Current client state (buffers, headers, etc...)
478  *          2  :  rsp = http_response data structure for output
479  *          3  :  parameters = map of cgi parameters
480  *
481  * CGI Parameters :
482  *           type : Selects the type of banner between "trans", "logo",
483  *                  and "auto". Defaults to "logo" if absent or invalid.
484  *                  "auto" means to select as if we were image-blocking.
485  *                  (Only the first character really counts; b and t are
486  *                  equivalent).
487  *
488  * Returns     :  JB_ERR_OK on success
489  *                JB_ERR_MEMORY on out-of-memory error.  
490  *
491  *********************************************************************/
492 jb_err cgi_send_banner(struct client_state *csp,
493                        struct http_response *rsp,
494                        const struct map *parameters)
495 {
496    char imagetype = lookup(parameters, "type")[0];
497
498    /*
499     * If type is auto, then determine the right thing
500     * to do from the set-image-blocker action
501     */
502    if (imagetype == 'a') 
503    {
504       /*
505        * Default to pattern
506        */
507       imagetype = 'p';
508
509 #ifdef FEATURE_IMAGE_BLOCKING
510       if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
511       {
512          static const char prefix1[] = CGI_PREFIX "send-banner?type=";
513          static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
514          const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
515
516          if (p == NULL)
517          {
518             /* Use default - nothing to do here. */
519          }
520          else if (0 == strcmpic(p, "blank"))
521          {
522             imagetype = 'b';
523          }
524          else if (0 == strcmpic(p, "pattern"))
525          {
526             imagetype = 'p';
527          }
528
529          /*
530           * If the action is to call this CGI, determine
531           * the argument:
532           */
533          else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
534          {
535             imagetype = p[sizeof(prefix1) - 1];
536          }
537          else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
538          {
539             imagetype = p[sizeof(prefix2) - 1];
540          }
541
542          /*
543           * Everything else must (should) be a URL to
544           * redirect to.
545           */
546          else
547          {
548             imagetype = 'r';
549          }
550       }
551 #endif /* def FEATURE_IMAGE_BLOCKING */
552    }
553       
554    /*
555     * Now imagetype is either the non-auto type we were called with,
556     * or it was auto and has since been determined. In any case, we
557     * can proceed to actually answering the request by sending a redirect
558     * or an image as appropriate:
559     */
560    if (imagetype == 'r') 
561    {
562       rsp->status = strdup("302 Local Redirect from Privoxy");
563       if (rsp->status == NULL)
564       {
565          return JB_ERR_MEMORY;
566       }
567       if (enlist_unique_header(rsp->headers, "Location",
568                                csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
569       {
570          return JB_ERR_MEMORY;
571       }
572    }
573    else
574    {
575       if ((imagetype == 'b') || (imagetype == 't')) 
576       {
577          rsp->body = bindup(image_blank_data, image_blank_length);
578          rsp->content_length = image_blank_length;
579       }
580       else
581       {
582          rsp->body = bindup(image_pattern_data, image_pattern_length);
583          rsp->content_length = image_pattern_length;
584       }
585
586       if (rsp->body == NULL)
587       {
588          return JB_ERR_MEMORY;
589       }
590       if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
591       {
592          return JB_ERR_MEMORY;
593       }
594
595       rsp->is_static = 1;
596    }
597
598    return JB_ERR_OK;
599
600 }
601
602
603 /*********************************************************************
604  *
605  * Function    :  cgi_transparent_image
606  *
607  * Description :  CGI function that sends a 1x1 transparent image.
608  *
609  * Parameters  :
610  *          1  :  csp = Current client state (buffers, headers, etc...)
611  *          2  :  rsp = http_response data structure for output
612  *          3  :  parameters = map of cgi parameters
613  *
614  * CGI Parameters : None
615  *
616  * Returns     :  JB_ERR_OK on success
617  *                JB_ERR_MEMORY on out-of-memory error.  
618  *
619  *********************************************************************/
620 jb_err cgi_transparent_image(struct client_state *csp,
621                              struct http_response *rsp,
622                              const struct map *parameters)
623 {
624    rsp->body = bindup(image_blank_data, image_blank_length);
625    rsp->content_length = image_blank_length;
626
627    if (rsp->body == NULL)
628    {
629       return JB_ERR_MEMORY;
630    }
631
632    if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
633    {
634       return JB_ERR_MEMORY;
635    }
636
637    rsp->is_static = 1;
638
639    return JB_ERR_OK;
640
641 }
642
643
644 /*********************************************************************
645  *
646  * Function    :  cgi_send_stylesheet
647  *
648  * Description :  CGI function that sends a css stylesheet found
649  *                in the cgi-style.css template
650  *
651  * Parameters  :
652  *          1  :  csp = Current client state (buffers, headers, etc...)
653  *          2  :  rsp = http_response data structure for output
654  *          3  :  parameters = map of cgi parameters
655  *
656  * CGI Parameters : None
657  *
658  * Returns     :  JB_ERR_OK on success
659  *                JB_ERR_MEMORY on out-of-memory error.  
660  *
661  *********************************************************************/
662 jb_err cgi_send_stylesheet(struct client_state *csp,
663                            struct http_response *rsp,
664                            const struct map *parameters)
665 {
666    jb_err err;
667    
668    assert(csp);
669    assert(rsp);
670
671    err = template_load(csp, &rsp->body, "cgi-style.css", 0);
672
673    if (err == JB_ERR_FILE)
674    {
675       /*
676        * No way to tell user; send empty stylesheet
677        */
678       log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
679    }
680    else if (err)
681    {
682       return err; /* JB_ERR_MEMORY */
683    }
684
685    if (enlist(rsp->headers, "Content-Type: text/css"))
686    {
687       return JB_ERR_MEMORY;
688    }
689
690    return JB_ERR_OK;
691
692 }
693 /*********************************************************************
694  *
695  * Function    :  cgi_send_user_manual
696  *
697  * Description :  CGI function that sends a file in the user
698  *                manual directory.
699  *
700  * Parameters  :
701  *          1  :  csp = Current client state (buffers, headers, etc...)
702  *          2  :  rsp = http_response data structure for output
703  *          3  :  parameters = map of cgi parameters
704  *
705  * CGI Parameters : file=name.html, the name of the HTML file
706  *                  (relative to user-manual from config)
707  *
708  * Returns     :  JB_ERR_OK on success
709  *                JB_ERR_MEMORY on out-of-memory error.  
710  *
711  *********************************************************************/
712 jb_err cgi_send_user_manual(struct client_state *csp,
713                             struct http_response *rsp,
714                             const struct map *parameters)
715 {
716    const char * filename;
717    char *full_path;
718    FILE *fp;
719    jb_err err = JB_ERR_OK;
720    size_t length;
721
722    assert(csp);
723    assert(rsp);
724    assert(parameters);
725
726    if (!parameters->first)
727    {
728       /* requested http://p.p/user-manual (without trailing slash) */
729       return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
730    }
731
732    get_string_param(parameters, "file", &filename);
733    /* Check paramter for hack attempts */
734    if (filename && strchr(filename, '/'))
735    {
736       return JB_ERR_CGI_PARAMS;
737    }
738    if (filename && strstr(filename, ".."))
739    {
740       return JB_ERR_CGI_PARAMS;
741    }
742
743    full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
744    if (full_path == NULL)
745    {
746       return JB_ERR_MEMORY;
747    }
748
749    /* Open user-manual file */
750 #ifdef WIN32
751    /*
752     * XXX: Do we support other operating systems that
753     * require special treatment to fopen in binary mode?
754     */
755    if (NULL == (fp = fopen(full_path, "rb")))
756 #else
757    if (NULL == (fp = fopen(full_path, "r")))
758 #endif /* def WIN32 */
759    {
760       log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
761       err = cgi_error_no_template(csp, rsp, full_path);
762       free(full_path);
763       return err;
764    }
765
766    /* Get file length */
767    fseek(fp, 0, SEEK_END);
768    length = ftell(fp);
769    fseek(fp, 0, SEEK_SET);
770
771    /* Allocate memory and load the file directly into the body */
772    rsp->body = (char *)malloc(length+1);
773    if (!rsp->body)
774    {
775       fclose(fp);
776       free(full_path);
777       return JB_ERR_MEMORY;
778    }
779    if (!fread(rsp->body, length, 1, fp))
780    {
781       /*
782        * This happens if we didn't fopen in binary mode.
783        * If it does, we just log it and serve what we got,
784        * most likely padded with garbage.
785        */
786       log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
787    }
788    fclose(fp);
789    free(full_path);
790
791    rsp->content_length = (int)length;
792
793    /* Guess correct Content-Type based on the filename's ending */
794    if (filename)
795    {
796       length = strlen(filename);
797    }
798    else
799    {
800       length = 0;
801    } 
802    if((length>=4) && !strcmp(&filename[length-4], ".css"))
803    {
804       err = enlist(rsp->headers, "Content-Type: text/css");
805    }
806    else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
807    {
808       err = enlist(rsp->headers, "Content-Type: image/jpeg");
809    }
810    else
811    {
812       err = enlist(rsp->headers, "Content-Type: text/html");
813    }
814
815    return err;
816 }
817
818
819 /*********************************************************************
820  *
821  * Function    :  cgi_show_version
822  *
823  * Description :  CGI function that returns a a web page describing the
824  *                file versions of Privoxy.
825  *
826  * Parameters  :
827  *          1  :  csp = Current client state (buffers, headers, etc...)
828  *          2  :  rsp = http_response data structure for output
829  *          3  :  parameters = map of cgi parameters
830  *
831  * CGI Parameters : none
832  *
833  * Returns     :  JB_ERR_OK on success
834  *                JB_ERR_MEMORY on out-of-memory error.  
835  *
836  *********************************************************************/
837 jb_err cgi_show_version(struct client_state *csp,
838                         struct http_response *rsp,
839                         const struct map *parameters)
840 {
841    struct map *exports;
842
843    assert(csp);
844    assert(rsp);
845    assert(parameters);
846
847    if (NULL == (exports = default_exports(csp, "show-version")))
848    {
849       return JB_ERR_MEMORY;
850    }
851
852    if (map(exports, "sourceversions", 1, show_rcs(), 0))
853    {
854       free_map(exports);
855       return JB_ERR_MEMORY;
856    }
857
858    return template_fill_for_cgi(csp, "show-version", exports, rsp);
859 }
860
861  
862 /*********************************************************************
863  *
864  * Function    :  cgi_show_status
865  *
866  * Description :  CGI function that returns a a web page describing the
867  *                current status of Privoxy.
868  *
869  * Parameters  :
870  *          1  :  csp = Current client state (buffers, headers, etc...)
871  *          2  :  rsp = http_response data structure for output
872  *          3  :  parameters = map of cgi parameters
873  *
874  * CGI Parameters :
875  *        file :  Which file to show.  Only first letter is checked,
876  *                valid values are:
877  *                - "p"ermissions (actions) file
878  *                - "r"egex
879  *                - "t"rust
880  *                Default is to show menu and other information.
881  *
882  * Returns     :  JB_ERR_OK on success
883  *                JB_ERR_MEMORY on out-of-memory error.  
884  *
885  *********************************************************************/
886 jb_err cgi_show_status(struct client_state *csp,
887                        struct http_response *rsp,
888                        const struct map *parameters)
889 {
890    char *s = NULL;
891    unsigned i;
892    int j;
893
894    FILE * fp;
895    char buf[BUFFER_SIZE];
896    const char * filename = NULL;
897    char * file_description = NULL;
898 #ifdef FEATURE_STATISTICS
899    float perc_rej;   /* Percentage of http requests rejected */
900    int local_urls_read;
901    int local_urls_rejected;
902 #endif /* ndef FEATURE_STATISTICS */
903    struct file_list * fl;
904    struct url_actions * b;
905    jb_err err = JB_ERR_OK;
906
907    struct map *exports;
908
909    assert(csp);
910    assert(rsp);
911    assert(parameters);
912
913    if (NULL == (exports = default_exports(csp, "show-status")))
914    {
915       return JB_ERR_MEMORY;
916    }
917
918    switch (*(lookup(parameters, "file")))
919    {
920    case 'a':
921       if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
922       {
923          filename = csp->actions_list[i]->filename;
924          file_description = "Actions File";
925       }
926       break;
927
928    case 'f':
929       if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
930       {
931          filename = csp->rlist[i]->filename;
932          file_description = "Filter File";
933       }
934       break;
935
936 #ifdef FEATURE_TRUST
937    case 't':
938       if (csp->tlist)
939       {
940          filename = csp->tlist->filename;
941          file_description = "Trust File";
942       }
943       break;
944 #endif /* def FEATURE_TRUST */
945    }
946
947    if (NULL != filename)
948    {
949       if ( map(exports, "file-description", 1, file_description, 1)
950         || map(exports, "filepath", 1, html_encode(filename), 0) )
951       {
952          free_map(exports);
953          return JB_ERR_MEMORY;
954       }
955
956       if ((fp = fopen(filename, "r")) == NULL)
957       {
958          if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
959          {
960             free_map(exports);
961             return JB_ERR_MEMORY;
962          }
963       }
964       else
965       {
966          s = strdup("");
967          while ((s != NULL) && fgets(buf, sizeof(buf), fp))
968          {
969             string_join  (&s, html_encode(buf));
970          }
971          fclose(fp);
972
973          if (map(exports, "contents", 1, s, 0))
974          {
975             free_map(exports);
976             return JB_ERR_MEMORY;
977          }
978       }
979
980       return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
981    }
982
983    s = strdup("");
984    for (j = 0; (s != NULL) && (j < Argc); j++)
985    {
986       if (!err) err = string_join  (&s, html_encode(Argv[j]));
987       if (!err) err = string_append(&s, " ");
988    }
989    if (!err) err = map(exports, "invocation", 1, s, 0);
990
991    if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
992    if (!err) err = show_defines(exports);
993
994    if (err) 
995    {
996       free_map(exports);
997       return JB_ERR_MEMORY;
998    }
999
1000 #ifdef FEATURE_STATISTICS
1001    local_urls_read     = urls_read;
1002    local_urls_rejected = urls_rejected;
1003
1004    /*
1005     * Need to alter the stats not to include the fetch of this
1006     * page.
1007     *
1008     * Can't do following thread safely! doh!
1009     *
1010     * urls_read--;
1011     * urls_rejected--; * This will be incremented subsequently *
1012     */
1013
1014    if (local_urls_read == 0)
1015    {
1016       if (!err) err = map_block_killer(exports, "have-stats");
1017    }
1018    else
1019    {
1020       if (!err) err = map_block_killer(exports, "have-no-stats");
1021
1022       perc_rej = (float)local_urls_rejected * 100.0F /
1023             (float)local_urls_read;
1024
1025       sprintf(buf, "%d", local_urls_read);
1026       if (!err) err = map(exports, "requests-received", 1, buf, 1);
1027
1028       sprintf(buf, "%d", local_urls_rejected);
1029       if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1030
1031       sprintf(buf, "%6.2f", perc_rej);
1032       if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1033    }
1034
1035 #else /* ndef FEATURE_STATISTICS */
1036    err = err || map_block_killer(exports, "statistics");
1037 #endif /* ndef FEATURE_STATISTICS */
1038    
1039    /* 
1040     * List all action files in use, together with view and edit links,
1041     * except for standard.action, which should only be viewable. (Not
1042     * enforced in the editor itself)
1043     * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1044     */
1045    s = strdup("");
1046    for (i = 0; i < MAX_AF_FILES; i++)
1047    {
1048       if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
1049       {
1050          if (!err) err = string_append(&s, "<tr><td>");
1051          if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1052          snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&amp;index=%d\">View</a>", i);
1053          if (!err) err = string_append(&s, buf);
1054
1055 #ifdef FEATURE_CGI_EDIT_ACTIONS
1056          if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
1057          {
1058             snprintf(buf, 100, "&nbsp;&nbsp;<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
1059             if (!err) err = string_append(&s, buf);
1060          }
1061 #endif
1062
1063          if (!err) err = string_append(&s, "</td></tr>\n");
1064       }
1065    }
1066    if (*s != '\0')   
1067    {
1068       if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1069    }
1070    else
1071    {
1072       if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1073    }
1074
1075    /* 
1076     * List all re_filterfiles in use, together with view options.
1077     * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1078     */
1079    s = strdup("");
1080    for (i = 0; i < MAX_AF_FILES; i++)
1081    {
1082       if (((fl = csp->rlist[i]) != NULL) && ((b = fl->f) != NULL))
1083       {
1084          if (!err) err = string_append(&s, "<tr><td>");
1085          if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1086          snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&amp;index=%d\">View</a>", i);
1087          if (!err) err = string_append(&s, buf);
1088          if (!err) err = string_append(&s, "</td></tr>\n");
1089       }
1090    }
1091    if (*s != '\0')   
1092    {
1093       if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1094    }
1095    else
1096    {
1097       if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1098       if (!err) err = map_block_killer(exports, "have-filterfile");
1099    }
1100
1101 #ifdef FEATURE_TRUST
1102    if (csp->tlist)
1103    {
1104       if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1105    }
1106    else
1107    {
1108       if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1109       if (!err) err = map_block_killer(exports, "have-trustfile");
1110    }
1111 #else
1112    if (!err) err = map_block_killer(exports, "trust-support");
1113 #endif /* ndef FEATURE_TRUST */
1114
1115    if (err)
1116    {
1117       free_map(exports);
1118       return JB_ERR_MEMORY;
1119    }
1120
1121    return template_fill_for_cgi(csp, "show-status", exports, rsp);
1122 }
1123
1124  
1125 /*********************************************************************
1126  *
1127  * Function    :  cgi_show_url_info
1128  *
1129  * Description :  CGI function that determines and shows which actions
1130  *                Privoxy will perform for a given url, and which
1131  *                matches starting from the defaults have lead to that.
1132  *
1133  * Parameters  :
1134  *          1  :  csp = Current client state (buffers, headers, etc...)
1135  *          2  :  rsp = http_response data structure for output
1136  *          3  :  parameters = map of cgi parameters
1137  *
1138  * CGI Parameters :
1139  *            url : The url whose actions are to be determined.
1140  *                  If url is unset, the url-given conditional will be
1141  *                  set, so that all but the form can be suppressed in
1142  *                  the template.
1143  *
1144  * Returns     :  JB_ERR_OK on success
1145  *                JB_ERR_MEMORY on out-of-memory error.  
1146  *
1147  *********************************************************************/
1148 jb_err cgi_show_url_info(struct client_state *csp,
1149                          struct http_response *rsp,
1150                          const struct map *parameters)
1151 {
1152    char *url_param;
1153    struct map *exports;
1154    char buf[150];
1155
1156    assert(csp);
1157    assert(rsp);
1158    assert(parameters);
1159
1160    if (NULL == (exports = default_exports(csp, "show-url-info")))
1161    {
1162       return JB_ERR_MEMORY;
1163    }
1164
1165    /*
1166     * Get the url= parameter (if present) and remove any leading/trailing spaces.
1167     */
1168    url_param = strdup(lookup(parameters, "url"));
1169    if (url_param == NULL)
1170    {
1171       free_map(exports);
1172       return JB_ERR_MEMORY;
1173    }
1174    chomp(url_param);
1175
1176    /*
1177     * Handle prefixes.  4 possibilities:
1178     * 1) "http://" or "https://" prefix present and followed by URL - OK
1179     * 2) Only the "http://" or "https://" part is present, no URL - change
1180     *    to empty string so it will be detected later as "no URL".
1181     * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1182     *    "http://" prefix.
1183     * 4) Parameter not specified or is empty string - let this fall through
1184     *    for now, next block of code will handle it.
1185     */
1186    if (0 == strncmp(url_param, "http://", 7))
1187    {
1188       if (url_param[7] == '\0')
1189       {
1190          /*
1191           * Empty URL (just prefix).
1192           * Make it totally empty so it's caught by the next if()
1193           */
1194          url_param[0] = '\0';
1195       }
1196    }
1197    else if (0 == strncmp(url_param, "https://", 8))
1198    {
1199       if (url_param[8] == '\0')
1200       {
1201          /*
1202           * Empty URL (just prefix).
1203           * Make it totally empty so it's caught by the next if()
1204           */
1205          url_param[0] = '\0';
1206       }
1207    }
1208    else if (url_param[0] != '\0')
1209    {
1210       /*
1211        * Unknown prefix - assume http://
1212        */
1213       char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1214       if (NULL == url_param_prefixed)
1215       {
1216          free(url_param);
1217          free_map(exports);
1218          return JB_ERR_MEMORY;
1219       }
1220       strcpy(url_param_prefixed, "http://");
1221       strcpy(url_param_prefixed + 7, url_param);
1222       free(url_param);
1223       url_param = url_param_prefixed;
1224    }
1225
1226
1227    if (url_param[0] == '\0')
1228    {
1229       /* URL paramater not specified, display query form only. */
1230       free(url_param);
1231       if (map_block_killer(exports, "url-given")
1232         || map(exports, "url", 1, "", 1))
1233       {
1234          free_map(exports);
1235          return JB_ERR_MEMORY;
1236       }
1237    }
1238    else
1239    {
1240       /* Given a URL, so query it. */
1241       jb_err err;
1242       char *matches;
1243       char *s;
1244       int hits = 0;
1245       struct file_list *fl;
1246       struct url_actions *b;
1247       struct http_request url_to_query[1];
1248       struct current_action_spec action[1];
1249       int i;
1250       
1251       if (map(exports, "url", 1, html_encode(url_param), 0))
1252       {
1253          free(url_param);
1254          free_map(exports);
1255          return JB_ERR_MEMORY;
1256       }
1257
1258       init_current_action(action);
1259
1260       if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1261       {
1262          free_current_action(action);
1263          free(url_param);
1264          free_map(exports);
1265          return JB_ERR_MEMORY;
1266       }
1267
1268       err = parse_http_url(url_param, url_to_query, csp);
1269
1270       free(url_param);
1271
1272       if (err == JB_ERR_MEMORY)
1273       {
1274          free_http_request(url_to_query);
1275          free_current_action(action);
1276          free_map(exports);
1277          return JB_ERR_MEMORY;
1278       }
1279       else if (err)
1280       {
1281          /* Invalid URL */
1282
1283          err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1284          if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1285
1286          free_current_action(action);
1287          free_http_request(url_to_query);
1288
1289          if (err)
1290          {
1291             free_map(exports);
1292             return JB_ERR_MEMORY;
1293          }
1294
1295          return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1296       }
1297
1298       /*
1299        * We have a warning about SSL paths.  Hide it for insecure sites.
1300        */
1301       if (!url_to_query->ssl)
1302       {
1303          if (map_block_killer(exports, "https"))
1304          {
1305             free_current_action(action);
1306             free_map(exports);
1307             free_http_request(url_to_query);
1308             return JB_ERR_MEMORY;
1309          }
1310       }
1311
1312       matches = strdup("<table class=\"transparent\">");
1313
1314       for (i = 0; i < MAX_AF_FILES; i++)
1315       {
1316          if (NULL == csp->config->actions_file_short[i]
1317              || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1318
1319          b = NULL;
1320          hits = 1;
1321          if ((fl = csp->actions_list[i]) != NULL)
1322          {
1323             if ((b = fl->f) != NULL)
1324             {
1325                /* FIXME: Hardcoded HTML! */
1326                string_append(&matches, "<tr><th>In file: ");
1327                string_join  (&matches, html_encode(csp->config->actions_file_short[i]));
1328                snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&amp;index=%d\">", i);
1329                string_append(&matches, buf);
1330                string_append(&matches, "View</a>");
1331 #ifdef FEATURE_CGI_EDIT_ACTIONS
1332                string_append(&matches, " <a class=\"cmd\" href=\"/edit-actions-list?f=");
1333                string_join  (&matches, html_encode(csp->config->actions_file_short[i]));
1334                string_append(&matches, "\">Edit</a>");
1335 #endif
1336                string_append(&matches, "</th></tr>\n");
1337
1338                hits = 0;
1339                b = b->next;
1340             }
1341          }
1342
1343          for (; (b != NULL) && (matches != NULL); b = b->next)
1344          {
1345             if (url_match(b->url, url_to_query))
1346             {
1347                string_append(&matches, "<tr><td>{");
1348                string_join  (&matches, actions_to_html(csp, b->action));
1349                string_append(&matches, " }</b><br>\n<code>");
1350                string_join  (&matches, html_encode(b->url->spec));
1351                string_append(&matches, "</code></td></tr>\n");
1352
1353                if (merge_current_action(action, b->action))
1354                {
1355                   freez(matches);
1356                   free_http_request(url_to_query);
1357                   free_current_action(action);
1358                   free_map(exports);
1359                   return JB_ERR_MEMORY;
1360                }
1361                hits++;
1362             }
1363          }
1364
1365          if (!hits)
1366          {
1367             string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1368          }
1369       }
1370       string_append(&matches, "</table>\n");
1371
1372       free_http_request(url_to_query);
1373
1374       if (matches == NULL)
1375       {
1376          free_current_action(action);
1377          free_map(exports);
1378          return JB_ERR_MEMORY;
1379       }
1380
1381       if (map(exports, "matches", 1, matches , 0))
1382       {
1383          free_current_action(action);
1384          free_map(exports);
1385          return JB_ERR_MEMORY;
1386       }
1387
1388       s = current_action_to_html(csp, action);
1389
1390       free_current_action(action);
1391
1392       if (map(exports, "final", 1, s, 0))
1393       {
1394          free_map(exports);
1395          return JB_ERR_MEMORY;
1396       }
1397    }
1398
1399    return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1400 }
1401
1402
1403 /*********************************************************************
1404  *
1405  * Function    :  cgi_robots_txt
1406  *
1407  * Description :  CGI function to return "/robots.txt".
1408  *
1409  * Parameters  :
1410  *          1  :  csp = Current client state (buffers, headers, etc...)
1411  *          2  :  rsp = http_response data structure for output
1412  *          3  :  parameters = map of cgi parameters
1413  *
1414  * CGI Parameters : None
1415  *
1416  * Returns     :  JB_ERR_OK on success
1417  *                JB_ERR_MEMORY on out-of-memory error.  
1418  *
1419  *********************************************************************/
1420 jb_err cgi_robots_txt(struct client_state *csp,
1421                       struct http_response *rsp,
1422                       const struct map *parameters)
1423 {
1424    char buf[100];
1425    jb_err err;
1426
1427    rsp->body = strdup(
1428       "# This is the Privoxy control interface.\n"
1429       "# It isn't very useful to index it, and you're likely to break stuff.\n"
1430       "# So go away!\n"
1431       "\n"
1432       "User-agent: *\n"
1433       "Disallow: /\n"
1434       "\n");
1435    if (rsp->body == NULL)
1436    {
1437       return JB_ERR_MEMORY;
1438    }
1439
1440    err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1441
1442    rsp->is_static = 1;
1443
1444    get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1445    if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1446
1447    return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1448 }
1449
1450
1451 /*********************************************************************
1452  *
1453  * Function    :  show_defines
1454  *
1455  * Description :  Add to a map the state od all conditional #defines
1456  *                used when building
1457  *
1458  * Parameters  :
1459  *          1  :  exports = map to extend
1460  *
1461  * Returns     :  JB_ERR_OK on success
1462  *                JB_ERR_MEMORY on out-of-memory error.  
1463  *
1464  *********************************************************************/
1465 static jb_err show_defines(struct map *exports)
1466 {
1467    jb_err err = JB_ERR_OK;
1468
1469 #ifdef FEATURE_ACL
1470    if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1471 #else /* ifndef FEATURE_ACL */
1472    if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1473 #endif /* ndef FEATURE_ACL */
1474
1475 #ifdef FEATURE_CGI_EDIT_ACTIONS
1476    if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1477 #else /* ifndef FEATURE_COOKIE_JAR */
1478    if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1479 #endif /* ndef FEATURE_COOKIE_JAR */
1480
1481 #ifdef FEATURE_COOKIE_JAR
1482    if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1483 #else /* ifndef FEATURE_COOKIE_JAR */
1484    if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1485 #endif /* ndef FEATURE_COOKIE_JAR */
1486
1487 #ifdef FEATURE_FAST_REDIRECTS
1488    if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1489 #else /* ifndef FEATURE_FAST_REDIRECTS */
1490    if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1491 #endif /* ndef FEATURE_FAST_REDIRECTS */
1492
1493 #ifdef FEATURE_FORCE_LOAD
1494    if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1495    if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1496 #else /* ifndef FEATURE_FORCE_LOAD */
1497    if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1498    if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1499 #endif /* ndef FEATURE_FORCE_LOAD */
1500
1501 #ifdef FEATURE_GRACEFUL_TERMINATION
1502    if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1503 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1504    if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1505 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1506
1507 #ifdef FEATURE_IMAGE_BLOCKING
1508    if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1509 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1510    if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1511 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1512
1513 #ifdef FEATURE_IMAGE_DETECT_MSIE
1514    if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1515 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1516    if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1517 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1518
1519 #ifdef FEATURE_KILL_POPUPS
1520    if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1521 #else /* ifndef FEATURE_KILL_POPUPS */
1522    if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1523 #endif /* ndef FEATURE_KILL_POPUPS */
1524
1525 #ifdef FEATURE_NO_GIFS
1526    if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1527 #else /* ifndef FEATURE_NO_GIFS */
1528    if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1529 #endif /* ndef FEATURE_NO_GIFS */
1530
1531 #ifdef FEATURE_PTHREAD
1532    if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1533 #else /* ifndef FEATURE_PTHREAD */
1534    if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1535 #endif /* ndef FEATURE_PTHREAD */
1536
1537 #ifdef FEATURE_STATISTICS
1538    if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1539 #else /* ifndef FEATURE_STATISTICS */
1540    if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1541 #endif /* ndef FEATURE_STATISTICS */
1542
1543 #ifdef FEATURE_TOGGLE
1544    if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1545 #else /* ifndef FEATURE_TOGGLE */
1546    if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1547 #endif /* ndef FEATURE_TOGGLE */
1548
1549 #ifdef FEATURE_TRUST
1550    if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1551 #else /* ifndef FEATURE_TRUST */
1552    if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1553 #endif /* ndef FEATURE_TRUST */
1554
1555 #ifdef STATIC_PCRE
1556    if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1557 #else /* ifndef STATIC_PCRE */
1558    if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1559 #endif /* ndef STATIC_PCRE */
1560
1561 #ifdef STATIC_PCRS
1562    if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1563 #else /* ifndef STATIC_PCRS */
1564    if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1565 #endif /* ndef STATIC_PCRS */
1566
1567    return err;
1568 }
1569
1570
1571 /*********************************************************************
1572  *
1573  * Function    :  show_rcs
1574  *
1575  * Description :  Create a string with the rcs info for all sourcefiles
1576  *
1577  * Parameters  :  None
1578  *
1579  * Returns     :  A string, or NULL on out-of-memory.
1580  *
1581  *********************************************************************/
1582 static char *show_rcs(void)
1583 {
1584    char *result = strdup("");
1585    char buf[BUFFER_SIZE];
1586
1587    /* Instead of including *all* dot h's in the project (thus creating a
1588     * tremendous amount of dependencies), I will concede to declaring them
1589     * as extern's.  This forces the developer to add to this list, but oh well.
1590     */
1591
1592 #define SHOW_RCS(__x)              \
1593    {                               \
1594       extern const char __x[];     \
1595       sprintf(buf, "%s\n", __x);   \
1596       string_append(&result, buf); \
1597    }
1598
1599    /* In alphabetical order */
1600    SHOW_RCS(actions_h_rcs)
1601    SHOW_RCS(actions_rcs)
1602 #ifdef AMIGA
1603    SHOW_RCS(amiga_h_rcs)
1604    SHOW_RCS(amiga_rcs)
1605 #endif /* def AMIGA */
1606    SHOW_RCS(cgi_h_rcs)
1607    SHOW_RCS(cgi_rcs)
1608 #ifdef FEATURE_CGI_EDIT_ACTIONS
1609    SHOW_RCS(cgiedit_h_rcs)
1610    SHOW_RCS(cgiedit_rcs)
1611 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1612    SHOW_RCS(cgisimple_h_rcs)
1613    SHOW_RCS(cgisimple_rcs)
1614 #ifdef __MINGW32__
1615    SHOW_RCS(cygwin_h_rcs)
1616 #endif
1617    SHOW_RCS(deanimate_h_rcs)
1618    SHOW_RCS(deanimate_rcs)
1619    SHOW_RCS(encode_h_rcs)
1620    SHOW_RCS(encode_rcs)
1621    SHOW_RCS(errlog_h_rcs)
1622    SHOW_RCS(errlog_rcs)
1623    SHOW_RCS(filters_h_rcs)
1624    SHOW_RCS(filters_rcs)
1625    SHOW_RCS(gateway_h_rcs)
1626    SHOW_RCS(gateway_rcs)
1627    SHOW_RCS(jbsockets_h_rcs)
1628    SHOW_RCS(jbsockets_rcs)
1629    SHOW_RCS(jcc_h_rcs)
1630    SHOW_RCS(jcc_rcs)
1631 #ifdef FEATURE_KILL_POPUPS
1632    SHOW_RCS(killpopup_h_rcs)
1633    SHOW_RCS(killpopup_rcs)
1634 #endif /* def FEATURE_KILL_POPUPS */
1635    SHOW_RCS(list_h_rcs)
1636    SHOW_RCS(list_rcs)
1637    SHOW_RCS(loadcfg_h_rcs)
1638    SHOW_RCS(loadcfg_rcs)
1639    SHOW_RCS(loaders_h_rcs)
1640    SHOW_RCS(loaders_rcs)
1641    SHOW_RCS(miscutil_h_rcs)
1642    SHOW_RCS(miscutil_rcs)
1643    SHOW_RCS(parsers_h_rcs)
1644    SHOW_RCS(parsers_rcs)
1645    SHOW_RCS(pcrs_rcs)
1646    SHOW_RCS(pcrs_h_rcs)
1647    SHOW_RCS(project_h_rcs)
1648    SHOW_RCS(ssplit_h_rcs)
1649    SHOW_RCS(ssplit_rcs)
1650    SHOW_RCS(urlmatch_h_rcs)
1651    SHOW_RCS(urlmatch_rcs)
1652 #ifdef _WIN32
1653 #ifndef _WIN_CONSOLE
1654    SHOW_RCS(w32log_h_rcs)
1655    SHOW_RCS(w32log_rcs)
1656    SHOW_RCS(w32res_h_rcs)
1657    SHOW_RCS(w32taskbar_h_rcs)
1658    SHOW_RCS(w32taskbar_rcs)
1659 #endif /* ndef _WIN_CONSOLE */
1660    SHOW_RCS(win32_h_rcs)
1661    SHOW_RCS(win32_rcs)
1662 #endif /* def _WIN32 */
1663
1664 #undef SHOW_RCS
1665
1666    return result;
1667
1668 }
1669
1670
1671 /*
1672   Local Variables:
1673   tab-width: 3
1674   end:
1675 */