comparison smsc-sendmt/smsc_addr.c @ 6:18b7f75fed9b

smsc-sendmt/smsc_addr.c: temporary code stashaway
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Aug 2023 14:28:54 -0800
parents smsc-daemon/main.c@cef4677a4cf8
children 7543aa173634
comparison
equal deleted inserted replaced
5:cef4677a4cf8 6:18b7f75fed9b
1 /*
2 * This C module is being stashed here temporarily until we figure out
3 * where this function ultimately needs to go. The parsing of the SMSC
4 * address is being moved out of proto-smsc-daemon to proto-smsc-sendmt,
5 * but we haven't started putting together the latter program yet.
6 */
7
8 #include <ctype.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 char smsc_addr_num[21]; /* maximum of 20 digits per GSM 04.11 */
14 uint8_t smsc_addr_ton_npi;
15
16 void parse_smsc_addr_arg(char *arg)
17 {
18 char *cp, *dp, *endp;
19 unsigned ndig;
20
21 cp = arg;
22 dp = smsc_addr_num;
23 ndig = 0;
24 while (isdigit(*cp)) {
25 if (ndig >= 20) {
26 fprintf(stderr,
27 "error: SMSC address argument exceeds GSM 04.11 limit of 20 digits\n");
28 exit(1);
29 }
30 *dp++ = *cp++;
31 ndig++;
32 }
33 if (!ndig) {
34 invalid: fprintf(stderr,
35 "error: SMSC address argument \"%s\" is invalid\n",
36 arg);
37 exit(1);
38 }
39 if (!*cp) {
40 /* default to TON=1, NPI=1, i.e., a pretend Global Title */
41 smsc_addr_ton_npi = 0x91;
42 return;
43 }
44 if (*cp++ != ',')
45 goto invalid;
46 if (!*cp)
47 goto invalid;
48 smsc_addr_ton_npi = strtoul(cp, &endp, 0);
49 if (*endp)
50 goto invalid;
51 }