annotate smsc-sendmt/smsc_addr.c @ 9:dfe99a061249

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