Module: sip-router
Branch: master
Commit: cb23be9456c178957399ec9d8ce8a1420d50fc32
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=cb23be9…
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
---
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 bb54e79..6dc3275 100644
--- a/modules/permissions/address.c
+++ b/modules/permissions/address.c
@@ -253,6 +253,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 b1cbbf4..ef72253 100644
--- a/modules/permissions/address.h
+++ b/modules/permissions/address.h
@@ -55,6 +55,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 34e831f..9467f1d 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;
}