--------------------- PatchSet 1479 Date: 2001/02/02 13:22:26 Author: rbcollins Branch: rbcollins_filters Tag: (none) Log: Moez's htmldemo filter Members: src/modules/htmldemo/Makefile.in:1.1->1.1.2.1 src/modules/htmldemo/htmldemo.c:1.1->1.1.2.1 --- /dev/null Wed Feb 14 00:48:56 2007 +++ squid/src/modules/htmldemo/Makefile.in Wed Feb 14 00:49:35 2007 @@ -0,0 +1,70 @@ +# +# Makefile for the ntlm authentication scheme module for the Squid Object Cache server +# +# $Id: Makefile.in,v 1.1.2.1 2001/02/02 13:22:26 rbcollins Exp $ +# + +MODULE = htmldemo + +#SUBDIRS = helpers + +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ + +CC = @CC@ +MAKEDEPEND = @MAKEDEPEND@ +AR_R = @AR_R@ +RANLIB = @RANLIB@ +AC_CFLAGS = @CFLAGS@ +SHELL = /bin/sh + +INCLUDE = -I../../../include -I$(top_srcdir)/include -I$(top_srcdir)/src/ +CFLAGS = $(AC_CFLAGS) $(INCLUDE) $(DEFINES) + +OUT = ../$(MODULE).a + +OBJS = \ + htmldemo.o + + +all install: $(OUT) + @for dir in $(SUBDIRS); do \ + if [ -f $$dir/Makefile ]; then \ + sh -c "cd $$dir && $(MAKE) $@" || exit 1; \ + fi; \ + done; + +$(OUT): $(OBJS) + @rm -f ../stamp + $(AR_R) $(OUT) $(OBJS) + $(RANLIB) $(OUT) + +$(OBJS): $(top_srcdir)/include/version.h ../../../include/autoconf.h + +.c.o: + @rm -f ../stamp + $(CC) $(CFLAGS) -c $< + +clean: + -rm -rf *.o *pure_* core ../$(MODULE).a + -for dir in *; do \ + if [ -f $$dir/Makefile ]; then \ + sh -c "cd $$dir && $(MAKE) clean"; \ + fi; \ + done + +distclean: clean + -rm -f Makefile + -rm -f Makefile.bak + -rm -f tags + -for dir in *; do \ + if [ -f $$dir/Makefile ]; then \ + sh -c "cd $$dir && $(MAKE) distclean"; \ + fi; \ + done + +tags: + ctags *.[ch] $(top_srcdir)/src/*.[ch] $(top_srcdir)/include/*.h $(top_srcdir)/lib/*.[ch] + +depend: + $(MAKEDEPEND) $(INCLUDE) -fMakefile *.c --- /dev/null Wed Feb 14 00:48:56 2007 +++ squid/src/modules/htmldemo/htmldemo.c Wed Feb 14 00:49:35 2007 @@ -0,0 +1,227 @@ + +/* + * + * DEBUG: section 83 Content Processing Filters + * AUTHOR: Moez Mahfoudh + * + * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from the + * Internet community. Development is led by Duane Wessels of the + * National Laboratory for Applied Network Research and funded by the + * National Science Foundation. Squid is Copyrighted (C) 1998 by + * the Regents of the University of California. Please see the + * COPYRIGHT file for full details. Squid incorporates software + * developed and/or copyrighted by other sources. Please see the + * CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#include "squid.h" + +/* This filter has one config option : + type 0 : the filter interlaces spaces in the HTML to make its size grow + type 1 : the filter removes HTML tags Isize decreases + */ + +/* The tester filter */ +typedef struct _tester_cfg TesterConfig; +typedef struct _tester_state TesterState; +struct _tester_state { + TesterConfig *config; + char *buf; + int buf_len,buf_max_len; + int in_tag; +}; +struct _tester_cfg { + int type; +}; + + +static REMOVEFILTER clientFilterTester_Remove; +static ADDFILTER clientFilterTester_Add; +static FILTERMKSTATE clientFilterTester_MakeState; +static FILTERPARSE clientFilterTester_Parse; +static DATAFILTER clientFilterTester; + + +MOD_INSTALL mod_install_url_rewrite; + + +static void +clientFilterFreeConfig(void *data) { + TesterConfig *config=data; + + xfree(config); +} + +static void +clientFilterTester_AddInstance(FILTER_instance *instance) { + TesterConfig *config; + instance->Add=clientFilterTester_Add; + instance->MakeState=clientFilterTester_MakeState; + instance->Parse =clientFilterTester_Parse; + instance->data=xmalloc(sizeof(TesterConfig)); + /* Set defaults, if sensible defaults exist */ + config=instance->data; +} + +static void +clientFilterTester_RemInstance(FILTER_instance *instance) { + instance->Add=NULL; + instance->MakeState=NULL; + clientFilterFreeConfig(instance->data); + instance->data=NULL; +} + +static void +clientFilterTester_Add(dlink_list *filters, void *filter_config) { + FILTER_list *temp_filter; + temp_filter=xmalloc(sizeof(FILTER_list)); + temp_filter->filter=clientFilterTester; + temp_filter->Remove=clientFilterTester_Remove; + temp_filter->data=filter_config; + /* cbDataLock(http); ? */ + dlinkAddTail(temp_filter, &temp_filter->node, filters); +} + +static void * +clientFilterTester_MakeState(void * data) { + TesterState *state; + TesterConfig *config=data; + if (!config) + return NULL; + /* it's up to the filter writer wether to refcount the config, + * or copy it. For now, to save learning cbdata, I copy it + */ + state=xmalloc(sizeof(TesterState)); + state->config=xmalloc(sizeof(TesterConfig)); + state->config->type=config->type; + state->buf=NULL; + state->buf_len=state->buf_max_len=0; + return state; +} + +static void +clientFilterTester_Remove(FILTER_list *filters, dlink_list *filter_list, void *data) { + TesterState *state=data; + dlinkDelete(&filters->node, filter_list); + xfree(filters); + clientFilterFreeConfig(state->config); + state->config=NULL; + xfree(state); +} + +static void +clientFilterTester_Parse(void *data, const char *namestr, char *param_str) { + TesterConfig *config=data; + char *z; + + if (strcasecmp(param_str, "type") == 0) { + parse_eol(&z); + config->type=atoi(z); + } /*else if (strcasecmp(param_str, "search") == 0) { + parse_eol(&config->searchstring); + } */else { + debug(33, 0) ("unrecognised parameter '%s' for filter %s\n", param_str,namestr); + } +} + +void TesterWrite(TesterState *s,char *c,int l) +{ + if (s->buf_max_len<=s->buf_max_len+l) + { + s->buf_max_len=((s->buf_len+l)/256+1)*256; + s->buf=(char *)xrealloc(s->buf,s->buf_max_len); + }; + memcpy(s->buf+s->buf_len,c,l); + s->buf_len+=l; +} + +/* register as a module */ +void +mod_install_tester (const char *namestr) +{ + /* Register as a potential client_side reply filter */ + filterRegisterModule (namestr, clientFilterTester_AddInstance, + clientFilterTester_RemInstance); + debug(1,1)("******* registering=[%p]\n",namestr); +} + +/* deregister as a module */ +void +mod_uninstall_tester(const char *namestr) { + filterDeregisterModule(namestr); + debug(1,1)("******* unregistering=[%p]\n",namestr); +} + +static void +clientFilterTester(const char *buf, size_t len, dlink_list *filter_list, + FILTER_list *filters, unsigned int flags, void *data) { + FILTER_list *temp_filter; + TesterState *state=data; + TesterConfig *config=state->config; + + temp_filter=filters->node.next->data; + debug(1,1)("******* clientFilterTester (%p,%d,%d)\n",buf,len,flags); + + if (flags & FILTER_HTTP_HEADER) + { + temp_filter->filter(buf,len,filter_list, temp_filter, flags, + temp_filter->data); + debug(1,1)("[%s]\n",buf); + return; + }; + + /* On each chunk do Parse then call filters with output_buffer as buf */ + if (buf) + { + int i; + + state->buf_len=0; + for (i=0;iin_tag=1; + + if (config->type==0) + { + TesterWrite(state,buf+i,1); + if (!state->in_tag) + TesterWrite(state," ",1); + } + else + { + if (!state->in_tag) + TesterWrite(state,buf+i,1); + }; + + if (buf[i]=='>') + state->in_tag=0; + }; + + temp_filter->filter(state->buf,state->buf_len,filter_list, + temp_filter, flags, temp_filter->data); + /*TesterWrite(state,"",1); + debug(1,1)("[%s]\n",state->buf);*/ + }; + if (flags & FILTER_EOF) + { + xfree(state->buf); + }; +}