FreeCalypso > hg > themwi-system-sw
annotate utils/themwi-update-outrt.c @ 160:4b35a5a400f1
mgw/dtmf_defs.h: reduce DTMF_MIN_FRAMES to 5 (100 ms)
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Oct 2022 13:05:26 -0800 |
parents | aa278d75d757 |
children | de7c64c4d6fd |
rev | line source |
---|---|
130
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads (parses) ThemWi config file /var/gsm/out-routes, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * generates the compiled binary form of this database, and then makes |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * it live via atomic rename. |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/socket.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <netinet/in.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <arpa/inet.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <ctype.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdio.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdint.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <stdlib.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <string.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include <strings.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include <unistd.h> |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include "../include/out_routes.h" |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #define MAX_DEST_ENTRIES 16 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #define MAX_INN_ENTRIES 64 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #define MAX_SPC_NUM_ENTRIES 64 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 static struct sip_out_dest dest_records[MAX_DEST_ENTRIES]; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 static char *dest_names[MAX_DEST_ENTRIES]; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 static struct inn_route inn_records[MAX_INN_ENTRIES]; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 static struct special_num_route special_num_records[MAX_SPC_NUM_ENTRIES]; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 static unsigned dest_rec_count, inn_rec_count, special_num_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 static char *system_dir; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 static FILE *inf; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 static int lineno; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 static char linebuf[256]; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 static int |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 find_dest_by_name(sought_name) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 char *sought_name; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 unsigned n; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 for (n = 0; n < dest_rec_count; n++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (!strcmp(dest_names[n], sought_name)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 return n; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return -1; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 static int |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 find_dest_by_number(target_num) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 char *target_num; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 unsigned inn_index; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 struct inn_route *rec; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 char *pp, *tp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 for (inn_index = 0; inn_index < inn_rec_count; inn_index++) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 rec = inn_records + inn_index; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 pp = rec->prefix; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 tp = target_num; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 while (*pp && *pp == *tp) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 pp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 tp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (*pp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 continue; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return rec->sip_dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 return -1; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 handle_dest_line(cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 char *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 char *name, *name_copy, *domain, *ip_str, *port_str; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 struct sip_out_dest *rec; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 unsigned portnum; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 int rc; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 for (name = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (*cp == '\0' || *cp == '#') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 inv_syntax: fprintf(stderr, "out-routes line %d: invalid syntax for dest\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 for (domain = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (*cp == '\0' || *cp == '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 for (ip_str = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 if (*cp == '\0' || *cp == '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 port_str = 0; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 else { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 for (port_str = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 if (*cp != '\0' && *cp != '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 rc = find_dest_by_name(name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (rc >= 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 "out-routes line %d: duplicate destination name \"%s\"\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 lineno, name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 if (dest_rec_count >= MAX_DEST_ENTRIES) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 "out-routes line %d: MAX_DEST_ENTRIES exceeded\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 name_copy = strdup(name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 if (!name_copy) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 perror("strdup"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 dest_names[dest_rec_count] = name_copy; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 rec = dest_records + dest_rec_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (strlen(domain) > MAX_SIP_DEST_DOMAIN) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 "out-routes line %d: dest domain string is too long\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 strcpy(rec->domain, domain); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 rec->sin.sin_family = AF_INET; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 rec->sin.sin_addr.s_addr = inet_addr(ip_str); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 if (rec->sin.sin_addr.s_addr == INADDR_NONE) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 "out-routes line %d: dest IP address is invalid\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (port_str) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 portnum = strtoul(port_str, &cp, 10); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 } else |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 portnum = 5060; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 rec->sin.sin_port = htons(portnum); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 dest_rec_count++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 handle_inn_route(cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 char *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 char *prefix, *dest_name; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 struct inn_route *rec; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 int rc, dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 for (prefix = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 if (*cp == '\0' || *cp == '#') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 inv_syntax: fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 "out-routes line %d: invalid syntax for inn-route\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 for (dest_name = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 if (*cp != '\0' && *cp != '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 rc = grok_number_string(prefix, 1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 if (rc < 1) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 if (rc > MAX_INN_PREFIX) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 "out-routes line %d: inn-route prefix is too long\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 dest_id = find_dest_by_name(dest_name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 if (dest_id < 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 "out-routes line %d: SIP destination \"%s\" not defined\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 lineno, dest_name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 if (inn_rec_count >= MAX_INN_ENTRIES) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 "out-routes line %d: MAX_INN_ENTRIES exceeded\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 rec = inn_records + inn_rec_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 dehyphen_number_string(prefix, rec->prefix); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 rec->sip_dest_id = dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 inn_rec_count++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 preen_special_num_code(num_code) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 char *num_code; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 char *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 int c; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 unsigned n; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 n = 0; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 for (cp = num_code; *cp; ) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 c = *cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 if (is_valid_ext_digit(c)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 n++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 else { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 "out-routes line %d: special-num string \"%s\" is invalid\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 lineno, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 if (n > MAX_SPECIAL_NUM) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 "out-routes line %d: special-num string \"%s\" is too long\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 lineno, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 handle_special_num_map_to(num_code, cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 char *num_code, *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 struct special_num_route *rec; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 char *tgt_num_src; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 int rc, dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 if (*cp++ != '+') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 inv_syntax: fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 "out-routes line %d: invalid syntax for special-num map-to\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 if (!isdigit(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 for (tgt_num_src = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 if (*cp != '\0' && *cp != '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 rc = grok_number_string(tgt_num_src, 1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 if (rc < 1) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 if (rc > MAX_E164_NUMBER) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 "out-routes line %d: map-to number is too long for E.164\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 rec = special_num_records + special_num_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 strcpy(rec->special_num, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 rec->sip_user[0] = '+'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 dehyphen_number_string(tgt_num_src, rec->sip_user+1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 dest_id = find_dest_by_number(rec->sip_user+1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 if (dest_id < 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 "out-routes line %d: no inn-route for map-to number\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 rec->sip_dest_id = dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 special_num_count++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 handle_special_num_route_to(num_code, cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 char *num_code, *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 struct special_num_route *rec; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 char *dest_name; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 int dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 if (*cp == '\0' || *cp == '#') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 inv_syntax: fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 "out-routes line %d: invalid syntax for special-num route-to\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 for (dest_name = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 if (*cp != '\0' && *cp != '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 dest_id = find_dest_by_name(dest_name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 if (dest_id < 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 "out-routes line %d: SIP destination \"%s\" not defined\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 lineno, dest_name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 rec = special_num_records + special_num_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 strcpy(rec->special_num, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 strcpy(rec->sip_user, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 rec->sip_dest_id = dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 special_num_count++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 handle_special_num(cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 char *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 char *num_code, *handling_kw; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 for (num_code = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 preen_special_num_code(num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 if (special_num_count >= MAX_SPC_NUM_ENTRIES) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 "out-routes line %d: MAX_SPC_NUM_ENTRIES exceeded\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 if (*cp == '\0' || *cp == '#') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 inv_syntax: fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 "out-routes line %d: invalid syntax for special-num\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 for (handling_kw = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 if (!strcmp(handling_kw, "map-to")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 handle_special_num_map_to(num_code, cp); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 else if (!strcmp(handling_kw, "route-to")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 handle_special_num_route_to(num_code, cp); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 else |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 process_line() |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 char *cp, *np; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 void (*handler)(); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 if (!index(linebuf, '\n')) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 "out-routes line %d: too long or missing newline\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 for (cp = linebuf; isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 if (*cp == '\0' || *cp == '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 return; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 for (np = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 if (!strcmp(np, "dest")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 handler = handle_dest_line; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 else if (!strcmp(np, "inn-route")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 handler = handle_inn_route; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
394 else if (!strcmp(np, "special-num")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 handler = handle_special_num; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 else { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
397 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
398 "out-routes line %d: non-understood keyword \"%s\"\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 lineno, np); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 if (*cp == '\0' || *cp == '#') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 "out-routes line %d: missing argument after \"%s\" keyword\n", |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
407 lineno, np); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 handler(cp); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
411 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
412 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
414 emit_output() |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 FILE *outf; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 struct out_routes_header hdr; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
418 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 outf = fopen("out-routes.newbin", "w"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 if (!outf) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 perror("creating out-routes.newbin"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 hdr.num_dest = dest_rec_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 hdr.num_inn = inn_rec_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
426 hdr.num_special = special_num_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 if (fwrite(&hdr, sizeof hdr, 1, outf) != 1) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
428 write_err: fprintf(stderr, "error writing to new binary file\n"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 if (fwrite(dest_records, sizeof(dest_records[0]), dest_rec_count, outf) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 != dest_rec_count) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
433 goto write_err; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
434 if (fwrite(inn_records, sizeof(inn_records[0]), inn_rec_count, outf) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 != inn_rec_count) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 goto write_err; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 if (fwrite(special_num_records, sizeof(special_num_records[0]), |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 special_num_count, outf) != special_num_count) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 goto write_err; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
440 fclose(outf); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
442 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
443 main(argc, argv) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 char **argv; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 if (argc > 2) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 fprintf(stderr, "usage: %s [directory]\n", argv[0]); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
448 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 if (argv[1]) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 system_dir = argv[1]; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 else |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 system_dir = "/var/gsm"; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 if (chdir(system_dir) < 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 perror(system_dir); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 inf = fopen("out-routes", "r"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 if (!inf) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 perror("opening out-routes"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
461 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
463 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 process_line(); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 fclose(inf); |
132
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
466 if (!dest_rec_count) { |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
467 fprintf(stderr, "error: no SIP destinations defined\n"); |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
468 exit(1); |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
469 } |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
470 if (!inn_rec_count && !special_num_count) { |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
471 fprintf(stderr, "error: no routes defined\n"); |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
472 exit(1); |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
473 } |
130
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 emit_output(); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 /* make it live */ |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
476 if (rename("out-routes.newbin", "out-routes.bin") < 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 perror("rename"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
479 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 exit(0); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
481 } |