Module: sip-router
Branch: 4.0
Commit: 7aba649db775a00e28dc75a9145a3da50f797776
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7aba649…
Author: Federico Cabiddu <federico.cabiddu(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Dec 2 17:05:35 2013 +0100
permissions: re-init db connection for reload cmd
- some workers for specific mi/rpc commands may not have a db connection from the start
(cherry picked from commit cb23be9456c178957399ec9d8ce8a1420d50fc32)
---
modules/permissions/address.c | 25 +++++++++++++++++++++++++
modules/permissions/address.h | 5 +++++
modules/permissions/mi.c | 4 ++--
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/modules/permissions/address.c b/modules/permissions/address.c
index 501d59e..9a6bd44 100644
--- a/modules/permissions/address.c
+++ b/modules/permissions/address.c
@@ -227,6 +227,31 @@ dberror:
return -1;
}
+/*
+ * Wrapper to reload addr table from mi or rpc
+ * we need to open the db_handle
+ */
+int reload_address_table_cmd(void)
+{
+ if (!db_handle) {
+ db_handle = perm_dbf.init(&db_url);
+ if (!db_handle) {
+ LM_ERR("unable to connect database\n");
+ return -1;
+ }
+ }
+
+ if (reload_address_table () != 1) {
+ perm_dbf.close(db_handle);
+ db_handle = 0;
+ return -1;
+ }
+
+ perm_dbf.close(db_handle);
+ db_handle = 0;
+
+ return 1;
+}
/*
* Initialize data structures
diff --git a/modules/permissions/address.h b/modules/permissions/address.h
index e501204..c138120 100644
--- a/modules/permissions/address.h
+++ b/modules/permissions/address.h
@@ -52,6 +52,11 @@ int mi_init_addresses(void);
*/
int reload_address_table(void);
+/*
+ * Wrapper to reload addr table from mi or rpc
+ * we need to open the db_handle
+ */
+int reload_address_table_cmd(void);
/*
* Close connections and release memory
diff --git a/modules/permissions/mi.c b/modules/permissions/mi.c
index e38bc05..9ac67ff 100644
--- a/modules/permissions/mi.c
+++ b/modules/permissions/mi.c
@@ -114,7 +114,7 @@ void rpc_trusted_dump(rpc_t* rpc, void* c) {
*/
struct mi_root* mi_address_reload(struct mi_root *cmd_tree, void *param)
{
- if (reload_address_table () == 1) {
+ if (reload_address_table_cmd () == 1) {
return init_mi_tree( 200, MI_SSTR(MI_OK));
} else {
return init_mi_tree( 400, MI_SSTR("Address table reload failed"));
@@ -125,7 +125,7 @@ struct mi_root* mi_address_reload(struct mi_root *cmd_tree, void
*param)
* RPC function to reload address table
*/
void rpc_address_reload(rpc_t* rpc, void* c) {
- if (reload_address_table () != 1) {
+ if (reload_address_table_cmd () != 1) {
rpc->fault(c, 500, "Reload failed.");
return;
}