[asterisk-commits] rizzo: branch rizzo/astobj2 r47261 - /team/rizzo/astobj2/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Nov 7 07:35:54 MST 2006


Author: rizzo
Date: Tue Nov  7 08:35:54 2006
New Revision: 47261

URL: http://svn.digium.com/view/asterisk?rev=47261&view=rev
Log:
put the body of "sip show channel" and "sip show history" in
separate functions, to make it easy to move the dialoglist to
use containers, either with iterators or callbacks.

Note that currently (and in all versions so far)
these two functions, which are expensive and can take a long
time to do the I/O, run with the list locked.
This means that during their execution, incoming packets cannot
be processed (find_call() blocks on the list).

Moving the implementation to use iterators will remove this
problem (this commit is a step in that direction, but we are not there yet).


Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?rev=47261&r1=47260&r2=47261&view=diff
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Tue Nov  7 08:35:54 2006
@@ -10668,109 +10668,145 @@
 	return NULL;
 }
 
+/*!
+ * When running functions on the list of pvt's (dialogs), it is convenient
+ * to have the arguments all in one structure. This not only makes it easy
+ * to make the transition of the pvt list to proper containers, but also eases
+ * the implementation of other functions that need to run over the entire list.
+ * At this time, we need to store a file descriptor for I/O, a string and its length
+ * (used as a search key), and a variable used to count the number of matches.
+ */
+struct pvt_cb_arg {
+	int fd;			/* descriptor used for I/O */
+	const char *str;	/* search string */
+	int len;		/* length of the above string */
+	uint found;		/* number of matches */
+};
+
+/*! \brief show one channel */
+static int show_channel_cb(const struct sip_pvt *cur, struct pvt_cb_arg *arg)
+{
+	char formatbuf[BUFSIZ/2];
+	int fd = arg->fd;
+
+	if (strncasecmp(cur->callid, arg->str, arg->len))
+		return 0;
+	ast_cli(fd,"\n");
+	if (cur->subscribed != NONE)
+		ast_cli(fd, "  * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
+	else
+		ast_cli(fd, "  * SIP Call\n");
+	ast_cli(fd, "  Curr. trans. direction:  %s\n", ast_test_flag(&cur->flags[0], SIP_OUTGOING) ? "Outgoing" : "Incoming");
+	ast_cli(fd, "  Call-ID:                %s\n", cur->callid);
+	ast_cli(fd, "  Owner channel ID:       %s\n", cur->owner ? cur->owner->name : "<none>");
+	ast_cli(fd, "  Our Codec Capability:   %d\n", cur->capability);
+	ast_cli(fd, "  Non-Codec Capability (DTMF):   %d\n", cur->noncodeccapability);
+	ast_cli(fd, "  Their Codec Capability:   %d\n", cur->peercapability);
+	ast_cli(fd, "  Joint Codec Capability:   %d\n", cur->jointcapability);
+	ast_cli(fd, "  Format:                 %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0) );
+	ast_cli(fd, "  T.38 support            %s\n", cur->udptl ? "Yes" : "No");
+	ast_cli(fd, "  Video support           %s\n", cur->vrtp ? "Yes" : "No");
+	ast_cli(fd, "  MaxCallBR:              %d kbps\n", cur->maxcallbitrate);
+	ast_cli(fd, "  Theoretical Address:    %s:%d\n", ast_inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port));
+	ast_cli(fd, "  Received Address:       %s:%d\n", ast_inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port));
+	ast_cli(fd, "  SIP Transfer mode:      %s\n", transfermode2str(cur->allowtransfer));
+	ast_cli(fd, "  NAT Support:            %s\n", nat2str(ast_test_flag(&cur->flags[0], SIP_NAT)));
+	ast_cli(fd, "  Audio IP:               %s %s\n", ast_inet_ntoa(cur->redirip.sin_addr.s_addr ? cur->redirip.sin_addr : cur->ourip), cur->redirip.sin_addr.s_addr ? "(Outside bridge)" : "(local)" );
+	ast_cli(fd, "  Our Tag:                %s\n", cur->tag);
+	ast_cli(fd, "  Their Tag:              %s\n", cur->theirtag);
+	ast_cli(fd, "  SIP User agent:         %s\n", cur->useragent);
+	if (!ast_strlen_zero(cur->username))
+		ast_cli(fd, "  Username:               %s\n", cur->username);
+	if (!ast_strlen_zero(cur->peername))
+		ast_cli(fd, "  Peername:               %s\n", cur->peername);
+	if (!ast_strlen_zero(cur->uri))
+		ast_cli(fd, "  Original uri:           %s\n", cur->uri);
+	if (!ast_strlen_zero(cur->cid_num))
+		ast_cli(fd, "  Caller-ID:              %s\n", cur->cid_num);
+	ast_cli(fd, "  Need Destroy:           %d\n", ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY));
+	ast_cli(fd, "  Last Message:           %s\n", cur->lastmsg);
+	ast_cli(fd, "  Promiscuous Redir:      %s\n", ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR) ? "Yes" : "No");
+	ast_cli(fd, "  Route:                  %s\n", cur->route ? cur->route->hop : "N/A");
+	ast_cli(fd, "  DTMF Mode:              %s\n", dtmfmode2str(ast_test_flag(&cur->flags[0], SIP_DTMF)));
+	ast_cli(fd, "  SIP Options:            ");
+	if (cur->sipoptions) {
+		int x;
+		for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) {
+			if (cur->sipoptions & sip_options[x].id)
+				ast_cli(fd, "%s ", sip_options[x].text);
+		}
+	} else
+		ast_cli(fd, "(none)\n");
+	ast_cli(fd, "\n\n");
+	arg->found++;
+	return 1;	/* found */
+}
+
 /*! \brief Show details of one active dialog */
 static int sip_show_channel(int fd, int argc, char *argv[])
 {
 	struct sip_pvt *cur;
-	size_t len;
-	int found = 0;
+	struct pvt_cb_arg arg;
 
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
-	len = strlen(argv[3]);
+	arg.fd = fd;
+	arg.str = argv[3];
+	arg.len = strlen(argv[3]);
+	arg.found = 0;
 	dialoglist_lock();
 	for (cur = dialoglist; cur; cur = cur->next) {
-		if (!strncasecmp(cur->callid, argv[3], len)) {
-			char formatbuf[BUFSIZ/2];
-			ast_cli(fd,"\n");
-			if (cur->subscribed != NONE)
-				ast_cli(fd, "  * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
-			else
-				ast_cli(fd, "  * SIP Call\n");
-			ast_cli(fd, "  Curr. trans. direction:  %s\n", ast_test_flag(&cur->flags[0], SIP_OUTGOING) ? "Outgoing" : "Incoming");
-			ast_cli(fd, "  Call-ID:                %s\n", cur->callid);
-			ast_cli(fd, "  Owner channel ID:       %s\n", cur->owner ? cur->owner->name : "<none>");
-			ast_cli(fd, "  Our Codec Capability:   %d\n", cur->capability);
-			ast_cli(fd, "  Non-Codec Capability (DTMF):   %d\n", cur->noncodeccapability);
-			ast_cli(fd, "  Their Codec Capability:   %d\n", cur->peercapability);
-			ast_cli(fd, "  Joint Codec Capability:   %d\n", cur->jointcapability);
-			ast_cli(fd, "  Format:                 %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0) );
-			ast_cli(fd, "  T.38 support            %s\n", cur->udptl ? "Yes" : "No");
-			ast_cli(fd, "  Video support           %s\n", cur->vrtp ? "Yes" : "No");
-			ast_cli(fd, "  MaxCallBR:              %d kbps\n", cur->maxcallbitrate);
-			ast_cli(fd, "  Theoretical Address:    %s:%d\n", ast_inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port));
-			ast_cli(fd, "  Received Address:       %s:%d\n", ast_inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port));
-			ast_cli(fd, "  SIP Transfer mode:      %s\n", transfermode2str(cur->allowtransfer));
-			ast_cli(fd, "  NAT Support:            %s\n", nat2str(ast_test_flag(&cur->flags[0], SIP_NAT)));
-			ast_cli(fd, "  Audio IP:               %s %s\n", ast_inet_ntoa(cur->redirip.sin_addr.s_addr ? cur->redirip.sin_addr : cur->ourip), cur->redirip.sin_addr.s_addr ? "(Outside bridge)" : "(local)" );
-			ast_cli(fd, "  Our Tag:                %s\n", cur->tag);
-			ast_cli(fd, "  Their Tag:              %s\n", cur->theirtag);
-			ast_cli(fd, "  SIP User agent:         %s\n", cur->useragent);
-			if (!ast_strlen_zero(cur->username))
-				ast_cli(fd, "  Username:               %s\n", cur->username);
-			if (!ast_strlen_zero(cur->peername))
-				ast_cli(fd, "  Peername:               %s\n", cur->peername);
-			if (!ast_strlen_zero(cur->uri))
-				ast_cli(fd, "  Original uri:           %s\n", cur->uri);
-			if (!ast_strlen_zero(cur->cid_num))
-				ast_cli(fd, "  Caller-ID:              %s\n", cur->cid_num);
-			ast_cli(fd, "  Need Destroy:           %d\n", ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY));
-			ast_cli(fd, "  Last Message:           %s\n", cur->lastmsg);
-			ast_cli(fd, "  Promiscuous Redir:      %s\n", ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR) ? "Yes" : "No");
-			ast_cli(fd, "  Route:                  %s\n", cur->route ? cur->route->hop : "N/A");
-			ast_cli(fd, "  DTMF Mode:              %s\n", dtmfmode2str(ast_test_flag(&cur->flags[0], SIP_DTMF)));
-			ast_cli(fd, "  SIP Options:            ");
-			if (cur->sipoptions) {
-				int x;
-				for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) {
-					if (cur->sipoptions & sip_options[x].id)
-						ast_cli(fd, "%s ", sip_options[x].text);
-				}
-			} else
-				ast_cli(fd, "(none)\n");
-			ast_cli(fd, "\n\n");
-			found++;
-		}
+		show_channel_cb(cur, &arg);
 	}
 	dialoglist_unlock();
