--------------------- PatchSet 2075 Date: 2001/04/24 07:44:23 Author: rbcollins Branch: generic_modules Tag: (none) Log: first fully dynamic parsing - iplist acls Members: src/acl.c:1.21.4.7->1.21.4.8 Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.21.4.7 retrieving revision 1.21.4.8 diff -u -r1.21.4.7 -r1.21.4.8 --- squid/src/acl.c 24 Apr 2001 06:37:20 -0000 1.21.4.7 +++ squid/src/acl.c 24 Apr 2001 07:44:23 -0000 1.21.4.8 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.21.4.7 2001/04/24 06:37:20 rbcollins Exp $ + * $Id: acl.c,v 1.21.4.8 2001/04/24 07:44:23 rbcollins Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -37,6 +37,17 @@ #include "splay.h" #include "squid_parser.h" +typedef struct _aclName aclName; + +struct _aclName { + dlink_node node; + char * namestr; + parserTypeNode *type; +}; + +/* this is the list of acl names to parser types */ +static dlink_list aclNames = {NULL,NULL}; + /* this is the parent instance_name that acls live under */ static void * aclinstances = NULL; @@ -109,6 +120,64 @@ #endif static int aclCacheMatchAcl(dlink_list * cache, squid_acl acltype, void *data, char *MatchParam); + +CBDATA_TYPE (aclName); + +static void +aclNameFree(void *data) +{ + aclName *Name=data; + dlinkDelete(&Name->node,&aclNames); + debug(3,0)("aclNameFree freed name %s\n",Name->namestr); + safe_free(Name->namestr); + cbdataUnlock(Name->type); +} + + +/* FIXME: this should be merged into cache_cf */ +aclName * +aclNameByName(const char *name) +{ + dlink_node *node; + node=aclNames.head; + while (node && strcmp(((aclName *)node->data)->namestr,name)) { + node=node->next; + + } + if (node) + return (aclName *)node->data; + else + return NULL; +} + +static aclName * +aclRegisterAclName(const char *namestr, parserTypeNode *parserType) { + aclName *Name; + if ((Name=aclNameByName(namestr))==NULL) { + /* register the type */ + debug(28,3)("aclRegisterAclName new name '%s'\n",Name); + if (aclNames.head == NULL) + CBDATA_INIT_TYPE_FREECB(aclName,aclNameFree); + Name=cbdataAlloc(aclName); + Name->namestr=xstrdup(namestr); + Name->type=parserType; + cbdataLock(parserType); +// Name->default_none=default_none; +// Name->post_parse_func=post_parse_func; + dlinkAddTail(Name,&Name->node,&aclNames); + return Name; +} else { + debug(28,0)("parserRegisterInstanceName already registered name '%s'\n",Name); + return NULL; + /* TODO: fatal this */ + } +} + + + + + + static char * strtokFile(void) { @@ -732,7 +801,8 @@ // LOCAL_ARRAY(char, aclname, ACL_NAME_SZ); squid_acl acltype; int new_acl = 0; - parserTypeNode * parserType; + parserTypeNode * parserType=NULL; + aclName *aclname; #if NEVER /* snarf the ACL name */ @@ -760,9 +830,11 @@ } debug (28,0) ("acl name string %s\n",token); -parserType=parserTypeByName(token); -if (parserType) -debug (28,0) ("found parserType %s\n",parserType->typestr); +aclname = aclNameByName(token); +if (aclname) { + parserType=aclname->type; + debug (28,0) ("found parserType %s\n",parserType->typestr); +} #if NEVER if ((A = aclFindByName(aclname)) == NULL) { @@ -797,30 +869,23 @@ /* FIXME: the sub type should be registered via a one off instance - no new registrations * Allowed. Ideally this is declaritive (list the allowed types, sepcificy one type per * child */ -switch (A->type) { -case ACL_SRC_IP: -case ACL_DST_IP: -case ACL_MY_IP: +if (parserType) { /* back strtok up a step. Yummy - Should be macroised */ *(token + strlen(token))=' '; *(token-2) = 'A'; *(token-1) = ' '; strtok(token-2,w_space); -break; + + parserRegisterName(parserName, aclname->namestr, parserType, &(A->data), NULL, NULL, NULL); + /* parse the rest of the line. */ + parse_directive(parserName); } + else switch (A->type) { case ACL_SRC_IP: - parserRegisterName(parserName, "src", parserTypeByName("iplist"), &(A->data), NULL, NULL, NULL); - /* parse the rest of the line. */ - parse_directive(parserName); - break; case ACL_DST_IP: - parserRegisterName(parserName, "dst", parserTypeByName("iplist"), &(A->data), NULL, NULL, NULL); - parse_directive(parserName); - break; case ACL_MY_IP: - parserRegisterName(parserName, "myip", parserTypeByName("iplist"), &(A->data), NULL, NULL, NULL); - parse_directive(parserName); + fatal("You hurt my feelings \n"); break; case ACL_SRC_DOMAIN: case ACL_DST_DOMAIN: @@ -3098,6 +3163,9 @@ { /* register the ACL types */ parserRegisterType("iplist", aclParseIpList, aclDestroyIpList, dump_IpList ); + aclRegisterAclName("src", parserTypeByName("iplist")); + aclRegisterAclName("dst", parserTypeByName("iplist")); + aclRegisterAclName("myip", parserTypeByName("iplist")); // aclParseIpList(&A->data);aclParseDomainList(&A->data);aclParseTimeSpec(&A->data); if (aclinstances)