From bcf147f18f4370d061aff7890873aeed10542663 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 24 Jun 2008 17:50:29 +0400 Subject: * Add initial support of perl filters --- cfg_utils.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 12 deletions(-) (limited to 'cfg_utils.c') diff --git a/cfg_utils.c b/cfg_utils.c index 277a8d8e6..afaa6a262 100644 --- a/cfg_utils.c +++ b/cfg_utils.c @@ -4,14 +4,18 @@ #include #include #include -#include -#include #include #include #include #include #include #include +#include +#ifndef OWN_QUEUE_H +#include +#else +#include "queue.h" +#endif #include "cfg_file.h" #include "memcached.h" @@ -19,13 +23,12 @@ extern int yylineno; extern char *yytext; - int add_memcached_server (struct config_file *cf, char *str) { char *cur_tok, *err_str; struct memcached_server *mc; - struct hostent *he; + struct hostent *hent; uint16_t port; if (str == NULL) return 0; @@ -53,12 +56,12 @@ add_memcached_server (struct config_file *cf, char *str) if (!inet_aton (cur_tok, &mc->addr)) { /* Try to call gethostbyname */ - he = gethostbyname (cur_tok); - if (he == NULL) { + hent = gethostbyname (cur_tok); + if (hent == NULL) { return 0; } else { - memcpy((char *)&mc->addr, he->h_addr, sizeof(struct in_addr)); + memcpy((char *)&mc->addr, hent->h_addr, sizeof(struct in_addr)); } } mc->port = port; @@ -70,11 +73,10 @@ int parse_bind_line (struct config_file *cf, char *str) { char *cur_tok, *err_str; - struct hostent *he; + struct hostent *hent; size_t s; if (str == NULL) return 0; - cur_tok = strsep (&str, ":"); if (cur_tok[0] == '/' || cur_tok[0] == '.') { @@ -95,13 +97,13 @@ parse_bind_line (struct config_file *cf, char *str) if (!inet_aton (cur_tok, &cf->bind_addr)) { /* Try to call gethostbyname */ - he = gethostbyname (cur_tok); - if (he == NULL) { + hent = gethostbyname (cur_tok); + if (hent == NULL) { return 0; } else { cf->bind_host = strdup (cur_tok); - memcpy((char *)&cf->bind_addr, he->h_addr, sizeof(struct in_addr)); + memcpy((char *)&cf->bind_addr, hent->h_addr, sizeof(struct in_addr)); s = strlen (cur_tok) + 1; } } @@ -123,11 +125,18 @@ init_defaults (struct config_file *cfg) cfg->memcached_protocol = TCP_TEXT; cfg->workers_number = DEFAULT_WORKERS_NUM; + + LIST_INIT (&cfg->filters); + LIST_INIT (&cfg->modules); } void free_config (struct config_file *cfg) { + struct filter_chain *chain, *tmp_chain; + struct script_param *param, *tmp_param; + struct perl_module *module, *tmp_module; + if (cfg->pid_file) { g_free (cfg->pid_file); } @@ -137,6 +146,48 @@ free_config (struct config_file *cfg) if (cfg->bind_host) { g_free (cfg->bind_host); } + + LIST_FOREACH_SAFE (chain, &cfg->filters, next, tmp_chain) { + LIST_FOREACH_SAFE (param, chain->scripts, next, tmp_param) { + if (param->symbol) { + g_free (param->symbol); + } + if (param->function) { + g_free (param->function); + } + LIST_REMOVE (param, next); + free (param); + } + LIST_REMOVE (chain, next); + free (chain); + } + LIST_FOREACH_SAFE (module, &cfg->modules, next, tmp_module) { + if (module->path) { + g_free (module->path); + } + LIST_REMOVE (module, next); + free (module); + } + +} + +int +parse_script (char *str, struct script_param *param, enum script_type type) +{ + char *cur_tok; + + bzero (param, sizeof (struct script_param)); + param->type = type; + + /* symbol:path:function -> cur_tok - symbol, str -> function */ + cur_tok = strsep (&str, ":"); + + if (str == NULL || cur_tok == NULL || *cur_tok == '\0') return -1; + + param->symbol = strdup (cur_tok); + param->function = strdup (str); + + return 0; } /* -- cgit v1.2.3