FreeCalypso > hg > fc-sim-tools
annotate simtool/sws.c @ 30:25530c262137
fc-simtool sws-lookup implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Mar 2021 00:19:18 +0000 |
parents | |
children | cca7d0528f89 |
rev | line source |
---|---|
30
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements a few high-level commands for working with |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * Sysmocom webshop SIM cards, using sws-card-db to look up per-card data. |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "../libutil/dbread.h" |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 static char sws_card_db_file[] = "/opt/freecalypso/sim-data/sws-card-db"; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 static |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 lookup_sws_card(dbs) |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 struct dbread_state *dbs; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 int rc; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char iccid[21]; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 rc = retrieve_iccid(iccid); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (rc < 0) |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 return(rc); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return dbread_find_record(sws_card_db_file, dbs, "ICCID", iccid); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 cmd_sws_lookup(argc, argv, outf) |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 char **argv; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 FILE *outf; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 { |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 int rc; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 struct dbread_state dbs; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 char **kp, *val; |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 rc = lookup_sws_card(&dbs); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (rc < 0) |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(rc); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (argc == 2) { |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 val = dbread_find_key_req(&dbs, argv[1]); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (!val) |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 return(-1); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 fprintf(outf, "%s\n", val); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(0); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 for (kp = argv + 1; *kp; kp++) { |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 val = dbread_find_key(&dbs, *kp); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (val) |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 fprintf(outf, "%s=%s\n", *kp, val); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return(0); |
25530c262137
fc-simtool sws-lookup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |