Преглед на файлове

sipdump: implemented sipdump.enable rpc command

Daniel-Constantin Mierla преди 8 години
родител
ревизия
986094362b
променени са 3 файла, в които са добавени 69 реда и са изтрити 0 реда
  1. 5 0
      src/modules/sipdump/sipdump_mod.c
  2. 62 0
      src/modules/sipdump/sipdump_write.c
  3. 2 0
      src/modules/sipdump/sipdump_write.h

+ 5 - 0
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;

+ 62 - 0
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;
+}

+ 2 - 0
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