[sr-dev] git:master:98609436: sipdump: implemented sipdump.enable rpc command

Daniel-Constantin Mierla miconda at gmail.com
Fri Oct 13 12:33:49 CEST 2017


Module: kamailio
Branch: master
Commit: 986094362b8ff384cc0378a7028425ea092609aa
URL: https://github.com/kamailio/kamailio/commit/986094362b8ff384cc0378a7028425ea092609aa

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-10-13T12:33:30+02:00

sipdump: implemented sipdump.enable rpc command

---

Modified: src/modules/sipdump/sipdump_mod.c
Modified: src/modules/sipdump/sipdump_write.c
Modified: src/modules/sipdump/sipdump_write.h

---

Diff:  https://github.com/kamailio/kamailio/commit/986094362b8ff384cc0378a7028425ea092609aa.diff
Patch: https://github.com/kamailio/kamailio/commit/986094362b8ff384cc0378a7028425ea092609aa.patch

---

diff --git a/src/modules/sipdump/sipdump_mod.c b/src/modules/sipdump/sipdump_mod.c
index 48a77ada76..e7ba0a69a5 100644
--- a/src/modules/sipdump/sipdump_mod.c
+++ b/src/modules/sipdump/sipdump_mod.c
@@ -94,6 +94,11 @@ struct module_exports exports = {
  */
 static int mod_init(void)
 {
+	if(sipdump_rpc_init()<0) {
+		LM_ERR("failed to register rpc commands\n");
+		return -1;
+	}
+
 	if(sipdump_file_init(&sipdump_folder, &sipdump_fprefix) < 0) {
 		LM_ERR("cannot initialize storage file\n");
 		return -1;
diff --git a/src/modules/sipdump/sipdump_write.c b/src/modules/sipdump/sipdump_write.c
index 7d76715c7d..8d8c890721 100644
--- a/src/modules/sipdump/sipdump_write.c
+++ b/src/modules/sipdump/sipdump_write.c
@@ -27,6 +27,8 @@
 
 #include "../../core/dprint.h"
 #include "../../core/ut.h"
+#include "../../core/rpc.h"
+#include "../../core/rpc_lookup.h"
 
 #include "sipdump_write.h"
 
@@ -226,3 +228,63 @@ void sipdump_timer_exec(unsigned int ticks, void *param)
 		shm_free(sdd);
 	}
 }
+
+static const char *sipdump_rpc_enable_doc[2] = {
+	"Command to control sipdump enable value", 0};
+
+
+/*
+* RPC command to control sipdump enable
+*/
+static void sipdump_rpc_enable(rpc_t *rpc, void *ctx)
+{
+	int enval = -1;
+	int oval = 0;
+	int nval = 0;
+
+	void *th;
+
+	if(rpc->scan(ctx, "*d", &enval) != 1) {
+		enval = -1;
+	}
+
+	if(rpc->add(ctx, "{", &th) < 0) {
+		rpc->fault(ctx, 500, "Internal error root reply");
+		return;
+	}
+
+	if(_sipdump_list) {
+		oval = _sipdump_list->enable;
+		if(enval==0 || enval==1) {
+			_sipdump_list->enable = enval;
+			nval = enval;
+		} else {
+			nval = oval;
+		}
+	}
+
+	if(rpc->struct_add(th, "dd", "oldval", oval, "newval", nval) < 0) {
+		rpc->fault(ctx, 500, "Internal error reply structure");
+		return;
+	}
+}
+
+/* clang-format off */
+rpc_export_t sipdump_rpc_cmds[] = {
+	{"sipdump.enable", sipdump_rpc_enable,
+		sipdump_rpc_enable_doc, 0},
+	{0, 0, 0, 0}
+};
+/* clang-format on */
+
+/**
+ * register RPC commands
+ */
+int sipdump_rpc_init(void)
+{
+	if(rpc_register_array(sipdump_rpc_cmds) != 0) {
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
+	return 0;
+}
\ No newline at end of file
diff --git a/src/modules/sipdump/sipdump_write.h b/src/modules/sipdump/sipdump_write.h
index e9d5de4131..611fd10fd9 100644
--- a/src/modules/sipdump/sipdump_write.h
+++ b/src/modules/sipdump/sipdump_write.h
@@ -51,4 +51,6 @@ int sipdump_file_init(str *folder, str *fprefix);
 
 int sipdump_enabled(void);
 
+int sipdump_rpc_init(void);
+
 #endif




More information about the sr-dev mailing list