1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.58 2007/07/21 12:19:50 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.58 2007/07/21 12:19:50 fabiankeil
40 * If show-url-info is called with an URL that Privoxy
41 * would reject as invalid, don't show unresolved forwarding
42 * variables, "final matches" or claim the site's secure.
44 * Revision 1.57 2007/06/01 16:53:05 fabiankeil
45 * Adjust cgi_show_url_info() to show what forward-override{}
46 * would do with the requested URL (instead of showing how the
47 * request for the CGI page would be forwarded if it wasn't a
50 * Revision 1.56 2007/05/21 10:50:35 fabiankeil
51 * - Use strlcpy() instead of strcpy().
52 * - Stop treating actions files special. Expect a complete file name
53 * (with or without path) like it's done for the rest of the files.
55 * - Don't rerun sed() in cgi_show_request().
57 * Revision 1.55 2007/04/13 13:36:46 fabiankeil
58 * Reference action files in CGI URLs by id instead
59 * of using the first part of the file name.
60 * Fixes BR 1694250 and BR 1590556.
62 * Revision 1.54 2007/04/09 18:11:35 fabiankeil
63 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
65 * Revision 1.53 2007/04/08 13:21:04 fabiankeil
66 * Reference action files in CGI URLs by id instead
67 * of using the first part of the file name.
68 * Fixes BR 1694250 and BR 1590556.
70 * Revision 1.52 2007/02/13 15:10:26 fabiankeil
71 * Apparently fopen()ing in "binary" mode doesn't require
72 * #ifdefs, it's already done without them in cgiedit.c.
74 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
75 * - Show forwarding settings on the show-url-info page
76 * - Fix some HTML syntax errors.
78 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
79 * Add favicon delivery functions.
81 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
82 * Suppress edit buttons for action files if Privoxy has
83 * no write access. Suggested by Roland in PR 1564026.
85 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
86 * Display warning if show-url-info CGI page
87 * is used while Privoxy is toggled off.
89 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
90 * Use zalloc in cgi_send_user_manual.
92 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
93 * Add FEATURE_ZLIB to the list of conditional
94 * defines at the show-status page.
96 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
97 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
98 * body memory before using it, replaced sprintf calls with snprintf.
100 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
101 * Removed checks whether or not AF_FILES have
102 * data structures associated with them in cgi_show_status.
103 * It doesn't matter as we're only interested in the file names.
105 * For the action files the checks were always true,
106 * but they prevented empty filter files from being
107 * listed. Fixes parts of BR 1619208.
109 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
110 * - Added FEATURE_GRACEFUL_TERMINATION to the
111 * "conditional #defines" section
112 * - Escaped ampersands in generated HTML.
113 * - Renamed re-filter-filename to re-filter-filenames
115 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
116 * Add special treatment for WIN32 to make sure
117 * cgi_send_user_manual opens the files in binary mode.
118 * Fixes BR 1600411 and unbreaks image delivery.
120 * Remove outdated comment.
122 * Revision 1.41 2006/10/09 19:18:28 roro
123 * Redirect http://p.p/user-manual (without trailing slash) to
124 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
126 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
127 * Modified cgi_send_user_manual to serve binary
128 * content without destroying it first. Should also be
129 * faster now. Added ".jpg" check for Content-Type guessing.
131 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
132 * Deliver documents in the user-manual directory
133 * with "Content-Type text/css" if their filename
136 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
137 * Incorporate modified version of Roland Rosenfeld's patch to
138 * optionally access the user-manual via Privoxy. Closes patch 679075.
140 * Formatting changed to Privoxy style, added call to
141 * cgi_error_no_template if the requested file doesn't
142 * exist and modified check whether or not Privoxy itself
143 * should serve the manual. Should work cross-platform now.
145 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
146 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
147 * with what was really the latest development (the v_3_0_branch branch)
149 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
150 * Multiple filter file support
152 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
153 * Undo some damaging memory leak patches
155 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
156 * A few memory leaks plugged (mostly on error paths)
158 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
159 * Another instance of:
160 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
161 * Thanks to Magnus Holmgren for the patch
163 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
164 * - Prevent line wrap beween "View/Edit" link buttons on status page
165 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
167 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
168 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
170 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
171 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
173 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
174 * Applying patch from Andreas as provided by Hal on the list.
175 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
177 * Revision 1.35 2002/05/12 21:44:44 jongfoster
178 * Adding amiga.[ch] revision information, if on an amiga.
180 * Revision 1.34 2002/04/30 12:06:12 oes
181 * Deleted unused code from default_cgi
183 * Revision 1.33 2002/04/30 11:14:52 oes
184 * Made csp the first parameter in *action_to_html
186 * Revision 1.32 2002/04/26 18:29:13 jongfoster
187 * Fixing this Visual C++ warning:
188 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
190 * Revision 1.31 2002/04/26 12:54:36 oes
191 * - Kill obsolete REDIRECT_URL code
192 * - Error handling fixes
193 * - Style sheet related HTML snipplet changes
194 * - cgi_show_url_info:
195 * - Matches now in table, actions on single lines,
197 * - standard.action suppressed
198 * - Buttons to View and Edit AFs
200 * Revision 1.30 2002/04/24 02:18:08 oes
201 * - show-status is now the starting point for editing
202 * the actions files, generate list of all AFs with buttons
203 * for viewing and editing, new look for file list (Jon:
204 * buttons now aligned ;-P ), view mode now supports multiple
205 * AFs, name changes, no view links for unspecified files,
206 * no edit link for standard.action.
208 * - Jon's multiple AF patch: cgi_show_url_info now uses all
209 * AFs and marks the output accordingly
211 * Revision 1.29 2002/04/10 13:38:35 oes
212 * load_template signature changed
214 * Revision 1.28 2002/04/07 15:42:12 jongfoster
215 * Fixing send-banner?type=auto when the image-blocker is
216 * a redirect to send-banner
218 * Revision 1.27 2002/04/05 15:50:48 oes
219 * added send-stylesheet CGI
221 * Revision 1.26 2002/04/04 00:36:36 gliptak
222 * always use pcre for matching
224 * Revision 1.25 2002/04/03 22:28:03 gliptak
225 * Removed references to gnu_regex
227 * Revision 1.24 2002/04/02 16:12:47 oes
228 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
230 * Revision 1.23 2002/03/26 22:29:54 swa
231 * we have a new homepage!
233 * Revision 1.22 2002/03/24 16:18:15 jongfoster
236 * Revision 1.21 2002/03/24 15:23:33 jongfoster
239 * Revision 1.20 2002/03/24 13:25:43 swa
240 * name change related issues
242 * Revision 1.19 2002/03/16 23:54:06 jongfoster
243 * Adding graceful termination feature, to help look for memory leaks.
244 * If you enable this (which, by design, has to be done by hand
245 * editing config.h) and then go to http://i.j.b/die, then the program
246 * will exit cleanly after the *next* request. It should free all the
247 * memory that was used.
249 * Revision 1.18 2002/03/12 01:44:49 oes
250 * Changed default for "blocked" image from jb logo to checkboard pattern
252 * Revision 1.17 2002/03/08 16:43:18 oes
253 * Added choice beween GIF and PNG built-in images
255 * Revision 1.16 2002/03/07 03:48:38 oes
256 * - Changed built-in images from GIF to PNG
257 * (with regard to Unisys patent issue)
258 * - Added a 4x4 pattern PNG which is less intrusive
259 * than the logo but also clearly marks the deleted banners
261 * Revision 1.15 2002/03/06 22:54:35 jongfoster
262 * Automated function-comment nitpicking.
264 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
265 * Clean up a little CRLF unpleasantness that suddenly appeared
267 * Revision 1.13 2002/02/21 00:10:37 jongfoster
268 * Adding send-banner?type=auto option
270 * Revision 1.12 2002/01/23 01:03:32 jongfoster
271 * Fixing gcc [CygWin] compiler warnings
273 * Revision 1.11 2002/01/23 00:01:04 jongfoster
274 * Adding cgi_transparent_gif() for http://i.j.b/t
275 * Adding missing html_encode() to many CGI functions.
276 * Adding urlmatch.[ch] to http://i.j.b/show-version
278 * Revision 1.10 2002/01/17 21:10:37 jongfoster
279 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
280 * Also fixing a problem in the same function with improperly quoted URLs
281 * in output HTML, and adding code to handle https:// URLs correctly.
283 * Revision 1.9 2001/11/30 23:09:15 jongfoster
284 * Now reports on FEATURE_CGI_EDIT_ACTIONS
285 * Removing FEATURE_DENY_GZIP from template
287 * Revision 1.8 2001/11/13 00:14:07 jongfoster
288 * Fixing stupid bug now I've figured out what || means.
289 * (It always returns 0 or 1, not one of it's paramaters.)
291 * Revision 1.7 2001/10/23 21:48:19 jongfoster
292 * Cleaning up error handling in CGI functions - they now send back
293 * a HTML error page and should never cause a FATAL error. (Fixes one
294 * potential source of "denial of service" attacks).
296 * CGI actions file editor that works and is actually useful.
298 * Ability to toggle JunkBuster remotely using a CGI call.
300 * You can turn off both the above features in the main configuration
301 * file, e.g. if you are running a multi-user proxy.
303 * Revision 1.6 2001/10/14 22:00:32 jongfoster
304 * Adding support for a 404 error when an invalid CGI page is requested.
306 * Revision 1.5 2001/10/07 15:30:41 oes
307 * Removed FEATURE_DENY_GZIP
309 * Revision 1.4 2001/10/02 15:31:12 oes
310 * Introduced show-request cgi
312 * Revision 1.3 2001/09/22 16:34:44 jongfoster
313 * Removing unneeded #includes
315 * Revision 1.2 2001/09/19 18:01:11 oes
316 * Fixed comments; cosmetics
318 * Revision 1.1 2001/09/16 17:08:54 jongfoster
319 * Moving simple CGI functions from cgi.c to new file cgisimple.c
322 **********************************************************************/
328 #include <sys/types.h>
336 #endif /* def HAVE_ACCESS */
340 #include "cgisimple.h"
346 #include "miscutil.h"
349 #include "urlmatch.h"
352 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
355 static char *show_rcs(void);
356 static jb_err show_defines(struct map *exports);
359 * 16x16 ico blobs for favicon delivery functions.
361 const char default_favicon_data[] =
362 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
363 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
364 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
365 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
366 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
367 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
368 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
369 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
370 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
371 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
372 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
373 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
374 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
376 const char error_favicon_data[] =
377 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
378 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
379 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
380 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
381 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
382 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
383 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
384 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
385 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
386 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
387 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
388 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
389 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
391 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
392 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
394 /*********************************************************************
396 * Function : cgi_default
398 * Description : CGI function that is called for the CGI_SITE_1_HOST
399 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
400 * Boring - only exports the default exports.
403 * 1 : csp = Current client state (buffers, headers, etc...)
404 * 2 : rsp = http_response data structure for output
405 * 3 : parameters = map of cgi parameters
407 * CGI Parameters : none
409 * Returns : JB_ERR_OK on success
410 * JB_ERR_MEMORY on out-of-memory
412 *********************************************************************/
413 jb_err cgi_default(struct client_state *csp,
414 struct http_response *rsp,
415 const struct map *parameters)
422 if (NULL == (exports = default_exports(csp, "")))
424 return JB_ERR_MEMORY;
427 return template_fill_for_cgi(csp, "default", exports, rsp);
431 /*********************************************************************
433 * Function : cgi_error_404
435 * Description : CGI function that is called if an unknown action was
439 * 1 : csp = Current client state (buffers, headers, etc...)
440 * 2 : rsp = http_response data structure for output
441 * 3 : parameters = map of cgi parameters
443 * CGI Parameters : none
445 * Returns : JB_ERR_OK on success
446 * JB_ERR_MEMORY on out-of-memory error.
448 *********************************************************************/
449 jb_err cgi_error_404(struct client_state *csp,
450 struct http_response *rsp,
451 const struct map *parameters)
459 if (NULL == (exports = default_exports(csp, NULL)))
461 return JB_ERR_MEMORY;
464 rsp->status = strdup("404 Privoxy configuration page not found");
465 if (rsp->status == NULL)
468 return JB_ERR_MEMORY;
471 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
475 #ifdef FEATURE_GRACEFUL_TERMINATION
476 /*********************************************************************
480 * Description : CGI function to shut down Privoxy.
481 * NOTE: Turning this on in a production build
482 * would be a BAD idea. An EXTREMELY BAD idea.
483 * In short, don't do it.
486 * 1 : csp = Current client state (buffers, headers, etc...)
487 * 2 : rsp = http_response data structure for output
488 * 3 : parameters = map of cgi parameters
490 * CGI Parameters : none
492 * Returns : JB_ERR_OK on success
493 * JB_ERR_MEMORY on out-of-memory error.
495 *********************************************************************/
496 jb_err cgi_die (struct client_state *csp,
497 struct http_response *rsp,
498 const struct map *parameters)
508 * I don't really care what gets sent back to the browser.
509 * Take the easy option - "out of memory" page.
512 return JB_ERR_MEMORY;
514 #endif /* def FEATURE_GRACEFUL_TERMINATION */
517 /*********************************************************************
519 * Function : cgi_show_request
521 * Description : Show the client's request and what sed() would have
525 * 1 : csp = Current client state (buffers, headers, etc...)
526 * 2 : rsp = http_response data structure for output
527 * 3 : parameters = map of cgi parameters
529 * CGI Parameters : none
531 * Returns : JB_ERR_OK on success
532 * JB_ERR_MEMORY on out-of-memory error.
534 *********************************************************************/
535 jb_err cgi_show_request(struct client_state *csp,
536 struct http_response *rsp,
537 const struct map *parameters)
546 if (NULL == (exports = default_exports(csp, "show-request")))
548 return JB_ERR_MEMORY;
552 * Repair the damage done to the IOB by get_header()
554 for (p = csp->iob->buf; p < csp->iob->eod; p++)
556 if (*p == '\0') *p = '\n';
560 * Export the original client's request and the one we would
561 * be sending to the server if this wasn't a CGI call
564 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
567 return JB_ERR_MEMORY;
570 if (map(exports, "processed-request", 1,
571 html_encode_and_free_original(list_to_text(csp->headers)), 0))
574 return JB_ERR_MEMORY;
577 return template_fill_for_cgi(csp, "show-request", exports, rsp);
581 /*********************************************************************
583 * Function : cgi_send_banner
585 * Description : CGI function that returns a banner.
588 * 1 : csp = Current client state (buffers, headers, etc...)
589 * 2 : rsp = http_response data structure for output
590 * 3 : parameters = map of cgi parameters
593 * type : Selects the type of banner between "trans", "logo",
594 * and "auto". Defaults to "logo" if absent or invalid.
595 * "auto" means to select as if we were image-blocking.
596 * (Only the first character really counts; b and t are
599 * Returns : JB_ERR_OK on success
600 * JB_ERR_MEMORY on out-of-memory error.
602 *********************************************************************/
603 jb_err cgi_send_banner(struct client_state *csp,
604 struct http_response *rsp,
605 const struct map *parameters)
607 char imagetype = lookup(parameters, "type")[0];
610 * If type is auto, then determine the right thing
611 * to do from the set-image-blocker action
613 if (imagetype == 'a')
620 #ifdef FEATURE_IMAGE_BLOCKING
621 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
623 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
624 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
625 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
629 /* Use default - nothing to do here. */
631 else if (0 == strcmpic(p, "blank"))
635 else if (0 == strcmpic(p, "pattern"))
641 * If the action is to call this CGI, determine
644 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
646 imagetype = p[sizeof(prefix1) - 1];
648 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
650 imagetype = p[sizeof(prefix2) - 1];
654 * Everything else must (should) be a URL to
662 #endif /* def FEATURE_IMAGE_BLOCKING */
666 * Now imagetype is either the non-auto type we were called with,
667 * or it was auto and has since been determined. In any case, we
668 * can proceed to actually answering the request by sending a redirect
669 * or an image as appropriate:
671 if (imagetype == 'r')
673 rsp->status = strdup("302 Local Redirect from Privoxy");
674 if (rsp->status == NULL)
676 return JB_ERR_MEMORY;
678 if (enlist_unique_header(rsp->headers, "Location",
679 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
681 return JB_ERR_MEMORY;
686 if ((imagetype == 'b') || (imagetype == 't'))
688 rsp->body = bindup(image_blank_data, image_blank_length);
689 rsp->content_length = image_blank_length;
693 rsp->body = bindup(image_pattern_data, image_pattern_length);
694 rsp->content_length = image_pattern_length;
697 if (rsp->body == NULL)
699 return JB_ERR_MEMORY;
701 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
703 return JB_ERR_MEMORY;
714 /*********************************************************************
716 * Function : cgi_transparent_image
718 * Description : CGI function that sends a 1x1 transparent image.
721 * 1 : csp = Current client state (buffers, headers, etc...)
722 * 2 : rsp = http_response data structure for output
723 * 3 : parameters = map of cgi parameters
725 * CGI Parameters : None
727 * Returns : JB_ERR_OK on success
728 * JB_ERR_MEMORY on out-of-memory error.
730 *********************************************************************/
731 jb_err cgi_transparent_image(struct client_state *csp,
732 struct http_response *rsp,
733 const struct map *parameters)
735 rsp->body = bindup(image_blank_data, image_blank_length);
736 rsp->content_length = image_blank_length;
738 if (rsp->body == NULL)
740 return JB_ERR_MEMORY;
743 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
745 return JB_ERR_MEMORY;
755 /*********************************************************************
757 * Function : cgi_send_default_favicon
759 * Description : CGI function that sends the standard favicon.
762 * 1 : csp = Current client state (buffers, headers, etc...)
763 * 2 : rsp = http_response data structure for output
764 * 3 : parameters = map of cgi parameters
766 * CGI Parameters : None
768 * Returns : JB_ERR_OK on success
769 * JB_ERR_MEMORY on out-of-memory error.
771 *********************************************************************/
772 jb_err cgi_send_default_favicon(struct client_state *csp,
773 struct http_response *rsp,
774 const struct map *parameters)
776 rsp->body = bindup(default_favicon_data, default_favicon_length);
777 rsp->content_length = default_favicon_length;
779 if (rsp->body == NULL)
781 return JB_ERR_MEMORY;
784 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
786 return JB_ERR_MEMORY;
796 /*********************************************************************
798 * Function : cgi_send_error_favicon
800 * Description : CGI function that sends the favicon for error pages.
803 * 1 : csp = Current client state (buffers, headers, etc...)
804 * 2 : rsp = http_response data structure for output
805 * 3 : parameters = map of cgi parameters
807 * CGI Parameters : None
809 * Returns : JB_ERR_OK on success
810 * JB_ERR_MEMORY on out-of-memory error.
812 *********************************************************************/
813 jb_err cgi_send_error_favicon(struct client_state *csp,
814 struct http_response *rsp,
815 const struct map *parameters)
817 rsp->body = bindup(error_favicon_data, error_favicon_length);
818 rsp->content_length = error_favicon_length;
820 if (rsp->body == NULL)
822 return JB_ERR_MEMORY;
825 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
827 return JB_ERR_MEMORY;
837 /*********************************************************************
839 * Function : cgi_send_stylesheet
841 * Description : CGI function that sends a css stylesheet found
842 * in the cgi-style.css template
845 * 1 : csp = Current client state (buffers, headers, etc...)
846 * 2 : rsp = http_response data structure for output
847 * 3 : parameters = map of cgi parameters
849 * CGI Parameters : None
851 * Returns : JB_ERR_OK on success
852 * JB_ERR_MEMORY on out-of-memory error.
854 *********************************************************************/
855 jb_err cgi_send_stylesheet(struct client_state *csp,
856 struct http_response *rsp,
857 const struct map *parameters)
864 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
866 if (err == JB_ERR_FILE)
869 * No way to tell user; send empty stylesheet
871 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
875 return err; /* JB_ERR_MEMORY */
878 if (enlist(rsp->headers, "Content-Type: text/css"))
880 return JB_ERR_MEMORY;
886 /*********************************************************************
888 * Function : cgi_send_user_manual
890 * Description : CGI function that sends a file in the user
894 * 1 : csp = Current client state (buffers, headers, etc...)
895 * 2 : rsp = http_response data structure for output
896 * 3 : parameters = map of cgi parameters
898 * CGI Parameters : file=name.html, the name of the HTML file
899 * (relative to user-manual from config)
901 * Returns : JB_ERR_OK on success
902 * JB_ERR_MEMORY on out-of-memory error.
904 *********************************************************************/
905 jb_err cgi_send_user_manual(struct client_state *csp,
906 struct http_response *rsp,
907 const struct map *parameters)
909 const char * filename;
912 jb_err err = JB_ERR_OK;
919 if (!parameters->first)
921 /* requested http://p.p/user-manual (without trailing slash) */
922 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
925 get_string_param(parameters, "file", &filename);
926 /* Check paramter for hack attempts */
927 if (filename && strchr(filename, '/'))
929 return JB_ERR_CGI_PARAMS;
931 if (filename && strstr(filename, ".."))
933 return JB_ERR_CGI_PARAMS;
936 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
937 if (full_path == NULL)
939 return JB_ERR_MEMORY;
942 /* Open user-manual file */
943 if (NULL == (fp = fopen(full_path, "rb")))
945 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
946 err = cgi_error_no_template(csp, rsp, full_path);
951 /* Get file length */
952 fseek(fp, 0, SEEK_END);
953 length = (size_t)ftell(fp);
954 fseek(fp, 0, SEEK_SET);
956 /* Allocate memory and load the file directly into the body */
957 rsp->body = (char *)zalloc(length+1);
962 return JB_ERR_MEMORY;
964 if (!fread(rsp->body, length, 1, fp))
967 * May happen if the file size changes between fseek() and fread().
968 * If it does, we just log it and serve what we got.
970 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
975 rsp->content_length = length;
977 /* Guess correct Content-Type based on the filename's ending */
980 length = strlen(filename);
986 if((length>=4) && !strcmp(&filename[length-4], ".css"))
988 err = enlist(rsp->headers, "Content-Type: text/css");
990 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
992 err = enlist(rsp->headers, "Content-Type: image/jpeg");
996 err = enlist(rsp->headers, "Content-Type: text/html");
1003 /*********************************************************************
1005 * Function : cgi_show_version
1007 * Description : CGI function that returns a a web page describing the
1008 * file versions of Privoxy.
1011 * 1 : csp = Current client state (buffers, headers, etc...)
1012 * 2 : rsp = http_response data structure for output
1013 * 3 : parameters = map of cgi parameters
1015 * CGI Parameters : none
1017 * Returns : JB_ERR_OK on success
1018 * JB_ERR_MEMORY on out-of-memory error.
1020 *********************************************************************/
1021 jb_err cgi_show_version(struct client_state *csp,
1022 struct http_response *rsp,
1023 const struct map *parameters)
1025 struct map *exports;
1031 if (NULL == (exports = default_exports(csp, "show-version")))
1033 return JB_ERR_MEMORY;
1036 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1039 return JB_ERR_MEMORY;
1042 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1046 /*********************************************************************
1048 * Function : cgi_show_status
1050 * Description : CGI function that returns a web page describing the
1051 * current status of Privoxy.
1054 * 1 : csp = Current client state (buffers, headers, etc...)
1055 * 2 : rsp = http_response data structure for output
1056 * 3 : parameters = map of cgi parameters
1059 * file : Which file to show. Only first letter is checked,
1061 * - "p"ermissions (actions) file
1064 * Default is to show menu and other information.
1066 * Returns : JB_ERR_OK on success
1067 * JB_ERR_MEMORY on out-of-memory error.
1069 *********************************************************************/
1070 jb_err cgi_show_status(struct client_state *csp,
1071 struct http_response *rsp,
1072 const struct map *parameters)
1079 char buf[BUFFER_SIZE];
1080 const char * filename = NULL;
1081 char * file_description = NULL;
1082 #ifdef FEATURE_STATISTICS
1083 float perc_rej; /* Percentage of http requests rejected */
1084 int local_urls_read;
1085 int local_urls_rejected;
1086 #endif /* ndef FEATURE_STATISTICS */
1087 jb_err err = JB_ERR_OK;
1089 struct map *exports;
1095 if (NULL == (exports = default_exports(csp, "show-status")))
1097 return JB_ERR_MEMORY;
1100 switch (*(lookup(parameters, "file")))
1103 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1105 filename = csp->actions_list[i]->filename;
1106 file_description = "Actions File";
1111 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1113 filename = csp->rlist[i]->filename;
1114 file_description = "Filter File";
1118 #ifdef FEATURE_TRUST
1122 filename = csp->tlist->filename;
1123 file_description = "Trust File";
1126 #endif /* def FEATURE_TRUST */
1129 if (NULL != filename)
1131 if ( map(exports, "file-description", 1, file_description, 1)
1132 || map(exports, "filepath", 1, html_encode(filename), 0) )
1135 return JB_ERR_MEMORY;
1138 if ((fp = fopen(filename, "r")) == NULL)
1140 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1143 return JB_ERR_MEMORY;
1149 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1151 string_join (&s, html_encode(buf));
1155 if (map(exports, "contents", 1, s, 0))
1158 return JB_ERR_MEMORY;
1162 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1166 for (j = 0; (s != NULL) && (j < Argc); j++)
1168 if (!err) err = string_join (&s, html_encode(Argv[j]));
1169 if (!err) err = string_append(&s, " ");
1171 if (!err) err = map(exports, "invocation", 1, s, 0);
1173 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1174 if (!err) err = show_defines(exports);
1179 return JB_ERR_MEMORY;
1182 #ifdef FEATURE_STATISTICS
1183 local_urls_read = urls_read;
1184 local_urls_rejected = urls_rejected;
1187 * Need to alter the stats not to include the fetch of this
1190 * Can't do following thread safely! doh!
1193 * urls_rejected--; * This will be incremented subsequently *
1196 if (local_urls_read == 0)
1198 if (!err) err = map_block_killer(exports, "have-stats");
1202 if (!err) err = map_block_killer(exports, "have-no-stats");
1204 perc_rej = (float)local_urls_rejected * 100.0F /
1205 (float)local_urls_read;
1207 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1208 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1210 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1211 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1213 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1214 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1217 #else /* ndef FEATURE_STATISTICS */
1218 err = err || map_block_killer(exports, "statistics");
1219 #endif /* ndef FEATURE_STATISTICS */
1222 * List all action files in use, together with view and edit links,
1223 * except for standard.action, which should only be viewable. (Not
1224 * enforced in the editor itself)
1225 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1228 for (i = 0; i < MAX_AF_FILES; i++)
1230 if (csp->actions_list[i] != NULL)
1232 if (!err) err = string_append(&s, "<tr><td>");
1233 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1234 snprintf(buf, sizeof(buf),
1235 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1236 if (!err) err = string_append(&s, buf);
1238 #ifdef FEATURE_CGI_EDIT_ACTIONS
1239 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
1242 if (access(csp->config->actions_file[i], W_OK) == 0)
1244 #endif /* def HAVE_ACCESS */
1245 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1246 if (!err) err = string_append(&s, buf);
1251 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1253 #endif /* def HAVE_ACCESS */
1257 if (!err) err = string_append(&s, "</td></tr>\n");
1262 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1266 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1270 * List all re_filterfiles in use, together with view options.
1271 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1274 for (i = 0; i < MAX_AF_FILES; i++)
1276 if (csp->rlist[i] != NULL)
1278 if (!err) err = string_append(&s, "<tr><td>");
1279 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1281 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1282 if (!err) err = string_append(&s, buf);
1283 if (!err) err = string_append(&s, "</td></tr>\n");
1288 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1292 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1293 if (!err) err = map_block_killer(exports, "have-filterfile");
1296 #ifdef FEATURE_TRUST
1299 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1303 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1304 if (!err) err = map_block_killer(exports, "have-trustfile");
1307 if (!err) err = map_block_killer(exports, "trust-support");
1308 #endif /* ndef FEATURE_TRUST */
1313 return JB_ERR_MEMORY;
1316 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1320 /*********************************************************************
1322 * Function : cgi_show_url_info
1324 * Description : CGI function that determines and shows which actions
1325 * Privoxy will perform for a given url, and which
1326 * matches starting from the defaults have lead to that.
1329 * 1 : csp = Current client state (buffers, headers, etc...)
1330 * 2 : rsp = http_response data structure for output
1331 * 3 : parameters = map of cgi parameters
1334 * url : The url whose actions are to be determined.
1335 * If url is unset, the url-given conditional will be
1336 * set, so that all but the form can be suppressed in
1339 * Returns : JB_ERR_OK on success
1340 * JB_ERR_MEMORY on out-of-memory error.
1342 *********************************************************************/
1343 jb_err cgi_show_url_info(struct client_state *csp,
1344 struct http_response *rsp,
1345 const struct map *parameters)
1348 struct map *exports;
1355 if (NULL == (exports = default_exports(csp, "show-url-info")))
1357 return JB_ERR_MEMORY;
1361 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1363 url_param = strdup(lookup(parameters, "url"));
1364 if (url_param == NULL)
1367 return JB_ERR_MEMORY;
1372 * Handle prefixes. 4 possibilities:
1373 * 1) "http://" or "https://" prefix present and followed by URL - OK
1374 * 2) Only the "http://" or "https://" part is present, no URL - change
1375 * to empty string so it will be detected later as "no URL".
1376 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1378 * 4) Parameter not specified or is empty string - let this fall through
1379 * for now, next block of code will handle it.
1381 if (0 == strncmp(url_param, "http://", 7))
1383 if (url_param[7] == '\0')
1386 * Empty URL (just prefix).
1387 * Make it totally empty so it's caught by the next if()
1389 url_param[0] = '\0';
1392 else if (0 == strncmp(url_param, "https://", 8))
1394 if (url_param[8] == '\0')
1397 * Empty URL (just prefix).
1398 * Make it totally empty so it's caught by the next if()
1400 url_param[0] = '\0';
1403 else if (url_param[0] != '\0')
1406 * Unknown prefix - assume http://
1408 const size_t url_param_prefixed_size = 7 + 1 + strlen(url_param);
1409 char * url_param_prefixed = malloc(url_param_prefixed_size);
1410 if (NULL == url_param_prefixed)
1414 return JB_ERR_MEMORY;
1416 strlcpy(url_param_prefixed, "http://", url_param_prefixed_size);
1417 strlcat(url_param_prefixed, url_param, url_param_prefixed_size);
1419 url_param = url_param_prefixed;
1423 * Hide "toggle off" warning if Privoxy is toggled on.
1426 #ifdef FEATURE_TOGGLE
1427 (global_toggle_state == 1) &&
1428 #endif /* def FEATURE_TOGGLE */
1429 map_block_killer(exports, "privoxy-is-toggled-off")
1433 return JB_ERR_MEMORY;
1436 if (url_param[0] == '\0')
1438 /* URL paramater not specified, display query form only. */
1440 if (map_block_killer(exports, "url-given")
1441 || map(exports, "url", 1, "", 1))
1444 return JB_ERR_MEMORY;
1449 /* Given a URL, so query it. */
1454 struct file_list *fl;
1455 struct url_actions *b;
1456 struct http_request url_to_query[1];
1457 struct current_action_spec action[1];
1460 if (map(exports, "url", 1, html_encode(url_param), 0))
1464 return JB_ERR_MEMORY;
1467 init_current_action(action);
1469 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1471 free_current_action(action);
1474 return JB_ERR_MEMORY;
1477 err = parse_http_url(url_param, url_to_query, csp);
1481 if (err == JB_ERR_MEMORY)
1483 free_http_request(url_to_query);
1484 free_current_action(action);
1486 return JB_ERR_MEMORY;
1492 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1493 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1494 if (!err) err = map_block_killer(exports, "valid-url");
1496 free_current_action(action);
1497 free_http_request(url_to_query);
1502 return JB_ERR_MEMORY;
1505 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1509 * We have a warning about SSL paths. Hide it for unencrypted sites.
1511 if (!url_to_query->ssl)
1513 if (map_block_killer(exports, "https"))
1515 free_current_action(action);
1517 free_http_request(url_to_query);
1518 return JB_ERR_MEMORY;
1522 matches = strdup("<table summary=\"\" class=\"transparent\">");
1524 for (i = 0; i < MAX_AF_FILES; i++)
1526 if (NULL == csp->config->actions_file_short[i]
1527 || !strcmp(csp->config->actions_file_short[i], "standard.action")) continue;
1531 if ((fl = csp->actions_list[i]) != NULL)
1533 if ((b = fl->f) != NULL)
1535 /* FIXME: Hardcoded HTML! */
1536 string_append(&matches, "<tr><th>In file: ");
1537 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1538 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1539 string_append(&matches, buf);
1540 string_append(&matches, "View</a>");
1541 #ifdef FEATURE_CGI_EDIT_ACTIONS
1542 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/edit-actions-list?f=%d\">", i);
1543 string_append(&matches, buf);
1544 string_append(&matches, "Edit</a>");
1546 string_append(&matches, "</th></tr>\n");
1553 for (; (b != NULL) && (matches != NULL); b = b->next)
1555 if (url_match(b->url, url_to_query))
1557 string_append(&matches, "<tr><td>{");
1558 string_join (&matches, actions_to_html(csp, b->action));
1559 string_append(&matches, " }<br>\n<code>");
1560 string_join (&matches, html_encode(b->url->spec));
1561 string_append(&matches, "</code></td></tr>\n");
1563 if (merge_current_action(action, b->action))
1566 free_http_request(url_to_query);
1567 free_current_action(action);
1569 return JB_ERR_MEMORY;
1577 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1580 string_append(&matches, "</table>\n");
1583 * XXX: Kludge to make sure the "Forward settings" section
1584 * shows what forward-override{} would do with the requested URL.
1585 * No one really cares how the CGI request would be forwarded
1586 * if it wasn't intercepted as CGI request in the first place.
1588 * From here on the action bitmask will no longer reflect
1589 * the real url (http://config.privoxy.org/show-url-info?url=.*),
1590 * but luckily it's no longer required later on anyway.
1592 free_current_action(csp->action);
1593 url_actions(url_to_query, csp);
1596 * Fill in forwarding settings.
1598 * The possibilities are:
1600 * - http forwarding only
1601 * - socks4(a) forwarding only
1602 * - socks4(a) and http forwarding.
1604 * XXX: Parts of this code could be reused for the
1605 * "forwarding-failed" template which currently doesn't
1606 * display the proxy port and an eventual second forwarder.
1609 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1611 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1613 if (!err) err = map_block_killer(exports, "socks-forwarder");
1614 if (!err) err = map_block_killer(exports, "http-forwarder");
1618 char port[10]; /* We save proxy ports as int but need a string here */
1620 if (!err) err = map_block_killer(exports, "no-forwarder");
1622 if (fwd->gateway_host != NULL)
1624 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1625 "socks4" : "socks4a", 1);
1626 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1627 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1628 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1632 if (!err) err = map_block_killer(exports, "socks-forwarder");
1635 if (fwd->forward_host != NULL)
1637 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1638 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1639 if (!err) err = map(exports, "forward-port", 1, port, 1);
1643 if (!err) err = map_block_killer(exports, "http-forwarder");
1648 free_http_request(url_to_query);
1650 if (err || matches == NULL)
1652 free_current_action(action);
1654 return JB_ERR_MEMORY;
1657 if (map(exports, "matches", 1, matches , 0))
1659 free_current_action(action);
1661 return JB_ERR_MEMORY;
1664 s = current_action_to_html(csp, action);
1666 free_current_action(action);
1668 if (map(exports, "final", 1, s, 0))
1671 return JB_ERR_MEMORY;
1675 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1679 /*********************************************************************
1681 * Function : cgi_robots_txt
1683 * Description : CGI function to return "/robots.txt".
1686 * 1 : csp = Current client state (buffers, headers, etc...)
1687 * 2 : rsp = http_response data structure for output
1688 * 3 : parameters = map of cgi parameters
1690 * CGI Parameters : None
1692 * Returns : JB_ERR_OK on success
1693 * JB_ERR_MEMORY on out-of-memory error.
1695 *********************************************************************/
1696 jb_err cgi_robots_txt(struct client_state *csp,
1697 struct http_response *rsp,
1698 const struct map *parameters)
1704 "# This is the Privoxy control interface.\n"
1705 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1711 if (rsp->body == NULL)
1713 return JB_ERR_MEMORY;
1716 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1720 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1721 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1723 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1727 /*********************************************************************
1729 * Function : show_defines
1731 * Description : Add to a map the state od all conditional #defines
1732 * used when building
1735 * 1 : exports = map to extend
1737 * Returns : JB_ERR_OK on success
1738 * JB_ERR_MEMORY on out-of-memory error.
1740 *********************************************************************/
1741 static jb_err show_defines(struct map *exports)
1743 jb_err err = JB_ERR_OK;
1746 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1747 #else /* ifndef FEATURE_ACL */
1748 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1749 #endif /* ndef FEATURE_ACL */
1751 #ifdef FEATURE_CGI_EDIT_ACTIONS
1752 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1753 #else /* ifndef FEATURE_COOKIE_JAR */
1754 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1755 #endif /* ndef FEATURE_COOKIE_JAR */
1757 #ifdef FEATURE_COOKIE_JAR
1758 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1759 #else /* ifndef FEATURE_COOKIE_JAR */
1760 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1761 #endif /* ndef FEATURE_COOKIE_JAR */
1763 #ifdef FEATURE_FAST_REDIRECTS
1764 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1765 #else /* ifndef FEATURE_FAST_REDIRECTS */
1766 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1767 #endif /* ndef FEATURE_FAST_REDIRECTS */
1769 #ifdef FEATURE_FORCE_LOAD
1770 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1771 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1772 #else /* ifndef FEATURE_FORCE_LOAD */
1773 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1774 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1775 #endif /* ndef FEATURE_FORCE_LOAD */
1777 #ifdef FEATURE_GRACEFUL_TERMINATION
1778 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1779 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1780 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1781 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1783 #ifdef FEATURE_IMAGE_BLOCKING
1784 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1785 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1786 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1787 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1789 #ifdef FEATURE_IMAGE_DETECT_MSIE
1790 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1791 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1792 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1793 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1795 #ifdef FEATURE_KILL_POPUPS
1796 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1797 #else /* ifndef FEATURE_KILL_POPUPS */
1798 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1799 #endif /* ndef FEATURE_KILL_POPUPS */
1801 #ifdef FEATURE_NO_GIFS
1802 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1803 #else /* ifndef FEATURE_NO_GIFS */
1804 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1805 #endif /* ndef FEATURE_NO_GIFS */
1807 #ifdef FEATURE_PTHREAD
1808 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1809 #else /* ifndef FEATURE_PTHREAD */
1810 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1811 #endif /* ndef FEATURE_PTHREAD */
1813 #ifdef FEATURE_STATISTICS
1814 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1815 #else /* ifndef FEATURE_STATISTICS */
1816 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1817 #endif /* ndef FEATURE_STATISTICS */
1819 #ifdef FEATURE_TOGGLE
1820 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1821 #else /* ifndef FEATURE_TOGGLE */
1822 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1823 #endif /* ndef FEATURE_TOGGLE */
1825 #ifdef FEATURE_TRUST
1826 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1827 #else /* ifndef FEATURE_TRUST */
1828 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1829 #endif /* ndef FEATURE_TRUST */
1832 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1833 #else /* ifndef FEATURE_ZLIB */
1834 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1835 #endif /* ndef FEATURE_ZLIB */
1838 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1839 #else /* ifndef STATIC_PCRE */
1840 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1841 #endif /* ndef STATIC_PCRE */
1844 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1845 #else /* ifndef STATIC_PCRS */
1846 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1847 #endif /* ndef STATIC_PCRS */
1853 /*********************************************************************
1855 * Function : show_rcs
1857 * Description : Create a string with the rcs info for all sourcefiles
1861 * Returns : A string, or NULL on out-of-memory.
1863 *********************************************************************/
1864 static char *show_rcs(void)
1866 char *result = strdup("");
1867 char buf[BUFFER_SIZE];
1869 /* Instead of including *all* dot h's in the project (thus creating a
1870 * tremendous amount of dependencies), I will concede to declaring them
1871 * as extern's. This forces the developer to add to this list, but oh well.
1874 #define SHOW_RCS(__x) \
1876 extern const char __x[]; \
1877 snprintf(buf, sizeof(buf), " %s\n", __x); \
1878 string_append(&result, buf); \
1881 /* In alphabetical order */
1882 SHOW_RCS(actions_h_rcs)
1883 SHOW_RCS(actions_rcs)
1885 SHOW_RCS(amiga_h_rcs)
1887 #endif /* def AMIGA */
1890 #ifdef FEATURE_CGI_EDIT_ACTIONS
1891 SHOW_RCS(cgiedit_h_rcs)
1892 SHOW_RCS(cgiedit_rcs)
1893 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1894 SHOW_RCS(cgisimple_h_rcs)
1895 SHOW_RCS(cgisimple_rcs)
1897 SHOW_RCS(cygwin_h_rcs)
1899 SHOW_RCS(deanimate_h_rcs)
1900 SHOW_RCS(deanimate_rcs)
1901 SHOW_RCS(encode_h_rcs)
1902 SHOW_RCS(encode_rcs)
1903 SHOW_RCS(errlog_h_rcs)
1904 SHOW_RCS(errlog_rcs)
1905 SHOW_RCS(filters_h_rcs)
1906 SHOW_RCS(filters_rcs)
1907 SHOW_RCS(gateway_h_rcs)
1908 SHOW_RCS(gateway_rcs)
1909 SHOW_RCS(jbsockets_h_rcs)
1910 SHOW_RCS(jbsockets_rcs)
1913 #ifdef FEATURE_KILL_POPUPS
1914 SHOW_RCS(killpopup_h_rcs)
1915 SHOW_RCS(killpopup_rcs)
1916 #endif /* def FEATURE_KILL_POPUPS */
1917 SHOW_RCS(list_h_rcs)
1919 SHOW_RCS(loadcfg_h_rcs)
1920 SHOW_RCS(loadcfg_rcs)
1921 SHOW_RCS(loaders_h_rcs)
1922 SHOW_RCS(loaders_rcs)
1923 SHOW_RCS(miscutil_h_rcs)
1924 SHOW_RCS(miscutil_rcs)
1925 SHOW_RCS(parsers_h_rcs)
1926 SHOW_RCS(parsers_rcs)
1928 SHOW_RCS(pcrs_h_rcs)
1929 SHOW_RCS(project_h_rcs)
1930 SHOW_RCS(ssplit_h_rcs)
1931 SHOW_RCS(ssplit_rcs)
1932 SHOW_RCS(urlmatch_h_rcs)
1933 SHOW_RCS(urlmatch_rcs)
1935 #ifndef _WIN_CONSOLE
1936 SHOW_RCS(w32log_h_rcs)
1937 SHOW_RCS(w32log_rcs)
1938 SHOW_RCS(w32res_h_rcs)
1939 SHOW_RCS(w32taskbar_h_rcs)
1940 SHOW_RCS(w32taskbar_rcs)
1941 #endif /* ndef _WIN_CONSOLE */
1942 SHOW_RCS(win32_h_rcs)
1944 #endif /* def _WIN32 */