view smsc-sendmt/smsc_addr.c @ 7:22ddb71f6883

smsc-daemon: convert to setting IPA name on the command line
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Aug 2023 14:47:24 -0800
parents 18b7f75fed9b
children 7543aa173634
line wrap: on
line source

/*
 * 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;
}