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