annotate libutil/number_decode.c @ 179:efe944a5c4e3

doc/Brute-force-search: update for data directory rename
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 02 Mar 2021 05:20:19 +0000
parents f064dbcc5f41
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements functions for decoding phone numbers.
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 static char gsm_address_digits[16] =
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 {'0','1','2','3','4','5','6','7','8','9','*','#','a','b','c','?'};
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 decode_phone_number(data, nbytes, out)
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 u_char *data;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 unsigned nbytes;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char *out;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 u_char *dp, *endp;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 int c;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 dp = data;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 endp = data + nbytes;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 while (dp < endp) {
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 c = *dp & 0xF;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (c == 0xF)
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(-1);
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 *out++ = gsm_address_digits[c];
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 c = *dp >> 4;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (c == 0xF) {
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (dp + 1 == endp)
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 break;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 else
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(-1);
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 *out++ = gsm_address_digits[c];
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 dp++;
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 *out = '\0';
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return(0);
4a9bf783491d phone number decoding factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
38
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
38
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
39 decode_address_digits(inbuf, outbuf, ndigits)
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
40 u_char *inbuf;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
41 char *outbuf;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
42 unsigned ndigits;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
43 {
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
44 u_char *inp = inbuf;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
45 char *outp = outbuf;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
46 unsigned n = 0, b;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
47
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
48 while (n < ndigits) {
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
49 b = *inp++;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
50 *outp++ = gsm_address_digits[b & 0xF];
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
51 n++;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
52 if (n >= ndigits)
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
53 break;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
54 *outp++ = gsm_address_digits[b >> 4];
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
55 n++;
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
56 }
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
57 *outp = '\0';
f5a26c1d0b93 fc-simtool smsp-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
58 }