Browse code

modules/sca: reduce verbosity of RPC sca.all_subscriptions output

- accommodate more subscriptions without hitting kamcmd buffer limits.

Andrew Mortensen authored on 08/04/2013 19:01:41
Showing 1 changed files
... ...
@@ -23,6 +23,9 @@
23 23
  */
24 24
 #include "sca_common.h"
25 25
 
26
+#include <sys/types.h>
27
+#include <time.h>
28
+
26 29
 #include "sca_rpc.h"
27 30
 
28 31
 #include "sca.h"
... ...
@@ -82,7 +85,9 @@ sca_rpc_show_all_subscriptions( rpc_t *rpc, void *ctx )
82 85
     sca_hash_table	*ht;
83 86
     sca_hash_entry	*ent;
84 87
     sca_subscription	*sub;
88
+    sip_uri_t		aor_uri, sub_uri;
85 89
     str			sub_state = STR_NULL;
90
+    time_t		now;
86 91
     int			i;
87 92
     int			rc = 0;
88 93
 
... ...
@@ -91,6 +96,8 @@ sca_rpc_show_all_subscriptions( rpc_t *rpc, void *ctx )
91 96
 	return;
92 97
     }
93 98
 
99
+    now = time( NULL );
100
+
94 101
     for ( i = 0; i < ht->size; i++ ) {
95 102
 	sca_hash_table_lock_index( ht, i );
96 103
 
... ...
@@ -98,12 +105,31 @@ sca_rpc_show_all_subscriptions( rpc_t *rpc, void *ctx )
98 105
 	    sub = (sca_subscription *)ent->value;
99 106
 	    sca_subscription_state_to_str( sub->state, &sub_state );
100 107
 
101
-	    rc = rpc->printf( ctx, "%d: %.*s %.*s %s %d %.*s", i,
102
-				STR_FMT( &sub->target_aor ),
103
-				STR_FMT( &sub->subscriber ),
104
-				sca_event_name_from_type( sub->event ),
105
-				sub->expires,
106
-				STR_FMT( &sub_state ));
108
+	    rc = parse_uri( sub->target_aor.s, sub->target_aor.len, &aor_uri );
109
+	    if ( rc >= 0 ) {
110
+		rc = parse_uri( sub->subscriber.s, sub->subscriber.len,
111
+				&sub_uri );
112
+	    }
113
+	    if ( rc >= 0 ) {
114
+		rc = rpc->printf( ctx, "%.*s %.*s%s%.*s %s %ld %.*s",
115
+				    STR_FMT( &aor_uri.user ),
116
+				    STR_FMT( &sub_uri.host ),
117
+				    (sub_uri.port.len ? ":" : "" ),
118
+				    STR_FMT( &sub_uri.port ),
119
+				    sca_event_name_from_type( sub->event ),
120
+				    (long)(sub->expires - now),
121
+				    STR_FMT( &sub_state ));
122
+	    } else {
123
+		LM_ERR( "sca_rpc_show_all_subscriptions: parse_uri %.*s "
124
+			"failed, dumping unparsed info",
125
+			STR_FMT( &sub->target_aor ));
126
+		rc = rpc->printf( ctx, "%.*s %.*s %s %ld %.*s",
127
+				    STR_FMT( &sub->target_aor ),
128
+				    STR_FMT( &sub->subscriber ),
129
+				    sca_event_name_from_type( sub->event ),
130
+				    (long)sub->expires,
131
+				    STR_FMT( &sub_state ));
132
+	    }
107 133
 
108 134
 	    if ( rc < 0 ) {
109 135
 		/* make sure we unlock below */