-	if (!found) 
+	if (arg.found == 0) 
 		ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
 	return RESULT_SUCCESS;
 }
 
+static int show_history_cb(const struct sip_pvt *cur, struct pvt_cb_arg *arg)
+{
+	int fd = arg->fd;
+	struct sip_history *hist;
+	int x = 0;
+
+	if (strncasecmp(cur->callid, arg->str, arg->len))
+		return 0;	/* not found */
+
+	ast_cli(fd,"\n");
+	if (cur->subscribed != NONE)
+		ast_cli(fd, "  * Subscription\n");
+	else
+		ast_cli(fd, "  * SIP Call\n");
+	if (cur->history)
+		AST_LIST_TRAVERSE(cur->history, hist, list)
+			ast_cli(fd, "%d. %s\n", ++x, hist->event);
+	if (x == 0)
+		ast_cli(fd, "Call '%s' has no history\n", cur->callid);
+	arg->found++;
+	return 0;
+}
+
 /*! \brief Show history details of one dialog */
 static int sip_show_history(int fd, int argc, char *argv[])
 {
 	struct sip_pvt *cur;
-	size_t len;
-	int found = 0;
+	struct pvt_cb_arg arg;
 
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	if (!recordhistory)
 		ast_cli(fd, "\n***Note: History recording is currently DISABLED.  Use 'sip history' to ENABLE.\n");
-	len = strlen(argv[3]);
+	arg.fd = 0;
+	arg.str = argv[3];
+	arg.len = strlen(argv[3]);
+	arg.found = 0;
 	dialoglist_lock();
 	for (cur = dialoglist; cur; cur = cur->next) {
-		if (!strncasecmp(cur->callid, argv[3], len)) {
-			struct sip_history *hist;
-			int x = 0;
-
-			ast_cli(fd,"\n");
-			if (cur->subscribed != NONE)
-				ast_cli(fd, "  * Subscription\n");
-			else
-				ast_cli(fd, "  * SIP Call\n");
-			if (cur->history)
-				AST_LIST_TRAVERSE(cur->history, hist, list)
-					ast_cli(fd, "%d. %s\n", ++x, hist->event);
-			if (x == 0)
-				ast_cli(fd, "Call '%s' has no history\n", cur->callid);
-			found++;
-		}
+		show_history_cb(cur, &arg);
 	}
 	dialoglist_unlock();
-	if (!found) 
+	if (!arg.found) 
 		ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]);
 	return RESULT_SUCCESS;
 }



More information about the asterisk-commits mailing list