annotate smpp-send/input.c @ 251:df2726b88034

top Makefile: sip-in changed to use libnumdb2
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 23:43:28 -0800
parents 62184b971c8e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
223
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements input handling for smpp-send.
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <ctype.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "error.h"
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern char input_line[];
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int input_lineno;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern void set_src_addr();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern void set_src_ton();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern void set_src_npi();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern void set_dest_addr();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern void set_dest_ton();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern void set_dest_npi();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern void set_pid_byte();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern void set_dcs_byte();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern void set_esm_class();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern void set_priority();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern void set_reg_deliv();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern void set_replace_flag();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 extern void cmd_msg_plain();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 extern void cmd_msg_udh();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static struct cmdtab {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 char *cmd;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int minargs;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 int maxargs;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 void (*func)();
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 } cmdtab[] = {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"src", 1, 1, set_src_addr},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {"src-ton", 1, 1, set_src_ton},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {"src-npi", 1, 1, set_src_npi},
224
62184b971c8e smpp-send/input.c: copy-n-paste error
Mychaela Falconia <falcon@freecalypso.org>
parents: 223
diff changeset
39 {"dest", 1, 1, set_dest_addr},
62184b971c8e smpp-send/input.c: copy-n-paste error
Mychaela Falconia <falcon@freecalypso.org>
parents: 223
diff changeset
40 {"dest-ton", 1, 1, set_dest_ton},
62184b971c8e smpp-send/input.c: copy-n-paste error
Mychaela Falconia <falcon@freecalypso.org>
parents: 223
diff changeset
41 {"dest-npi", 1, 1, set_dest_npi},
223
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {"pid", 1, 1, set_pid_byte},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {"dcs", 1, 2, set_dcs_byte},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {"esm-class", 1, 1, set_esm_class},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {"priority", 1, 1, set_priority},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {"reg-deliv", 1, 1, set_reg_deliv},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {"replace-flag", 1, 1, set_replace_flag},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {"msg", 1, 1, cmd_msg_plain},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 {"msg-udh", 1, 1, cmd_msg_udh},
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 /* table search terminator */
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {0, 0, 0, 0}
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 };
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 void
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 process_input_line()
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 char *argv[10];
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 char *cp, **ap;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 struct cmdtab *tp;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 cp = index(input_line, '\n');
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (!cp) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 fprintf(stderr, ERR_PREFIX "missing newline\n", input_lineno);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 for (cp = input_line; isspace(*cp); cp++)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 ;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (*cp == '\0' || *cp == '#')
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 argv[0] = cp;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 while (*cp && !isspace(*cp))
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 cp++;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (*cp)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 *cp++ = '\0';
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 for (tp = cmdtab; tp->cmd; tp++)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (!strcmp(tp->cmd, argv[0]))
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 break;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (!tp->func) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 fprintf(stderr, ERR_PREFIX "invalid command \"%s\"\n",
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 input_lineno, argv[0]);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 for (ap = argv + 1; ; ) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 while (isspace(*cp))
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 cp++;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (!*cp || *cp == '#')
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 break;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (ap - argv - 1 >= tp->maxargs) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 fprintf(stderr, ERR_PREFIX "too many arguments\n",
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 input_lineno);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 if (*cp == '"') {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 *ap++ = ++cp;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 for (;;) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (!*cp) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 unterm_qstring: fprintf(stderr, ERR_PREFIX
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 "unterminated quoted string\n",
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 input_lineno);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (*cp == '"')
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 break;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (*cp++ == '\\') {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 if (!*cp)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 goto unterm_qstring;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 cp++;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 *cp++ = '\0';
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 } else {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 *ap++ = cp;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 while (*cp && !isspace(*cp))
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 cp++;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 if (*cp)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 *cp++ = '\0';
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if (ap - argv - 1 < tp->minargs) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 fprintf(stderr, ERR_PREFIX "too few arguments\n", input_lineno);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 *ap = 0;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 tp->func(ap - argv, argv);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 }