--------------------- PatchSet 1614 Date: 2001/02/20 06:22:52 Author: rbcollins Branch: generic_modules Tag: (none) Log: dynamic parsing Members: src/cache_cf.c:1.18.4.5->1.18.4.6 src/cf.data.pre:1.21.4.3->1.21.4.4 src/cf_gen.c:1.7.8.1->1.7.8.2 src/protos.h:1.18.4.6->1.18.4.7 src/structs.h:1.24.4.5->1.24.4.6 src/typedefs.h:1.15.4.4->1.15.4.5 Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cache_cf.c,v retrieving revision 1.18.4.5 retrieving revision 1.18.4.6 diff -u -r1.18.4.5 -r1.18.4.6 --- squid/src/cache_cf.c 19 Feb 2001 21:02:51 -0000 1.18.4.5 +++ squid/src/cache_cf.c 20 Feb 2001 06:22:52 -0000 1.18.4.6 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.18.4.5 2001/02/19 21:02:51 rbcollins Exp $ + * $Id: cache_cf.c,v 1.18.4.6 2001/02/20 06:22:52 rbcollins Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -58,39 +58,46 @@ static void update_maxobjsize(void); static void configDoConfigure(void); -static void parse_refreshpattern(refresh_t **); +static PARSER_PARSE parse_refreshpattern; static int parseTimeUnits(const char *unit); static void parseTimeLine(time_t * tptr, const char *units); -static void parse_ushort(u_short * var); -static void parse_string(char **); -void parse_wordlist(wordlist **); +static PARSER_PARSE parse_ushort; +static PARSER_PARSE parse_string; +PARSER_PARSE parse_wordlist; static void default_all(void); static void defaults_if_none(void); static int parse_line(char *); static void parseBytesLine(size_t * bptr, const char *units); static size_t parseBytesUnits(const char *unit); static void free_all(void); +static void parserRegisterAllTypes(void); +static void parserDeregisterAllTypes(void); +static void parserRegisterAllNames(void); +static void parserDeregisterAllNames(void); void requirePathnameExists(const char *name, const char *path); static OBJH dump_config; -static void dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]); -static void parse_http_header_access(header_mangler header[]); -static void free_http_header_access(header_mangler header[]); -static void dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler header[]); -static void parse_http_header_replace(header_mangler * header); -static void free_http_header_replace(header_mangler * header); -static void parse_denyinfo(acl_deny_info_list ** var); -static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var); -static void free_denyinfo(acl_deny_info_list ** var); -static void parse_sockaddr_in_list(sockaddr_in_list **); -static void dump_sockaddr_in_list(StoreEntry *, const char *, const sockaddr_in_list *); -static void free_sockaddr_in_list(sockaddr_in_list **); +static PARSER_DUMP dump_http_header_access; +static PARSER_PARSE parse_http_header_access; +static PARSER_FREE free_http_header_access; +static PARSER_DUMP dump_http_header_replace; +static PARSER_PARSE parse_http_header_replace; +static PARSER_FREE free_http_header_replace; +static PARSER_PARSE parse_denyinfo; +static PARSER_DUMP dump_denyinfo; +static PARSER_FREE free_denyinfo; +static PARSER_PARSE parse_sockaddr_in_list; +static PARSER_DUMP dump_sockaddr_in_list; +static PARSER_FREE free_sockaddr_in_list; static int check_null_sockaddr_in_list(const sockaddr_in_list *); /* dynamic type and name support */ +parserTypeNode *parserTypeByName(const char *); void parserRegisterType(const char *, PARSER_PARSE *, PARSER_FREE *, PARSER_DUMP *); void parserDeregisterType(const char *); -void parserRegisterName(const char *, const char *); +parserNameNode *parserNameByName(const char *name); +void parserRegisterName(const char *, parserTypeNode *, void *); void parserDeregisterName(const char *); +static int parse_line(char *buff); void self_destruct(void) @@ -100,8 +107,9 @@ } void -wordlistDestroy(wordlist ** list) +wordlistDestroy(void *data) { + wordlist ** list=data; wordlist *w = NULL; while ((w = *list) != NULL) { *list = w->next; @@ -523,8 +531,9 @@ *****************************************************************************/ static void -dump_acl(StoreEntry * entry, const char *name, acl * ae) +dump_acl(StoreEntry * entry, const char *name, void const * const data) { + acl * ae=*(acl * *)data; wordlist *w; wordlist *v; while (ae != NULL) { @@ -545,20 +554,23 @@ } static void -parse_acl(acl ** ae) +parse_acl(void * data) { + acl ** ae=(acl **)data; aclParseAclLine(ae); } static void -free_acl(acl ** ae) +free_acl(void *data) { + acl ** ae=(acl **)data; aclDestroyAcls(ae); } static void -dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) +dump_acl_access(StoreEntry * entry, const char *name, void const * const data) { + acl_access *head=*(acl_access **)data; acl_list *l; while (head != NULL) { storeAppendPrintf(entry, "%s %s", @@ -575,26 +587,30 @@ } static void -parse_acl_access(acl_access ** head) +parse_acl_access(void * data) { + acl_access ** head=(acl_access **)data; aclParseAccessLine(head); } static void -free_acl_access(acl_access ** head) +free_acl_access(void * data) { + acl_access ** head=(acl_access **)data; aclDestroyAccessList(head); } static void -dump_address(StoreEntry * entry, const char *name, struct in_addr addr) +dump_address(StoreEntry * entry, const char *name, void const * const data) { + struct in_addr addr=*(struct in_addr *)data; storeAppendPrintf(entry, "%s %s\n", name, inet_ntoa(addr)); } static void -parse_address(struct in_addr *addr) +parse_address(void * data) { + struct in_addr *addr=data; const struct hostent *hp; char *token = strtok(NULL, w_space); @@ -609,8 +625,9 @@ } static void -free_address(struct in_addr *addr) +free_address(void * data) { + struct in_addr *addr=data; memset(addr, '\0', sizeof(struct in_addr)); } @@ -619,16 +636,17 @@ /* do nothing - free_delay_pool_count is the magic free function. * this is why delay_pool_count isn't just marked TYPE: ushort */ -#define free_delay_pool_class(X) -#define free_delay_pool_access(X) -#define free_delay_pool_rates(X) -#define dump_delay_pool_class(X, Y, Z) -#define dump_delay_pool_access(X, Y, Z) -#define dump_delay_pool_rates(X, Y, Z) +//#define free_delay_pool_class(X) +//#define free_delay_pool_access(X) +//#define free_delay_pool_rates(X) +//#define dump_delay_pool_class(X, Y, Z) +//#define dump_delay_pool_access(X, Y, Z) +//#define dump_delay_pool_rates(X, Y, Z) static void -free_delay_pool_count(delayConfig * cfg) +free_delay_pool_count(void * data) { + delayConfig * cfg=data; int i; if (!cfg->pools) @@ -647,9 +665,14 @@ memset(cfg, 0, sizeof(*cfg)); } +#define free_delay_pool_class free_delay_pool_count +#define free_delay_pool_access free_delay_pool_count +#define free_delay_pool_rates free_delay_pool_count + static void -dump_delay_pool_count(StoreEntry * entry, const char *name, delayConfig cfg) +dump_delay_pool_count(StoreEntry * entry, const char *name, void const * const data) { + delayConfig cfg=*(delayConfig *)data; int i; LOCAL_ARRAY(char, nom, 32); @@ -679,9 +702,14 @@ } } +#define dump_delay_pool_class dump_delay_pool_count +#define dump_delay_pool_access dump_delay_pool_count +#define dump_delay_pool_rates dump_delay_pool_count + static void -parse_delay_pool_count(delayConfig * cfg) +parse_delay_pool_count(void * data) { + delayConfig * cfg=data; if (cfg->pools) { debug(3, 0) ("parse_delay_pool_count: multiple delay_pools lines, aborting all previous delay_pools config\n"); free_delay_pool_count(cfg); @@ -694,8 +722,9 @@ } static void -parse_delay_pool_class(delayConfig * cfg) +parse_delay_pool_class(void * data) { + delayConfig * cfg=data; ushort pool, class; parse_ushort(&pool); @@ -724,8 +753,9 @@ } static void -parse_delay_pool_rates(delayConfig * cfg) +parse_delay_pool_rates(void * data) { + delayConfig * cfg=data; ushort pool, class; int i; delaySpec *ptr; @@ -769,8 +799,9 @@ } static void -parse_delay_pool_access(delayConfig * cfg) +parse_delay_pool_access(void * data) { + delayConfig * cfg=data; ushort pool; parse_ushort(&pool); @@ -783,10 +814,11 @@ #endif static void -dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]) +dump_http_header_access(StoreEntry * entry, const char *name, void const * const data) { + header_mangler *header=data; int i; - storeAppendPrintf(entry, "%s:", name); + storeAppendPrintf(entry, "%s", name); for (i = 0; i < HDR_ENUM_END; i++) { if (header[i].access_list != NULL) { storeAppendPrintf(entry, "\t"); @@ -797,8 +829,9 @@ } static void -parse_http_header_access(header_mangler header[]) +parse_http_header_access(void * data) { + header_mangler *header=data; int id, i; char *t = NULL; if ((t = strtok(NULL, w_space)) == NULL) { @@ -834,8 +867,9 @@ } static void -free_http_header_access(header_mangler header[]) +free_http_header_access(void * data) { + header_mangler *header=data; int i; for (i = 0; i < HDR_ENUM_END; i++) { free_acl_access(&header[i].access_list); @@ -843,11 +877,11 @@ } static void -dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler - header[]) +dump_http_header_replace(StoreEntry * entry, const char *name, void const * const data) { + header_mangler *header=data; int i; - storeAppendPrintf(entry, "%s:", name); + storeAppendPrintf(entry, "%s", name); for (i = 0; i < HDR_ENUM_END; i++) { if (NULL == header[i].replacement) continue; @@ -857,8 +891,9 @@ } static void -parse_http_header_replace(header_mangler header[]) +parse_http_header_replace(void * data) { + header_mangler *header=data; int id, i; char *t = NULL; if ((t = strtok(NULL, w_space)) == NULL) { @@ -894,8 +929,9 @@ } static void -free_http_header_replace(header_mangler header[]) +free_http_header_replace(void * data) { + header_mangler *header=data; int i; for (i = 0; i < HDR_ENUM_END; i++) { if (header[i].replacement != NULL) @@ -904,8 +940,9 @@ } static void -dump_cachedir(StoreEntry * entry, const char *name, cacheSwap swap) +dump_cachedir(StoreEntry * entry, const char *name, void const * const data) { + cacheSwap swap=*(cacheSwap *)data; SwapDir *s; int i; for (i = 0; i < swap.n_configured; i++) { @@ -944,8 +981,9 @@ } static void -parse_authparam(authConfig * config) +parse_authparam(void * data) { + authConfig * config=data; char *type_str; char *param_str; authScheme *scheme = NULL; @@ -978,8 +1016,9 @@ } static void -free_authparam(authConfig * cfg) +free_authparam(void * data) { + authConfig * cfg=data; authScheme *scheme; int i; /* DON'T FREE THESE FOR RECONFIGURE */ @@ -996,8 +1035,9 @@ } static void -dump_authparam(StoreEntry * entry, const char *name, authConfig cfg) +dump_authparam(StoreEntry * entry, const char *name, void const * const data) { + authConfig cfg=*(authConfig *)data; authScheme *scheme; int i; for (i = 0; i < cfg.n_configured; i++) { @@ -1035,8 +1075,9 @@ /* TODO: write a cbdataFree handler for modNode's. */ static void -parse_mod_install(modConfig * cfg) +parse_mod_install(void *data) { + modConfig * cfg = data; char *type_str = NULL, *name_str = NULL; mod_t type = MOD_NONE; modNode *node = NULL; @@ -1098,8 +1139,9 @@ } static void -free_mod_install(modConfig * cfg) +free_mod_install(void *data) { + modConfig * cfg=data; dlink_node *node, *tmpnode; modNode *module; node = cfg->modules.head; @@ -1116,11 +1158,12 @@ } static void -dump_mod_install(StoreEntry * entry, const char *name, modConfig cfg) +dump_mod_install(StoreEntry * entry, const char *name, void const *data) { + modConfig const * cfg=data; dlink_node *node; modNode *module; - node = cfg.modules.head; + node = cfg->modules.head; while (node) { module = node->data; storeAppendPrintf(entry, "mod_install %s %s\n",mod_type_str(module->type),module->namestr); @@ -1149,6 +1192,10 @@ find_fstype(char *type) { int i; + if (!storefs_list) { + debug(3,0)("No fs module installed\n"); + return (-1); + } for (i = 0; storefs_list[i].typestr != NULL; i++) { if (strcasecmp(type, storefs_list[i].typestr) == 0) { return i; @@ -1158,8 +1205,9 @@ } static void -parse_cachedir(cacheSwap * swap) +parse_cachedir(void * data) { + cacheSwap * swap=data; char *type_str; char *path_str; SwapDir *sd; @@ -1302,8 +1350,9 @@ } static void -free_cachedir(cacheSwap * swap) +free_cachedir(void * data) { + cacheSwap * swap=data; SwapDir *s; int i; /* DON'T FREE THESE FOR RECONFIGURE */ @@ -1340,8 +1389,9 @@ } static void -dump_peer(StoreEntry * entry, const char *name, peer * p) +dump_peer(StoreEntry * entry, const char *name, void const * const data) { + peer * p=*(peer **)data; domain_ping *d; acl_access *a; domain_type *t; @@ -1375,8 +1425,9 @@ } static void -parse_peer(peer ** head) +parse_peer(void * data) { + peer ** head=(peer **)data; char *token = NULL; peer *p; int i; @@ -1483,8 +1534,9 @@ } static void -free_peer(peer ** P) +free_peer(void * data) { + peer ** P=(peer **)data; peer *p; while ((p = *P) != NULL) { *P = p->next; @@ -1499,8 +1551,9 @@ } static void -dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list) +dump_cachemgrpasswd(StoreEntry * entry, const char *name, void const * const data) { + cachemgr_passwd * list=*(cachemgr_passwd **)data; wordlist *w; while (list != NULL) { if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) @@ -1516,8 +1569,9 @@ } static void -parse_cachemgrpasswd(cachemgr_passwd ** head) +parse_cachemgrpasswd(void * data) { + cachemgr_passwd ** head=(cachemgr_passwd **)data; char *passwd = NULL; wordlist *actions = NULL; cachemgr_passwd *p; @@ -1532,8 +1586,9 @@ } static void -free_cachemgrpasswd(cachemgr_passwd ** head) +free_cachemgrpasswd(void * data) { + cachemgr_passwd ** head=(cachemgr_passwd **)data; cachemgr_passwd *p; while ((p = *head) != NULL) { *head = p->next; @@ -1544,8 +1599,9 @@ } static void -dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var) +dump_denyinfo(StoreEntry * entry, const char *name, void const * const data) { + acl_deny_info_list *var=*(acl_deny_info_list **)data; acl_name_list *a; while (var != NULL) { storeAppendPrintf(entry, "%s %s", name, var->err_page_name); @@ -1557,14 +1613,16 @@ } static void -parse_denyinfo(acl_deny_info_list ** var) +parse_denyinfo(void * data) { + acl_deny_info_list ** var=( acl_deny_info_list **)data; aclParseDenyInfoLine(var); } void -free_denyinfo(acl_deny_info_list ** list) +free_denyinfo(void * data) { + acl_deny_info_list ** list=( acl_deny_info_list **)data; acl_deny_info_list *a = NULL; acl_deny_info_list *a_next = NULL; acl_name_list *l = NULL; @@ -1583,7 +1641,7 @@ } static void -parse_peer_access(void) +parse_peer_access(void * data) { char *host = NULL; peer *p; @@ -1598,7 +1656,19 @@ } static void -parse_hostdomain(void) +free_peer_access(void * data) +{ + /* nop as it's currently freed with the peer */ +} + +static void +dump_peer_access(StoreEntry * entry, const char *name, void const * const data) +{ + /* nop as it's currently dumped with the peer settings */ +} + +static void +parse_hostdomain(void * data) { char *host = NULL; char *domain = NULL; @@ -1626,7 +1696,19 @@ } static void -parse_hostdomaintype(void) +free_hostdomain(void * data) +{ + /* nop as it's currently freed with the peer */ +} + +static void +dump_hostdomain(StoreEntry * entry, const char *name, void const * const data) +{ + /* nop as it's currently dumped with the peer settings */ +} + +static void +parse_hostdomaintype(void * data) { char *host = NULL; char *type = NULL; @@ -1652,10 +1734,23 @@ } } +static void +free_hostdomaintype(void * data) +{ + /* nop as it's currently freed with the peer */ +} + +static void +dump_hostdomaintype(StoreEntry * entry, const char *name, void const * const data) +{ + /* nop as it's currently dumped with the peer settings */ +} + #if UNUSED_CODE static void -dump_ushortlist(StoreEntry * entry, const char *name, ushortlist * u) +dump_ushortlist(StoreEntry * entry, const char *name, void const * const data) { + ushortlist * u=*(ushortlist **)data; while (u) { storeAppendPrintf(entry, "%s %d\n", name, (int) u->i); u = u->next; @@ -1699,34 +1794,39 @@ #endif static void -dump_int(StoreEntry * entry, const char *name, int var) +dump_int(StoreEntry * entry, const char *name, void const * const data) { + int var=*(int *)data; storeAppendPrintf(entry, "%s %d\n", name, var); } void -parse_int(int *var) +parse_int(void * data) { + int *var=data; int i; i = GetInteger(); *var = i; } static void -free_int(int *var) +free_int(void * data) { + int *var=data; *var = 0; } static void -dump_onoff(StoreEntry * entry, const char *name, int var) +dump_onoff(StoreEntry * entry, const char *name, void const * const data) { + int var=*(int *)data; storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off"); } static void -parse_onoff(int *var) +parse_onoff(void * data) { + int *var=data; char *token = strtok(NULL, w_space); if (token == NULL) @@ -1742,8 +1842,9 @@ #define free_eol free_string static void -dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head) +dump_refreshpattern(StoreEntry * entry, const char *name, void const * const data) { + refresh_t * head=*(refresh_t **)data; while (head != NULL) { storeAppendPrintf(entry, "%s%s %s %d %d%% %d\n", name, @@ -1768,8 +1869,9 @@ } static void -parse_refreshpattern(refresh_t ** head) +parse_refreshpattern(void * data) { + refresh_t ** head=(refresh_t **)data; char *token; char *pattern; time_t min = 0; @@ -1867,8 +1969,9 @@ } static void -free_refreshpattern(refresh_t ** head) +free_refreshpattern(void * data) { + refresh_t ** head=(refresh_t **)data; refresh_t *t; while ((t = *head) != NULL) { *head = t->next; @@ -1879,15 +1982,17 @@ } static void -dump_string(StoreEntry * entry, const char *name, char *var) +dump_string(StoreEntry * entry, const char *name, void const * const data) { + char *var=*(char **)data; if (var != NULL) storeAppendPrintf(entry, "%s %s\n", name, var); } static void -parse_string(char **var) +parse_string(void * data) { + char **var=(char **)data; char *token = strtok(NULL, w_space); safe_free(*var); if (token == NULL) @@ -1896,14 +2001,16 @@ } static void -free_string(char **var) +free_string(void * data) { + char **var=(char **) data; safe_free(*var); } void -parse_eol(char *volatile *var) +parse_eol(void * data) { + char *volatile *var=(char *volatile*)data; unsigned char *token = strtok(NULL, null_string); safe_free(*var); if (token == NULL) @@ -1916,64 +2023,74 @@ } static void -dump_time_t(StoreEntry * entry, const char *name, time_t var) +dump_time_t(StoreEntry * entry, const char *name, void const * const data) { + time_t var=*(time_t *)data; storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var); } void -parse_time_t(time_t * var) +parse_time_t(void * data) { + time_t * var=data; parseTimeLine(var, T_SECOND_STR); } static void -free_time_t(time_t * var) +free_time_t(void * data) { + time_t * var=data; *var = 0; } static void -dump_size_t(StoreEntry * entry, const char *name, size_t var) +dump_size_t(StoreEntry * entry, const char *name, void const * const data) { + size_t var=*(size_t *)data; storeAppendPrintf(entry, "%s %d\n", name, (int) var); } static void -dump_b_size_t(StoreEntry * entry, const char *name, size_t var) +dump_b_size_t(StoreEntry * entry, const char *name, void const * const data) { + size_t var=*(size_t *)data; storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); } static void -dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) +dump_kb_size_t(StoreEntry * entry, const char *name, void const * const data) { + size_t var=*(size_t *)data; storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR); } static void -parse_size_t(size_t * var) +parse_size_t(void * data) { + size_t * var=data; int i; i = GetInteger(); *var = (size_t) i; } static void -parse_b_size_t(size_t * var) +parse_b_size_t(void * data) { + size_t * var=data; parseBytesLine(var, B_BYTES_STR); } static void -parse_kb_size_t(size_t * var) +parse_kb_size_t(void * data) { + size_t * var=data; parseBytesLine(var, B_KBYTES_STR); } static void -free_size_t(size_t * var) +free_size_t(void * data) { + size_t * var=data; *var = 0; } @@ -1983,20 +2100,23 @@ #define free_gb_size_t free_size_t static void -dump_ushort(StoreEntry * entry, const char *name, u_short var) +dump_ushort(StoreEntry * entry, const char *name, void const * const data) { + u_short var=*(u_short *)data; storeAppendPrintf(entry, "%s %d\n", name, var); } static void -free_ushort(u_short * u) +free_ushort(void * data) { + u_short * u=data; *u = 0; } static void -parse_ushort(u_short * var) +parse_ushort(void * data) { + u_short * var=data; int i; i = GetInteger(); @@ -2006,8 +2126,9 @@ } static void -dump_wordlist(StoreEntry * entry, const char *name, wordlist * list) +dump_wordlist(StoreEntry * entry, const char *name, void const * const data) { + wordlist * list=*(wordlist **)data; while (list != NULL) { storeAppendPrintf(entry, "%s %s\n", name, list->key); list = list->next; @@ -2015,8 +2136,9 @@ } void -parse_wordlist(wordlist ** list) +parse_wordlist(void * data) { + wordlist ** list=data; char *token; while ((token = strtok(NULL, w_space))) wordlistAdd(list, token); @@ -2039,8 +2161,9 @@ #define free_uri_whitespace free_int static void -parse_uri_whitespace(int *var) +parse_uri_whitespace(void * data) { + int *var=data; char *token = strtok(NULL, w_space); if (token == NULL) self_destruct(); @@ -2060,8 +2183,9 @@ static void -dump_uri_whitespace(StoreEntry * entry, const char *name, int var) +dump_uri_whitespace(StoreEntry * entry, const char *name, void const * const data) { + int var=*(int *)data; char *s; if (var == URI_WHITESPACE_ALLOW) s = "allow"; @@ -2077,8 +2201,9 @@ } static void -free_removalpolicy(RemovalPolicySettings ** settings) +free_removalpolicy(void * data) { + RemovalPolicySettings ** settings=(RemovalPolicySettings **)data; if (!*settings) return; free_string(&(*settings)->type); @@ -2088,8 +2213,9 @@ } static void -parse_removalpolicy(RemovalPolicySettings ** settings) +parse_removalpolicy(void * data) { + RemovalPolicySettings ** settings=(RemovalPolicySettings **)data; if (*settings) free_removalpolicy(settings); *settings = xcalloc(1, sizeof(**settings)); @@ -2098,8 +2224,9 @@ } static void -dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings) +dump_removalpolicy(StoreEntry * entry, const char *name, void const * const data) { + RemovalPolicySettings * settings=*(RemovalPolicySettings * *)data; wordlist *args; storeAppendPrintf(entry, "%s %s", name, settings->type); args = settings->args; @@ -2131,8 +2258,9 @@ } static void -parse_sockaddr_in_list(sockaddr_in_list ** head) +parse_sockaddr_in_list(void * data) { + sockaddr_in_list ** head =(sockaddr_in_list **)data; char *token; char *t; char *host; @@ -2171,8 +2299,9 @@ } static void -dump_sockaddr_in_list(StoreEntry * e, const char *n, const sockaddr_in_list * s) +dump_sockaddr_in_list(StoreEntry * e, const char *n, void const * const data) { + sockaddr_in_list * s=*(sockaddr_in_list **)data; while (s) { storeAppendPrintf(e, "%s %s:%d\n", n, @@ -2183,8 +2312,9 @@ } static void -free_sockaddr_in_list(sockaddr_in_list ** head) +free_sockaddr_in_list(void * data) { + sockaddr_in_list ** head=(sockaddr_in_list **)data; sockaddr_in_list *s; while ((s = *head) != NULL) { *head = s->next; @@ -2213,13 +2343,69 @@ fatalf("%s: %s", path, xstrerror()); } -void parserRegisterType(const char *typestr, PARSER_PARSE *parse, PARSER_FREE *free, PARSER_DUMP *dump) +/* dynamic parser support routines */ + +CBDATA_TYPE(parserTypeNode); +CBDATA_TYPE(parserNameNode); + +parserTypeNode * +parserTypeByName(const char *typestr) +{ + dlink_node *node; + node=parserTypes.head; + while (node && strcmp(((parserTypeNode *)node->data)->typestr,typestr)) { + node=node->next; + } + if (node) + return (parserTypeNode *)node->data; + else + return NULL; +} + +void +parserRegisterType(const char *typestr, PARSER_PARSE *parsefunc, PARSER_FREE *freefunc, PARSER_DUMP *dumpfunc) { - debug(3,0)("parserRegisterType '%s'\n",typestr); + parserTypeNode *parserType; + if ((parserType=parserTypeByName(typestr))==NULL) { + /* register the type */ + debug(3,3)("parserRegisterType new type '%s'\n",typestr); + if (parserTypes.head==NULL) + CBDATA_INIT_TYPE(parserTypeNode); + parserType=CBDATA_ALLOC(parserTypeNode,NULL); + parserType->typestr=typestr; + parserType->parsefunc=parsefunc; + parserType->freefunc=freefunc; + parserType->dumpfunc=dumpfunc; + dlinkAddTail(parserType,&parserType->node,&parserTypes); + } else { + /* confirm the pointers are the same */ + debug(3,3)("parserRegisterType already registered type '%s'\n",typestr); + if ((parserType->parsefunc!=parsefunc) || + (parserType->freefunc!=freefunc) || + (parserType->dumpfunc!=dumpfunc)) { + debug(3,0)("parserRegisterType already registered type '%s' has different function pointers!\n",typestr); + } + } } void parserDeregisterType(const char *typestr) { + debug(3,0)("parserDeregisterType '%s'\n",typestr); +} + + +parserNameNode * +parserNameByName(const char *name) +{ + dlink_node *node; + node=parserNames.head; + while (node && strcmp(((parserNameNode *)node->data)->namestr,name)) { + node=node->next; + } + if (node) + return (parserNameNode *)node->data; + else + return NULL; } /* register a new name for the config file @@ -2229,15 +2415,32 @@ * TODO: have cf_parser.c dynamically register all the config file builtin types, * ignoring errors (because they have been migrated to auto register ). */ -void parserRegisterName(const char *name, const char *type, void *location) +void parserRegisterName(const char *name, parserTypeNode *parserType, void *location) { - /* check for well known types */ - /* check for dynamically registered types */ - /* add the name to the list of names */ + parserNameNode *parserName; + if ((parserName=parserNameByName(name))==NULL) { + /* register the type */ + debug(3,3)("parserRegisterName new name '%s'\n",name); + if (parserNames.head==NULL) + CBDATA_INIT_TYPE(parserNameNode); + parserName=CBDATA_ALLOC(parserNameNode,NULL); + parserName->namestr=name; + parserName->type=parserType; + parserName->location=location; + dlinkAddTail(parserName,&parserName->node,&parserNames); +} else { + /* confirm the pointers are the same */ + debug(3,3)("parserRegisterName already registered name '%s'\n",name); + if ((parserName->type!=parserType) || + (parserName->location!=location)) { + debug(3,0)("parserRegisterName already registered name '%s' has a different type or location!\n",name); + } +} } void parserDeregisterName(const char *name) { + debug(3,0)("parserDeregisterName '%s'\n",name); } /* APPROACH two: make the cf_parser register all the types, and then register all the names @@ -2245,4 +2448,20 @@ then parse_line becomes local to cache_cf. */ - +static int +parse_line(char *buff) +{ + char *token; + parserNameNode *parserName; + debug(0,10)("parse_line: %s\n", buff); + if ((token = strtok(buff, w_space)) == NULL) + return 1; /* ignore empty lines */ + if ((parserName=parserNameByName(token))==NULL) { + /* unregistered name */ + return 0; + } else { + /* registered name */ + parserName->type->parsefunc(parserName->location); + return 1; + } +} Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf.data.pre,v retrieving revision 1.21.4.3 retrieving revision 1.21.4.4 diff -u -r1.21.4.3 -r1.21.4.4 --- squid/src/cf.data.pre 15 Feb 2001 12:25:16 -0000 1.21.4.3 +++ squid/src/cf.data.pre 20 Feb 2001 06:22:52 -0000 1.21.4.4 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.21.4.3 2001/02/15 12:25:16 rbcollins Exp $ +# $Id: cf.data.pre,v 1.21.4.4 2001/02/20 06:22:52 rbcollins Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -362,7 +362,7 @@ NAME: cache_peer_domain cache_host_domain TYPE: hostdomain DEFAULT: none -LOC: none +LOC: Config.peers DOC_START Use to limit the domains for which a neighbor cache will be queried. Usage: @@ -395,7 +395,7 @@ NAME: neighbor_type_domain TYPE: hostdomaintype DEFAULT: none -LOC: none +LOC: Config.peers DOC_START usage: neighbor_type_domain parent|sibling domain domain ... @@ -2075,7 +2075,7 @@ NAME: cache_peer_access TYPE: peer_access DEFAULT: none -LOC: none +LOC: Config.peers DOC_START Similar to 'cache_peer_domain' but provides more flexibility by using ACL elements. Index: squid/src/cf_gen.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cf_gen.c,v retrieving revision 1.7.8.1 retrieving revision 1.7.8.2 diff -u -r1.7.8.1 -r1.7.8.2 --- squid/src/cf_gen.c 19 Feb 2001 21:02:52 -0000 1.7.8.1 +++ squid/src/cf_gen.c 20 Feb 2001 06:22:52 -0000 1.7.8.2 @@ -1,6 +1,6 @@ /* - * $Id: cf_gen.c,v 1.7.8.1 2001/02/19 21:02:52 rbcollins Exp $ + * $Id: cf_gen.c,v 1.7.8.2 2001/02/20 06:22:52 rbcollins Exp $ * * DEBUG: none Generate squid.conf and cf_parser.c * AUTHOR: Max Okumoto @@ -41,8 +41,7 @@ * The output files are as follows: * cf_parser.c - this file contains, default_all() which * initializes variables with the default - * values, parse_line() that parses line from - * squid.conf, dump_config that dumps the + * values, dump_config that dumps the * current the values of the variables. * squid.conf - default configuration file given to the server * administrator. @@ -109,10 +108,13 @@ static const char WS[] = " \t"; static int gen_default(Entry *, FILE *); -static void gen_parse(Entry *, FILE *); static void gen_dump(Entry *, FILE *); static void gen_free(Entry *, FILE *); static void gen_conf(Entry *, FILE *); +static void gen_registertypes(Entry *, FILE *); +static void gen_deregistertypes(Entry *, FILE *); +static void gen_registernames(Entry *, FILE *); +static void gen_deregisternames(Entry *, FILE *); static void gen_default_if_none(Entry *, FILE *); static void @@ -326,7 +328,6 @@ * Generate parserRegisterAllNames() * Generate parserDeregisterAllNames() * Generate default_all() - * Generate parse_line() * Generate dump_config() * Generate free_all() * Generate example squid.conf file @@ -352,9 +353,12 @@ ); rc = gen_default(entries, fp); gen_default_if_none(entries, fp); - gen_parse(entries, fp); gen_dump(entries, fp); gen_free(entries, fp); + gen_registertypes(entries, fp); + gen_registernames(entries, fp); + gen_deregistertypes(entries, fp); + gen_deregisternames(entries, fp); fclose(fp); /* Open output x.conf file */ @@ -464,55 +468,6 @@ } static void -gen_parse(Entry * head, FILE * fp) -{ - Entry *entry; - - fprintf(fp, - "static int\n" - "parse_line(char *buff)\n" - "{\n" - "\tint\tresult = 1;\n" - "\tchar\t*token;\n" - "\tdebug(0,10)(\"parse_line: %%s\\n\", buff);\n" - "\tif ((token = strtok(buff, w_space)) == NULL)\n" - "\t\t(void) 0;\t/* ignore empty lines */\n" - ); - - for (entry = head; entry != NULL; entry = entry->next) { - if (strcmp(entry->name, "comment") == 0) - continue; - if (entry->ifdef) - fprintf(fp, "#if %s\n", entry->ifdef); - fprintf(fp, "\telse if (!strcmp(token, \"%s\"))\n", - entry->name - ); - assert(entry->loc); - if (strcmp(entry->loc, "none") == 0) { - fprintf(fp, - "\t\tparse_%s();\n", - entry->type - ); - } else { - fprintf(fp, - "\t\tparse_%s(&%s%s);\n", - entry->type, entry->loc, - entry->array_flag ? "[0]" : "" - ); - } - if (entry->ifdef) - fprintf(fp, "#endif\n"); - } - - fprintf(fp, - "\telse\n" - "\t\tresult = 0; /* failure */\n" - "\treturn(result);\n" - "}\n\n" - ); -} - -static void gen_dump(Entry * head, FILE * fp) { Entry *entry; @@ -529,10 +484,17 @@ continue; if (entry->ifdef) fprintf(fp, "#if %s\n", entry->ifdef); +#if old fprintf(fp, "\tdump_%s(entry, \"%s\", %s);\n", entry->type, entry->name, entry->loc); +#endif + fprintf(fp, "\tdump_%s(entry, \"%s\", &%s%s);\n", + entry->type, + entry->name, + entry->loc, + entry->array_flag ? "[0]" : ""); if (entry->ifdef) fprintf(fp, "#endif\n"); } @@ -565,6 +527,107 @@ fprintf(fp, "}\n\n"); } +static void +gen_registertypes(Entry * head, FILE * fp) +{ + Entry *entry; + fprintf(fp, + "static void\n" + "parserRegisterAllTypes(void)\n" + "{\n" + ); + for (entry = head; entry != NULL; entry = entry->next) { + assert(entry->loc); + if (strcmp(entry->name, "comment") == 0) + continue; + if (entry->ifdef) + fprintf(fp, "#if %s\n", entry->ifdef); + fprintf(fp, "\tparserRegisterType(\"%s\",parse_%s,free_%s,dump_%s);\n", + entry->type, + entry->type, + entry->type, + entry->type); + if (entry->ifdef) + fprintf(fp, "#endif\n"); + } + fprintf(fp, "}\n\n"); +} + +static void +gen_deregistertypes(Entry * head, FILE * fp) +{ + Entry *entry; + fprintf(fp, + "static void\n" + "parserDeregisterAllTypes(void)\n" + "{\n" + ); + for (entry = head; entry != NULL; entry = entry->next) { + assert(entry->loc); + if (strcmp(entry->name, "comment") == 0) + continue; + if (entry->ifdef) + fprintf(fp, "#if %s\n", entry->ifdef); + fprintf(fp, "\tparserDeregisterType(\"%s\");\n", + entry->type); + if (entry->ifdef) + fprintf(fp, "#endif\n"); + } + fprintf(fp, "}\n\n"); +} + +static void +gen_registernames(Entry * head, FILE * fp) +{ + Entry *entry; + fprintf(fp, + "static void\n" + "parserRegisterAllNames(void)\n" + "{\n" + ); + for (entry = head; entry != NULL; entry = entry->next) { + assert(entry->loc); + if (strcmp(entry->name, "comment") == 0) + continue; + if (strcmp(entry->loc, "none") == 0) { + printf("location \"none\" not valid for name %s\n", entry->name); + exit(1); + } + if (entry->ifdef) + fprintf(fp, "#if %s\n", entry->ifdef); + fprintf(fp, "\tparserRegisterName(\"%s\",parserTypeByName(\"%s\"),&%s%s);\n", + entry->name, + entry->type, + entry->loc, + entry->array_flag ? "[0]" : ""); + if (entry->ifdef) + fprintf(fp, "#endif\n"); + } + fprintf(fp, "}\n\n"); +} + +static void +gen_deregisternames(Entry * head, FILE * fp) +{ + Entry *entry; + fprintf(fp, + "static void\n" + "parserDeregisterAllNames(void)\n" + "{\n" + ); + for (entry = head; entry != NULL; entry = entry->next) { + assert(entry->loc); + if (strcmp(entry->name, "comment") == 0) + continue; + if (entry->ifdef) + fprintf(fp, "#if %s\n", entry->ifdef); + fprintf(fp, "\tparserDeregisterName(\"%s\");\n", + entry->name); + if (entry->ifdef) + fprintf(fp, "#endif\n"); + } + fprintf(fp, "}\n\n"); +} static int defined(char *name) { Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.18.4.6 retrieving revision 1.18.4.7 diff -u -r1.18.4.6 -r1.18.4.7 --- squid/src/protos.h 19 Feb 2001 21:02:52 -0000 1.18.4.6 +++ squid/src/protos.h 20 Feb 2001 06:22:52 -0000 1.18.4.7 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.18.4.6 2001/02/19 21:02:52 rbcollins Exp $ + * $Id: protos.h,v 1.18.4.7 2001/02/20 06:22:52 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -80,7 +80,7 @@ extern void wordlistAddWl(wordlist **, wordlist *); extern void wordlistJoin(wordlist **, wordlist **); extern wordlist *wordlistDup(const wordlist *); -extern void wordlistDestroy(wordlist **); +extern void wordlistDestroy(void *); extern void configFreeMemory(void); extern void wordlistCat(const wordlist *, MemBuf * mb); extern void allocate_new_swapdir(cacheSwap *); @@ -88,18 +88,18 @@ extern int GetInteger(void); /* extra functions from cache_cf.c useful for lib modules */ -extern void parse_int(int *var); -extern void parse_eol(char *volatile *var); -extern void parse_wordlist(wordlist ** list); +extern void parse_int(void *); +extern void parse_eol(void *); +extern void parse_wordlist(void *); /* was: wordlist ** list); */ extern void requirePathnameExists(const char *name, const char *path); -extern void parse_time_t(time_t * var); +extern void parse_time_t(void *); 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(const char *); /* name, type */ -extern void parserRegisterName(const char *, const char *, void *); +extern void parserRegisterName(const char *, parserTypeNode *, void *); extern void parserDeregisterName(const char *); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.24.4.5 retrieving revision 1.24.4.6 diff -u -r1.24.4.5 -r1.24.4.6 --- squid/src/structs.h 19 Feb 2001 21:02:52 -0000 1.24.4.5 +++ squid/src/structs.h 20 Feb 2001 06:22:52 -0000 1.24.4.6 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.24.4.5 2001/02/19 21:02:52 rbcollins Exp $ + * $Id: structs.h,v 1.24.4.6 2001/02/20 06:22:52 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -306,15 +306,15 @@ struct _parserTypeNode { dlink_node node; - char *typestr; - PARSER_PARSE *parse; - PARSER_FREE *free; - PARSER_DUMP *dump; + const char *typestr; + PARSER_PARSE *parsefunc; + PARSER_FREE *freefunc; + PARSER_DUMP *dumpfunc; }; struct _parserNameNode { dlink_node node; - char *namestr; + const char *namestr; parserTypeNode *type; void *location; }; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.15.4.4 retrieving revision 1.15.4.5 diff -u -r1.15.4.4 -r1.15.4.5 --- squid/src/typedefs.h 19 Feb 2001 21:02:52 -0000 1.15.4.4 +++ squid/src/typedefs.h 20 Feb 2001 06:22:52 -0000 1.15.4.5 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.15.4.4 2001/02/19 21:02:52 rbcollins Exp $ + * $Id: typedefs.h,v 1.15.4.5 2001/02/20 06:22:52 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -367,6 +367,6 @@ typedef void PARSER_PARSE(void *); typedef void PARSER_FREE (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 *); +typedef void PARSER_DUMP (StoreEntry *, const char *, void const *const); #endif /* _TYPEDEFS_H_ */