annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the reading of hex-encoded SMS-DELIVER TPDU
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * from stdin.
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern int decode_hex_line(const char *inbuf, uint8_t *outbuf, unsigned outmax);
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 uint8_t tpdu_buf[176];
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 unsigned tpdu_len;
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 void read_pdu_from_stdin(void)
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char linebuf[512], *nl;
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int rc;
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (!fgets(linebuf, sizeof(linebuf), stdin)) {
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 fprintf(stderr, "error: empty stdin is not acceptable\n");
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 exit(1);
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 nl = strchr(linebuf, '\n');
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (!nl) {
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 fprintf(stderr,
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 "error: stdin line is too long or unterminated\n");
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 *nl = '\0';
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 rc = decode_hex_line(linebuf, tpdu_buf, sizeof(tpdu_buf));
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (rc <= 0) {
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 fprintf(stderr, "error: stdin line is not a valid hex PDU\n");
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 exit(1);
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 tpdu_len = rc;
7543aa173634 proto-smsc-sendmt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }