annotate sip-in/readconf.c @ 91:fd23e2747b45

sip-in: add sip-udp-retrans configuration setting
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 23 Sep 2022 19:05:08 -0800
parents 736c2d68595f
children a9137bdb6047
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement the reading of /var/gsm/themwi-sip-in.cfg:
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * the main settings are bind-ip and bind-port, but we also have some
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * optional config settings.
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/socket.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <netinet/in.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <arpa/inet.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <ctype.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdio.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <string.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <strings.h>
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 struct in_addr sip_bind_ip;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned sip_bind_port;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int cfg_use_100rel;
68
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
20 unsigned cfg_retrans_timeout = 500;
709b78a4ebf0 sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
21 unsigned cfg_retrans_count = 10;
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static char config_file_pathname[] = "/var/gsm/themwi-sip-in.cfg";
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct parse_state {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 int lineno;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 int set_mask;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 };
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static void
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
31 require_one_arg(st, kw, arg)
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
32 struct parse_state *st;
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
33 char *kw, *arg;
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
34 {
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
35 char *cp;
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
36
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
37 if (*arg == '\0' || *arg == '#') {
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
38 inv_syntax: fprintf(stderr,
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
39 "%s line %d: %s setting requires one argument\n",
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
40 config_file_pathname, st->lineno, kw);
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
41 exit(1);
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
42 }
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
43 for (cp = arg; *cp && !isspace(*cp); cp++)
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
44 ;
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
45 if (*cp)
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
46 *cp++ = '\0';
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
47 while (isspace(*cp))
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
48 cp++;
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
49 if (*cp != '\0' && *cp != '#')
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
50 goto inv_syntax;
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
51 }
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
52
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
53 static void
90
736c2d68595f sip-in/readconf.c: second step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
54 handle_ip(st, kw, arg, var)
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 struct parse_state *st;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 char *kw, *arg;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 struct in_addr *var;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
59 require_one_arg(st, kw, arg);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 var->s_addr = inet_addr(arg);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (var->s_addr == INADDR_NONE) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 fprintf(stderr,
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 "%s line %d: invalid IP address argument \"%s\"\n",
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 config_file_pathname, st->lineno, arg);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 exit(1);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 static void
90
736c2d68595f sip-in/readconf.c: second step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
70 handle_num(st, kw, arg, var)
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 struct parse_state *st;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 char *kw, *arg;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 unsigned *var;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 char *endp;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
77 require_one_arg(st, kw, arg);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 *var = strtoul(arg, &endp, 10);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (*endp) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fprintf(stderr, "%s line %d: invalid numeric argument \"%s\"\n",
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 config_file_pathname, st->lineno, arg);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 exit(1);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 static void
90
736c2d68595f sip-in/readconf.c: second step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
87 handle_bool(st, kw, arg, var)
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 struct parse_state *st;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 char *kw, *arg;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 int *var;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
92 require_one_arg(st, kw, arg);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (!strcmp(arg, "true") || !strcmp(arg, "on") || !strcmp(arg, "yes")
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 || !strcmp(arg, "1")) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 *var = 1;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 return;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (!strcmp(arg, "false") || !strcmp(arg, "off") || !strcmp(arg, "no")
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 || !strcmp(arg, "0")) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 *var = 0;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 return;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 fprintf(stderr, "%s line %d: invalid boolean argument \"%s\"\n",
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 config_file_pathname, st->lineno, arg);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 exit(1);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 static void
91
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
109 handle_retrans_conf(st, kw, arg)
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
110 struct parse_state *st;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
111 char *kw, *arg;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
112 {
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
113 char *cp = arg;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
114
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
115 if (!isdigit(*cp)) {
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
116 inv: fprintf(stderr,
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
117 "%s line %d: %s setting requires two numeric arguments\n",
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
118 config_file_pathname, st->lineno, kw);
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
119 exit(1);
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
120 }
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
121 cfg_retrans_timeout = strtoul(cp, &cp, 10);
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
122 while (isspace(*cp))
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
123 cp++;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
124 if (!isdigit(*cp))
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
125 goto inv;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
126 cfg_retrans_count = strtoul(cp, &cp, 10);
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
127 while (isspace(*cp))
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
128 cp++;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
129 if (*cp != '\0' && *cp != '#')
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
130 goto inv;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
131 }
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
132
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
133 static void
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 process_line(st, line)
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 struct parse_state *st;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 char *line;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 {
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
138 char *cp, *kw;
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 void (*handler)(), *var;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 int set_id;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (!index(line, '\n')) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 fprintf(stderr, "%s line %d: too long or missing newline\n",
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 config_file_pathname, st->lineno);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 exit(1);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 for (cp = line; isspace(*cp); cp++)
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 ;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 if (*cp == '\0' || *cp == '#')
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 return;
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
151 for (kw = cp; *cp && !isspace(*cp); cp++)
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 ;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 if (*cp)
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 *cp++ = '\0';
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
155 if (!strcmp(kw, "bind-ip")) {
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 handler = handle_ip;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 var = &sip_bind_ip;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 set_id = 1;
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
159 } else if (!strcmp(kw, "bind-port")) {
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 handler = handle_num;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 var = &sip_bind_port;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 set_id = 2;
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
163 } else if (!strcmp(kw, "use-100rel")) {
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 handler = handle_bool;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 var = &cfg_use_100rel;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 set_id = 0;
91
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
167 } else if (!strcmp(kw, "sip-udp-retrans")) {
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
168 handler = handle_retrans_conf;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
169 var = (void *) 0;
fd23e2747b45 sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents: 90
diff changeset
170 set_id = 0;
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 } else {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 fprintf(stderr, "%s line %d: non-understood keyword \"%s\"\n",
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
173 config_file_pathname, st->lineno, kw);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 exit(1);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 if (st->set_mask & set_id) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 fprintf(stderr, "%s line %d: duplicate %s setting\n",
89
e64d4d44025d sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 68
diff changeset
178 config_file_pathname, st->lineno, kw);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 exit(1);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 while (isspace(*cp))
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 cp++;
90
736c2d68595f sip-in/readconf.c: second step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
183 handler(st, kw, cp, var);
47
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 st->set_mask |= set_id;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 read_config_file()
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 FILE *inf;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 struct parse_state pst;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 char linebuf[256];
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 inf = fopen(config_file_pathname, "r");
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 if (!inf) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 perror(config_file_pathname);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 exit(1);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 pst.set_mask = 0;
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 for (pst.lineno = 1; fgets(linebuf, sizeof linebuf, inf); pst.lineno++)
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 process_line(&pst, linebuf);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 fclose(inf);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 if (pst.set_mask != 3) {
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 fprintf(stderr, "error: %s did not set all required settings\n",
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 config_file_pathname);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 exit(1);
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 }
62f39c7cee15 themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 }