Module: sip-router
Branch: master
Commit: 0ff087e9715298abf3187c52a9d1ac70031f1499
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0ff087e…
Author: Juha Heinanen <jh(a)tutpro.com>
Committer: Juha Heinanen <jh(a)tutpro.com>
Date: Wed May 1 11:54:20 2013 +0300
modules/mtree: added mtree.reload rcp command
---
modules/mtree/README | 15 ++++++++-
modules/mtree/doc/mtree_admin.xml | 12 ++++++++
modules/mtree/mtree_mod.c | 57 +++++++++++++++++++++++++++++++++++++
3 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/modules/mtree/README b/modules/mtree/README
index 05f3422..d548e89 100644
--- a/modules/mtree/README
+++ b/modules/mtree/README
@@ -20,9 +20,9 @@ Juha Heinanen
<jh(a)tutpro.com>
- Copyright � 2010 Daniel-Constantin Mierla (
asipto.com)
+ Copyright (c) 2010 Daniel-Constantin Mierla (
asipto.com)
- Copyright � 2011 Juha Heinanen
+ Copyright (c) 2011 Juha Heinanen
__________________________________________________________________
Table of Contents
@@ -64,6 +64,7 @@ Juha Heinanen
6. RPC Commands
6.1. mtree.summary
+ 6.2. mtree.reload
List of Examples
@@ -121,6 +122,7 @@ Chapter 1. Admin Guide
6. RPC Commands
6.1. mtree.summary
+ 6.2. mtree.reload
1. Overview
@@ -375,9 +377,18 @@ mt_match("mytree", "$rU", "0");
6. RPC Commands
6.1. mtree.summary
+ 6.2. mtree.reload
6.1. mtree.summary
List usage summary for all trees.
Parameters: none.
+
+6.2. mtree.reload
+
+ Reload mtree from database to memory.
+
+ Parameters:
+ * _mtree_
+ - name of mtree or empty string meaning all mtrees
diff --git a/modules/mtree/doc/mtree_admin.xml b/modules/mtree/doc/mtree_admin.xml
index 62154f0..0d81e72 100644
--- a/modules/mtree/doc/mtree_admin.xml
+++ b/modules/mtree/doc/mtree_admin.xml
@@ -428,6 +428,18 @@ mt_match("mytree", "$rU", "0");
</para>
<para>Parameters: none.</para>
</section>
+ <section>
+ <title>
+ <function moreinfo="none">mtree.reload</function>
+ </title>
+ <para>
+ Reload mtree from database to memory.
+ </para>
+ <para>Parameters:</para>
+ <itemizedlist>
+ <listitem><para>_mtree_</para> - name of mtree or empty string
meaning all mtrees</listitem>
+ </itemizedlist>
+ </section>
</section><!-- RPC commands -->
</chapter>
diff --git a/modules/mtree/mtree_mod.c b/modules/mtree/mtree_mod.c
index ac22d48..464f1c5 100644
--- a/modules/mtree/mtree_mod.c
+++ b/modules/mtree/mtree_mod.c
@@ -1044,8 +1044,65 @@ static const char* rpc_mtree_summary_doc[2] = {
0
};
+void rpc_mtree_reload(rpc_t* rpc, void* c)
+{
+ str tname = {0, 0};
+ m_tree_t *pt;
+
+ if(db_table.len>0)
+ {
+ /* re-loading all information from database */
+ if(mt_load_db_trees()!=0)
+ {
+ LM_ERR("cannot re-load mtrees from database\n");
+ goto error;
+ }
+ } else {
+ if(!mt_defined_trees())
+ {
+ LM_ERR("empty mtree list\n");
+ goto error;
+ }
+
+ /* read tree name */
+ if (rpc->scan(c, "S", &tname) != 1) {
+ rpc->fault(c, 500, "Failed to get table name parameter");
+ return;
+ }
+
+ pt = mt_get_first_tree();
+
+ while(pt!=NULL)
+ {
+ if(tname.s==NULL
+ || (tname.s!=NULL && pt->tname.len>=tname.len
+ && strncmp(pt->tname.s, tname.s, tname.len)==0))
+ {
+ /* re-loading table from database */
+ if(mt_load_db(&pt->tname)!=0)
+ {
+ LM_ERR("cannot re-load mtree from database\n");
+ goto error;
+ }
+ }
+ pt = pt->next;
+ }
+ }
+
+ return;
+
+error:
+ rpc->fault(c, 500, "Mtree Reload Failed");
+}
+
+static const char* rpc_mtree_reload_doc[2] = {
+ "Reload mtrees from database to memory",
+ 0
+};
+
rpc_export_t mtree_rpc[] = {
{"mtree.summary", rpc_mtree_summary, rpc_mtree_summary_doc, 0},
+ {"mtree.reload", rpc_mtree_reload, rpc_mtree_reload_doc, 0},
{0, 0, 0, 0}
};