[asterisk-commits] qwell: trunk r90991 - in /trunk: CHANGES channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 4 15:23:31 CST 2007


Author: qwell
Date: Tue Dec  4 15:23:30 2007
New Revision: 90991

URL: http://svn.digium.com/view/asterisk?view=rev&rev=90991
Log:
Add manager action 'sipshowregistry'.

Closes issue #11464, patch by eliel.

Modified:
    trunk/CHANGES
    trunk/channels/chan_sip.c

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?view=diff&rev=90991&r1=90990&r2=90991
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Tue Dec  4 15:23:30 2007
@@ -4,6 +4,7 @@
 
 AMI - The manager (TCP/TLS/HTTP)
 --------------------------------
+  * Added a new action 'SIPshowregistry' to list SIP registrations.
   * Added TLS support for the manager interface and HTTP server
   * Added the URI redirect option for the built-in HTTP server
   * The output of CallerID in Manager events is now more consistent.

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=90991&r1=90990&r2=90991
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Tue Dec  4 15:23:30 2007
@@ -10811,6 +10811,59 @@
 
 	return CLI_SUCCESS;
 #undef FORMAT
+}
+
+/*! \brief Manager Action SIPShowRegistry description */
+static char mandescr_show_registry[] =
+"Description: Lists all registration requests and status\n"
+"Registrations will follow as separate events. followed by a final event called\n"
+"RegistrationsComplete.\n"
+"Variables: \n"
+"  ActionID: <id>       Action ID for this transaction. Will be returned.\n";
+
+/*! \brief Show SIP registrations in the manager API */
+static int manager_show_registry(struct mansession *s, const struct message *m)
+{
+	const char *id = astman_get_header(m, "ActionID");
+	char idtext[256] = "";
+	char tmpdat[256] = "";
+	int total = 0;
+	struct ast_tm tm;
+
+	if (!ast_strlen_zero(id))
+		snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id);
+
+	astman_send_listack(s, m, "Registrations will follow", "start");
+
+	ASTOBJ_CONTAINER_TRAVERSE(&regl, 1, do {
+		ASTOBJ_RDLOCK(iterator);
+		if (iterator->regtime.tv_sec) {
+			ast_localtime(&iterator->regtime, &tm, NULL);
+			ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
+		} else
+			tmpdat[0] = '\0';
+		astman_append(s,
+			"Event: RegistryEntry\r\n"
+			"Host: %s\r\n"
+			"Port: %d\r\n"
+			"Username: %s\r\n"
+			"Refresh: %d\r\n"
+			"State: %s\r\n"
+			"Reg.Time: %s\r\n"
+			"\r\n", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT,
+			iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
+		ASTOBJ_UNLOCK(iterator);
+		total++;
+	} while(0));
+
+	astman_append(s,
+		"Event: RegistrationsComplete\r\n"
+		"EventList: Complete\r\n"
+		"ListItems: %d\r\n"
+		"%s"
+		"\r\n", total, idtext);
+	
+	return 0;
 }
 
 static char mandescr_show_peers[] = 
@@ -19307,7 +19360,8 @@
 			"List SIP peers (text format)", mandescr_show_peers);
 	ast_manager_register2("SIPshowpeer", EVENT_FLAG_SYSTEM, manager_sip_show_peer,
 			"Show SIP peer (text format)", mandescr_show_peer);
-
+	ast_manager_register2("SIPshowregistry", EVENT_FLAG_SYSTEM, manager_show_registry,
+			"Show SIP registrations (text format)", mandescr_show_registry);
 	sip_poke_all_peers();	
 	sip_send_all_registers();
 	
@@ -19348,6 +19402,7 @@
 	/* Unregister AMI actions */
 	ast_manager_unregister("SIPpeers");
 	ast_manager_unregister("SIPshowpeer");
+	ast_manager_unregister("SIPshowregistry");
 
 	dialoglist_lock();
 	/* Hangup all dialogs if they have an owner */




More information about the asterisk-commits mailing list