FreeCalypso > hg > themwi-system-sw
annotate utils/themwi-update-outrt.c @ 217:9f6a148ceb25
tcpserv-dump: brown paper bag
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 24 Jul 2023 22:33:01 -0800 |
parents | de7c64c4d6fd |
children | b0bf167bb846 |
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 |
204
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
218 handle_default_rt(cp) |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
219 char *cp; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
220 { |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
221 char *dest_name; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
222 struct inn_route *rec; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
223 int dest_id; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
224 |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
225 for (dest_name = cp; *cp && !isspace(*cp); cp++) |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
226 ; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
227 if (*cp) |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
228 *cp++ = '\0'; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
229 while (isspace(*cp)) |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
230 cp++; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
231 if (*cp != '\0' && *cp != '#') { |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
232 fprintf(stderr, |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
233 "out-routes line %d: invalid syntax for inn-default-rt\n", |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
234 lineno); |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
235 exit(1); |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
236 } |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
237 dest_id = find_dest_by_name(dest_name); |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
238 if (dest_id < 0) { |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
239 fprintf(stderr, |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
240 "out-routes line %d: SIP destination \"%s\" not defined\n", |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
241 lineno, dest_name); |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
242 exit(1); |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
243 } |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
244 if (inn_rec_count >= MAX_INN_ENTRIES) { |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
245 fprintf(stderr, |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
246 "out-routes line %d: MAX_INN_ENTRIES exceeded\n", |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
247 lineno); |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
248 exit(1); |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
249 } |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
250 rec = inn_records + inn_rec_count; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
251 rec->prefix[0] = '\0'; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
252 rec->sip_dest_id = dest_id; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
253 inn_rec_count++; |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
254 } |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
255 |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
256 static void |
130
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 preen_special_num_code(num_code) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 char *num_code; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 char *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 int c; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 unsigned n; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 n = 0; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 for (cp = num_code; *cp; ) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 c = *cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 if (is_valid_ext_digit(c)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 n++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 else { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 "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
|
272 lineno, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 if (n > MAX_SPECIAL_NUM) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 "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
|
279 lineno, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 handle_special_num_map_to(num_code, cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 char *num_code, *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 struct special_num_route *rec; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 char *tgt_num_src; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 int rc, dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 if (*cp++ != '+') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 inv_syntax: fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 "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
|
297 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 if (!isdigit(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 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
|
303 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 if (*cp != '\0' && *cp != '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 rc = grok_number_string(tgt_num_src, 1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 if (rc < 1) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 if (rc > MAX_E164_NUMBER) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 "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
|
316 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 rec = special_num_records + special_num_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 strcpy(rec->special_num, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 rec->sip_user[0] = '+'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 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
|
323 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
|
324 if (dest_id < 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 "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
|
327 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 rec->sip_dest_id = dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 special_num_count++; |
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 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 handle_special_num_route_to(num_code, cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 char *num_code, *cp; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 struct special_num_route *rec; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 char *dest_name; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 int dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 if (*cp == '\0' || *cp == '#') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 inv_syntax: fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 "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
|
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 for (dest_name = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 if (*cp != '\0' && *cp != '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 dest_id = find_dest_by_name(dest_name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 if (dest_id < 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 "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
|
362 lineno, dest_name); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 rec = special_num_records + special_num_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 strcpy(rec->special_num, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 strcpy(rec->sip_user, num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 rec->sip_dest_id = dest_id; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 special_num_count++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 handle_special_num(cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 char *cp; |
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 char *num_code, *handling_kw; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 for (num_code = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 preen_special_num_code(num_code); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 if (special_num_count >= MAX_SPC_NUM_ENTRIES) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 "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
|
386 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 if (*cp == '\0' || *cp == '#') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 inv_syntax: fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 "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
|
394 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
397 for (handling_kw = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
398 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 if (!strcmp(handling_kw, "map-to")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 handle_special_num_map_to(num_code, cp); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 else if (!strcmp(handling_kw, "route-to")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 handle_special_num_route_to(num_code, cp); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 else |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 goto inv_syntax; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
407 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 process_line() |
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 char *cp, *np; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 void (*handler)(); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
414 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 if (!index(linebuf, '\n')) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 "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
|
418 lineno); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 for (cp = linebuf; isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 if (*cp == '\0' || *cp == '#') |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 return; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 for (np = cp; *cp && !isspace(*cp); cp++) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
426 ; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 if (*cp) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
428 *cp++ = '\0'; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 if (!strcmp(np, "dest")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 handler = handle_dest_line; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 else if (!strcmp(np, "inn-route")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 handler = handle_inn_route; |
204
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
433 else if (!strcmp(np, "inn-default-rt")) |
de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
Mychaela Falconia <falcon@freecalypso.org>
parents:
132
diff
changeset
|
434 handler = handle_default_rt; |
130
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 else if (!strcmp(np, "special-num")) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 handler = handle_special_num; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 else { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 "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
|
440 lineno, np); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 exit(1); |
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 while (isspace(*cp)) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 cp++; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 if (*cp == '\0' || *cp == '#') { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 fprintf(stderr, |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 "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
|
448 lineno, np); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 handler(cp); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 static void |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 emit_output() |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 FILE *outf; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 struct out_routes_header hdr; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 outf = fopen("out-routes.newbin", "w"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
461 if (!outf) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 perror("creating out-routes.newbin"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
463 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 hdr.num_dest = dest_rec_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
466 hdr.num_inn = inn_rec_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
467 hdr.num_special = special_num_count; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
468 if (fwrite(&hdr, sizeof hdr, 1, outf) != 1) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
469 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
|
470 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
471 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
472 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
|
473 != dest_rec_count) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 goto write_err; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 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
|
476 != inn_rec_count) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 goto write_err; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 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
|
479 special_num_count, outf) != special_num_count) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 goto write_err; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
481 fclose(outf); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
482 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
483 |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
484 main(argc, argv) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
485 char **argv; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
486 { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
487 if (argc > 2) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
488 fprintf(stderr, "usage: %s [directory]\n", argv[0]); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
489 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
490 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
491 if (argv[1]) |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
492 system_dir = argv[1]; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
493 else |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
494 system_dir = "/var/gsm"; |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
495 if (chdir(system_dir) < 0) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
496 perror(system_dir); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
497 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
498 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
499 inf = fopen("out-routes", "r"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
500 if (!inf) { |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
501 perror("opening out-routes"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
502 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
503 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
504 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
|
505 process_line(); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
506 fclose(inf); |
132
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
507 if (!dest_rec_count) { |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
508 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
|
509 exit(1); |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
510 } |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
511 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
|
512 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
|
513 exit(1); |
aa278d75d757
themwi-update-outrt: catch and reject empty tables
Mychaela Falconia <falcon@freecalypso.org>
parents:
131
diff
changeset
|
514 } |
130
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
515 emit_output(); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
516 /* make it live */ |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
517 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
|
518 perror("rename"); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
519 exit(1); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
520 } |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
521 exit(0); |
44dc809ffec0
themwi-update-out-routes utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
522 } |