view smpp-send/msg_cmd.c @ 260:b997de027717

themwi-update-outrt: special-num route-to: add support for explicit setting of SIP user part
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 15 Aug 2023 23:23:57 -0800
parents f11c3e40c87a
children
line wrap: on
line source

/*
 * This module implements msg and msg-udh input commands,
 * after all settings have been captured.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "error.h"

extern int input_lineno;

static int
decode_hex_digit(c)
{
	if (c >= '0' && c <= '9')
		return(c - '0');
	if (c >= 'A' && c <= 'F')
		return(c - 'A' + 10);
	if (c >= 'a' && c <= 'f')
		return(c - 'a' + 10);
	return(-1);
}

static void
cmd_msg_common(arg, udhi)
	char *arg;
{
	u_char input[160];
	unsigned input_len;

	for (input_len = 0; ; input_len++) {
		while (isspace(*arg))
			arg++;
		if (!*arg)
			break;
		if (!isxdigit(arg[0]) || !isxdigit(arg[1])) {
			fprintf(stderr, ERR_PREFIX "invalid hex string\n",
				input_lineno);
			exit(1);
		}
		if (input_len >= 160) {
			fprintf(stderr, ERR_PREFIX "hex string is too long\n",
				input_lineno);
			exit(1);
		}
		input[input_len] = (decode_hex_digit(arg[0]) << 4) |
				    decode_hex_digit(arg[1]);
		arg += 2;
	}
	build_submit_sm(input, input_len, udhi);
}

void
cmd_msg_plain(argc, argv)
	char **argv;
{
	cmd_msg_common(argv[1], 0);
}

void
cmd_msg_udh(argc, argv)
	char **argv;
{
	cmd_msg_common(argv[1], 1);
}