Module: sip-router
Branch: master
Commit: 6d34982c99060436bc9a3a07058eb805488fc34d
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6d34982c99060436bc9a3a07058eb805488fc34d

Author: Olle E. Johansson <[email protected]>
Committer: Olle E. Johansson <[email protected]>
Date:   Thu Jan 10 21:45:09 2013 +0100

mtree   Add RPC command mtree.summary

---

 modules/mtree/README              |   28 +++++++++++--
 modules/mtree/doc/mtree_admin.xml |   14 ++++++-
 modules/mtree/mtree_mod.c         |   78 +++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+), 6 deletions(-)

diff --git a/modules/mtree/README b/modules/mtree/README
index 3be2e53..05f3422 100644
--- a/modules/mtree/README
+++ b/modules/mtree/README
@@ -61,6 +61,10 @@ Juha Heinanen
               5.2. mt_reload
               5.3. mt_summary
 
+        6. RPC Commands
+
+              6.1. mtree.summary
+
    List of Examples
 
    1.1. Set db_url parameter
@@ -114,6 +118,10 @@ Chapter 1. Admin Guide
         5.2. mt_reload
         5.3. mt_summary
 
+   6. RPC Commands
+
+        6.1. mtree.summary
+
 1. Overview
 
    This module loads data indexed by prefixes from database and returns
@@ -155,7 +163,7 @@ Chapter 1. Admin Guide
 
    URL of the database server to be used.
 
-   Default value is "mysql://openser:openserrw@localhost/openser".
+   Default value is "mysql://kamailio:kamailiorw@localhost/kamailio".
 
    Example 1.1. Set db_url parameter
 ...
@@ -302,7 +310,7 @@ modparam("mtree", "mt_allow_duplicates", 1)
 
    4.1. mt_match(mtree, pv, mode)
 
-4.1. mt_match(mtree, pv, mode)
+4.1.  mt_match(mtree, pv, mode)
 
    Match 'pv' value against 'mtree'. If 'mtree' type is 0 or 2 and value
    of 'mode' is NOT 2, sets a value of the longest matching prefix to
@@ -323,7 +331,7 @@ mt_match("mytree", "$rU", "0");
    5.2. mt_reload
    5.3. mt_summary
 
-5.1. mt_list
+5.1.  mt_list
 
    List content of a tree.
 
@@ -337,7 +345,7 @@ mt_match("mytree", "$rU", "0");
                 _mtname_
                 _empty_line_
 
-5.2. mt_reload
+5.2.  mt_reload
 
    Reload mtree from database.
 
@@ -352,7 +360,7 @@ mt_match("mytree", "$rU", "0");
                 _mtname_
                 _empty_line_
 
-5.3. mt_summary
+5.3.  mt_summary
 
    List usage summary for all trees.
 
@@ -363,3 +371,13 @@ mt_match("mytree", "$rU", "0");
    MI FIFO Command Format:
                 :mt_summary:_reply_fifo_file_
                 _empty_line_
+
+6. RPC Commands
+
+   6.1. mtree.summary
+
+6.1.  mtree.summary
+
+   List usage summary for all trees.
+
+   Parameters: none.
diff --git a/modules/mtree/doc/mtree_admin.xml 
b/modules/mtree/doc/mtree_admin.xml
index 8558ccd..62154f0 100644
--- a/modules/mtree/doc/mtree_admin.xml
+++ b/modules/mtree/doc/mtree_admin.xml
@@ -416,7 +416,19 @@ mt_match("mytree", "$rU", "0");
                _empty_line_
                </programlisting>
     </section>
-    </section>
+    </section><!-- MI commands -->
+       <section>
+       <title>RPC Commands</title>
+       <section>
+               <title>
+               <function moreinfo="none">mtree.summary</function>
+               </title>
+               <para>
+               List usage summary for all trees.
+               </para>
+               <para>Parameters: none.</para>
+        </section>
+       </section><!-- RPC commands -->
 
 </chapter>
 
diff --git a/modules/mtree/mtree_mod.c b/modules/mtree/mtree_mod.c
index 389fa3d..ac22d48 100644
--- a/modules/mtree/mtree_mod.c
+++ b/modules/mtree/mtree_mod.c
@@ -39,6 +39,8 @@
 #include "../../action.h"
 #include "../../mod_fix.h"
 #include "../../parser/parse_from.h"
+#include "../../rpc.h"
+#include "../../rpc_lookup.h"
 
 #include "mtree.h"
 
@@ -109,6 +111,7 @@ static int  mod_init(void);
 static void mod_destroy(void);
 static int  child_init(int rank);
 static int  mi_child_init(void);
+static int mtree_init_rpc(void);
 
 static int mt_match(struct sip_msg *msg, gparam_t *dm, gparam_t *var,
                gparam_t *mode);
@@ -183,6 +186,11 @@ static int mod_init(void)
                LM_ERR("failed to register MI commands\n");
                return -1;
        }
+       if(mtree_init_rpc()!=0)
+        {
+                LM_ERR("failed to register RPC commands\n");
+                return -1;
+        }
 
        db_url.len = strlen(db_url.s);
        db_table.len = strlen(db_table.s);
@@ -980,3 +988,73 @@ error:
        free_mi_tree(rpl_tree);
        return 0;
 }
+
+void rpc_mtree_summary(rpc_t* rpc, void* c) 
+{
+       m_tree_t *pt;
+       void* th;
+       void* ih;
+
+       if(!mt_defined_trees())
+       {
+               rpc->fault(c, 500, "Empty tree list.");
+                return;
+       }
+
+       if (rpc->add(c, "{", &th) < 0)
+       {
+               rpc->fault(c, 500, "Internal error creating rpc");
+               return;
+       }
+       pt = mt_get_first_tree();
+
+       while(pt!=NULL)
+       {
+               if(rpc->struct_add(th, "s{",
+                               "table", pt->tname.s,
+                               "item", &ih) < 0)
+                       {
+                               rpc->fault(c, 500, "Internal error creating rpc 
ih");
+                               return;
+                       }
+
+               if(rpc->struct_add(ih, "d", "ttype", pt->type) < 0 ) {
+                                rpc->fault(c, 500, "Internal error adding 
type");
+                                return;
+                }
+               if(rpc->struct_add(ih, "d", "memsize", pt->memsize) < 0 ) {
+                                rpc->fault(c, 500, "Internal error adding 
memsize");
+                                return;
+                }
+               if(rpc->struct_add(ih, "d", "nrnodes", pt->nrnodes) < 0 ) {
+                                rpc->fault(c, 500, "Internal error adding 
nodes");
+                                return;
+                }
+               if(rpc->struct_add(ih, "d", "nritems", pt->nritems) < 0 ) {
+                                rpc->fault(c, 500, "Internal error adding 
items");
+                                return;
+                }
+               pt = pt->next;
+       }
+       return;
+}
+
+static const char* rpc_mtree_summary_doc[2] = {
+       "Print summary of loaded mtree tables",
+       0
+};
+
+rpc_export_t mtree_rpc[] = {
+       {"mtree.summary", rpc_mtree_summary, rpc_mtree_summary_doc, 0},
+       {0, 0, 0, 0}
+};
+
+static int mtree_init_rpc(void)
+{
+       if (rpc_register_array(mtree_rpc) != 0)
+       {
+               LM_ERR("failed to register RPC commands\n");
+               return -1;
+       }
+       return 0;
+}


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to