blob: fc1781bd6032bc30d66d6e09d92e7f8e678b48b6 [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>
Harald Welted43c22e2022-05-14 15:35:49 +02003 * (C) 2022 by Harald Welte <laforge@osmocom.org>
Jan Luebbefaaa49c2008-12-27 01:07:07 +00004 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Jan Luebbefaaa49c2008-12-27 01:07:07 +00009 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Jan Luebbefaaa49c2008-12-27 01:07:07 +000015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Jan Luebbefaaa49c2008-12-27 01:07:07 +000018 *
19 */
20
21#ifndef _DB_H
22#define _DB_H
23
Maxe6052c42016-06-30 10:25:49 +020024#include <stdbool.h>
25
Holger Hans Peter Freyther81863cd2011-04-12 21:33:35 +020026#include "gsm_subscriber.h"
Jan Luebbefaaa49c2008-12-27 01:07:07 +000027
Neels Hofmeyr7c5346c2019-02-19 02:36:35 +010028#define VSUB_USE_SMS_RECEIVER "SMS-receiver"
29
Holger Hans Peter Freyther28dcbc52010-12-22 18:21:14 +010030struct gsm_network;
Holger Hans Peter Freyther28dcbc52010-12-22 18:21:14 +010031struct gsm_sms;
Holger Hans Peter Freyther28dcbc52010-12-22 18:21:14 +010032
Holger Freyther12aa50d2009-01-01 18:02:05 +000033/* one time initialisation */
Harald Welted43c22e2022-05-14 15:35:49 +020034int db_init(void *ctx, const char *fname, bool enable_sqlite_logging);
Harald Welted1476bc2011-07-16 13:24:09 +020035int db_prepare(void);
36int db_fini(void);
Jan Luebbefaaa49c2008-12-27 01:07:07 +000037
Harald Welte7e310b12009-03-30 20:56:32 +000038/* SMS store-and-forward */
39int db_sms_store(struct gsm_sms *sms);
Holger Hans Peter Freyther812dad02010-12-24 23:18:31 +010040struct gsm_sms *db_sms_get(struct gsm_network *net, unsigned long long id);
Harald Welte2483f1b2016-06-19 18:06:02 +020041struct gsm_sms *db_sms_get_next_unsent(struct gsm_network *net,
42 unsigned long long min_sms_id,
Harald Welted43c22e2022-05-14 15:35:49 +020043 int max_failed);
Harald Welte2483f1b2016-06-19 18:06:02 +020044struct gsm_sms *db_sms_get_next_unsent_rr_msisdn(struct gsm_network *net,
45 const char *last_msisdn,
Harald Welted43c22e2022-05-14 15:35:49 +020046 int max_failed);
Harald Welte2483f1b2016-06-19 18:06:02 +020047struct gsm_sms *db_sms_get_unsent_for_subscr(struct vlr_subscr *vsub,
Harald Welted43c22e2022-05-14 15:35:49 +020048 int max_failed);
Alexander Chemeris1e77e3d2014-03-08 21:27:37 +010049int db_sms_mark_delivered(struct gsm_sms *sms);
Holger Hans Peter Freyther212e1052010-09-17 00:35:46 +080050int db_sms_inc_deliver_attempts(struct gsm_sms *sms);
Harald Welte2483f1b2016-06-19 18:06:02 +020051int db_sms_delete_by_msisdn(const char *msisdn);
Stefan Sperling6ba2d5a2018-01-18 18:55:26 +010052int db_sms_delete_sent_message_by_id(unsigned long long sms_id);
Stefan Sperling87cba1f2018-01-22 17:05:37 +010053int db_sms_delete_expired_message_by_id(unsigned long long sms_id);
Stefan Sperling14e05172018-01-22 17:31:20 +010054void db_sms_delete_oldest_expired_message(void);
Harald Welteffa55a42009-12-22 19:07:32 +010055
Jan Luebbefaaa49c2008-12-27 01:07:07 +000056#endif /* _DB_H */