blob: eba72dfdc88edb880ac7b2df2d38b8f1abc0bff0 [file] [log] [blame]
Jan Luebbefaaa49c2008-12-27 01:07:07 +00001/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
Holger Freyther12aa50d2009-01-01 18:02:05 +00002 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Jan Luebbefaaa49c2008-12-27 01:07:07 +00003 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01006 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
Jan Luebbefaaa49c2008-12-27 01:07:07 +00008 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Jan Luebbefaaa49c2008-12-27 01:07:07 +000017 *
18 */
19
20#include <openbsc/db.h>
Holger Hans Peter Freyther28dcbc52010-12-22 18:21:14 +010021#include <openbsc/gsm_subscriber.h>
Jan Luebbe7398eb92008-12-27 00:45:41 +000022
23#include <stdio.h>
Jan Luebbe5c15c852008-12-27 15:59:25 +000024#include <string.h>
Harald Welte12247c62009-05-21 07:23:02 +000025#include <stdlib.h>
Jan Luebbe7398eb92008-12-27 00:45:41 +000026
Holger Freyther12aa50d2009-01-01 18:02:05 +000027#define COMPARE(original, copy) \
28 if (original->id != copy->id) \
29 fprintf(stderr, "Ids do not match in %s:%d %llu %llu\n", \
30 __FUNCTION__, __LINE__, original->id, copy->id); \
31 if (original->lac != copy->lac) \
32 fprintf(stderr, "LAC do not match in %s:%d %d %d\n", \
33 __FUNCTION__, __LINE__, original->lac, copy->lac); \
34 if (original->authorized != copy->authorized) \
35 fprintf(stderr, "Authorize do not match in %s:%d %d %d\n", \
36 __FUNCTION__, __LINE__, original->authorized, \
37 copy->authorized); \
38 if (strcmp(original->imsi, copy->imsi) != 0) \
39 fprintf(stderr, "IMSIs do not match in %s:%d '%s' '%s'\n", \
40 __FUNCTION__, __LINE__, original->imsi, copy->imsi); \
Holger Hans Peter Freyther22230252009-08-19 12:53:57 +020041 if (original->tmsi != copy->tmsi) \
42 fprintf(stderr, "TMSIs do not match in %s:%d '%u' '%u'\n", \
Holger Freyther12aa50d2009-01-01 18:02:05 +000043 __FUNCTION__, __LINE__, original->tmsi, copy->tmsi); \
44 if (strcmp(original->name, copy->name) != 0) \
45 fprintf(stderr, "names do not match in %s:%d '%s' '%s'\n", \
46 __FUNCTION__, __LINE__, original->name, copy->name); \
47 if (strcmp(original->extension, copy->extension) != 0) \
48 fprintf(stderr, "names do not match in %s:%d '%s' '%s'\n", \
49 __FUNCTION__, __LINE__, original->extension, copy->extension); \
50
Jan Luebbe7398eb92008-12-27 00:45:41 +000051int main() {
52
Holger Freytherc7b86f92009-06-06 13:54:20 +000053 if (db_init("hlr.sqlite3")) {
Jan Luebbe5c15c852008-12-27 15:59:25 +000054 printf("DB: Failed to init database. Please check the option settings.\n");
55 return 1;
56 }
57 printf("DB: Database initialized.\n");
Jan Luebbe7398eb92008-12-27 00:45:41 +000058
Jan Luebbe5c15c852008-12-27 15:59:25 +000059 if (db_prepare()) {
60 printf("DB: Failed to prepare database.\n");
61 return 1;
62 }
63 printf("DB: Database prepared.\n");
Jan Luebbe7398eb92008-12-27 00:45:41 +000064
Jan Luebbe5c15c852008-12-27 15:59:25 +000065 struct gsm_subscriber *alice = NULL;
Holger Freyther12aa50d2009-01-01 18:02:05 +000066 struct gsm_subscriber *alice_db;
Jan Luebbe7398eb92008-12-27 00:45:41 +000067
Holger Freyther12aa50d2009-01-01 18:02:05 +000068 char *alice_imsi = "3243245432345";
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020069 alice = db_create_subscriber(NULL, alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000070 db_sync_subscriber(alice);
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020071 alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice->imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000072 COMPARE(alice, alice_db);
73 subscr_put(alice_db);
74 subscr_put(alice);
Jan Luebbe7398eb92008-12-27 00:45:41 +000075
Holger Freyther12aa50d2009-01-01 18:02:05 +000076 alice_imsi = "3693245423445";
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020077 alice = db_create_subscriber(NULL, alice_imsi);
Jan Luebbe391d86e2008-12-27 22:33:34 +000078 db_subscriber_assoc_imei(alice, "1234567890");
Jan Luebbe5c15c852008-12-27 15:59:25 +000079 db_subscriber_alloc_tmsi(alice);
80 alice->lac=42;
Holger Freyther12aa50d2009-01-01 18:02:05 +000081 db_sync_subscriber(alice);
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020082 alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000083 COMPARE(alice, alice_db);
84 subscr_put(alice);
85 subscr_put(alice_db);
Jan Luebbe7398eb92008-12-27 00:45:41 +000086
Holger Freyther12aa50d2009-01-01 18:02:05 +000087 alice_imsi = "9993245423445";
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020088 alice = db_create_subscriber(NULL, alice_imsi);
Jan Luebbe5c15c852008-12-27 15:59:25 +000089 db_subscriber_alloc_tmsi(alice);
90 alice->lac=42;
Holger Freyther12aa50d2009-01-01 18:02:05 +000091 db_sync_subscriber(alice);
Jan Luebbefac25fc2008-12-27 18:04:34 +000092 db_subscriber_assoc_imei(alice, "1234567890");
93 db_subscriber_assoc_imei(alice, "6543560920");
Holger Hans Peter Freytherb4564942009-07-29 06:46:07 +020094 alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice_imsi);
Holger Freyther12aa50d2009-01-01 18:02:05 +000095 COMPARE(alice, alice_db);
96 subscr_put(alice);
97 subscr_put(alice_db);
Jan Luebbe5c15c852008-12-27 15:59:25 +000098
99 db_fini();
100
101 return 0;
Jan Luebbe7398eb92008-12-27 00:45:41 +0000102}
Holger Freytherbab9cd92009-04-12 05:37:07 +0000103
104/* stubs */
105void input_event(void) {}
106void nm_state_event(void) {}
Holger Hans Peter Freyther763b42a2010-12-29 11:07:22 +0100107void vty_out() {}