--------------------- PatchSet 2072 Date: 2001/04/23 22:28:33 Author: rbcollins Branch: generic_modules Tag: (none) Log: more dynamic acl work Members: include/squid_parser.h:1.1->1.1.2.1 src/acl.c:1.21.4.5->1.21.4.6 src/cache_cf.c:1.18.4.22->1.18.4.23 src/dlink.h:1.1->1.1.2.1 src/protos.h:1.18.4.18->1.18.4.19 src/structs.h:1.24.4.16->1.24.4.17 src/typedefs.h:1.15.4.14->1.15.4.15 --- /dev/null Wed Feb 14 00:51:37 2007 +++ squid/include/squid_parser.h Wed Feb 14 00:52:42 2007 @@ -0,0 +1,176 @@ +/* + * $Id$ + * + * * * * * * * * Legal stuff * * * * * * * + * + * (C) 2001 Robert Collins + * + * 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 + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; 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. + * + * * * * * * * * Declaration of intents * * * * * * * + * + * Here are defined an interface to squid's runtime-parser which is able + * To manage many of the issues in parsing the config file automaticall. + */ + +/* + +#include "defines.h" +#include "enums.h" +#include "typedefs.h" +#include "structs.h" +#include "protos.h" + +*/ + +#ifndef _SQUID_PARSER_H_ +#define _SQUID_PARSER_H_ + +/* parser types */ +typedef struct _parserTypeNode parserTypeNode; +typedef struct _parserNameNode parserNameNode; +typedef struct _includefile_t includefile_t; +typedef struct _instance_name instance_name; +typedef struct _instance_node instance_node; +typedef void PARSER_PARSE(parserNameNode *, void *); +typedef void PARSER_FREE (parserNameNode *, void *); +/* the next one is different to the cache_cf entries, because it has to be */ +typedef void PARSER_DUMP (StoreEntry *, const char *, void const *const); +typedef void PARSER_DEFAULT_NONE(void *); +typedef void PARSER_NAME_DOCUMENT(void); +typedef int PARSER_POST_PARSE(void); + +struct _includefile_t { + includefile_t * next; + char *filename; +}; + +struct _instance_name { + dlink_node node; + dlink_list instances; + char *namestr; + parserTypeNode *type; + PARSER_DEFAULT_NONE *default_none; + PARSER_NAME_DOCUMENT *documentfunc; + PARSER_POST_PARSE *post_parse_func; +}; + +struct _instance_node { + dlink_node node; + dlink_list *head; + char *namestr; + void *data; + parserNameNode *parserName; + instance_name *name; +}; + +struct _parserTypeNode { + dlink_node node; + const char *typestr; + PARSER_PARSE *parsefunc; + PARSER_FREE *freefunc; + PARSER_DUMP *dumpfunc; + struct { + unsigned int registered:1; + } flags; +}; + +struct _parserNameNode { + dlink_node node; + dlink_list children; + dlink_list *head; + const char *namestr; + parserTypeNode *type; + parserNameNode *parent; + PARSER_DEFAULT_NONE *default_none; + PARSER_NAME_DOCUMENT *documentfunc; + PARSER_POST_PARSE *post_parse_func; + void *location; + struct { + unsigned int registered:1; + } flags; +}; + + +/* + * cache_cf.c + */ +extern void parserAddDocumentOption(const char *option); +extern int parserDoDocument(const char *file_name); +extern int parserReconfigure(const char *file_name); +extern void intlistDestroy(intlist **); +extern int intlistFind(intlist * list, int i); +extern const char *wordlistAdd(wordlist **, const char *); +extern void wordlistAddWl(wordlist **, wordlist *); +extern void wordlistJoin(wordlist **, wordlist **); +extern wordlist *wordlistDup(const wordlist *); +extern void wordlistDestroy(wordlist **); +extern void configFreeMemory(void); +extern void wordlistCat(const wordlist *, MemBuf * mb); +extern void allocate_new_swapdir(cacheSwap *); +extern void self_destruct(void); +extern int GetInteger(void); + +/* extra functions from cache_cf.c useful for lib modules */ +extern void default_line(const char *); +extern PARSER_PARSE parse_int; +extern PARSER_PARSE parse_eol; +extern PARSER_PARSE parse_wordlist; +extern PARSER_FREE free_wordlist; +extern void requirePathnameExists(const char *name, const char *path); +extern PARSER_PARSE parse_time_t; + +/* support for dynamic cache types */ +extern void parserRegisterType(const char *, PARSER_PARSE *, PARSER_FREE *, PARSER_DUMP *); +extern void parserDeregisterType(parserTypeNode *); +extern parserTypeNode *parserTypeByName(const char *); +/* name, type */ +extern void parserRegisterName(parserNameNode *, const char *, parserTypeNode *, void *, PARSER_DEFAULT_NONE *, PARSER_NAME_DOCUMENT *, PARSER_POST_PARSE *); +extern void parserDeregisterName(parserNameNode *); +extern parserNameNode *parserNameByName(const char *); + +/* heirarchical parsing */ +//extern void parserRegisterInstanceType(parserNameNode *, const char *, PARSER_PARSE *, PARSER_FREE *, PARSER_DUMP *); + + +void * parserRegisterInstanceName(const char *, parserTypeNode *, PARSER_DEFAULT_NONE *, PARSER_POST_PARSE *); +extern instance_node *InstanceByNameStr(instance_name *, const char *); +extern int parse_directive(parserNameNode *); + +#endif /* _SQUID_PARSER_H_ */ Index: squid/src/acl.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/acl.c,v retrieving revision 1.21.4.5 retrieving revision 1.21.4.6 diff -u -r1.21.4.5 -r1.21.4.6 --- squid/src/acl.c 4 Apr 2001 21:50:21 -0000 1.21.4.5 +++ squid/src/acl.c 23 Apr 2001 22:28:33 -0000 1.21.4.6 @@ -1,6 +1,6 @@ /* - * $Id: acl.c,v 1.21.4.5 2001/04/04 21:50:21 rbcollins Exp $ + * $Id: acl.c,v 1.21.4.6 2001/04/23 22:28:33 rbcollins Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -35,6 +35,7 @@ #include "squid.h" #include "splay.h" +#include "squid_parser.h" /* this is the parent instance_name that acls live under */ static void * aclinstances = NULL; @@ -44,7 +45,7 @@ static void aclParseDomainList(void *curlist); static void aclParseUserList(void **current); -static void aclParseIpList(void *curlist); +static PARSER_PARSE aclParseIpList; #if UNUSED_CODE static void aclParseIntlist(void *curlist); #endif @@ -526,7 +527,7 @@ /******************/ static void -aclParseIpList(void *curlist) +aclParseIpList(parserNameNode *parserName, void *curlist) { char *t = NULL; splayNode **Top = curlist; @@ -726,16 +727,15 @@ acl ** head=(acl **)data; /* we're already using strtok() to grok the line */ - char *t = NULL; + char *token = NULL; acl *A = NULL; // LOCAL_ARRAY(char, aclname, ACL_NAME_SZ); squid_acl acltype; int new_acl = 0; - #if NEVER /* snarf the ACL name */ - if ((t = strtok(NULL, w_space)) == NULL) { + if ((token = strtok(NULL, w_space)) == NULL) { debug(28, 0) ("%s line %d: %s\n", cfg_filename, config_lineno, config_input_line); debug(28, 0) ("aclParseAclLine: missing ACL name.\n"); @@ -744,16 +744,16 @@ xstrncpy(aclname, t, ACL_NAME_SZ); #endif /* snarf the ACL type */ - if ((t = strtok(NULL, w_space)) == NULL) { + if ((token = strtok(NULL, w_space)) == NULL) { debug(28, 0) ("%s line %d: %s\n", cfg_filename, config_lineno, config_input_line); debug(28, 0) ("aclParseAclLine: missing ACL type.\n"); return; } - if ((acltype = aclStrToType(t)) == ACL_NONE) { + if ((acltype = aclStrToType(token)) == ACL_NONE) { debug(28, 0) ("%s line %d: %s\n", cfg_filename, config_lineno, config_input_line); - debug(28, 0) ("aclParseAclLine: Invalid ACL type '%s'\n", t); + debug(28, 0) ("aclParseAclLine: Invalid ACL type '%s'\n", token); return; } #if NEVER @@ -789,11 +789,30 @@ /* 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: + /* back strtok up a step. Yummy - Should be macroised */ + *(token + strlen(token))=' '; + *(token-2) = 'A'; + *(token-1) = ' '; + strtok(token-2,w_space); +break; +} 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: - aclParseIpList(&A->data); + parserRegisterName(parserName, "myip", parserTypeByName("iplist"), &(A->data), NULL, NULL, NULL); + parse_directive(parserName); break; case ACL_SRC_DOMAIN: case ACL_DST_DOMAIN: Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cache_cf.c,v retrieving revision 1.18.4.22 retrieving revision 1.18.4.23 diff -u -r1.18.4.22 -r1.18.4.23 --- squid/src/cache_cf.c 4 Apr 2001 21:50:21 -0000 1.18.4.22 +++ squid/src/cache_cf.c 23 Apr 2001 22:28:33 -0000 1.18.4.23 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.18.4.22 2001/04/04 21:50:21 rbcollins Exp $ + * $Id: cache_cf.c,v 1.18.4.23 2001/04/23 22:28:33 rbcollins Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -2651,19 +2651,19 @@ if ((instance=InstanceByNameStr(Name,token))==NULL) { /* register me */ - if (Name->instances.head==NULL) - CBDATA_INIT_TYPE_FREECB(instance_node,InstanceNodeFree); - instance=cbdataAlloc(instance_node); + if (Name->instances.head==NULL) + CBDATA_INIT_TYPE_FREECB(instance_node,InstanceNodeFree); + instance=cbdataAlloc(instance_node); - debug(3,0)("parsing new instance name %s\n",token); + debug(3,0)("parsing new instance name %s\n",token); - instance->namestr=xstrdup(token); - instance->head=&Name->instances; - instance->data=NULL; - parserRegisterName(parserName, instance->namestr, Name->type, &instance->data, NULL, NULL, NULL); - instance->parserName=parserNameByNodeName(&parserName->children, instance->namestr); - assert(instance->parserName); - dlinkAddTail(instance,&instance->node, instance->head); + instance->namestr=xstrdup(token); + instance->head=&Name->instances; + instance->data=NULL; + parserRegisterName(parserName, instance->namestr, Name->type, &instance->data, NULL, NULL, NULL); + instance->parserName=parserNameByNodeName(&parserName->children, instance->namestr); + assert(instance->parserName); + dlinkAddTail(instance,&instance->node, instance->head); } /* parse that instance */ instance->parserName->type->parsefunc(instance->parserName, instance->parserName->location); @@ -2843,6 +2843,7 @@ parserName->documentfunc=documentfunc; parserName->post_parse_func=post_parse_func; parserName->head = parent ? &parent->children : &parserNames; + parserName->parent = parent; parserName->children.head=NULL; parserName->children.tail=NULL; dlinkAddTail(parserName,&parserName->node,parserName->head); @@ -2918,20 +2919,23 @@ { char *token; char saved; + size_t saved_len; saved=current_token[strlen(current_token)-1]; + saved_len = strlen(current_token+strlen(current_token)+1); if ((token = strtok(NULL, w_space)) == NULL) /* Fail if no more tokens on this line */ return 0; debug(3,8)("next token %s\n",token); /* back up strtok a step. Yummy */ - *(token + strlen(token))=' '; + if (strlen(token) != saved_len) + *(token + strlen(token))=' '; *(token-2) = saved; *(token-1) = ' '; strtok(token-2,w_space); return 1; } -static int +int parse_directive(parserNameNode *parent) { char *token; --- /dev/null Wed Feb 14 00:51:37 2007 +++ squid/src/dlink.h Wed Feb 14 00:52:42 2007 @@ -0,0 +1,51 @@ + +/* + * $Id$ + * + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; 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. + * + */ + +#ifndef _DLINK_H_ +#define _DLINK_H_ + +typedef struct _dlink_node dlink_node; +typedef struct _dlink_list dlink_list; + +struct _dlink_node { + void *data; + dlink_node *prev; + dlink_node *next; +}; + +struct _dlink_list { + dlink_node *head; + dlink_node *tail; +}; + +#endif /* DLINK_H */ Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.18.4.18 retrieving revision 1.18.4.19 diff -u -r1.18.4.18 -r1.18.4.19 --- squid/src/protos.h 31 Mar 2001 11:07:23 -0000 1.18.4.18 +++ squid/src/protos.h 23 Apr 2001 22:28:33 -0000 1.18.4.19 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.18.4.18 2001/03/31 11:07:23 rbcollins Exp $ + * $Id: protos.h,v 1.18.4.19 2001/04/23 22:28:33 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -74,49 +74,11 @@ /* * cache_cf.c + * FIXME: these should be registered by the appropriate "area" of squid, not in + * cache_cf.c */ -extern void parserAddDocumentOption(const char *option); -extern int parserDoDocument(const char *file_name); -extern int parserReconfigure(const char *file_name); -extern void intlistDestroy(intlist **); -extern int intlistFind(intlist * list, int i); -extern const char *wordlistAdd(wordlist **, const char *); -extern void wordlistAddWl(wordlist **, wordlist *); -extern void wordlistJoin(wordlist **, wordlist **); -extern wordlist *wordlistDup(const wordlist *); -extern void wordlistDestroy(wordlist **); -extern void configFreeMemory(void); -extern void wordlistCat(const wordlist *, MemBuf * mb); -extern void allocate_new_swapdir(cacheSwap *); -extern void self_destruct(void); -extern int GetInteger(void); - -/* extra functions from cache_cf.c useful for lib modules */ -extern void default_line(const char *); -extern PARSER_PARSE parse_int; -extern PARSER_PARSE parse_eol; -extern PARSER_PARSE parse_wordlist; -extern PARSER_FREE free_wordlist; -extern void requirePathnameExists(const char *name, const char *path); -extern PARSER_PARSE parse_time_t; extern void parse_cachedir_options(SwapDir * sd, struct cache_dir_option *options, int reconfiguring); -/* support for dynamic cache types */ -extern void parserRegisterType(const char *, PARSER_PARSE *, PARSER_FREE *, PARSER_DUMP *); -extern void parserDeregisterType(parserTypeNode *); -extern parserTypeNode *parserTypeByName(const char *); -/* name, type */ -extern void parserRegisterName(parserNameNode *, const char *, parserTypeNode *, void *, PARSER_DEFAULT_NONE *, PARSER_NAME_DOCUMENT *, PARSER_POST_PARSE *); -extern void parserDeregisterName(parserNameNode *); -extern parserNameNode *parserNameByName(const char *); - -/* heirarchical parsing */ -//extern void parserRegisterInstanceType(parserNameNode *, const char *, PARSER_PARSE *, PARSER_FREE *, PARSER_DUMP *); - - -void * parserRegisterInstanceName(const char *, parserTypeNode *, PARSER_DEFAULT_NONE *, PARSER_POST_PARSE *); -extern instance_node *InstanceByNameStr(instance_name *, const char *); - /* * cbdata.c */ Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.24.4.16 retrieving revision 1.24.4.17 diff -u -r1.24.4.16 -r1.24.4.17 --- squid/src/structs.h 31 Mar 2001 11:07:23 -0000 1.24.4.16 +++ squid/src/structs.h 23 Apr 2001 22:28:33 -0000 1.24.4.17 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.24.4.16 2001/03/31 11:07:23 rbcollins Exp $ + * $Id: structs.h,v 1.24.4.17 2001/04/23 22:28:33 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -33,17 +33,8 @@ #include "config.h" #include "splay.h" - -struct _dlink_node { - void *data; - dlink_node *prev; - dlink_node *next; -}; - -struct _dlink_list { - dlink_node *head; - dlink_node *tail; -}; +/* FIXME: remove this - no global structures should refer to the parser library */ +#include "squid_parser.h" struct _acl_user_data { splayNode *names; @@ -299,51 +290,6 @@ dlink_list modules; }; -struct _instance_name { - dlink_node node; - dlink_list instances; - char *namestr; - parserTypeNode *type; - PARSER_DEFAULT_NONE *default_none; - PARSER_NAME_DOCUMENT *documentfunc; - PARSER_POST_PARSE *post_parse_func; -}; - -struct _instance_node { - dlink_node node; - dlink_list *head; - char *namestr; - void *data; - parserNameNode *parserName; - instance_name *name; -}; - -struct _parserTypeNode { - dlink_node node; - const char *typestr; - PARSER_PARSE *parsefunc; - PARSER_FREE *freefunc; - PARSER_DUMP *dumpfunc; - struct { - unsigned int registered:1; - } flags; -}; - -struct _parserNameNode { - dlink_node node; - dlink_list children; - dlink_list *head; - const char *namestr; - parserTypeNode *type; - PARSER_DEFAULT_NONE *default_none; - PARSER_NAME_DOCUMENT *documentfunc; - PARSER_POST_PARSE *post_parse_func; - void *location; - struct { - unsigned int registered:1; - } flags; -}; - #if DELAY_POOLS struct _delaySpec { int restore_bps; @@ -374,11 +320,6 @@ wordlist *args; }; -struct _includefile_t { - includefile_t * next; - char *filename; -}; - struct _SquidConfig { modConfig modules; includefile_t *files; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.15.4.14 retrieving revision 1.15.4.15 diff -u -r1.15.4.14 -r1.15.4.15 --- squid/src/typedefs.h 31 Mar 2001 11:07:23 -0000 1.15.4.14 +++ squid/src/typedefs.h 23 Apr 2001 22:28:34 -0000 1.15.4.15 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.15.4.14 2001/03/31 11:07:23 rbcollins Exp $ + * $Id: typedefs.h,v 1.15.4.15 2001/04/23 22:28:34 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -34,6 +34,9 @@ #ifndef _TYPEDEFS_H_ #define _TYPEDEFS_H_ +/* FIXME: this shouldn't be a global include */ +#include "dlink.h" + typedef unsigned int store_status_t; typedef unsigned int mem_status_t; typedef unsigned int ping_status_t; @@ -149,8 +152,6 @@ typedef struct _refresh_t refresh_t; typedef struct _CommWriteStateData CommWriteStateData; typedef struct _ErrorState ErrorState; -typedef struct _dlink_node dlink_node; -typedef struct _dlink_list dlink_list; typedef struct _StatCounters StatCounters; typedef struct _tlv tlv; typedef struct _storeSwapLogData storeSwapLogData; @@ -199,20 +200,6 @@ typedef unsigned int MOD_UNINSTALL(const char *); /* end modules.c */ -/* parser types */ -typedef struct _parserTypeNode parserTypeNode; -typedef struct _parserNameNode parserNameNode; -typedef struct _includefile_t includefile_t; -typedef struct _instance_name instance_name; -typedef struct _instance_node instance_node; -typedef void PARSER_PARSE(parserNameNode *, void *); -typedef void PARSER_FREE (parserNameNode *, void *); -/* the next one is different to the cache_cf entries, because it has to be */ -typedef void PARSER_DUMP (StoreEntry *, const char *, void const *const); -typedef void PARSER_DEFAULT_NONE(void *); -typedef void PARSER_NAME_DOCUMENT(void); -typedef int PARSER_POST_PARSE(void); - #if SQUID_SNMP typedef variable_list *(oid_ParseFn) (variable_list *, snint *); typedef struct _snmp_request_t snmp_request_t;