[sr-dev] git:master: pdt(k): added rpc command pdt.reload

Elena-Ramona Modroiu ramona at rosdev.ro
Tue Dec 20 21:51:20 CET 2011


Module: sip-router
Branch: master
Commit: 29ac2f12f5b475993c5e2be806ecc4c98696e270
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=29ac2f12f5b475993c5e2be806ecc4c98696e270

Author: Elena-Ramona Modroiu <ramona at asipto.com>
Committer: Elena-Ramona Modroiu <ramona at asipto.com>
Date:   Tue Dec 20 21:49:36 2011 +0100

pdt(k): added rpc command pdt.reload

- reload database records to pdt cache

---

 modules_k/pdt/pdt.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/modules_k/pdt/pdt.c b/modules_k/pdt/pdt.c
index 2748ea2..fba5f21 100644
--- a/modules_k/pdt/pdt.c
+++ b/modules_k/pdt/pdt.c
@@ -54,6 +54,8 @@
 #include "../../action.h"
 #include "../../mod_fix.h"
 #include "../../parser/parse_from.h"
+#include "../../rpc.h"
+#include "../../rpc_lookup.h"
 
 #include "pdtree.h"
 
@@ -98,10 +100,11 @@ static void mod_destroy(void);
 static int  child_init(int rank);
 static int  pd_translate(sip_msg_t *msg, str *sdomain, int rmode, int fmode);
 
-static int  w_pd_translate(struct sip_msg* msg, char* str1, char* str2);
+static int w_pd_translate(struct sip_msg* msg, char* str1, char* str2);
 static int fixup_translate(void** param, int param_no);
 
 static int update_new_uri(struct sip_msg *msg, int plen, str *d, int mode);
+static int pdt_init_rpc(void);
 
 static cmd_export_t cmds[]={
 	{"prefix2domain", (cmd_function)w_prefix2domain,   0, 0,
@@ -160,6 +163,12 @@ static int mod_init(void)
 	}
 #endif
 
+	if(pdt_init_rpc()<0)
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
+
 	db_url.len = strlen(db_url.s);
 	db_table.len = strlen(db_table.s);
 	sdomain_column.len = strlen(sdomain_column.s);
@@ -703,3 +712,46 @@ pdt_tree_t **pdt_get_ptree(void)
 {
 	return _ptree;
 }
+
+
+/*** RPC commands implementation ***/
+
+static const char* pdt_rpc_reload_doc[2] = {
+	"Reload PDT database records",
+	0
+};
+
+
+/*
+ * RPC command to reload pdt db records
+ */
+static void pdt_rpc_reload(rpc_t* rpc, void* ctx)
+{
+	if(pdt_load_db()<0) {
+		LM_ERR("cannot re-load pdt records from database\n");	
+		rpc->fault(ctx, 500, "Reload Failed");
+		return;
+	}
+	return;
+}
+
+
+rpc_export_t pdt_rpc_cmds[] = {
+	{"pdt.reload", pdt_rpc_reload,
+		pdt_rpc_reload_doc, 0},
+	{0, 0, 0, 0}
+};
+
+
+/**
+ * register RPC commands
+ */
+static int pdt_init_rpc(void)
+{
+	if (rpc_register_array(pdt_rpc_cmds)!=0)
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
+	return 0;
+}




More information about the sr-dev mailing list