author | viric@llimona |
Fri, 16 Jun 2006 18:45:24 +0200 | |
changeset 62 | 39bf7ecd7b21 |
parent 57 | de776a4548da |
permissions | -rw-r--r-- |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
1 |
#include <string.h> |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
2 |
#include <stdio.h> |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
3 |
#include <sys/types.h> |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
4 |
#include <sys/stat.h> |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
5 |
#include <fcntl.h> |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
6 |
#include <unistd.h> |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
7 |
#include <assert.h> |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
8 |
#include <errno.h> |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
9 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
10 |
#include "syslog.h" |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
11 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
12 |
#define CONFIG_FILE "syslog.conf" |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
13 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
14 |
/* Data structures */ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
15 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
16 |
static struct |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
17 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
18 |
int n; /* Number of config elements */ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
19 |
struct config_element el[ETYPE_END]; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
20 |
} main_config; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
21 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
22 |
/* Aquesta variable ha de reflexar l'ordre de la enum etype_config de syslog.h*/ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
23 |
const static struct config_element default_config[ETYPE_END+1] = { |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
24 |
{ FROM_UNIX, "unixlog" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
25 |
{ FROM_NPIPE, "disabled" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
26 |
{ FROM_UDP, "disabled" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
27 |
{ TO_UDP_HOST, "localhost" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
28 |
{ TO_UDP_PORT, "1235" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
29 |
{ TCP_MANAGER, "1234" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
30 |
{ LOG_FILE, "file.log" }, |
57
de776a4548da
Added the check for a pid file (syslog.pid by default).
viric@llimona
parents:
44
diff
changeset
|
31 |
{ PID_FILE, "syslog.pid" }, |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
32 |
{ ETYPE_END, "" }}; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
33 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
34 |
/* Aquesta variable ha de reflexar l'ordre de la enum etype_config de syslog.h*/ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
35 |
const static struct { |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
36 |
enum etype_config type; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
37 |
char string[MAX_STRING]; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
38 |
} etype_string[ETYPE_END+1] = { |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
39 |
{ FROM_UNIX, "from_unix" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
40 |
{ FROM_NPIPE, "from_npipe" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
41 |
{ FROM_UDP, "from_udp" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
42 |
{ TO_UDP_HOST, "to_udp_host" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
43 |
{ TO_UDP_PORT, "to_udp_port" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
44 |
{ TCP_MANAGER, "tcp_manager" }, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
45 |
{ LOG_FILE, "log_file" }, |
57
de776a4548da
Added the check for a pid file (syslog.pid by default).
viric@llimona
parents:
44
diff
changeset
|
46 |
{ PID_FILE, "pid_file" }, |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
47 |
{ ETYPE_END, "" }}; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
48 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
49 |
/* Prototypes */ |
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
50 |
static int add_config_element(const char * restrict p, const char * restrict v, |
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
51 |
const int max); |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
52 |
static void read_config(char * restrict fname); |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
53 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
54 |
/* Functions' code */ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
55 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
56 |
void init_config() |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
57 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
58 |
main_config.n = 0; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
59 |
read_config(CONFIG_FILE); |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
60 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
61 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
62 |
static void read_config(char * restrict fname) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
63 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
64 |
int file; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
65 |
char rchar; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
66 |
int res; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
67 |
char parameter[MAX_STRING]; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
68 |
int nparameter; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
69 |
char value[MAX_STRING]; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
70 |
int nvalue; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
71 |
enum { |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
72 |
READ_PARAMETER, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
73 |
READ_VALUE |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
74 |
} state; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
75 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
76 |
file = open(fname, O_RDONLY); |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
77 |
if (file == -1) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
78 |
{ |
44 | 79 |
fprintf(stderr,"The config file cannot be opened.\n"); |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
80 |
return; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
81 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
82 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
83 |
nparameter=0; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
84 |
state=READ_PARAMETER; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
85 |
while ((res = read(file, &rchar, 1)) == 1) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
86 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
87 |
switch (rchar) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
88 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
89 |
case '=': |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
90 |
assert(nparameter <= MAX_STRING); |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
91 |
parameter[nparameter]='\0'; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
92 |
nvalue=0; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
93 |
state=READ_VALUE; |
24 | 94 |
break; |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
95 |
case '\n': |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
96 |
if (state == READ_VALUE) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
97 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
98 |
value[nvalue]='\0'; |
24 | 99 |
assert( add_config_element(parameter, |
100 |
value, MAX_STRING)>=0); |
|
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
101 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
102 |
nparameter=0; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
103 |
nvalue=0; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
104 |
state=READ_PARAMETER; |
24 | 105 |
break; |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
106 |
default: |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
107 |
switch(state) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
108 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
109 |
case READ_PARAMETER: |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
110 |
assert(nparameter <= MAX_STRING); |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
111 |
parameter[nparameter++]=rchar; |
24 | 112 |
break; |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
113 |
case READ_VALUE: |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
114 |
assert(nvalue <= MAX_STRING); |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
115 |
value[nvalue++]=rchar; |
24 | 116 |
break; |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
117 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
118 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
119 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
120 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
121 |
if (res == -1) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
122 |
{ |
44 | 123 |
fprintf(stderr, "Error reading config file: %s\n", |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
124 |
strerror(errno)); |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
125 |
} |
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
126 |
|
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
127 |
close(file); |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
128 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
129 |
|
24 | 130 |
/* Retorna el tipus si ha pogut afegir l'element, -1 si hi ha hagut error */ |
131 |
static int add_config_element(const char * restrict p, const char * restrict v, |
|
132 |
const int max) |
|
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
133 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
134 |
enum etype_config i, type; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
135 |
int j, pos; |
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
136 |
int my_max; |
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
137 |
|
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
138 |
my_max = max; |
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
139 |
if (my_max > MAX_STRING) |
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
140 |
my_max = MAX_STRING; |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
141 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
142 |
/* busquem de quin paràmetre es tracta */ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
143 |
for(i=0; i<ETYPE_END; i++) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
144 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
145 |
/* a etype_string corresponen índex amb tipus */ |
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
146 |
|
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
147 |
if (strncmp(p,etype_string[i].string, my_max) == 0) |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
148 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
149 |
type=i; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
150 |
break; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
151 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
152 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
153 |
if (i==ETYPE_END) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
154 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
155 |
/* Si el paràmetre no és conegut... */ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
156 |
return -1; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
157 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
158 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
159 |
/* Busquem si el paràmetre ja està a la configuració main_config */ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
160 |
for (j=0; j<main_config.n; j++) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
161 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
162 |
if(main_config.el[j].type == type) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
163 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
164 |
pos = j; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
165 |
break; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
166 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
167 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
168 |
if(j == main_config.n) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
169 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
170 |
pos = j; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
171 |
main_config.n++; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
172 |
/* At maximum, there should be ETYPE_END elements) */ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
173 |
assert(main_config.n <= ETYPE_END); |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
174 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
175 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
176 |
main_config.el[pos].type = type; |
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
177 |
strncpy(main_config.el[pos].value, v, MAX_STRING); |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
178 |
|
24 | 179 |
return type; |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
180 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
181 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
182 |
/* Returns 2 on configured type, 1 on default value, 0 on disabled, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
183 |
* -1 on error */ |
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
184 |
int get_config(const enum etype_config type, char * restrict v, const int max) |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
185 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
186 |
int j; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
187 |
enum { |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
188 |
DISABLED=0, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
189 |
DEFAULT=1, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
190 |
CONFIGURED=2, |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
191 |
ERROR=-1 |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
192 |
} ret; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
193 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
194 |
if (type < 0 || type >= ETYPE_END) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
195 |
return ERROR; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
196 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
197 |
for (j=0; j<main_config.n; j++) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
198 |
{ |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
199 |
if(main_config.el[j].type == type) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
200 |
{ |
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
201 |
strncpy(v, main_config.el[j].value, max); |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
202 |
ret = CONFIGURED; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
203 |
break; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
204 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
205 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
206 |
|
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
207 |
if(j == main_config.n) |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
208 |
{ |
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
209 |
strncpy(v, default_config[type].value, max); |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
210 |
ret = DEFAULT; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
211 |
} |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
212 |
|
23
3e2a39def0db
Added use of strncmp, strncpy instead of the non-limited ones.
viric@mandarina
parents:
21
diff
changeset
|
213 |
if(strncmp(v, "disabled", max) == 0) |
21
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
214 |
return DISABLED; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
215 |
else |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
216 |
return ret; |
24714adbc325
Implemented the configuration file for starting the services.
viric@mandarina
parents:
diff
changeset
|
217 |
} |