annotate smpp-send/msg_cmd.c @ 223:f11c3e40c87a

new program smpp-send
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 12:24:31 -0800
parents
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 msg and msg-udh input commands,
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * after all settings have been captured.
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
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "error.h"
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int input_lineno;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static int
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 decode_hex_digit(c)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (c >= '0' && c <= '9')
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 return(c - '0');
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (c >= 'A' && c <= 'F')
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(c - 'A' + 10);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (c >= 'a' && c <= 'f')
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return(c - 'a' + 10);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return(-1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static void
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 cmd_msg_common(arg, udhi)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 char *arg;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 u_char input[160];
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 unsigned input_len;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 for (input_len = 0; ; input_len++) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 while (isspace(*arg))
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 arg++;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (!*arg)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 break;
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (!isxdigit(arg[0]) || !isxdigit(arg[1])) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 fprintf(stderr, ERR_PREFIX "invalid hex string\n",
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 input_lineno);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (input_len >= 160) {
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(stderr, ERR_PREFIX "hex string is too long\n",
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 input_lineno);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 input[input_len] = (decode_hex_digit(arg[0]) << 4) |
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 decode_hex_digit(arg[1]);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 arg += 2;
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 build_submit_sm(input, input_len, udhi);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
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 void
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 cmd_msg_plain(argc, argv)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 char **argv;
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 cmd_msg_common(argv[1], 0);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 void
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 cmd_msg_udh(argc, argv)
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 char **argv;
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 cmd_msg_common(argv[1], 1);
f11c3e40c87a new program smpp-send
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }