FreeCalypso > hg > sms-coding-utils
changeset 15:5854e48d0ef7
sms-gen-tpdu: add support for alphanumeric user-addr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Aug 2023 06:43:23 +0000 |
parents | b014abaf0898 |
children | d9d722033ff1 |
files | gen-pdu/settings.c libcoding/Makefile libcoding/alpha_addr.c libcoding/gsm7_encode2.c |
diffstat | 4 files changed, 106 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/gen-pdu/settings.c Sun Aug 27 05:13:04 2023 +0000 +++ b/gen-pdu/settings.c Sun Aug 27 06:43:23 2023 +0000 @@ -32,7 +32,7 @@ } rc = encode_phone_number_arg(argv[1], sc_addr, 0); if (rc < 0) { - fprintf(stderr, ERR_PREFIX "invalid phone number argument\n", + fprintf(stderr, ERR_PREFIX "invalid SC-address argument\n", input_lineno); exit(1); } @@ -43,11 +43,18 @@ char **argv; { int rc; + char *err_desc; - rc = encode_phone_number_arg(argv[1], user_addr, 1); + if (!strncmp(argv[1], "alpha:", 6)) { + rc = encode_alpha_addr(argv[1] + 6, user_addr); + err_desc = "alpha address"; + } else { + rc = encode_phone_number_arg(argv[1], user_addr, 1); + err_desc = "phone number"; + } if (rc < 0) { - fprintf(stderr, ERR_PREFIX "invalid phone number argument\n", - input_lineno); + fprintf(stderr, ERR_PREFIX "invalid %s argument\n", + input_lineno, err_desc); exit(1); } }
--- a/libcoding/Makefile Sun Aug 27 05:13:04 2023 +0000 +++ b/libcoding/Makefile Sun Aug 27 06:43:23 2023 +0000 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 -OBJS= check_high_bit.o gsm7_encode.o gsm7_encode_table.o gsm7_pack.o \ - hexdigits.o hexout.o number_encode.o timestamp.o ucs2_bigend.o \ - utf8_decode.o utf8_decode2.o +OBJS= alpha_addr.o check_high_bit.o gsm7_encode.o gsm7_encode2.o \ + gsm7_encode_table.o gsm7_pack.o hexdigits.o hexout.o number_encode.o \ + timestamp.o ucs2_bigend.o utf8_decode.o utf8_decode2.o LIB= libcoding.a all: ${LIB}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcoding/alpha_addr.c Sun Aug 27 06:43:23 2023 +0000 @@ -0,0 +1,24 @@ +/* + * This library module implements encoding of alphanumeric From addresses + * that are allowed in SMS-DELIVER TPDUs. + */ + +#include <sys/types.h> + +u_char alpha_septets_to_digits[12] = {0, 2, 4, 6, 7, 9, 11, 13, 14, 16, 18, 20}; + +encode_alpha_addr(arg, bin) + char *arg; + u_char *bin; +{ + u_char gsm7[11]; + int rc; + + rc = qstring_arg_to_gsm7(arg, gsm7, 11); + if (rc < 0) + return(rc); + bin[0] = alpha_septets_to_digits[rc]; + bin[1] = 0x50; + gsm7_pack(gsm7, bin + 2, (bin[0] + 1) >> 1); + return(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcoding/gsm7_encode2.c Sun Aug 27 06:43:23 2023 +0000 @@ -0,0 +1,68 @@ +/* + * This module implements functions for parsing quoted string + * arguments intended for GSM7 string encoding, and actually + * encoding them into GSM7 binary strings. + */ + +#include <sys/types.h> +#include <ctype.h> +#include <stdio.h> + +extern u_char gsm7_encode_table[256]; + +qstring_arg_to_gsm7(arg, record, maxlen) + char *arg; + u_char *record; + unsigned maxlen; +{ + unsigned acclen, nadd; + char *cp; + int c; + + cp = arg; + for (acclen = 0; *cp; ) { + c = *cp++; + if (c == '\\') { + if (*cp == '\0') + return(-1); + c = *cp++; + if (c >= '0' && c <= '7' && isxdigit(*cp)) { + c = ((c - '0') << 4) | decode_hex_digit(*cp++); + goto bypass_encoding; + } + switch (c) { + case 'n': + c = '\n'; + goto bypass_encoding; + case 'r': + c = '\r'; + goto bypass_encoding; + case 'e': + c = 0x1B; + goto bypass_encoding; + case 'E': /* Euro currency symbol */ + c = 0xE5; + goto bypass_encoding; + case '"': + case '\\': + break; + default: + return(-1); + } + } + c = gsm7_encode_table[c]; + if (c == 0xFF) + return(-1); +bypass_encoding: + if (c & 0x80) + nadd = 2; + else + nadd = 1; + if (acclen + nadd > maxlen) + return(-1); + if (c & 0x80) + record[acclen++] = 0x1B; + record[acclen++] = c & 0x7F; + } + return(acclen); +}