FreeCalypso > hg > sms-coding-utils
changeset 26:c8cb05b69118
libcoding alpha addr: support both encoding and decoding
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 13 Jun 2024 01:55:19 +0000 |
parents | 2a19b44c272e |
children | 7418ca2e9949 |
files | libcoding/Makefile libcoding/alpha_addr.c libcoding/alpha_addr_enc.c |
diffstat | 3 files changed, 37 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/libcoding/Makefile Tue May 21 01:59:17 2024 +0000 +++ b/libcoding/Makefile Thu Jun 13 01:55:19 2024 +0000 @@ -1,6 +1,6 @@ -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 +OBJS= alpha_addr.o alpha_addr_enc.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 include ../config.defs
--- a/libcoding/alpha_addr.c Tue May 21 01:59:17 2024 +0000 +++ b/libcoding/alpha_addr.c Thu Jun 13 01:55:19 2024 +0000 @@ -1,24 +1,21 @@ /* - * This library module implements encoding of alphanumeric From addresses - * that are allowed in SMS-DELIVER TPDUs. + * This library module contains some bits that help working with + * alphabetic addresses. */ #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; +alpha_addr_valid(ndigits, sepp) + unsigned ndigits, *sepp; { - u_char gsm7[11]; - int rc; + unsigned n; - 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); + for (n = 1; n <= 11; n++) + if (alpha_septets_to_digits[n] == ndigits) { + *sepp = n; + return(1); + } return(0); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libcoding/alpha_addr_enc.c Thu Jun 13 01:55:19 2024 +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> + +extern u_char alpha_septets_to_digits[12]; + +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); +}