comparison libcoding/alpha_addr.c @ 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 5854e48d0ef7
children
comparison
equal deleted inserted replaced
25:2a19b44c272e 26:c8cb05b69118
1 /* 1 /*
2 * This library module implements encoding of alphanumeric From addresses 2 * This library module contains some bits that help working with
3 * that are allowed in SMS-DELIVER TPDUs. 3 * alphabetic addresses.
4 */ 4 */
5 5
6 #include <sys/types.h> 6 #include <sys/types.h>
7 7
8 u_char alpha_septets_to_digits[12] = {0, 2, 4, 6, 7, 9, 11, 13, 14, 16, 18, 20}; 8 u_char alpha_septets_to_digits[12] = {0, 2, 4, 6, 7, 9, 11, 13, 14, 16, 18, 20};
9 9
10 encode_alpha_addr(arg, bin) 10 alpha_addr_valid(ndigits, sepp)
11 char *arg; 11 unsigned ndigits, *sepp;
12 u_char *bin;
13 { 12 {
14 u_char gsm7[11]; 13 unsigned n;
15 int rc;
16 14
17 rc = qstring_arg_to_gsm7(arg, gsm7, 11); 15 for (n = 1; n <= 11; n++)
18 if (rc < 0) 16 if (alpha_septets_to_digits[n] == ndigits) {
19 return(rc); 17 *sepp = n;
20 bin[0] = alpha_septets_to_digits[rc]; 18 return(1);
21 bin[1] = 0x50; 19 }
22 gsm7_pack(gsm7, bin + 2, (bin[0] + 1) >> 1);
23 return(0); 20 return(0);
24 } 21 }