Module: kamailio
Branch: master
Commit: a8d4236070f69c6fd9c83dedd9c007facc34f70d
URL:
https://github.com/kamailio/kamailio/commit/a8d4236070f69c6fd9c83dedd9c007f…
Author: Stefan Mititelu <stefan-cristian.mititelu(a)1and1.ro>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-08-28T20:17:30+02:00
mqueue: add two new module parameters
Add mqueue_name and mqueue_size to define queues.
Updated doc.
---
Modified: src/modules/mqueue/doc/mqueue_admin.xml
Modified: src/modules/mqueue/mqueue_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/a8d4236070f69c6fd9c83dedd9c007f…
Patch:
https://github.com/kamailio/kamailio/commit/a8d4236070f69c6fd9c83dedd9c007f…
---
diff --git a/src/modules/mqueue/doc/mqueue_admin.xml
b/src/modules/mqueue/doc/mqueue_admin.xml
index 7d785ac90b..9cdf57cfa4 100644
--- a/src/modules/mqueue/doc/mqueue_admin.xml
+++ b/src/modules/mqueue/doc/mqueue_admin.xml
@@ -150,6 +150,64 @@ modparam("mqueue", "mqueue",
"name=qaz")
</example>
</section>
+
+ <section id="mqueue.p.mqueue_name">
+ <title><varname>mqueue_name</varname> (string)</title>
+ <para>
+ Definition of a memory queue, just by name.
+ </para>
+ <para>
+ <emphasis>
+ Default value is <quote>none</quote>.
+ </emphasis>
+ </para>
+ <para>
+ Value must be a string.
+ </para>
+ <para>
+ The parameter can be set many times, each holding the definition of one queue.
+
+ The max size of each queue defined this way will be equal to mqueue_size(if mqueue_size
configured),
+ or limitless (if mqueue_size not configured).
+ </para>
+ <example>
+ <title>Set <varname>mqueue_name</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("mqueue", "mqueue_name", "my_own_queue")
+...
+ </programlisting>
+ </example>
+ </section>
+
+ <section id="mqueue.p.mqueue_size">
+ <title><varname>mqueue_size</varname> (int)</title>
+ <para>
+ Definition of the size of all memory queues defined via "mqueue_name"
parameter.
+ </para>
+ <para>
+ <emphasis>
+ Default value is <quote>0</quote>.
+ </emphasis>
+ </para>
+ <para>
+ Value must be an int.
+ </para>
+ <para>
+ The parameter should be set before defining any "mqueue_name".
+ If not set, the queues defined via "mqueue_name" will be limitless.
+ </para>
+ <example>
+ <title>Set <varname>mqueue_size</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("mqueue", "mqueue_size", 1024)
+...
+ </programlisting>
+ </example>
+ </section>
+
+
</section>
<section>
diff --git a/src/modules/mqueue/mqueue_mod.c b/src/modules/mqueue/mqueue_mod.c
index 325c84b472..154f5b5d81 100644
--- a/src/modules/mqueue/mqueue_mod.c
+++ b/src/modules/mqueue/mqueue_mod.c
@@ -50,11 +50,14 @@ static int w_mq_size(struct sip_msg *msg, char *mq, char *str2);
static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val);
static int w_mq_pv_free(struct sip_msg* msg, char* mq, char* str2);
int mq_param(modparam_t type, void *val);
+int mq_param_name(modparam_t type, void *val);
static int fixup_mq_add(void** param, int param_no);
static int bind_mq(mq_api_t* api);
static int mqueue_rpc_init(void);
+static int mqueue_size = 0;
+
static pv_export_t mod_pvs[] = {
{ {"mqk", sizeof("mqk")-1}, PVT_OTHER, pv_get_mqk, 0,
@@ -84,6 +87,8 @@ static cmd_export_t cmds[]={
static param_export_t params[]={
{"db_url", PARAM_STR, &mqueue_db_url},
{"mqueue", PARAM_STRING|USE_FUNC_PARAM, (void*)mq_param},
+ {"mqueue_name", PARAM_STRING|USE_FUNC_PARAM, (void*)mq_param_name},
+ {"mqueue_size", INT_PARAM, &mqueue_size },
{0, 0, 0}
};
@@ -268,6 +273,39 @@ int mq_param(modparam_t type, void *val)
return 0;
}
+int mq_param_name(modparam_t type, void *val)
+{
+ str qname = {0, 0};
+ int msize = 0;
+
+ if(val==NULL)
+ return -1;
+
+ if(!shm_initialized())
+ {
+ LM_ERR("shm not initialized - cannot define mqueue now\n");
+ return 0;
+ }
+
+ qname.s = (char*)val;
+ qname.len = strlen(qname.s);
+
+ msize = mqueue_size;
+
+ if(qname.len<=0)
+ {
+ LM_ERR("mqueue name not defined: %.*s\n", qname.len, qname.s);
+ return -1;
+ }
+ if(mq_head_add(&qname, msize)<0)
+ {
+ LM_ERR("cannot add mqueue: %.*s\n", qname.len, qname.s);
+ return -1;
+ }
+ LM_INFO("mqueue param: [%.*s|%d]\n", qname.len, qname.s, msize);
+ return 0;
+}
+
static int fixup_mq_add(void** param, int param_no)
{
if(param_no==1 || param_no==2 || param_no==3) {