annotate libutil/imsi_entry.c @ 63:e5aee661e3b2

sip-in: beginning to handle incoming MNCC messages from themwi-mncc
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 18 Sep 2022 15:01:11 -0800
parents 40e5097437fa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The library function implemented in this module supports IMSI entry
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * at UI level, either in the standard form (long string of digits)
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * or in the shorthand notation introduced in fc-sim-tools.
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 grok_imsi_user_arg(arg, dest)
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char *arg, *dest;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char *cp, *dp;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int n, tail_len, remain;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 if (!isdigit(*arg))
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 return(-1);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 cp = arg;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 dp = dest;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 n = 0;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 while (isdigit(*cp)) {
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (n >= 15)
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return(-1);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 *dp++ = *cp++;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 n++;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!*cp) {
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (n < 6)
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(-1);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 *dp = '\0';
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(0);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (*cp != '-')
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(-1);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 cp++;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 tail_len = strlen(cp);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (!tail_len)
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(-1);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 remain = 15 - n;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (remain < tail_len + 1)
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return(-1);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 while (remain > tail_len) {
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 *dp++ = '0';
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 remain--;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 while (*cp) {
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (!isdigit(*cp))
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return(-1);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 *dp++ = *cp++;
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *dp = '\0';
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return(0);
40e5097437fa libutil: add grok_imsi_user_arg()
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }