[svn-commits] bmd: branch group/newcdr r119464 - in /team/group/newcdr: channels/ funcs/ in...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri May 30 19:00:15 CDT 2008


Author: bmd
Date: Fri May 30 19:00:14 2008
New Revision: 119464

URL: http://svn.digium.com/view/asterisk?view=rev&rev=119464
Log:
incorporate hangupsource concept to CEL logging and include it in CEL_HANGUP event, along with the Dialstatus variable

Modified:
    team/group/newcdr/channels/chan_iax2.c
    team/group/newcdr/channels/chan_sip.c
    team/group/newcdr/channels/chan_zap.c
    team/group/newcdr/funcs/func_channel.c
    team/group/newcdr/include/asterisk/channel.h
    team/group/newcdr/main/channel.c
    team/group/newcdr/main/pbx.c
    team/group/newcdr/res/res_agi.c

Modified: team/group/newcdr/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/channels/chan_iax2.c?view=diff&rev=119464&r1=119463&r2=119464
==============================================================================
--- team/group/newcdr/channels/chan_iax2.c (original)
+++ team/group/newcdr/channels/chan_iax2.c Fri May 30 19:00:14 2008
@@ -8646,17 +8646,28 @@
 			case IAX_COMMAND_HANGUP:
 				ast_set_flag(iaxs[fr->callno], IAX_ALREADYGONE);
 				ast_debug(1, "Immediately destroying %d, having received hangup\n", fr->callno);
-				/* Set hangup cause according to remote */
-				if (ies.causecode && iaxs[fr->callno]->owner)
-					iaxs[fr->callno]->owner->hangupcause = ies.causecode;
+				/* Set hangup cause according to remote and hangupsource */
+				if (iaxs[fr->callno]->owner) {
+					struct ast_channel *owner = iaxs[fr->callno]->owner;
+					if (ies.causecode) {
+						owner->hangupcause = ies.causecode;
+					}
+					ast_set_hangupsource(owner, owner->name, 0);
+				}
+				
 				/* Send ack immediately, before we destroy */
 				send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
 				iax2_destroy(fr->callno);
 				break;
 			case IAX_COMMAND_REJECT:
-				/* Set hangup cause according to remote */
-				if (ies.causecode && iaxs[fr->callno]->owner)
-					iaxs[fr->callno]->owner->hangupcause = ies.causecode;
+				/* Set hangup cause according to remote and hangup source */
+				if (iaxs[fr->callno]->owner) {
+					struct ast_channel *owner = iaxs[fr->callno]->owner;
+					if (ies.causecode) {
+						owner->hangupcause = ies.causecode;
+					}
+					ast_set_hangupsource(owner, owner->name, 0);
+				}
 
 				if (!ast_test_flag(iaxs[fr->callno], IAX_PROVISION)) {
 					if (iaxs[fr->callno]->owner && authdebug)

Modified: team/group/newcdr/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/channels/chan_sip.c?view=diff&rev=119464&r1=119463&r2=119464
==============================================================================
--- team/group/newcdr/channels/chan_sip.c (original)
+++ team/group/newcdr/channels/chan_sip.c Fri May 30 19:00:14 2008
@@ -15804,16 +15804,20 @@
 		/* First we ACK */
 		xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
 		ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", get_header(&p->initreq, "From"));
-		if (!req->ignore && p->owner)
+		if (!req->ignore && p->owner) {
+			ast_set_hangupsource(p->owner, p->owner->name, 0);
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
+		}
 		p->needdestroy = 1;
 		sip_alreadygone(p);
 		break;
 
 	case 404: /* Not found */
 		xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
-		if (p->owner && !req->ignore)
+		if (p->owner && !req->ignore) {
+			ast_set_hangupsource(p->owner, p->owner->name, 0);
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
+		}
 		sip_alreadygone(p);
 		break;
 
@@ -18391,8 +18395,10 @@
 		update_call_counter(p, DEC_CALL_LIMIT);
 
 	stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */
-	if (p->owner)
+	if (p->owner) {
+		ast_set_hangupsource(p->owner, p->owner->name, 0);
 		ast_queue_hangup(p->owner);
+	}
 	else
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 	if (p->initreq.len > 0) {
@@ -18559,6 +18565,7 @@
 				ast_queue_hangup_with_cause(p->owner, AST_CAUSE_PROTOCOL_ERROR);
 		}
 	} else if (p->owner) {
+		ast_set_hangupsource(p->owner, p->owner->name, 0);
 		ast_queue_hangup(p->owner);
 		ast_debug(3, "Received bye, issuing owner hangup\n");
 	} else {

Modified: team/group/newcdr/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/channels/chan_zap.c?view=diff&rev=119464&r1=119463&r2=119464
==============================================================================
--- team/group/newcdr/channels/chan_zap.c (original)
+++ team/group/newcdr/channels/chan_zap.c Fri May 30 19:00:14 2008
@@ -5108,6 +5108,7 @@
 			
 				if (ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) > p->polarityonanswerdelay) {
 					ast_debug(1, "Polarity Reversal detected and now Hanging up on channel %d\n", p->channel);
+					ast_set_hangupsource(p->owner, p->owner->name, 0);
 					ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
 					p->polarity = POLARITY_IDLE;
 				} else
