more wip sms_storage

This commit is contained in:
Harald Welte 2022-05-25 17:04:43 +02:00
parent 2722fbacda
commit 8ec1e3b61d
19 changed files with 27 additions and 1137 deletions

View File

@ -36,7 +36,6 @@ if test "x$PKG_CONFIG_INSTALLED" = "xno"; then
fi
PKG_PROG_PKG_CONFIG([0.20])
PKG_CHECK_MODULES(LIBSQLITE3, sqlite3)
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.6.0)
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.6.0)
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.6.0)

View File

@ -32,7 +32,6 @@ BuildRequires: libtool
BuildRequires: systemd-rpm-macros
%endif
BuildRequires: pkgconfig >= 0.20
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(libcrypto) >= 0.9.5
BuildRequires: pkgconfig(libosmo-gsup-client) >= 1.4.0
BuildRequires: pkgconfig(libosmo-mgcp-client) >= 1.9.0

1
debian/control vendored
View File

@ -9,7 +9,6 @@ Build-Depends: debhelper (>=9),
automake,
libtool,
pkg-config,
libsqlite3-dev,
libsctp-dev,
libtalloc-dev,
libsmpp34-dev (>= 1.14.0),

View File

@ -1,7 +1,6 @@
noinst_HEADERS = \
call_leg.h \
cell_id_list.h \
db.h \
debug.h \
e_link.h \
gsm_04_08.h \
@ -47,6 +46,7 @@ noinst_HEADERS = \
silent_call.h \
smpp.h \
sms_queue.h \
sms_storage.h \
transaction.h \
vlr.h \
vlr_sgs.h \

View File

@ -1,56 +0,0 @@
/* (C) 2008 by Jan Luebbe <jluebbe@debian.org>
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2022 by Harald Welte <laforge@osmocom.org>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _DB_H
#define _DB_H
#include <stdbool.h>
#include "gsm_subscriber.h"
#define VSUB_USE_SMS_RECEIVER "SMS-receiver"
struct gsm_network;
struct gsm_sms;
/* one time initialisation */
int db_init(void *ctx, const char *fname, bool enable_sqlite_logging);
int db_prepare(void);
int db_fini(void);
/* SMS store-and-forward */
int db_sms_store(struct gsm_sms *sms);
struct gsm_sms *db_sms_get(struct gsm_network *net, unsigned long long id);
struct gsm_sms *db_sms_get_next_unsent(struct gsm_network *net,
unsigned long long min_sms_id,
int max_failed);
struct gsm_sms *db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net,
const char *last_msisdn,
int max_failed);
struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub,
int max_failed);
int db_sms_mark_delivered(struct gsm_sms *sms);
int db_sms_inc_deliver_attempts(struct gsm_sms *sms);
int db_sms_delete_by_msisdn(const char *msisdn);
int db_sms_delete_sent_message_by_id(unsigned long long sms_id);
int db_sms_delete_expired_message_by_id(unsigned long long sms_id);
void db_sms_delete_oldest_expired_message(void);
#endif /* _DB_H */

View File

