From: David Schmidt Date: Mon, 22 Sep 2003 00:33:01 +0000 (+0000) Subject: Enable sending a custom 'blocked' image. Shows up as X-Git-Tag: v_3_1_archive_branchpoint~11 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=4358bf8b00f9591e18d2d7baa94f83efc5224e6c;ds=sidebyside Enable sending a custom 'blocked' image. Shows up as "image-blocker-custom-file" parameter in config, and "+set-image-blocker{custom}" in action files. --- diff --git a/ChangeLog b/ChangeLog index 0eacb894..d692c00d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,8 @@ ChangeLog for Privoxy - Add an INSTALL file, and remove these instructions from README. - Add a demoronizer filter, which fixes MS's abuse of std charsets (common cases anyway). +- Add a 'dashboard' to watch activity in real-time - implemented + as a GUI in Java *** Version 3.0 *** diff --git a/config b/config index 8e34eb8e..de69de6f 100644 --- a/config +++ b/config @@ -2,7 +2,7 @@ # # Copyright (C) 2001, 2002 Privoxy Developers http://privoxy.org # -# $Id: config,v 1.43 2003/02/20 13:51:50 hal9 Exp $ +# $Id: config,v 1.44 2003/04/20 17:37:28 hal9 Exp $ # #################################################################### # # @@ -325,6 +325,37 @@ jarfile jarfile # #trustfile trust +# +# 1.8. image-blocker-custom-file +# ============== +# +# Specifies: +# +# The custom image to display for blocked images when +# +set-image-blocker{custom} is in effect in an action file +# +# Type of value: +# +# File name, relative to confdir; can be a jpeg, png or gif image +# +# Default value: +# +# Unset +# +# Effect if unset: +# +# If a custom image is called for and it is unset, the "pattern" +# built-in image will be sent instead. I.e. it is as if you had +# specified "+set-image-blocker{pattern}" instead of +# "+set-image-blocker{custom}". +# +# Notes: +# +# If the specified file signature is not found to be jpeg, png +# or gif, the the built-in "pattern" image will be sent instead. +# +#image-blocker-custom-file my-custom-image.jpg + # # 2. LOCAL SET-UP DOCUMENTATION # ============================= diff --git a/default.action.master b/default.action.master index 71332269..87b0cb95 100644 --- a/default.action.master +++ b/default.action.master @@ -2,7 +2,7 @@ # # File : $Source: /cvsroot/ijbswa/current/default.action.master,v $ # -# $Id: default.action.master,v 1.6 2002/10/20 19:33:07 hal9 Exp $ +# $Id: default.action.master,v 1.7 2003/02/20 14:00:55 hal9 Exp $ # # Purpose : Default actions file, see # http://www.privoxy.org/user-manual/actions-file.html @@ -285,15 +285,17 @@ # # +set-image-blocker{blank} # +set-image-blocker{pattern} +# +set-image-blocker{custom} # +set-image-blocker{} with being any valid image URL # Decides what to do with URLs that end up tagged with {+block +handle-as-image}. -# There are 4 options: +# There are 5 options: # * "-set-image-blocker" will send a HTML "blocked" page, usually # resulting in a "broken image" icon. # * "+set-image-blocker{blank}" will send a 1x1 transparent image # * "+set-image-blocker{pattern}" will send a 4x4 grey/white pattern -# which is less intrusive than the logo but easier to recognize -# than the transparent one. +# which is easier to recognize than the transparent one. +# * "+set-image-blocker{custom}" will send an image file as specified +# in the config file (see image-blocker-custom-file within config). # * "+set-image-blocker{}" will send a HTTP temporary redirect # to the specified image URL. # diff --git a/src/cgisimple.c b/src/cgisimple.c index c3de9462..92d0e3f8 100644 --- a/src/cgisimple.c +++ b/src/cgisimple.c @@ -1,4 +1,4 @@ -const char cgisimple_rcs[] = "$Id: cgisimple.c,v 2.1 2002/07/04 14:35:05 oes Exp $"; +const char cgisimple_rcs[] = "$Id: cgisimple.c,v 2.2 2002/12/28 03:58:19 david__schmidt Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/src/cgisimple.c,v $ @@ -36,6 +36,10 @@ const char cgisimple_rcs[] = "$Id: cgisimple.c,v 2.1 2002/07/04 14:35:05 oes Exp * * Revisions : * $Log: cgisimple.c,v $ + * Revision 2.2 2002/12/28 03:58:19 david__schmidt + * Initial drop of dashboard instrumentation - enabled with + * --enable-activity-console + * * Revision 2.1 2002/07/04 14:35:05 oes * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto * @@ -438,6 +442,7 @@ jb_err cgi_send_banner(struct client_state *csp, const struct map *parameters) { char imagetype = lookup(parameters, "type")[0]; + char *image_mimetype = BUILTIN_IMAGE_MIMETYPE; /* * If type is auto, then determine the right thing @@ -469,6 +474,10 @@ jb_err cgi_send_banner(struct client_state *csp, { imagetype = 'p'; } + else if (0 == strcmpic(p, "custom")) + { + imagetype = 'c'; + } /* * If the action is to call this CGI, determine @@ -521,6 +530,12 @@ jb_err cgi_send_banner(struct client_state *csp, rsp->body = bindup(image_blank_data, image_blank_length); rsp->content_length = image_blank_length; } + else if (imagetype == 'c') + { + rsp->body = bindup(csp->config->image_blocker_data, csp->config->image_blocker_length); + rsp->content_length = csp->config->image_blocker_length; + image_mimetype = csp->config->image_blocker_format; + } else { rsp->body = bindup(image_pattern_data, image_pattern_length); @@ -531,7 +546,11 @@ jb_err cgi_send_banner(struct client_state *csp, { return JB_ERR_MEMORY; } - if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE)) + if (enlist(rsp->headers, "Content-Type: ")) + { + return JB_ERR_MEMORY; + } + if (enlist(rsp->headers, image_mimetype)) { return JB_ERR_MEMORY; } @@ -872,11 +891,13 @@ jb_err cgi_show_status(struct client_state *csp, snprintf(buf, 100, "View ", i); if (!err) err = string_append(&s, buf); +#ifdef FEATURE_CGI_EDIT_ACTIONS if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i]) { snprintf(buf, 100, "Edit", csp->config->actions_file_short[i]); if (!err) err = string_append(&s, buf); } +#endif if (!err) err = string_append(&s, "\n"); } diff --git a/src/filters.c b/src/filters.c index 814cf206..2918ed4d 100644 --- a/src/filters.c +++ b/src/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 2.3 2002/12/28 03:58:19 david__schmidt Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 2.4 2003/01/21 02:49:27 david__schmidt Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/src/filters.c,v $ @@ -38,6 +38,13 @@ const char filters_rcs[] = "$Id: filters.c,v 2.3 2002/12/28 03:58:19 david__schm * * Revisions : * $Log: filters.c,v $ + * Revision 2.4 2003/01/21 02:49:27 david__schmidt + * Developer TODO 612294: src: C++ keyword as variable name + * I changed all ocurrences of 'new' to 'new_something' wherever I found + * one. I also brought up all the source files in MSDEV to see if I could + * spot any highlighted keywords that really were variables. Non-scientific, + * but at least I tried. :-) + * * Revision 2.3 2002/12/28 03:58:19 david__schmidt * Initial drop of dashboard instrumentation - enabled with * --enable-activity-console @@ -782,6 +789,23 @@ struct http_response *block_url(struct client_state *csp) } } + else if (0 == strcmpic(p, "custom")) + { + rsp->body = bindup(csp->config->image_blocker_data, csp->config->image_blocker_length); + if (rsp->body == NULL) + { + free_http_response(rsp); + return cgi_error_memory(); + } + rsp->content_length = csp->config->image_blocker_length; + + if (enlist_unique_header(rsp->headers, "Content-Type", csp->config->image_blocker_format)) + { + free_http_response(rsp); + return cgi_error_memory(); + } + } + else { rsp->status = strdup("302 Local Redirect from Privoxy"); diff --git a/src/loadcfg.c b/src/loadcfg.c index 9772ef6b..67ec5261 100644 --- a/src/loadcfg.c +++ b/src/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 2.3 2002/09/19 03:48:29 iwanttokeepanon Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 2.4 2002/12/28 03:58:19 david__schmidt Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/src/loadcfg.c,v $ @@ -35,6 +35,10 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 2.3 2002/09/19 03:48:29 iwanttokeep * * Revisions : * $Log: loadcfg.c,v $ + * Revision 2.4 2002/12/28 03:58:19 david__schmidt + * Initial drop of dashboard instrumentation - enabled with + * --enable-activity-console + * * Revision 2.3 2002/09/19 03:48:29 iwanttokeepanon * Just moved "int i" up 3 lines in function unload_configfile, out of the "ifdef FEATURE_ACL" clause. I disable ACL and it was not compiling because "int i" was ifdef(d) out. I noticed this in the past, but am just now in a spot where I can change/commit stuff ... long live broadband! * @@ -438,6 +442,7 @@ static struct file_list *current_configfile = NULL; #define hash_forward 2029845ul /**< "forward" */ #define hash_forward_socks4 3963965521ul /**< "forward-socks4" */ #define hash_forward_socks4a 2639958518ul /**< "forward-socks4a" */ +#define hash_image_blocker_custom_file 2863352327ul /**< "image-blocker-custom-file" */ #define hash_jarfile 2046641ul /**< "jarfile" */ #define hash_listen_address 1255650842ul /**< "listen-address" */ #define hash_logdir 422889ul /**< "logdir" */ @@ -536,6 +541,8 @@ void unload_configfile (void * data) freez(config->re_filterfile); + freez(config->image_blocker_data); + freez(config->image_blocker_format); } @@ -577,13 +584,15 @@ void unload_current_config_file(void) struct configuration_spec * load_config(void) { char buf[BUFFER_SIZE]; - char *p, *q; - FILE *configfp = NULL; + char *p, *q, *image_buf, *image_path; + FILE *configfp = NULL, + *imagefp = NULL; struct configuration_spec * config = NULL; struct client_state * fake_csp; struct file_list *fs; + struct stat statbuf[1]; unsigned long linenum = 0; - int i; + int i, file_size, bytes_read; if ( !check_file_changed(current_configfile, configfile, &fs)) { @@ -1364,6 +1373,87 @@ struct configuration_spec * load_config(void) #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */ +/* ************************************************************************* + * image-blocker-custom-file + * *************************************************************************/ + case hash_image_blocker_custom_file : + freez(config->image_blocker_data); + freez(config->image_blocker_format); + config->image_blocker_length = 0; + image_path = make_path(config->confdir, arg); + + /* + * Load up the custom image bitmap file + */ + if (NULL == (imagefp = fopen(image_path, "rb"))) + { + /* + * If we can't open the user's requested image, complain + */ + log_error(LOG_LEVEL_ERROR, "Unable to load custom blocker image: %s.", image_path); + } + else + { + if (stat(image_path, statbuf) == 0) + { + file_size = statbuf->st_size; + image_buf = zalloc(file_size); + if (image_buf != NULL) + { + bytes_read = fread(image_buf,1,file_size,imagefp); + if (bytes_read > 0) + { + config->image_blocker_data = image_buf; + config->image_blocker_length = file_size; + /* + * Ensure we can look into files for file signatures + */ + if (file_size > 10) + { + /* + * Snoop into the binary data for a filetype signature + */ + if (memcmp(image_buf,"GIF",3) == 0) + config->image_blocker_format = IMAGE_MIMETYPE_GIF; + else if (memcmp(&image_buf[6],"JFIF",4) == 0) + config->image_blocker_format = IMAGE_MIMETYPE_JPG; + else if (memcmp(&image_buf[1],"PNG",3) == 0) + config->image_blocker_format = IMAGE_MIMETYPE_PNG; + else + { + log_error(LOG_LEVEL_ERROR, "Unsupported custom image file type."); + freez(config->image_blocker_data); + } + } + else + freez(config->image_blocker_data); + } + else + { + log_error(LOG_LEVEL_ERROR, "Unable to read custom blocker image: %s", image_path, bytes_read, file_size); + freez(image_buf); + config->image_blocker_length = 0; + } + } + else + log_error(LOG_LEVEL_ERROR, "Unable to allocate memory for custom blocker image: %s.", image_path); + } + else + log_error(LOG_LEVEL_ERROR, "Unable to get statistics on custom blocker image file: %s", image_path); + } + freez(image_path); + /* + * If our load failed for some reason, just give the default + * checkerboard pattern + */ + if (config->image_blocker_data == NULL) + { + log_error(LOG_LEVEL_ERROR, "Custom blocker image processing failed; defaulting to \"pattern\"."); + config->image_blocker_data = (char*)image_pattern_data; + config->image_blocker_length = image_pattern_length; + config->image_blocker_format = BUILTIN_IMAGE_MIMETYPE; + } + continue; /* ************************************************************************* * Warnings about unsupported features diff --git a/src/project.h b/src/project.h index 43de24c3..17e51ce9 100644 --- a/src/project.h +++ b/src/project.h @@ -1,7 +1,7 @@ #ifndef PROJECT_H_INCLUDED #define PROJECT_H_INCLUDED /** Version string. */ -#define PROJECT_H_VERSION "$Id: project.h,v 2.3 2002/09/05 08:00:23 oes Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 2.4 2002/12/28 03:58:19 david__schmidt Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/src/project.h,v $ @@ -37,6 +37,10 @@ * * Revisions : * $Log: project.h,v $ + * Revision 2.4 2002/12/28 03:58:19 david__schmidt + * Initial drop of dashboard instrumentation - enabled with + * --enable-activity-console + * * Revision 2.3 2002/09/05 08:00:23 oes * Synced with the stable branch: * Revision 1.72.2.1 2002/08/10 11:25:18 oes @@ -1418,6 +1422,15 @@ struct configuration_spec /** Nonzero if we need to bind() to the new port. */ int need_bind; + + /** The raw blocker custom bitmap data */ + char *image_blocker_data; + + /** The length of the blocker custom image data */ + size_t image_blocker_length; + + /** The mimetype of the blocker custom image data */ + char *image_blocker_format; }; /** Calculates the number of elements in an array, using sizeof. */ @@ -1428,11 +1441,15 @@ struct configuration_spec #define FORCE_PREFIX "/PRIVOXY-FORCE" #endif /* def FEATURE_FORCE_LOAD */ +#define IMAGE_MIMETYPE_PNG "image/png" +#define IMAGE_MIMETYPE_GIF "image/gif" +#define IMAGE_MIMETYPE_JPG "image/jpg" + #ifdef FEATURE_NO_GIFS -/** The MIME type for images ("image/png" or "image/gif"). */ -#define BUILTIN_IMAGE_MIMETYPE "image/png" +/** The MIME type for built-in images ("image/png" or "image/gif"). */ +#define BUILTIN_IMAGE_MIMETYPE IMAGE_MIMETYPE_PNG #else -#define BUILTIN_IMAGE_MIMETYPE "image/gif" +#define BUILTIN_IMAGE_MIMETYPE IMAGE_MIMETYPE_GIF #endif /* def FEATURE_NO_GIFS */ diff --git a/templates/edit-actions-for-url b/templates/edit-actions-for-url index 9aa4d676..e0f15087 100644 --- a/templates/edit-actions-for-url +++ b/templates/edit-actions-for-url @@ -1,6 +1,6 @@ ############################################################################## # -# File : $Source: /cvsroot/ijbswa//current/templates/edit-actions-for-url,v $ +# File : $Source: /cvsroot/ijbswa/current/templates/edit-actions-for-url,v $ # # Purpose : Template used to edit the actions associated with a # particular section in an actions file. @@ -32,6 +32,14 @@ # # Revisions : # $Log: edit-actions-for-url,v $ +# Revision 1.30 2002/09/05 16:12:02 oes +# Synced with stable branch: +# Revision 1.29.2.3 2002/08/23 02:22:53 hal9 +# Fix a perl brain fart with
  • in comments. +# +# Revision 1.29.2.1 2002/08/02 12:51:42 oes +# Added top submit button; Consistency with docs: Change default name for action from hide-referer to hide-referrer +# # Revision 1.29.2.3 2002/08/23 02:22:53 hal9 # Fix a perl brain fart with
  • in comments. # @@ -797,7 +805,11 @@ function show_send_wafer_opts(tf)
    + for="set_image_blocker_mode_blank">Send a 1x1 transparent image
    +