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