Module: sip-router
Branch: oej/permissionsrpc
Commit: 7e95598b0d5f20fd28afd56922a2d8b85f2478d2
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7e95598…
Author: Olle E. Johansson <oej(a)edvina.net>
Committer: Olle E. Johansson <oej(a)edvina.net>
Date: Fri Dec 21 23:09:53 2012 +0100
Adding rpc for address reload
---
modules_k/permissions/address.c | 36 +++++++++++++++++++++++++++-------
modules_k/permissions/mi.c | 12 +++++++++++
modules_k/permissions/mi.h | 1 +
modules_k/permissions/permissions.c | 6 +++++
4 files changed, 47 insertions(+), 8 deletions(-)
diff --git a/modules_k/permissions/address.c b/modules_k/permissions/address.c
index 5dbe547..501d59e 100644
--- a/modules_k/permissions/address.c
+++ b/modules_k/permissions/address.c
@@ -1,5 +1,5 @@
+
/*
- *
* allow_address related functions
*
* Copyright (C) 2006 Juha Heinanen
@@ -136,14 +136,34 @@ int reload_address_table(void)
for (i = 0; i < RES_ROW_N(res); i++) {
val = ROW_VALUES(row + i);
/* basic checks to db values */
- if ((ROW_N(row + i) != 5)
- || (VAL_TYPE(val) != DB1_INT) || VAL_NULL(val)
- || (VAL_INT(val) <= 0)
- || (VAL_TYPE(val + 1) != DB1_STRING) || VAL_NULL(val + 1)
- || (VAL_TYPE(val + 2) != DB1_INT) || VAL_NULL(val + 2)
- || (VAL_TYPE(val + 3) != DB1_INT) || VAL_NULL(val + 3))
+ if (ROW_N(row + i) != 5)
+ {
+ LM_DBG("failure during checks of db address table: Colums %d - expected
5\n", ROW_N(row + i));
+ goto dberror;
+ }
+ if ((VAL_TYPE(val) != DB1_INT) || VAL_NULL(val) || (VAL_INT(val) <= 0))
+ {
+ LM_DBG("failure during checks of database value 1 (group) in address
table\n");
+ goto dberror;
+ }
+ if ((VAL_TYPE(val + 1) != DB1_STRING) && (VAL_TYPE(val + 1) != DB1_STR))
+ {
+ LM_DBG("failure during checks of database value 2 (IP address) in address table -
not a string value\n");
+ goto dberror;
+ }
+ if (VAL_NULL(val + 1))
+ {
+ LM_DBG("failure during checks of database value 2 (IP address) in address table -
NULL value not permitted\n");
+ goto dberror;
+ }
+ if ((VAL_TYPE(val + 2) != DB1_INT) || VAL_NULL(val + 2))
+ {
+ LM_DBG("failure during checks of database value 3 (subnet size/CIDR) in address
table\n");
+ goto dberror;
+ }
+ if ((VAL_TYPE(val + 3) != DB1_INT) || VAL_NULL(val + 3))
{
- LM_DBG("failure during checks of db values\n");
+ LM_DBG("failure during checks of database value 4 (port) in address
table\n");
goto dberror;
}
gid = VAL_UINT(val);
diff --git a/modules_k/permissions/mi.c b/modules_k/permissions/mi.c
index 9c3fb1a..22a8d47 100644
--- a/modules_k/permissions/mi.c
+++ b/modules_k/permissions/mi.c
@@ -102,6 +102,18 @@ struct mi_root* mi_address_reload(struct mi_root *cmd_tree, void
*param)
}
}
+/*! \brief
+ * RPC function to reload address table
+ */
+void rpc_address_reload(rpc_t* rpc, void* c) {
+ if (reload_address_table () != 1) {
+ rpc->fault(c, 500, "Reload failed.");
+ return;
+ }
+
+ rpc->printf(c, "Reload OK");
+ return;
+}
/*
* MI function to print address entries from current hash table
diff --git a/modules_k/permissions/mi.h b/modules_k/permissions/mi.h
index f37f4d5..5b271bd 100644
--- a/modules_k/permissions/mi.h
+++ b/modules_k/permissions/mi.h
@@ -45,6 +45,7 @@ void rpc_trusted_reload(rpc_t* rpc, void* c);
struct mi_root* mi_trusted_dump(struct mi_root *cmd, void *param);
struct mi_root* mi_address_reload(struct mi_root *cmd, void *param);
+void rpc_address_reload(rpc_t* rpc, void* c);
struct mi_root* mi_address_dump(struct mi_root *cmd, void *param);
diff --git a/modules_k/permissions/permissions.c b/modules_k/permissions/permissions.c
index 6e4fef0..e96a271 100644
--- a/modules_k/permissions/permissions.c
+++ b/modules_k/permissions/permissions.c
@@ -989,8 +989,14 @@ static const char* rpc_trusted_reload_doc[2] = {
0
};
+static const char* rpc_address_reload_doc[2] = {
+ "Reload permissions address table",
+ 0
+};
+
rpc_export_t permissions_rpc[] = {
{"permissions.trustedreload", rpc_trusted_reload, rpc_trusted_reload_doc, 0},
+ {"permissions.addressreload", rpc_address_reload, rpc_address_reload_doc, 0},
{0, 0, 0, 0}
};