@@ -5229,6 +5230,12 @@
 		return f;
 	}
 	f = zt_handle_event(ast);
+
+    /* tell the cdr this zap device hung up */
+	if (f == NULL) {
+		ast_set_hangupsource(ast, ast->name, 0);
+	}
+
 	return f;
 }
 
@@ -11062,6 +11069,8 @@
 									case PRI_CAUSE_NORMAL_TEMPORARY_FAILURE:
 										pri->pvts[chanpos]->subs[SUB_REAL].needcongestion =1;
 										break;
+									case PRI_CAUSE_NORMAL_CLEARING:
+										ast_set_hangupsource(pri->pvts[chanpos]->owner, pri->pvts[chanpos]->owner->name, 0);
 									default:
 										pri->pvts[chanpos]->owner->_softhangup |= AST_SOFTHANGUP_DEV;
 									}

Modified: team/group/newcdr/funcs/func_channel.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/funcs/func_channel.c?view=diff&rev=119464&r1=119463&r2=119464
==============================================================================
--- team/group/newcdr/funcs/func_channel.c (original)
+++ team/group/newcdr/funcs/func_channel.c Fri May 30 19:00:14 2008
@@ -95,6 +95,8 @@
 		locked_copy_string(chan, buf, chan->accountcode, len);
 	else if (!strcasecmp(data, "peeraccount"))
 		locked_copy_string(chan, buf, chan->peeraccount, len);
+	else if (!strcasecmp(data, "hangupsource"))
+		locked_copy_string(chan, buf, chan->hangupsource, len);
 	else if (!strcasecmp(data, "appname") && chan->appl)
 		locked_copy_string(chan, buf, chan->appl, len);
 	else if (!strcasecmp(data, "appdata") && chan->data)
@@ -176,6 +178,9 @@
 		ast_channel_unlock(chan);
 	} else if (!strcasecmp(data, "peeraccount"))
 		locked_string_field_set(chan, peeraccount, value);
+	else if (!strcasecmp(data, "hangupsource"))
+		/* XXX - should we be forcing this here? */
+		ast_set_hangupsource(chan, value, 0);
 #ifdef CHANNEL_TRACE
 	else if (!strcasecmp(data, "trace")) {
 		ast_channel_lock(chan);

Modified: team/group/newcdr/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/include/asterisk/channel.h?view=diff&rev=119464&r1=119463&r2=119464
==============================================================================
--- team/group/newcdr/include/asterisk/channel.h (original)
+++ team/group/newcdr/include/asterisk/channel.h Fri May 30 19:00:14 2008
@@ -439,6 +439,7 @@
 		AST_STRING_FIELD(uniqueid);		/*!< Unique Channel Identifier */
 		AST_STRING_FIELD(linkedid);		/*!< Linked Channel Identifier -- gets propagated by linkage */
 		AST_STRING_FIELD(parkinglot);		/*! Default parking lot, if empty, default parking lot  */
+		AST_STRING_FIELD(hangupsource);		/*! Who is responsible for hanging up this channel */
 	);
 	
 	int fds[AST_MAX_FDS];				/*!< File descriptors for channel -- Drivers will poll on
@@ -939,6 +940,16 @@
  * \param cause	Ast hangupcause for hangup (see cause.h) */
 int ast_softhangup_nolock(struct ast_channel *chan, int cause);
 
