1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.54 2007/04/09 18:11:35 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.54 2007/04/09 18:11:35 fabiankeil
40 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
42 * Revision 1.53 2007/04/08 13:21:04 fabiankeil
43 * Reference action files in CGI URLs by id instead
44 * of using the first part of the file name.
45 * Fixes BR 1694250 and BR 1590556.
47 * Revision 1.52 2007/02/13 15:10:26 fabiankeil
48 * Apparently fopen()ing in "binary" mode doesn't require
49 * #ifdefs, it's already done without them in cgiedit.c.
51 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
52 * - Show forwarding settings on the show-url-info page
53 * - Fix some HTML syntax errors.
55 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
56 * Add favicon delivery functions.
58 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
59 * Suppress edit buttons for action files if Privoxy has
60 * no write access. Suggested by Roland in PR 1564026.
62 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
63 * Display warning if show-url-info CGI page
64 * is used while Privoxy is toggled off.
66 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
67 * Use zalloc in cgi_send_user_manual.
69 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
70 * Add FEATURE_ZLIB to the list of conditional
71 * defines at the show-status page.
73 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
74 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
75 * body memory before using it, replaced sprintf calls with snprintf.
77 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
78 * Removed checks whether or not AF_FILES have
79 * data structures associated with them in cgi_show_status.
80 * It doesn't matter as we're only interested in the file names.
82 * For the action files the checks were always true,
83 * but they prevented empty filter files from being
84 * listed. Fixes parts of BR 1619208.
86 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
87 * - Added FEATURE_GRACEFUL_TERMINATION to the
88 * "conditional #defines" section
89 * - Escaped ampersands in generated HTML.
90 * - Renamed re-filter-filename to re-filter-filenames
92 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
93 * Add special treatment for WIN32 to make sure
94 * cgi_send_user_manual opens the files in binary mode.
95 * Fixes BR 1600411 and unbreaks image delivery.
97 * Remove outdated comment.
99 * Revision 1.41 2006/10/09 19:18:28 roro
100 * Redirect http://p.p/user-manual (without trailing slash) to
101 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
103 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
104 * Modified cgi_send_user_manual to serve binary
105 * content without destroying it first. Should also be
106 * faster now. Added ".jpg" check for Content-Type guessing.
108 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
109 * Deliver documents in the user-manual directory
110 * with "Content-Type text/css" if their filename
113 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
114 * Incorporate modified version of Roland Rosenfeld's patch to
115 * optionally access the user-manual via Privoxy. Closes patch 679075.
117 * Formatting changed to Privoxy style, added call to
118 * cgi_error_no_template if the requested file doesn't
119 * exist and modified check whether or not Privoxy itself
120 * should serve the manual. Should work cross-platform now.
122 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
123 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
124 * with what was really the latest development (the v_3_0_branch branch)
126 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
127 * Multiple filter file support
129 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
130 * Undo some damaging memory leak patches
132 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
133 * A few memory leaks plugged (mostly on error paths)
135 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
136 * Another instance of:
137 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
138 * Thanks to Magnus Holmgren for the patch
140 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
141 * - Prevent line wrap beween "View/Edit" link buttons on status page
142 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
144 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
145 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
147 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
148 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
150 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
151 * Applying patch from Andreas as provided by Hal on the list.
152 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
154 * Revision 1.35 2002/05/12 21:44:44 jongfoster
155 * Adding amiga.[ch] revision information, if on an amiga.
157 * Revision 1.34 2002/04/30 12:06:12 oes
158 * Deleted unused code from default_cgi
160 * Revision 1.33 2002/04/30 11:14:52 oes
161 * Made csp the first parameter in *action_to_html
163 * Revision 1.32 2002/04/26 18:29:13 jongfoster
164 * Fixing this Visual C++ warning:
165 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
167 * Revision 1.31 2002/04/26 12:54:36 oes
168 * - Kill obsolete REDIRECT_URL code
169 * - Error handling fixes
170 * - Style sheet related HTML snipplet changes
171 * - cgi_show_url_info:
172 * - Matches now in table, actions on single lines,
174 * - standard.action suppressed
175 * - Buttons to View and Edit AFs
177 * Revision 1.30 2002/04/24 02:18:08 oes
178 * - show-status is now the starting point for editing
179 * the actions files, generate list of all AFs with buttons
180 * for viewing and editing, new look for file list (Jon:
181 * buttons now aligned ;-P ), view mode now supports multiple
182 * AFs, name changes, no view links for unspecified files,
183 * no edit link for standard.action.
185 * - Jon's multiple AF patch: cgi_show_url_info now uses all
186 * AFs and marks the output accordingly
188 * Revision 1.29 2002/04/10 13:38:35 oes
189 * load_template signature changed
191 * Revision 1.28 2002/04/07 15:42:12 jongfoster
192 * Fixing send-banner?type=auto when the image-blocker is
193 * a redirect to send-banner
195 * Revision 1.27 2002/04/05 15:50:48 oes
196 * added send-stylesheet CGI
198 * Revision 1.26 2002/04/04 00:36:36 gliptak
199 * always use pcre for matching
201 * Revision 1.25 2002/04/03 22:28:03 gliptak
202 * Removed references to gnu_regex
204 * Revision 1.24 2002/04/02 16:12:47 oes
205 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
207 * Revision 1.23 2002/03/26 22:29:54 swa
208 * we have a new homepage!
210 * Revision 1.22 2002/03/24 16:18:15 jongfoster
213 * Revision 1.21 2002/03/24 15:23:33 jongfoster
216 * Revision 1.20 2002/03/24 13:25:43 swa
217 * name change related issues
219 * Revision 1.19 2002/03/16 23:54:06 jongfoster
220 * Adding graceful termination feature, to help look for memory leaks.
221 * If you enable this (which, by design, has to be done by hand
222 * editing config.h) and then go to http://i.j.b/die, then the program
223 * will exit cleanly after the *next* request. It should free all the
224 * memory that was used.
226 * Revision 1.18 2002/03/12 01:44:49 oes
227 * Changed default for "blocked" image from jb logo to checkboard pattern
229 * Revision 1.17 2002/03/08 16:43:18 oes
230 * Added choice beween GIF and PNG built-in images
232 * Revision 1.16 2002/03/07 03:48:38 oes
233 * - Changed built-in images from GIF to PNG
234 * (with regard to Unisys patent issue)
235 * - Added a 4x4 pattern PNG which is less intrusive
236 * than the logo but also clearly marks the deleted banners
238 * Revision 1.15 2002/03/06 22:54:35 jongfoster
239 * Automated function-comment nitpicking.
241 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
242 * Clean up a little CRLF unpleasantness that suddenly appeared
244 * Revision 1.13 2002/02/21 00:10:37 jongfoster
245 * Adding send-banner?type=auto option
247 * Revision 1.12 2002/01/23 01:03:32 jongfoster
248 * Fixing gcc [CygWin] compiler warnings
250 * Revision 1.11 2002/01/23 00:01:04 jongfoster
251 * Adding cgi_transparent_gif() for http://i.j.b/t
252 * Adding missing html_encode() to many CGI functions.
253 * Adding urlmatch.[ch] to http://i.j.b/show-version
255 * Revision 1.10 2002/01/17 21:10:37 jongfoster
256 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
257 * Also fixing a problem in the same function with improperly quoted URLs
258 * in output HTML, and adding code to handle https:// URLs correctly.
260 * Revision 1.9 2001/11/30 23:09:15 jongfoster
261 * Now reports on FEATURE_CGI_EDIT_ACTIONS
262 * Removing FEATURE_DENY_GZIP from template
264 * Revision 1.8 2001/11/13 00:14:07 jongfoster
265 * Fixing stupid bug now I've figured out what || means.
266 * (It always returns 0 or 1, not one of it's paramaters.)
268 * Revision 1.7 2001/10/23 21:48:19 jongfoster
269 * Cleaning up error handling in CGI functions - they now send back
270 * a HTML error page and should never cause a FATAL error. (Fixes one
271 * potential source of "denial of service" attacks).
273 * CGI actions file editor that works and is actually useful.
275 * Ability to toggle JunkBuster remotely using a CGI call.
277 * You can turn off both the above features in the main configuration
278 * file, e.g. if you are running a multi-user proxy.
280 * Revision 1.6 2001/10/14 22:00:32 jongfoster
281 * Adding support for a 404 error when an invalid CGI page is requested.
283 * Revision 1.5 2001/10/07 15:30:41 oes
284 * Removed FEATURE_DENY_GZIP
286 * Revision 1.4 2001/10/02 15:31:12 oes
287 * Introduced show-request cgi
289 * Revision 1.3 2001/09/22 16:34:44 jongfoster
290 * Removing unneeded #includes
292 * Revision 1.2 2001/09/19 18:01:11 oes
293 * Fixed comments; cosmetics
295 * Revision 1.1 2001/09/16 17:08:54 jongfoster
296 * Moving simple CGI functions from cgi.c to new file cgisimple.c
299 **********************************************************************/
305 #include <sys/types.h>
313 #endif /* def HAVE_ACCESS */
317 #include "cgisimple.h"
323 #include "miscutil.h"
326 #include "urlmatch.h"
329 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
332 static char *show_rcs(void);
333 static jb_err show_defines(struct map *exports);
336 * 16x16 ico blobs for favicon delivery functions.
338 const char default_favicon_data[] =
339 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
340 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
341 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
342 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
343 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
344 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
345 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
346 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
347 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
348 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
349 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
350 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
351 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
353 const char error_favicon_data[] =
354 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
355 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
356 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
357 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
358 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
359 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
360 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
361 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
362 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
363 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
364 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
365 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
366 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
368 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
369 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
371 /*********************************************************************
373 * Function : cgi_default
375 * Description : CGI function that is called for the CGI_SITE_1_HOST
376 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
377 * Boring - only exports the default exports.
380 * 1 : csp = Current client state (buffers, headers, etc...)
381 * 2 : rsp = http_response data structure for output
382 * 3 : parameters = map of cgi parameters
384 * CGI Parameters : none
386 * Returns : JB_ERR_OK on success
387 * JB_ERR_MEMORY on out-of-memory
389 *********************************************************************/
390 jb_err cgi_default(struct client_state *csp,
391 struct http_response *rsp,
392 const struct map *parameters)
399 if (NULL == (exports = default_exports(csp, "")))
401 return JB_ERR_MEMORY;
404 return template_fill_for_cgi(csp, "default", exports, rsp);
408 /*********************************************************************
410 * Function : cgi_error_404
412 * Description : CGI function that is called if an unknown action was
416 * 1 : csp = Current client state (buffers, headers, etc...)
417 * 2 : rsp = http_response data structure for output
418 * 3 : parameters = map of cgi parameters
420 * CGI Parameters : none
422 * Returns : JB_ERR_OK on success
423 * JB_ERR_MEMORY on out-of-memory error.
425 *********************************************************************/
426 jb_err cgi_error_404(struct client_state *csp,
427 struct http_response *rsp,
428 const struct map *parameters)
436 if (NULL == (exports = default_exports(csp, NULL)))
438 return JB_ERR_MEMORY;
441 rsp->status = strdup("404 Privoxy configuration page not found");
442 if (rsp->status == NULL)
445 return JB_ERR_MEMORY;
448 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
452 #ifdef FEATURE_GRACEFUL_TERMINATION
453 /*********************************************************************
457 * Description : CGI function to shut down Privoxy.
458 * NOTE: Turning this on in a production build
459 * would be a BAD idea. An EXTREMELY BAD idea.
460 * In short, don't do it.
463 * 1 : csp = Current client state (buffers, headers, etc...)
464 * 2 : rsp = http_response data structure for output
465 * 3 : parameters = map of cgi parameters
467 * CGI Parameters : none
469 * Returns : JB_ERR_OK on success
470 * JB_ERR_MEMORY on out-of-memory error.
472 *********************************************************************/
473 jb_err cgi_die (struct client_state *csp,
474 struct http_response *rsp,
475 const struct map *parameters)
485 * I don't really care what gets sent back to the browser.
486 * Take the easy option - "out of memory" page.
489 return JB_ERR_MEMORY;
491 #endif /* def FEATURE_GRACEFUL_TERMINATION */
494 /*********************************************************************
496 * Function : cgi_show_request
498 * Description : Show the client's request and what sed() would have
502 * 1 : csp = Current client state (buffers, headers, etc...)
503 * 2 : rsp = http_response data structure for output
504 * 3 : parameters = map of cgi parameters
506 * CGI Parameters : none
508 * Returns : JB_ERR_OK on success
509 * JB_ERR_MEMORY on out-of-memory error.
511 *********************************************************************/
512 jb_err cgi_show_request(struct client_state *csp,
513 struct http_response *rsp,
514 const struct map *parameters)
523 if (NULL == (exports = default_exports(csp, "show-request")))
525 return JB_ERR_MEMORY;
529 * Repair the damage done to the IOB by get_header()
531 for (p = csp->iob->buf; p < csp->iob->eod; p++)
533 if (*p == '\0') *p = '\n';
537 * Export the original client's request and the one we would
538 * be sending to the server if this wasn't a CGI call
541 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
544 return JB_ERR_MEMORY;
547 if (map(exports, "processed-request", 1, html_encode_and_free_original(
548 sed(client_patterns, add_client_headers, csp)), 0))
551 return JB_ERR_MEMORY;
554 return template_fill_for_cgi(csp, "show-request", exports, rsp);
558 /*********************************************************************
560 * Function : cgi_send_banner
562 * Description : CGI function that returns a banner.
565 * 1 : csp = Current client state (buffers, headers, etc...)
566 * 2 : rsp = http_response data structure for output
567 * 3 : parameters = map of cgi parameters
570 * type : Selects the type of banner between "trans", "logo",
571 * and "auto". Defaults to "logo" if absent or invalid.
572 * "auto" means to select as if we were image-blocking.
573 * (Only the first character really counts; b and t are
576 * Returns : JB_ERR_OK on success
577 * JB_ERR_MEMORY on out-of-memory error.
579 *********************************************************************/
580 jb_err cgi_send_banner(struct client_state *csp,
581 struct http_response *rsp,
582 const struct map *parameters)
584 char imagetype = lookup(parameters, "type")[0];
587 * If type is auto, then determine the right thing
588 * to do from the set-image-blocker action
590 if (imagetype == 'a')
597 #ifdef FEATURE_IMAGE_BLOCKING
598 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
600 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
601 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
602 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
606 /* Use default - nothing to do here. */
608 else if (0 == strcmpic(p, "blank"))
612 else if (0 == strcmpic(p, "pattern"))
618 * If the action is to call this CGI, determine
621 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
623 imagetype = p[sizeof(prefix1) - 1];
625 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
627 imagetype = p[sizeof(prefix2) - 1];
631 * Everything else must (should) be a URL to
639 #endif /* def FEATURE_IMAGE_BLOCKING */
643 * Now imagetype is either the non-auto type we were called with,
644 * or it was auto and has since been determined. In any case, we
645 * can proceed to actually answering the request by sending a redirect
646 * or an image as appropriate:
648 if (imagetype == 'r')
650 rsp->status = strdup("302 Local Redirect from Privoxy");
651 if (rsp->status == NULL)
653 return JB_ERR_MEMORY;
655 if (enlist_unique_header(rsp->headers, "Location",
656 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
658 return JB_ERR_MEMORY;
663 if ((imagetype == 'b') || (imagetype == 't'))
665 rsp->body = bindup(image_blank_data, image_blank_length);
666 rsp->content_length = image_blank_length;
670 rsp->body = bindup(image_pattern_data, image_pattern_length);
671 rsp->content_length = image_pattern_length;
674 if (rsp->body == NULL)
676 return JB_ERR_MEMORY;
678 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
680 return JB_ERR_MEMORY;
691 /*********************************************************************
693 * Function : cgi_transparent_image
695 * Description : CGI function that sends a 1x1 transparent image.
698 * 1 : csp = Current client state (buffers, headers, etc...)
699 * 2 : rsp = http_response data structure for output
700 * 3 : parameters = map of cgi parameters
702 * CGI Parameters : None
704 * Returns : JB_ERR_OK on success
705 * JB_ERR_MEMORY on out-of-memory error.
707 *********************************************************************/
708 jb_err cgi_transparent_image(struct client_state *csp,
709 struct http_response *rsp,
710 const struct map *parameters)
712 rsp->body = bindup(image_blank_data, image_blank_length);
713 rsp->content_length = image_blank_length;
715 if (rsp->body == NULL)
717 return JB_ERR_MEMORY;
720 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
722 return JB_ERR_MEMORY;
732 /*********************************************************************
734 * Function : cgi_send_default_favicon
736 * Description : CGI function that sends the standard favicon.
739 * 1 : csp = Current client state (buffers, headers, etc...)
740 * 2 : rsp = http_response data structure for output
741 * 3 : parameters = map of cgi parameters
743 * CGI Parameters : None
745 * Returns : JB_ERR_OK on success
746 * JB_ERR_MEMORY on out-of-memory error.
748 *********************************************************************/
749 jb_err cgi_send_default_favicon(struct client_state *csp,
750 struct http_response *rsp,
751 const struct map *parameters)
753 rsp->body = bindup(default_favicon_data, default_favicon_length);
754 rsp->content_length = default_favicon_length;
756 if (rsp->body == NULL)
758 return JB_ERR_MEMORY;
761 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
763 return JB_ERR_MEMORY;
773 /*********************************************************************
775 * Function : cgi_send_error_favicon
777 * Description : CGI function that sends the favicon for error pages.
780 * 1 : csp = Current client state (buffers, headers, etc...)
781 * 2 : rsp = http_response data structure for output
782 * 3 : parameters = map of cgi parameters
784 * CGI Parameters : None
786 * Returns : JB_ERR_OK on success
787 * JB_ERR_MEMORY on out-of-memory error.
789 *********************************************************************/
790 jb_err cgi_send_error_favicon(struct client_state *csp,
791 struct http_response *rsp,
792 const struct map *parameters)
794 rsp->body = bindup(error_favicon_data, error_favicon_length);
795 rsp->content_length = error_favicon_length;
797 if (rsp->body == NULL)
799 return JB_ERR_MEMORY;
802 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
804 return JB_ERR_MEMORY;
814 /*********************************************************************
816 * Function : cgi_send_stylesheet
818 * Description : CGI function that sends a css stylesheet found
819 * in the cgi-style.css template
822 * 1 : csp = Current client state (buffers, headers, etc...)
823 * 2 : rsp = http_response data structure for output
824 * 3 : parameters = map of cgi parameters
826 * CGI Parameters : None
828 * Returns : JB_ERR_OK on success
829 * JB_ERR_MEMORY on out-of-memory error.
831 *********************************************************************/
832 jb_err cgi_send_stylesheet(struct client_state *csp,
833 struct http_response *rsp,
834 const struct map *parameters)
841 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
843 if (err == JB_ERR_FILE)
846 * No way to tell user; send empty stylesheet
848 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
852 return err; /* JB_ERR_MEMORY */
855 if (enlist(rsp->headers, "Content-Type: text/css"))
857 return JB_ERR_MEMORY;
863 /*********************************************************************
865 * Function : cgi_send_user_manual
867 * Description : CGI function that sends a file in the user
871 * 1 : csp = Current client state (buffers, headers, etc...)
872 * 2 : rsp = http_response data structure for output
873 * 3 : parameters = map of cgi parameters
875 * CGI Parameters : file=name.html, the name of the HTML file
876 * (relative to user-manual from config)
878 * Returns : JB_ERR_OK on success
879 * JB_ERR_MEMORY on out-of-memory error.
881 *********************************************************************/
882 jb_err cgi_send_user_manual(struct client_state *csp,
883 struct http_response *rsp,
884 const struct map *parameters)
886 const char * filename;
889 jb_err err = JB_ERR_OK;
896 if (!parameters->first)
898 /* requested http://p.p/user-manual (without trailing slash) */
899 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
902 get_string_param(parameters, "file", &filename);
903 /* Check paramter for hack attempts */
904 if (filename && strchr(filename, '/'))
906 return JB_ERR_CGI_PARAMS;
908 if (filename && strstr(filename, ".."))
910 return JB_ERR_CGI_PARAMS;
913 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
914 if (full_path == NULL)
916 return JB_ERR_MEMORY;
919 /* Open user-manual file */
920 if (NULL == (fp = fopen(full_path, "rb")))
922 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
923 err = cgi_error_no_template(csp, rsp, full_path);
928 /* Get file length */
929 fseek(fp, 0, SEEK_END);
930 length = (size_t)ftell(fp);
931 fseek(fp, 0, SEEK_SET);
933 /* Allocate memory and load the file directly into the body */
934 rsp->body = (char *)zalloc(length+1);
939 return JB_ERR_MEMORY;
941 if (!fread(rsp->body, length, 1, fp))
944 * May happen if the file size changes between fseek() and fread().
945 * If it does, we just log it and serve what we got.
947 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
952 rsp->content_length = length;
954 /* Guess correct Content-Type based on the filename's ending */
957 length = strlen(filename);
963 if((length>=4) && !strcmp(&filename[length-4], ".css"))
965 err = enlist(rsp->headers, "Content-Type: text/css");
967 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
969 err = enlist(rsp->headers, "Content-Type: image/jpeg");
973 err = enlist(rsp->headers, "Content-Type: text/html");
980 /*********************************************************************
982 * Function : cgi_show_version
984 * Description : CGI function that returns a a web page describing the
985 * file versions of Privoxy.
988 * 1 : csp = Current client state (buffers, headers, etc...)
989 * 2 : rsp = http_response data structure for output
990 * 3 : parameters = map of cgi parameters
992 * CGI Parameters : none
994 * Returns : JB_ERR_OK on success
995 * JB_ERR_MEMORY on out-of-memory error.
997 *********************************************************************/
998 jb_err cgi_show_version(struct client_state *csp,
999 struct http_response *rsp,
1000 const struct map *parameters)
1002 struct map *exports;
1008 if (NULL == (exports = default_exports(csp, "show-version")))
1010 return JB_ERR_MEMORY;
1013 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1016 return JB_ERR_MEMORY;
1019 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1023 /*********************************************************************
1025 * Function : cgi_show_status
1027 * Description : CGI function that returns a web page describing the
1028 * current status of Privoxy.
1031 * 1 : csp = Current client state (buffers, headers, etc...)
1032 * 2 : rsp = http_response data structure for output
1033 * 3 : parameters = map of cgi parameters
1036 * file : Which file to show. Only first letter is checked,
1038 * - "p"ermissions (actions) file
1041 * Default is to show menu and other information.
1043 * Returns : JB_ERR_OK on success
1044 * JB_ERR_MEMORY on out-of-memory error.
1046 *********************************************************************/
1047 jb_err cgi_show_status(struct client_state *csp,
1048 struct http_response *rsp,
1049 const struct map *parameters)
1056 char buf[BUFFER_SIZE];
1057 const char * filename = NULL;
1058 char * file_description = NULL;
1059 #ifdef FEATURE_STATISTICS
1060 float perc_rej; /* Percentage of http requests rejected */
1061 int local_urls_read;
1062 int local_urls_rejected;
1063 #endif /* ndef FEATURE_STATISTICS */
1064 jb_err err = JB_ERR_OK;
1066 struct map *exports;
1072 if (NULL == (exports = default_exports(csp, "show-status")))
1074 return JB_ERR_MEMORY;
1077 switch (*(lookup(parameters, "file")))
1080 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1082 filename = csp->actions_list[i]->filename;
1083 file_description = "Actions File";
1088 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1090 filename = csp->rlist[i]->filename;
1091 file_description = "Filter File";
1095 #ifdef FEATURE_TRUST
1099 filename = csp->tlist->filename;
1100 file_description = "Trust File";
1103 #endif /* def FEATURE_TRUST */
1106 if (NULL != filename)
1108 if ( map(exports, "file-description", 1, file_description, 1)
1109 || map(exports, "filepath", 1, html_encode(filename), 0) )
1112 return JB_ERR_MEMORY;
1115 if ((fp = fopen(filename, "r")) == NULL)
1117 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1120 return JB_ERR_MEMORY;
1126 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1128 string_join (&s, html_encode(buf));
1132 if (map(exports, "contents", 1, s, 0))
1135 return JB_ERR_MEMORY;
1139 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1143 for (j = 0; (s != NULL) && (j < Argc); j++)
1145 if (!err) err = string_join (&s, html_encode(Argv[j]));
1146 if (!err) err = string_append(&s, " ");
1148 if (!err) err = map(exports, "invocation", 1, s, 0);
1150 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1151 if (!err) err = show_defines(exports);
1156 return JB_ERR_MEMORY;
1159 #ifdef FEATURE_STATISTICS
1160 local_urls_read = urls_read;
1161 local_urls_rejected = urls_rejected;
1164 * Need to alter the stats not to include the fetch of this
1167 * Can't do following thread safely! doh!
1170 * urls_rejected--; * This will be incremented subsequently *
1173 if (local_urls_read == 0)
1175 if (!err) err = map_block_killer(exports, "have-stats");
1179 if (!err) err = map_block_killer(exports, "have-no-stats");
1181 perc_rej = (float)local_urls_rejected * 100.0F /
1182 (float)local_urls_read;
1184 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1185 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1187 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1188 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1190 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1191 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1194 #else /* ndef FEATURE_STATISTICS */
1195 err = err || map_block_killer(exports, "statistics");
1196 #endif /* ndef FEATURE_STATISTICS */
1199 * List all action files in use, together with view and edit links,
1200 * except for standard.action, which should only be viewable. (Not
1201 * enforced in the editor itself)
1202 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1205 for (i = 0; i < MAX_AF_FILES; i++)
1207 if (csp->actions_list[i] != NULL)
1209 if (!err) err = string_append(&s, "<tr><td>");
1210 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1211 snprintf(buf, sizeof(buf),
1212 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1213 if (!err) err = string_append(&s, buf);
1215 #ifdef FEATURE_CGI_EDIT_ACTIONS
1216 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
1219 if (access(csp->config->actions_file[i], W_OK) == 0)
1221 #endif /* def HAVE_ACCESS */
1222 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1223 if (!err) err = string_append(&s, buf);
1228 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1230 #endif /* def HAVE_ACCESS */
1234 if (!err) err = string_append(&s, "</td></tr>\n");
1239 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1243 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1247 * List all re_filterfiles in use, together with view options.
1248 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1251 for (i = 0; i < MAX_AF_FILES; i++)
1253 if (csp->rlist[i] != NULL)
1255 if (!err) err = string_append(&s, "<tr><td>");
1256 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1258 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1259 if (!err) err = string_append(&s, buf);
1260 if (!err) err = string_append(&s, "</td></tr>\n");
1265 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1269 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1270 if (!err) err = map_block_killer(exports, "have-filterfile");
1273 #ifdef FEATURE_TRUST
1276 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1280 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1281 if (!err) err = map_block_killer(exports, "have-trustfile");
1284 if (!err) err = map_block_killer(exports, "trust-support");
1285 #endif /* ndef FEATURE_TRUST */
1290 return JB_ERR_MEMORY;
1293 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1297 /*********************************************************************
1299 * Function : cgi_show_url_info
1301 * Description : CGI function that determines and shows which actions
1302 * Privoxy will perform for a given url, and which
1303 * matches starting from the defaults have lead to that.
1306 * 1 : csp = Current client state (buffers, headers, etc...)
1307 * 2 : rsp = http_response data structure for output
1308 * 3 : parameters = map of cgi parameters
1311 * url : The url whose actions are to be determined.
1312 * If url is unset, the url-given conditional will be
1313 * set, so that all but the form can be suppressed in
1316 * Returns : JB_ERR_OK on success
1317 * JB_ERR_MEMORY on out-of-memory error.
1319 *********************************************************************/
1320 jb_err cgi_show_url_info(struct client_state *csp,
1321 struct http_response *rsp,
1322 const struct map *parameters)
1325 struct map *exports;
1332 if (NULL == (exports = default_exports(csp, "show-url-info")))
1334 return JB_ERR_MEMORY;
1338 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1340 url_param = strdup(lookup(parameters, "url"));
1341 if (url_param == NULL)
1344 return JB_ERR_MEMORY;
1349 * Handle prefixes. 4 possibilities:
1350 * 1) "http://" or "https://" prefix present and followed by URL - OK
1351 * 2) Only the "http://" or "https://" part is present, no URL - change
1352 * to empty string so it will be detected later as "no URL".
1353 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1355 * 4) Parameter not specified or is empty string - let this fall through
1356 * for now, next block of code will handle it.
1358 if (0 == strncmp(url_param, "http://", 7))
1360 if (url_param[7] == '\0')
1363 * Empty URL (just prefix).
1364 * Make it totally empty so it's caught by the next if()
1366 url_param[0] = '\0';
1369 else if (0 == strncmp(url_param, "https://", 8))
1371 if (url_param[8] == '\0')
1374 * Empty URL (just prefix).
1375 * Make it totally empty so it's caught by the next if()
1377 url_param[0] = '\0';
1380 else if (url_param[0] != '\0')
1383 * Unknown prefix - assume http://
1385 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1386 if (NULL == url_param_prefixed)
1390 return JB_ERR_MEMORY;
1392 strcpy(url_param_prefixed, "http://");
1393 strcpy(url_param_prefixed + 7, url_param);
1395 url_param = url_param_prefixed;
1399 * Hide "toggle off" warning if Privoxy is toggled on.
1402 #ifdef FEATURE_TOGGLE
1403 (global_toggle_state == 1) &&
1404 #endif /* def FEATURE_TOGGLE */
1405 map_block_killer(exports, "privoxy-is-toggled-off")
1409 return JB_ERR_MEMORY;
1412 if (url_param[0] == '\0')
1414 /* URL paramater not specified, display query form only. */
1416 if (map_block_killer(exports, "url-given")
1417 || map(exports, "url", 1, "", 1))
1420 return JB_ERR_MEMORY;
1425 /* Given a URL, so query it. */
1430 struct file_list *fl;
1431 struct url_actions *b;
1432 struct http_request url_to_query[1];
1433 struct current_action_spec action[1];
1436 if (map(exports, "url", 1, html_encode(url_param), 0))
1440 return JB_ERR_MEMORY;
1443 init_current_action(action);
1445 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1447 free_current_action(action);
1450 return JB_ERR_MEMORY;
1453 err = parse_http_url(url_param, url_to_query, csp);
1457 if (err == JB_ERR_MEMORY)
1459 free_http_request(url_to_query);
1460 free_current_action(action);
1462 return JB_ERR_MEMORY;
1468 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1469 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1471 free_current_action(action);
1472 free_http_request(url_to_query);
1477 return JB_ERR_MEMORY;
1480 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1484 * We have a warning about SSL paths. Hide it for insecure sites.
1486 if (!url_to_query->ssl)
1488 if (map_block_killer(exports, "https"))
1490 free_current_action(action);
1492 free_http_request(url_to_query);
1493 return JB_ERR_MEMORY;
1497 matches = strdup("<table summary=\"\" class=\"transparent\">");
1499 for (i = 0; i < MAX_AF_FILES; i++)
1501 if (NULL == csp->config->actions_file_short[i]
1502 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1506 if ((fl = csp->actions_list[i]) != NULL)
1508 if ((b = fl->f) != NULL)
1510 /* FIXME: Hardcoded HTML! */
1511 string_append(&matches, "<tr><th>In file: ");
1512 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1513 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1514 string_append(&matches, buf);
1515 string_append(&matches, "View</a>");
1516 #ifdef FEATURE_CGI_EDIT_ACTIONS
1517 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/edit-actions-list?f=%d\">", i);
1518 string_append(&matches, buf);
1519 string_append(&matches, "Edit</a>");
1521 string_append(&matches, "</th></tr>\n");
1528 for (; (b != NULL) && (matches != NULL); b = b->next)
1530 if (url_match(b->url, url_to_query))
1532 string_append(&matches, "<tr><td>{");
1533 string_join (&matches, actions_to_html(csp, b->action));
1534 string_append(&matches, " }<br>\n<code>");
1535 string_join (&matches, html_encode(b->url->spec));
1536 string_append(&matches, "</code></td></tr>\n");
1538 if (merge_current_action(action, b->action))
1541 free_http_request(url_to_query);
1542 free_current_action(action);
1544 return JB_ERR_MEMORY;
1552 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1555 string_append(&matches, "</table>\n");
1558 * Fill in forwarding settings.
1560 * The possibilities are:
1562 * - http forwarding only
1563 * - socks4(a) forwarding only
1564 * - socks4(a) and http forwarding.
1566 * XXX: Parts of this code could be reused for the
1567 * "forwarding-failed" template which currently doesn't
1568 * display the proxy port and an eventuell second forwarder.
1571 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1573 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1575 if (!err) err = map_block_killer(exports, "socks-forwarder");
1576 if (!err) err = map_block_killer(exports, "http-forwarder");
1580 char port[10]; /* We save proxy ports as int but need a string here */
1582 if (!err) err = map_block_killer(exports, "no-forwarder");
1584 if (fwd->gateway_host != NULL)
1586 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1587 "socks4" : "socks4a", 1);
1588 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1589 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1590 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1594 if (!err) err = map_block_killer(exports, "socks-forwarder");
1597 if (fwd->forward_host != NULL)
1599 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1600 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1601 if (!err) err = map(exports, "forward-port", 1, port, 1);
1605 if (!err) err = map_block_killer(exports, "http-forwarder");
1610 free_http_request(url_to_query);
1612 if (err || matches == NULL)
1614 free_current_action(action);
1616 return JB_ERR_MEMORY;
1619 if (map(exports, "matches", 1, matches , 0))
1621 free_current_action(action);
1623 return JB_ERR_MEMORY;
1626 s = current_action_to_html(csp, action);
1628 free_current_action(action);
1630 if (map(exports, "final", 1, s, 0))
1633 return JB_ERR_MEMORY;
1637 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1641 /*********************************************************************
1643 * Function : cgi_robots_txt
1645 * Description : CGI function to return "/robots.txt".
1648 * 1 : csp = Current client state (buffers, headers, etc...)
1649 * 2 : rsp = http_response data structure for output
1650 * 3 : parameters = map of cgi parameters
1652 * CGI Parameters : None
1654 * Returns : JB_ERR_OK on success
1655 * JB_ERR_MEMORY on out-of-memory error.
1657 *********************************************************************/
1658 jb_err cgi_robots_txt(struct client_state *csp,
1659 struct http_response *rsp,
1660 const struct map *parameters)
1666 "# This is the Privoxy control interface.\n"
1667 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1673 if (rsp->body == NULL)
1675 return JB_ERR_MEMORY;
1678 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1682 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1683 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1685 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1689 /*********************************************************************
1691 * Function : show_defines
1693 * Description : Add to a map the state od all conditional #defines
1694 * used when building
1697 * 1 : exports = map to extend
1699 * Returns : JB_ERR_OK on success
1700 * JB_ERR_MEMORY on out-of-memory error.
1702 *********************************************************************/
1703 static jb_err show_defines(struct map *exports)
1705 jb_err err = JB_ERR_OK;
1708 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1709 #else /* ifndef FEATURE_ACL */
1710 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1711 #endif /* ndef FEATURE_ACL */
1713 #ifdef FEATURE_CGI_EDIT_ACTIONS
1714 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1715 #else /* ifndef FEATURE_COOKIE_JAR */
1716 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1717 #endif /* ndef FEATURE_COOKIE_JAR */
1719 #ifdef FEATURE_COOKIE_JAR
1720 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1721 #else /* ifndef FEATURE_COOKIE_JAR */
1722 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1723 #endif /* ndef FEATURE_COOKIE_JAR */
1725 #ifdef FEATURE_FAST_REDIRECTS
1726 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1727 #else /* ifndef FEATURE_FAST_REDIRECTS */
1728 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1729 #endif /* ndef FEATURE_FAST_REDIRECTS */
1731 #ifdef FEATURE_FORCE_LOAD
1732 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1733 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1734 #else /* ifndef FEATURE_FORCE_LOAD */
1735 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1736 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1737 #endif /* ndef FEATURE_FORCE_LOAD */
1739 #ifdef FEATURE_GRACEFUL_TERMINATION
1740 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1741 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1742 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1743 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1745 #ifdef FEATURE_IMAGE_BLOCKING
1746 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1747 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1748 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1749 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1751 #ifdef FEATURE_IMAGE_DETECT_MSIE
1752 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1753 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1754 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1755 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1757 #ifdef FEATURE_KILL_POPUPS
1758 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1759 #else /* ifndef FEATURE_KILL_POPUPS */
1760 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1761 #endif /* ndef FEATURE_KILL_POPUPS */
1763 #ifdef FEATURE_NO_GIFS
1764 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1765 #else /* ifndef FEATURE_NO_GIFS */
1766 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1767 #endif /* ndef FEATURE_NO_GIFS */
1769 #ifdef FEATURE_PTHREAD
1770 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1771 #else /* ifndef FEATURE_PTHREAD */
1772 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1773 #endif /* ndef FEATURE_PTHREAD */
1775 #ifdef FEATURE_STATISTICS
1776 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1777 #else /* ifndef FEATURE_STATISTICS */
1778 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1779 #endif /* ndef FEATURE_STATISTICS */
1781 #ifdef FEATURE_TOGGLE
1782 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1783 #else /* ifndef FEATURE_TOGGLE */
1784 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1785 #endif /* ndef FEATURE_TOGGLE */
1787 #ifdef FEATURE_TRUST
1788 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1789 #else /* ifndef FEATURE_TRUST */
1790 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1791 #endif /* ndef FEATURE_TRUST */
1794 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1795 #else /* ifndef FEATURE_ZLIB */
1796 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1797 #endif /* ndef FEATURE_ZLIB */
1800 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1801 #else /* ifndef STATIC_PCRE */
1802 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1803 #endif /* ndef STATIC_PCRE */
1806 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1807 #else /* ifndef STATIC_PCRS */
1808 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1809 #endif /* ndef STATIC_PCRS */
1815 /*********************************************************************
1817 * Function : show_rcs
1819 * Description : Create a string with the rcs info for all sourcefiles
1823 * Returns : A string, or NULL on out-of-memory.
1825 *********************************************************************/
1826 static char *show_rcs(void)
1828 char *result = strdup("");
1829 char buf[BUFFER_SIZE];
1831 /* Instead of including *all* dot h's in the project (thus creating a
1832 * tremendous amount of dependencies), I will concede to declaring them
1833 * as extern's. This forces the developer to add to this list, but oh well.
1836 #define SHOW_RCS(__x) \
1838 extern const char __x[]; \
1839 snprintf(buf, sizeof(buf), " %s\n", __x); \
1840 string_append(&result, buf); \
1843 /* In alphabetical order */
1844 SHOW_RCS(actions_h_rcs)
1845 SHOW_RCS(actions_rcs)
1847 SHOW_RCS(amiga_h_rcs)
1849 #endif /* def AMIGA */
1852 #ifdef FEATURE_CGI_EDIT_ACTIONS
1853 SHOW_RCS(cgiedit_h_rcs)
1854 SHOW_RCS(cgiedit_rcs)
1855 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1856 SHOW_RCS(cgisimple_h_rcs)
1857 SHOW_RCS(cgisimple_rcs)
1859 SHOW_RCS(cygwin_h_rcs)
1861 SHOW_RCS(deanimate_h_rcs)
1862 SHOW_RCS(deanimate_rcs)
1863 SHOW_RCS(encode_h_rcs)
1864 SHOW_RCS(encode_rcs)
1865 SHOW_RCS(errlog_h_rcs)
1866 SHOW_RCS(errlog_rcs)
1867 SHOW_RCS(filters_h_rcs)
1868 SHOW_RCS(filters_rcs)
1869 SHOW_RCS(gateway_h_rcs)
1870 SHOW_RCS(gateway_rcs)
1871 SHOW_RCS(jbsockets_h_rcs)
1872 SHOW_RCS(jbsockets_rcs)
1875 #ifdef FEATURE_KILL_POPUPS
1876 SHOW_RCS(killpopup_h_rcs)
1877 SHOW_RCS(killpopup_rcs)
1878 #endif /* def FEATURE_KILL_POPUPS */
1879 SHOW_RCS(list_h_rcs)
1881 SHOW_RCS(loadcfg_h_rcs)
1882 SHOW_RCS(loadcfg_rcs)
1883 SHOW_RCS(loaders_h_rcs)
1884 SHOW_RCS(loaders_rcs)
1885 SHOW_RCS(miscutil_h_rcs)
1886 SHOW_RCS(miscutil_rcs)
1887 SHOW_RCS(parsers_h_rcs)
1888 SHOW_RCS(parsers_rcs)
1890 SHOW_RCS(pcrs_h_rcs)
1891 SHOW_RCS(project_h_rcs)
1892 SHOW_RCS(ssplit_h_rcs)
1893 SHOW_RCS(ssplit_rcs)
1894 SHOW_RCS(urlmatch_h_rcs)
1895 SHOW_RCS(urlmatch_rcs)
1897 #ifndef _WIN_CONSOLE
1898 SHOW_RCS(w32log_h_rcs)
1899 SHOW_RCS(w32log_rcs)
1900 SHOW_RCS(w32res_h_rcs)
1901 SHOW_RCS(w32taskbar_h_rcs)
1902 SHOW_RCS(w32taskbar_rcs)
1903 #endif /* ndef _WIN_CONSOLE */
1904 SHOW_RCS(win32_h_rcs)
1906 #endif /* def _WIN32 */