Imported Upstream version 2.5.1
[ossec-hids.git] / src / config / dbd-config.c
1 /* @(#) $Id$ */
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 dbd configuration files
13  */
14
15
16 #include "shared.h"
17 #include "dbd-config.h"
18
19
20 int Read_DB(XML_NODE node, void *config1, void *config2)
21 {
22     int i = 0;
23     DBConfig *db_config;
24
25
26     /* XML definitions */
27     char *xml_dbhost = "hostname";
28     char *xml_dbuser = "username";
29     char *xml_dbpass = "password";
30     char *xml_dbdb = "database";
31     char *xml_dbport = "port";
32     char *xml_dbsock = "socket";
33     char *xml_dbtype = "type";
34
35     
36     db_config = (DBConfig *)config2;
37     if(!db_config)
38     {
39         return(0);
40     }
41
42
43     /* Reading the xml */ 
44     while(node[i])
45     {
46         if(!node[i]->element)
47         {
48             merror(XML_ELEMNULL, ARGV0);
49             return(OS_INVALID);
50         }
51         else if(!node[i]->content)
52         {
53             merror(XML_VALUENULL, ARGV0, node[i]->element);
54             return(OS_INVALID);
55         }
56         /* Mail notification */
57         else if(strcmp(node[i]->element, xml_dbhost) == 0)
58         {
59             os_strdup(node[i]->content, db_config->host);
60         }
61         else if(strcmp(node[i]->element, xml_dbuser) == 0)
62         {
63             os_strdup(node[i]->content, db_config->user);
64         }
65         else if(strcmp(node[i]->element, xml_dbpass) == 0)
66         {
67             os_strdup(node[i]->content, db_config->pass);
68         }
69         else if(strcmp(node[i]->element, xml_dbdb) == 0)
70         {
71             os_strdup(node[i]->content, db_config->db);
72         }
73         else if(strcmp(node[i]->element, xml_dbport) == 0)
74         {
75             db_config->port = atoi(node[i]->content);
76         }
77         else if(strcmp(node[i]->element, xml_dbsock) == 0)
78         {
79             os_strdup(node[i]->content, db_config->sock);
80         }
81         else if(strcmp(node[i]->element, xml_dbtype) == 0)
82         {
83             if(strcmp(node[i]->content, "mysql") == 0)
84             {
85                 db_config->db_type = MYSQLDB;
86             }
87             else if(strcmp(node[i]->content, "postgresql") == 0)
88             {
89                 db_config->db_type = POSTGDB;
90             }
91             else
92             {
93                 merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content);
94                 return(OS_INVALID);
95             }
96         }
97         else
98         {
99             merror(XML_INVELEM, ARGV0, node[i]->element);
100             return(OS_INVALID);
101         }
102         i++;
103     }
104
105
106     return(0);
107 }
108
109
110 /* EOF */