FreeCalypso > hg > osmo-playpen
diff smsc-sendmt/read_pdu.c @ 12:7543aa173634
proto-smsc-sendmt program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Aug 2023 16:36:28 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/smsc-sendmt/read_pdu.c Sun Aug 27 16:36:28 2023 -0800 @@ -0,0 +1,38 @@ +/* + * 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; +}