1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.56 2007/05/21 10:50: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.56 2007/05/21 10:50:35 fabiankeil
40 * - Use strlcpy() instead of strcpy().
41 * - Stop treating actions files special. Expect a complete file name
42 * (with or without path) like it's done for the rest of the files.
44 * - Don't rerun sed() in cgi_show_request().
46 * Revision 1.55 2007/04/13 13:36:46 fabiankeil
47 * Reference action files in CGI URLs by id instead
48 * of using the first part of the file name.
49 * Fixes BR 1694250 and BR 1590556.
51 * Revision 1.54 2007/04/09 18:11:35 fabiankeil
52 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
54 * Revision 1.53 2007/04/08 13:21:04 fabiankeil
55 * Reference action files in CGI URLs by id instead
56 * of using the first part of the file name.
57 * Fixes BR 1694250 and BR 1590556.
59 * Revision 1.52 2007/02/13 15:10:26 fabiankeil
60 * Apparently fopen()ing in "binary" mode doesn't require
61 * #ifdefs, it's already done without them in cgiedit.c.
63 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
64 * - Show forwarding settings on the show-url-info page
65 * - Fix some HTML syntax errors.
67 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
68 * Add favicon delivery functions.
70 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
71 * Suppress edit buttons for action files if Privoxy has
72 * no write access. Suggested by Roland in PR 1564026.
74 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
75 * Display warning if show-url-info CGI page
76 * is used while Privoxy is toggled off.
78 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
79 * Use zalloc in cgi_send_user_manual.
81 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
82 * Add FEATURE_ZLIB to the list of conditional
83 * defines at the show-status page.
85 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
86 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
87 * body memory before using it, replaced sprintf calls with snprintf.
89 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
90 * Removed checks whether or not AF_FILES have
91 * data structures associated with them in cgi_show_status.
92 * It doesn't matter as we're only interested in the file names.
94 * For the action files the checks were always true,
95 * but they prevented empty filter files from being
96 * listed. Fixes parts of BR 1619208.
98 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
99 * - Added FEATURE_GRACEFUL_TERMINATION to the
100 * "conditional #defines" section
101 * - Escaped ampersands in generated HTML.
102 * - Renamed re-filter-filename to re-filter-filenames
104 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
105 * Add special treatment for WIN32 to make sure
106 * cgi_send_user_manual opens the files in binary mode.
107 * Fixes BR 1600411 and unbreaks image delivery.
109 * Remove outdated comment.
111 * Revision 1.41 2006/10/09 19:18:28 roro
112 * Redirect http://p.p/user-manual (without trailing slash) to
113 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
115 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
116 * Modified cgi_send_user_manual to serve binary
117 * content without destroying it first. Should also be
118 * faster now. Added ".jpg" check for Content-Type guessing.
120 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
121 * Deliver documents in the user-manual directory
122 * with "Content-Type text/css" if their filename
125 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
126 * Incorporate modified version of Roland Rosenfeld's patch to
127 * optionally access the user-manual via Privoxy. Closes patch 679075.
129 * Formatting changed to Privoxy style, added call to
130 * cgi_error_no_template if the requested file doesn't
131 * exist and modified check whether or not Privoxy itself
132 * should serve the manual. Should work cross-platform now.
134 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
135 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
136 * with what was really the latest development (the v_3_0_branch branch)
138 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
139 * Multiple filter file support
141 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
142 * Undo some damaging memory leak patches
144 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
145 * A few memory leaks plugged (mostly on error paths)
147 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
148 * Another instance of:
149 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
150 * Thanks to Magnus Holmgren for the patch
152 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
153 * - Prevent line wrap beween "View/Edit" link buttons on status page
154 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
156 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
157 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
159 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
160 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
162 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
163 * Applying patch from Andreas as provided by Hal on the list.
164 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
166 * Revision 1.35 2002/05/12 21:44:44 jongfoster
167 * Adding amiga.[ch] revision information, if on an amiga.
169 * Revision 1.34 2002/04/30 12:06:12 oes
170 * Deleted unused code from default_cgi
172 * Revision 1.33 2002/04/30 11:14:52 oes
173 * Made csp the first parameter in *action_to_html
175 * Revision 1.32 2002/04/26 18:29:13 jongfoster
176 * Fixing this Visual C++ warning:
177 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
179 * Revision 1.31 2002/04/26 12:54:36 oes
180 * - Kill obsolete REDIRECT_URL code
181 * - Error handling fixes
182 * - Style sheet related HTML snipplet changes
183 * - cgi_show_url_info:
184 * - Matches now in table, actions on single lines,
186 * - standard.action suppressed
187 * - Buttons to View and Edit AFs
189 * Revision 1.30 2002/04/24 02:18:08 oes
190 * - show-status is now the starting point for editing
191 * the actions files, generate list of all AFs with buttons
192 * for viewing and editing, new look for file list (Jon:
193 * buttons now aligned ;-P ), view mode now supports multiple
194 * AFs, name changes, no view links for unspecified files,
195 * no edit link for standard.action.
197 * - Jon's multiple AF patch: cgi_show_url_info now uses all
198 * AFs and marks the output accordingly
200 * Revision 1.29 2002/04/10 13:38:35 oes
201 * load_template signature changed
203 * Revision 1.28 2002/04/07 15:42:12 jongfoster
204 * Fixing send-banner?type=auto when the image-blocker is
205 * a redirect to send-banner
207 * Revision 1.27 2002/04/05 15:50:48 oes
208 * added send-stylesheet CGI
210 * Revision 1.26 2002/04/04 00:36:36 gliptak
211 * always use pcre for matching
213 * Revision 1.25 2002/04/03 22:28:03 gliptak
214 * Removed references to gnu_regex
216 * Revision 1.24 2002/04/02 16:12:47 oes
217 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
219 * Revision 1.23 2002/03/26 22:29:54 swa
220 * we have a new homepage!
222 * Revision 1.22 2002/03/24 16:18:15 jongfoster
225 * Revision 1.21 2002/03/24 15:23:33 jongfoster
228 * Revision 1.20 2002/03/24 13:25:43 swa
229 * name change related issues
231 * Revision 1.19 2002/03/16 23:54:06 jongfoster
232 * Adding graceful termination feature, to help look for memory leaks.
233 * If you enable this (which, by design, has to be done by hand
234 * editing config.h) and then go to http://i.j.b/die, then the program
235 * will exit cleanly after the *next* request. It should free all the
236 * memory that was used.
238 * Revision 1.18 2002/03/12 01:44:49 oes
239 * Changed default for "blocked" image from jb logo to checkboard pattern
241 * Revision 1.17 2002/03/08 16:43:18 oes
242 * Added choice beween GIF and PNG built-in images
244 * Revision 1.16 2002/03/07 03:48:38 oes
245 * - Changed built-in images from GIF to PNG
246 * (with regard to Unisys patent issue)
247 * - Added a 4x4 pattern PNG which is less intrusive
248 * than the logo but also clearly marks the deleted banners
250 * Revision 1.15 2002/03/06 22:54:35 jongfoster
251 * Automated function-comment nitpicking.
253 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
254 * Clean up a little CRLF unpleasantness that suddenly appeared
256 * Revision 1.13 2002/02/21 00:10:37 jongfoster
257 * Adding send-banner?type=auto option
259 * Revision 1.12 2002/01/23 01:03:32 jongfoster
260 * Fixing gcc [CygWin] compiler warnings
262 * Revision 1.11 2002/01/23 00:01:04 jongfoster
263 * Adding cgi_transparent_gif() for http://i.j.b/t
264 * Adding missing html_encode() to many CGI functions.
265 * Adding urlmatch.[ch] to http://i.j.b/show-version
267 * Revision 1.10 2002/01/17 21:10:37 jongfoster
268 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
269 * Also fixing a problem in the same function with improperly quoted URLs
270 * in output HTML, and adding code to handle https:// URLs correctly.
272 * Revision 1.9 2001/11/30 23:09:15 jongfoster
273 * Now reports on FEATURE_CGI_EDIT_ACTIONS
274 * Removing FEATURE_DENY_GZIP from template
276 * Revision 1.8 2001/11/13 00:14:07 jongfoster
277 * Fixing stupid bug now I've figured out what || means.
278 * (It always returns 0 or 1, not one of it's paramaters.)
280 * Revision 1.7 2001/10/23 21:48:19 jongfoster
281 * Cleaning up error handling in CGI functions - they now send back
282 * a HTML error page and should never cause a FATAL error. (Fixes one
283 * potential source of "denial of service" attacks).
285 * CGI actions file editor that works and is actually useful.
287 * Ability to toggle JunkBuster remotely using a CGI call.
289 * You can turn off both the above features in the main configuration
290 * file, e.g. if you are running a multi-user proxy.
292 * Revision 1.6 2001/10/14 22:00:32 jongfoster
293 * Adding support for a 404 error when an invalid CGI page is requested.
295 * Revision 1.5 2001/10/07 15:30:41 oes
296 * Removed FEATURE_DENY_GZIP
298 * Revision 1.4 2001/10/02 15:31:12 oes
299 * Introduced show-request cgi
301 * Revision 1.3 2001/09/22 16:34:44 jongfoster
302 * Removing unneeded #includes
304 * Revision 1.2 2001/09/19 18:01:11 oes
305 * Fixed comments; cosmetics
307 * Revision 1.1 2001/09/16 17:08:54 jongfoster
308 * Moving simple CGI functions from cgi.c to new file cgisimple.c
311 **********************************************************************/
317 #include <sys/types.h>
325 #endif /* def HAVE_ACCESS */
329 #include "cgisimple.h"
335 #include "miscutil.h"
338 #include "urlmatch.h"
341 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
344 static char *show_rcs(void);
345 static jb_err show_defines(struct map *exports);
348 * 16x16 ico blobs for favicon delivery functions.
350 const char default_favicon_data[] =
351 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
352 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
353 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
354 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
355 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
356 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
357 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
358 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
359 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
360 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
361 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
362 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
363 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
365 const char error_favicon_data[] =
366 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
367 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
368 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
369 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
370 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
371 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
372 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
373 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
374 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
375 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
376 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
377 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
378 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
380 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
381 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
383 /*********************************************************************
385 * Function : cgi_default
387 * Description : CGI function that is called for the CGI_SITE_1_HOST
388 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
389 * Boring - only exports the default exports.
392 * 1 : csp = Current client state (buffers, headers, etc...)
393 * 2 : rsp = http_response data structure for output
394 * 3 : parameters = map of cgi parameters
396 * CGI Parameters : none
398 * Returns : JB_ERR_OK on success
399 * JB_ERR_MEMORY on out-of-memory
401 *********************************************************************/
402 jb_err cgi_default(struct client_state *csp,
403 struct http_response *rsp,
404 const struct map *parameters)
411 if (NULL == (exports = default_exports(csp, "")))
413 return JB_ERR_MEMORY;
416 return template_fill_for_cgi(csp, "default", exports, rsp);
420 /*********************************************************************
422 * Function : cgi_error_404
424 * Description : CGI function that is called if an unknown action was
428 * 1 : csp = Current client state (buffers, headers, etc...)
429 * 2 : rsp = http_response data structure for output
430 * 3 : parameters = map of cgi parameters
432 * CGI Parameters : none
434 * Returns : JB_ERR_OK on success
435 * JB_ERR_MEMORY on out-of-memory error.
437 *********************************************************************/
438 jb_err cgi_error_404(struct client_state *csp,
439 struct http_response *rsp,
440 const struct map *parameters)
448 if (NULL == (exports = default_exports(csp, NULL)))
450 return JB_ERR_MEMORY;
453 rsp->status = strdup("404 Privoxy configuration page not found");
454 if (rsp->status == NULL)
457 return JB_ERR_MEMORY;
460 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
464 #ifdef FEATURE_GRACEFUL_TERMINATION
465 /*********************************************************************
469 * Description : CGI function to shut down Privoxy.
470 * NOTE: Turning this on in a production build
471 * would be a BAD idea. An EXTREMELY BAD idea.
472 * In short, don't do it.
475 * 1 : csp = Current client state (buffers, headers, etc...)
476 * 2 : rsp = http_response data structure for output
477 * 3 : parameters = map of cgi parameters
479 * CGI Parameters : none
481 * Returns : JB_ERR_OK on success
482 * JB_ERR_MEMORY on out-of-memory error.
484 *********************************************************************/
485 jb_err cgi_die (struct client_state *csp,
486 struct http_response *rsp,
487 const struct map *parameters)
497 * I don't really care what gets sent back to the browser.
498 * Take the easy option - "out of memory" page.
501 return JB_ERR_MEMORY;
503 #endif /* def FEATURE_GRACEFUL_TERMINATION */
506 /*********************************************************************
508 * Function : cgi_show_request
510 * Description : Show the client's request and what sed() would have
514 * 1 : csp = Current client state (buffers, headers, etc...)
515 * 2 : rsp = http_response data structure for output
516 * 3 : parameters = map of cgi parameters
518 * CGI Parameters : none
520 * Returns : JB_ERR_OK on success
521 * JB_ERR_MEMORY on out-of-memory error.
523 *********************************************************************/
524 jb_err cgi_show_request(struct client_state *csp,
525 struct http_response *rsp,
526 const struct map *parameters)
535 if (NULL == (exports = default_exports(csp, "show-request")))
537 return JB_ERR_MEMORY;
541 * Repair the damage done to the IOB by get_header()
543 for (p = csp->iob->buf; p < csp->iob->eod; p++)
545 if (*p == '\0') *p = '\n';
549 * Export the original client's request and the one we would
550 * be sending to the server if this wasn't a CGI call
553 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
556 return JB_ERR_MEMORY;
559 if (map(exports, "processed-request", 1, html_encode(list_to_text(csp->headers)), 0))
562 return JB_ERR_MEMORY;
565 return template_fill_for_cgi(csp, "show-request", exports, rsp);
569 /*********************************************************************
571 * Function : cgi_send_banner
573 * Description : CGI function that returns a banner.
576 * 1 : csp = Current client state (buffers, headers, etc...)
577 * 2 : rsp = http_response data structure for output
578 * 3 : parameters = map of cgi parameters
581 * type : Selects the type of banner between "trans", "logo",
582 * and "auto". Defaults to "logo" if absent or invalid.
583 * "auto" means to select as if we were image-blocking.
584 * (Only the first character really counts; b and t are
587 * Returns : JB_ERR_OK on success
588 * JB_ERR_MEMORY on out-of-memory error.
590 *********************************************************************/
591 jb_err cgi_send_banner(struct client_state *csp,
592 struct http_response *rsp,
593 const struct map *parameters)
595 char imagetype = lookup(parameters, "type")[0];
598 * If type is auto, then determine the right thing
599 * to do from the set-image-blocker action
601 if (imagetype == 'a')
608 #ifdef FEATURE_IMAGE_BLOCKING
609 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
611 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
612 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
613 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
617 /* Use default - nothing to do here. */
619 else if (0 == strcmpic(p, "blank"))
623 else if (0 == strcmpic(p, "pattern"))
629 * If the action is to call this CGI, determine
632 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
634 imagetype = p[sizeof(prefix1) - 1];
636 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
638 imagetype = p[sizeof(prefix2) - 1];
642 * Everything else must (should) be a URL to
650 #endif /* def FEATURE_IMAGE_BLOCKING */
654 * Now imagetype is either the non-auto type we were called with,
655 * or it was auto and has since been determined. In any case, we
656 * can proceed to actually answering the request by sending a redirect
657 * or an image as appropriate:
659 if (imagetype == 'r')
661 rsp->status = strdup("302 Local Redirect from Privoxy");
662 if (rsp->status == NULL)
664 return JB_ERR_MEMORY;
666 if (enlist_unique_header(rsp->headers, "Location",
667 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
669 return JB_ERR_MEMORY;
674 if ((imagetype == 'b') || (imagetype == 't'))
676 rsp->body = bindup(image_blank_data, image_blank_length);
677 rsp->content_length = image_blank_length;
681 rsp->body = bindup(image_pattern_data, image_pattern_length);
682 rsp->content_length = image_pattern_length;
685 if (rsp->body == NULL)
687 return JB_ERR_MEMORY;
689 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
691 return JB_ERR_MEMORY;
702 /*********************************************************************
704 * Function : cgi_transparent_image
706 * Description : CGI function that sends a 1x1 transparent image.
709 * 1 : csp = Current client state (buffers, headers, etc...)
710 * 2 : rsp = http_response data structure for output
711 * 3 : parameters = map of cgi parameters
713 * CGI Parameters : None
715 * Returns : JB_ERR_OK on success
716 * JB_ERR_MEMORY on out-of-memory error.
718 *********************************************************************/
719 jb_err cgi_transparent_image(struct client_state *csp,
720 struct http_response *rsp,
721 const struct map *parameters)
723 rsp->body = bindup(image_blank_data, image_blank_length);
724 rsp->content_length = image_blank_length;
726 if (rsp->body == NULL)
728 return JB_ERR_MEMORY;
731 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
733 return JB_ERR_MEMORY;
743 /*********************************************************************
745 * Function : cgi_send_default_favicon
747 * Description : CGI function that sends the standard favicon.
750 * 1 : csp = Current client state (buffers, headers, etc...)
751 * 2 : rsp = http_response data structure for output
752 * 3 : parameters = map of cgi parameters
754 * CGI Parameters : None
756 * Returns : JB_ERR_OK on success
757 * JB_ERR_MEMORY on out-of-memory error.
759 *********************************************************************/
760 jb_err cgi_send_default_favicon(struct client_state *csp,
761 struct http_response *rsp,
762 const struct map *parameters)
764 rsp->body = bindup(default_favicon_data, default_favicon_length);
765 rsp->content_length = default_favicon_length;
767 if (rsp->body == NULL)
769 return JB_ERR_MEMORY;
772 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
774 return JB_ERR_MEMORY;
784 /*********************************************************************
786 * Function : cgi_send_error_favicon
788 * Description : CGI function that sends the favicon for error pages.
791 * 1 : csp = Current client state (buffers, headers, etc...)
792 * 2 : rsp = http_response data structure for output
793 * 3 : parameters = map of cgi parameters
795 * CGI Parameters : None
797 * Returns : JB_ERR_OK on success
798 * JB_ERR_MEMORY on out-of-memory error.
800 *********************************************************************/
801 jb_err cgi_send_error_favicon(struct client_state *csp,
802 struct http_response *rsp,
803 const struct map *parameters)
805 rsp->body = bindup(error_favicon_data, error_favicon_length);
806 rsp->content_length = error_favicon_length;
808 if (rsp->body == NULL)
810 return JB_ERR_MEMORY;
813 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
815 return JB_ERR_MEMORY;
825 /*********************************************************************
827 * Function : cgi_send_stylesheet
829 * Description : CGI function that sends a css stylesheet found
830 * in the cgi-style.css template
833 * 1 : csp = Current client state (buffers, headers, etc...)
834 * 2 : rsp = http_response data structure for output
835 * 3 : parameters = map of cgi parameters
837 * CGI Parameters : None
839 * Returns : JB_ERR_OK on success
840 * JB_ERR_MEMORY on out-of-memory error.
842 *********************************************************************/
843 jb_err cgi_send_stylesheet(struct client_state *csp,
844 struct http_response *rsp,
845 const struct map *parameters)
852 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
854 if (err == JB_ERR_FILE)
857 * No way to tell user; send empty stylesheet
859 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
863 return err; /* JB_ERR_MEMORY */
866 if (enlist(rsp->headers, "Content-Type: text/css"))
868 return JB_ERR_MEMORY;
874 /*********************************************************************
876 * Function : cgi_send_user_manual
878 * Description : CGI function that sends a file in the user
882 * 1 : csp = Current client state (buffers, headers, etc...)
883 * 2 : rsp = http_response data structure for output
884 * 3 : parameters = map of cgi parameters
886 * CGI Parameters : file=name.html, the name of the HTML file
887 * (relative to user-manual from config)
889 * Returns : JB_ERR_OK on success
890 * JB_ERR_MEMORY on out-of-memory error.
892 *********************************************************************/
893 jb_err cgi_send_user_manual(struct client_state *csp,
894 struct http_response *rsp,
895 const struct map *parameters)
897 const char * filename;
900 jb_err err = JB_ERR_OK;
907 if (!parameters->first)
909 /* requested http://p.p/user-manual (without trailing slash) */
910 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
913 get_string_param(parameters, "file", &filename);
914 /* Check paramter for hack attempts */
915 if (filename && strchr(filename, '/'))
917 return JB_ERR_CGI_PARAMS;
919 if (filename && strstr(filename, ".."))
921 return JB_ERR_CGI_PARAMS;
924 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
925 if (full_path == NULL)
927 return JB_ERR_MEMORY;
930 /* Open user-manual file */
931 if (NULL == (fp = fopen(full_path, "rb")))
933 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
934 err = cgi_error_no_template(csp, rsp, full_path);
939 /* Get file length */
940 fseek(fp, 0, SEEK_END);
941 length = (size_t)ftell(fp);
942 fseek(fp, 0, SEEK_SET);
944 /* Allocate memory and load the file directly into the body */
945 rsp->body = (char *)zalloc(length+1);
950 return JB_ERR_MEMORY;
952 if (!fread(rsp->body, length, 1, fp))
955 * May happen if the file size changes between fseek() and fread().
956 * If it does, we just log it and serve what we got.
958 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
963 rsp->content_length = length;
965 /* Guess correct Content-Type based on the filename's ending */
968 length = strlen(filename);
974 if((length>=4) && !strcmp(&filename[length-4], ".css"))
976 err = enlist(rsp->headers, "Content-Type: text/css");
978 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
980 err = enlist(rsp->headers, "Content-Type: image/jpeg");
984 err = enlist(rsp->headers, "Content-Type: text/html");
991 /*********************************************************************
993 * Function : cgi_show_version
995 * Description : CGI function that returns a a web page describing the
996 * file versions of Privoxy.
999 * 1 : csp = Current client state (buffers, headers, etc...)
1000 * 2 : rsp = http_response data structure for output
1001 * 3 : parameters = map of cgi parameters
1003 * CGI Parameters : none
1005 * Returns : JB_ERR_OK on success
1006 * JB_ERR_MEMORY on out-of-memory error.
1008 *********************************************************************/
1009 jb_err cgi_show_version(struct client_state *csp,
1010 struct http_response *rsp,
1011 const struct map *parameters)
1013 struct map *exports;
1019 if (NULL == (exports = default_exports(csp, "show-version")))
1021 return JB_ERR_MEMORY;
1024 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1027 return JB_ERR_MEMORY;
1030 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1034 /*********************************************************************
1036 * Function : cgi_show_status
1038 * Description : CGI function that returns a web page describing the
1039 * current status of Privoxy.
1042 * 1 : csp = Current client state (buffers, headers, etc...)
1043 * 2 : rsp = http_response data structure for output
1044 * 3 : parameters = map of cgi parameters
1047 * file : Which file to show. Only first letter is checked,
1049 * - "p"ermissions (actions) file
1052 * Default is to show menu and other information.
1054 * Returns : JB_ERR_OK on success
1055 * JB_ERR_MEMORY on out-of-memory error.
1057 *********************************************************************/
1058 jb_err cgi_show_status(struct client_state *csp,
1059 struct http_response *rsp,
1060 const struct map *parameters)
1067 char buf[BUFFER_SIZE];
1068 const char * filename = NULL;
1069 char * file_description = NULL;
1070 #ifdef FEATURE_STATISTICS
1071 float perc_rej; /* Percentage of http requests rejected */
1072 int local_urls_read;
1073 int local_urls_rejected;
1074 #endif /* ndef FEATURE_STATISTICS */
1075 jb_err err = JB_ERR_OK;
1077 struct map *exports;
1083 if (NULL == (exports = default_exports(csp, "show-status")))
1085 return JB_ERR_MEMORY;
1088 switch (*(lookup(parameters, "file")))
1091 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1093 filename = csp->actions_list[i]->filename;
1094 file_description = "Actions File";
1099 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1101 filename = csp->rlist[i]->filename;
1102 file_description = "Filter File";
1106 #ifdef FEATURE_TRUST
1110 filename = csp->tlist->filename;
1111 file_description = "Trust File";
1114 #endif /* def FEATURE_TRUST */
1117 if (NULL != filename)
1119 if ( map(exports, "file-description", 1, file_description, 1)
1120 || map(exports, "filepath", 1, html_encode(filename), 0) )
1123 return JB_ERR_MEMORY;
1126 if ((fp = fopen(filename, "r")) == NULL)
1128 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1131 return JB_ERR_MEMORY;
1137 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1139 string_join (&s, html_encode(buf));
1143 if (map(exports, "contents", 1, s, 0))
1146 return JB_ERR_MEMORY;
1150 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1154 for (j = 0; (s != NULL) && (j < Argc); j++)
1156 if (!err) err = string_join (&s, html_encode(Argv[j]));
1157 if (!err) err = string_append(&s, " ");
1159 if (!err) err = map(exports, "invocation", 1, s, 0);
1161 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1162 if (!err) err = show_defines(exports);
1167 return JB_ERR_MEMORY;
1170 #ifdef FEATURE_STATISTICS
1171 local_urls_read = urls_read;
1172 local_urls_rejected = urls_rejected;
1175 * Need to alter the stats not to include the fetch of this
1178 * Can't do following thread safely! doh!
1181 * urls_rejected--; * This will be incremented subsequently *
1184 if (local_urls_read == 0)
1186 if (!err) err = map_block_killer(exports, "have-stats");
1190 if (!err) err = map_block_killer(exports, "have-no-stats");
1192 perc_rej = (float)local_urls_rejected * 100.0F /
1193 (float)local_urls_read;
1195 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1196 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1198 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1199 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1201 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1202 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1205 #else /* ndef FEATURE_STATISTICS */
1206 err = err || map_block_killer(exports, "statistics");
1207 #endif /* ndef FEATURE_STATISTICS */
1210 * List all action files in use, together with view and edit links,
1211 * except for standard.action, which should only be viewable. (Not
1212 * enforced in the editor itself)
1213 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1216 for (i = 0; i < MAX_AF_FILES; i++)
1218 if (csp->actions_list[i] != NULL)
1220 if (!err) err = string_append(&s, "<tr><td>");
1221 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1222 snprintf(buf, sizeof(buf),
1223 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1224 if (!err) err = string_append(&s, buf);
1226 #ifdef FEATURE_CGI_EDIT_ACTIONS
1227 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
1230 if (access(csp->config->actions_file[i], W_OK) == 0)
1232 #endif /* def HAVE_ACCESS */
1233 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1234 if (!err) err = string_append(&s, buf);
1239 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1241 #endif /* def HAVE_ACCESS */
1245 if (!err) err = string_append(&s, "</td></tr>\n");
1250 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1254 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1258 * List all re_filterfiles in use, together with view options.
1259 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1262 for (i = 0; i < MAX_AF_FILES; i++)
1264 if (csp->rlist[i] != NULL)
1266 if (!err) err = string_append(&s, "<tr><td>");
1267 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1269 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1270 if (!err) err = string_append(&s, buf);
1271 if (!err) err = string_append(&s, "</td></tr>\n");
1276 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1280 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1281 if (!err) err = map_block_killer(exports, "have-filterfile");
1284 #ifdef FEATURE_TRUST
1287 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1291 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1292 if (!err) err = map_block_killer(exports, "have-trustfile");
1295 if (!err) err = map_block_killer(exports, "trust-support");
1296 #endif /* ndef FEATURE_TRUST */
1301 return JB_ERR_MEMORY;
1304 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1308 /*********************************************************************
1310 * Function : cgi_show_url_info
1312 * Description : CGI function that determines and shows which actions
1313 * Privoxy will perform for a given url, and which
1314 * matches starting from the defaults have lead to that.
1317 * 1 : csp = Current client state (buffers, headers, etc...)
1318 * 2 : rsp = http_response data structure for output
1319 * 3 : parameters = map of cgi parameters
1322 * url : The url whose actions are to be determined.
1323 * If url is unset, the url-given conditional will be
1324 * set, so that all but the form can be suppressed in
1327 * Returns : JB_ERR_OK on success
1328 * JB_ERR_MEMORY on out-of-memory error.
1330 *********************************************************************/
1331 jb_err cgi_show_url_info(struct client_state *csp,
1332 struct http_response *rsp,
1333 const struct map *parameters)
1336 struct map *exports;
1343 if (NULL == (exports = default_exports(csp, "show-url-info")))
1345 return JB_ERR_MEMORY;
1349 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1351 url_param = strdup(lookup(parameters, "url"));
1352 if (url_param == NULL)
1355 return JB_ERR_MEMORY;
1360 * Handle prefixes. 4 possibilities:
1361 * 1) "http://" or "https://" prefix present and followed by URL - OK
1362 * 2) Only the "http://" or "https://" part is present, no URL - change
1363 * to empty string so it will be detected later as "no URL".
1364 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1366 * 4) Parameter not specified or is empty string - let this fall through
1367 * for now, next block of code will handle it.
1369 if (0 == strncmp(url_param, "http://", 7))
1371 if (url_param[7] == '\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 (0 == strncmp(url_param, "https://", 8))
1382 if (url_param[8] == '\0')
1385 * Empty URL (just prefix).
1386 * Make it totally empty so it's caught by the next if()
1388 url_param[0] = '\0';
1391 else if (url_param[0] != '\0')
1394 * Unknown prefix - assume http://
1396 const size_t url_param_prefixed_size = 7 + 1 + strlen(url_param);
1397 char * url_param_prefixed = malloc(url_param_prefixed_size);
1398 if (NULL == url_param_prefixed)
1402 return JB_ERR_MEMORY;
1404 strlcpy(url_param_prefixed, "http://", url_param_prefixed_size);
1405 strlcat(url_param_prefixed, url_param, url_param_prefixed_size);
1407 url_param = url_param_prefixed;
1411 * Hide "toggle off" warning if Privoxy is toggled on.
1414 #ifdef FEATURE_TOGGLE
1415 (global_toggle_state == 1) &&
1416 #endif /* def FEATURE_TOGGLE */
1417 map_block_killer(exports, "privoxy-is-toggled-off")
1421 return JB_ERR_MEMORY;
1424 if (url_param[0] == '\0')
1426 /* URL paramater not specified, display query form only. */
1428 if (map_block_killer(exports, "url-given")
1429 || map(exports, "url", 1, "", 1))
1432 return JB_ERR_MEMORY;
1437 /* Given a URL, so query it. */
1442 struct file_list *fl;
1443 struct url_actions *b;
1444 struct http_request url_to_query[1];
1445 struct current_action_spec action[1];
1448 if (map(exports, "url", 1, html_encode(url_param), 0))
1452 return JB_ERR_MEMORY;
1455 init_current_action(action);
1457 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1459 free_current_action(action);
1462 return JB_ERR_MEMORY;
1465 err = parse_http_url(url_param, url_to_query, csp);
1469 if (err == JB_ERR_MEMORY)
1471 free_http_request(url_to_query);
1472 free_current_action(action);
1474 return JB_ERR_MEMORY;
1480 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1481 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1483 free_current_action(action);
1484 free_http_request(url_to_query);
1489 return JB_ERR_MEMORY;
1492 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1496 * We have a warning about SSL paths. Hide it for insecure sites.
1498 if (!url_to_query->ssl)
1500 if (map_block_killer(exports, "https"))
1502 free_current_action(action);
1504 free_http_request(url_to_query);
1505 return JB_ERR_MEMORY;
1509 matches = strdup("<table summary=\"\" class=\"transparent\">");
1511 for (i = 0; i < MAX_AF_FILES; i++)
1513 if (NULL == csp->config->actions_file_short[i]
1514 || !strcmp(csp->config->actions_file_short[i], "standard.action")) continue;
1518 if ((fl = csp->actions_list[i]) != NULL)
1520 if ((b = fl->f) != NULL)
1522 /* FIXME: Hardcoded HTML! */
1523 string_append(&matches, "<tr><th>In file: ");
1524 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1525 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1526 string_append(&matches, buf);
1527 string_append(&matches, "View</a>");
1528 #ifdef FEATURE_CGI_EDIT_ACTIONS
1529 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/edit-actions-list?f=%d\">", i);
1530 string_append(&matches, buf);
1531 string_append(&matches, "Edit</a>");
1533 string_append(&matches, "</th></tr>\n");
1540 for (; (b != NULL) && (matches != NULL); b = b->next)
1542 if (url_match(b->url, url_to_query))
1544 string_append(&matches, "<tr><td>{");
1545 string_join (&matches, actions_to_html(csp, b->action));
1546 string_append(&matches, " }<br>\n<code>");
1547 string_join (&matches, html_encode(b->url->spec));
1548 string_append(&matches, "</code></td></tr>\n");
1550 if (merge_current_action(action, b->action))
1553 free_http_request(url_to_query);
1554 free_current_action(action);
1556 return JB_ERR_MEMORY;
1564 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1567 string_append(&matches, "</table>\n");
1570 * XXX: Kludge to make sure the "Forward settings" section
1571 * shows what forward-override{} would do with the requested URL.
1572 * No one really cares how the CGI request would be forwarded
1573 * if it wasn't intercepted as CGI request in the first place.
1575 * From here on the action bitmask will no longer reflect
1576 * the real url (http://config.privoxy.org/show-url-info?url=.*),
1577 * but luckily it's no longer required later on anyway.
1579 free_current_action(csp->action);
1580 url_actions(url_to_query, csp);
1583 * Fill in forwarding settings.
1585 * The possibilities are:
1587 * - http forwarding only
1588 * - socks4(a) forwarding only
1589 * - socks4(a) and http forwarding.
1591 * XXX: Parts of this code could be reused for the
1592 * "forwarding-failed" template which currently doesn't
1593 * display the proxy port and an eventual second forwarder.
1596 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1598 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1600 if (!err) err = map_block_killer(exports, "socks-forwarder");
1601 if (!err) err = map_block_killer(exports, "http-forwarder");
1605 char port[10]; /* We save proxy ports as int but need a string here */
1607 if (!err) err = map_block_killer(exports, "no-forwarder");
1609 if (fwd->gateway_host != NULL)
1611 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1612 "socks4" : "socks4a", 1);
1613 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1614 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1615 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1619 if (!err) err = map_block_killer(exports, "socks-forwarder");
1622 if (fwd->forward_host != NULL)
1624 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1625 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1626 if (!err) err = map(exports, "forward-port", 1, port, 1);
1630 if (!err) err = map_block_killer(exports, "http-forwarder");
1635 free_http_request(url_to_query);
1637 if (err || matches == NULL)
1639 free_current_action(action);
1641 return JB_ERR_MEMORY;
1644 if (map(exports, "matches", 1, matches , 0))
1646 free_current_action(action);
1648 return JB_ERR_MEMORY;
1651 s = current_action_to_html(csp, action);
1653 free_current_action(action);
1655 if (map(exports, "final", 1, s, 0))
1658 return JB_ERR_MEMORY;
1662 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1666 /*********************************************************************
1668 * Function : cgi_robots_txt
1670 * Description : CGI function to return "/robots.txt".
1673 * 1 : csp = Current client state (buffers, headers, etc...)
1674 * 2 : rsp = http_response data structure for output
1675 * 3 : parameters = map of cgi parameters
1677 * CGI Parameters : None
1679 * Returns : JB_ERR_OK on success
1680 * JB_ERR_MEMORY on out-of-memory error.
1682 *********************************************************************/
1683 jb_err cgi_robots_txt(struct client_state *csp,
1684 struct http_response *rsp,
1685 const struct map *parameters)
1691 "# This is the Privoxy control interface.\n"
1692 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1698 if (rsp->body == NULL)
1700 return JB_ERR_MEMORY;
1703 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1707 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1708 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1710 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1714 /*********************************************************************
1716 * Function : show_defines
1718 * Description : Add to a map the state od all conditional #defines
1719 * used when building
1722 * 1 : exports = map to extend
1724 * Returns : JB_ERR_OK on success
1725 * JB_ERR_MEMORY on out-of-memory error.
1727 *********************************************************************/
1728 static jb_err show_defines(struct map *exports)
1730 jb_err err = JB_ERR_OK;
1733 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1734 #else /* ifndef FEATURE_ACL */
1735 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1736 #endif /* ndef FEATURE_ACL */
1738 #ifdef FEATURE_CGI_EDIT_ACTIONS
1739 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1740 #else /* ifndef FEATURE_COOKIE_JAR */
1741 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1742 #endif /* ndef FEATURE_COOKIE_JAR */
1744 #ifdef FEATURE_COOKIE_JAR
1745 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1746 #else /* ifndef FEATURE_COOKIE_JAR */
1747 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1748 #endif /* ndef FEATURE_COOKIE_JAR */
1750 #ifdef FEATURE_FAST_REDIRECTS
1751 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1752 #else /* ifndef FEATURE_FAST_REDIRECTS */
1753 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1754 #endif /* ndef FEATURE_FAST_REDIRECTS */
1756 #ifdef FEATURE_FORCE_LOAD
1757 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1758 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1759 #else /* ifndef FEATURE_FORCE_LOAD */
1760 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1761 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1762 #endif /* ndef FEATURE_FORCE_LOAD */
1764 #ifdef FEATURE_GRACEFUL_TERMINATION
1765 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1766 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1767 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1768 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1770 #ifdef FEATURE_IMAGE_BLOCKING
1771 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1772 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1773 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1774 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1776 #ifdef FEATURE_IMAGE_DETECT_MSIE
1777 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1778 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1779 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1780 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1782 #ifdef FEATURE_KILL_POPUPS
1783 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1784 #else /* ifndef FEATURE_KILL_POPUPS */
1785 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1786 #endif /* ndef FEATURE_KILL_POPUPS */
1788 #ifdef FEATURE_NO_GIFS
1789 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1790 #else /* ifndef FEATURE_NO_GIFS */
1791 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1792 #endif /* ndef FEATURE_NO_GIFS */
1794 #ifdef FEATURE_PTHREAD
1795 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1796 #else /* ifndef FEATURE_PTHREAD */
1797 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1798 #endif /* ndef FEATURE_PTHREAD */
1800 #ifdef FEATURE_STATISTICS
1801 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1802 #else /* ifndef FEATURE_STATISTICS */
1803 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1804 #endif /* ndef FEATURE_STATISTICS */
1806 #ifdef FEATURE_TOGGLE
1807 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1808 #else /* ifndef FEATURE_TOGGLE */
1809 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1810 #endif /* ndef FEATURE_TOGGLE */
1812 #ifdef FEATURE_TRUST
1813 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1814 #else /* ifndef FEATURE_TRUST */
1815 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1816 #endif /* ndef FEATURE_TRUST */
1819 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1820 #else /* ifndef FEATURE_ZLIB */
1821 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1822 #endif /* ndef FEATURE_ZLIB */
1825 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1826 #else /* ifndef STATIC_PCRE */
1827 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1828 #endif /* ndef STATIC_PCRE */
1831 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1832 #else /* ifndef STATIC_PCRS */
1833 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1834 #endif /* ndef STATIC_PCRS */
1840 /*********************************************************************
1842 * Function : show_rcs
1844 * Description : Create a string with the rcs info for all sourcefiles
1848 * Returns : A string, or NULL on out-of-memory.
1850 *********************************************************************/
1851 static char *show_rcs(void)
1853 char *result = strdup("");
1854 char buf[BUFFER_SIZE];
1856 /* Instead of including *all* dot h's in the project (thus creating a
1857 * tremendous amount of dependencies), I will concede to declaring them
1858 * as extern's. This forces the developer to add to this list, but oh well.
1861 #define SHOW_RCS(__x) \
1863 extern const char __x[]; \
1864 snprintf(buf, sizeof(buf), " %s\n", __x); \
1865 string_append(&result, buf); \
1868 /* In alphabetical order */
1869 SHOW_RCS(actions_h_rcs)
1870 SHOW_RCS(actions_rcs)
1872 SHOW_RCS(amiga_h_rcs)
1874 #endif /* def AMIGA */
1877 #ifdef FEATURE_CGI_EDIT_ACTIONS
1878 SHOW_RCS(cgiedit_h_rcs)
1879 SHOW_RCS(cgiedit_rcs)
1880 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1881 SHOW_RCS(cgisimple_h_rcs)
1882 SHOW_RCS(cgisimple_rcs)
1884 SHOW_RCS(cygwin_h_rcs)
1886 SHOW_RCS(deanimate_h_rcs)
1887 SHOW_RCS(deanimate_rcs)
1888 SHOW_RCS(encode_h_rcs)
1889 SHOW_RCS(encode_rcs)
1890 SHOW_RCS(errlog_h_rcs)
1891 SHOW_RCS(errlog_rcs)
1892 SHOW_RCS(filters_h_rcs)
1893 SHOW_RCS(filters_rcs)
1894 SHOW_RCS(gateway_h_rcs)
1895 SHOW_RCS(gateway_rcs)
1896 SHOW_RCS(jbsockets_h_rcs)
1897 SHOW_RCS(jbsockets_rcs)
1900 #ifdef FEATURE_KILL_POPUPS
1901 SHOW_RCS(killpopup_h_rcs)
1902 SHOW_RCS(killpopup_rcs)
1903 #endif /* def FEATURE_KILL_POPUPS */
1904 SHOW_RCS(list_h_rcs)
1906 SHOW_RCS(loadcfg_h_rcs)
1907 SHOW_RCS(loadcfg_rcs)
1908 SHOW_RCS(loaders_h_rcs)
1909 SHOW_RCS(loaders_rcs)
1910 SHOW_RCS(miscutil_h_rcs)
1911 SHOW_RCS(miscutil_rcs)
1912 SHOW_RCS(parsers_h_rcs)
1913 SHOW_RCS(parsers_rcs)
1915 SHOW_RCS(pcrs_h_rcs)
1916 SHOW_RCS(project_h_rcs)
1917 SHOW_RCS(ssplit_h_rcs)
1918 SHOW_RCS(ssplit_rcs)
1919 SHOW_RCS(urlmatch_h_rcs)
1920 SHOW_RCS(urlmatch_rcs)
1922 #ifndef _WIN_CONSOLE
1923 SHOW_RCS(w32log_h_rcs)
1924 SHOW_RCS(w32log_rcs)
1925 SHOW_RCS(w32res_h_rcs)
1926 SHOW_RCS(w32taskbar_h_rcs)
1927 SHOW_RCS(w32taskbar_rcs)
1928 #endif /* ndef _WIN_CONSOLE */
1929 SHOW_RCS(win32_h_rcs)
1931 #endif /* def _WIN32 */