Skip to content

Commit

Permalink
mqueue: add support for db persistency
Browse files Browse the repository at this point in the history
  • Loading branch information
jchavanton committed Jun 30, 2020
1 parent 1189d75 commit c85da32
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/modules/mqueue/Makefile
Expand Up @@ -6,4 +6,6 @@ auto_gen=
NAME=mqueue.so
LIBS=

SERLIBPATH=../../lib
SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1
include ../../Makefile.modules
2 changes: 1 addition & 1 deletion src/modules/mqueue/doc/mqueue.xml
Expand Up @@ -46,7 +46,7 @@
<holder>Elena-Ramona Modroiu (asipto.com)</holder>
</copyright>
<copyright>
<year>2018</year>
<year>2018-2020</year>
<holder>Julien chavanton, Flowroute</holder>
</copyright>
</bookinfo>
Expand Down
36 changes: 36 additions & 0 deletions src/modules/mqueue/doc/mqueue_admin.xml
Expand Up @@ -61,6 +61,32 @@
<section>
<title>Parameters</title>

<section id="mqueue.p.db_url">
<title><varname>db_url</varname> (str)</title>
<para>
The <acronym>URL</acronym> to connect to database for loading values in mqueue table at start up and/or saving values at shutdown.
</para>
<para>
<emphasis>
Default value is NULL (do not connect).
</emphasis>
</para>
<example>
<title>Set <varname>db_url</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("mqueue", "db_url", "&defaultdb;")

# Example of table in sqlite, you have the set the fields to support the length according to the data that will be present in the mqueue
CREATE TABLE mqueue_name (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key character varying(64) DEFAULT "" NOT NULL,
val character varying(4096) DEFAULT "" NOT NULL
);
...
</programlisting>
</example>
</section>
<section id="mqueue.p.mqueue">
<title><varname>mqueue</varname> (string)</title>
<para>
Expand Down Expand Up @@ -95,6 +121,16 @@
If not set the queue will be limitless.
</para>
</listitem>
<listitem>
<para>
<emphasis>dbmode</emphasis>: If set to 1, the content of the queue
is written to database table when the SIP server is stopped
(i.e., ensure persistency over restarts).
If set to 2, it is written at shutdown but not read at startup.
If set to 3, it is read at sartup but not written at shutdown.
Default value is 0 (no db table interaction).
</para>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
Expand Down
28 changes: 27 additions & 1 deletion src/modules/mqueue/mqueue_api.c
Expand Up @@ -34,7 +34,7 @@
#include "../../core/fmsg.h"

#include "mqueue_api.h"

#include "mqueue_db.h"

/**
*
Expand Down Expand Up @@ -71,6 +71,11 @@ void mq_destroy(void)
mh = _mq_head_list;
while(mh!=NULL)
{
if(mh->dbmode == 1 || mh->dbmode == 3)
{
LM_INFO("mqueue[%.*s] dbmode[%d]\n", mh->name.len, mh->name.s, mh->dbmode);
mqueue_db_save_queue(&mh->name);
}
mi = mh->ifirst;
while(mi!=NULL)
{
Expand Down Expand Up @@ -180,6 +185,27 @@ mq_head_t *mq_head_get(str *name)
return NULL;
}

/**
*
*/
int mq_set_dbmode(str *name, int dbmode)
{
mq_head_t *mh = NULL;

mh = _mq_head_list;
while(mh!=NULL)
{
if(name->len == mh->name.len
&& strncmp(mh->name.s, name->s, name->len)==0)
{
mh->dbmode = dbmode;
return 0;
}
mh = mh->next;
}
return -1;
}

/**
*
*/
Expand Down
3 changes: 2 additions & 1 deletion src/modules/mqueue/mqueue_api.h
Expand Up @@ -44,6 +44,7 @@ typedef struct _mq_head
str name;
int msize;
int csize;
int dbmode;
gen_lock_t lock;
mq_item_t *ifirst;
mq_item_t *ilast;
Expand All @@ -61,7 +62,6 @@ typedef struct _mq_pv
} mq_pv_t;

mq_pv_t *mq_pv_get(str *name);

int pv_parse_mq_name(pv_spec_p sp, str *in);
int pv_get_mqk(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
Expand All @@ -79,6 +79,7 @@ void mq_pv_free(str *name);
int mq_item_add(str *qname, str *key, str *val);

int _mq_get_csize(str *);
int mq_set_dbmode(str *, int dbmode);

#endif

0 comments on commit c85da32

Please sign in to comment.