aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libmsc/db.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsc/src/libmsc/db.c')
-rw-r--r--openbsc/src/libmsc/db.c56
1 files changed, 38 insertions, 18 deletions
diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index 4e20e2318..9f1fa9832 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -42,7 +42,7 @@ static char *db_basename = NULL;
static char *db_dirname = NULL;
static dbi_conn conn;
-#define SCHEMA_REVISION "3"
+#define SCHEMA_REVISION "50000000"
static char *create_stmts[] = {
"CREATE TABLE IF NOT EXISTS Meta ("
@@ -95,7 +95,6 @@ static char *create_stmts[] = {
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"created TIMESTAMP NOT NULL, "
"sent TIMESTAMP, "
- "sender_id INTEGER NOT NULL, "
"receiver_id INTEGER NOT NULL, "
"deliver_attempts INTEGER NOT NULL DEFAULT 0, "
/* data directly copied/derived from SMS */
@@ -105,7 +104,12 @@ static char *create_stmts[] = {
"protocol_id INTEGER NOT NULL, "
"data_coding_scheme INTEGER NOT NULL, "
"ud_hdr_ind INTEGER NOT NULL, "
- "dest_addr TEXT, "
+ "src_addr TEXT NOT NULL, "
+ "src_ton INTEGER NOT NULL, "
+ "src_npi INTEGER NOT NULL, "
+ "dest_addr TEXT NOT NULL, "
+ "dest_ton INTEGER NOT NULL, "
+ "dest_npi INTEGER NOT NULL, "
"user_data BLOB, " /* TP-UD */
/* additional data, interpreted from SMS */
"header BLOB, " /* UD Header */
@@ -1077,7 +1081,7 @@ int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char imei[GSM_IM
int db_sms_store(struct gsm_sms *sms)
{
dbi_result result;
- char *q_text, *q_daddr;
+ char *q_text, *q_daddr, *q_saddr;
unsigned char *q_udata;
char *validity_timestamp = "2222-2-2";
@@ -1085,25 +1089,35 @@ int db_sms_store(struct gsm_sms *sms)
dbi_conn_quote_string_copy(conn, (char *)sms->text, &q_text);
dbi_conn_quote_string_copy(conn, (char *)sms->dst.addr, &q_daddr);
+ dbi_conn_quote_string_copy(conn, (char *)sms->src.addr, &q_saddr);
dbi_conn_quote_binary_copy(conn, sms->user_data, sms->user_data_len,
&q_udata);
+
/* FIXME: correct validity period */
result = dbi_conn_queryf(conn,
"INSERT INTO SMS "
- "(created, sender_id, receiver_id, valid_until, "
+ "(created, receiver_id, valid_until, "
"reply_path_req, status_rep_req, protocol_id, "
- "data_coding_scheme, ud_hdr_ind, dest_addr, "
- "user_data, text) VALUES "
- "(datetime('now'), %llu, %llu, %u, "
- "%u, %u, %u, %u, %u, %s, %s, %s)",
- sms->sender->id,
+ "data_coding_scheme, ud_hdr_ind, "
+ "user_data, text, "
+ "dest_addr, dest_ton, dest_npi, "
+ "src_addr, src_ton, src_npi) VALUES "
+ "(datetime('now'), %llu, %u, "
+ "%u, %u, %u, "
+ "%u, %u, "
+ "%s, %s, "
+ "%s, %u, %u, "
+ "%s, %u, %u)",
sms->receiver ? sms->receiver->id : 0, validity_timestamp,
sms->reply_path_req, sms->status_rep_req, sms->protocol_id,
sms->data_coding_scheme, sms->ud_hdr_ind,
- q_daddr, q_udata, q_text);
+ q_udata, q_text,
+ q_daddr, sms->dst.ton, sms->dst.npi,
+ q_saddr, sms->src.ton, sms->src.npi);
free(q_text);
- free(q_daddr);
free(q_udata);
+ free(q_daddr);
+ free(q_saddr);
if (!result)
return -EIO;
@@ -1115,8 +1129,8 @@ int db_sms_store(struct gsm_sms *sms)
static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result result)
{
struct gsm_sms *sms = sms_alloc();
- long long unsigned int sender_id, receiver_id;
- const char *text, *daddr;
+ long long unsigned int receiver_id;
+ const char *text, *daddr, *saddr;
const unsigned char *user_data;
if (!sms)
@@ -1124,10 +1138,6 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
sms->id = dbi_result_get_ulonglong(result, "id");
- sender_id = dbi_result_get_ulonglong(result, "sender_id");
- sms->sender = subscr_get_by_id(net, sender_id);
- strncpy(sms->src.addr, sms->sender->extension, sizeof(sms->src.addr)-1);
-
receiver_id = dbi_result_get_ulonglong(result, "receiver_id");
sms->receiver = subscr_get_by_id(net, receiver_id);
@@ -1141,12 +1151,22 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
"data_coding_scheme");
/* sms->msg_ref is temporary and not stored in DB */
+ sms->dst.npi = dbi_result_get_uint(result, "dest_npi");
+ sms->dst.ton = dbi_result_get_uint(result, "dest_ton");
daddr = dbi_result_get_string(result, "dest_addr");
if (daddr) {
strncpy(sms->dst.addr, daddr, sizeof(sms->dst.addr));
sms->dst.addr[sizeof(sms->dst.addr)-1] = '\0';
}
+ sms->src.npi = dbi_result_get_uint(result, "src_npi");
+ sms->src.ton = dbi_result_get_uint(result, "src_ton");
+ saddr = dbi_result_get_string(result, "src_addr");
+ if (saddr) {
+ strncpy(sms->src.addr, saddr, sizeof(sms->src.addr));
+ sms->src.addr[sizeof(sms->src.addr)-1] = '\0';
+ }
+
sms->user_data_len = dbi_result_get_field_length(result, "user_data");
user_data = dbi_result_get_binary(result, "user_data");
if (sms->user_data_len > sizeof(sms->user_data))