FreeCalypso > hg > themwi-system-sw
annotate sip-out/readconf.c @ 180:565477d07418
themwi-rtp-mgr: close file descriptors after sending them across
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Mar 2023 20:41:23 -0800 |
parents | 0bacca1f2f7b |
children |
rev | line source |
---|---|
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
2 * In this module we implement the reading of /var/gsm/themwi-sip-out.cfg: |
47
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; |
68
709b78a4ebf0
sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
19 unsigned cfg_retrans_timeout = 500; |
709b78a4ebf0
sip-in: implement retransmission of INVITE responses
Mychaela Falconia <falcon@freecalypso.org>
parents:
47
diff
changeset
|
20 unsigned cfg_retrans_count = 10; |
92
a9137bdb6047
sip-in: make BYE Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
21 unsigned max_forwards = 70; |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
22 unsigned sip_linger_timeout = 10; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
23 unsigned sip_linger_invite_err = 10; |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
24 unsigned sip_linger_gotbye = 30; |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
25 unsigned sip_linger_bye_out_ok = 5; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
26 unsigned sip_linger_bye_out_err = 180; |
156
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
154
diff
changeset
|
27 unsigned sip_linger_response_err = 180; |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
28 int block_1900_numbers = 1; |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
30 static char config_file_pathname[] = "/var/gsm/themwi-sip-out.cfg"; |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 struct parse_state { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 int lineno; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 int set_mask; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 }; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 static void |
89
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
38 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
|
39 struct parse_state *st; |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
40 char *kw, *arg; |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
41 { |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
42 char *cp; |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
43 |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
44 if (*arg == '\0' || *arg == '#') { |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
45 inv_syntax: fprintf(stderr, |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
46 "%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
|
47 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
|
48 exit(1); |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
49 } |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
50 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
|
51 ; |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
52 if (*cp) |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
53 *cp++ = '\0'; |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
54 while (isspace(*cp)) |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
55 cp++; |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
56 if (*cp != '\0' && *cp != '#') |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
57 goto inv_syntax; |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
58 } |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
59 |
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
60 static void |
90
736c2d68595f
sip-in/readconf.c: second step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
61 handle_ip(st, kw, arg, var) |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 struct parse_state *st; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 char *kw, *arg; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 struct in_addr *var; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 { |
89
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
66 require_one_arg(st, kw, arg); |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 var->s_addr = inet_addr(arg); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if (var->s_addr == INADDR_NONE) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 fprintf(stderr, |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 "%s line %d: invalid IP address argument \"%s\"\n", |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 config_file_pathname, st->lineno, arg); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
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 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 static void |
90
736c2d68595f
sip-in/readconf.c: second step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
77 handle_num(st, kw, arg, var) |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 struct parse_state *st; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 char *kw, *arg; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 unsigned *var; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 char *endp; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 |
89
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
84 require_one_arg(st, kw, arg); |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 *var = strtoul(arg, &endp, 10); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 if (*endp) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 fprintf(stderr, "%s line %d: invalid numeric argument \"%s\"\n", |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 config_file_pathname, st->lineno, arg); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 static void |
90
736c2d68595f
sip-in/readconf.c: second step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
94 handle_bool(st, kw, arg, var) |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 struct parse_state *st; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 char *kw, *arg; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 int *var; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 { |
89
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
99 require_one_arg(st, kw, arg); |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 if (!strcmp(arg, "true") || !strcmp(arg, "on") || !strcmp(arg, "yes") |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 || !strcmp(arg, "1")) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 *var = 1; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 return; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 if (!strcmp(arg, "false") || !strcmp(arg, "off") || !strcmp(arg, "no") |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 || !strcmp(arg, "0")) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 *var = 0; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 return; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 fprintf(stderr, "%s line %d: invalid boolean argument \"%s\"\n", |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 config_file_pathname, st->lineno, arg); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 static void |
91
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
116 handle_retrans_conf(st, kw, arg) |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
117 struct parse_state *st; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
118 char *kw, *arg; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
119 { |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
120 char *cp = arg; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
121 |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
122 if (!isdigit(*cp)) { |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
123 inv: fprintf(stderr, |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
124 "%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
|
125 config_file_pathname, st->lineno, kw); |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
126 exit(1); |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
127 } |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
128 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
|
129 while (isspace(*cp)) |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
130 cp++; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
131 if (!isdigit(*cp)) |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
132 goto inv; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
133 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
|
134 while (isspace(*cp)) |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
135 cp++; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
136 if (*cp != '\0' && *cp != '#') |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
137 goto inv; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
138 } |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
139 |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
140 static void |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 process_line(st, line) |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 struct parse_state *st; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 char *line; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 { |
89
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
145 char *cp, *kw; |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 void (*handler)(), *var; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 int set_id; |
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 (!index(line, '\n')) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 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
|
151 config_file_pathname, st->lineno); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 for (cp = line; isspace(*cp); cp++) |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 ; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 if (*cp == '\0' || *cp == '#') |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 return; |
89
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
158 for (kw = cp; *cp && !isspace(*cp); cp++) |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 ; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 if (*cp) |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 *cp++ = '\0'; |
89
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
162 if (!strcmp(kw, "bind-ip")) { |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 handler = handle_ip; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 var = &sip_bind_ip; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 set_id = 1; |
89
e64d4d44025d
sip-in/readconf.c: first step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
68
diff
changeset
|
166 } else if (!strcmp(kw, "bind-port")) { |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 handler = handle_num; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 var = &sip_bind_port; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 set_id = 2; |
91
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
170 } 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
|
171 handler = handle_retrans_conf; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
172 var = (void *) 0; |
fd23e2747b45
sip-in: add sip-udp-retrans configuration setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
173 set_id = 0; |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
174 } else if (!strcmp(kw, "sip-linger-timeout")) { |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
175 handler = handle_num; |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
176 var = &sip_linger_timeout; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
177 set_id = 0; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
178 } else if (!strcmp(kw, "sip-linger-invite-error")) { |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
179 handler = handle_num; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
180 var = &sip_linger_invite_err; |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
181 set_id = 0; |
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
182 } else if (!strcmp(kw, "sip-linger-got-bye")) { |
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
183 handler = handle_num; |
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
184 var = &sip_linger_gotbye; |
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
185 set_id = 0; |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
186 } else if (!strcmp(kw, "sip-linger-bye-out-ok")) { |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
187 handler = handle_num; |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
188 var = &sip_linger_bye_out_ok; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
189 set_id = 0; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
190 } else if (!strcmp(kw, "sip-linger-bye-out-error")) { |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
191 handler = handle_num; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
192 var = &sip_linger_bye_out_err; |
109
9b87894704eb
sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
193 set_id = 0; |
156
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
154
diff
changeset
|
194 } else if (!strcmp(kw, "sip-linger-response-error")) { |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
154
diff
changeset
|
195 handler = handle_num; |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
154
diff
changeset
|
196 var = &sip_linger_response_err; |
0bacca1f2f7b
sip-out: handle all INVITE responses, except errors
Mychaela Falconia <falcon@freecalypso.org>
parents:
154
diff
changeset
|
197 set_id = 0; |
92
a9137bdb6047
sip-in: make BYE Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
198 } else if (!strcmp(kw, "max-forwards")) { |
a9137bdb6047
sip-in: make BYE Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
199 handler = &handle_num; |
a9137bdb6047
sip-in: make BYE Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
200 var = &max_forwards; |
a9137bdb6047
sip-in: make BYE Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
201 set_id = 0; |
154
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
202 } else if (!strcmp(kw, "block-1900")) { |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
203 handler = handle_bool; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
204 var = &block_1900_numbers; |
e54b0a9e322f
beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
205 set_id = 0; |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 } else { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 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
|
208 config_file_pathname, st->lineno, kw); |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 if (st->set_mask & set_id) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 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
|
213 config_file_pathname, st->lineno, kw); |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 while (isspace(*cp)) |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 cp++; |
90
736c2d68595f
sip-in/readconf.c: second step toward non-trivial settings
Mychaela Falconia <falcon@freecalypso.org>
parents:
89
diff
changeset
|
218 handler(st, kw, cp, var); |
47
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 st->set_mask |= set_id; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 read_config_file() |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 FILE *inf; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 struct parse_state pst; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 char linebuf[256]; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 inf = fopen(config_file_pathname, "r"); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 if (!inf) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 perror(config_file_pathname); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 pst.set_mask = 0; |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 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
|
235 process_line(&pst, linebuf); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 fclose(inf); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 if (pst.set_mask != 3) { |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 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
|
239 config_file_pathname); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 exit(1); |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 } |
62f39c7cee15
themwi-sip-in skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 } |