view smsc-sendmt/read_pdu.c @ 18:9c2c1444dca9

doc/Proto-SMSC-testing: OS#6135 patches have been merged
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 13 Nov 2023 12:47:12 -0800
parents 7543aa173634
children
line wrap: on
line source

/*
 * This module implements the reading of hex-encoded SMS-DELIVER TPDU
 * from stdin.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

extern int decode_hex_line(const char *inbuf, uint8_t *outbuf, unsigned outmax);

uint8_t tpdu_buf[176];
unsigned tpdu_len;

void read_pdu_from_stdin(void)
{
	char linebuf[512], *nl;
	int rc;

	if (!fgets(linebuf, sizeof(linebuf), stdin)) {
		fprintf(stderr, "error: empty stdin is not acceptable\n");
		exit(1);
	}
	nl = strchr(linebuf, '\n');
	if (!nl) {
		fprintf(stderr,
			"error: stdin line is too long or unterminated\n");
		exit(1);
	}
	*nl = '\0';
	rc = decode_hex_line(linebuf, tpdu_buf, sizeof(tpdu_buf));
	if (rc <= 0) {
		fprintf(stderr, "error: stdin line is not a valid hex PDU\n");
		exit(1);
	}
	tpdu_len = rc;
}