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