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