Module: sip-router
Branch: master
Commit: f492b41bd12904e3132260562073e79d76a003a5
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f492b41…
Author: Alex Balashov <abalashov(a)evaristesys.com>
Committer: Alex Balashov <abalashov(a)evaristesys.com>
Date: Mon Jul 23 22:23:36 2012 -0400
mqueue: Added mq_size() function to get runtime size of mqueue in script.
---
modules/mqueue/doc/mqueue.xml | 6 ++++++
modules/mqueue/doc/mqueue_admin.xml | 18 ++++++++++++++++++
modules/mqueue/mqueue_mod.c | 21 +++++++++++++++++++++
3 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/modules/mqueue/doc/mqueue.xml b/modules/mqueue/doc/mqueue.xml
index 4ad3797..af880f6 100644
--- a/modules/mqueue/doc/mqueue.xml
+++ b/modules/mqueue/doc/mqueue.xml
@@ -23,6 +23,12 @@
<surname>Modroiu</surname>
<email>ramona(a)asipto.com</email>
</editor>
+ <editor>
+ <firstname>Alex</firstname>
+ <surname>Balashov</surname>
+ <email>abalashov(a)evaristesys.com</email>
+ <affiliation><orgname>Evariste Systems</orgname></affiliation>
+ </editor>
</authorgroup>
<copyright>
<year>2010</year>
diff --git a/modules/mqueue/doc/mqueue_admin.xml b/modules/mqueue/doc/mqueue_admin.xml
index 1b0363c..3a6ce9e 100644
--- a/modules/mqueue/doc/mqueue_admin.xml
+++ b/modules/mqueue/doc/mqueue_admin.xml
@@ -155,6 +155,24 @@ mq_pv_free("myq");
</programlisting>
</example>
</section>
+
+ <section>
+ <title>
+ <function moreinfo="none">mq_size(queue)</function>
+ </title>
+ <para>
+ Returns the current number of elements in the mqueue.
+ </para>
+ <example>
+ <title><function>mq_size</function> usage</title>
+ <programlisting format="linespecific">
+...
+$var(q_size) = mq_size("queue");
+xlog("L_INFO", "Size of queue is: $var(q_size)\n");
+...
+</programlisting>
+ </example>
+ </section>
</section>
diff --git a/modules/mqueue/mqueue_mod.c b/modules/mqueue/mqueue_mod.c
index 1559c51..3eacf02 100644
--- a/modules/mqueue/mqueue_mod.c
+++ b/modules/mqueue/mqueue_mod.c
@@ -45,6 +45,7 @@ static int mod_init(void);
static void mod_destroy(void);
static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2);
+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);
@@ -73,6 +74,8 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE},
{"mq_pv_free", (cmd_function)w_mq_pv_free, 1, fixup_spve_null,
0, ANY_ROUTE},
+ {"mq_size", (cmd_function) w_mq_size, 1, fixup_spve_null,
+ 0, ANY_ROUTE},
{"bind_mq", (cmd_function)bind_mq, 1, 0,
0, ANY_ROUTE},
{0, 0, 0, 0, 0, 0}
@@ -140,6 +143,24 @@ static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2)
return 1;
}
+static int w_mq_size(struct sip_msg *msg, char *mq, char *str2)
+{
+ int ret;
+ str q;
+
+ if(fixup_get_svalue(msg, (gparam_t *) mq, &q) < 0) {
+ LM_ERR("cannot get queue parameter\n");
+ return -1;
+ }
+
+ ret = _mq_get_csize(&q);
+
+ if(ret < 0)
+ LM_ERR("mqueue not found\n");
+
+ return ret;
+}
+
static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val)
{
str q;