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