Browse code

cnxcc: added rpc and removed mi command

Daniel-Constantin Mierla authored on 02/01/2017 12:14:10
Showing 2 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2012 Carlos Ruiz Díaz (caruizdiaz.com),
5 3
  *                    ConexionGroup (www.conexiongroup.com)
6 4
  *
... ...
@@ -125,9 +123,9 @@ static credit_data_t *__alloc_new_credit_data(str *client_id, credit_type_t type
125 123
 static credit_data_t *__get_or_create_credit_data_entry(str *client_id, credit_type_t type);
126 124
 
127 125
 /*
128
- * MI interface
126
+ * control interface
129 127
  */
130
-static struct mi_root *__mi_credit_control_stats(struct mi_root *tree, void *param);
128
+void rpc_credit_control_stats(rpc_t* rpc, void* ctx);
131 129
 
132 130
 /*
133 131
  * Dialog management callback functions
... ...
@@ -179,10 +177,17 @@ static const char* rpc_kill_call_doc[2] = {
179 177
 	NULL
180 178
 };
181 179
 
182
-rpc_export_t ul_rpc[] = {
180
+static const char* rpc_credit_control_stats_doc[2] = {
181
+	"List credit control stats",
182
+	NULL
183
+};
184
+
185
+
186
+rpc_export_t cnxcc_rpc[] = {
183 187
     { "cnxcc.active_clients", rpc_active_clients, rpc_active_clients_doc,	0},
184 188
     { "cnxcc.check_client", rpc_check_client_stats, rpc_check_client_stats_doc,	0},
185 189
     { "cnxcc.kill_call", rpc_kill_call, rpc_kill_call_doc, 0},
190
+	{ "cnxcc.stats", rpc_credit_control_stats, rpc_credit_control_stats_doc, 0},
186 191
     { NULL, NULL, NULL, 0}
187 192
 };
188 193
 
... ...
@@ -308,15 +313,13 @@ static int __mod_init(void) {
308 313
 	cnxcc_lock_init(_data.money.lock);
309 314
 	cnxcc_lock_init(_data.channel.lock);
310 315
 
311
-	register_mi_cmd(__mi_credit_control_stats, "cnxcc_stats", NULL, NULL, 0);
312
-
313 316
 	/*
314 317
 	 * One for time based monitoring
315 318
 	 * One for money based monitoring
316 319
 	 */
317 320
 	register_dummy_timers(NUMBER_OF_TIMERS);
318 321
 
319
-	if (rpc_register_array(ul_rpc) != 0) {
322
+	if (rpc_register_array(cnxcc_rpc) != 0) {
320 323
 		LM_ERR("Failed registering RPC commands\n");
321 324
 		return -1;
322 325
 	}
... ...
@@ -1977,46 +1980,19 @@ static int __pv_get_calls(struct sip_msg *msg, pv_param_t *param, pv_value_t *re
1977 1980
 	return -1;
1978 1981
 }
1979 1982
 
1980
-static struct mi_root *__mi_credit_control_stats(struct mi_root *tree, void *param) {
1981
-	char *p;
1982
-	int len;
1983
-	struct mi_root *rpl_tree;
1984
-	struct mi_node *node, *node1;
1985
-
1986
-	rpl_tree = init_mi_tree(200, "OK", 2);
1987
-	node	 = &rpl_tree->node;
1988
-
1989
-	node1 = add_mi_node_child(node, 0, MI_SSTR("CNX Credit Control"), 0, 0);
1990
-	if (node1 == NULL) {
1991
-		LM_ERR("Error creating child node\n");
1992
-		goto error;
1993
-	}
1983
+void rpc_credit_control_stats(rpc_t* rpc, void* ctx)
1984
+{
1985
+	void *rh;
1994 1986
 
1995
-	p = int2str((unsigned long) _data.stats->active, &len);
1996
-	if (p == NULL) {
1997
-		LM_ERR("Error converting INT to STR\n");
1998
-		goto error;
1999
-	}
2000
-	add_mi_node_child(node1, MI_DUP_VALUE, MI_SSTR("active"), p, len);
2001
-
2002
-	p = int2str((unsigned long) _data.stats->dropped, &len);
2003
-	if (p == NULL) {
2004
-		LM_ERR("Error converting INT to STR\n");
2005
-		goto error;
2006
-	}
2007
-
2008
-	add_mi_node_child(node1, MI_DUP_VALUE, MI_SSTR("dropped"), p, len);
2009
-
2010
-	p = int2str((unsigned long) _data.stats->total, &len);
2011
-	if (p == NULL) {
2012
-		LM_ERR("Error converting INT to STR\n");
2013
-		goto error;
1987
+	if(rpc->add(ctx, "{", &rh)<0) {
1988
+		rpc->fault(ctx, 500, "Server failure");
1989
+		return;
2014 1990
 	}
2015 1991
 
2016
-	add_mi_node_child(node1, MI_DUP_VALUE, MI_SSTR("total"), p, len);
1992
+	rpc->struct_add(rh, "sddd",
1993
+				"info", "CNX Credit Control",
1994
+				"active", _data.stats->active,
1995
+				"dropped", _data.stats->dropped,
1996
+				"total", _data.stats->total);
2017 1997
 
2018
-	return rpl_tree;
2019
-
2020
-error:
2021
-	return init_mi_tree(500, MI_INTERNAL_ERR, MI_INTERNAL_ERR_LEN);
2022 1998
 }
... ...
@@ -352,7 +352,7 @@ if (!cnxcc_terminate_all("$var(customer)")) {
352 352
     </section>
353 353
    
354 354
     <section>
355
-	<title>Exported RPC Commands</title>
355
+	<title>RPC Commands</title>
356 356
 
357 357
 	<section>
358 358
 	    <title><varname>cnxcc.active_clients</varname></title>
... ...
@@ -401,6 +401,22 @@ if (!cnxcc_terminate_all("$var(customer)")) {
401 401
             &sercmd; cnxcc.kill_call qumojlaahitafih@carlosrdcnx-laptop.site
402 402
             </programlisting>
403 403
         </section>
404
+	<section>
405
+	    <title><varname>cnxcc.stats</varname></title>
406
+	    <para>
407
+		List credit control stats.
408
+	    </para>
409
+	    <para>
410
+		Parameters: <emphasis>none</emphasis>
411
+	    </para>
412
+	    <para>
413
+		Example:
414
+	    </para>
415
+	    <programlisting format="linespecific">
416
+	    &sercmd; cnxcc.stats
417
+	    </programlisting>
418
+	</section>
419
+
404 420
     </section>
405 421
 
406 422
     <section>