+/*! \brief Set the source of the hangup in this channel and it's bridge
+ * \param chan channel to set the field on
+ * \param source a string describing the source of the hangup for this channel
+ *
+ * Hangupsource is generally the channel name that caused the bridge to be
+ * hung up, but it can also be other things such as "dialplan/agi"
+ * This can then be logged in the CDR or CEL
+ */
+void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force);
+
 /*! \brief Check to see if a channel is needing hang up 
  * \param chan channel on which to check for hang up
  * This function determines if the channel is being requested to be hung up.

Modified: team/group/newcdr/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/channel.c?view=diff&rev=119464&r1=119463&r2=119464
==============================================================================
--- team/group/newcdr/main/channel.c (original)
+++ team/group/newcdr/main/channel.c Fri May 30 19:00:14 2008
@@ -1632,12 +1632,30 @@
 	clone->rawreadformat = clone->nativeformats;
 }
 
+void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
+{
+	struct ast_channel *bridge;
+
+	ast_channel_lock(chan);
+	if (force || ast_strlen_zero(chan->hangupsource)) {
+		ast_string_field_set(chan, hangupsource, source);
+	}
+	bridge = ast_bridged_channel(chan);
+	ast_channel_unlock(chan);
+
+	if (bridge && (force || ast_strlen_zero(bridge->hangupsource))) {
+		ast_channel_lock(bridge);
+		ast_string_field_set(chan, hangupsource, source);
+		ast_channel_unlock(bridge);
+	}
+}
+
 /*! \brief Hangup a channel */
 int ast_hangup(struct ast_channel *chan)
 {
 	int res = 0;
 	struct ast_cdr *cdr = NULL;
-	char cause_str[16];
+	char extra_str[64]; /* used for cel logging below */
 
 	/* Don't actually hang up a channel that will masquerade as someone else, or
 	   if someone is going to masquerade as us */
@@ -1688,8 +1706,9 @@
 			chan->generator->release(chan, chan->generatordata);
 	chan->generatordata = NULL;
 	chan->generator = NULL;
-	snprintf(cause_str, sizeof(cause_str), "%d", chan->hangupcause);
-	ast_cel_report_event(chan, CEL_HANGUP, NULL, cause_str, NULL);
+
+	snprintf(extra_str, sizeof(extra_str), "%d,%s,%s", chan->hangupcause, chan->hangupsource, S_OR(pbx_builtin_getvar_helper(chan, "DIALSTATUS"), ""));
+	ast_cel_report_event(chan, CEL_HANGUP, NULL, extra_str, NULL);
 	
 	if (chan->cdr) {		/* End the CDR if it hasn't already */
 		ast_cdr_end(chan->cdr);

Modified: team/group/newcdr/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/pbx.c?view=diff&rev=119464&r1=119463&r2=119464
==============================================================================
--- team/group/newcdr/main/pbx.c (original)
+++ team/group/newcdr/main/pbx.c Fri May 30 19:00:14 2008
@@ -7408,6 +7408,8 @@
  */
 static int pbx_builtin_hangup(struct ast_channel *chan, void *data)
 {
+	ast_set_hangupsource(chan, "dialplan/builtin", 0);
+	
 	if (!ast_strlen_zero(data)) {
 		int cause;
 		char *endptr;

Modified: team/group/newcdr/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/res/res_agi.c?view=diff&rev=119464&r1=119463&r2=119464
==============================================================================
--- team/group/newcdr/res/res_agi.c (original)
+++ team/group/newcdr/res/res_agi.c Fri May 30 19:00:14 2008
@@ -1424,6 +1424,7 @@
 
 	if (argc == 1) {
 		/* no argument: hangup the current channel */
+		ast_set_hangupsource(chan, "dialplan/agi", 0);
 		ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT);
 		ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
 		return RESULT_SUCCESS;
@@ -1432,6 +1433,7 @@
 		c = ast_get_channel_by_name_locked(argv[1]);
 		if (c) {
 			/* we have a matching channel */
+			ast_set_hangupsource(c, "dialplan/agi", 0);
 			ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT);
 			ast_agi_fdprintf(chan, agi->fd, "200 result=1\n");
 			ast_channel_unlock(c);




More information about the svn-commits mailing list