comparison smpp-send/input.c @ 223:f11c3e40c87a

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