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

Author: Olle E. Johansson <[email protected]>
Committer: Olle E. Johansson <[email protected]>
Date:   Sun Dec  7 18:58:43 2014 +0100

dialplan Add dialplan.dump <id> RPC command

---

 modules/dialplan/README                 |   30 +++++++---
 modules/dialplan/dialplan.c             |  102 +++++++++++++++++++++++++++++++
 modules/dialplan/doc/dialplan_admin.xml |   16 +++++
 3 files changed, 140 insertions(+), 8 deletions(-)

diff --git a/modules/dialplan/README b/modules/dialplan/README
index 08ee011..5604c7c 100644
--- a/modules/dialplan/README
+++ b/modules/dialplan/README
@@ -56,8 +56,9 @@ Juha Heinanen
 
         8. Exported RPC Commands
 
-              8.1. dialplan.reload
-              8.2. dialplan.translate
+              8.1. dialplan.dump
+              8.2. dialplan.reload
+              8.3. dialplan.translate
 
         9. Installation
 
@@ -121,8 +122,9 @@ Chapter 1. Admin Guide
 
    8. Exported RPC Commands
 
-        8.1. dialplan.reload
-        8.2. dialplan.translate
+        8.1. dialplan.dump
+        8.2. dialplan.reload
+        8.3. dialplan.translate
 
    9. Installation
 
@@ -453,10 +455,22 @@ xlog("translated to var $var(y) \n");
 
 8. Exported RPC Commands
 
-   8.1. dialplan.reload
-   8.2. dialplan.translate
+   8.1. dialplan.dump
+   8.2. dialplan.reload
+   8.3. dialplan.translate
 
-8.1. dialplan.reload
+8.1. dialplan.dump
+
+   Dumps the content of one dialplan ID
+
+   Name: dialplan.dump
+
+   Parameters: Dialplan ID
+
+   Example:
+                kamcmd dialplan.dump 100
+
+8.2. dialplan.reload
 
    Forces an update of the translation rules from the database.
 
@@ -467,7 +481,7 @@ xlog("translated to var $var(y) \n");
    Example:
                 kamcmd dialplan.reload
 
-8.2. dialplan.translate
+8.3. dialplan.translate
 
    Will apply a translation rule identified by a dialplan id and an input
    string.
diff --git a/modules/dialplan/dialplan.c b/modules/dialplan/dialplan.c
index d86eb56..3d6fcbe 100644
--- a/modules/dialplan/dialplan.c
+++ b/modules/dialplan/dialplan.c
@@ -5,6 +5,8 @@
  *
  * Copyright (C)  2008 Juha Heinanen
  *
+ * Copyright (C)  2015 Olle E. Johansson, Edvina AB
+ *
  * This file is part of SIP-router, a free SIP server.
  *
  * SIP-router is free software; you can redistribute it and/or modify
@@ -25,6 +27,7 @@
  * --------
  *  2007-08-01 initial version (ancuta onofrei)
  *  2008-10-09 module is now using pcre regexp lib (juha heinanen)
