summaryrefslogtreecommitdiffstats
path: root/cfg_utils.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2008-06-24 17:50:29 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2008-06-24 17:50:29 +0400
commitbcf147f18f4370d061aff7890873aeed10542663 (patch)
treec869bbbb8a227ab1956d9436a7d93a9bce1a4bc9 /cfg_utils.c
parentdaca72b007e666fb9abebcfa7c27ed6ddcadfd58 (diff)
downloadrspamd-bcf147f18f4370d061aff7890873aeed10542663.tar.gz
rspamd-bcf147f18f4370d061aff7890873aeed10542663.zip
* Add initial support of perl filters
Diffstat (limited to 'cfg_utils.c')
-rw-r--r--cfg_utils.c75
1 files changed, 63 insertions, 12 deletions
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <libmilter/mfapi.h>
-#include <sys/queue.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <syslog.h>
#include <netdb.h>
#include <math.h>
+#include <sys/types.h>
+#ifndef OWN_QUEUE_H
+#include <sys/queue.h>
+#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;
}
/*