1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.55 2007/04/13 13:36:46 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.55 2007/04/13 13:36:46 fabiankeil
40 * Reference action files in CGI URLs by id instead
41 * of using the first part of the file name.
42 * Fixes BR 1694250 and BR 1590556.
44 * Revision 1.54 2007/04/09 18:11:35 fabiankeil
45 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
47 * Revision 1.53 2007/04/08 13:21:04 fabiankeil
48 * Reference action files in CGI URLs by id instead
49 * of using the first part of the file name.
50 * Fixes BR 1694250 and BR 1590556.
52 * Revision 1.52 2007/02/13 15:10:26 fabiankeil
53 * Apparently fopen()ing in "binary" mode doesn't require
54 * #ifdefs, it's already done without them in cgiedit.c.
56 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
57 * - Show forwarding settings on the show-url-info page
58 * - Fix some HTML syntax errors.
60 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
61 * Add favicon delivery functions.
63 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
64 * Suppress edit buttons for action files if Privoxy has
65 * no write access. Suggested by Roland in PR 1564026.
67 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
68 * Display warning if show-url-info CGI page
69 * is used while Privoxy is toggled off.
71 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
72 * Use zalloc in cgi_send_user_manual.
74 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
75 * Add FEATURE_ZLIB to the list of conditional
76 * defines at the show-status page.
78 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
79 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
80 * body memory before using it, replaced sprintf calls with snprintf.
82 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
83 * Removed checks whether or not AF_FILES have
84 * data structures associated with them in cgi_show_status.
85 * It doesn't matter as we're only interested in the file names.
87 * For the action files the checks were always true,
88 * but they prevented empty filter files from being
89 * listed. Fixes parts of BR 1619208.
91 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
92 * - Added FEATURE_GRACEFUL_TERMINATION to the
93 * "conditional #defines" section
94 * - Escaped ampersands in generated HTML.
95 * - Renamed re-filter-filename to re-filter-filenames
97 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
98 * Add special treatment for WIN32 to make sure
99 * cgi_send_user_manual opens the files in binary mode.
100 * Fixes BR 1600411 and unbreaks image delivery.
102 * Remove outdated comment.
104 * Revision 1.41 2006/10/09 19:18:28 roro
105 * Redirect http://p.p/user-manual (without trailing slash) to
106 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
108 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
109 * Modified cgi_send_user_manual to serve binary
110 * content without destroying it first. Should also be
111 * faster now. Added ".jpg" check for Content-Type guessing.
113 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
114 * Deliver documents in the user-manual directory
115 * with "Content-Type text/css" if their filename
118 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
119 * Incorporate modified version of Roland Rosenfeld's patch to
120 * optionally access the user-manual via Privoxy. Closes patch 679075.
122 * Formatting changed to Privoxy style, added call to
123 * cgi_error_no_template if the requested file doesn't
124 * exist and modified check whether or not Privoxy itself
125 * should serve the manual. Should work cross-platform now.
127 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
128 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
129 * with what was really the latest development (the v_3_0_branch branch)
131 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
132 * Multiple filter file support
134 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
135 * Undo some damaging memory leak patches
137 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
138 * A few memory leaks plugged (mostly on error paths)
140 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
141 * Another instance of:
142 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
143 * Thanks to Magnus Holmgren for the patch
145 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
146 * - Prevent line wrap beween "View/Edit" link buttons on status page
147 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
149 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
150 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
152 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
153 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
155 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
156 * Applying patch from Andreas as provided by Hal on the list.
157 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
159 * Revision 1.35 2002/05/12 21:44:44 jongfoster
160 * Adding amiga.[ch] revision information, if on an amiga.
162 * Revision 1.34 2002/04/30 12:06:12 oes
163 * Deleted unused code from default_cgi
165 * Revision 1.33 2002/04/30 11:14:52 oes
166 * Made csp the first parameter in *action_to_html
168 * Revision 1.32 2002/04/26 18:29:13 jongfoster
169 * Fixing this Visual C++ warning:
170 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
172 * Revision 1.31 2002/04/26 12:54:36 oes
173 * - Kill obsolete REDIRECT_URL code
174 * - Error handling fixes
175 * - Style sheet related HTML snipplet changes
176 * - cgi_show_url_info:
177 * - Matches now in table, actions on single lines,
179 * - standard.action suppressed
180 * - Buttons to View and Edit AFs
182 * Revision 1.30 2002/04/24 02:18:08 oes
183 * - show-status is now the starting point for editing
184 * the actions files, generate list of all AFs with buttons
185 * for viewing and editing, new look for file list (Jon:
186 * buttons now aligned ;-P ), view mode now supports multiple
187 * AFs, name changes, no view links for unspecified files,
188 * no edit link for standard.action.
190 * - Jon's multiple AF patch: cgi_show_url_info now uses all
191 * AFs and marks the output accordingly
193 * Revision 1.29 2002/04/10 13:38:35 oes
194 * load_template signature changed
196 * Revision 1.28 2002/04/07 15:42:12 jongfoster
197 * Fixing send-banner?type=auto when the image-blocker is
198 * a redirect to send-banner
200 * Revision 1.27 2002/04/05 15:50:48 oes
201 * added send-stylesheet CGI
203 * Revision 1.26 2002/04/04 00:36:36 gliptak
204 * always use pcre for matching
206 * Revision 1.25 2002/04/03 22:28:03 gliptak
207 * Removed references to gnu_regex
209 * Revision 1.24 2002/04/02 16:12:47 oes
210 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
212 * Revision 1.23 2002/03/26 22:29:54 swa
213 * we have a new homepage!
215 * Revision 1.22 2002/03/24 16:18:15 jongfoster
218 * Revision 1.21 2002/03/24 15:23:33 jongfoster
221 * Revision 1.20 2002/03/24 13:25:43 swa
222 * name change related issues
224 * Revision 1.19 2002/03/16 23:54:06 jongfoster
225 * Adding graceful termination feature, to help look for memory leaks.
226 * If you enable this (which, by design, has to be done by hand
227 * editing config.h) and then go to http://i.j.b/die, then the program
228 * will exit cleanly after the *next* request. It should free all the
229 * memory that was used.
231 * Revision 1.18 2002/03/12 01:44:49 oes
232 * Changed default for "blocked" image from jb logo to checkboard pattern
234 * Revision 1.17 2002/03/08 16:43:18 oes
235 * Added choice beween GIF and PNG built-in images
237 * Revision 1.16 2002/03/07 03:48:38 oes
238 * - Changed built-in images from GIF to PNG
239 * (with regard to Unisys patent issue)
240 * - Added a 4x4 pattern PNG which is less intrusive
241 * than the logo but also clearly marks the deleted banners
243 * Revision 1.15 2002/03/06 22:54:35 jongfoster
244 * Automated function-comment nitpicking.
246 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
247 * Clean up a little CRLF unpleasantness that suddenly appeared
249 * Revision 1.13 2002/02/21 00:10:37 jongfoster
250 * Adding send-banner?type=auto option
252 * Revision 1.12 2002/01/23 01:03:32 jongfoster
253 * Fixing gcc [CygWin] compiler warnings
255 * Revision 1.11 2002/01/23 00:01:04 jongfoster
256 * Adding cgi_transparent_gif() for http://i.j.b/t
257 * Adding missing html_encode() to many CGI functions.
258 * Adding urlmatch.[ch] to http://i.j.b/show-version
260 * Revision 1.10 2002/01/17 21:10:37 jongfoster
261 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
262 * Also fixing a problem in the same function with improperly quoted URLs
263 * in output HTML, and adding code to handle https:// URLs correctly.
265 * Revision 1.9 2001/11/30 23:09:15 jongfoster
266 * Now reports on FEATURE_CGI_EDIT_ACTIONS
267 * Removing FEATURE_DENY_GZIP from template
269 * Revision 1.8 2001/11/13 00:14:07 jongfoster
270 * Fixing stupid bug now I've figured out what || means.
271 * (It always returns 0 or 1, not one of it's paramaters.)
273 * Revision 1.7 2001/10/23 21:48:19 jongfoster
274 * Cleaning up error handling in CGI functions - they now send back
275 * a HTML error page and should never cause a FATAL error. (Fixes one
276 * potential source of "denial of service" attacks).
278 * CGI actions file editor that works and is actually useful.
280 * Ability to toggle JunkBuster remotely using a CGI call.
282 * You can turn off both the above features in the main configuration
283 * file, e.g. if you are running a multi-user proxy.
285 * Revision 1.6 2001/10/14 22:00:32 jongfoster
286 * Adding support for a 404 error when an invalid CGI page is requested.
288 * Revision 1.5 2001/10/07 15:30:41 oes
289 * Removed FEATURE_DENY_GZIP
291 * Revision 1.4 2001/10/02 15:31:12 oes
292 * Introduced show-request cgi
294 * Revision 1.3 2001/09/22 16:34:44 jongfoster
295 * Removing unneeded #includes
297 * Revision 1.2 2001/09/19 18:01:11 oes
298 * Fixed comments; cosmetics
300 * Revision 1.1 2001/09/16 17:08:54 jongfoster
301 * Moving simple CGI functions from cgi.c to new file cgisimple.c
304 **********************************************************************/
310 #include <sys/types.h>
318 #endif /* def HAVE_ACCESS */
322 #include "cgisimple.h"
328 #include "miscutil.h"
331 #include "urlmatch.h"
334 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
337 static char *show_rcs(void);
338 static jb_err show_defines(struct map *exports);
341 * 16x16 ico blobs for favicon delivery functions.
343 const char default_favicon_data[] =
344 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
345 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
346 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
347 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
348 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
349 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
350 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
351 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
352 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
353 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
354 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
355 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
356 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
358 const char error_favicon_data[] =
359 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
360 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
361 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
362 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
363 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
364 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
365 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
366 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
367 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
368 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
369 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
370 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
371 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
373 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
374 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
376 /*********************************************************************
378 * Function : cgi_default
380 * Description : CGI function that is called for the CGI_SITE_1_HOST
381 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
382 * Boring - only exports the default exports.
385 * 1 : csp = Current client state (buffers, headers, etc...)
386 * 2 : rsp = http_response data structure for output
387 * 3 : parameters = map of cgi parameters
389 * CGI Parameters : none
391 * Returns : JB_ERR_OK on success
392 * JB_ERR_MEMORY on out-of-memory
394 *********************************************************************/
395 jb_err cgi_default(struct client_state *csp,
396 struct http_response *rsp,
397 const struct map *parameters)
404 if (NULL == (exports = default_exports(csp, "")))
406 return JB_ERR_MEMORY;
409 return template_fill_for_cgi(csp, "default", exports, rsp);
413 /*********************************************************************
415 * Function : cgi_error_404
417 * Description : CGI function that is called if an unknown action was
421 * 1 : csp = Current client state (buffers, headers, etc...)
422 * 2 : rsp = http_response data structure for output
423 * 3 : parameters = map of cgi parameters
425 * CGI Parameters : none
427 * Returns : JB_ERR_OK on success
428 * JB_ERR_MEMORY on out-of-memory error.
430 *********************************************************************/
431 jb_err cgi_error_404(struct client_state *csp,
432 struct http_response *rsp,
433 const struct map *parameters)
441 if (NULL == (exports = default_exports(csp, NULL)))
443 return JB_ERR_MEMORY;
446 rsp->status = strdup("404 Privoxy configuration page not found");
447 if (rsp->status == NULL)
450 return JB_ERR_MEMORY;
453 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
457 #ifdef FEATURE_GRACEFUL_TERMINATION
458 /*********************************************************************
462 * Description : CGI function to shut down Privoxy.
463 * NOTE: Turning this on in a production build
464 * would be a BAD idea. An EXTREMELY BAD idea.
465 * In short, don't do it.
468 * 1 : csp = Current client state (buffers, headers, etc...)
469 * 2 : rsp = http_response data structure for output
470 * 3 : parameters = map of cgi parameters
472 * CGI Parameters : none
474 * Returns : JB_ERR_OK on success
475 * JB_ERR_MEMORY on out-of-memory error.
477 *********************************************************************/
478 jb_err cgi_die (struct client_state *csp,
479 struct http_response *rsp,
480 const struct map *parameters)
490 * I don't really care what gets sent back to the browser.
491 * Take the easy option - "out of memory" page.
494 return JB_ERR_MEMORY;
496 #endif /* def FEATURE_GRACEFUL_TERMINATION */
499 /*********************************************************************
501 * Function : cgi_show_request
503 * Description : Show the client's request and what sed() would have
507 * 1 : csp = Current client state (buffers, headers, etc...)
508 * 2 : rsp = http_response data structure for output
509 * 3 : parameters = map of cgi parameters
511 * CGI Parameters : none
513 * Returns : JB_ERR_OK on success
514 * JB_ERR_MEMORY on out-of-memory error.
516 *********************************************************************/
517 jb_err cgi_show_request(struct client_state *csp,
518 struct http_response *rsp,
519 const struct map *parameters)
528 if (NULL == (exports = default_exports(csp, "show-request")))
530 return JB_ERR_MEMORY;
534 * Repair the damage done to the IOB by get_header()
536 for (p = csp->iob->buf; p < csp->iob->eod; p++)
538 if (*p == '\0') *p = '\n';
542 * Export the original client's request and the one we would
543 * be sending to the server if this wasn't a CGI call
546 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
549 return JB_ERR_MEMORY;
552 if (map(exports, "processed-request", 1, html_encode(list_to_text(csp->headers)), 0))
555 return JB_ERR_MEMORY;
558 return template_fill_for_cgi(csp, "show-request", exports, rsp);
562 /*********************************************************************
564 * Function : cgi_send_banner
566 * Description : CGI function that returns a banner.
569 * 1 : csp = Current client state (buffers, headers, etc...)
570 * 2 : rsp = http_response data structure for output
571 * 3 : parameters = map of cgi parameters
574 * type : Selects the type of banner between "trans", "logo",
575 * and "auto". Defaults to "logo" if absent or invalid.
576 * "auto" means to select as if we were image-blocking.
577 * (Only the first character really counts; b and t are
580 * Returns : JB_ERR_OK on success
581 * JB_ERR_MEMORY on out-of-memory error.
583 *********************************************************************/
584 jb_err cgi_send_banner(struct client_state *csp,
585 struct http_response *rsp,
586 const struct map *parameters)
588 char imagetype = lookup(parameters, "type")[0];
591 * If type is auto, then determine the right thing
592 * to do from the set-image-blocker action
594 if (imagetype == 'a')
601 #ifdef FEATURE_IMAGE_BLOCKING
602 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
604 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
605 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
606 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
610 /* Use default - nothing to do here. */
612 else if (0 == strcmpic(p, "blank"))
616 else if (0 == strcmpic(p, "pattern"))
622 * If the action is to call this CGI, determine
625 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
627 imagetype = p[sizeof(prefix1) - 1];
629 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
631 imagetype = p[sizeof(prefix2) - 1];
635 * Everything else must (should) be a URL to
643 #endif /* def FEATURE_IMAGE_BLOCKING */
647 * Now imagetype is either the non-auto type we were called with,
648 * or it was auto and has since been determined. In any case, we
649 * can proceed to actually answering the request by sending a redirect
650 * or an image as appropriate:
652 if (imagetype == 'r')
654 rsp->status = strdup("302 Local Redirect from Privoxy");
655 if (rsp->status == NULL)
657 return JB_ERR_MEMORY;
659 if (enlist_unique_header(rsp->headers, "Location",
660 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
662 return JB_ERR_MEMORY;
667 if ((imagetype == 'b') || (imagetype == 't'))
669 rsp->body = bindup(image_blank_data, image_blank_length);
670 rsp->content_length = image_blank_length;
674 rsp->body = bindup(image_pattern_data, image_pattern_length);
675 rsp->content_length = image_pattern_length;
678 if (rsp->body == NULL)
680 return JB_ERR_MEMORY;
682 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
684 return JB_ERR_MEMORY;
695 /*********************************************************************
697 * Function : cgi_transparent_image
699 * Description : CGI function that sends a 1x1 transparent image.
702 * 1 : csp = Current client state (buffers, headers, etc...)
703 * 2 : rsp = http_response data structure for output
704 * 3 : parameters = map of cgi parameters
706 * CGI Parameters : None
708 * Returns : JB_ERR_OK on success
709 * JB_ERR_MEMORY on out-of-memory error.
711 *********************************************************************/
712 jb_err cgi_transparent_image(struct client_state *csp,
713 struct http_response *rsp,
714 const struct map *parameters)
716 rsp->body = bindup(image_blank_data, image_blank_length);
717 rsp->content_length = image_blank_length;
719 if (rsp->body == NULL)
721 return JB_ERR_MEMORY;
724 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
726 return JB_ERR_MEMORY;
736 /*********************************************************************
738 * Function : cgi_send_default_favicon
740 * Description : CGI function that sends the standard favicon.
743 * 1 : csp = Current client state (buffers, headers, etc...)
744 * 2 : rsp = http_response data structure for output
745 * 3 : parameters = map of cgi parameters
747 * CGI Parameters : None
749 * Returns : JB_ERR_OK on success
750 * JB_ERR_MEMORY on out-of-memory error.
752 *********************************************************************/
753 jb_err cgi_send_default_favicon(struct client_state *csp,
754 struct http_response *rsp,
755 const struct map *parameters)
757 rsp->body = bindup(default_favicon_data, default_favicon_length);
758 rsp->content_length = default_favicon_length;
760 if (rsp->body == NULL)
762 return JB_ERR_MEMORY;
765 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
767 return JB_ERR_MEMORY;
777 /*********************************************************************
779 * Function : cgi_send_error_favicon
781 * Description : CGI function that sends the favicon for error pages.
784 * 1 : csp = Current client state (buffers, headers, etc...)
785 * 2 : rsp = http_response data structure for output
786 * 3 : parameters = map of cgi parameters
788 * CGI Parameters : None
790 * Returns : JB_ERR_OK on success
791 * JB_ERR_MEMORY on out-of-memory error.
793 *********************************************************************/
794 jb_err cgi_send_error_favicon(struct client_state *csp,
795 struct http_response *rsp,
796 const struct map *parameters)
798 rsp->body = bindup(error_favicon_data, error_favicon_length);
799 rsp->content_length = error_favicon_length;
801 if (rsp->body == NULL)
803 return JB_ERR_MEMORY;
806 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
808 return JB_ERR_MEMORY;
818 /*********************************************************************
820 * Function : cgi_send_stylesheet
822 * Description : CGI function that sends a css stylesheet found
823 * in the cgi-style.css template
826 * 1 : csp = Current client state (buffers, headers, etc...)
827 * 2 : rsp = http_response data structure for output
828 * 3 : parameters = map of cgi parameters
830 * CGI Parameters : None
832 * Returns : JB_ERR_OK on success
833 * JB_ERR_MEMORY on out-of-memory error.
835 *********************************************************************/
836 jb_err cgi_send_stylesheet(struct client_state *csp,
837 struct http_response *rsp,
838 const struct map *parameters)
845 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
847 if (err == JB_ERR_FILE)
850 * No way to tell user; send empty stylesheet
852 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
856 return err; /* JB_ERR_MEMORY */
859 if (enlist(rsp->headers, "Content-Type: text/css"))
861 return JB_ERR_MEMORY;
867 /*********************************************************************
869 * Function : cgi_send_user_manual
871 * Description : CGI function that sends a file in the user
875 * 1 : csp = Current client state (buffers, headers, etc...)
876 * 2 : rsp = http_response data structure for output
877 * 3 : parameters = map of cgi parameters
879 * CGI Parameters : file=name.html, the name of the HTML file
880 * (relative to user-manual from config)
882 * Returns : JB_ERR_OK on success
883 * JB_ERR_MEMORY on out-of-memory error.
885 *********************************************************************/
886 jb_err cgi_send_user_manual(struct client_state *csp,
887 struct http_response *rsp,
888 const struct map *parameters)
890 const char * filename;
893 jb_err err = JB_ERR_OK;
900 if (!parameters->first)
902 /* requested http://p.p/user-manual (without trailing slash) */
903 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
906 get_string_param(parameters, "file", &filename);
907 /* Check paramter for hack attempts */
908 if (filename && strchr(filename, '/'))
910 return JB_ERR_CGI_PARAMS;
912 if (filename && strstr(filename, ".."))
914 return JB_ERR_CGI_PARAMS;
917 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
918 if (full_path == NULL)
920 return JB_ERR_MEMORY;
923 /* Open user-manual file */
924 if (NULL == (fp = fopen(full_path, "rb")))
926 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
927 err = cgi_error_no_template(csp, rsp, full_path);
932 /* Get file length */
933 fseek(fp, 0, SEEK_END);
934 length = (size_t)ftell(fp);
935 fseek(fp, 0, SEEK_SET);
937 /* Allocate memory and load the file directly into the body */
938 rsp->body = (char *)zalloc(length+1);
943 return JB_ERR_MEMORY;
945 if (!fread(rsp->body, length, 1, fp))
948 * May happen if the file size changes between fseek() and fread().
949 * If it does, we just log it and serve what we got.
951 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
956 rsp->content_length = length;
958 /* Guess correct Content-Type based on the filename's ending */
961 length = strlen(filename);
967 if((length>=4) && !strcmp(&filename[length-4], ".css"))
969 err = enlist(rsp->headers, "Content-Type: text/css");
971 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
973 err = enlist(rsp->headers, "Content-Type: image/jpeg");
977 err = enlist(rsp->headers, "Content-Type: text/html");
984 /*********************************************************************
986 * Function : cgi_show_version
988 * Description : CGI function that returns a a web page describing the
989 * file versions of Privoxy.
992 * 1 : csp = Current client state (buffers, headers, etc...)
993 * 2 : rsp = http_response data structure for output
994 * 3 : parameters = map of cgi parameters
996 * CGI Parameters : none
998 * Returns : JB_ERR_OK on success
999 * JB_ERR_MEMORY on out-of-memory error.
1001 *********************************************************************/
1002 jb_err cgi_show_version(struct client_state *csp,
1003 struct http_response *rsp,
1004 const struct map *parameters)
1006 struct map *exports;
1012 if (NULL == (exports = default_exports(csp, "show-version")))
1014 return JB_ERR_MEMORY;
1017 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1020 return JB_ERR_MEMORY;
1023 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1027 /*********************************************************************
1029 * Function : cgi_show_status
1031 * Description : CGI function that returns a web page describing the
1032 * current status of Privoxy.
1035 * 1 : csp = Current client state (buffers, headers, etc...)
1036 * 2 : rsp = http_response data structure for output
1037 * 3 : parameters = map of cgi parameters
1040 * file : Which file to show. Only first letter is checked,
1042 * - "p"ermissions (actions) file
1045 * Default is to show menu and other information.
1047 * Returns : JB_ERR_OK on success
1048 * JB_ERR_MEMORY on out-of-memory error.
1050 *********************************************************************/
1051 jb_err cgi_show_status(struct client_state *csp,
1052 struct http_response *rsp,
1053 const struct map *parameters)
1060 char buf[BUFFER_SIZE];
1061 const char * filename = NULL;
1062 char * file_description = NULL;
1063 #ifdef FEATURE_STATISTICS
1064 float perc_rej; /* Percentage of http requests rejected */
1065 int local_urls_read;
1066 int local_urls_rejected;
1067 #endif /* ndef FEATURE_STATISTICS */
1068 jb_err err = JB_ERR_OK;
1070 struct map *exports;
1076 if (NULL == (exports = default_exports(csp, "show-status")))
1078 return JB_ERR_MEMORY;
1081 switch (*(lookup(parameters, "file")))
1084 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1086 filename = csp->actions_list[i]->filename;
1087 file_description = "Actions File";
1092 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1094 filename = csp->rlist[i]->filename;
1095 file_description = "Filter File";
1099 #ifdef FEATURE_TRUST
1103 filename = csp->tlist->filename;
1104 file_description = "Trust File";
1107 #endif /* def FEATURE_TRUST */
1110 if (NULL != filename)
1112 if ( map(exports, "file-description", 1, file_description, 1)
1113 || map(exports, "filepath", 1, html_encode(filename), 0) )
1116 return JB_ERR_MEMORY;
1119 if ((fp = fopen(filename, "r")) == NULL)
1121 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1124 return JB_ERR_MEMORY;
1130 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1132 string_join (&s, html_encode(buf));
1136 if (map(exports, "contents", 1, s, 0))
1139 return JB_ERR_MEMORY;
1143 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1147 for (j = 0; (s != NULL) && (j < Argc); j++)
1149 if (!err) err = string_join (&s, html_encode(Argv[j]));
1150 if (!err) err = string_append(&s, " ");
1152 if (!err) err = map(exports, "invocation", 1, s, 0);
1154 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1155 if (!err) err = show_defines(exports);
1160 return JB_ERR_MEMORY;
1163 #ifdef FEATURE_STATISTICS
1164 local_urls_read = urls_read;
1165 local_urls_rejected = urls_rejected;
1168 * Need to alter the stats not to include the fetch of this
1171 * Can't do following thread safely! doh!
1174 * urls_rejected--; * This will be incremented subsequently *
1177 if (local_urls_read == 0)
1179 if (!err) err = map_block_killer(exports, "have-stats");
1183 if (!err) err = map_block_killer(exports, "have-no-stats");
1185 perc_rej = (float)local_urls_rejected * 100.0F /
1186 (float)local_urls_read;
1188 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1189 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1191 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1192 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1194 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1195 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1198 #else /* ndef FEATURE_STATISTICS */
1199 err = err || map_block_killer(exports, "statistics");
1200 #endif /* ndef FEATURE_STATISTICS */
1203 * List all action files in use, together with view and edit links,
1204 * except for standard.action, which should only be viewable. (Not
1205 * enforced in the editor itself)
1206 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1209 for (i = 0; i < MAX_AF_FILES; i++)
1211 if (csp->actions_list[i] != NULL)
1213 if (!err) err = string_append(&s, "<tr><td>");
1214 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1215 snprintf(buf, sizeof(buf),
1216 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1217 if (!err) err = string_append(&s, buf);
1219 #ifdef FEATURE_CGI_EDIT_ACTIONS
1220 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
1223 if (access(csp->config->actions_file[i], W_OK) == 0)
1225 #endif /* def HAVE_ACCESS */
1226 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1227 if (!err) err = string_append(&s, buf);
1232 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1234 #endif /* def HAVE_ACCESS */
1238 if (!err) err = string_append(&s, "</td></tr>\n");
1243 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1247 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1251 * List all re_filterfiles in use, together with view options.
1252 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1255 for (i = 0; i < MAX_AF_FILES; i++)
1257 if (csp->rlist[i] != NULL)
1259 if (!err) err = string_append(&s, "<tr><td>");
1260 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1262 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1263 if (!err) err = string_append(&s, buf);
1264 if (!err) err = string_append(&s, "</td></tr>\n");
1269 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1273 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1274 if (!err) err = map_block_killer(exports, "have-filterfile");
1277 #ifdef FEATURE_TRUST
1280 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1284 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1285 if (!err) err = map_block_killer(exports, "have-trustfile");
1288 if (!err) err = map_block_killer(exports, "trust-support");
1289 #endif /* ndef FEATURE_TRUST */
1294 return JB_ERR_MEMORY;
1297 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1301 /*********************************************************************
1303 * Function : cgi_show_url_info
1305 * Description : CGI function that determines and shows which actions
1306 * Privoxy will perform for a given url, and which
1307 * matches starting from the defaults have lead to that.
1310 * 1 : csp = Current client state (buffers, headers, etc...)
1311 * 2 : rsp = http_response data structure for output
1312 * 3 : parameters = map of cgi parameters
1315 * url : The url whose actions are to be determined.
1316 * If url is unset, the url-given conditional will be
1317 * set, so that all but the form can be suppressed in
1320 * Returns : JB_ERR_OK on success
1321 * JB_ERR_MEMORY on out-of-memory error.
1323 *********************************************************************/
1324 jb_err cgi_show_url_info(struct client_state *csp,
1325 struct http_response *rsp,
1326 const struct map *parameters)
1329 struct map *exports;
1336 if (NULL == (exports = default_exports(csp, "show-url-info")))
1338 return JB_ERR_MEMORY;
1342 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1344 url_param = strdup(lookup(parameters, "url"));
1345 if (url_param == NULL)
1348 return JB_ERR_MEMORY;
1353 * Handle prefixes. 4 possibilities:
1354 * 1) "http://" or "https://" prefix present and followed by URL - OK
1355 * 2) Only the "http://" or "https://" part is present, no URL - change
1356 * to empty string so it will be detected later as "no URL".
1357 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1359 * 4) Parameter not specified or is empty string - let this fall through
1360 * for now, next block of code will handle it.
1362 if (0 == strncmp(url_param, "http://", 7))
1364 if (url_param[7] == '\0')
1367 * Empty URL (just prefix).
1368 * Make it totally empty so it's caught by the next if()
1370 url_param[0] = '\0';
1373 else if (0 == strncmp(url_param, "https://", 8))
1375 if (url_param[8] == '\0')
1378 * Empty URL (just prefix).
1379 * Make it totally empty so it's caught by the next if()
1381 url_param[0] = '\0';
1384 else if (url_param[0] != '\0')
1387 * Unknown prefix - assume http://
1389 const size_t url_param_prefixed_size = 7 + 1 + strlen(url_param);
1390 char * url_param_prefixed = malloc(url_param_prefixed_size);
1391 if (NULL == url_param_prefixed)
1395 return JB_ERR_MEMORY;
1397 strlcpy(url_param_prefixed, "http://", url_param_prefixed_size);
1398 strlcat(url_param_prefixed, url_param, url_param_prefixed_size);
1400 url_param = url_param_prefixed;
1404 * Hide "toggle off" warning if Privoxy is toggled on.
1407 #ifdef FEATURE_TOGGLE
1408 (global_toggle_state == 1) &&
1409 #endif /* def FEATURE_TOGGLE */
1410 map_block_killer(exports, "privoxy-is-toggled-off")
1414 return JB_ERR_MEMORY;
1417 if (url_param[0] == '\0')
1419 /* URL paramater not specified, display query form only. */
1421 if (map_block_killer(exports, "url-given")
1422 || map(exports, "url", 1, "", 1))
1425 return JB_ERR_MEMORY;
1430 /* Given a URL, so query it. */
1435 struct file_list *fl;
1436 struct url_actions *b;
1437 struct http_request url_to_query[1];
1438 struct current_action_spec action[1];
1441 if (map(exports, "url", 1, html_encode(url_param), 0))
1445 return JB_ERR_MEMORY;
1448 init_current_action(action);
1450 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1452 free_current_action(action);
1455 return JB_ERR_MEMORY;
1458 err = parse_http_url(url_param, url_to_query, csp);
1462 if (err == JB_ERR_MEMORY)
1464 free_http_request(url_to_query);
1465 free_current_action(action);
1467 return JB_ERR_MEMORY;
1473 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1474 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1476 free_current_action(action);
1477 free_http_request(url_to_query);
1482 return JB_ERR_MEMORY;
1485 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1489 * We have a warning about SSL paths. Hide it for insecure sites.
1491 if (!url_to_query->ssl)
1493 if (map_block_killer(exports, "https"))
1495 free_current_action(action);
1497 free_http_request(url_to_query);
1498 return JB_ERR_MEMORY;
1502 matches = strdup("<table summary=\"\" class=\"transparent\">");
1504 for (i = 0; i < MAX_AF_FILES; i++)
1506 if (NULL == csp->config->actions_file_short[i]
1507 || !strcmp(csp->config->actions_file_short[i], "standard.action")) continue;
1511 if ((fl = csp->actions_list[i]) != NULL)
1513 if ((b = fl->f) != NULL)
1515 /* FIXME: Hardcoded HTML! */
1516 string_append(&matches, "<tr><th>In file: ");
1517 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1518 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1519 string_append(&matches, buf);
1520 string_append(&matches, "View</a>");
1521 #ifdef FEATURE_CGI_EDIT_ACTIONS
1522 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/edit-actions-list?f=%d\">", i);
1523 string_append(&matches, buf);
1524 string_append(&matches, "Edit</a>");
1526 string_append(&matches, "</th></tr>\n");
1533 for (; (b != NULL) && (matches != NULL); b = b->next)
1535 if (url_match(b->url, url_to_query))
1537 string_append(&matches, "<tr><td>{");
1538 string_join (&matches, actions_to_html(csp, b->action));
1539 string_append(&matches, " }<br>\n<code>");
1540 string_join (&matches, html_encode(b->url->spec));
1541 string_append(&matches, "</code></td></tr>\n");
1543 if (merge_current_action(action, b->action))
1546 free_http_request(url_to_query);
1547 free_current_action(action);
1549 return JB_ERR_MEMORY;
1557 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1560 string_append(&matches, "</table>\n");
1563 * Fill in forwarding settings.
1565 * The possibilities are:
1567 * - http forwarding only
1568 * - socks4(a) forwarding only
1569 * - socks4(a) and http forwarding.
1571 * XXX: Parts of this code could be reused for the
1572 * "forwarding-failed" template which currently doesn't
1573 * display the proxy port and an eventuell second forwarder.
1576 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1578 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1580 if (!err) err = map_block_killer(exports, "socks-forwarder");
1581 if (!err) err = map_block_killer(exports, "http-forwarder");
1585 char port[10]; /* We save proxy ports as int but need a string here */
1587 if (!err) err = map_block_killer(exports, "no-forwarder");
1589 if (fwd->gateway_host != NULL)
1591 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1592 "socks4" : "socks4a", 1);
1593 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1594 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1595 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1599 if (!err) err = map_block_killer(exports, "socks-forwarder");
1602 if (fwd->forward_host != NULL)
1604 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1605 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1606 if (!err) err = map(exports, "forward-port", 1, port, 1);
1610 if (!err) err = map_block_killer(exports, "http-forwarder");
1615 free_http_request(url_to_query);
1617 if (err || matches == NULL)
1619 free_current_action(action);
1621 return JB_ERR_MEMORY;
1624 if (map(exports, "matches", 1, matches , 0))
1626 free_current_action(action);
1628 return JB_ERR_MEMORY;
1631 s = current_action_to_html(csp, action);
1633 free_current_action(action);
1635 if (map(exports, "final", 1, s, 0))
1638 return JB_ERR_MEMORY;
1642 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1646 /*********************************************************************
1648 * Function : cgi_robots_txt
1650 * Description : CGI function to return "/robots.txt".
1653 * 1 : csp = Current client state (buffers, headers, etc...)
1654 * 2 : rsp = http_response data structure for output
1655 * 3 : parameters = map of cgi parameters
1657 * CGI Parameters : None
1659 * Returns : JB_ERR_OK on success
1660 * JB_ERR_MEMORY on out-of-memory error.
1662 *********************************************************************/
1663 jb_err cgi_robots_txt(struct client_state *csp,
1664 struct http_response *rsp,
1665 const struct map *parameters)
1671 "# This is the Privoxy control interface.\n"
1672 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1678 if (rsp->body == NULL)
1680 return JB_ERR_MEMORY;
1683 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1687 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1688 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1690 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1694 /*********************************************************************
1696 * Function : show_defines
1698 * Description : Add to a map the state od all conditional #defines
1699 * used when building
1702 * 1 : exports = map to extend
1704 * Returns : JB_ERR_OK on success
1705 * JB_ERR_MEMORY on out-of-memory error.
1707 *********************************************************************/
1708 static jb_err show_defines(struct map *exports)
1710 jb_err err = JB_ERR_OK;
1713 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1714 #else /* ifndef FEATURE_ACL */
1715 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1716 #endif /* ndef FEATURE_ACL */
1718 #ifdef FEATURE_CGI_EDIT_ACTIONS
1719 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1720 #else /* ifndef FEATURE_COOKIE_JAR */
1721 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1722 #endif /* ndef FEATURE_COOKIE_JAR */
1724 #ifdef FEATURE_COOKIE_JAR
1725 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1726 #else /* ifndef FEATURE_COOKIE_JAR */
1727 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1728 #endif /* ndef FEATURE_COOKIE_JAR */
1730 #ifdef FEATURE_FAST_REDIRECTS
1731 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1732 #else /* ifndef FEATURE_FAST_REDIRECTS */
1733 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1734 #endif /* ndef FEATURE_FAST_REDIRECTS */
1736 #ifdef FEATURE_FORCE_LOAD
1737 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1738 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1739 #else /* ifndef FEATURE_FORCE_LOAD */
1740 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1741 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1742 #endif /* ndef FEATURE_FORCE_LOAD */
1744 #ifdef FEATURE_GRACEFUL_TERMINATION
1745 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1746 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1747 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1748 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1750 #ifdef FEATURE_IMAGE_BLOCKING
1751 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1752 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1753 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1754 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1756 #ifdef FEATURE_IMAGE_DETECT_MSIE
1757 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1758 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1759 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1760 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1762 #ifdef FEATURE_KILL_POPUPS
1763 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1764 #else /* ifndef FEATURE_KILL_POPUPS */
1765 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1766 #endif /* ndef FEATURE_KILL_POPUPS */
1768 #ifdef FEATURE_NO_GIFS
1769 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1770 #else /* ifndef FEATURE_NO_GIFS */
1771 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1772 #endif /* ndef FEATURE_NO_GIFS */
1774 #ifdef FEATURE_PTHREAD
1775 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1776 #else /* ifndef FEATURE_PTHREAD */
1777 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1778 #endif /* ndef FEATURE_PTHREAD */
1780 #ifdef FEATURE_STATISTICS
1781 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1782 #else /* ifndef FEATURE_STATISTICS */
1783 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1784 #endif /* ndef FEATURE_STATISTICS */
1786 #ifdef FEATURE_TOGGLE
1787 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1788 #else /* ifndef FEATURE_TOGGLE */
1789 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1790 #endif /* ndef FEATURE_TOGGLE */
1792 #ifdef FEATURE_TRUST
1793 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1794 #else /* ifndef FEATURE_TRUST */
1795 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1796 #endif /* ndef FEATURE_TRUST */
1799 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1800 #else /* ifndef FEATURE_ZLIB */
1801 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1802 #endif /* ndef FEATURE_ZLIB */
1805 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1806 #else /* ifndef STATIC_PCRE */
1807 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1808 #endif /* ndef STATIC_PCRE */
1811 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1812 #else /* ifndef STATIC_PCRS */
1813 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1814 #endif /* ndef STATIC_PCRS */
1820 /*********************************************************************
1822 * Function : show_rcs
1824 * Description : Create a string with the rcs info for all sourcefiles
1828 * Returns : A string, or NULL on out-of-memory.
1830 *********************************************************************/
1831 static char *show_rcs(void)
1833 char *result = strdup("");
1834 char buf[BUFFER_SIZE];
1836 /* Instead of including *all* dot h's in the project (thus creating a
1837 * tremendous amount of dependencies), I will concede to declaring them
1838 * as extern's. This forces the developer to add to this list, but oh well.
1841 #define SHOW_RCS(__x) \
1843 extern const char __x[]; \
1844 snprintf(buf, sizeof(buf), " %s\n", __x); \
1845 string_append(&result, buf); \
1848 /* In alphabetical order */
1849 SHOW_RCS(actions_h_rcs)
1850 SHOW_RCS(actions_rcs)
1852 SHOW_RCS(amiga_h_rcs)
1854 #endif /* def AMIGA */
1857 #ifdef FEATURE_CGI_EDIT_ACTIONS
1858 SHOW_RCS(cgiedit_h_rcs)
1859 SHOW_RCS(cgiedit_rcs)
1860 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1861 SHOW_RCS(cgisimple_h_rcs)
1862 SHOW_RCS(cgisimple_rcs)
1864 SHOW_RCS(cygwin_h_rcs)
1866 SHOW_RCS(deanimate_h_rcs)
1867 SHOW_RCS(deanimate_rcs)
1868 SHOW_RCS(encode_h_rcs)
1869 SHOW_RCS(encode_rcs)
1870 SHOW_RCS(errlog_h_rcs)
1871 SHOW_RCS(errlog_rcs)
1872 SHOW_RCS(filters_h_rcs)
1873 SHOW_RCS(filters_rcs)
1874 SHOW_RCS(gateway_h_rcs)
1875 SHOW_RCS(gateway_rcs)
1876 SHOW_RCS(jbsockets_h_rcs)
1877 SHOW_RCS(jbsockets_rcs)
1880 #ifdef FEATURE_KILL_POPUPS
1881 SHOW_RCS(killpopup_h_rcs)
1882 SHOW_RCS(killpopup_rcs)
1883 #endif /* def FEATURE_KILL_POPUPS */
1884 SHOW_RCS(list_h_rcs)
1886 SHOW_RCS(loadcfg_h_rcs)
1887 SHOW_RCS(loadcfg_rcs)
1888 SHOW_RCS(loaders_h_rcs)
1889 SHOW_RCS(loaders_rcs)
1890 SHOW_RCS(miscutil_h_rcs)
1891 SHOW_RCS(miscutil_rcs)
1892 SHOW_RCS(parsers_h_rcs)
1893 SHOW_RCS(parsers_rcs)
1895 SHOW_RCS(pcrs_h_rcs)
1896 SHOW_RCS(project_h_rcs)
1897 SHOW_RCS(ssplit_h_rcs)
1898 SHOW_RCS(ssplit_rcs)
1899 SHOW_RCS(urlmatch_h_rcs)
1900 SHOW_RCS(urlmatch_rcs)
1902 #ifndef _WIN_CONSOLE
1903 SHOW_RCS(w32log_h_rcs)
1904 SHOW_RCS(w32log_rcs)
1905 SHOW_RCS(w32res_h_rcs)
1906 SHOW_RCS(w32taskbar_h_rcs)
1907 SHOW_RCS(w32taskbar_rcs)
1908 #endif /* ndef _WIN_CONSOLE */
1909 SHOW_RCS(win32_h_rcs)
1911 #endif /* def _WIN32 */