FreeCalypso > hg > themwi-rtp-mgr
annotate rtp-mgr/readconf.c @ 10:9499d41fc393 default tip
daemon: change config file name to themwi-rtp-mgr.cfg
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 27 May 2024 22:47:19 +0000 |
parents | 247f4bbde24c |
children |
rev | line source |
---|---|
2
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement the reading of /var/gsm/themwi-rtp.cfg: |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * we parse and save the configured IP address and port range for each |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * of our two sides, GSM and PSTN. |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/socket.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <sys/time.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <netinet/in.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <arpa/inet.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <ctype.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdio.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <stdint.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <stdlib.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <string.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <strings.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include <syslog.h> |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include "struct.h" |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 struct bind_range_cfg bind_range_gsm, bind_range_pstn; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int syslog_facility = LOG_USER; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
10
9499d41fc393
daemon: change config file name to themwi-rtp-mgr.cfg
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
24 static const char config_file_pathname[] = "/var/gsm/themwi-rtp-mgr.cfg"; |
2
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 struct parse_state { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 int lineno; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int set_mask; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 }; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 static void |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 handle_bind_ip(st, kw, brc, line) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 struct parse_state *st; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 char *kw, *line; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 struct bind_range_cfg *brc; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 char *cp, *np; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 for (cp = line; isspace(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (*cp == '\0' || *cp == '#') { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 inv_syntax: fprintf(stderr, |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 "%s line %d: %s setting requires one argument\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 config_file_pathname, st->lineno, kw); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 for (np = cp; *cp && !isspace(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (*cp) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 *cp++ = '\0'; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 while (isspace(*cp)) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 cp++; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (*cp != '\0' && *cp != '#') |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 goto inv_syntax; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 brc->bind_ip.s_addr = inet_addr(np); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (brc->bind_ip.s_addr == INADDR_NONE) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 fprintf(stderr, |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 "%s line %d: invalid IP address argument \"%s\"\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 config_file_pathname, st->lineno, np); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 static void |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 handle_port_range(st, kw, brc, line) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 struct parse_state *st; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 char *kw, *line; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 struct bind_range_cfg *brc; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 char *cp, *np1, *np2; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 for (cp = line; isspace(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (!isdigit(*cp)) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 inv_syntax: fprintf(stderr, |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 "%s line %d: %s setting requires two numeric arguments\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 config_file_pathname, st->lineno, kw); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 for (np1 = cp; isdigit(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (!isspace(*cp)) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 goto inv_syntax; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 while (isspace(*cp)) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 cp++; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 if (!isdigit(*cp)) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 goto inv_syntax; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 for (np2 = cp; isdigit(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (*cp && !isspace(*cp)) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 goto inv_syntax; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 while (isspace(*cp)) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 cp++; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 if (*cp != '\0' && *cp != '#') |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 goto inv_syntax; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 brc->port_range_start = atoi(np1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 brc->port_range_end = atoi(np2); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (brc->port_range_start & 1) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 fprintf(stderr, "%s line %d: start port must be even\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 config_file_pathname, st->lineno); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 if (!(brc->port_range_end & 1)) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 fprintf(stderr, "%s line %d: end port must be odd\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 config_file_pathname, st->lineno); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 if (brc->port_range_end <= brc->port_range_start) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 fprintf(stderr, |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 "%s line %d: end port must be greater than start port\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 config_file_pathname, st->lineno); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 brc->port_next = brc->port_range_start; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 brc->port_tries = (brc->port_range_end - brc->port_range_start + 1) / 2; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 static void |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 handle_syslog_facility(st, kw, dummy_ptr, line) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 struct parse_state *st; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 char *kw, *line; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 void *dummy_ptr; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 char *cp, *np; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 for (cp = line; isspace(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (*cp == '\0' || *cp == '#') { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 inv_syntax: fprintf(stderr, |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 "%s line %d: %s setting requires one argument\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 config_file_pathname, st->lineno, kw); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 for (np = cp; *cp && !isspace(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (*cp) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 *cp++ = '\0'; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 while (isspace(*cp)) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 cp++; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 if (*cp != '\0' && *cp != '#') |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 goto inv_syntax; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 if (!strcmp(np, "authpriv")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 syslog_facility = LOG_AUTHPRIV; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 else if (!strcmp(np, "cron")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 syslog_facility = LOG_CRON; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 else if (!strcmp(np, "daemon")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 syslog_facility = LOG_DAEMON; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 else if (!strcmp(np, "ftp")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 syslog_facility = LOG_FTP; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 else if (!strcmp(np, "lpr")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 syslog_facility = LOG_LPR; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 else if (!strcmp(np, "mail")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 syslog_facility = LOG_MAIL; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 else if (!strcmp(np, "news")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 syslog_facility = LOG_NEWS; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 else if (!strcmp(np, "user")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 syslog_facility = LOG_USER; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 else if (!strcmp(np, "uucp")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 syslog_facility = LOG_UUCP; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 else if (!strcmp(np, "local0")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 syslog_facility = LOG_LOCAL0; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 else if (!strcmp(np, "local1")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 syslog_facility = LOG_LOCAL1; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 else if (!strcmp(np, "local2")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 syslog_facility = LOG_LOCAL2; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 else if (!strcmp(np, "local3")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 syslog_facility = LOG_LOCAL3; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 else if (!strcmp(np, "local4")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 syslog_facility = LOG_LOCAL4; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 else if (!strcmp(np, "local5")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 syslog_facility = LOG_LOCAL5; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 else if (!strcmp(np, "local6")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 syslog_facility = LOG_LOCAL6; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 else if (!strcmp(np, "local7")) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 syslog_facility = LOG_LOCAL7; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 else { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 fprintf(stderr, |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 "%s line %d: \"%s\" is not a recognized syslog facility\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 config_file_pathname, st->lineno, np); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 static void |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 process_line(st, line) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 struct parse_state *st; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 char *line; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 char *cp, *np; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 void (*handler)(); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 struct bind_range_cfg *ipside; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 int set_id; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 if (!index(line, '\n')) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 fprintf(stderr, "%s line %d: too long or missing newline\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 config_file_pathname, st->lineno); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 for (cp = line; isspace(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 if (*cp == '\0' || *cp == '#') |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 return; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 for (np = cp; *cp && !isspace(*cp); cp++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 ; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 if (*cp) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 *cp++ = '\0'; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 if (!strcmp(np, "gsm-ip-addr")) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 handler = handle_bind_ip; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 ipside = &bind_range_gsm; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 set_id = 1; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 } else if (!strcmp(np, "gsm-port-range")) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 handler = handle_port_range; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 ipside = &bind_range_gsm; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 set_id = 2; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 } else if (!strcmp(np, "pstn-ip-addr")) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 handler = handle_bind_ip; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 ipside = &bind_range_pstn; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 set_id = 4; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 } else if (!strcmp(np, "pstn-port-range")) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 handler = handle_port_range; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 ipside = &bind_range_pstn; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 set_id = 8; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 } else if (!strcmp(np, "syslog-facility")) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 handler = handle_syslog_facility; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 ipside = NULL; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 set_id = 0; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 } else { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 fprintf(stderr, "%s line %d: non-understood keyword \"%s\"\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 config_file_pathname, st->lineno, np); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 if (st->set_mask & set_id) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 fprintf(stderr, "%s line %d: duplicate %s setting\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 config_file_pathname, st->lineno, np); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 handler(st, np, ipside, cp); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 st->set_mask |= set_id; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 read_config_file() |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 FILE *inf; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 struct parse_state pst; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 char linebuf[256]; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 inf = fopen(config_file_pathname, "r"); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 if (!inf) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 perror(config_file_pathname); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 pst.set_mask = 0; |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 for (pst.lineno = 1; fgets(linebuf, sizeof linebuf, inf); pst.lineno++) |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 process_line(&pst, linebuf); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 fclose(inf); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 if (pst.set_mask != 15) { |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 fprintf(stderr, "error: %s did not set all required settings\n", |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 config_file_pathname); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 exit(1); |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 } |
247f4bbde24c
rtp-mgr: daemon ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 } |