summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorGuillaume Friloux <guillaume.friloux@gmail.com>2013-12-19 16:03:43 +0100
committerGuillaume Friloux <guillaume.friloux@gmail.com>2013-12-19 16:03:43 +0100
commitceac6266f34b4c014fa5c95c467a9c382579265c (patch)
treecd5b5ba1259bbcbc7fcf76b7869b263ad74c5ef7 /src/lib
parentd380b49deef43c71de1c4353d4ab2c4c808da559 (diff)
Rules are now completly loaded.
Next step is to setup the spy library to put a watch on each log file matching the globs from rules.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/conf/conf_main.c8
-rw-r--r--src/lib/rules/rules_load.c104
-rw-r--r--src/lib/rules/rules_main.c20
-rw-r--r--src/lib/rules/rules_private.h2
4 files changed, 119 insertions, 15 deletions
diff --git a/src/lib/conf/conf_main.c b/src/lib/conf/conf_main.c
index 5de7438..c28e886 100644
--- a/src/lib/conf/conf_main.c
+++ b/src/lib/conf/conf_main.c
@@ -3,9 +3,17 @@
3static int _conf_init_count = 0; 3static int _conf_init_count = 0;
4int _conf_log_dom_global = -1; 4int _conf_log_dom_global = -1;
5 5
6const char *
7conf_file_get(Conf *conf)
8{
9 EINA_SAFETY_ON_NULL_RETURN_VAL(conf, NULL);
10 return conf->file;
11}
12
6Eina_Hash * 13Eina_Hash *
7conf_variables_get(Conf *conf) 14conf_variables_get(Conf *conf)
8{ 15{
16 EINA_SAFETY_ON_NULL_RETURN_VAL(conf, NULL);
9 return conf->variables; 17 return conf->variables;
10} 18}
11 19
diff --git a/src/lib/rules/rules_load.c b/src/lib/rules/rules_load.c
index 58daf1f..47ae3bf 100644
--- a/src/lib/rules/rules_load.c
+++ b/src/lib/rules/rules_load.c
@@ -1,5 +1,88 @@
1#include "rules_private.h" 1#include "rules_private.h"
2 2
3void
4rules_load_rule(void *data,
5 Conf *conf)
6{
7 Rules_Load *rl;
8 Rule *rule;
9 Eina_Iterator *it;
10 const char *file,
11 *s;
12
13 rl = data;
14 file = conf_file_get(conf);
15
16 DBG("Loaded rule %s", file);
17
18 s = strrchr(file, '/');
19 if (!s) s = file;
20 else s += 1;
21
22 rule = calloc(1, sizeof(Rule));
23 rule->name = strdup(s);
24
25 it = eina_hash_iterator_tuple_new(conf_variables_get(conf));
26 while (eina_iterator_next(it, &data))
27 {
28 const char *variable,
29 *value;
30 Eina_Hash_Tuple *t = data;
31
32 variable = t->key;
33 value = t->data;
34 if (!strcmp(variable, "filename"))
35 rule->spec.filename = strdup(value);
36 else if (!strcmp(variable, "tags"))
37 rule->spec.tags = strdup(value);
38 else if (!strcmp(variable, "source_host"))
39 rule->spec.source_host = strdup(value);
40 else if (!strcmp(variable, "source_path"))
41 rule->spec.source_path = strdup(value);
42 else if (!strcmp(variable, "todel"))
43 rule->spec.todel = !!atoi(value);
44
45 else if (!strncmp(variable, "message", 7))
46 {
47 Rule_Regex *rr;
48 int r;
49
50 rr = calloc(1, sizeof(Rule_Regex));
51 rule->spec.regex = eina_inlist_append(rule->spec.regex,
52 EINA_INLIST_GET(rr));
53
54 r = regcomp(&(rr->preg), value, REG_EXTENDED);
55 if (r)
56 {
57 ERR("Failed to compile regex \"%s\", dropping rule.", value);
58 eina_iterator_free(it);
59 rules_rule_free(rule);
60 return;
61 }
62 rr->regex = strdup(value);
63
64 if (!strstr(variable + 7, "unmatch"))
65 rr->must_match = EINA_TRUE;
66 }
67 }
68 eina_iterator_free(it);
69 rl->cb.progress((void *)rl->cb.data, rl->rules, rule);
70}
71
72void
73rules_load_rule_error(void *data,
74 Conf *conf,
75 const char *errstr)
76{
77 Rules_Load *rl;
78
79 rl = data;
80
81 DBG("Failed to load rule %s", conf_file_get(conf));
82 rl->cb.error((void *)rl->cb.data, rl->rules, errstr);
83 free(rl);
84}
85
3Eina_Bool 86Eina_Bool
4rules_load_ls_filter(void *data EINA_UNUSED, 87rules_load_ls_filter(void *data EINA_UNUSED,
5 Eio_File *handler EINA_UNUSED, 88 Eio_File *handler EINA_UNUSED,
@@ -16,31 +99,22 @@ rules_load_ls(void *data,
16 const Eina_File_Direct_Info *info) 99 const Eina_File_Direct_Info *info)
17{ 100{
18 Rules_Load *rl; 101 Rules_Load *rl;
19 Rule *rule;
20
21 DBG("Rule file : %s", info->path + info->name_start);
22 102
23 rl = data; 103 rl = data;
104 DBG("rl[%p] Rule file : %s", rl, info->path + info->name_start);
24 105
25 /* We load file */ 106 /* We load file */
26 107 conf_load((char *)info->path,
27 /* If file is OK, we register it */ 108 rules_load_rule,
28 rule = calloc(1, sizeof(Rule)); 109 rules_load_rule_error,
29 rule->name = strdup(info->path + info->name_start); 110 rl);
30
31 rl->cb.progress((void *)rl->cb.data, rl->rules, rule);
32} 111}
33 112
34void 113void
35rules_load_ls_done(void *data, 114rules_load_ls_done(void *data EINA_UNUSED,
36 Eio_File *handler EINA_UNUSED) 115 Eio_File *handler EINA_UNUSED)
37{ 116{
38 Rules_Load *rl;
39
40 DBG("End of rules listing."); 117 DBG("End of rules listing.");
41 rl = data;
42 rl->cb.done((void *)rl->cb.data, rl->rules);
43 free(rl);
44} 118}
45 119
46 120
diff --git a/src/lib/rules/rules_main.c b/src/lib/rules/rules_main.c
index 3ea4746..e1f73a8 100644
--- a/src/lib/rules/rules_main.c
+++ b/src/lib/rules/rules_main.c
@@ -3,6 +3,26 @@
3static int _rules_init_count = 0; 3static int _rules_init_count = 0;
4int _rules_log_dom_global = -1; 4int _rules_log_dom_global = -1;
5 5
6
7void
8rules_rule_free(Rule *rule)
9{
10 Rule_Regex *rr;
11 EINA_SAFETY_ON_NULL_RETURN(rule);
12
13 free((char *)rule->name);
14 free((char *)rule->spec.filename);
15 free((char *)rule->spec.source_host);
16 free((char *)rule->spec.source_path);
17 free((char *)rule->spec.tags);
18
19 EINA_INLIST_FOREACH(rule->spec.regex, rr)
20 {
21 free((char *)rr->regex);
22 free(rr);
23 }
24}
25
6Rules * 26Rules *
7rules_new(const char *directory) 27rules_new(const char *directory)
8{ 28{
diff --git a/src/lib/rules/rules_private.h b/src/lib/rules/rules_private.h
index 1d74d95..f20293e 100644
--- a/src/lib/rules/rules_private.h
+++ b/src/lib/rules/rules_private.h
@@ -27,6 +27,8 @@ typedef struct _Rules_Load
27 } cb; 27 } cb;
28} Rules_Load; 28} Rules_Load;
29 29
30void rules_rule_free(Rule *rule);
31
30Eina_Bool rules_load_ls_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *info); 32Eina_Bool rules_load_ls_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *info);
31void rules_load_ls(void *data, Eio_File *handler, const Eina_File_Direct_Info *info); 33void rules_load_ls(void *data, Eio_File *handler, const Eina_File_Direct_Info *info);
32void rules_load_ls_done(void *data, Eio_File *handler); 34void rules_load_ls_done(void *data, Eio_File *handler);