@ -182,6 +182,7 @@ struct gsm_network {
} rrlp;
struct gsm_sms_queue *sms_queue;
struct sms_storage_inst *sms_storage;
/* The "SMS over GSUP" kill-switch that basically breaks internal
* SMS routing (i.e. SQLite DB and SMPP), and enables forwarding
@ -318,6 +319,8 @@ struct gsm_sms {
uint8_t user_data_len;
uint8_t user_data[SMS_TEXT_SIZE];
int failed_attempts;
char text[SMS_TEXT_SIZE];
};

View File

@ -21,6 +21,7 @@ struct sms_queue_config *sms_queue_cfg_alloc(void *ctx);
#define VSUB_USE_SMS_PENDING "SMS-pending"
#define MSC_A_USE_SMS_PENDING "SMS-pending"
#define VSUB_USE_SMS_RECEIVER "SMS-receiver"
int sms_queue_start(struct gsm_network *net);
int sms_queue_trigger(struct gsm_sms_queue *);

View File

@ -199,6 +199,10 @@ struct vlr_subscr {
struct osmo_plmn_id last_eutran_plmn;
} sgs;
struct {
struct llist_head pending;
} sms;
struct osmo_gsm48_classmark classmark;
};

View File

@ -32,7 +32,6 @@ libmsc_a_SOURCES = \
cell_id_list.c \
sccp_ran.c \
msc_vty.c \
db.c \
e_link.c \
gsm_04_08.c \
gsm_04_08_cc.c \

View File

@ -23,7 +23,6 @@
#include <osmocom/core/utils.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/gsm_subscriber.h>
#include <osmocom/msc/db.h>
#include <osmocom/msc/debug.h>
#include <osmocom/msc/vlr.h>

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,6 @@
#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
#include <osmocom/msc/db.h>
#include <osmocom/msc/debug.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/gsm_subscriber.h>

View File

@ -47,11 +47,10 @@
#include <osmocom/msc/debug.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/db.h>
#include <osmocom/msc/sms_storage.h>
#include <osmocom/msc/gsm_subscriber.h>
#include <osmocom/msc/gsm_04_08.h>
#include <osmocom/msc/signal.h>
#include <osmocom/msc/db.h>
#include <osmocom/msc/transaction.h>
#include <osmocom/msc/vlr.h>
#include <osmocom/msc/msub.h>
@ -286,7 +285,7 @@ int gsm411_mn_send(struct gsm411_smr_inst *inst, int msg_type,
static int gsm340_rx_sms_submit(struct gsm_trans *trans, struct gsm_sms *gsms)
{
if (db_sms_store(gsms) != 0) {
if (sms_storage_to_disk_req(trans->net->sms_storage, gsms) != 0) {
LOG_TRANS(trans, LOGL_ERROR, "Failed to store SMS in Database\n");
return GSM411_RP_CAUSE_MO_NET_OUT_OF_ORDER;
}
@ -892,7 +891,7 @@ static int gsm411_rx_rp_ack(struct gsm_trans *trans,
}
/* mark this SMS as sent in database */
db_sms_mark_delivered(sms);
sms_storage_delete_from_disk_req(trans->net->sms_storage, sms->id, SMSS_DELETE_CAUSE_DELIVERED);
send_signal(S_SMS_DELIVERED, trans, sms, 0);
@ -1249,7 +1248,6 @@ int gsm411_send_sms(struct gsm_network *net,
trans->sms.sms = sms;
rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, MSC_CTR_SMS_DELIVERED));
db_sms_inc_deliver_attempts(trans->sms.sms);
return gsm411_rp_sendmsg(&trans->sms.smr_inst, msg,
GSM411_MT_RP_DATA_MT, trans->sms.sm_rp_mr,

View File

@ -54,8 +54,8 @@
#include <osmocom/msc/msc_a.h>
#include <osmocom/msc/vlr.h>
#include <osmocom/msc/transaction.h>
#include <osmocom/msc/db.h>
#include <osmocom/msc/sms_queue.h>
#include <osmocom/msc/sms_storage.h>
#include <osmocom/msc/silent_call.h>
#include <osmocom/msc/gsm_04_80.h>
#include <osmocom/msc/gsm_04_14.h>

View File

@ -40,7 +40,7 @@
#include <osmocom/msc/gsm_subscriber.h>
#include <osmocom/msc/debug.h>
#include <osmocom/msc/db.h>
#include <osmocom/msc/sms_storage.h>
#include <osmocom/msc/gsm_04_11.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/signal.h>
@ -300,8 +300,7 @@ int handle_smpp_submit(struct osmo_esme *esme, struct submit_sm_t *submit,
case 0: /* default */
case 1: /* datagram */
case 3: /* store-and-forward */
rc = db_sms_store(sms);
sms_free(sms);
rc = sms_storage_to_disk_req(net->sms_storage, sms);
sms = NULL;
if (rc < 0) {
LOGP(DLSMS, LOGL_ERROR, "SMPP SUBMIT-SM: Unable to "

View File

@ -1,6 +1,7 @@
/* SMS queue to continuously attempt to deliver SMS */
/*
* (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2022 by Harald Welte <laforge@osmocom.org>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
@ -31,7 +32,7 @@
#include <limits.h>
#include <osmocom/msc/sms_queue.h>
#include <osmocom/msc/db.h>
#include <osmocom/msc/sms_storage.h>
#include <osmocom/msc/debug.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/gsm_04_11.h>
@ -109,6 +110,7 @@ static const struct rate_ctr_group_desc smsq_ctrg_desc = {
* a pointer to the database record. It holds a reference on the vlr_subscriber
* and some counters. While this object exists in RAM, we are regularly attempting
* to deliver the related SMS. */
#if 0
struct gsm_sms_pending {
struct llist_head entry; /* gsm_sms_queue.pending_sms */
@ -118,6 +120,7 @@ struct gsm_sms_pending {
int failed_attempts; /* count of failed deliver attempts so far */
int resend; /* should we try re-sending it (now) ? */
};
#endif
/* (global) state of the SMS queue. */
struct gsm_sms_queue {
@ -616,15 +619,12 @@ static int sms_sms_cb(unsigned int subsys, unsigned int signal,
switch (signal) {
case S_SMS_DELIVERED:
smsq_rate_ctr_inc(smq, SMSQ_CTR_SMS_DELIVERY_ACK);
/* Remember the subscriber and clear the pending entry */
vsub = pending->vsub;
vlr_subscr_get(vsub, __func__);
if (smq->cfg->delete_delivered)
db_sms_delete_sent_message_by_id(pending->sms_id);
sms_pending_free(smq, pending);
/* ask SMS thread to delete message from storage */
ms_storage_delete_from_disk_req(network->sms_storage, sms->id,
SMSS_DELETE_CAUSE_DELIVERED);
sms_free(network->sms_storage, sms);
/* Attempt to send another SMS to this subscriber */
sms_send_next(vsub);
vlr_subscr_put(vsub, __func__);
break;
case S_SMS_MEM_EXCEEDED:
smsq_rate_ctr_inc(smq, SMSQ_CTR_SMS_DELIVERY_NOMEM);
@ -657,10 +657,6 @@ static int sms_sms_cb(unsigned int subsys, unsigned int signal,
sig_sms->paging_result);
}
/* While here, attempt to remove an expired SMS from the DB. */
if (smq->cfg->delete_expired)
db_sms_delete_oldest_expired_message();
return 0;
}

View File

@ -82,15 +82,7 @@
#include <osmocom/msc/debug.h>
#include <osmocom/msc/gsm_data.h>
#include <osmocom/msc/gsm_04_11.h>
/* configuration of SMS storage */
struct sms_storage_cfg {
char storage_dir[PATH_MAX+1];
/* unlink messages after delivery, or just move them? */
bool unlink_delivered;
/* unlink messages after expiration, or just move them? */
bool unlink_expired;
};
#include <osmocom/msc/sms_storage.h>
/* all the state of a SMS storage instance */
struct sms_storage_inst {
@ -167,12 +159,6 @@ enum smss_m2s_op {
SMSS_M2S_OP_SMS_DELETE_FROM_DISK_REQ,
};
enum smss_delete_cause {
SMSS_DELETE_CAUSE_UNKNOWN,
SMSS_DELETE_CAUSE_DELIVERED,
SMSS_DELETE_CAUSE_EXPIRED,
};
struct smss_m2s_evt {
struct llist_head list;
@ -770,6 +756,7 @@ static void storage2main_read_cb(struct osmo_it_q *q, struct llist_head *item)
switch (evt->op) {
case SMSS_S2M_OP_NULL:
break;
case SMSS_S2M_OP_SMS_FROM_DISK_IND:
/* SMS storage has read a SMS from disk, asks main thread to add it to queue */
break;

View File

@ -402,6 +402,7 @@ static struct vlr_subscr *_vlr_subscr_alloc(struct vlr_instance *vlr)
INIT_LLIST_HEAD(&vsub->cs.requests);
INIT_LLIST_HEAD(&vsub->ps.pdp_list);
INIT_LLIST_HEAD(&vsub->sms.pending);
/* Create an SGs FSM, which is needed to control CSFB,
* in cases where CSFB/SGs is not in use, this FSM will

View File

@ -39,7 +39,7 @@
/* build switches from the configure script */
#include "config.h"
#include <osmocom/msc/db.h>
#include <osmocom/msc/sms_storage.h>
#include <osmocom/core/application.h>
#include <osmocom/core/select.h>
#include <osmocom/core/stats.h>
@ -790,7 +790,6 @@ TODO: we probably want some of the _net_ ctrl commands from bsc_base_ctrl_cmds_i
}
} while (!osmo_select_shutdown_done());
db_fini();
log_fini();
/**