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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Nov 7 09:43:10 MST 2006


Author: rizzo
Date: Tue Nov  7 10:43:09 2006
New Revision: 47267

URL: http://svn.digium.com/view/asterisk?rev=47267&view=rev
Log:
move sip show channels to a callback form


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=47267&r1=47266&r2=47267&view=diff
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Tue Nov  7 10:43:09 2006
@@ -10517,59 +10517,70 @@
         return __sip_show_channels(fd, argc, argv, 1);
 }
 
-/*! \brief SIP show channels CLI (main function) */
-static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions)
-{
+struct __show_chan_arg {
+	int fd;
+	int subscriptions;
+	int numchans;	/* return value */
+};
+
 #define FORMAT3 "%-15.15s  %-10.10s  %-11.11s  %-15.15s  %-13.13s  %-15.15s %-10.10s\n"
 #define FORMAT2 "%-15.15s  %-10.10s  %-11.11s  %-11.11s  %-4.4s  %-7.7s  %-15.15s\n"
 #define FORMAT  "%-15.15s  %-10.10s  %-11.11s  %5.5d/%5.5d  %-4.4s  %-3.3s %-3.3s  %-15.15s %-10.10s\n"
+static int show_chanannels_cb(struct sip_pvt *cur, struct __show_chan_arg *arg)
+{
+	if (cur->subscribed == NONE && !arg->subscriptions) {
+		/* set if SIP transfer in progress */
+		const char *referstatus = cur->refer ? referstatus2str(cur->refer->status) : "";
+
+		ast_cli(arg->fd, FORMAT, ast_inet_ntoa(cur->sa.sin_addr), 
+			S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
+			cur->callid, 
+			cur->ocseq, cur->icseq, 
+			ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), 
+			ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD) ? "Yes" : "No",
+			ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY) ? "(d)" : "",
+			cur->lastmsg ,
+			referstatus
+		);
+		arg->numchans++;
+	}
+	if (cur->subscribed != NONE && arg->subscriptions) {
+		ast_cli(arg->fd, FORMAT3, ast_inet_ntoa(cur->sa.sin_addr),
+			S_OR(cur->username, S_OR(cur->cid_num, "(None)")), 
+			cur->callid,
+			/* the 'complete' exten/context is hidden in the refer_to field for subscriptions */
+			cur->subscribed == MWI_NOTIFICATION ? "--" : cur->subscribeuri,
+			cur->subscribed == MWI_NOTIFICATION ? "<none>" : ast_extension_state2str(cur->laststate), 
+			subscription_type2str(cur->subscribed),
+			cur->subscribed == MWI_NOTIFICATION ? (cur->relatedpeer ? cur->relatedpeer->mailbox : "<none>") : "<none>"
+);
+		arg->numchans++;
+	}
+	return 0;	/* don't care, we scan all channels */
+}
+
+/*! \brief SIP show channels CLI (main function) */
+static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions)
+{
 	struct sip_pvt *cur;
-	int numchans = 0;
+	struct __show_chan_arg arg = { .fd = fd, .subscriptions = subscriptions, .numchans = 0 };
 
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
-	dialoglist_lock();
-	cur = dialoglist;
+
 	if (!subscriptions)
 		ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
 	else 
 		ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox");
-	for (; cur; cur = cur->next) {
-
-		if (cur->subscribed == NONE && !subscriptions) {
-			/* set if SIP transfer in progress */
-			const char *referstatus = cur->refer ? referstatus2str(cur->refer->status) : "";
-
-			ast_cli(fd, FORMAT, ast_inet_ntoa(cur->sa.sin_addr), 
-				S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
-				cur->callid, 
-				cur->ocseq, cur->icseq, 
-				ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), 
-				ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD) ? "Yes" : "No",
-				ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY) ? "(d)" : "",
-				cur->lastmsg ,
-				referstatus
-			);
-			numchans++;
-		}
-		if (cur->subscribed != NONE && subscriptions) {
-			ast_cli(fd, FORMAT3, ast_inet_ntoa(cur->sa.sin_addr),
-				S_OR(cur->username, S_OR(cur->cid_num, "(None)")), 
-			   	cur->callid,
-				/* the 'complete' exten/context is hidden in the refer_to field for subscriptions */
-				cur->subscribed == MWI_NOTIFICATION ? "--" : cur->subscribeuri,
-				cur->subscribed == MWI_NOTIFICATION ? "<none>" : ast_extension_state2str(cur->laststate), 
-				subscription_type2str(cur->subscribed),
-				cur->subscribed == MWI_NOTIFICATION ? (cur->relatedpeer ? cur->relatedpeer->mailbox : "<none>") : "<none>"
-);
-			numchans++;
-		}
+	dialoglist_lock();
+	for (cur = dialoglist; cur; cur = cur->next) {
+		show_chanannels_cb(cur, &arg);
 	}
 	dialoglist_unlock();
 	if (!subscriptions)
-		ast_cli(fd, "%d active SIP channel%s\n", numchans, (numchans != 1) ? "s" : "");
+		ast_cli(fd, "%d active SIP channel%s\n", arg.numchans, (arg.numchans != 1) ? "s" : "");
 	else
-		ast_cli(fd, "%d active SIP subscription%s\n", numchans, (numchans != 1) ? "s" : "");
+		ast_cli(fd, "%d active SIP subscription%s\n", arg.numchans, (arg.numchans != 1) ? "s" : "");
 	return RESULT_SUCCESS;
 #undef FORMAT
 #undef FORMAT2



More information about the asterisk-commits mailing list