--------------------- PatchSet 1458 Date: 2001/01/31 12:41:51 Author: rbcollins Branch: rbcollins_filters Tag: (none) Log: mod_register configure option: used to tell squid about a module. syntax is in squid.conf.default Members: src/acl.c:1.1.1.3.8.8.4.2->1.1.1.3.8.8.4.3 src/cache_cf.c:1.1.1.3.4.1.4.7.4.5->1.1.1.3.4.1.4.7.4.6 src/cf.data.pre:1.1.1.3.4.1.4.11.4.3->1.1.1.3.4.1.4.11.4.4 src/conf_modules.sh:1.1.2.1->1.1.2.2 src/enums.h:1.1.1.3.8.8.4.1->1.1.1.3.8.8.4.2 src/filters.c:1.1.2.2->1.1.2.3 src/main.c:1.1.1.3.4.1.4.10.4.1->1.1.1.3.4.1.4.10.4.2 src/modules.c:1.1.2.1->1.1.2.2 src/protos.h:1.1.1.3.8.11.2.5->1.1.1.3.8.11.2.6 src/structs.h:1.1.1.3.4.1.4.12.2.9->1.1.1.3.4.1.4.12.2.10 src/typedefs.h:1.1.1.3.8.7.4.8->1.1.1.3.8.7.4.9 src/modules/textreplace/textreplace.c:1.1.2.4->1.1.2.5 Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.1.1.3.8.8.4.2 retrieving revision 1.1.1.3.8.8.4.3 diff -u -r1.1.1.3.8.8.4.2 -r1.1.1.3.8.8.4.3 --- squid/src/acl.c 30 Jan 2001 11:00:01 -0000 1.1.1.3.8.8.4.2 +++ squid/src/acl.c 31 Jan 2001 12:41:51 -0000 1.1.1.3.8.8.4.3 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.1.1.3.8.8.4.2 2001/01/30 11:00:01 rbcollins Exp $ + * $Id: acl.c,v 1.1.1.3.8.8.4.3 2001/01/31 12:41:51 rbcollins Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -2047,6 +2047,8 @@ case ACL_BROWSER: case ACL_SRC_DOM_REGEX: case ACL_DST_DOM_REGEX: + case ACL_REP_MIME_TYPE: + case ACL_REQ_MIME_TYPE: aclDestroyRegexList(a->data); break; case ACL_PROTO: Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cache_cf.c,v retrieving revision 1.1.1.3.4.1.4.7.4.5 retrieving revision 1.1.1.3.4.1.4.7.4.6 diff -u -r1.1.1.3.4.1.4.7.4.5 -r1.1.1.3.4.1.4.7.4.6 --- squid/src/cache_cf.c 30 Jan 2001 09:32:52 -0000 1.1.1.3.4.1.4.7.4.5 +++ squid/src/cache_cf.c 31 Jan 2001 12:41:51 -0000 1.1.1.3.4.1.4.7.4.6 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.1.1.3.4.1.4.7.4.5 2001/01/30 09:32:52 rbcollins Exp $ + * $Id: cache_cf.c,v 1.1.1.3.4.1.4.7.4.6 2001/01/31 12:41:51 rbcollins Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -990,6 +990,102 @@ } } + +CBDATA_TYPE(modNode); +/* Operation of modNode cbdata: + config allocates the record, and free frees it. + any configuration that depends on the record + locks it and + any matching free configuration + unlocks it +*/ + +const char * +mod_type_str(const mod_t type) +{ + switch (type) { + case MOD_INTERNAL: + return "internal"; + break; + case MOD_EXTERNAL: + return "external"; + break; + default: + return "unknown"; + break; + } +} + + +/* TODO: write a cbdataFree handler for modNode's. */ +static void +parse_mod_install(modConfig * cfg) { + char *type_str=NULL, *name_str=NULL; + mod_t type=MOD_NONE; + modNode *node= NULL; + int rv; + + if ((type_str = strtok(NULL, w_space)) == NULL) + self_destruct(); + + if ((name_str = strtok(NULL, w_space)) == NULL) + self_destruct(); + + + + if (strcasecmp(type_str,"internal")==0) { + /* internal module */ + type=MOD_INTERNAL; + } else if (strcasecmp(type_str,"external")==0) { + /* external module */ + debug(3,0)("external modules not supported yet\n"); + } + if (type==MOD_NONE) + self_destruct(); + + CBDATA_INIT_TYPE(modNode); + node=CBDATA_ALLOC(modNode, NULL); + assert(node); + node->type=type; + node->namestr=xstrdup(name_str); + if (type==MOD_INTERNAL) + rv = mod_internal_install(node->namestr, node); +#if 0 + else if (type==MOD_EXTERNAL) + rv = mod_external_install(node->namestr, node); +#endif + if (rv) + dlinkAddTail(node,&node->node,&cfg->modules); + else { + safe_free(node->namestr); + cbdataFree(node); + } + +} + +static void +free_mod_install(modConfig * cfg) { + dlink_node *node,*tmpnode; + modNode *module; + node=cfg->modules.head; + while (node) { + tmpnode=node; + module=node->data; + node=node->next; + dlinkDelete(tmpnode,&cfg->modules); + module->uninstall(module->namestr); + cbdataFree(module); + } + cfg->modules.head=NULL; + cfg->modules.tail=NULL; +} + +static void +dump_mod_install(StoreEntry * entry, const char *name, modConfig cfg){ +} + + + /* allocate new filteraccess record. Caveats with changing address apply as per * new_filterinstance */ void @@ -1119,6 +1215,7 @@ cfg->n_configured++; instance->namestr=xstrdup(instance_str); instance->module=module; + cbdataLock(module); module->AddInstance(instance); } } @@ -1131,6 +1228,7 @@ for (i = 0; i < cfg->n_configured; i++) { instance = cfg->instances + i; instance->module->RemInstance(instance); + cbdataUnlock(instance->module); safe_free(instance->namestr); } safe_free(cfg->instances); Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf.data.pre,v retrieving revision 1.1.1.3.4.1.4.11.4.3 retrieving revision 1.1.1.3.4.1.4.11.4.4 diff -u -r1.1.1.3.4.1.4.11.4.3 -r1.1.1.3.4.1.4.11.4.4 --- squid/src/cf.data.pre 30 Jan 2001 04:28:30 -0000 1.1.1.3.4.1.4.11.4.3 +++ squid/src/cf.data.pre 31 Jan 2001 12:41:51 -0000 1.1.1.3.4.1.4.11.4.4 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.1.1.3.4.1.4.11.4.3 2001/01/30 04:28:30 rbcollins Exp $ +# $Id: cf.data.pre,v 1.1.1.3.4.1.4.11.4.4 2001/01/31 12:41:51 rbcollins Exp $ # # # SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -49,6 +49,25 @@ COMMENT_END COMMENT_START + MODULE OPTIONS + ----------------------------------------------------------------------------- + Squid's module architecture allows dynamic addition and removal + of code from the code base. Modules _must_ be registered before they + are used or referenced (even from other config lines). +COMMENT_END + +NAME: mod_register +TYPE: mod_install +DEFAULT: none +LOC: Config.modules +DOC_START + usage: mod_register internal|external modulename + + External modules are not implemented yet. +DOC_END + + +COMMENT_START NETWORK OPTIONS ----------------------------------------------------------------------------- COMMENT_END Index: squid/src/conf_modules.sh =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/conf_modules.sh,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/conf_modules.sh 30 Jan 2001 00:53:04 -0000 1.1.2.1 +++ squid/src/conf_modules.sh 31 Jan 2001 12:41:52 -0000 1.1.2.2 @@ -6,10 +6,16 @@ echo "" for module in "$@"; do echo "extern MOD_INSTALL mod_install_${module};" + echo "extern MOD_UNINSTALL mod_uninstall_${module};" done -echo "void mod_compiled_install(void)" +echo "int mod_internal_install(const char *namestr, modNode *module)" echo "{" for module in "$@"; do - echo " mod_register(\"$module\", mod_install_${module});" + echo " if (strcasecmp(namestr,\"$module\")==0) {" + echo " mod_register(\"$module\", mod_install_${module}, mod_uninstall_${module}, module);" + echo " return -1;" + echo " } else" done +echo " debug(3,0)(\"mod_internal_install: unrecognised module '%s'.\n\",namestr);" +echo " return 0;" echo "}" Index: squid/src/enums.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/enums.h,v retrieving revision 1.1.1.3.8.8.4.1 retrieving revision 1.1.1.3.8.8.4.2 diff -u -r1.1.1.3.8.8.4.1 -r1.1.1.3.8.8.4.2 --- squid/src/enums.h 28 Jan 2001 13:24:14 -0000 1.1.1.3.8.8.4.1 +++ squid/src/enums.h 31 Jan 2001 12:41:52 -0000 1.1.1.3.8.8.4.2 @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.1.1.3.8.8.4.1 2001/01/28 13:24:14 rbcollins Exp $ + * $Id: enums.h,v 1.1.1.3.8.8.4.2 2001/01/31 12:41:52 rbcollins Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -149,6 +149,12 @@ }; typedef enum { + MOD_NONE, + MOD_INTERNAL, + MOD_EXTERNAL +} mod_t; + +typedef enum { PEER_NONE, PEER_SIBLING, PEER_PARENT, Index: squid/src/filters.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/filters.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/filters.c 30 Jan 2001 08:57:18 -0000 1.1.2.2 +++ squid/src/filters.c 31 Jan 2001 12:41:52 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: filters.c,v 1.1.2.2 2001/01/30 08:57:18 rbcollins Exp $ + * $Id: filters.c,v 1.1.2.3 2001/01/31 12:41:52 rbcollins Exp $ * * DEBUG: section 83 Content Processing Filters * AUTHOR: Robert Collins @@ -36,30 +36,73 @@ #include "squid.h" /* globals */ +CBDATA_TYPE(FILTER_module); + static FILTER_module *filter_list= NULL; +void filterModuleUnlink(void *); +/* TODO: make these linked lists so we can remove cleanly */ /* filter framework */ void filterRegisterModule(const char *namestr, ADDFILTERINSTANCE *add, REMFILTERINSTANCE *remove) { - int i; - debug(33,4)("filterRegisterModule: Registering filter '%s'\n",namestr); + FILTER_module *new; + CBDATA_INIT_TYPE(FILTER_module); + debug(83,4)("filterRegisterModule: Registering filter '%s'\n",namestr); /* find the current count */ - for (i = 0; filter_list && filter_list[i].namestr; i++) { + new=filter_list; + while (new) { /* don't allow double additions. FIXME: this should be a debug and - * abort action, to allow for dynamic registration */ - assert(strcmp(filter_list[i].namestr, namestr) != 0); + * abort action, to allow for dynamic registration mistakes */ + assert(strcmp(new->namestr, namestr) != 0); + new=new->next; + } + /* add the filter (to the head) */ + new=CBDATA_ALLOC(FILTER_module, filterModuleUnlink); + memset(new, 0, sizeof(FILTER_module)); + new->next=filter_list; + filter_list=new; + new->namestr=xstrdup(namestr); + new->AddInstance=add; + new->RemInstance=remove; +} + +/* deregister a module */ +/* remove all config details. XXX: we cannot unload the code from memory without + * turning this into a callback scenario because filters may be in use for arbitrary + * periods of time - until the current requests finish + */ +void filterDeregisterModule(const char *namestr) { + FILTER_module *filter,*temp; + debug(83,4)("filterDeregisterModule: Deregistering filter '%s'\n",namestr); + filter=filter_list; + temp=filter_list; + while (filter) { + temp=filter; + filter=filter->next; + if (strcmp(temp->namestr, namestr) == 0) { + cbdataFree(temp); + filter=NULL; + } + } +} + +void +filterModuleUnlink(void *data) { + FILTER_module *filter, *self=data; + filter=filter_list; + assert(data); + debug(83,4)("filterModuleUnlink: unlinking '%s'\n",self->namestr); + /* special case: removing head */ + if (filter==self) { + filter_list=self->next; + return; } - /* add the filter */ - /* FIXME: xrealloc may be ad - if the array moves arround after initalisation - ie - * with dynamic module additions, then pointers to the modules will get corrupted - */ - filter_list = xrealloc(filter_list, (i+2) * sizeof(FILTER_module)); - memset(&filter_list[i+1], 0, sizeof(FILTER_module)); - filter_list[i].namestr=xstrdup(namestr); - filter_list[i].AddInstance=add; - filter_list[i].RemInstance=remove; + while (filter && (filter->next != self)) + filter=filter->next; + if (filter->next) + filter->next=self->next; } FILTER_module * Index: squid/src/main.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/main.c,v retrieving revision 1.1.1.3.4.1.4.10.4.1 retrieving revision 1.1.1.3.4.1.4.10.4.2 diff -u -r1.1.1.3.4.1.4.10.4.1 -r1.1.1.3.4.1.4.10.4.2 --- squid/src/main.c 30 Jan 2001 00:53:04 -0000 1.1.1.3.4.1.4.10.4.1 +++ squid/src/main.c 31 Jan 2001 12:41:52 -0000 1.1.1.3.4.1.4.10.4.2 @@ -1,6 +1,6 @@ /* - * $Id: main.c,v 1.1.1.3.4.1.4.10.4.1 2001/01/30 00:53:04 rbcollins Exp $ + * $Id: main.c,v 1.1.1.3.4.1.4.10.4.2 2001/01/31 12:41:52 rbcollins Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -634,7 +634,6 @@ eventInit(); /* eventInit() is required for config parsing */ storeFsInit(); /* required for config parsing */ authenticateSchemeInit(); /* required for config parsign */ - modules_install(); /* require for config file parsing */ parse_err = parseConfigFile(ConfigFile); if (opt_parse_cfg_only) Index: squid/src/modules.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/modules.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/modules.c 30 Jan 2001 00:53:04 -0000 1.1.2.1 +++ squid/src/modules.c 31 Jan 2001 12:41:52 -0000 1.1.2.2 @@ -35,13 +35,11 @@ #include "squid.h" -void -modules_install(){ - mod_compiled_install(); -} - void -mod_register(const char *namestr, MOD_INSTALL *install_func) { +mod_register(const char *namestr, MOD_INSTALL *install, MOD_UNINSTALL *uninstall, modNode *module) { debug(84,1)("mod_register: registering %s\n"); - install_func(namestr); + module->install=install; + module->uninstall=uninstall; + /* this may be skippable here ... */ + install(namestr); } Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.1.1.3.8.11.2.5 retrieving revision 1.1.1.3.8.11.2.6 diff -u -r1.1.1.3.8.11.2.5 -r1.1.1.3.8.11.2.6 --- squid/src/protos.h 30 Jan 2001 08:57:18 -0000 1.1.1.3.8.11.2.5 +++ squid/src/protos.h 31 Jan 2001 12:41:52 -0000 1.1.1.3.8.11.2.6 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.1.1.3.8.11.2.5 2001/01/30 08:57:18 rbcollins Exp $ + * $Id: protos.h,v 1.1.1.3.8.11.2.6 2001/01/31 12:41:52 rbcollins Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1303,12 +1303,12 @@ /* conf_modules.sh */ -extern void mod_compiled_install(void); +extern int mod_internal_install(const char *, modNode *); /* modules.c */ -extern void mod_register(const char * namestr, MOD_INSTALL *installfunc); -extern void modules_install(); +extern void mod_register(const char * namestr, MOD_INSTALL *, MOD_UNINSTALL *, modNode *); /* filters.c */ extern FILTER_module *filterByName(const char *namestr); extern FILTER_instance *filterInstanceByName(const char *namestr, filterConfig *cfg); extern void filterRegisterModule(const char *, ADDFILTERINSTANCE *, REMFILTERINSTANCE *); +extern void filterDeregisterModule(const char *); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.1.1.3.4.1.4.12.2.9 retrieving revision 1.1.1.3.4.1.4.12.2.10 diff -u -r1.1.1.3.4.1.4.12.2.9 -r1.1.1.3.4.1.4.12.2.10 --- squid/src/structs.h 30 Jan 2001 04:28:30 -0000 1.1.1.3.4.1.4.12.2.9 +++ squid/src/structs.h 31 Jan 2001 12:41:52 -0000 1.1.1.3.4.1.4.12.2.10 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.9 2001/01/30 04:28:30 rbcollins Exp $ + * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.10 2001/01/31 12:41:52 rbcollins Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -291,6 +291,18 @@ sockaddr_in_list *next; }; +struct _modNode { + dlink_node node; + char *namestr; + mod_t type; + MOD_INSTALL *install; + MOD_UNINSTALL *uninstall; +}; + +struct _modConfig { + dlink_list modules; +}; + struct _filterConfig { FILTER_instance *instances; int n_allocated; @@ -307,6 +319,7 @@ }; struct _FILTER_module { + FILTER_module *next; char *namestr; ADDFILTERINSTANCE *AddInstance; REMFILTERINSTANCE *RemInstance; @@ -361,6 +374,7 @@ }; struct _SquidConfig { + modConfig modules; struct { size_t maxSize; int highWaterMark; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.1.1.3.8.7.4.8 retrieving revision 1.1.1.3.8.7.4.9 diff -u -r1.1.1.3.8.7.4.8 -r1.1.1.3.8.7.4.9 --- squid/src/typedefs.h 30 Jan 2001 04:28:31 -0000 1.1.1.3.8.7.4.8 +++ squid/src/typedefs.h 31 Jan 2001 12:41:52 -0000 1.1.1.3.8.7.4.9 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.1.1.3.8.7.4.8 2001/01/30 04:28:31 rbcollins Exp $ + * $Id: typedefs.h,v 1.1.1.3.8.7.4.9 2001/01/31 12:41:52 rbcollins Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -374,7 +374,13 @@ typedef void FILTERPARSE(void *,const char *, char *); /* modules.c */ +typedef struct _modConfig modConfig; +typedef struct _modNode modNode; + /* name to register under */ typedef void MOD_INSTALL(const char *); +typedef void MOD_UNINSTALL(const char *); + + #endif /* _TYPEDEFS_H_ */ Index: squid/src/modules/textreplace/textreplace.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/modules/textreplace/Attic/textreplace.c,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid/src/modules/textreplace/textreplace.c 30 Jan 2001 15:24:25 -0000 1.1.2.4 +++ squid/src/modules/textreplace/textreplace.c 31 Jan 2001 12:41:53 -0000 1.1.2.5 @@ -1,6 +1,6 @@ /* - * $Id: textreplace.c,v 1.1.2.4 2001/01/30 15:24:25 rbcollins Exp $ + * $Id: textreplace.c,v 1.1.2.5 2001/01/31 12:41:53 rbcollins Exp $ * * DEBUG: section 83 Content Processing Filters * AUTHOR: Robert Collins @@ -59,7 +59,6 @@ static DATAFILTER clientFilterOnUnload; -MOD_INSTALL mod_install_textreplace; static void @@ -159,6 +158,7 @@ } } +/* register as a module */ void mod_install_textreplace (const char *namestr) { @@ -167,6 +167,12 @@ clientFilterOnUnload_RemInstance); } +/* deregister as a module */ +void +mod_uninstall_textreplace(const char *namestr) { + filterDeregisterModule(namestr); +} + char * strnchr (const char *str, char chr, size_t len)