X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=filters.c;h=1a1da409823f7a6ed0df34740e5f3da4222b71b4;hp=744af6a204abdd067c6a1e0f7bedeb1dcba871fa;hb=7537bf8433682b12ccf1099e1e30c978f4bd52a2;hpb=72081f829de368392d04076728f8c991178c0080 diff --git a/filters.c b/filters.c index 744af6a2..1a1da409 100644 --- a/filters.c +++ b/filters.c @@ -1,7 +1,7 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.58.2.9 2006/01/29 23:10:56 david__schmidt Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.63 2006/08/31 10:11:28 fabiankeil Exp $"; /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/Attic/filters.c,v $ + * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ * * Purpose : Declares functions to parse/crunch headers and pages. * Functions declared include: @@ -39,6 +39,21 @@ const char filters_rcs[] = "$Id: filters.c,v 1.58.2.9 2006/01/29 23:10:56 david_ * * Revisions : * $Log: filters.c,v $ + * Revision 1.63 2006/08/31 10:11:28 fabiankeil + * Don't free p which is still in use and will be later + * freed by free_map(). Don't claim the referrer is unknown + * when the client didn't set one. + * + * Revision 1.62 2006/08/14 00:27:47 david__schmidt + * Feature request 595948: Re-Filter logging in single line + * + * Revision 1.61 2006/08/03 02:46:41 david__schmidt + * Incorporate Fabian Keil's patch work: http://www.fabiankeil.de/sourcecode/privoxy/ + * + * Revision 1.60 2006/07/18 14:48:46 david__schmidt + * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch) + * with what was really the latest development (the v_3_0_branch branch) + * * Revision 1.58.2.9 2006/01/29 23:10:56 david__schmidt * Multiple filter file support * @@ -721,6 +736,7 @@ int match_portlist(const char *portlist, int port) struct http_response *block_url(struct client_state *csp) { struct http_response *rsp; + const char *new_content_type = NULL; /* * If it's not blocked, don't block it ;-) @@ -729,7 +745,10 @@ struct http_response *block_url(struct client_state *csp) { return NULL; } - + if (csp->action->flags & ACTION_REDIRECT) + { + log_error(LOG_LEVEL_ERROR, "redirect{} overruled by block."); + } /* * Else, prepare a response */ @@ -750,11 +769,21 @@ struct http_response *block_url(struct client_state *csp) /* determine HOW images should be blocked */ p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER]; + if(csp->action->flags & ACTION_HANDLE_AS_EMPTY_DOCUMENT) + { + log_error(LOG_LEVEL_ERROR, "handle-as-empty-document overruled by handle-as-image."); + } #if 1 /* Two alternative strategies, use this one for now: */ /* and handle accordingly: */ if ((p == NULL) || (0 == strcmpic(p, "pattern"))) { + rsp->status = strdup("403 Request blocked by Privoxy"); + if (rsp->status == NULL) + { + free_http_response(rsp); + return cgi_error_memory(); + } rsp->body = bindup(image_pattern_data, image_pattern_length); if (rsp->body == NULL) { @@ -772,6 +801,12 @@ struct http_response *block_url(struct client_state *csp) else if (0 == strcmpic(p, "blank")) { + rsp->status = strdup("403 Request blocked by Privoxy"); + if (rsp->status == NULL) + { + free_http_response(rsp); + return cgi_error_memory(); + } rsp->body = bindup(image_blank_data, image_blank_length); if (rsp->body == NULL) { @@ -827,6 +862,34 @@ struct http_response *block_url(struct client_state *csp) return cgi_error_memory(); } #endif /* Preceeding code is disabled for now */ + } + else if(csp->action->flags & ACTION_HANDLE_AS_EMPTY_DOCUMENT) + { + /* + * Send empty document. + */ + new_content_type = csp->action->string[ACTION_STRING_CONTENT_TYPE]; + + freez(rsp->body); + rsp->body = strdup(" "); + rsp->content_length = 1; + + rsp->status = strdup("403 Request blocked by Privoxy"); + if (rsp->status == NULL) + { + free_http_response(rsp); + return cgi_error_memory(); + } + if (new_content_type != 0) + { + log_error(LOG_LEVEL_HEADER, "Overwriting Content-Type with %s", new_content_type); + if (enlist_unique_header(rsp->headers, "Content-Type", new_content_type)) + { + free_http_response(rsp); + return cgi_error_memory(); + } + } + } else #endif /* def FEATURE_IMAGE_BLOCKING */ @@ -910,7 +973,7 @@ struct http_response *block_url(struct client_state *csp) * Function : trust_url FIXME: I should be called distrust_url * * Description : Calls is_untrusted_url to determine if the URL is trusted - * and if not, returns a HTTP 304 response with a reject message. + * and if not, returns a HTTP 403 response with a reject message. * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) @@ -944,8 +1007,9 @@ struct http_response *trust_url(struct client_state *csp) return cgi_error_memory(); } + rsp->status = strdup("403 Request blocked by Privoxy"); exports = default_exports(csp, NULL); - if (exports == NULL) + if (exports == NULL || rsp->status == NULL) { free_http_response(rsp); return cgi_error_memory(); @@ -964,7 +1028,7 @@ struct http_response *trust_url(struct client_state *csp) } else { - if (!err) err = map(exports, "referrer", 1, "unknown", 1); + if (!err) err = map(exports, "referrer", 1, "none set", 1); } if (err) @@ -984,7 +1048,6 @@ struct http_response *trust_url(struct client_state *csp) string_append(&p, buf); } err = map(exports, "trusted-referrers", 1, p, 0); - freez(p); if (err) { @@ -1007,7 +1070,6 @@ struct http_response *trust_url(struct client_state *csp) string_append(&p, buf); } err = map(exports, "trust-info", 1, p, 0); - freez(p); } else { @@ -1070,18 +1132,55 @@ struct http_response *redirect_url(struct client_state *csp) { char *p, *q; struct http_response *rsp; + char *redirect_mode = NULL; + int x, y; - p = q = csp->http->path; - log_error(LOG_LEVEL_REDIRECTS, "checking path for redirects: %s", p); - - /* - * find the last URL encoded in the request - */ - while ((p = strstr(p, "http://")) != NULL) + if ((csp->action->flags & ACTION_REDIRECT)) { - q = p++; + q = csp->action->string[ACTION_STRING_REDIRECT]; } + else + { + redirect_mode = csp->action->string[ACTION_STRING_FAST_REDIRECTS]; + if (0 == strcmpic(redirect_mode, "check-decoded-url")) + { + p = q = csp->http->path; + log_error(LOG_LEVEL_REDIRECTS, "Decoding path: %s if necessary.", p); + while (*p) + { + if (*p == '%') /* Escape sequence? */ + { + /* Yes, translate from hexadecimal to decimal */ + p++; + /* First byte */ + x=((int)*p++)-48; + if (x>9) x-=7; + x<<=4; + /* Second byte */ + y=((int)*p++)-48; + if (y>9)y-=7; + /* Merge */ + *q++=(char)(x|y); + } + else + { + /* No, forward character. */ + *q++=*p++; + } + } + *q='\0'; + } + p = q = csp->http->path; + log_error(LOG_LEVEL_REDIRECTS, "Checking path for redirects: %s", p); + /* + * find the last URL encoded in the request + */ + while ((p = strstr(p, "http://")) != NULL) + { + q = p++; + } + } /* * if there was any, generate and return a HTTP redirect */ @@ -1301,7 +1400,7 @@ int is_untrusted_url(struct client_state *csp) char *pcrs_filter_response(struct client_state *csp) { int hits=0; - size_t size; + size_t size, prev_size; char *old = csp->iob->cur, *new = NULL; pcrs_job *job; @@ -1383,9 +1482,7 @@ char *pcrs_filter_response(struct client_state *csp) continue; } - log_error(LOG_LEVEL_RE_FILTER, "re_filtering %s%s (size %d) with filter %s...", - csp->http->hostport, csp->http->path, size, b->name); - + prev_size = size; /* Apply all jobs from the joblist */ for (job = b->joblist; NULL != job; job = job->next) { @@ -1394,7 +1491,9 @@ char *pcrs_filter_response(struct client_state *csp) old=new; } - log_error(LOG_LEVEL_RE_FILTER, " ...produced %d hits (new size %d).", current_hits, size); + log_error(LOG_LEVEL_RE_FILTER, "re_filtering %s%s (size %d) with filter %s produced %d hits (new size %d).", + csp->http->hostport, csp->http->path, prev_size, b->name, current_hits, size); + hits += current_hits; } }