Module: kamailio
Branch: master
Commit: 955152dbe5d1f05bf24d6ba23b091fe91a202cc3
URL:
https://github.com/kamailio/kamailio/commit/955152dbe5d1f05bf24d6ba23b091fe…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-04-21T19:09:21+02:00
dmq: added dmq.remove rpc command
- make it possible to remove a node that still is reachable by old
address without having to shut dowm all nodes
---
Modified: src/modules/dmq/dmq.c
Modified: src/modules/dmq/dmqnode.c
Modified: src/modules/dmq/dmqnode.h
---
Diff:
https://github.com/kamailio/kamailio/commit/955152dbe5d1f05bf24d6ba23b091fe…
Patch:
https://github.com/kamailio/kamailio/commit/955152dbe5d1f05bf24d6ba23b091fe…
---
diff --git a/src/modules/dmq/dmq.c b/src/modules/dmq/dmq.c
index fea60e0cc4..1db7cdd1f4 100644
--- a/src/modules/dmq/dmq.c
+++ b/src/modules/dmq/dmq.c
@@ -430,8 +430,29 @@ static void dmq_rpc_list_nodes(rpc_t *rpc, void *c)
static const char *dmq_rpc_list_nodes_doc[2] = {"Print all nodes", 0};
+void rpc_dmq_remove(rpc_t* rpc, void* ctx)
+{
+ str taddr = STR_NULL;
+
+ if (rpc->scan(ctx, ".S", &taddr) < 1) {
+ rpc->fault(ctx, 500, "Invalid Parameters");
+ return;
+ }
+ if(dmq_node_del_by_uri(dmq_node_list, &taddr)<0) {
+ rpc->fault(ctx, 500, "Failure");
+ return;
+ }
+}
+
+static const char* rpc_dmq_remove_doc[3] = {
+ "Remove a DMQ node",
+ "address - the DMQ node address",
+ 0
+};
+
static rpc_export_t rpc_methods[] = {
{"dmq.list_nodes", dmq_rpc_list_nodes, dmq_rpc_list_nodes_doc, RET_ARRAY},
+ {"dmq.remove", rpc_dmq_remove, rpc_dmq_remove_doc, 0},
{0, 0, 0, 0}
};
diff --git a/src/modules/dmq/dmqnode.c b/src/modules/dmq/dmqnode.c
index 7e6ef93bdf..631dce11d5 100644
--- a/src/modules/dmq/dmqnode.c
+++ b/src/modules/dmq/dmqnode.c
@@ -350,6 +350,22 @@ int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node)
return 0;
}
+/**
+ * @brief delete dmq node by uri
+ */
+int dmq_node_del_by_uri(dmq_node_list_t *list, str *suri)
+{
+ dmq_node_t dnode;
+
+ memset(&dnode, 0, sizeof(dmq_node_t));
+ if(parse_uri(suri->s, suri->len, &dnode.uri) < 0) {
+ LM_ERR("error parsing uri [%.*s]\n", suri->len, suri->s);
+ return -1;
+ }
+
+ return del_dmq_node(list, &dnode);
+}
+
/**
* @brief add dmq node
*/
diff --git a/src/modules/dmq/dmqnode.h b/src/modules/dmq/dmqnode.h
index 45cac604a4..22c5c6fb1d 100644
--- a/src/modules/dmq/dmqnode.h
+++ b/src/modules/dmq/dmqnode.h
@@ -69,6 +69,7 @@ dmq_node_t *find_dmq_node(dmq_node_list_t *list, dmq_node_t *node);
dmq_node_t *find_dmq_node_uri(dmq_node_list_t *list, str *uri);
dmq_node_t *find_dmq_node_uri2(str *uri);
int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node);
+int dmq_node_del_by_uri(dmq_node_list_t *list, str *suri);
int cmp_dmq_node(dmq_node_t *node, dmq_node_t *cmpnode);
int update_dmq_node_status(dmq_node_list_t *list, dmq_node_t *node, int status);
dmq_node_t *shm_dup_node(dmq_node_t *node);