Jan Luebbe | faaa49c | 2008-12-27 01:07:07 +0000 | [diff] [blame] | 1 | /* (C) 2008 by Jan Luebbe <jluebbe@debian.org> |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <openbsc/db.h> |
Jan Luebbe | 7398eb9 | 2008-12-27 00:45:41 +0000 | [diff] [blame] | 21 | |
| 22 | #include <stdio.h> |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 23 | #include <string.h> |
Harald Welte | 255539c | 2008-12-28 02:26:27 +0000 | [diff] [blame] | 24 | #include <malloc.h> |
Jan Luebbe | 7398eb9 | 2008-12-27 00:45:41 +0000 | [diff] [blame] | 25 | |
| 26 | int main() { |
| 27 | |
Holger Freyther | bde3610 | 2008-12-28 22:51:39 +0000 | [diff] [blame] | 28 | if (db_init("hlr.sqlite3")) { |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 29 | printf("DB: Failed to init database. Please check the option settings.\n"); |
| 30 | return 1; |
| 31 | } |
| 32 | printf("DB: Database initialized.\n"); |
Jan Luebbe | 7398eb9 | 2008-12-27 00:45:41 +0000 | [diff] [blame] | 33 | |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 34 | if (db_prepare()) { |
| 35 | printf("DB: Failed to prepare database.\n"); |
| 36 | return 1; |
| 37 | } |
| 38 | printf("DB: Database prepared.\n"); |
Jan Luebbe | 7398eb9 | 2008-12-27 00:45:41 +0000 | [diff] [blame] | 39 | |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 40 | struct gsm_subscriber *alice = NULL; |
Jan Luebbe | 7398eb9 | 2008-12-27 00:45:41 +0000 | [diff] [blame] | 41 | |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 42 | alice = db_create_subscriber("3243245432345"); |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 43 | db_set_subscriber(alice); |
| 44 | db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice); |
| 45 | free(alice); |
Jan Luebbe | 7398eb9 | 2008-12-27 00:45:41 +0000 | [diff] [blame] | 46 | |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 47 | alice = db_create_subscriber("3693245423445"); |
Jan Luebbe | 391d86e | 2008-12-27 22:33:34 +0000 | [diff] [blame] | 48 | db_subscriber_assoc_imei(alice, "1234567890"); |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 49 | db_subscriber_alloc_tmsi(alice); |
| 50 | alice->lac=42; |
| 51 | db_set_subscriber(alice); |
| 52 | db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice); |
| 53 | free(alice); |
Jan Luebbe | 7398eb9 | 2008-12-27 00:45:41 +0000 | [diff] [blame] | 54 | |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 55 | alice = db_create_subscriber("9993245423445"); |
| 56 | db_subscriber_alloc_tmsi(alice); |
| 57 | alice->lac=42; |
| 58 | db_set_subscriber(alice); |
Jan Luebbe | fac25fc | 2008-12-27 18:04:34 +0000 | [diff] [blame] | 59 | db_subscriber_assoc_imei(alice, "1234567890"); |
| 60 | db_subscriber_assoc_imei(alice, "6543560920"); |
Jan Luebbe | 5c15c85 | 2008-12-27 15:59:25 +0000 | [diff] [blame] | 61 | db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice); |
| 62 | free(alice); |
| 63 | |
| 64 | db_fini(); |
| 65 | |
| 66 | return 0; |
Jan Luebbe | 7398eb9 | 2008-12-27 00:45:41 +0000 | [diff] [blame] | 67 | } |