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

Author: Jason Penton <[email protected]>
Committer: Jason Penton <[email protected]>
Date:   Wed May 28 12:12:35 2014 +0200

modules/cdp: added RPC cmd to list diameter information, including peers and 
their detail

---

 modules/cdp/cdp_rpc.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/modules/cdp/cdp_rpc.c b/modules/cdp/cdp_rpc.c
index 53aabe5..0db5b26 100644
--- a/modules/cdp/cdp_rpc.c
+++ b/modules/cdp/cdp_rpc.c
@@ -12,10 +12,13 @@
 #include "../../dprint.h"
 
 extern dp_config *config;
+extern peer_list_t *peer_list;
+extern gen_lock_t *peer_list_lock;
+extern char *dp_states[];
 
 static const char* cdp_rpc_disable_peer_doc[2]         =       {"disable 
diameter peer", 0 };
 static const char* cdp_rpc_enable_peer_doc[2]  =       {"enable diameter 
peer", 0 };
-
+static const char* cdp_rpc_list_peers_doc[2]   =       {"list diameter peers 
and their state", 0 };
 
 static void cdp_rpc_enable_peer(rpc_t* rpc, void* ctx)
 {
@@ -58,9 +61,57 @@ static void cdp_rpc_disable_peer(rpc_t* rpc, void* ctx)
 
 }
 
+static void cdp_rpc_list_peers(rpc_t* rpc, void* ctx)
+{
+    void *peers_header;
+    void *peers_container;
+    void *peerdetail_container;
+    peer *i;
+
+    if (rpc->add(ctx, "{", &peers_header) < 0) {
+            rpc->fault(ctx, 500, "Internal error creating top rpc");
+            return;
+    }
+
+    if (rpc->struct_add(peers_header, "SSddddddd{",
+                            "Realm", &config->realm,
+                            "Identity", &config->identity,
+                            "Accept unknown peers", 
config->accept_unknown_peers,
+                            "Connect timeout", config->connect_timeout,
+                            "Transaction timeout", config->transaction_timeout,
+                            "Default auth session timeout", 
config->default_auth_session_timeout,
+                            "Queue length", config->queue_length,
+                            "Workers", config->workers,
+                            "Peer count", config->peers_cnt,
+                            "Peers", &peers_container) < 0) {
+            rpc->fault(ctx, 500, "Internal error creating peers header 
struct");
+            return;
+    }
+
+    lock_get(peer_list_lock);
+    i = peer_list->head;
+    while (i) {
+            if (rpc->struct_add(peers_container, "S{",
+                            "FQDN", &i->fqdn,
+                            "Details", &peerdetail_container) < 0) {
+                    rpc->fault(ctx, 500, "Internal error creating peers 
container struct");
+                    return;
+            }
+            if (rpc->struct_add(peerdetail_container, "ss",
+                    "State", dp_states[(int)i->state],
+                    "Disabled", i->disabled?"True":"False") < 0) {
+                    rpc->fault(ctx, 500, "Internal error creating peer detail 
container struct");
+                    return;
+            }
+            i = i->next;
+    }
+    lock_release(peer_list_lock);
+}
+
 rpc_export_t cdp_rpc[] = {
        {"cdp.disable_peer",    cdp_rpc_disable_peer,   
cdp_rpc_disable_peer_doc,   0},
        {"cdp.enable_peer",     cdp_rpc_enable_peer,    
cdp_rpc_enable_peer_doc,        0},
+       {"cdp.list_peers",      cdp_rpc_list_peers,     cdp_rpc_list_peers_doc, 
        0},
        {0, 0, 0, 0}
 };
 


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

Reply via email to