1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.52 2007/02/13 15:10:26 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.52 2007/02/13 15:10:26 fabiankeil
40 * Apparently fopen()ing in "binary" mode doesn't require
41 * #ifdefs, it's already done without them in cgiedit.c.
43 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
44 * - Show forwarding settings on the show-url-info page
45 * - Fix some HTML syntax errors.
47 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
48 * Add favicon delivery functions.
50 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
51 * Suppress edit buttons for action files if Privoxy has
52 * no write access. Suggested by Roland in PR 1564026.
54 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
55 * Display warning if show-url-info CGI page
56 * is used while Privoxy is toggled off.
58 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
59 * Use zalloc in cgi_send_user_manual.
61 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
62 * Add FEATURE_ZLIB to the list of conditional
63 * defines at the show-status page.
65 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
66 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
67 * body memory before using it, replaced sprintf calls with snprintf.
69 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
70 * Removed checks whether or not AF_FILES have
71 * data structures associated with them in cgi_show_status.
72 * It doesn't matter as we're only interested in the file names.
74 * For the action files the checks were always true,
75 * but they prevented empty filter files from being
76 * listed. Fixes parts of BR 1619208.
78 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
79 * - Added FEATURE_GRACEFUL_TERMINATION to the
80 * "conditional #defines" section
81 * - Escaped ampersands in generated HTML.
82 * - Renamed re-filter-filename to re-filter-filenames
84 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
85 * Add special treatment for WIN32 to make sure
86 * cgi_send_user_manual opens the files in binary mode.
87 * Fixes BR 1600411 and unbreaks image delivery.
89 * Remove outdated comment.
91 * Revision 1.41 2006/10/09 19:18:28 roro
92 * Redirect http://p.p/user-manual (without trailing slash) to
93 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
95 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
96 * Modified cgi_send_user_manual to serve binary
97 * content without destroying it first. Should also be
98 * faster now. Added ".jpg" check for Content-Type guessing.
100 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
101 * Deliver documents in the user-manual directory
102 * with "Content-Type text/css" if their filename
105 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
106 * Incorporate modified version of Roland Rosenfeld's patch to
107 * optionally access the user-manual via Privoxy. Closes patch 679075.
109 * Formatting changed to Privoxy style, added call to
110 * cgi_error_no_template if the requested file doesn't
111 * exist and modified check whether or not Privoxy itself
112 * should serve the manual. Should work cross-platform now.
114 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
115 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
116 * with what was really the latest development (the v_3_0_branch branch)
118 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
119 * Multiple filter file support
121 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
122 * Undo some damaging memory leak patches
124 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
125 * A few memory leaks plugged (mostly on error paths)
127 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
128 * Another instance of:
129 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
130 * Thanks to Magnus Holmgren for the patch
132 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
133 * - Prevent line wrap beween "View/Edit" link buttons on status page
134 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
136 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
137 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
139 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
140 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
142 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
143 * Applying patch from Andreas as provided by Hal on the list.
144 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
146 * Revision 1.35 2002/05/12 21:44:44 jongfoster
147 * Adding amiga.[ch] revision information, if on an amiga.
149 * Revision 1.34 2002/04/30 12:06:12 oes
150 * Deleted unused code from default_cgi
152 * Revision 1.33 2002/04/30 11:14:52 oes
153 * Made csp the first parameter in *action_to_html
155 * Revision 1.32 2002/04/26 18:29:13 jongfoster
156 * Fixing this Visual C++ warning:
157 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
159 * Revision 1.31 2002/04/26 12:54:36 oes
160 * - Kill obsolete REDIRECT_URL code
161 * - Error handling fixes
162 * - Style sheet related HTML snipplet changes
163 * - cgi_show_url_info:
164 * - Matches now in table, actions on single lines,
166 * - standard.action suppressed
167 * - Buttons to View and Edit AFs
169 * Revision 1.30 2002/04/24 02:18:08 oes
170 * - show-status is now the starting point for editing
171 * the actions files, generate list of all AFs with buttons
172 * for viewing and editing, new look for file list (Jon:
173 * buttons now aligned ;-P ), view mode now supports multiple
174 * AFs, name changes, no view links for unspecified files,
175 * no edit link for standard.action.
177 * - Jon's multiple AF patch: cgi_show_url_info now uses all
178 * AFs and marks the output accordingly
180 * Revision 1.29 2002/04/10 13:38:35 oes
181 * load_template signature changed
183 * Revision 1.28 2002/04/07 15:42:12 jongfoster
184 * Fixing send-banner?type=auto when the image-blocker is
185 * a redirect to send-banner
187 * Revision 1.27 2002/04/05 15:50:48 oes
188 * added send-stylesheet CGI
190 * Revision 1.26 2002/04/04 00:36:36 gliptak
191 * always use pcre for matching
193 * Revision 1.25 2002/04/03 22:28:03 gliptak
194 * Removed references to gnu_regex
196 * Revision 1.24 2002/04/02 16:12:47 oes
197 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
199 * Revision 1.23 2002/03/26 22:29:54 swa
200 * we have a new homepage!
202 * Revision 1.22 2002/03/24 16:18:15 jongfoster
205 * Revision 1.21 2002/03/24 15:23:33 jongfoster
208 * Revision 1.20 2002/03/24 13:25:43 swa
209 * name change related issues
211 * Revision 1.19 2002/03/16 23:54:06 jongfoster
212 * Adding graceful termination feature, to help look for memory leaks.
213 * If you enable this (which, by design, has to be done by hand
214 * editing config.h) and then go to http://i.j.b/die, then the program
215 * will exit cleanly after the *next* request. It should free all the
216 * memory that was used.
218 * Revision 1.18 2002/03/12 01:44:49 oes
219 * Changed default for "blocked" image from jb logo to checkboard pattern
221 * Revision 1.17 2002/03/08 16:43:18 oes
222 * Added choice beween GIF and PNG built-in images
224 * Revision 1.16 2002/03/07 03:48:38 oes
225 * - Changed built-in images from GIF to PNG
226 * (with regard to Unisys patent issue)
227 * - Added a 4x4 pattern PNG which is less intrusive
228 * than the logo but also clearly marks the deleted banners
230 * Revision 1.15 2002/03/06 22:54:35 jongfoster
231 * Automated function-comment nitpicking.
233 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
234 * Clean up a little CRLF unpleasantness that suddenly appeared
236 * Revision 1.13 2002/02/21 00:10:37 jongfoster
237 * Adding send-banner?type=auto option
239 * Revision 1.12 2002/01/23 01:03:32 jongfoster
240 * Fixing gcc [CygWin] compiler warnings
242 * Revision 1.11 2002/01/23 00:01:04 jongfoster
243 * Adding cgi_transparent_gif() for http://i.j.b/t
244 * Adding missing html_encode() to many CGI functions.
245 * Adding urlmatch.[ch] to http://i.j.b/show-version
247 * Revision 1.10 2002/01/17 21:10:37 jongfoster
248 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
249 * Also fixing a problem in the same function with improperly quoted URLs
250 * in output HTML, and adding code to handle https:// URLs correctly.
252 * Revision 1.9 2001/11/30 23:09:15 jongfoster
253 * Now reports on FEATURE_CGI_EDIT_ACTIONS
254 * Removing FEATURE_DENY_GZIP from template
256 * Revision 1.8 2001/11/13 00:14:07 jongfoster
257 * Fixing stupid bug now I've figured out what || means.
258 * (It always returns 0 or 1, not one of it's paramaters.)
260 * Revision 1.7 2001/10/23 21:48:19 jongfoster
261 * Cleaning up error handling in CGI functions - they now send back
262 * a HTML error page and should never cause a FATAL error. (Fixes one
263 * potential source of "denial of service" attacks).
265 * CGI actions file editor that works and is actually useful.
267 * Ability to toggle JunkBuster remotely using a CGI call.
269 * You can turn off both the above features in the main configuration
270 * file, e.g. if you are running a multi-user proxy.
272 * Revision 1.6 2001/10/14 22:00:32 jongfoster
273 * Adding support for a 404 error when an invalid CGI page is requested.
275 * Revision 1.5 2001/10/07 15:30:41 oes
276 * Removed FEATURE_DENY_GZIP
278 * Revision 1.4 2001/10/02 15:31:12 oes
279 * Introduced show-request cgi
281 * Revision 1.3 2001/09/22 16:34:44 jongfoster
282 * Removing unneeded #includes
284 * Revision 1.2 2001/09/19 18:01:11 oes
285 * Fixed comments; cosmetics
287 * Revision 1.1 2001/09/16 17:08:54 jongfoster
288 * Moving simple CGI functions from cgi.c to new file cgisimple.c
291 **********************************************************************/
297 #include <sys/types.h>
305 #endif /* def HAVE_ACCESS */
308 #define snprintf _snprintf
309 #endif /* def _WIN32 */
313 #include "cgisimple.h"
319 #include "miscutil.h"
322 #include "urlmatch.h"
325 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
328 static char *show_rcs(void);
329 static jb_err show_defines(struct map *exports);
332 * 16x16 ico blobs for favicon delivery functions.
334 const char default_favicon_data[] =
335 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
336 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
337 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
338 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
339 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
340 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
341 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
342 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
343 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
344 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
345 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
346 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
347 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
349 const char error_favicon_data[] =
350 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
351 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
352 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
353 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
354 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
355 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
356 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
357 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
358 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
359 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
360 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
361 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
362 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
364 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
365 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
367 /*********************************************************************
369 * Function : cgi_default
371 * Description : CGI function that is called for the CGI_SITE_1_HOST
372 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
373 * Boring - only exports the default exports.
376 * 1 : csp = Current client state (buffers, headers, etc...)
377 * 2 : rsp = http_response data structure for output
378 * 3 : parameters = map of cgi parameters
380 * CGI Parameters : none
382 * Returns : JB_ERR_OK on success
383 * JB_ERR_MEMORY on out-of-memory
385 *********************************************************************/
386 jb_err cgi_default(struct client_state *csp,
387 struct http_response *rsp,
388 const struct map *parameters)
395 if (NULL == (exports = default_exports(csp, "")))
397 return JB_ERR_MEMORY;
400 return template_fill_for_cgi(csp, "default", exports, rsp);
404 /*********************************************************************
406 * Function : cgi_error_404
408 * Description : CGI function that is called if an unknown action was
412 * 1 : csp = Current client state (buffers, headers, etc...)
413 * 2 : rsp = http_response data structure for output
414 * 3 : parameters = map of cgi parameters
416 * CGI Parameters : none
418 * Returns : JB_ERR_OK on success
419 * JB_ERR_MEMORY on out-of-memory error.
421 *********************************************************************/
422 jb_err cgi_error_404(struct client_state *csp,
423 struct http_response *rsp,
424 const struct map *parameters)
432 if (NULL == (exports = default_exports(csp, NULL)))
434 return JB_ERR_MEMORY;
437 rsp->status = strdup("404 Privoxy configuration page not found");
438 if (rsp->status == NULL)
441 return JB_ERR_MEMORY;
444 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
448 #ifdef FEATURE_GRACEFUL_TERMINATION
449 /*********************************************************************
453 * Description : CGI function to shut down Privoxy.
454 * NOTE: Turning this on in a production build
455 * would be a BAD idea. An EXTREMELY BAD idea.
456 * In short, don't do it.
459 * 1 : csp = Current client state (buffers, headers, etc...)
460 * 2 : rsp = http_response data structure for output
461 * 3 : parameters = map of cgi parameters
463 * CGI Parameters : none
465 * Returns : JB_ERR_OK on success
466 * JB_ERR_MEMORY on out-of-memory error.
468 *********************************************************************/
469 jb_err cgi_die (struct client_state *csp,
470 struct http_response *rsp,
471 const struct map *parameters)
481 * I don't really care what gets sent back to the browser.
482 * Take the easy option - "out of memory" page.
485 return JB_ERR_MEMORY;
487 #endif /* def FEATURE_GRACEFUL_TERMINATION */
490 /*********************************************************************
492 * Function : cgi_show_request
494 * Description : Show the client's request and what sed() would have
498 * 1 : csp = Current client state (buffers, headers, etc...)
499 * 2 : rsp = http_response data structure for output
500 * 3 : parameters = map of cgi parameters
502 * CGI Parameters : none
504 * Returns : JB_ERR_OK on success
505 * JB_ERR_MEMORY on out-of-memory error.
507 *********************************************************************/
508 jb_err cgi_show_request(struct client_state *csp,
509 struct http_response *rsp,
510 const struct map *parameters)
519 if (NULL == (exports = default_exports(csp, "show-request")))
521 return JB_ERR_MEMORY;
525 * Repair the damage done to the IOB by get_header()
527 for (p = csp->iob->buf; p < csp->iob->eod; p++)
529 if (*p == '\0') *p = '\n';
533 * Export the original client's request and the one we would
534 * be sending to the server if this wasn't a CGI call
537 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
540 return JB_ERR_MEMORY;
543 if (map(exports, "processed-request", 1, html_encode_and_free_original(
544 sed(client_patterns, add_client_headers, csp)), 0))
547 return JB_ERR_MEMORY;
550 return template_fill_for_cgi(csp, "show-request", exports, rsp);
554 /*********************************************************************
556 * Function : cgi_send_banner
558 * Description : CGI function that returns a banner.
561 * 1 : csp = Current client state (buffers, headers, etc...)
562 * 2 : rsp = http_response data structure for output
563 * 3 : parameters = map of cgi parameters
566 * type : Selects the type of banner between "trans", "logo",
567 * and "auto". Defaults to "logo" if absent or invalid.
568 * "auto" means to select as if we were image-blocking.
569 * (Only the first character really counts; b and t are
572 * Returns : JB_ERR_OK on success
573 * JB_ERR_MEMORY on out-of-memory error.
575 *********************************************************************/
576 jb_err cgi_send_banner(struct client_state *csp,
577 struct http_response *rsp,
578 const struct map *parameters)
580 char imagetype = lookup(parameters, "type")[0];
583 * If type is auto, then determine the right thing
584 * to do from the set-image-blocker action
586 if (imagetype == 'a')
593 #ifdef FEATURE_IMAGE_BLOCKING
594 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
596 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
597 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
598 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
602 /* Use default - nothing to do here. */
604 else if (0 == strcmpic(p, "blank"))
608 else if (0 == strcmpic(p, "pattern"))
614 * If the action is to call this CGI, determine
617 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
619 imagetype = p[sizeof(prefix1) - 1];
621 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
623 imagetype = p[sizeof(prefix2) - 1];
627 * Everything else must (should) be a URL to
635 #endif /* def FEATURE_IMAGE_BLOCKING */
639 * Now imagetype is either the non-auto type we were called with,
640 * or it was auto and has since been determined. In any case, we
641 * can proceed to actually answering the request by sending a redirect
642 * or an image as appropriate:
644 if (imagetype == 'r')
646 rsp->status = strdup("302 Local Redirect from Privoxy");
647 if (rsp->status == NULL)
649 return JB_ERR_MEMORY;
651 if (enlist_unique_header(rsp->headers, "Location",
652 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
654 return JB_ERR_MEMORY;
659 if ((imagetype == 'b') || (imagetype == 't'))
661 rsp->body = bindup(image_blank_data, image_blank_length);
662 rsp->content_length = image_blank_length;
666 rsp->body = bindup(image_pattern_data, image_pattern_length);
667 rsp->content_length = image_pattern_length;
670 if (rsp->body == NULL)
672 return JB_ERR_MEMORY;
674 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
676 return JB_ERR_MEMORY;
687 /*********************************************************************
689 * Function : cgi_transparent_image
691 * Description : CGI function that sends a 1x1 transparent image.
694 * 1 : csp = Current client state (buffers, headers, etc...)
695 * 2 : rsp = http_response data structure for output
696 * 3 : parameters = map of cgi parameters
698 * CGI Parameters : None
700 * Returns : JB_ERR_OK on success
701 * JB_ERR_MEMORY on out-of-memory error.
703 *********************************************************************/
704 jb_err cgi_transparent_image(struct client_state *csp,
705 struct http_response *rsp,
706 const struct map *parameters)
708 rsp->body = bindup(image_blank_data, image_blank_length);
709 rsp->content_length = image_blank_length;
711 if (rsp->body == NULL)
713 return JB_ERR_MEMORY;
716 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
718 return JB_ERR_MEMORY;
728 /*********************************************************************
730 * Function : cgi_send_default_favicon
732 * Description : CGI function that sends the standard favicon.
735 * 1 : csp = Current client state (buffers, headers, etc...)
736 * 2 : rsp = http_response data structure for output
737 * 3 : parameters = map of cgi parameters
739 * CGI Parameters : None
741 * Returns : JB_ERR_OK on success
742 * JB_ERR_MEMORY on out-of-memory error.
744 *********************************************************************/
745 jb_err cgi_send_default_favicon(struct client_state *csp,
746 struct http_response *rsp,
747 const struct map *parameters)
749 rsp->body = bindup(default_favicon_data, default_favicon_length);
750 rsp->content_length = default_favicon_length;
752 if (rsp->body == NULL)
754 return JB_ERR_MEMORY;
757 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
759 return JB_ERR_MEMORY;
769 /*********************************************************************
771 * Function : cgi_send_error_favicon
773 * Description : CGI function that sends the favicon for error pages.
776 * 1 : csp = Current client state (buffers, headers, etc...)
777 * 2 : rsp = http_response data structure for output
778 * 3 : parameters = map of cgi parameters
780 * CGI Parameters : None
782 * Returns : JB_ERR_OK on success
783 * JB_ERR_MEMORY on out-of-memory error.
785 *********************************************************************/
786 jb_err cgi_send_error_favicon(struct client_state *csp,
787 struct http_response *rsp,
788 const struct map *parameters)
790 rsp->body = bindup(error_favicon_data, error_favicon_length);
791 rsp->content_length = error_favicon_length;
793 if (rsp->body == NULL)
795 return JB_ERR_MEMORY;
798 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
800 return JB_ERR_MEMORY;
810 /*********************************************************************
812 * Function : cgi_send_stylesheet
814 * Description : CGI function that sends a css stylesheet found
815 * in the cgi-style.css template
818 * 1 : csp = Current client state (buffers, headers, etc...)
819 * 2 : rsp = http_response data structure for output
820 * 3 : parameters = map of cgi parameters
822 * CGI Parameters : None
824 * Returns : JB_ERR_OK on success
825 * JB_ERR_MEMORY on out-of-memory error.
827 *********************************************************************/
828 jb_err cgi_send_stylesheet(struct client_state *csp,
829 struct http_response *rsp,
830 const struct map *parameters)
837 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
839 if (err == JB_ERR_FILE)
842 * No way to tell user; send empty stylesheet
844 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
848 return err; /* JB_ERR_MEMORY */
851 if (enlist(rsp->headers, "Content-Type: text/css"))
853 return JB_ERR_MEMORY;
859 /*********************************************************************
861 * Function : cgi_send_user_manual
863 * Description : CGI function that sends a file in the user
867 * 1 : csp = Current client state (buffers, headers, etc...)
868 * 2 : rsp = http_response data structure for output
869 * 3 : parameters = map of cgi parameters
871 * CGI Parameters : file=name.html, the name of the HTML file
872 * (relative to user-manual from config)
874 * Returns : JB_ERR_OK on success
875 * JB_ERR_MEMORY on out-of-memory error.
877 *********************************************************************/
878 jb_err cgi_send_user_manual(struct client_state *csp,
879 struct http_response *rsp,
880 const struct map *parameters)
882 const char * filename;
885 jb_err err = JB_ERR_OK;
892 if (!parameters->first)
894 /* requested http://p.p/user-manual (without trailing slash) */
895 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
898 get_string_param(parameters, "file", &filename);
899 /* Check paramter for hack attempts */
900 if (filename && strchr(filename, '/'))
902 return JB_ERR_CGI_PARAMS;
904 if (filename && strstr(filename, ".."))
906 return JB_ERR_CGI_PARAMS;
909 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
910 if (full_path == NULL)
912 return JB_ERR_MEMORY;
915 /* Open user-manual file */
916 if (NULL == (fp = fopen(full_path, "rb")))
918 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
919 err = cgi_error_no_template(csp, rsp, full_path);
924 /* Get file length */
925 fseek(fp, 0, SEEK_END);
926 length = (size_t)ftell(fp);
927 fseek(fp, 0, SEEK_SET);
929 /* Allocate memory and load the file directly into the body */
930 rsp->body = (char *)zalloc(length+1);
935 return JB_ERR_MEMORY;
937 if (!fread(rsp->body, length, 1, fp))
940 * May happen if the file size changes between fseek() and fread().
941 * If it does, we just log it and serve what we got.
943 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
948 rsp->content_length = length;
950 /* Guess correct Content-Type based on the filename's ending */
953 length = strlen(filename);
959 if((length>=4) && !strcmp(&filename[length-4], ".css"))
961 err = enlist(rsp->headers, "Content-Type: text/css");
963 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
965 err = enlist(rsp->headers, "Content-Type: image/jpeg");
969 err = enlist(rsp->headers, "Content-Type: text/html");
976 /*********************************************************************
978 * Function : cgi_show_version
980 * Description : CGI function that returns a a web page describing the
981 * file versions of Privoxy.
984 * 1 : csp = Current client state (buffers, headers, etc...)
985 * 2 : rsp = http_response data structure for output
986 * 3 : parameters = map of cgi parameters
988 * CGI Parameters : none
990 * Returns : JB_ERR_OK on success
991 * JB_ERR_MEMORY on out-of-memory error.
993 *********************************************************************/
994 jb_err cgi_show_version(struct client_state *csp,
995 struct http_response *rsp,
996 const struct map *parameters)
1004 if (NULL == (exports = default_exports(csp, "show-version")))
1006 return JB_ERR_MEMORY;
1009 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1012 return JB_ERR_MEMORY;
1015 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1019 /*********************************************************************
1021 * Function : cgi_show_status
1023 * Description : CGI function that returns a web page describing the
1024 * current status of Privoxy.
1027 * 1 : csp = Current client state (buffers, headers, etc...)
1028 * 2 : rsp = http_response data structure for output
1029 * 3 : parameters = map of cgi parameters
1032 * file : Which file to show. Only first letter is checked,
1034 * - "p"ermissions (actions) file
1037 * Default is to show menu and other information.
1039 * Returns : JB_ERR_OK on success
1040 * JB_ERR_MEMORY on out-of-memory error.
1042 *********************************************************************/
1043 jb_err cgi_show_status(struct client_state *csp,
1044 struct http_response *rsp,
1045 const struct map *parameters)
1052 char buf[BUFFER_SIZE];
1053 const char * filename = NULL;
1054 char * file_description = NULL;
1055 #ifdef FEATURE_STATISTICS
1056 float perc_rej; /* Percentage of http requests rejected */
1057 int local_urls_read;
1058 int local_urls_rejected;
1059 #endif /* ndef FEATURE_STATISTICS */
1060 jb_err err = JB_ERR_OK;
1062 struct map *exports;
1068 if (NULL == (exports = default_exports(csp, "show-status")))
1070 return JB_ERR_MEMORY;
1073 switch (*(lookup(parameters, "file")))
1076 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1078 filename = csp->actions_list[i]->filename;
1079 file_description = "Actions File";
1084 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1086 filename = csp->rlist[i]->filename;
1087 file_description = "Filter File";
1091 #ifdef FEATURE_TRUST
1095 filename = csp->tlist->filename;
1096 file_description = "Trust File";
1099 #endif /* def FEATURE_TRUST */
1102 if (NULL != filename)
1104 if ( map(exports, "file-description", 1, file_description, 1)
1105 || map(exports, "filepath", 1, html_encode(filename), 0) )
1108 return JB_ERR_MEMORY;
1111 if ((fp = fopen(filename, "r")) == NULL)
1113 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1116 return JB_ERR_MEMORY;
1122 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1124 string_join (&s, html_encode(buf));
1128 if (map(exports, "contents", 1, s, 0))
1131 return JB_ERR_MEMORY;
1135 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1139 for (j = 0; (s != NULL) && (j < Argc); j++)
1141 if (!err) err = string_join (&s, html_encode(Argv[j]));
1142 if (!err) err = string_append(&s, " ");
1144 if (!err) err = map(exports, "invocation", 1, s, 0);
1146 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1147 if (!err) err = show_defines(exports);
1152 return JB_ERR_MEMORY;
1155 #ifdef FEATURE_STATISTICS
1156 local_urls_read = urls_read;
1157 local_urls_rejected = urls_rejected;
1160 * Need to alter the stats not to include the fetch of this
1163 * Can't do following thread safely! doh!
1166 * urls_rejected--; * This will be incremented subsequently *
1169 if (local_urls_read == 0)
1171 if (!err) err = map_block_killer(exports, "have-stats");
1175 if (!err) err = map_block_killer(exports, "have-no-stats");
1177 perc_rej = (float)local_urls_rejected * 100.0F /
1178 (float)local_urls_read;
1180 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1181 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1183 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1184 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1186 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1187 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1190 #else /* ndef FEATURE_STATISTICS */
1191 err = err || map_block_killer(exports, "statistics");
1192 #endif /* ndef FEATURE_STATISTICS */
1195 * List all action files in use, together with view and edit links,
1196 * except for standard.action, which should only be viewable. (Not
1197 * enforced in the editor itself)
1198 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1201 for (i = 0; i < MAX_AF_FILES; i++)
1203 if (csp->actions_list[i] != NULL)
1205 if (!err) err = string_append(&s, "<tr><td>");
1206 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1207 snprintf(buf, sizeof(buf),
1208 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1209 if (!err) err = string_append(&s, buf);
1211 #ifdef FEATURE_CGI_EDIT_ACTIONS
1212 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
1215 if (access(csp->config->actions_file[i], W_OK) == 0)
1217 #endif /* def HAVE_ACCESS */
1218 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1219 if (!err) err = string_append(&s, buf);
1224 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1226 #endif /* def HAVE_ACCESS */
1230 if (!err) err = string_append(&s, "</td></tr>\n");
1235 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1239 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1243 * List all re_filterfiles in use, together with view options.
1244 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1247 for (i = 0; i < MAX_AF_FILES; i++)
1249 if (csp->rlist[i] != NULL)
1251 if (!err) err = string_append(&s, "<tr><td>");
1252 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1254 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1255 if (!err) err = string_append(&s, buf);
1256 if (!err) err = string_append(&s, "</td></tr>\n");
1261 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1265 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1266 if (!err) err = map_block_killer(exports, "have-filterfile");
1269 #ifdef FEATURE_TRUST
1272 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1276 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1277 if (!err) err = map_block_killer(exports, "have-trustfile");
1280 if (!err) err = map_block_killer(exports, "trust-support");
1281 #endif /* ndef FEATURE_TRUST */
1286 return JB_ERR_MEMORY;
1289 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1293 /*********************************************************************
1295 * Function : cgi_show_url_info
1297 * Description : CGI function that determines and shows which actions
1298 * Privoxy will perform for a given url, and which
1299 * matches starting from the defaults have lead to that.
1302 * 1 : csp = Current client state (buffers, headers, etc...)
1303 * 2 : rsp = http_response data structure for output
1304 * 3 : parameters = map of cgi parameters
1307 * url : The url whose actions are to be determined.
1308 * If url is unset, the url-given conditional will be
1309 * set, so that all but the form can be suppressed in
1312 * Returns : JB_ERR_OK on success
1313 * JB_ERR_MEMORY on out-of-memory error.
1315 *********************************************************************/
1316 jb_err cgi_show_url_info(struct client_state *csp,
1317 struct http_response *rsp,
1318 const struct map *parameters)
1321 struct map *exports;
1328 if (NULL == (exports = default_exports(csp, "show-url-info")))
1330 return JB_ERR_MEMORY;
1334 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1336 url_param = strdup(lookup(parameters, "url"));
1337 if (url_param == NULL)
1340 return JB_ERR_MEMORY;
1345 * Handle prefixes. 4 possibilities:
1346 * 1) "http://" or "https://" prefix present and followed by URL - OK
1347 * 2) Only the "http://" or "https://" part is present, no URL - change
1348 * to empty string so it will be detected later as "no URL".
1349 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1351 * 4) Parameter not specified or is empty string - let this fall through
1352 * for now, next block of code will handle it.
1354 if (0 == strncmp(url_param, "http://", 7))
1356 if (url_param[7] == '\0')
1359 * Empty URL (just prefix).
1360 * Make it totally empty so it's caught by the next if()
1362 url_param[0] = '\0';
1365 else if (0 == strncmp(url_param, "https://", 8))
1367 if (url_param[8] == '\0')
1370 * Empty URL (just prefix).
1371 * Make it totally empty so it's caught by the next if()
1373 url_param[0] = '\0';
1376 else if (url_param[0] != '\0')
1379 * Unknown prefix - assume http://
1381 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1382 if (NULL == url_param_prefixed)
1386 return JB_ERR_MEMORY;
1388 strcpy(url_param_prefixed, "http://");
1389 strcpy(url_param_prefixed + 7, url_param);
1391 url_param = url_param_prefixed;
1395 * Hide "toggle off" warning if Privoxy is toggled on.
1398 #ifdef FEATURE_TOGGLE
1399 (global_toggle_state == 1) &&
1400 #endif /* def FEATURE_TOGGLE */
1401 map_block_killer(exports, "privoxy-is-toggled-off")
1405 return JB_ERR_MEMORY;
1408 if (url_param[0] == '\0')
1410 /* URL paramater not specified, display query form only. */
1412 if (map_block_killer(exports, "url-given")
1413 || map(exports, "url", 1, "", 1))
1416 return JB_ERR_MEMORY;
1421 /* Given a URL, so query it. */
1426 struct file_list *fl;
1427 struct url_actions *b;
1428 struct http_request url_to_query[1];
1429 struct current_action_spec action[1];
1432 if (map(exports, "url", 1, html_encode(url_param), 0))
1436 return JB_ERR_MEMORY;
1439 init_current_action(action);
1441 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1443 free_current_action(action);
1446 return JB_ERR_MEMORY;
1449 err = parse_http_url(url_param, url_to_query, csp);
1453 if (err == JB_ERR_MEMORY)
1455 free_http_request(url_to_query);
1456 free_current_action(action);
1458 return JB_ERR_MEMORY;
1464 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1465 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1467 free_current_action(action);
1468 free_http_request(url_to_query);
1473 return JB_ERR_MEMORY;
1476 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1480 * We have a warning about SSL paths. Hide it for insecure sites.
1482 if (!url_to_query->ssl)
1484 if (map_block_killer(exports, "https"))
1486 free_current_action(action);
1488 free_http_request(url_to_query);
1489 return JB_ERR_MEMORY;
1493 matches = strdup("<table summary=\"\" class=\"transparent\">");
1495 for (i = 0; i < MAX_AF_FILES; i++)
1497 if (NULL == csp->config->actions_file_short[i]
1498 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1502 if ((fl = csp->actions_list[i]) != NULL)
1504 if ((b = fl->f) != NULL)
1506 /* FIXME: Hardcoded HTML! */
1507 string_append(&matches, "<tr><th>In file: ");
1508 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1509 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1510 string_append(&matches, buf);
1511 string_append(&matches, "View</a>");
1512 #ifdef FEATURE_CGI_EDIT_ACTIONS
1513 string_append(&matches, " <a class=\"cmd\" href=\"/edit-actions-list?f=");
1514 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1515 string_append(&matches, "\">Edit</a>");
1517 string_append(&matches, "</th></tr>\n");
1524 for (; (b != NULL) && (matches != NULL); b = b->next)
1526 if (url_match(b->url, url_to_query))
1528 string_append(&matches, "<tr><td>{");
1529 string_join (&matches, actions_to_html(csp, b->action));
1530 string_append(&matches, " }<br>\n<code>");
1531 string_join (&matches, html_encode(b->url->spec));
1532 string_append(&matches, "</code></td></tr>\n");
1534 if (merge_current_action(action, b->action))
1537 free_http_request(url_to_query);
1538 free_current_action(action);
1540 return JB_ERR_MEMORY;
1548 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1551 string_append(&matches, "</table>\n");
1554 * Fill in forwarding settings.
1556 * The possibilities are:
1558 * - http forwarding only
1559 * - socks4(a) forwarding only
1560 * - socks4(a) and http forwarding.
1562 * XXX: Parts of this code could be reused for the
1563 * "forwarding-failed" template which currently doesn't
1564 * display the proxy port and an eventuell second forwarder.
1567 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1569 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1571 if (!err) err = map_block_killer(exports, "socks-forwarder");
1572 if (!err) err = map_block_killer(exports, "http-forwarder");
1576 char port[10]; /* We save proxy ports as int but need a string here */
1578 if (!err) err = map_block_killer(exports, "no-forwarder");
1580 if (fwd->gateway_host != NULL)
1582 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1583 "socks4" : "socks4a", 1);
1584 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1585 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1586 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1590 if (!err) err = map_block_killer(exports, "socks-forwarder");
1593 if (fwd->forward_host != NULL)
1595 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1596 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1597 if (!err) err = map(exports, "forward-port", 1, port, 1);
1601 if (!err) err = map_block_killer(exports, "http-forwarder");
1606 free_http_request(url_to_query);
1608 if (err || matches == NULL)
1610 free_current_action(action);
1612 return JB_ERR_MEMORY;
1615 if (map(exports, "matches", 1, matches , 0))
1617 free_current_action(action);
1619 return JB_ERR_MEMORY;
1622 s = current_action_to_html(csp, action);
1624 free_current_action(action);
1626 if (map(exports, "final", 1, s, 0))
1629 return JB_ERR_MEMORY;
1633 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1637 /*********************************************************************
1639 * Function : cgi_robots_txt
1641 * Description : CGI function to return "/robots.txt".
1644 * 1 : csp = Current client state (buffers, headers, etc...)
1645 * 2 : rsp = http_response data structure for output
1646 * 3 : parameters = map of cgi parameters
1648 * CGI Parameters : None
1650 * Returns : JB_ERR_OK on success
1651 * JB_ERR_MEMORY on out-of-memory error.
1653 *********************************************************************/
1654 jb_err cgi_robots_txt(struct client_state *csp,
1655 struct http_response *rsp,
1656 const struct map *parameters)
1662 "# This is the Privoxy control interface.\n"
1663 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1669 if (rsp->body == NULL)
1671 return JB_ERR_MEMORY;
1674 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1678 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1679 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1681 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1685 /*********************************************************************
1687 * Function : show_defines
1689 * Description : Add to a map the state od all conditional #defines
1690 * used when building
1693 * 1 : exports = map to extend
1695 * Returns : JB_ERR_OK on success
1696 * JB_ERR_MEMORY on out-of-memory error.
1698 *********************************************************************/
1699 static jb_err show_defines(struct map *exports)
1701 jb_err err = JB_ERR_OK;
1704 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1705 #else /* ifndef FEATURE_ACL */
1706 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1707 #endif /* ndef FEATURE_ACL */
1709 #ifdef FEATURE_CGI_EDIT_ACTIONS
1710 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1711 #else /* ifndef FEATURE_COOKIE_JAR */
1712 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1713 #endif /* ndef FEATURE_COOKIE_JAR */
1715 #ifdef FEATURE_COOKIE_JAR
1716 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1717 #else /* ifndef FEATURE_COOKIE_JAR */
1718 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1719 #endif /* ndef FEATURE_COOKIE_JAR */
1721 #ifdef FEATURE_FAST_REDIRECTS
1722 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1723 #else /* ifndef FEATURE_FAST_REDIRECTS */
1724 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1725 #endif /* ndef FEATURE_FAST_REDIRECTS */
1727 #ifdef FEATURE_FORCE_LOAD
1728 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1729 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1730 #else /* ifndef FEATURE_FORCE_LOAD */
1731 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1732 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1733 #endif /* ndef FEATURE_FORCE_LOAD */
1735 #ifdef FEATURE_GRACEFUL_TERMINATION
1736 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1737 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1738 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1739 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1741 #ifdef FEATURE_IMAGE_BLOCKING
1742 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1743 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1744 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1745 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1747 #ifdef FEATURE_IMAGE_DETECT_MSIE
1748 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1749 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1750 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1751 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1753 #ifdef FEATURE_KILL_POPUPS
1754 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1755 #else /* ifndef FEATURE_KILL_POPUPS */
1756 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1757 #endif /* ndef FEATURE_KILL_POPUPS */
1759 #ifdef FEATURE_NO_GIFS
1760 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1761 #else /* ifndef FEATURE_NO_GIFS */
1762 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1763 #endif /* ndef FEATURE_NO_GIFS */
1765 #ifdef FEATURE_PTHREAD
1766 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1767 #else /* ifndef FEATURE_PTHREAD */
1768 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1769 #endif /* ndef FEATURE_PTHREAD */
1771 #ifdef FEATURE_STATISTICS
1772 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1773 #else /* ifndef FEATURE_STATISTICS */
1774 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1775 #endif /* ndef FEATURE_STATISTICS */
1777 #ifdef FEATURE_TOGGLE
1778 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1779 #else /* ifndef FEATURE_TOGGLE */
1780 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1781 #endif /* ndef FEATURE_TOGGLE */
1783 #ifdef FEATURE_TRUST
1784 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1785 #else /* ifndef FEATURE_TRUST */
1786 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1787 #endif /* ndef FEATURE_TRUST */
1790 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1791 #else /* ifndef FEATURE_ZLIB */
1792 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1793 #endif /* ndef FEATURE_ZLIB */
1796 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1797 #else /* ifndef STATIC_PCRE */
1798 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1799 #endif /* ndef STATIC_PCRE */
1802 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1803 #else /* ifndef STATIC_PCRS */
1804 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1805 #endif /* ndef STATIC_PCRS */
1811 /*********************************************************************
1813 * Function : show_rcs
1815 * Description : Create a string with the rcs info for all sourcefiles
1819 * Returns : A string, or NULL on out-of-memory.
1821 *********************************************************************/
1822 static char *show_rcs(void)
1824 char *result = strdup("");
1825 char buf[BUFFER_SIZE];
1827 /* Instead of including *all* dot h's in the project (thus creating a
1828 * tremendous amount of dependencies), I will concede to declaring them
1829 * as extern's. This forces the developer to add to this list, but oh well.
1832 #define SHOW_RCS(__x) \
1834 extern const char __x[]; \
1835 snprintf(buf, sizeof(buf), " %s\n", __x); \
1836 string_append(&result, buf); \
1839 /* In alphabetical order */
1840 SHOW_RCS(actions_h_rcs)
1841 SHOW_RCS(actions_rcs)
1843 SHOW_RCS(amiga_h_rcs)
1845 #endif /* def AMIGA */
1848 #ifdef FEATURE_CGI_EDIT_ACTIONS
1849 SHOW_RCS(cgiedit_h_rcs)
1850 SHOW_RCS(cgiedit_rcs)
1851 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1852 SHOW_RCS(cgisimple_h_rcs)
1853 SHOW_RCS(cgisimple_rcs)
1855 SHOW_RCS(cygwin_h_rcs)
1857 SHOW_RCS(deanimate_h_rcs)
1858 SHOW_RCS(deanimate_rcs)
1859 SHOW_RCS(encode_h_rcs)
1860 SHOW_RCS(encode_rcs)
1861 SHOW_RCS(errlog_h_rcs)
1862 SHOW_RCS(errlog_rcs)
1863 SHOW_RCS(filters_h_rcs)
1864 SHOW_RCS(filters_rcs)
1865 SHOW_RCS(gateway_h_rcs)
1866 SHOW_RCS(gateway_rcs)
1867 SHOW_RCS(jbsockets_h_rcs)
1868 SHOW_RCS(jbsockets_rcs)
1871 #ifdef FEATURE_KILL_POPUPS
1872 SHOW_RCS(killpopup_h_rcs)
1873 SHOW_RCS(killpopup_rcs)
1874 #endif /* def FEATURE_KILL_POPUPS */
1875 SHOW_RCS(list_h_rcs)
1877 SHOW_RCS(loadcfg_h_rcs)
1878 SHOW_RCS(loadcfg_rcs)
1879 SHOW_RCS(loaders_h_rcs)
1880 SHOW_RCS(loaders_rcs)
1881 SHOW_RCS(miscutil_h_rcs)
1882 SHOW_RCS(miscutil_rcs)
1883 SHOW_RCS(parsers_h_rcs)
1884 SHOW_RCS(parsers_rcs)
1886 SHOW_RCS(pcrs_h_rcs)
1887 SHOW_RCS(project_h_rcs)
1888 SHOW_RCS(ssplit_h_rcs)
1889 SHOW_RCS(ssplit_rcs)
1890 SHOW_RCS(urlmatch_h_rcs)
1891 SHOW_RCS(urlmatch_rcs)
1893 #ifndef _WIN_CONSOLE
1894 SHOW_RCS(w32log_h_rcs)
1895 SHOW_RCS(w32log_rcs)
1896 SHOW_RCS(w32res_h_rcs)
1897 SHOW_RCS(w32taskbar_h_rcs)
1898 SHOW_RCS(w32taskbar_rcs)
1899 #endif /* ndef _WIN_CONSOLE */
1900 SHOW_RCS(win32_h_rcs)
1902 #endif /* def _WIN32 */