[sr-dev] git:master:e676498f: Merge pull request #2514 from gaaf/features/mqueue
GitHub
noreply at github.com
Tue Oct 20 13:52:19 CEST 2020
Module: kamailio
Branch: master
Commit: e676498f4d0a46ae81e4e07e56ff64c97a075faf
URL: https://github.com/kamailio/kamailio/commit/e676498f4d0a46ae81e4e07e56ff64c97a075faf
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: GitHub <noreply at github.com>
Date: 2020-10-20T13:52:13+02:00
Merge pull request #2514 from gaaf/features/mqueue
mqueue: RPC features
---
Modified: src/modules/mqueue/doc/mqueue_admin.xml
Modified: src/modules/mqueue/mqueue_api.c
Modified: src/modules/mqueue/mqueue_api.h
Modified: src/modules/mqueue/mqueue_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/e676498f4d0a46ae81e4e07e56ff64c97a075faf.diff
Patch: https://github.com/kamailio/kamailio/commit/e676498f4d0a46ae81e4e07e56ff64c97a075faf.patch
---
diff --git a/src/modules/mqueue/doc/mqueue_admin.xml b/src/modules/mqueue/doc/mqueue_admin.xml
index 5309098058..7d785ac90b 100644
--- a/src/modules/mqueue/doc/mqueue_admin.xml
+++ b/src/modules/mqueue/doc/mqueue_admin.xml
@@ -300,6 +300,24 @@ xlog("L_INFO", "Size of queue is: $var(q_size)\n");
...
&kamcmd; mqueue.fetch xyz
...
+</programlisting>
+ </example>
+ </section>
+
+ <section id="mqueue.r.get_sizes">
+ <title>mqueue.get_sizes</title>
+ <para>
+ Get the size for all memory queues.
+ </para>
+ <para>
+ Parameters: none
+ </para>
+ <example>
+ <title><function>mqueue.get_sizes</function> usage</title>
+ <programlisting format="linespecific">
+...
+&kamcmd; mqueue.get_sizes
+...
</programlisting>
</example>
</section>
diff --git a/src/modules/mqueue/mqueue_api.c b/src/modules/mqueue/mqueue_api.c
index 93204bba3c..4dd61c3e72 100644
--- a/src/modules/mqueue/mqueue_api.c
+++ b/src/modules/mqueue/mqueue_api.c
@@ -173,6 +173,9 @@ mq_head_t *mq_head_get(str *name)
mq_head_t *mh = NULL;
mh = _mq_head_list;
+ if (!name) {
+ return mh;
+ }
while(mh!=NULL)
{
if(name->len == mh->name.len
diff --git a/src/modules/mqueue/mqueue_api.h b/src/modules/mqueue/mqueue_api.h
index 843a7d7967..d60dfdf29a 100644
--- a/src/modules/mqueue/mqueue_api.h
+++ b/src/modules/mqueue/mqueue_api.h
@@ -77,6 +77,7 @@ int mq_head_add(str *name, int msize);
int mq_head_fetch(str *name);
void mq_pv_free(str *name);
int mq_item_add(str *qname, str *key, str *val);
+mq_head_t *mq_head_get(str *name);
int _mq_get_csize(str *);
int mq_set_dbmode(str *, int dbmode);
diff --git a/src/modules/mqueue/mqueue_mod.c b/src/modules/mqueue/mqueue_mod.c
index 860014cca9..325c84b472 100644
--- a/src/modules/mqueue/mqueue_mod.c
+++ b/src/modules/mqueue/mqueue_mod.c
@@ -294,13 +294,13 @@ static void mqueue_rpc_get_size(rpc_t* rpc, void* ctx)
int mqueue_sz = 0;
if (rpc->scan(ctx, "S", &mqueue_name) < 1) {
- rpc->fault(ctx, 500, "No queue name");
+ rpc->fault(ctx, 400, "No queue name");
return;
}
if(mqueue_name.len <= 0 || mqueue_name.s == NULL) {
LM_ERR("bad mqueue name\n");
- rpc->fault(ctx, 500, "Invalid queue name");
+ rpc->fault(ctx, 400, "Invalid queue name");
return;
}
@@ -308,7 +308,7 @@ static void mqueue_rpc_get_size(rpc_t* rpc, void* ctx)
if(mqueue_sz < 0) {
LM_ERR("no such mqueue\n");
- rpc->fault(ctx, 500, "No such queue");
+ rpc->fault(ctx, 404, "No such queue");
return;
}
@@ -327,6 +327,34 @@ static const char* mqueue_rpc_get_size_doc[2] = {
0
};
+static void mqueue_rpc_get_sizes(rpc_t* rpc, void* ctx)
+{
+ mq_head_t* mh = mq_head_get(NULL);
+ void* vh;
+ int size;
+
+ while(mh!=NULL)
+ {
+ if (rpc->add(ctx, "{", &vh) < 0) {
+ rpc->fault(ctx, 500, "Server error");
+ return;
+ }
+ lock_get(&mh->lock);
+ size = mh->csize;
+ lock_release(&mh->lock);
+ rpc->struct_add(vh, "Sd",
+ "name", &mh->name,
+ "size", size
+ );
+ mh = mh->next;
+ }
+}
+
+static const char* mqueue_rpc_get_sizes_doc[2] = {
+ "Get sizes of all mqueues.",
+ 0
+};
+
static void mqueue_rpc_fetch(rpc_t* rpc, void* ctx)
{
str mqueue_name;
@@ -392,6 +420,7 @@ static const char* mqueue_rpc_fetch_doc[2] = {
rpc_export_t mqueue_rpc[] = {
{"mqueue.get_size", mqueue_rpc_get_size, mqueue_rpc_get_size_doc, 0},
+ {"mqueue.get_sizes", mqueue_rpc_get_sizes, mqueue_rpc_get_sizes_doc, RET_ARRAY},
{"mqueue.fetch", mqueue_rpc_fetch, mqueue_rpc_fetch_doc, 0},
{0, 0, 0, 0}
};
More information about the sr-dev
mailing list