FreeCalypso > hg > osmo-playpen
changeset 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 | cef4677a4cf8 |
children | 22ddb71f6883 |
files | smsc-sendmt/smsc_addr.c |
diffstat | 1 files changed, 51 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/smsc-sendmt/smsc_addr.c Fri Aug 25 14:28:54 2023 -0800 @@ -0,0 +1,51 @@ +/* + * This C module is being stashed here temporarily until we figure out + * where this function ultimately needs to go. The parsing of the SMSC + * address is being moved out of proto-smsc-daemon to proto-smsc-sendmt, + * but we haven't started putting together the latter program yet. + */ + +#include <ctype.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +char smsc_addr_num[21]; /* maximum of 20 digits per GSM 04.11 */ +uint8_t smsc_addr_ton_npi; + +void parse_smsc_addr_arg(char *arg) +{ + char *cp, *dp, *endp; + unsigned ndig; + + cp = arg; + dp = smsc_addr_num; + ndig = 0; + while (isdigit(*cp)) { + if (ndig >= 20) { + fprintf(stderr, + "error: SMSC address argument exceeds GSM 04.11 limit of 20 digits\n"); + exit(1); + } + *dp++ = *cp++; + ndig++; + } + if (!ndig) { +invalid: fprintf(stderr, + "error: SMSC address argument \"%s\" is invalid\n", + arg); + exit(1); + } + if (!*cp) { + /* default to TON=1, NPI=1, i.e., a pretend Global Title */ + smsc_addr_ton_npi = 0x91; + return; + } + if (*cp++ != ',') + goto invalid; + if (!*cp) + goto invalid; + smsc_addr_ton_npi = strtoul(cp, &endp, 0); + if (*endp) + goto invalid; +}