85efc9504c3baeb597cf901e0c25352c8607a43e
[ossec-hids.git] / src / config / alerts-config.c
1 /*   $OSSEC, alerts-config.c, v0.1, 2005/04/02, Daniel B. Cid$   */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation
10  */
11
12 /* Functions to handle the configuration files
13  */
14
15
16 #include "shared.h"
17 #include "global-config.h"
18
19
20 int Read_Alerts(XML_NODE node, void *configp, void *mailp)
21 {
22     int i = 0;
23
24     /* XML definitions */
25     char *xml_email_level = "email_alert_level";
26     char *xml_log_level = "log_alert_level";
27
28     _Config *Config;
29      
30     Config = (_Config *)configp;
31      
32
33     while(node[i])
34     {
35         if(!node[i]->element)
36         {
37             merror(XML_ELEMNULL, ARGV0);
38             return(OS_INVALID);
39         }
40         else if(!node[i]->content)
41         {
42             merror(XML_VALUENULL, ARGV0, node[i]->element);
43             return(OS_INVALID);
44         }
45         /* Mail notification */
46         else if(strcmp(node[i]->element, xml_email_level) == 0)
47         {
48             if(!OS_StrIsNum(node[i]->content))
49             {
50                 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
51                 return(OS_INVALID);
52             }
53
54             Config->mailbylevel = atoi(node[i]->content);
55         }
56         /* Log alerts */
57         else if(strcmp(node[i]->element, xml_log_level) == 0)
58         {
59             if(!OS_StrIsNum(node[i]->content))
60             {
61                 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
62                 return(OS_INVALID);
63             }
64             Config->logbylevel  = atoi(node[i]->content);
65         }
66         else
67         {
68             merror(XML_INVELEM, ARGV0, node[i]->element);
69             return(OS_INVALID);
70         }
71         i++;
72     }
73     return(0);
74 }
75
76
77 /* EOF */