1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.60 2007/10/27 13:12:13 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.60 2007/10/27 13:12:13 fabiankeil
40 * Finish 1.49 and check write access before
41 * showing edit buttons on show-url-info page.
43 * Revision 1.59 2007/10/19 16:42:36 fabiankeil
44 * Plug memory leak I introduced five months ago.
45 * Yay Valgrind and Privoxy-Regression-Test.
47 * Revision 1.58 2007/07/21 12:19:50 fabiankeil
48 * If show-url-info is called with an URL that Privoxy
49 * would reject as invalid, don't show unresolved forwarding
50 * variables, "final matches" or claim the site's secure.
52 * Revision 1.57 2007/06/01 16:53:05 fabiankeil
53 * Adjust cgi_show_url_info() to show what forward-override{}
54 * would do with the requested URL (instead of showing how the
55 * request for the CGI page would be forwarded if it wasn't a
58 * Revision 1.56 2007/05/21 10:50:35 fabiankeil
59 * - Use strlcpy() instead of strcpy().
60 * - Stop treating actions files special. Expect a complete file name
61 * (with or without path) like it's done for the rest of the files.
63 * - Don't rerun sed() in cgi_show_request().
65 * Revision 1.55 2007/04/13 13:36:46 fabiankeil
66 * Reference action files in CGI URLs by id instead
67 * of using the first part of the file name.
68 * Fixes BR 1694250 and BR 1590556.
70 * Revision 1.54 2007/04/09 18:11:35 fabiankeil
71 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
73 * Revision 1.53 2007/04/08 13:21:04 fabiankeil
74 * Reference action files in CGI URLs by id instead
75 * of using the first part of the file name.
76 * Fixes BR 1694250 and BR 1590556.
78 * Revision 1.52 2007/02/13 15:10:26 fabiankeil
79 * Apparently fopen()ing in "binary" mode doesn't require
80 * #ifdefs, it's already done without them in cgiedit.c.
82 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
83 * - Show forwarding settings on the show-url-info page
84 * - Fix some HTML syntax errors.
86 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
87 * Add favicon delivery functions.
89 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
90 * Suppress edit buttons for action files if Privoxy has
91 * no write access. Suggested by Roland in PR 1564026.
93 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
94 * Display warning if show-url-info CGI page
95 * is used while Privoxy is toggled off.
97 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
98 * Use zalloc in cgi_send_user_manual.
100 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
101 * Add FEATURE_ZLIB to the list of conditional
102 * defines at the show-status page.
104 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
105 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
106 * body memory before using it, replaced sprintf calls with snprintf.
108 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
109 * Removed checks whether or not AF_FILES have
110 * data structures associated with them in cgi_show_status.
111 * It doesn't matter as we're only interested in the file names.
113 * For the action files the checks were always true,
114 * but they prevented empty filter files from being
115 * listed. Fixes parts of BR 1619208.
117 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
118 * - Added FEATURE_GRACEFUL_TERMINATION to the
119 * "conditional #defines" section
120 * - Escaped ampersands in generated HTML.
121 * - Renamed re-filter-filename to re-filter-filenames
123 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
124 * Add special treatment for WIN32 to make sure
125 * cgi_send_user_manual opens the files in binary mode.
126 * Fixes BR 1600411 and unbreaks image delivery.
128 * Remove outdated comment.
130 * Revision 1.41 2006/10/09 19:18:28 roro
131 * Redirect http://p.p/user-manual (without trailing slash) to
132 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
134 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
135 * Modified cgi_send_user_manual to serve binary
136 * content without destroying it first. Should also be
137 * faster now. Added ".jpg" check for Content-Type guessing.
139 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
140 * Deliver documents in the user-manual directory
141 * with "Content-Type text/css" if their filename
144 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
145 * Incorporate modified version of Roland Rosenfeld's patch to
146 * optionally access the user-manual via Privoxy. Closes patch 679075.
148 * Formatting changed to Privoxy style, added call to
149 * cgi_error_no_template if the requested file doesn't
150 * exist and modified check whether or not Privoxy itself
151 * should serve the manual. Should work cross-platform now.
153 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
154 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
155 * with what was really the latest development (the v_3_0_branch branch)
157 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
158 * Multiple filter file support
160 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
161 * Undo some damaging memory leak patches
163 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
164 * A few memory leaks plugged (mostly on error paths)
166 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
167 * Another instance of:
168 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
169 * Thanks to Magnus Holmgren for the patch
171 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
172 * - Prevent line wrap beween "View/Edit" link buttons on status page
173 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
175 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
176 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
178 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
179 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
181 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
182 * Applying patch from Andreas as provided by Hal on the list.
183 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
185 * Revision 1.35 2002/05/12 21:44:44 jongfoster
186 * Adding amiga.[ch] revision information, if on an amiga.
188 * Revision 1.34 2002/04/30 12:06:12 oes
189 * Deleted unused code from default_cgi
191 * Revision 1.33 2002/04/30 11:14:52 oes
192 * Made csp the first parameter in *action_to_html
194 * Revision 1.32 2002/04/26 18:29:13 jongfoster
195 * Fixing this Visual C++ warning:
196 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
198 * Revision 1.31 2002/04/26 12:54:36 oes
199 * - Kill obsolete REDIRECT_URL code
200 * - Error handling fixes
201 * - Style sheet related HTML snipplet changes
202 * - cgi_show_url_info:
203 * - Matches now in table, actions on single lines,
205 * - standard.action suppressed
206 * - Buttons to View and Edit AFs
208 * Revision 1.30 2002/04/24 02:18:08 oes
209 * - show-status is now the starting point for editing
210 * the actions files, generate list of all AFs with buttons
211 * for viewing and editing, new look for file list (Jon:
212 * buttons now aligned ;-P ), view mode now supports multiple
213 * AFs, name changes, no view links for unspecified files,
214 * no edit link for standard.action.
216 * - Jon's multiple AF patch: cgi_show_url_info now uses all
217 * AFs and marks the output accordingly
219 * Revision 1.29 2002/04/10 13:38:35 oes
220 * load_template signature changed
222 * Revision 1.28 2002/04/07 15:42:12 jongfoster
223 * Fixing send-banner?type=auto when the image-blocker is
224 * a redirect to send-banner
226 * Revision 1.27 2002/04/05 15:50:48 oes
227 * added send-stylesheet CGI
229 * Revision 1.26 2002/04/04 00:36:36 gliptak
230 * always use pcre for matching
232 * Revision 1.25 2002/04/03 22:28:03 gliptak
233 * Removed references to gnu_regex
235 * Revision 1.24 2002/04/02 16:12:47 oes
236 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
238 * Revision 1.23 2002/03/26 22:29:54 swa
239 * we have a new homepage!
241 * Revision 1.22 2002/03/24 16:18:15 jongfoster
244 * Revision 1.21 2002/03/24 15:23:33 jongfoster
247 * Revision 1.20 2002/03/24 13:25:43 swa
248 * name change related issues
250 * Revision 1.19 2002/03/16 23:54:06 jongfoster
251 * Adding graceful termination feature, to help look for memory leaks.
252 * If you enable this (which, by design, has to be done by hand
253 * editing config.h) and then go to http://i.j.b/die, then the program
254 * will exit cleanly after the *next* request. It should free all the
255 * memory that was used.
257 * Revision 1.18 2002/03/12 01:44:49 oes
258 * Changed default for "blocked" image from jb logo to checkboard pattern
260 * Revision 1.17 2002/03/08 16:43:18 oes
261 * Added choice beween GIF and PNG built-in images
263 * Revision 1.16 2002/03/07 03:48:38 oes
264 * - Changed built-in images from GIF to PNG
265 * (with regard to Unisys patent issue)
266 * - Added a 4x4 pattern PNG which is less intrusive
267 * than the logo but also clearly marks the deleted banners
269 * Revision 1.15 2002/03/06 22:54:35 jongfoster
270 * Automated function-comment nitpicking.
272 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
273 * Clean up a little CRLF unpleasantness that suddenly appeared
275 * Revision 1.13 2002/02/21 00:10:37 jongfoster
276 * Adding send-banner?type=auto option
278 * Revision 1.12 2002/01/23 01:03:32 jongfoster
279 * Fixing gcc [CygWin] compiler warnings
281 * Revision 1.11 2002/01/23 00:01:04 jongfoster
282 * Adding cgi_transparent_gif() for http://i.j.b/t
283 * Adding missing html_encode() to many CGI functions.
284 * Adding urlmatch.[ch] to http://i.j.b/show-version
286 * Revision 1.10 2002/01/17 21:10:37 jongfoster
287 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
288 * Also fixing a problem in the same function with improperly quoted URLs
289 * in output HTML, and adding code to handle https:// URLs correctly.
291 * Revision 1.9 2001/11/30 23:09:15 jongfoster
292 * Now reports on FEATURE_CGI_EDIT_ACTIONS
293 * Removing FEATURE_DENY_GZIP from template
295 * Revision 1.8 2001/11/13 00:14:07 jongfoster
296 * Fixing stupid bug now I've figured out what || means.
297 * (It always returns 0 or 1, not one of it's paramaters.)
299 * Revision 1.7 2001/10/23 21:48:19 jongfoster
300 * Cleaning up error handling in CGI functions - they now send back
301 * a HTML error page and should never cause a FATAL error. (Fixes one
302 * potential source of "denial of service" attacks).
304 * CGI actions file editor that works and is actually useful.
306 * Ability to toggle JunkBuster remotely using a CGI call.
308 * You can turn off both the above features in the main configuration
309 * file, e.g. if you are running a multi-user proxy.
311 * Revision 1.6 2001/10/14 22:00:32 jongfoster
312 * Adding support for a 404 error when an invalid CGI page is requested.
314 * Revision 1.5 2001/10/07 15:30:41 oes
315 * Removed FEATURE_DENY_GZIP
317 * Revision 1.4 2001/10/02 15:31:12 oes
318 * Introduced show-request cgi
320 * Revision 1.3 2001/09/22 16:34:44 jongfoster
321 * Removing unneeded #includes
323 * Revision 1.2 2001/09/19 18:01:11 oes
324 * Fixed comments; cosmetics
326 * Revision 1.1 2001/09/16 17:08:54 jongfoster
327 * Moving simple CGI functions from cgi.c to new file cgisimple.c
330 **********************************************************************/
336 #include <sys/types.h>
344 #endif /* def HAVE_ACCESS */
348 #include "cgisimple.h"
354 #include "miscutil.h"
357 #include "urlmatch.h"
360 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
363 static char *show_rcs(void);
364 static jb_err show_defines(struct map *exports);
367 * 16x16 ico blobs for favicon delivery functions.
369 const char default_favicon_data[] =
370 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
371 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
372 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
373 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
374 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
375 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
376 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
377 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
378 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
379 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
380 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
381 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
382 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
384 const char error_favicon_data[] =
385 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
386 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
387 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
388 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
389 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
390 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
391 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
392 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
393 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
394 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
395 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
396 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
397 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
399 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
400 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
402 /*********************************************************************
404 * Function : cgi_default
406 * Description : CGI function that is called for the CGI_SITE_1_HOST
407 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
408 * Boring - only exports the default exports.
411 * 1 : csp = Current client state (buffers, headers, etc...)
412 * 2 : rsp = http_response data structure for output
413 * 3 : parameters = map of cgi parameters
415 * CGI Parameters : none
417 * Returns : JB_ERR_OK on success
418 * JB_ERR_MEMORY on out-of-memory
420 *********************************************************************/
421 jb_err cgi_default(struct client_state *csp,
422 struct http_response *rsp,
423 const struct map *parameters)
430 if (NULL == (exports = default_exports(csp, "")))
432 return JB_ERR_MEMORY;
435 return template_fill_for_cgi(csp, "default", exports, rsp);
439 /*********************************************************************
441 * Function : cgi_error_404
443 * Description : CGI function that is called if an unknown action was
447 * 1 : csp = Current client state (buffers, headers, etc...)
448 * 2 : rsp = http_response data structure for output
449 * 3 : parameters = map of cgi parameters
451 * CGI Parameters : none
453 * Returns : JB_ERR_OK on success
454 * JB_ERR_MEMORY on out-of-memory error.
456 *********************************************************************/
457 jb_err cgi_error_404(struct client_state *csp,
458 struct http_response *rsp,
459 const struct map *parameters)
467 if (NULL == (exports = default_exports(csp, NULL)))
469 return JB_ERR_MEMORY;
472 rsp->status = strdup("404 Privoxy configuration page not found");
473 if (rsp->status == NULL)
476 return JB_ERR_MEMORY;
479 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
483 #ifdef FEATURE_GRACEFUL_TERMINATION
484 /*********************************************************************
488 * Description : CGI function to shut down Privoxy.
489 * NOTE: Turning this on in a production build
490 * would be a BAD idea. An EXTREMELY BAD idea.
491 * In short, don't do it.
494 * 1 : csp = Current client state (buffers, headers, etc...)
495 * 2 : rsp = http_response data structure for output
496 * 3 : parameters = map of cgi parameters
498 * CGI Parameters : none
500 * Returns : JB_ERR_OK on success
501 * JB_ERR_MEMORY on out-of-memory error.
503 *********************************************************************/
504 jb_err cgi_die (struct client_state *csp,
505 struct http_response *rsp,
506 const struct map *parameters)
516 * I don't really care what gets sent back to the browser.
517 * Take the easy option - "out of memory" page.
520 return JB_ERR_MEMORY;
522 #endif /* def FEATURE_GRACEFUL_TERMINATION */
525 /*********************************************************************
527 * Function : cgi_show_request
529 * Description : Show the client's request and what sed() would have
533 * 1 : csp = Current client state (buffers, headers, etc...)
534 * 2 : rsp = http_response data structure for output
535 * 3 : parameters = map of cgi parameters
537 * CGI Parameters : none
539 * Returns : JB_ERR_OK on success
540 * JB_ERR_MEMORY on out-of-memory error.
542 *********************************************************************/
543 jb_err cgi_show_request(struct client_state *csp,
544 struct http_response *rsp,
545 const struct map *parameters)
554 if (NULL == (exports = default_exports(csp, "show-request")))
556 return JB_ERR_MEMORY;
560 * Repair the damage done to the IOB by get_header()
562 for (p = csp->iob->buf; p < csp->iob->eod; p++)
564 if (*p == '\0') *p = '\n';
568 * Export the original client's request and the one we would
569 * be sending to the server if this wasn't a CGI call
572 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
575 return JB_ERR_MEMORY;
578 if (map(exports, "processed-request", 1,
579 html_encode_and_free_original(list_to_text(csp->headers)), 0))
582 return JB_ERR_MEMORY;
585 return template_fill_for_cgi(csp, "show-request", exports, rsp);
589 /*********************************************************************
591 * Function : cgi_send_banner
593 * Description : CGI function that returns a banner.
596 * 1 : csp = Current client state (buffers, headers, etc...)
597 * 2 : rsp = http_response data structure for output
598 * 3 : parameters = map of cgi parameters
601 * type : Selects the type of banner between "trans", "logo",
602 * and "auto". Defaults to "logo" if absent or invalid.
603 * "auto" means to select as if we were image-blocking.
604 * (Only the first character really counts; b and t are
607 * Returns : JB_ERR_OK on success
608 * JB_ERR_MEMORY on out-of-memory error.
610 *********************************************************************/
611 jb_err cgi_send_banner(struct client_state *csp,
612 struct http_response *rsp,
613 const struct map *parameters)
615 char imagetype = lookup(parameters, "type")[0];
618 * If type is auto, then determine the right thing
619 * to do from the set-image-blocker action
621 if (imagetype == 'a')
628 #ifdef FEATURE_IMAGE_BLOCKING
629 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
631 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
632 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
633 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
637 /* Use default - nothing to do here. */
639 else if (0 == strcmpic(p, "blank"))
643 else if (0 == strcmpic(p, "pattern"))
649 * If the action is to call this CGI, determine
652 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
654 imagetype = p[sizeof(prefix1) - 1];
656 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
658 imagetype = p[sizeof(prefix2) - 1];
662 * Everything else must (should) be a URL to
670 #endif /* def FEATURE_IMAGE_BLOCKING */
674 * Now imagetype is either the non-auto type we were called with,
675 * or it was auto and has since been determined. In any case, we
676 * can proceed to actually answering the request by sending a redirect
677 * or an image as appropriate:
679 if (imagetype == 'r')
681 rsp->status = strdup("302 Local Redirect from Privoxy");
682 if (rsp->status == NULL)
684 return JB_ERR_MEMORY;
686 if (enlist_unique_header(rsp->headers, "Location",
687 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
689 return JB_ERR_MEMORY;
694 if ((imagetype == 'b') || (imagetype == 't'))
696 rsp->body = bindup(image_blank_data, image_blank_length);
697 rsp->content_length = image_blank_length;
701 rsp->body = bindup(image_pattern_data, image_pattern_length);
702 rsp->content_length = image_pattern_length;
705 if (rsp->body == NULL)
707 return JB_ERR_MEMORY;
709 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
711 return JB_ERR_MEMORY;
722 /*********************************************************************
724 * Function : cgi_transparent_image
726 * Description : CGI function that sends a 1x1 transparent image.
729 * 1 : csp = Current client state (buffers, headers, etc...)
730 * 2 : rsp = http_response data structure for output
731 * 3 : parameters = map of cgi parameters
733 * CGI Parameters : None
735 * Returns : JB_ERR_OK on success
736 * JB_ERR_MEMORY on out-of-memory error.
738 *********************************************************************/
739 jb_err cgi_transparent_image(struct client_state *csp,
740 struct http_response *rsp,
741 const struct map *parameters)
743 rsp->body = bindup(image_blank_data, image_blank_length);
744 rsp->content_length = image_blank_length;
746 if (rsp->body == NULL)
748 return JB_ERR_MEMORY;
751 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
753 return JB_ERR_MEMORY;
763 /*********************************************************************
765 * Function : cgi_send_default_favicon
767 * Description : CGI function that sends the standard favicon.
770 * 1 : csp = Current client state (buffers, headers, etc...)
771 * 2 : rsp = http_response data structure for output
772 * 3 : parameters = map of cgi parameters
774 * CGI Parameters : None
776 * Returns : JB_ERR_OK on success
777 * JB_ERR_MEMORY on out-of-memory error.
779 *********************************************************************/
780 jb_err cgi_send_default_favicon(struct client_state *csp,
781 struct http_response *rsp,
782 const struct map *parameters)
784 rsp->body = bindup(default_favicon_data, default_favicon_length);
785 rsp->content_length = default_favicon_length;
787 if (rsp->body == NULL)
789 return JB_ERR_MEMORY;
792 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
794 return JB_ERR_MEMORY;
804 /*********************************************************************
806 * Function : cgi_send_error_favicon
808 * Description : CGI function that sends the favicon for error pages.
811 * 1 : csp = Current client state (buffers, headers, etc...)
812 * 2 : rsp = http_response data structure for output
813 * 3 : parameters = map of cgi parameters
815 * CGI Parameters : None
817 * Returns : JB_ERR_OK on success
818 * JB_ERR_MEMORY on out-of-memory error.
820 *********************************************************************/
821 jb_err cgi_send_error_favicon(struct client_state *csp,
822 struct http_response *rsp,
823 const struct map *parameters)
825 rsp->body = bindup(error_favicon_data, error_favicon_length);
826 rsp->content_length = error_favicon_length;
828 if (rsp->body == NULL)
830 return JB_ERR_MEMORY;
833 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
835 return JB_ERR_MEMORY;
845 /*********************************************************************
847 * Function : cgi_send_stylesheet
849 * Description : CGI function that sends a css stylesheet found
850 * in the cgi-style.css template
853 * 1 : csp = Current client state (buffers, headers, etc...)
854 * 2 : rsp = http_response data structure for output
855 * 3 : parameters = map of cgi parameters
857 * CGI Parameters : None
859 * Returns : JB_ERR_OK on success
860 * JB_ERR_MEMORY on out-of-memory error.
862 *********************************************************************/
863 jb_err cgi_send_stylesheet(struct client_state *csp,
864 struct http_response *rsp,
865 const struct map *parameters)
872 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
874 if (err == JB_ERR_FILE)
877 * No way to tell user; send empty stylesheet
879 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
883 return err; /* JB_ERR_MEMORY */
886 if (enlist(rsp->headers, "Content-Type: text/css"))
888 return JB_ERR_MEMORY;
894 /*********************************************************************
896 * Function : cgi_send_user_manual
898 * Description : CGI function that sends a file in the user
902 * 1 : csp = Current client state (buffers, headers, etc...)
903 * 2 : rsp = http_response data structure for output
904 * 3 : parameters = map of cgi parameters
906 * CGI Parameters : file=name.html, the name of the HTML file
907 * (relative to user-manual from config)
909 * Returns : JB_ERR_OK on success
910 * JB_ERR_MEMORY on out-of-memory error.
912 *********************************************************************/
913 jb_err cgi_send_user_manual(struct client_state *csp,
914 struct http_response *rsp,
915 const struct map *parameters)
917 const char * filename;
920 jb_err err = JB_ERR_OK;
927 if (!parameters->first)
929 /* requested http://p.p/user-manual (without trailing slash) */
930 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
933 get_string_param(parameters, "file", &filename);
934 /* Check paramter for hack attempts */
935 if (filename && strchr(filename, '/'))
937 return JB_ERR_CGI_PARAMS;
939 if (filename && strstr(filename, ".."))
941 return JB_ERR_CGI_PARAMS;
944 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
945 if (full_path == NULL)
947 return JB_ERR_MEMORY;
950 /* Open user-manual file */
951 if (NULL == (fp = fopen(full_path, "rb")))
953 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
954 err = cgi_error_no_template(csp, rsp, full_path);
959 /* Get file length */
960 fseek(fp, 0, SEEK_END);
961 length = (size_t)ftell(fp);
962 fseek(fp, 0, SEEK_SET);
964 /* Allocate memory and load the file directly into the body */
965 rsp->body = (char *)zalloc(length+1);
970 return JB_ERR_MEMORY;
972 if (!fread(rsp->body, length, 1, fp))
975 * May happen if the file size changes between fseek() and fread().
976 * If it does, we just log it and serve what we got.
978 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
983 rsp->content_length = length;
985 /* Guess correct Content-Type based on the filename's ending */
988 length = strlen(filename);
994 if((length>=4) && !strcmp(&filename[length-4], ".css"))
996 err = enlist(rsp->headers, "Content-Type: text/css");
998 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
1000 err = enlist(rsp->headers, "Content-Type: image/jpeg");
1004 err = enlist(rsp->headers, "Content-Type: text/html");
1011 /*********************************************************************
1013 * Function : cgi_show_version
1015 * Description : CGI function that returns a a web page describing the
1016 * file versions of Privoxy.
1019 * 1 : csp = Current client state (buffers, headers, etc...)
1020 * 2 : rsp = http_response data structure for output
1021 * 3 : parameters = map of cgi parameters
1023 * CGI Parameters : none
1025 * Returns : JB_ERR_OK on success
1026 * JB_ERR_MEMORY on out-of-memory error.
1028 *********************************************************************/
1029 jb_err cgi_show_version(struct client_state *csp,
1030 struct http_response *rsp,
1031 const struct map *parameters)
1033 struct map *exports;
1039 if (NULL == (exports = default_exports(csp, "show-version")))
1041 return JB_ERR_MEMORY;
1044 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1047 return JB_ERR_MEMORY;
1050 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1054 /*********************************************************************
1056 * Function : cgi_show_status
1058 * Description : CGI function that returns a web page describing the
1059 * current status of Privoxy.
1062 * 1 : csp = Current client state (buffers, headers, etc...)
1063 * 2 : rsp = http_response data structure for output
1064 * 3 : parameters = map of cgi parameters
1067 * file : Which file to show. Only first letter is checked,
1069 * - "p"ermissions (actions) file
1072 * Default is to show menu and other information.
1074 * Returns : JB_ERR_OK on success
1075 * JB_ERR_MEMORY on out-of-memory error.
1077 *********************************************************************/
1078 jb_err cgi_show_status(struct client_state *csp,
1079 struct http_response *rsp,
1080 const struct map *parameters)
1087 char buf[BUFFER_SIZE];
1088 const char * filename = NULL;
1089 char * file_description = NULL;
1090 #ifdef FEATURE_STATISTICS
1091 float perc_rej; /* Percentage of http requests rejected */
1092 int local_urls_read;
1093 int local_urls_rejected;
1094 #endif /* ndef FEATURE_STATISTICS */
1095 jb_err err = JB_ERR_OK;
1097 struct map *exports;
1103 if (NULL == (exports = default_exports(csp, "show-status")))
1105 return JB_ERR_MEMORY;
1108 switch (*(lookup(parameters, "file")))
1111 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1113 filename = csp->actions_list[i]->filename;
1114 file_description = "Actions File";
1119 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1121 filename = csp->rlist[i]->filename;
1122 file_description = "Filter File";
1126 #ifdef FEATURE_TRUST
1130 filename = csp->tlist->filename;
1131 file_description = "Trust File";
1134 #endif /* def FEATURE_TRUST */
1137 if (NULL != filename)
1139 if ( map(exports, "file-description", 1, file_description, 1)
1140 || map(exports, "filepath", 1, html_encode(filename), 0) )
1143 return JB_ERR_MEMORY;
1146 if ((fp = fopen(filename, "r")) == NULL)
1148 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1151 return JB_ERR_MEMORY;
1157 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1159 string_join (&s, html_encode(buf));
1163 if (map(exports, "contents", 1, s, 0))
1166 return JB_ERR_MEMORY;
1170 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1174 for (j = 0; (s != NULL) && (j < Argc); j++)
1176 if (!err) err = string_join (&s, html_encode(Argv[j]));
1177 if (!err) err = string_append(&s, " ");
1179 if (!err) err = map(exports, "invocation", 1, s, 0);
1181 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1182 if (!err) err = show_defines(exports);
1187 return JB_ERR_MEMORY;
1190 #ifdef FEATURE_STATISTICS
1191 local_urls_read = urls_read;
1192 local_urls_rejected = urls_rejected;
1195 * Need to alter the stats not to include the fetch of this
1198 * Can't do following thread safely! doh!
1201 * urls_rejected--; * This will be incremented subsequently *
1204 if (local_urls_read == 0)
1206 if (!err) err = map_block_killer(exports, "have-stats");
1210 if (!err) err = map_block_killer(exports, "have-no-stats");
1212 perc_rej = (float)local_urls_rejected * 100.0F /
1213 (float)local_urls_read;
1215 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1216 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1218 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1219 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1221 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1222 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1225 #else /* ndef FEATURE_STATISTICS */
1226 err = err || map_block_killer(exports, "statistics");
1227 #endif /* ndef FEATURE_STATISTICS */
1230 * List all action files in use, together with view and edit links,
1231 * except for standard.action, which should only be viewable. (Not
1232 * enforced in the editor itself)
1233 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1236 for (i = 0; i < MAX_AF_FILES; i++)
1238 if (csp->actions_list[i] != NULL)
1240 if (!err) err = string_append(&s, "<tr><td>");
1241 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1242 snprintf(buf, sizeof(buf),
1243 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1244 if (!err) err = string_append(&s, buf);
1246 #ifdef FEATURE_CGI_EDIT_ACTIONS
1247 if ((csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS)
1248 && (NULL == strstr(csp->actions_list[i]->filename, "standard.action"))
1249 && (NULL != csp->config->actions_file_short[i]))
1252 if (access(csp->config->actions_file[i], W_OK) == 0)
1254 #endif /* def HAVE_ACCESS */
1255 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1256 if (!err) err = string_append(&s, buf);
1261 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1263 #endif /* def HAVE_ACCESS */
1267 if (!err) err = string_append(&s, "</td></tr>\n");
1272 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1276 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1280 * List all re_filterfiles in use, together with view options.
1281 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1284 for (i = 0; i < MAX_AF_FILES; i++)
1286 if (csp->rlist[i] != NULL)
1288 if (!err) err = string_append(&s, "<tr><td>");
1289 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1291 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1292 if (!err) err = string_append(&s, buf);
1293 if (!err) err = string_append(&s, "</td></tr>\n");
1298 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1302 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1303 if (!err) err = map_block_killer(exports, "have-filterfile");
1306 #ifdef FEATURE_TRUST
1309 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1313 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1314 if (!err) err = map_block_killer(exports, "have-trustfile");
1317 if (!err) err = map_block_killer(exports, "trust-support");
1318 #endif /* ndef FEATURE_TRUST */
1320 #ifdef FEATURE_CGI_EDIT_ACTIONS
1321 if (!err && (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
1323 err = map_block_killer(exports, "cgi-editor-is-disabled");
1325 #endif /* ndef CGI_EDIT_ACTIONS */
1330 return JB_ERR_MEMORY;
1333 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1337 /*********************************************************************
1339 * Function : cgi_show_url_info
1341 * Description : CGI function that determines and shows which actions
1342 * Privoxy will perform for a given url, and which
1343 * matches starting from the defaults have lead to that.
1346 * 1 : csp = Current client state (buffers, headers, etc...)
1347 * 2 : rsp = http_response data structure for output
1348 * 3 : parameters = map of cgi parameters
1351 * url : The url whose actions are to be determined.
1352 * If url is unset, the url-given conditional will be
1353 * set, so that all but the form can be suppressed in
1356 * Returns : JB_ERR_OK on success
1357 * JB_ERR_MEMORY on out-of-memory error.
1359 *********************************************************************/
1360 jb_err cgi_show_url_info(struct client_state *csp,
1361 struct http_response *rsp,
1362 const struct map *parameters)
1365 struct map *exports;
1372 if (NULL == (exports = default_exports(csp, "show-url-info")))
1374 return JB_ERR_MEMORY;
1378 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1380 url_param = strdup(lookup(parameters, "url"));
1381 if (url_param == NULL)
1384 return JB_ERR_MEMORY;
1389 * Handle prefixes. 4 possibilities:
1390 * 1) "http://" or "https://" prefix present and followed by URL - OK
1391 * 2) Only the "http://" or "https://" part is present, no URL - change
1392 * to empty string so it will be detected later as "no URL".
1393 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1395 * 4) Parameter not specified or is empty string - let this fall through
1396 * for now, next block of code will handle it.
1398 if (0 == strncmp(url_param, "http://", 7))
1400 if (url_param[7] == '\0')
1403 * Empty URL (just prefix).
1404 * Make it totally empty so it's caught by the next if()
1406 url_param[0] = '\0';
1409 else if (0 == strncmp(url_param, "https://", 8))
1411 if (url_param[8] == '\0')
1414 * Empty URL (just prefix).
1415 * Make it totally empty so it's caught by the next if()
1417 url_param[0] = '\0';
1420 else if (url_param[0] != '\0')
1423 * Unknown prefix - assume http://
1425 const size_t url_param_prefixed_size = 7 + 1 + strlen(url_param);
1426 char * url_param_prefixed = malloc(url_param_prefixed_size);
1427 if (NULL == url_param_prefixed)
1431 return JB_ERR_MEMORY;
1433 strlcpy(url_param_prefixed, "http://", url_param_prefixed_size);
1434 strlcat(url_param_prefixed, url_param, url_param_prefixed_size);
1436 url_param = url_param_prefixed;
1440 * Hide "toggle off" warning if Privoxy is toggled on.
1443 #ifdef FEATURE_TOGGLE
1444 (global_toggle_state == 1) &&
1445 #endif /* def FEATURE_TOGGLE */
1446 map_block_killer(exports, "privoxy-is-toggled-off")
1450 return JB_ERR_MEMORY;
1453 if (url_param[0] == '\0')
1455 /* URL paramater not specified, display query form only. */
1457 if (map_block_killer(exports, "url-given")
1458 || map(exports, "url", 1, "", 1))
1461 return JB_ERR_MEMORY;
1466 /* Given a URL, so query it. */
1471 struct file_list *fl;
1472 struct url_actions *b;
1473 struct http_request url_to_query[1];
1474 struct current_action_spec action[1];
1477 if (map(exports, "url", 1, html_encode(url_param), 0))
1481 return JB_ERR_MEMORY;
1484 init_current_action(action);
1486 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1488 free_current_action(action);
1491 return JB_ERR_MEMORY;
1494 err = parse_http_url(url_param, url_to_query, csp);
1498 if (err == JB_ERR_MEMORY)
1500 free_http_request(url_to_query);
1501 free_current_action(action);
1503 return JB_ERR_MEMORY;
1509 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1510 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1511 if (!err) err = map_block_killer(exports, "valid-url");
1513 free_current_action(action);
1514 free_http_request(url_to_query);
1519 return JB_ERR_MEMORY;
1522 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1526 * We have a warning about SSL paths. Hide it for unencrypted sites.
1528 if (!url_to_query->ssl)
1530 if (map_block_killer(exports, "https"))
1532 free_current_action(action);
1534 free_http_request(url_to_query);
1535 return JB_ERR_MEMORY;
1539 matches = strdup("<table summary=\"\" class=\"transparent\">");
1541 for (i = 0; i < MAX_AF_FILES; i++)
1543 if (NULL == csp->config->actions_file_short[i]
1544 || !strcmp(csp->config->actions_file_short[i], "standard.action")) continue;
1548 if ((fl = csp->actions_list[i]) != NULL)
1550 if ((b = fl->f) != NULL)
1552 /* FIXME: Hardcoded HTML! */
1553 string_append(&matches, "<tr><th>In file: ");
1554 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1555 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1556 string_append(&matches, buf);
1557 string_append(&matches, "View</a>");
1558 #ifdef FEATURE_CGI_EDIT_ACTIONS
1560 if (access(csp->config->actions_file[i], W_OK) == 0)
1562 #endif /* def HAVE_ACCESS */
1563 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/edit-actions-list?f=%d\">", i);
1564 string_append(&matches, buf);
1565 string_append(&matches, "Edit</a>");
1570 string_append(&matches, " <strong>No write access.</strong>");
1572 #endif /* def HAVE_ACCESS */
1573 #endif /* FEATURE_CGI_EDIT_ACTIONS */
1575 string_append(&matches, "</th></tr>\n");
1582 for (; (b != NULL) && (matches != NULL); b = b->next)
1584 if (url_match(b->url, url_to_query))
1586 string_append(&matches, "<tr><td>{");
1587 string_join (&matches, actions_to_html(csp, b->action));
1588 string_append(&matches, " }<br>\n<code>");
1589 string_join (&matches, html_encode(b->url->spec));
1590 string_append(&matches, "</code></td></tr>\n");
1592 if (merge_current_action(action, b->action))
1595 free_http_request(url_to_query);
1596 free_current_action(action);
1598 return JB_ERR_MEMORY;
1606 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1609 string_append(&matches, "</table>\n");
1612 * XXX: Kludge to make sure the "Forward settings" section
1613 * shows what forward-override{} would do with the requested URL.
1614 * No one really cares how the CGI request would be forwarded
1615 * if it wasn't intercepted as CGI request in the first place.
1617 * From here on the action bitmask will no longer reflect
1618 * the real url (http://config.privoxy.org/show-url-info?url=.*),
1619 * but luckily it's no longer required later on anyway.
1621 free_current_action(csp->action);
1622 url_actions(url_to_query, csp);
1625 * Fill in forwarding settings.
1627 * The possibilities are:
1629 * - http forwarding only
1630 * - socks4(a) forwarding only
1631 * - socks4(a) and http forwarding.
1633 * XXX: Parts of this code could be reused for the
1634 * "forwarding-failed" template which currently doesn't
1635 * display the proxy port and an eventual second forwarder.
1638 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1640 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1642 if (!err) err = map_block_killer(exports, "socks-forwarder");
1643 if (!err) err = map_block_killer(exports, "http-forwarder");
1647 char port[10]; /* We save proxy ports as int but need a string here */
1649 if (!err) err = map_block_killer(exports, "no-forwarder");
1651 if (fwd->gateway_host != NULL)
1653 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1654 "socks4" : "socks4a", 1);
1655 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1656 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1657 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1661 if (!err) err = map_block_killer(exports, "socks-forwarder");
1664 if (fwd->forward_host != NULL)
1666 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1667 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1668 if (!err) err = map(exports, "forward-port", 1, port, 1);
1672 if (!err) err = map_block_killer(exports, "http-forwarder");
1677 free_http_request(url_to_query);
1679 if (err || matches == NULL)
1681 free_current_action(action);
1683 return JB_ERR_MEMORY;
1686 if (map(exports, "matches", 1, matches , 0))
1688 free_current_action(action);
1690 return JB_ERR_MEMORY;
1693 s = current_action_to_html(csp, action);
1695 free_current_action(action);
1697 if (map(exports, "final", 1, s, 0))
1700 return JB_ERR_MEMORY;
1704 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1708 /*********************************************************************
1710 * Function : cgi_robots_txt
1712 * Description : CGI function to return "/robots.txt".
1715 * 1 : csp = Current client state (buffers, headers, etc...)
1716 * 2 : rsp = http_response data structure for output
1717 * 3 : parameters = map of cgi parameters
1719 * CGI Parameters : None
1721 * Returns : JB_ERR_OK on success
1722 * JB_ERR_MEMORY on out-of-memory error.
1724 *********************************************************************/
1725 jb_err cgi_robots_txt(struct client_state *csp,
1726 struct http_response *rsp,
1727 const struct map *parameters)
1733 "# This is the Privoxy control interface.\n"
1734 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1740 if (rsp->body == NULL)
1742 return JB_ERR_MEMORY;
1745 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1749 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1750 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1752 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1756 /*********************************************************************
1758 * Function : show_defines
1760 * Description : Add to a map the state od all conditional #defines
1761 * used when building
1764 * 1 : exports = map to extend
1766 * Returns : JB_ERR_OK on success
1767 * JB_ERR_MEMORY on out-of-memory error.
1769 *********************************************************************/
1770 static jb_err show_defines(struct map *exports)
1772 jb_err err = JB_ERR_OK;
1775 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1776 #else /* ifndef FEATURE_ACL */
1777 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1778 #endif /* ndef FEATURE_ACL */
1780 #ifdef FEATURE_CGI_EDIT_ACTIONS
1781 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1782 #else /* ifndef FEATURE_COOKIE_JAR */
1783 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1784 #endif /* ndef FEATURE_COOKIE_JAR */
1786 #ifdef FEATURE_COOKIE_JAR
1787 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1788 #else /* ifndef FEATURE_COOKIE_JAR */
1789 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1790 #endif /* ndef FEATURE_COOKIE_JAR */
1792 #ifdef FEATURE_FAST_REDIRECTS
1793 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1794 #else /* ifndef FEATURE_FAST_REDIRECTS */
1795 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1796 #endif /* ndef FEATURE_FAST_REDIRECTS */
1798 #ifdef FEATURE_FORCE_LOAD
1799 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1800 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1801 #else /* ifndef FEATURE_FORCE_LOAD */
1802 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1803 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1804 #endif /* ndef FEATURE_FORCE_LOAD */
1806 #ifdef FEATURE_GRACEFUL_TERMINATION
1807 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1808 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1809 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1810 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1812 #ifdef FEATURE_IMAGE_BLOCKING
1813 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1814 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1815 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1816 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1818 #ifdef FEATURE_IMAGE_DETECT_MSIE
1819 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1820 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1821 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1822 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1824 #ifdef FEATURE_KILL_POPUPS
1825 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1826 #else /* ifndef FEATURE_KILL_POPUPS */
1827 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1828 #endif /* ndef FEATURE_KILL_POPUPS */
1830 #ifdef FEATURE_NO_GIFS
1831 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1832 #else /* ifndef FEATURE_NO_GIFS */
1833 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1834 #endif /* ndef FEATURE_NO_GIFS */
1836 #ifdef FEATURE_PTHREAD
1837 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1838 #else /* ifndef FEATURE_PTHREAD */
1839 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1840 #endif /* ndef FEATURE_PTHREAD */
1842 #ifdef FEATURE_STATISTICS
1843 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1844 #else /* ifndef FEATURE_STATISTICS */
1845 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1846 #endif /* ndef FEATURE_STATISTICS */
1848 #ifdef FEATURE_TOGGLE
1849 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1850 #else /* ifndef FEATURE_TOGGLE */
1851 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1852 #endif /* ndef FEATURE_TOGGLE */
1854 #ifdef FEATURE_TRUST
1855 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1856 #else /* ifndef FEATURE_TRUST */
1857 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1858 #endif /* ndef FEATURE_TRUST */
1861 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1862 #else /* ifndef FEATURE_ZLIB */
1863 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1864 #endif /* ndef FEATURE_ZLIB */
1867 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1868 #else /* ifndef STATIC_PCRE */
1869 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1870 #endif /* ndef STATIC_PCRE */
1873 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1874 #else /* ifndef STATIC_PCRS */
1875 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1876 #endif /* ndef STATIC_PCRS */
1882 /*********************************************************************
1884 * Function : show_rcs
1886 * Description : Create a string with the rcs info for all sourcefiles
1890 * Returns : A string, or NULL on out-of-memory.
1892 *********************************************************************/
1893 static char *show_rcs(void)
1895 char *result = strdup("");
1896 char buf[BUFFER_SIZE];
1898 /* Instead of including *all* dot h's in the project (thus creating a
1899 * tremendous amount of dependencies), I will concede to declaring them
1900 * as extern's. This forces the developer to add to this list, but oh well.
1903 #define SHOW_RCS(__x) \
1905 extern const char __x[]; \
1906 snprintf(buf, sizeof(buf), " %s\n", __x); \
1907 string_append(&result, buf); \
1910 /* In alphabetical order */
1911 SHOW_RCS(actions_h_rcs)
1912 SHOW_RCS(actions_rcs)
1914 SHOW_RCS(amiga_h_rcs)
1916 #endif /* def AMIGA */
1919 #ifdef FEATURE_CGI_EDIT_ACTIONS
1920 SHOW_RCS(cgiedit_h_rcs)
1921 SHOW_RCS(cgiedit_rcs)
1922 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1923 SHOW_RCS(cgisimple_h_rcs)
1924 SHOW_RCS(cgisimple_rcs)
1926 SHOW_RCS(cygwin_h_rcs)
1928 SHOW_RCS(deanimate_h_rcs)
1929 SHOW_RCS(deanimate_rcs)
1930 SHOW_RCS(encode_h_rcs)
1931 SHOW_RCS(encode_rcs)
1932 SHOW_RCS(errlog_h_rcs)
1933 SHOW_RCS(errlog_rcs)
1934 SHOW_RCS(filters_h_rcs)
1935 SHOW_RCS(filters_rcs)
1936 SHOW_RCS(gateway_h_rcs)
1937 SHOW_RCS(gateway_rcs)
1938 SHOW_RCS(jbsockets_h_rcs)
1939 SHOW_RCS(jbsockets_rcs)
1942 #ifdef FEATURE_KILL_POPUPS
1943 SHOW_RCS(killpopup_h_rcs)
1944 SHOW_RCS(killpopup_rcs)
1945 #endif /* def FEATURE_KILL_POPUPS */
1946 SHOW_RCS(list_h_rcs)
1948 SHOW_RCS(loadcfg_h_rcs)
1949 SHOW_RCS(loadcfg_rcs)
1950 SHOW_RCS(loaders_h_rcs)
1951 SHOW_RCS(loaders_rcs)
1952 SHOW_RCS(miscutil_h_rcs)
1953 SHOW_RCS(miscutil_rcs)
1954 SHOW_RCS(parsers_h_rcs)
1955 SHOW_RCS(parsers_rcs)
1957 SHOW_RCS(pcrs_h_rcs)
1958 SHOW_RCS(project_h_rcs)
1959 SHOW_RCS(ssplit_h_rcs)
1960 SHOW_RCS(ssplit_rcs)
1961 SHOW_RCS(urlmatch_h_rcs)
1962 SHOW_RCS(urlmatch_rcs)
1964 #ifndef _WIN_CONSOLE
1965 SHOW_RCS(w32log_h_rcs)
1966 SHOW_RCS(w32log_rcs)
1967 SHOW_RCS(w32res_h_rcs)
1968 SHOW_RCS(w32taskbar_h_rcs)
1969 SHOW_RCS(w32taskbar_rcs)
1970 #endif /* ndef _WIN_CONSOLE */
1971 SHOW_RCS(win32_h_rcs)
1973 #endif /* def _WIN32 */