Module: sip-router
Branch: oej/permissionsrpc
Commit: 22e9c9ee0269fabbe2cb0e7ba0de6b37b6a0f45f
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=22e9c9e…
Author: Olle E. Johansson <oej(a)edvina.net>
Committer: Olle E. Johansson <oej(a)edvina.net>
Date: Fri Dec 21 17:31:47 2012 +0100
Starting to add rpc calls to the permissions module
---
modules_k/permissions/mi.c | 19 ++++++++++++++++++-
modules_k/permissions/mi.h | 2 ++
modules_k/permissions/permissions.c | 30 ++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 1 deletions(-)
diff --git a/modules_k/permissions/mi.c b/modules_k/permissions/mi.c
index c2f900f..9c3fb1a 100644
--- a/modules_k/permissions/mi.c
+++ b/modules_k/permissions/mi.c
@@ -1,6 +1,6 @@
/*
*
- * Permissions MI functions
+ * Permissions MI and RPC functions
*
* Copyright (C) 2006 Juha Heinanen
*
@@ -49,6 +49,23 @@ struct mi_root* mi_trusted_reload(struct mi_root *cmd_tree, void
*param)
}
}
+/*! \brief
+ * RPC function to reload trusted table
+ */
+void rpc_trusted_reload(rpc_t* rpc, void* c) {
+ if (hash_table==NULL) {
+ rpc->fault(c, 500, "Reload failed. No hash table");
+ return;
+ }
+ if (reload_trusted_table () != 1) {
+ rpc->fault(c, 500, "Reload failed.");
+ return;
+ }
+
+ rpc->printf(c, "Reload OK");
+ return;
+}
+
/*
* MI function to print trusted entries from current hash table
diff --git a/modules_k/permissions/mi.h b/modules_k/permissions/mi.h
index 84a701e..f37f4d5 100644
--- a/modules_k/permissions/mi.h
+++ b/modules_k/permissions/mi.h
@@ -27,6 +27,7 @@
#include "../../lib/kmi/mi.h"
+#include "../../rpc.h"
#define MI_TRUSTED_RELOAD "trusted_reload"
@@ -39,6 +40,7 @@
#define MI_ALLOW_URI "allow_uri"
struct mi_root* mi_trusted_reload(struct mi_root *cmd, void *param);
+void rpc_trusted_reload(rpc_t* rpc, void* c);
struct mi_root* mi_trusted_dump(struct mi_root *cmd, void *param);
diff --git a/modules_k/permissions/permissions.c b/modules_k/permissions/permissions.c
index 7196203..6e4fef0 100644
--- a/modules_k/permissions/permissions.c
+++ b/modules_k/permissions/permissions.c
@@ -42,6 +42,8 @@
#include "../../globals.h"
#include "../../mod_fix.h"
#include "../../ut.h"
+#include "../../rpc.h"
+#include "../../rpc_lookup.h"
MODULE_VERSION
@@ -116,6 +118,8 @@ static void mod_exit(void);
static int child_init(int rank);
static int mi_trusted_child_init();
static int mi_addr_child_init();
+static int permissions_init_rpc(void);
+
/* Exported functions */
@@ -588,6 +592,12 @@ static int mod_init(void)
return -1;
}
+ if(permissions_init_rpc()!=0)
+ {
+ LM_ERR("failed to register RPC commands\n");
+ return -1;
+ }
+
if (db_url.s)
db_url.len = strlen(db_url.s);
trusted_table.len = strlen(trusted_table.s);
@@ -973,3 +983,23 @@ static int fixup_allow_address(void** param, int param_no)
return fixup_igp_null(param, 1);
return 0;
}
+
+static const char* rpc_trusted_reload_doc[2] = {
+ "Reload permissions trusted table",
+ 0
+};
+
+rpc_export_t permissions_rpc[] = {
+ {"permissions.trustedreload", rpc_trusted_reload, rpc_trusted_reload_doc, 0},
+ {0, 0, 0, 0}
+};
+
+static int permissions_init_rpc(void)
+{
+ if (rpc_register_array(permissions_rpc)!=0)
+ {
+ LM_ERR("failed to register RPC commands\n");
+ return -1;
+ }
+ return 0;
+}