1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.53 2007/04/08 13:21:04 fabiankeil Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
6 * Purpose : Simple CGIs to get information about Privoxy's
9 * Functions declared include:
12 * Copyright : Written by and Copyright (C) 2001-2007 the SourceForge
13 * Privoxy team. http://www.privoxy.org/
15 * Based on the Internet Junkbuster originally written
16 * by and Copyright (C) 1997 Anonymous Coders and
17 * Junkbusters Corporation. http://www.junkbusters.com
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.
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.
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.
38 * $Log: cgisimple.c,v $
39 * Revision 1.53 2007/04/08 13:21:04 fabiankeil
40 * Reference action files in CGI URLs by id instead
41 * of using the first part of the file name.
42 * Fixes BR 1694250 and BR 1590556.
44 * Revision 1.52 2007/02/13 15:10:26 fabiankeil
45 * Apparently fopen()ing in "binary" mode doesn't require
46 * #ifdefs, it's already done without them in cgiedit.c.
48 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
49 * - Show forwarding settings on the show-url-info page
50 * - Fix some HTML syntax errors.
52 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
53 * Add favicon delivery functions.
55 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
56 * Suppress edit buttons for action files if Privoxy has
57 * no write access. Suggested by Roland in PR 1564026.
59 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
60 * Display warning if show-url-info CGI page
61 * is used while Privoxy is toggled off.
63 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
64 * Use zalloc in cgi_send_user_manual.
66 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
67 * Add FEATURE_ZLIB to the list of conditional
68 * defines at the show-status page.
70 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
71 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
72 * body memory before using it, replaced sprintf calls with snprintf.
74 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
75 * Removed checks whether or not AF_FILES have
76 * data structures associated with them in cgi_show_status.
77 * It doesn't matter as we're only interested in the file names.
79 * For the action files the checks were always true,
80 * but they prevented empty filter files from being
81 * listed. Fixes parts of BR 1619208.
83 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
84 * - Added FEATURE_GRACEFUL_TERMINATION to the
85 * "conditional #defines" section
86 * - Escaped ampersands in generated HTML.
87 * - Renamed re-filter-filename to re-filter-filenames
89 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
90 * Add special treatment for WIN32 to make sure
91 * cgi_send_user_manual opens the files in binary mode.
92 * Fixes BR 1600411 and unbreaks image delivery.
94 * Remove outdated comment.
96 * Revision 1.41 2006/10/09 19:18:28 roro
97 * Redirect http://p.p/user-manual (without trailing slash) to
98 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
100 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
101 * Modified cgi_send_user_manual to serve binary
102 * content without destroying it first. Should also be
103 * faster now. Added ".jpg" check for Content-Type guessing.
105 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
106 * Deliver documents in the user-manual directory
107 * with "Content-Type text/css" if their filename
110 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
111 * Incorporate modified version of Roland Rosenfeld's patch to
112 * optionally access the user-manual via Privoxy. Closes patch 679075.
114 * Formatting changed to Privoxy style, added call to
115 * cgi_error_no_template if the requested file doesn't
116 * exist and modified check whether or not Privoxy itself
117 * should serve the manual. Should work cross-platform now.
119 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
120 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
121 * with what was really the latest development (the v_3_0_branch branch)
123 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
124 * Multiple filter file support
126 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
127 * Undo some damaging memory leak patches
129 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
130 * A few memory leaks plugged (mostly on error paths)
132 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
133 * Another instance of:
134 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
135 * Thanks to Magnus Holmgren for the patch
137 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
138 * - Prevent line wrap beween "View/Edit" link buttons on status page
139 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
141 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
142 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
144 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
145 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
147 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
148 * Applying patch from Andreas as provided by Hal on the list.
149 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
151 * Revision 1.35 2002/05/12 21:44:44 jongfoster
152 * Adding amiga.[ch] revision information, if on an amiga.
154 * Revision 1.34 2002/04/30 12:06:12 oes
155 * Deleted unused code from default_cgi
157 * Revision 1.33 2002/04/30 11:14:52 oes
158 * Made csp the first parameter in *action_to_html
160 * Revision 1.32 2002/04/26 18:29:13 jongfoster
161 * Fixing this Visual C++ warning:
162 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
164 * Revision 1.31 2002/04/26 12:54:36 oes
165 * - Kill obsolete REDIRECT_URL code
166 * - Error handling fixes
167 * - Style sheet related HTML snipplet changes
168 * - cgi_show_url_info:
169 * - Matches now in table, actions on single lines,
171 * - standard.action suppressed
172 * - Buttons to View and Edit AFs
174 * Revision 1.30 2002/04/24 02:18:08 oes
175 * - show-status is now the starting point for editing
176 * the actions files, generate list of all AFs with buttons
177 * for viewing and editing, new look for file list (Jon:
178 * buttons now aligned ;-P ), view mode now supports multiple
179 * AFs, name changes, no view links for unspecified files,
180 * no edit link for standard.action.
182 * - Jon's multiple AF patch: cgi_show_url_info now uses all
183 * AFs and marks the output accordingly
185 * Revision 1.29 2002/04/10 13:38:35 oes
186 * load_template signature changed
188 * Revision 1.28 2002/04/07 15:42:12 jongfoster
189 * Fixing send-banner?type=auto when the image-blocker is
190 * a redirect to send-banner
192 * Revision 1.27 2002/04/05 15:50:48 oes
193 * added send-stylesheet CGI
195 * Revision 1.26 2002/04/04 00:36:36 gliptak
196 * always use pcre for matching
198 * Revision 1.25 2002/04/03 22:28:03 gliptak
199 * Removed references to gnu_regex
201 * Revision 1.24 2002/04/02 16:12:47 oes
202 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
204 * Revision 1.23 2002/03/26 22:29:54 swa
205 * we have a new homepage!
207 * Revision 1.22 2002/03/24 16:18:15 jongfoster
210 * Revision 1.21 2002/03/24 15:23:33 jongfoster
213 * Revision 1.20 2002/03/24 13:25:43 swa
214 * name change related issues
216 * Revision 1.19 2002/03/16 23:54:06 jongfoster
217 * Adding graceful termination feature, to help look for memory leaks.
218 * If you enable this (which, by design, has to be done by hand
219 * editing config.h) and then go to http://i.j.b/die, then the program
220 * will exit cleanly after the *next* request. It should free all the
221 * memory that was used.
223 * Revision 1.18 2002/03/12 01:44:49 oes
224 * Changed default for "blocked" image from jb logo to checkboard pattern
226 * Revision 1.17 2002/03/08 16:43:18 oes
227 * Added choice beween GIF and PNG built-in images
229 * Revision 1.16 2002/03/07 03:48:38 oes
230 * - Changed built-in images from GIF to PNG
231 * (with regard to Unisys patent issue)
232 * - Added a 4x4 pattern PNG which is less intrusive
233 * than the logo but also clearly marks the deleted banners
235 * Revision 1.15 2002/03/06 22:54:35 jongfoster
236 * Automated function-comment nitpicking.
238 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
239 * Clean up a little CRLF unpleasantness that suddenly appeared
241 * Revision 1.13 2002/02/21 00:10:37 jongfoster
242 * Adding send-banner?type=auto option
244 * Revision 1.12 2002/01/23 01:03:32 jongfoster
245 * Fixing gcc [CygWin] compiler warnings
247 * Revision 1.11 2002/01/23 00:01:04 jongfoster
248 * Adding cgi_transparent_gif() for http://i.j.b/t
249 * Adding missing html_encode() to many CGI functions.
250 * Adding urlmatch.[ch] to http://i.j.b/show-version
252 * Revision 1.10 2002/01/17 21:10:37 jongfoster
253 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
254 * Also fixing a problem in the same function with improperly quoted URLs
255 * in output HTML, and adding code to handle https:// URLs correctly.
257 * Revision 1.9 2001/11/30 23:09:15 jongfoster
258 * Now reports on FEATURE_CGI_EDIT_ACTIONS
259 * Removing FEATURE_DENY_GZIP from template
261 * Revision 1.8 2001/11/13 00:14:07 jongfoster
262 * Fixing stupid bug now I've figured out what || means.
263 * (It always returns 0 or 1, not one of it's paramaters.)
265 * Revision 1.7 2001/10/23 21:48:19 jongfoster
266 * Cleaning up error handling in CGI functions - they now send back
267 * a HTML error page and should never cause a FATAL error. (Fixes one
268 * potential source of "denial of service" attacks).
270 * CGI actions file editor that works and is actually useful.
272 * Ability to toggle JunkBuster remotely using a CGI call.
274 * You can turn off both the above features in the main configuration
275 * file, e.g. if you are running a multi-user proxy.
277 * Revision 1.6 2001/10/14 22:00:32 jongfoster
278 * Adding support for a 404 error when an invalid CGI page is requested.
280 * Revision 1.5 2001/10/07 15:30:41 oes
281 * Removed FEATURE_DENY_GZIP
283 * Revision 1.4 2001/10/02 15:31:12 oes
284 * Introduced show-request cgi
286 * Revision 1.3 2001/09/22 16:34:44 jongfoster
287 * Removing unneeded #includes
289 * Revision 1.2 2001/09/19 18:01:11 oes
290 * Fixed comments; cosmetics
292 * Revision 1.1 2001/09/16 17:08:54 jongfoster
293 * Moving simple CGI functions from cgi.c to new file cgisimple.c
296 **********************************************************************/
302 #include <sys/types.h>
310 #endif /* def HAVE_ACCESS */
314 #include "cgisimple.h"
320 #include "miscutil.h"
323 #include "urlmatch.h"
326 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
329 static char *show_rcs(void);
330 static jb_err show_defines(struct map *exports);
333 * 16x16 ico blobs for favicon delivery functions.
335 const char default_favicon_data[] =
336 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
337 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
338 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
339 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
340 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
341 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
342 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
343 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
344 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
345 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
346 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
347 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
348 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
350 const char error_favicon_data[] =
351 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
352 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
353 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
354 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
355 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
356 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
357 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
358 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
359 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
360 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
361 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
362 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
363 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
365 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
366 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
368 /*********************************************************************
370 * Function : cgi_default
372 * Description : CGI function that is called for the CGI_SITE_1_HOST
373 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
374 * Boring - only exports the default exports.
377 * 1 : csp = Current client state (buffers, headers, etc...)
378 * 2 : rsp = http_response data structure for output
379 * 3 : parameters = map of cgi parameters
381 * CGI Parameters : none
383 * Returns : JB_ERR_OK on success
384 * JB_ERR_MEMORY on out-of-memory
386 *********************************************************************/
387 jb_err cgi_default(struct client_state *csp,
388 struct http_response *rsp,
389 const struct map *parameters)
396 if (NULL == (exports = default_exports(csp, "")))
398 return JB_ERR_MEMORY;
401 return template_fill_for_cgi(csp, "default", exports, rsp);
405 /*********************************************************************
407 * Function : cgi_error_404
409 * Description : CGI function that is called if an unknown action was
413 * 1 : csp = Current client state (buffers, headers, etc...)
414 * 2 : rsp = http_response data structure for output
415 * 3 : parameters = map of cgi parameters
417 * CGI Parameters : none
419 * Returns : JB_ERR_OK on success
420 * JB_ERR_MEMORY on out-of-memory error.
422 *********************************************************************/
423 jb_err cgi_error_404(struct client_state *csp,
424 struct http_response *rsp,
425 const struct map *parameters)
433 if (NULL == (exports = default_exports(csp, NULL)))
435 return JB_ERR_MEMORY;
438 rsp->status = strdup("404 Privoxy configuration page not found");
439 if (rsp->status == NULL)
442 return JB_ERR_MEMORY;
445 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
449 #ifdef FEATURE_GRACEFUL_TERMINATION
450 /*********************************************************************
454 * Description : CGI function to shut down Privoxy.
455 * NOTE: Turning this on in a production build
456 * would be a BAD idea. An EXTREMELY BAD idea.
457 * In short, don't do it.
460 * 1 : csp = Current client state (buffers, headers, etc...)
461 * 2 : rsp = http_response data structure for output
462 * 3 : parameters = map of cgi parameters
464 * CGI Parameters : none
466 * Returns : JB_ERR_OK on success
467 * JB_ERR_MEMORY on out-of-memory error.
469 *********************************************************************/
470 jb_err cgi_die (struct client_state *csp,
471 struct http_response *rsp,
472 const struct map *parameters)
482 * I don't really care what gets sent back to the browser.
483 * Take the easy option - "out of memory" page.
486 return JB_ERR_MEMORY;
488 #endif /* def FEATURE_GRACEFUL_TERMINATION */
491 /*********************************************************************
493 * Function : cgi_show_request
495 * Description : Show the client's request and what sed() would have
499 * 1 : csp = Current client state (buffers, headers, etc...)
500 * 2 : rsp = http_response data structure for output
501 * 3 : parameters = map of cgi parameters
503 * CGI Parameters : none
505 * Returns : JB_ERR_OK on success
506 * JB_ERR_MEMORY on out-of-memory error.
508 *********************************************************************/
509 jb_err cgi_show_request(struct client_state *csp,
510 struct http_response *rsp,
511 const struct map *parameters)
520 if (NULL == (exports = default_exports(csp, "show-request")))
522 return JB_ERR_MEMORY;
526 * Repair the damage done to the IOB by get_header()
528 for (p = csp->iob->buf; p < csp->iob->eod; p++)
530 if (*p == '\0') *p = '\n';
534 * Export the original client's request and the one we would
535 * be sending to the server if this wasn't a CGI call
538 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
541 return JB_ERR_MEMORY;
544 if (map(exports, "processed-request", 1, html_encode_and_free_original(
545 sed(client_patterns, add_client_headers, csp)), 0))
548 return JB_ERR_MEMORY;
551 return template_fill_for_cgi(csp, "show-request", exports, rsp);
555 /*********************************************************************
557 * Function : cgi_send_banner
559 * Description : CGI function that returns a banner.
562 * 1 : csp = Current client state (buffers, headers, etc...)
563 * 2 : rsp = http_response data structure for output
564 * 3 : parameters = map of cgi parameters
567 * type : Selects the type of banner between "trans", "logo",
568 * and "auto". Defaults to "logo" if absent or invalid.
569 * "auto" means to select as if we were image-blocking.
570 * (Only the first character really counts; b and t are
573 * Returns : JB_ERR_OK on success
574 * JB_ERR_MEMORY on out-of-memory error.
576 *********************************************************************/
577 jb_err cgi_send_banner(struct client_state *csp,
578 struct http_response *rsp,
579 const struct map *parameters)
581 char imagetype = lookup(parameters, "type")[0];
584 * If type is auto, then determine the right thing
585 * to do from the set-image-blocker action
587 if (imagetype == 'a')
594 #ifdef FEATURE_IMAGE_BLOCKING
595 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
597 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
598 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
599 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
603 /* Use default - nothing to do here. */
605 else if (0 == strcmpic(p, "blank"))
609 else if (0 == strcmpic(p, "pattern"))
615 * If the action is to call this CGI, determine
618 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
620 imagetype = p[sizeof(prefix1) - 1];
622 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
624 imagetype = p[sizeof(prefix2) - 1];
628 * Everything else must (should) be a URL to
636 #endif /* def FEATURE_IMAGE_BLOCKING */
640 * Now imagetype is either the non-auto type we were called with,
641 * or it was auto and has since been determined. In any case, we
642 * can proceed to actually answering the request by sending a redirect
643 * or an image as appropriate:
645 if (imagetype == 'r')
647 rsp->status = strdup("302 Local Redirect from Privoxy");
648 if (rsp->status == NULL)
650 return JB_ERR_MEMORY;
652 if (enlist_unique_header(rsp->headers, "Location",
653 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
655 return JB_ERR_MEMORY;
660 if ((imagetype == 'b') || (imagetype == 't'))
662 rsp->body = bindup(image_blank_data, image_blank_length);
663 rsp->content_length = image_blank_length;
667 rsp->body = bindup(image_pattern_data, image_pattern_length);
668 rsp->content_length = image_pattern_length;
671 if (rsp->body == NULL)
673 return JB_ERR_MEMORY;
675 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
677 return JB_ERR_MEMORY;
688 /*********************************************************************
690 * Function : cgi_transparent_image
692 * Description : CGI function that sends a 1x1 transparent image.
695 * 1 : csp = Current client state (buffers, headers, etc...)
696 * 2 : rsp = http_response data structure for output
697 * 3 : parameters = map of cgi parameters
699 * CGI Parameters : None
701 * Returns : JB_ERR_OK on success
702 * JB_ERR_MEMORY on out-of-memory error.
704 *********************************************************************/
705 jb_err cgi_transparent_image(struct client_state *csp,
706 struct http_response *rsp,
707 const struct map *parameters)
709 rsp->body = bindup(image_blank_data, image_blank_length);
710 rsp->content_length = image_blank_length;
712 if (rsp->body == NULL)
714 return JB_ERR_MEMORY;
717 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
719 return JB_ERR_MEMORY;
729 /*********************************************************************
731 * Function : cgi_send_default_favicon
733 * Description : CGI function that sends the standard favicon.
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
740 * CGI Parameters : None
742 * Returns : JB_ERR_OK on success
743 * JB_ERR_MEMORY on out-of-memory error.
745 *********************************************************************/
746 jb_err cgi_send_default_favicon(struct client_state *csp,
747 struct http_response *rsp,
748 const struct map *parameters)
750 rsp->body = bindup(default_favicon_data, default_favicon_length);
751 rsp->content_length = default_favicon_length;
753 if (rsp->body == NULL)
755 return JB_ERR_MEMORY;
758 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
760 return JB_ERR_MEMORY;
770 /*********************************************************************
772 * Function : cgi_send_error_favicon
774 * Description : CGI function that sends the favicon for error pages.
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
781 * CGI Parameters : None
783 * Returns : JB_ERR_OK on success
784 * JB_ERR_MEMORY on out-of-memory error.
786 *********************************************************************/
787 jb_err cgi_send_error_favicon(struct client_state *csp,
788 struct http_response *rsp,
789 const struct map *parameters)
791 rsp->body = bindup(error_favicon_data, error_favicon_length);
792 rsp->content_length = error_favicon_length;
794 if (rsp->body == NULL)
796 return JB_ERR_MEMORY;
799 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
801 return JB_ERR_MEMORY;
811 /*********************************************************************
813 * Function : cgi_send_stylesheet
815 * Description : CGI function that sends a css stylesheet found
816 * in the cgi-style.css template
819 * 1 : csp = Current client state (buffers, headers, etc...)
820 * 2 : rsp = http_response data structure for output
821 * 3 : parameters = map of cgi parameters
823 * CGI Parameters : None
825 * Returns : JB_ERR_OK on success
826 * JB_ERR_MEMORY on out-of-memory error.
828 *********************************************************************/
829 jb_err cgi_send_stylesheet(struct client_state *csp,
830 struct http_response *rsp,
831 const struct map *parameters)
838 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
840 if (err == JB_ERR_FILE)
843 * No way to tell user; send empty stylesheet
845 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
849 return err; /* JB_ERR_MEMORY */
852 if (enlist(rsp->headers, "Content-Type: text/css"))
854 return JB_ERR_MEMORY;
860 /*********************************************************************
862 * Function : cgi_send_user_manual
864 * Description : CGI function that sends a file in the user
868 * 1 : csp = Current client state (buffers, headers, etc...)
869 * 2 : rsp = http_response data structure for output
870 * 3 : parameters = map of cgi parameters
872 * CGI Parameters : file=name.html, the name of the HTML file
873 * (relative to user-manual from config)
875 * Returns : JB_ERR_OK on success
876 * JB_ERR_MEMORY on out-of-memory error.
878 *********************************************************************/
879 jb_err cgi_send_user_manual(struct client_state *csp,
880 struct http_response *rsp,
881 const struct map *parameters)
883 const char * filename;
886 jb_err err = JB_ERR_OK;
893 if (!parameters->first)
895 /* requested http://p.p/user-manual (without trailing slash) */
896 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
899 get_string_param(parameters, "file", &filename);
900 /* Check paramter for hack attempts */
901 if (filename && strchr(filename, '/'))
903 return JB_ERR_CGI_PARAMS;
905 if (filename && strstr(filename, ".."))
907 return JB_ERR_CGI_PARAMS;
910 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
911 if (full_path == NULL)
913 return JB_ERR_MEMORY;
916 /* Open user-manual file */
917 if (NULL == (fp = fopen(full_path, "rb")))
919 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
920 err = cgi_error_no_template(csp, rsp, full_path);
925 /* Get file length */
926 fseek(fp, 0, SEEK_END);
927 length = (size_t)ftell(fp);
928 fseek(fp, 0, SEEK_SET);
930 /* Allocate memory and load the file directly into the body */
931 rsp->body = (char *)zalloc(length+1);
936 return JB_ERR_MEMORY;
938 if (!fread(rsp->body, length, 1, fp))
941 * May happen if the file size changes between fseek() and fread().
942 * If it does, we just log it and serve what we got.
944 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
949 rsp->content_length = length;
951 /* Guess correct Content-Type based on the filename's ending */
954 length = strlen(filename);
960 if((length>=4) && !strcmp(&filename[length-4], ".css"))
962 err = enlist(rsp->headers, "Content-Type: text/css");
964 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
966 err = enlist(rsp->headers, "Content-Type: image/jpeg");
970 err = enlist(rsp->headers, "Content-Type: text/html");
977 /*********************************************************************
979 * Function : cgi_show_version
981 * Description : CGI function that returns a a web page describing the
982 * file versions of Privoxy.
985 * 1 : csp = Current client state (buffers, headers, etc...)
986 * 2 : rsp = http_response data structure for output
987 * 3 : parameters = map of cgi parameters
989 * CGI Parameters : none
991 * Returns : JB_ERR_OK on success
992 * JB_ERR_MEMORY on out-of-memory error.
994 *********************************************************************/
995 jb_err cgi_show_version(struct client_state *csp,
996 struct http_response *rsp,
997 const struct map *parameters)
1005 if (NULL == (exports = default_exports(csp, "show-version")))
1007 return JB_ERR_MEMORY;
1010 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1013 return JB_ERR_MEMORY;
1016 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1020 /*********************************************************************
1022 * Function : cgi_show_status
1024 * Description : CGI function that returns a web page describing the
1025 * current status of Privoxy.
1028 * 1 : csp = Current client state (buffers, headers, etc...)
1029 * 2 : rsp = http_response data structure for output
1030 * 3 : parameters = map of cgi parameters
1033 * file : Which file to show. Only first letter is checked,
1035 * - "p"ermissions (actions) file
1038 * Default is to show menu and other information.
1040 * Returns : JB_ERR_OK on success
1041 * JB_ERR_MEMORY on out-of-memory error.
1043 *********************************************************************/
1044 jb_err cgi_show_status(struct client_state *csp,
1045 struct http_response *rsp,
1046 const struct map *parameters)
1053 char buf[BUFFER_SIZE];
1054 const char * filename = NULL;
1055 char * file_description = NULL;
1056 #ifdef FEATURE_STATISTICS
1057 float perc_rej; /* Percentage of http requests rejected */
1058 int local_urls_read;
1059 int local_urls_rejected;
1060 #endif /* ndef FEATURE_STATISTICS */
1061 jb_err err = JB_ERR_OK;
1063 struct map *exports;
1069 if (NULL == (exports = default_exports(csp, "show-status")))
1071 return JB_ERR_MEMORY;
1074 switch (*(lookup(parameters, "file")))
1077 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1079 filename = csp->actions_list[i]->filename;
1080 file_description = "Actions File";
1085 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1087 filename = csp->rlist[i]->filename;
1088 file_description = "Filter File";
1092 #ifdef FEATURE_TRUST
1096 filename = csp->tlist->filename;
1097 file_description = "Trust File";
1100 #endif /* def FEATURE_TRUST */
1103 if (NULL != filename)
1105 if ( map(exports, "file-description", 1, file_description, 1)
1106 || map(exports, "filepath", 1, html_encode(filename), 0) )
1109 return JB_ERR_MEMORY;
1112 if ((fp = fopen(filename, "r")) == NULL)
1114 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1117 return JB_ERR_MEMORY;
1123 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1125 string_join (&s, html_encode(buf));
1129 if (map(exports, "contents", 1, s, 0))
1132 return JB_ERR_MEMORY;
1136 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1140 for (j = 0; (s != NULL) && (j < Argc); j++)
1142 if (!err) err = string_join (&s, html_encode(Argv[j]));
1143 if (!err) err = string_append(&s, " ");
1145 if (!err) err = map(exports, "invocation", 1, s, 0);
1147 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1148 if (!err) err = show_defines(exports);
1153 return JB_ERR_MEMORY;
1156 #ifdef FEATURE_STATISTICS
1157 local_urls_read = urls_read;
1158 local_urls_rejected = urls_rejected;
1161 * Need to alter the stats not to include the fetch of this
1164 * Can't do following thread safely! doh!
1167 * urls_rejected--; * This will be incremented subsequently *
1170 if (local_urls_read == 0)
1172 if (!err) err = map_block_killer(exports, "have-stats");
1176 if (!err) err = map_block_killer(exports, "have-no-stats");
1178 perc_rej = (float)local_urls_rejected * 100.0F /
1179 (float)local_urls_read;
1181 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1182 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1184 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1185 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1187 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1188 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1191 #else /* ndef FEATURE_STATISTICS */
1192 err = err || map_block_killer(exports, "statistics");
1193 #endif /* ndef FEATURE_STATISTICS */
1196 * List all action files in use, together with view and edit links,
1197 * except for standard.action, which should only be viewable. (Not
1198 * enforced in the editor itself)
1199 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1202 for (i = 0; i < MAX_AF_FILES; i++)
1204 if (csp->actions_list[i] != NULL)
1206 if (!err) err = string_append(&s, "<tr><td>");
1207 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1208 snprintf(buf, sizeof(buf),
1209 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1210 if (!err) err = string_append(&s, buf);
1212 #ifdef FEATURE_CGI_EDIT_ACTIONS
1213 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
1216 if (access(csp->config->actions_file[i], W_OK) == 0)
1218 #endif /* def HAVE_ACCESS */
1219 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1220 if (!err) err = string_append(&s, buf);
1225 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1227 #endif /* def HAVE_ACCESS */
1231 if (!err) err = string_append(&s, "</td></tr>\n");
1236 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1240 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1244 * List all re_filterfiles in use, together with view options.
1245 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1248 for (i = 0; i < MAX_AF_FILES; i++)
1250 if (csp->rlist[i] != NULL)
1252 if (!err) err = string_append(&s, "<tr><td>");
1253 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1255 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1256 if (!err) err = string_append(&s, buf);
1257 if (!err) err = string_append(&s, "</td></tr>\n");
1262 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1266 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1267 if (!err) err = map_block_killer(exports, "have-filterfile");
1270 #ifdef FEATURE_TRUST
1273 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1277 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1278 if (!err) err = map_block_killer(exports, "have-trustfile");
1281 if (!err) err = map_block_killer(exports, "trust-support");
1282 #endif /* ndef FEATURE_TRUST */
1287 return JB_ERR_MEMORY;
1290 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1294 /*********************************************************************
1296 * Function : cgi_show_url_info
1298 * Description : CGI function that determines and shows which actions
1299 * Privoxy will perform for a given url, and which
1300 * matches starting from the defaults have lead to that.
1303 * 1 : csp = Current client state (buffers, headers, etc...)
1304 * 2 : rsp = http_response data structure for output
1305 * 3 : parameters = map of cgi parameters
1308 * url : The url whose actions are to be determined.
1309 * If url is unset, the url-given conditional will be
1310 * set, so that all but the form can be suppressed in
1313 * Returns : JB_ERR_OK on success
1314 * JB_ERR_MEMORY on out-of-memory error.
1316 *********************************************************************/
1317 jb_err cgi_show_url_info(struct client_state *csp,
1318 struct http_response *rsp,
1319 const struct map *parameters)
1322 struct map *exports;
1329 if (NULL == (exports = default_exports(csp, "show-url-info")))
1331 return JB_ERR_MEMORY;
1335 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1337 url_param = strdup(lookup(parameters, "url"));
1338 if (url_param == NULL)
1341 return JB_ERR_MEMORY;
1346 * Handle prefixes. 4 possibilities:
1347 * 1) "http://" or "https://" prefix present and followed by URL - OK
1348 * 2) Only the "http://" or "https://" part is present, no URL - change
1349 * to empty string so it will be detected later as "no URL".
1350 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1352 * 4) Parameter not specified or is empty string - let this fall through
1353 * for now, next block of code will handle it.
1355 if (0 == strncmp(url_param, "http://", 7))
1357 if (url_param[7] == '\0')
1360 * Empty URL (just prefix).
1361 * Make it totally empty so it's caught by the next if()
1363 url_param[0] = '\0';
1366 else if (0 == strncmp(url_param, "https://", 8))
1368 if (url_param[8] == '\0')
1371 * Empty URL (just prefix).
1372 * Make it totally empty so it's caught by the next if()
1374 url_param[0] = '\0';
1377 else if (url_param[0] != '\0')
1380 * Unknown prefix - assume http://
1382 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1383 if (NULL == url_param_prefixed)
1387 return JB_ERR_MEMORY;
1389 strcpy(url_param_prefixed, "http://");
1390 strcpy(url_param_prefixed + 7, url_param);
1392 url_param = url_param_prefixed;
1396 * Hide "toggle off" warning if Privoxy is toggled on.
1399 #ifdef FEATURE_TOGGLE
1400 (global_toggle_state == 1) &&
1401 #endif /* def FEATURE_TOGGLE */
1402 map_block_killer(exports, "privoxy-is-toggled-off")
1406 return JB_ERR_MEMORY;
1409 if (url_param[0] == '\0')
1411 /* URL paramater not specified, display query form only. */
1413 if (map_block_killer(exports, "url-given")
1414 || map(exports, "url", 1, "", 1))
1417 return JB_ERR_MEMORY;
1422 /* Given a URL, so query it. */
1427 struct file_list *fl;
1428 struct url_actions *b;
1429 struct http_request url_to_query[1];
1430 struct current_action_spec action[1];
1433 if (map(exports, "url", 1, html_encode(url_param), 0))
1437 return JB_ERR_MEMORY;
1440 init_current_action(action);
1442 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1444 free_current_action(action);
1447 return JB_ERR_MEMORY;
1450 err = parse_http_url(url_param, url_to_query, csp);
1454 if (err == JB_ERR_MEMORY)
1456 free_http_request(url_to_query);
1457 free_current_action(action);
1459 return JB_ERR_MEMORY;
1465 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1466 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1468 free_current_action(action);
1469 free_http_request(url_to_query);
1474 return JB_ERR_MEMORY;
1477 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1481 * We have a warning about SSL paths. Hide it for insecure sites.
1483 if (!url_to_query->ssl)
1485 if (map_block_killer(exports, "https"))
1487 free_current_action(action);
1489 free_http_request(url_to_query);
1490 return JB_ERR_MEMORY;
1494 matches = strdup("<table summary=\"\" class=\"transparent\">");
1496 for (i = 0; i < MAX_AF_FILES; i++)
1498 if (NULL == csp->config->actions_file_short[i]
1499 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1503 if ((fl = csp->actions_list[i]) != NULL)
1505 if ((b = fl->f) != NULL)
1507 /* FIXME: Hardcoded HTML! */
1508 string_append(&matches, "<tr><th>In file: ");
1509 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1510 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1511 string_append(&matches, buf);
1512 string_append(&matches, "View</a>");
1513 #ifdef FEATURE_CGI_EDIT_ACTIONS
1514 string_append(&matches, " <a class=\"cmd\" href=\"/edit-actions-list?f=");
1515 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1516 string_append(&matches, "\">Edit</a>");
1518 string_append(&matches, "</th></tr>\n");
1525 for (; (b != NULL) && (matches != NULL); b = b->next)
1527 if (url_match(b->url, url_to_query))
1529 string_append(&matches, "<tr><td>{");
1530 string_join (&matches, actions_to_html(csp, b->action));
1531 string_append(&matches, " }<br>\n<code>");
1532 string_join (&matches, html_encode(b->url->spec));
1533 string_append(&matches, "</code></td></tr>\n");
1535 if (merge_current_action(action, b->action))
1538 free_http_request(url_to_query);
1539 free_current_action(action);
1541 return JB_ERR_MEMORY;
1549 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1552 string_append(&matches, "</table>\n");
1555 * Fill in forwarding settings.
1557 * The possibilities are:
1559 * - http forwarding only
1560 * - socks4(a) forwarding only
1561 * - socks4(a) and http forwarding.
1563 * XXX: Parts of this code could be reused for the
1564 * "forwarding-failed" template which currently doesn't
1565 * display the proxy port and an eventuell second forwarder.
1568 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1570 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1572 if (!err) err = map_block_killer(exports, "socks-forwarder");
1573 if (!err) err = map_block_killer(exports, "http-forwarder");
1577 char port[10]; /* We save proxy ports as int but need a string here */
1579 if (!err) err = map_block_killer(exports, "no-forwarder");
1581 if (fwd->gateway_host != NULL)
1583 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1584 "socks4" : "socks4a", 1);
1585 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1586 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1587 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1591 if (!err) err = map_block_killer(exports, "socks-forwarder");
1594 if (fwd->forward_host != NULL)
1596 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1597 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1598 if (!err) err = map(exports, "forward-port", 1, port, 1);
1602 if (!err) err = map_block_killer(exports, "http-forwarder");
1607 free_http_request(url_to_query);
1609 if (err || matches == NULL)
1611 free_current_action(action);
1613 return JB_ERR_MEMORY;
1616 if (map(exports, "matches", 1, matches , 0))
1618 free_current_action(action);
1620 return JB_ERR_MEMORY;
1623 s = current_action_to_html(csp, action);
1625 free_current_action(action);
1627 if (map(exports, "final", 1, s, 0))
1630 return JB_ERR_MEMORY;
1634 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1638 /*********************************************************************
1640 * Function : cgi_robots_txt
1642 * Description : CGI function to return "/robots.txt".
1645 * 1 : csp = Current client state (buffers, headers, etc...)
1646 * 2 : rsp = http_response data structure for output
1647 * 3 : parameters = map of cgi parameters
1649 * CGI Parameters : None
1651 * Returns : JB_ERR_OK on success
1652 * JB_ERR_MEMORY on out-of-memory error.
1654 *********************************************************************/
1655 jb_err cgi_robots_txt(struct client_state *csp,
1656 struct http_response *rsp,
1657 const struct map *parameters)
1663 "# This is the Privoxy control interface.\n"
1664 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1670 if (rsp->body == NULL)
1672 return JB_ERR_MEMORY;
1675 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1679 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1680 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1682 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1686 /*********************************************************************
1688 * Function : show_defines
1690 * Description : Add to a map the state od all conditional #defines
1691 * used when building
1694 * 1 : exports = map to extend
1696 * Returns : JB_ERR_OK on success
1697 * JB_ERR_MEMORY on out-of-memory error.
1699 *********************************************************************/
1700 static jb_err show_defines(struct map *exports)
1702 jb_err err = JB_ERR_OK;
1705 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1706 #else /* ifndef FEATURE_ACL */
1707 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1708 #endif /* ndef FEATURE_ACL */
1710 #ifdef FEATURE_CGI_EDIT_ACTIONS
1711 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1712 #else /* ifndef FEATURE_COOKIE_JAR */
1713 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1714 #endif /* ndef FEATURE_COOKIE_JAR */
1716 #ifdef FEATURE_COOKIE_JAR
1717 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1718 #else /* ifndef FEATURE_COOKIE_JAR */
1719 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1720 #endif /* ndef FEATURE_COOKIE_JAR */
1722 #ifdef FEATURE_FAST_REDIRECTS
1723 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1724 #else /* ifndef FEATURE_FAST_REDIRECTS */
1725 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1726 #endif /* ndef FEATURE_FAST_REDIRECTS */
1728 #ifdef FEATURE_FORCE_LOAD
1729 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1730 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1731 #else /* ifndef FEATURE_FORCE_LOAD */
1732 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1733 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1734 #endif /* ndef FEATURE_FORCE_LOAD */
1736 #ifdef FEATURE_GRACEFUL_TERMINATION
1737 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1738 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1739 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1740 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1742 #ifdef FEATURE_IMAGE_BLOCKING
1743 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1744 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1745 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1746 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1748 #ifdef FEATURE_IMAGE_DETECT_MSIE
1749 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1750 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1751 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1752 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1754 #ifdef FEATURE_KILL_POPUPS
1755 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1756 #else /* ifndef FEATURE_KILL_POPUPS */
1757 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1758 #endif /* ndef FEATURE_KILL_POPUPS */
1760 #ifdef FEATURE_NO_GIFS
1761 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1762 #else /* ifndef FEATURE_NO_GIFS */
1763 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1764 #endif /* ndef FEATURE_NO_GIFS */
1766 #ifdef FEATURE_PTHREAD
1767 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1768 #else /* ifndef FEATURE_PTHREAD */
1769 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1770 #endif /* ndef FEATURE_PTHREAD */
1772 #ifdef FEATURE_STATISTICS
1773 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1774 #else /* ifndef FEATURE_STATISTICS */
1775 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1776 #endif /* ndef FEATURE_STATISTICS */
1778 #ifdef FEATURE_TOGGLE
1779 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1780 #else /* ifndef FEATURE_TOGGLE */
1781 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1782 #endif /* ndef FEATURE_TOGGLE */
1784 #ifdef FEATURE_TRUST
1785 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1786 #else /* ifndef FEATURE_TRUST */
1787 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1788 #endif /* ndef FEATURE_TRUST */
1791 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1792 #else /* ifndef FEATURE_ZLIB */
1793 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1794 #endif /* ndef FEATURE_ZLIB */
1797 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1798 #else /* ifndef STATIC_PCRE */
1799 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1800 #endif /* ndef STATIC_PCRE */
1803 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1804 #else /* ifndef STATIC_PCRS */
1805 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1806 #endif /* ndef STATIC_PCRS */
1812 /*********************************************************************
1814 * Function : show_rcs
1816 * Description : Create a string with the rcs info for all sourcefiles
1820 * Returns : A string, or NULL on out-of-memory.
1822 *********************************************************************/
1823 static char *show_rcs(void)
1825 char *result = strdup("");
1826 char buf[BUFFER_SIZE];
1828 /* Instead of including *all* dot h's in the project (thus creating a
1829 * tremendous amount of dependencies), I will concede to declaring them
1830 * as extern's. This forces the developer to add to this list, but oh well.
1833 #define SHOW_RCS(__x) \
1835 extern const char __x[]; \
1836 snprintf(buf, sizeof(buf), " %s\n", __x); \
1837 string_append(&result, buf); \
1840 /* In alphabetical order */
1841 SHOW_RCS(actions_h_rcs)
1842 SHOW_RCS(actions_rcs)
1844 SHOW_RCS(amiga_h_rcs)
1846 #endif /* def AMIGA */
1849 #ifdef FEATURE_CGI_EDIT_ACTIONS
1850 SHOW_RCS(cgiedit_h_rcs)
1851 SHOW_RCS(cgiedit_rcs)
1852 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1853 SHOW_RCS(cgisimple_h_rcs)
1854 SHOW_RCS(cgisimple_rcs)
1856 SHOW_RCS(cygwin_h_rcs)
1858 SHOW_RCS(deanimate_h_rcs)
1859 SHOW_RCS(deanimate_rcs)
1860 SHOW_RCS(encode_h_rcs)
1861 SHOW_RCS(encode_rcs)
1862 SHOW_RCS(errlog_h_rcs)
1863 SHOW_RCS(errlog_rcs)
1864 SHOW_RCS(filters_h_rcs)
1865 SHOW_RCS(filters_rcs)
1866 SHOW_RCS(gateway_h_rcs)
1867 SHOW_RCS(gateway_rcs)
1868 SHOW_RCS(jbsockets_h_rcs)
1869 SHOW_RCS(jbsockets_rcs)
1872 #ifdef FEATURE_KILL_POPUPS
1873 SHOW_RCS(killpopup_h_rcs)
1874 SHOW_RCS(killpopup_rcs)
1875 #endif /* def FEATURE_KILL_POPUPS */
1876 SHOW_RCS(list_h_rcs)
1878 SHOW_RCS(loadcfg_h_rcs)
1879 SHOW_RCS(loadcfg_rcs)
1880 SHOW_RCS(loaders_h_rcs)
1881 SHOW_RCS(loaders_rcs)
1882 SHOW_RCS(miscutil_h_rcs)
1883 SHOW_RCS(miscutil_rcs)
1884 SHOW_RCS(parsers_h_rcs)
1885 SHOW_RCS(parsers_rcs)
1887 SHOW_RCS(pcrs_h_rcs)
1888 SHOW_RCS(project_h_rcs)
1889 SHOW_RCS(ssplit_h_rcs)
1890 SHOW_RCS(ssplit_rcs)
1891 SHOW_RCS(urlmatch_h_rcs)
1892 SHOW_RCS(urlmatch_rcs)
1894 #ifndef _WIN_CONSOLE
1895 SHOW_RCS(w32log_h_rcs)
1896 SHOW_RCS(w32log_rcs)
1897 SHOW_RCS(w32res_h_rcs)
1898 SHOW_RCS(w32taskbar_h_rcs)
1899 SHOW_RCS(w32taskbar_rcs)
1900 #endif /* ndef _WIN_CONSOLE */
1901 SHOW_RCS(win32_h_rcs)
1903 #endif /* def _WIN32 */