Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 1 | /* (C) 2008 by Jan Luebbe <jluebbe@debian.org> |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 2 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (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 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <openbsc/db.h> |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <string.h> |
Harald Welte | 5bc7c17 | 2009-05-21 07:23:02 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 26 | |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 27 | #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); \ |
| 41 | if (strcmp(original->tmsi, copy->tmsi) != 0) \ |
| 42 | fprintf(stderr, "TMSIs do not match in %s:%d '%s' '%s'\n", \ |
| 43 | __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 | |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 51 | int main() { |
| 52 | |
Holger Freyther | 761fdec | 2009-06-06 13:54:20 +0000 | [diff] [blame] | 53 | if (db_init("hlr.sqlite3")) { |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 54 | printf("DB: Failed to init database. Please check the option settings.\n"); |
| 55 | return 1; |
| 56 | } |
| 57 | printf("DB: Database initialized.\n"); |
| 58 | |
| 59 | if (db_prepare()) { |
| 60 | printf("DB: Failed to prepare database.\n"); |
| 61 | return 1; |
| 62 | } |
| 63 | printf("DB: Database prepared.\n"); |
| 64 | |
| 65 | struct gsm_subscriber *alice = NULL; |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 66 | struct gsm_subscriber *alice_db; |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 67 | |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 68 | char *alice_imsi = "3243245432345"; |
Holger Hans Peter Freyther | f62324a | 2009-07-29 06:46:07 +0200 | [diff] [blame^] | 69 | alice = db_create_subscriber(NULL, alice_imsi); |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 70 | db_sync_subscriber(alice); |
Holger Hans Peter Freyther | f62324a | 2009-07-29 06:46:07 +0200 | [diff] [blame^] | 71 | alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice->imsi); |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 72 | COMPARE(alice, alice_db); |
| 73 | subscr_put(alice_db); |
| 74 | subscr_put(alice); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 75 | |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 76 | alice_imsi = "3693245423445"; |
Holger Hans Peter Freyther | f62324a | 2009-07-29 06:46:07 +0200 | [diff] [blame^] | 77 | alice = db_create_subscriber(NULL, alice_imsi); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 78 | db_subscriber_assoc_imei(alice, "1234567890"); |
| 79 | db_subscriber_alloc_tmsi(alice); |
| 80 | alice->lac=42; |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 81 | db_sync_subscriber(alice); |
Holger Hans Peter Freyther | f62324a | 2009-07-29 06:46:07 +0200 | [diff] [blame^] | 82 | alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice_imsi); |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 83 | COMPARE(alice, alice_db); |
| 84 | subscr_put(alice); |
| 85 | subscr_put(alice_db); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 86 | |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 87 | alice_imsi = "9993245423445"; |
Holger Hans Peter Freyther | f62324a | 2009-07-29 06:46:07 +0200 | [diff] [blame^] | 88 | alice = db_create_subscriber(NULL, alice_imsi); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 89 | db_subscriber_alloc_tmsi(alice); |
| 90 | alice->lac=42; |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 91 | db_sync_subscriber(alice); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 92 | db_subscriber_assoc_imei(alice, "1234567890"); |
| 93 | db_subscriber_assoc_imei(alice, "6543560920"); |
Holger Hans Peter Freyther | f62324a | 2009-07-29 06:46:07 +0200 | [diff] [blame^] | 94 | alice_db = db_get_subscriber(NULL, GSM_SUBSCRIBER_IMSI, alice_imsi); |
Holger Freyther | aa82f0d | 2009-01-01 18:02:05 +0000 | [diff] [blame] | 95 | COMPARE(alice, alice_db); |
| 96 | subscr_put(alice); |
| 97 | subscr_put(alice_db); |
Holger Freyther | c1e1192 | 2008-12-31 23:25:05 +0000 | [diff] [blame] | 98 | |
| 99 | db_fini(); |
| 100 | |
| 101 | return 0; |
| 102 | } |
Holger Freyther | 4b8eadf | 2009-04-12 05:37:07 +0000 | [diff] [blame] | 103 | |
| 104 | /* stubs */ |
| 105 | void input_event(void) {} |
| 106 | void nm_state_event(void) {} |