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