+ *  2015-11-25 added RPC command for listing dialplan
  */
 
 /*!
@@ -657,12 +660,111 @@ static void dialplan_rpc_translate(rpc_t* rpc, void* ctx)
        return;
 }
 
+/*
+ * RPC command to dump dialplan 
+ */
+static void dialplan_rpc_dump(rpc_t* rpc, void* ctx)
+{
+       dpl_id_p idp;
+       dpl_index_p indexp;
+       dpl_node_p rulep;
+       str input;
+       int dpid;
+       str attrs  = {"", 0};
+       str output = {0, 0};
+       void* th;
+       void* ih;
+       void* sh;
+
+       if (rpc->scan(ctx, "d", &dpid) < 1)
+       {
+               rpc->fault(ctx, 500, "Missing parameter");
+               return;
+       }
+
+       if ((idp = select_dpid(dpid)) == 0 ) {
+               LM_ERR("no information available for dpid %i\n", dpid);
+               rpc->fault(ctx, 500, "Dialplan ID not matched");
+               return;
+       }
+
+       LM_DBG("trying to dump dpid %i\n", idp->dp_id);
+
+       /* add entry node */
+       if (rpc->add(ctx, "{", &th) < 0)
+       {
+               rpc->fault(ctx, 500, "Internal error root reply");
+               return;
+       }
+
+       if(rpc->struct_add(th, "d[",
+                               "DPID",  dpid,
+                               "ENTRIES", &ih)<0)
+       {
+               rpc->fault(ctx, 500, "Internal error sets structure");
+               return;
+       }
+
+       for(indexp=idp->first_index; indexp!=NULL;indexp=indexp->next) {
+               LM_DBG("INDEX LEN: %i\n", indexp->len);
+                for(rulep = indexp->first_rule; rulep!= NULL;rulep = 
rulep->next) {
+                       LM_DBG("DPID: %i PRIO : %i\n", rulep->dpid, rulep->pr);
+                       if (rpc->struct_add(ih, "{","ENTRY", &sh) < 0)
+                       {
+                               rpc->fault(ctx, 500, "Internal error root 
reply");
+                               return;
+                       }
+
+                       if (rpc->struct_add(sh, "dd", "PRIO", rulep->pr, 
+                               "MATCHOP", rulep->matchop)<0)
+                       {
+                               rpc->fault(ctx, 500, "Internal error adding 
prio");
+                               return;
+                       }
+                       if (rpc->struct_add(sh, "s", "MATCHEXP", 
rulep->match_exp) < 0 )
+                       {
+                               rpc->fault(ctx, 500, "Internal error adding 
match exp");
+                               return;
+                       }
+                       if (rpc->struct_add(sh, "d", "MATCHLEN", 
rulep->matchlen) < 0 )
+                       {
+                               rpc->fault(ctx, 500, "Internal error adding 
expression data and attribute");
+                               return;
+                       }
+                       if (rpc->struct_add(sh, "s", "SUBSTEXP", 
rulep->subst_exp) < 0 )
+                       {
+                               rpc->fault(ctx, 500, "Internal error adding 
subst exp");
+                               return;
+                       }
+                       if (rpc->struct_add(sh, "s", "REPLEXP", 
rulep->repl_exp) < 0 )
+                       {
+                               rpc->fault(ctx, 500, "Internal error adding 
replace exp ");
+                               return;
+                       }
+                       if (rpc->struct_add(sh, "s", "ATTRS", rulep->attrs) < 0 
)
+                       {
+                               rpc->fault(ctx, 500, "Internal error adding 
attribute");
+                               return;
+                       }
+               }
+       }
+
+       return;
+}
+
+static const char* dialplan_rpc_dump_doc[2] = {
+       "Dump dialplan content",
+       0
+};
+
 
 rpc_export_t dialplan_rpc_list[] = {
        {"dialplan.reload", dialplan_rpc_reload,
                dialplan_rpc_reload_doc, 0},
        {"dialplan.translate",   dialplan_rpc_translate,
                dialplan_rpc_translate_doc, 0},
+       {"dialplan.dump",   dialplan_rpc_dump,
+               dialplan_rpc_dump_doc, 0},
        {0, 0, 0, 0}
 };
 
diff --git a/modules/dialplan/doc/dialplan_admin.xml 
b/modules/dialplan/doc/dialplan_admin.xml
index 6b07a2d..5bfa870 100644
--- a/modules/dialplan/doc/dialplan_admin.xml
+++ b/modules/dialplan/doc/dialplan_admin.xml
@@ -553,6 +553,22 @@ xlog("translated to var $var(y) \n");
        <section>
        <title>Exported RPC Commands</title>
 
+               <section id="dialplan.r.dp.dump">
+                       <title><varname>dialplan.dump</varname></title>
+                       <para>
+                       Dumps the content of one dialplan ID
+                       </para>
+                       <para>
+                       Name: <emphasis>dialplan.dump</emphasis>
+                       </para>
+                       <para>Parameters: <emphasis>Dialplan 
ID</emphasis></para>
+                       <para>
+                       Example:
+                       </para>
+        <programlisting  format="linespecific">
+               &sercmd; dialplan.dump 100
+               </programlisting>
+               </section>
                <section id="dialplan.r.dp.reload">
                        <title><varname>dialplan.reload</varname></title>
                        <para>


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

Reply via email to