From: oes Date: Sun, 27 May 2001 22:17:04 +0000 (+0000) Subject: - re_process_buffer no longer writes the modified buffer X-Git-Tag: v_2_9_9~471 X-Git-Url: http://www.privoxy.org/gitweb/@default-cgi@/faq/%22https:/static/gitweb.js?a=commitdiff_plain;h=ffc1ab733579543abf77003e7d4b1a373d81c7a3;p=privoxy.git - re_process_buffer no longer writes the modified buffer to the client, which was very ugly. It now returns the buffer, which it is then written by chat. - content_length now adjusts the Content-Length: header for modified documents rather than crunch()ing it. (Length info in csp->content_length, which is 0 for unmodified documents) - For this to work, sed() is called twice when filtering. --- diff --git a/filters.c b/filters.c index f08acb89..44a884f5 100644 --- a/filters.c +++ b/filters.c @@ -1,4 +1,4 @@ -const char filters_rcs[] = "$Id: filters.c,v 1.7 2001/05/26 15:26:15 jongfoster Exp $"; +const char filters_rcs[] = "$Id: filters.c,v 1.8 2001/05/26 17:13:28 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.c,v $ @@ -38,6 +38,9 @@ const char filters_rcs[] = "$Id: filters.c,v 1.7 2001/05/26 15:26:15 jongfoster * * Revisions : * $Log: filters.c,v $ + * Revision 1.8 2001/05/26 17:13:28 jongfoster + * Filled in a function comment. + * * Revision 1.7 2001/05/26 15:26:15 jongfoster * ACL feature now provides more security by immediately dropping * connections from untrusted hosts. @@ -550,18 +553,17 @@ int block_imageurl_using_imagelist(struct http_request *http, struct client_stat * Function : re_process_buffer * * Description : Apply all jobs from the joblist (aka. Perl regexp's) to - * the text buffer that's been accumulated in csp->iob->buf. - * Then, write the modified buffer out to the client - * (Maybe this should happen from jcc.c via flush_socket - * for better readability). + * the text buffer that's been accumulated in csp->iob->buf + * and set csp->content_length to the modified size. * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) * - * Returns : N/A + * Returns : a pointer to the (newly allocated) modified buffer. + * * *********************************************************************/ -void re_process_buffer(struct client_state *csp) +char *re_process_buffer(struct client_state *csp) { int hits=0; int size = csp->iob->eod - csp->iob->cur; @@ -599,15 +601,11 @@ void re_process_buffer(struct client_state *csp) log_error(LOG_LEVEL_RE_FILTER, " produced %d hits (new size %d).", hits, size); - if (write_socket(csp->cfd, old, size) != size) - { - log_error(LOG_LEVEL_ERROR, "write to client failed."); - } + csp->content_length = size; /* fwiw, reset the iob */ IOB_RESET(csp); - freez(new); - return; + return(new); } #endif /* def PCRS */ diff --git a/filters.h b/filters.h index 0e563c33..eccc0c10 100644 --- a/filters.h +++ b/filters.h @@ -1,6 +1,6 @@ #ifndef _FILTERS_H #define _FILTERS_H -#define FILTERS_H_VERSION "$Id: filters.h,v 1.3 2001/05/22 18:46:04 oes Exp $" +#define FILTERS_H_VERSION "$Id: filters.h,v 1.4 2001/05/26 15:26:15 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/filters.h,v $ @@ -40,6 +40,10 @@ * * Revisions : * $Log: filters.h,v $ + * Revision 1.4 2001/05/26 15:26:15 jongfoster + * ACL feature now provides more security by immediately dropping + * connections from untrusted hosts. + * * Revision 1.3 2001/05/22 18:46:04 oes * * - Enabled filtering banners by size rather than URL @@ -148,7 +152,7 @@ extern char *add_stats(char *s); #endif /* def STATISTICS */ #ifdef PCRS -extern void re_process_buffer(struct client_state *csp); +extern char *re_process_buffer(struct client_state *csp); #endif /* def PCRS */ /* Revision control strings from this header and associated .c file */ diff --git a/jcc.c b/jcc.c index 75e48a29..cb302751 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.10 2001/05/26 15:26:15 jongfoster Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.11 2001/05/26 17:27:53 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,10 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.10 2001/05/26 15:26:15 jongfoster Exp $"; * * Revisions : * $Log: jcc.c,v $ + * Revision 1.11 2001/05/26 17:27:53 jongfoster + * Added support for CLF and fixed LOG_LEVEL_LOG. + * Also did CRLF->LF fix of my previous patch. + * * Revision 1.10 2001/05/26 15:26:15 jongfoster * ACL feature now provides more security by immediately dropping * connections from untrusted hosts. @@ -708,7 +712,17 @@ static void chat(struct client_state *csp) #ifdef PCRS if (filtering) { - re_process_buffer(csp); + p = re_process_buffer(csp); + hdr = sed(server_patterns, add_server_headers, csp); + n = strlen(hdr); + if ((write_socket(csp->cfd, hdr, n) != n) + || (write_socket(csp->cfd, p, csp->content_length) != csp->content_length)) + { + log_error(LOG_LEVEL_CONNECT, "write modified content to client failed: %E"); + return; + } + freez(hdr); + freez(p); } #endif /* def PCRS */ break; /* "game over, man" */ @@ -819,7 +833,7 @@ static void chat(struct client_state *csp) if (csp->is_text && /* It's a text / * MIME-Type */ !http->ssl && /* We talk plaintext */ - block_popups) + block_popups) /* Policy allows */ { block_popups_now = 1; } @@ -846,8 +860,8 @@ static void chat(struct client_state *csp) #endif /* def PCRS */ - if ((write_socket(csp->cfd, hdr, n) != n) - || (NOT_FILTERING_AND (n = flush_socket(csp->cfd, csp) < 0))) + if (NOT_FILTERING_AND ((write_socket(csp->cfd, hdr, n) != n) + || (n = flush_socket(csp->cfd, csp) < 0))) { log_error(LOG_LEVEL_CONNECT, "write header to client failed: %E"); @@ -1090,7 +1104,7 @@ static void listen_loop(void) #endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) */ sweep(); - if ( NULL == (csp = (struct client_state *) malloc(sizeof(*csp))) ) + if ( NULL == (csp = (struct client_state *) zalloc(sizeof(*csp))) ) { log_error(LOG_LEVEL_FATAL, "malloc(%d) for csp failed: %E", sizeof(*csp)); continue; diff --git a/parsers.c b/parsers.c index 18c0a9c2..cd03beba 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.6 2001/05/26 13:39:32 jongfoster Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.7 2001/05/27 13:19:06 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -41,6 +41,9 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.6 2001/05/26 13:39:32 jongfoster * * Revisions : * $Log: parsers.c,v $ + * Revision 1.7 2001/05/27 13:19:06 oes + * Patched Joergs solution for the content-length in. + * * Revision 1.6 2001/05/26 13:39:32 jongfoster * Only crunches Content-Length header if applying RE filtering. * Without this fix, Microsoft Windows Update wouldn't work. @@ -522,14 +525,12 @@ char *sed(const struct parsers pats[], void (* const more_headers[])(struct clie { for (p = csp->headers->next; p ; p = p->next) { + /* Header crunch()ed in previous run? -> ignore */ + if (p->str == NULL) continue; + if (v == pats) log_error(LOG_LEVEL_HEADER, "scan: %s", p->str); - if (p->str == NULL) - { - /* hit me */ - log_error(LOG_LEVEL_ERROR, "NULL header"); - } - else if (strncmpic(p->str, v->str, v->len) == 0) + if (strncmpic(p->str, v->str, v->len) == 0) { hdr = v->parser(v, p->str, csp); freez(p->str); @@ -544,8 +545,11 @@ char *sed(const struct parsers pats[], void (* const more_headers[])(struct clie (*f)(csp); } - /* add the blank line at the end of the header */ - enlist(csp->headers, ""); + /* add the blank line at the end of the header, if necessary */ + if(strlen(csp->headers->last->str) != 0) + { + enlist(csp->headers, ""); + } hdr = list_to_text(csp->headers); @@ -798,11 +802,13 @@ char *content_type(const struct parsers *v, char *s, struct client_state *csp) *********************************************************************/ char *content_length(const struct parsers *v, char *s, struct client_state *csp) { - if (((csp->permissions & PERMIT_RE_FILTER) != 0) && csp->is_text) - { - log_error(LOG_LEVEL_HEADER, "crunch!"); - return(NULL); - } + if (csp->content_length != 0) /* Content has been modified */ + { + s = (char *) zalloc(100); + snprintf(s, 100, "Content-Length: %d", csp->content_length); + log_error(LOG_LEVEL_HEADER, "Adjust Content-Length to %d", csp->content_length); + return(s); + } else { return(strdup(s)); diff --git a/project.h b/project.h index df218bdf..f9c2ad87 100644 --- a/project.h +++ b/project.h @@ -1,6 +1,6 @@ #ifndef _PROJECT_H #define _PROJECT_H -#define PROJECT_H_VERSION "$Id: project.h,v 1.4 2001/05/22 18:46:04 oes Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.5 2001/05/26 00:28:36 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -36,6 +36,13 @@ * * Revisions : * $Log: project.h,v $ + * Revision 1.5 2001/05/26 00:28:36 jongfoster + * Automatic reloading of config file. + * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32). + * Most of the global variables have been moved to a new + * struct configuration_spec, accessed through csp->config->globalname + * Most of the globals remaining are used by the Win32 GUI. + * * Revision 1.4 2001/05/22 18:46:04 oes * * - Enabled filtering banners by size rather than URL @@ -266,13 +273,8 @@ struct client_state #endif /* def FORCE_LOAD */ #ifdef TOGGLE - /* - * by haroon - most of credit to srt19170 - * We add an "on/off" toggle here that is used to effectively toggle - * the Junkbuster off or on - */ int toggled_on; -#endif +#endif /* def TOGGLE */ char *ip_addr_str; long ip_addr_long; @@ -316,6 +318,7 @@ struct client_state #ifdef PCRS struct file_list *rlist; /* Perl re_filterfile */ + size_t content_length; /* Length after processing */ #endif /* def PCRS */ #ifdef TRUST_FILES