[svn-commits] bmd: branch group/newcdr r116881 - in /team/group/newcdr: apps/ channels/ fun...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri May 16 19:36:56 CDT 2008


Author: bmd
Date: Fri May 16 19:36:54 2008
New Revision: 116881

URL: http://svn.digium.com/view/asterisk?view=rev&rev=116881
Log:
Some changes to how accountcode works in order to better handle
systems like Switchvox that do a lot of transfers/parks/queues/etc.
Instead of spreading between bridged channels, accountcode now tries
to stay only on the channel it's assigned to.  Also, a new variable,
peeraccount, is used to represent the accountcode of the channel on
the other side of the bridge.  This allows two parties with their own
accountcodes to participate on a call and be tracked successfully if
either one transfers away from the call.  Here's the specific changes
to the code:

1) chan->accountcode is changed to not copy implicitly across bridges.
2) chan_sip sets chan->accountcode in requested channels (instead of only calls that it originates)
3) a new channel stringfield, peeraccount is defined, representing the accountcode of the channel you're bridged with (or were bridged with, or about to be bridged with)
4) CHANNEL() dialplan function can now get/set accountcode and peeraccount, for channels with no CDRs
5) CDR() dialplan function can set the peeraccount field in the cdr structure
6) peeraccount and accountcode are copied around between channels during masqs and bridges such that they're always accurate (tested with queues with chan_local agents, sip assisted xfer, and park/unpark)
7) core show channels verbose now shows the peeraccount field too. 



Modified:
    team/group/newcdr/apps/app_dial.c
    team/group/newcdr/channels/chan_sip.c
    team/group/newcdr/funcs/func_cdr.c
    team/group/newcdr/funcs/func_channel.c
    team/group/newcdr/include/asterisk/cdr.h
    team/group/newcdr/include/asterisk/channel.h
    team/group/newcdr/main/cdr.c
    team/group/newcdr/main/channel.c
    team/group/newcdr/main/cli.c

Modified: team/group/newcdr/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/apps/app_dial.c?view=diff&rev=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/apps/app_dial.c (original)
+++ team/group/newcdr/apps/app_dial.c Fri May 16 19:36:54 2008
@@ -1481,7 +1481,9 @@
 		
 		/* Copy language from incoming to outgoing */
 		ast_string_field_set(tc, language, chan->language);
-		ast_string_field_set(tc, accountcode, chan->accountcode);
+		if (!ast_strlen_zero(chan->accountcode)) {
+			ast_string_field_set(tc, peeraccount, chan->accountcode);
+		}
 		tc->cdrflags = chan->cdrflags;
 		if (ast_strlen_zero(tc->musicclass))
 			ast_string_field_set(tc, musicclass, chan->musicclass);

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=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/channels/chan_sip.c (original)
+++ team/group/newcdr/channels/chan_sip.c Fri May 16 19:36:54 2008
@@ -4260,6 +4260,7 @@
 	ast_string_field_set(dialog, mohinterpret, peer->mohinterpret);
 	ast_string_field_set(dialog, tohost, peer->tohost);
 	ast_string_field_set(dialog, fullcontact, peer->fullcontact);
+	ast_string_field_set(dialog, accountcode, peer->accountcode);
 	ast_string_field_set(dialog, context, peer->context);
 	ast_string_field_set(dialog, parkinglot, peer->parkinglot);
 	dialog->outboundproxy = obproxy_get(dialog, peer);

Modified: team/group/newcdr/funcs/func_cdr.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/funcs/func_cdr.c?view=diff&rev=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/funcs/func_cdr.c (original)
+++ team/group/newcdr/funcs/func_cdr.c Fri May 16 19:36:54 2008
@@ -100,6 +100,8 @@
 
 	if (!strcasecmp(args.variable, "accountcode"))
 		ast_cdr_setaccount(chan, value);
+	else if (!strcasecmp(args.variable, "peeraccount"))
+		ast_cdr_setpeeraccount(chan, value);
 	else if (!strcasecmp(args.variable, "userfield"))
 		ast_cdr_setuserfield(chan, value);
 	else if (!strcasecmp(args.variable, "amaflags"))

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=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/funcs/func_channel.c (original)
+++ team/group/newcdr/funcs/func_channel.c Fri May 16 19:36:54 2008
@@ -90,6 +90,10 @@
 		locked_copy_string(chan, buf, ast_state2str(chan->_state), len);
 	else if (!strcasecmp(data, "channeltype"))
 		locked_copy_string(chan, buf, chan->tech->type, len);
+	else if (!strcasecmp(data, "accountcode"))
+		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, "transfercapability"))
 		locked_copy_string(chan, buf, transfercapability_table[chan->transfercapability & 0x1f], len);
 	else if (!strcasecmp(data, "callgroup")) {
@@ -115,6 +119,10 @@
 		locked_string_field_set(chan, parkinglot, value);
 	else if (!strcasecmp(data, "musicclass"))
 		locked_string_field_set(chan, musicclass, value);
+	else if (!strcasecmp(data, "accountcode"))
+		locked_string_field_set(chan, accountcode, value);
+	else if (!strcasecmp(data, "peeraccount"))
+		locked_string_field_set(chan, peeraccount, value);
 #ifdef CHANNEL_TRACE
 	else if (!strcasecmp(data, "trace")) {
 		ast_channel_lock(chan);

Modified: team/group/newcdr/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/include/asterisk/cdr.h?view=diff&rev=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/include/asterisk/cdr.h (original)
+++ team/group/newcdr/include/asterisk/cdr.h Fri May 16 19:36:54 2008
@@ -88,6 +88,8 @@
 	long int amaflags;				
 	/*! What account number to use */
 	char accountcode[AST_MAX_ACCOUNT_CODE];			
+	/*! Account number of the last person we talked to */
+	char peeraccount[AST_MAX_ACCOUNT_CODE];			
 	/*! flags */
 	unsigned int flags;				
 	/*! Unique Channel Identifier */
@@ -308,6 +310,9 @@
 /*! \brief Set account code, will generate AMI event */
 int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
 
+/*! \brief Set the peer account */
+int ast_cdr_setpeeraccount(struct ast_channel *chan, const char *account);
+
 /*! \brief Set AMA flags for channel */
 int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
 

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=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/include/asterisk/channel.h (original)
+++ team/group/newcdr/include/asterisk/channel.h Fri May 16 19:36:54 2008
@@ -433,6 +433,7 @@
 		AST_STRING_FIELD(language);		/*!< Language requested for voice prompts */
 		AST_STRING_FIELD(musicclass);		/*!< Default music class */
 		AST_STRING_FIELD(accountcode);		/*!< Account code for billing */
+		AST_STRING_FIELD(peeraccount);		/*!< Peer account code for billing */
 		AST_STRING_FIELD(userfield);		/*!< Userfield for CEL billing */
 		AST_STRING_FIELD(call_forward);		/*!< Where to forward to if asked to dial on this interface */
 		AST_STRING_FIELD(uniqueid);		/*!< Unique Channel Identifier */

Modified: team/group/newcdr/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/cdr.c?view=diff&rev=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/main/cdr.c (original)
+++ team/group/newcdr/main/cdr.c Fri May 16 19:36:54 2008
@@ -263,6 +263,8 @@
 		}
 	} else if (!strcasecmp(name, "accountcode"))
 		ast_copy_string(workspace, cdr->accountcode, workspacelen);
+	else if (!strcasecmp(name, "peeraccount"))
+		ast_copy_string(workspace, cdr->peeraccount, workspacelen);
 	else if (!strcasecmp(name, "uniqueid"))
 		ast_copy_string(workspace, cdr->uniqueid, workspacelen);
 	else if (!strcasecmp(name, "linkedid"))
@@ -642,6 +644,9 @@
 	if (ast_test_flag(from, AST_CDR_FLAG_LOCKED) || (ast_strlen_zero(to->accountcode) && !ast_strlen_zero(from->accountcode))) {
 		ast_copy_string(to->accountcode, from->accountcode, sizeof(to->accountcode));
 	}
+	if (ast_test_flag(from, AST_CDR_FLAG_LOCKED) || (ast_strlen_zero(to->peeraccount) && !ast_strlen_zero(from->peeraccount))) {
+		ast_copy_string(to->peeraccount, from->peeraccount, sizeof(to->peeraccount));
+	}
 	if (ast_test_flag(from, AST_CDR_FLAG_LOCKED) || (ast_strlen_zero(to->userfield) && !ast_strlen_zero(from->userfield))) {
 		ast_copy_string(to->userfield, from->userfield, sizeof(to->userfield));
 	}
@@ -824,6 +829,7 @@
 			cdr->disposition = (c->_state == AST_STATE_UP) ?  AST_CDR_ANSWERED : AST_CDR_NULL;
 			cdr->amaflags = c->amaflags ? c->amaflags :  ast_default_amaflags;
 			ast_copy_string(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode));
+			ast_copy_string(cdr->peeraccount, c->peeraccount, sizeof(cdr->peeraccount));
 			/* Destination information */
 			ast_copy_string(cdr->dst, S_OR(c->macroexten,c->exten), sizeof(cdr->dst));
 			ast_copy_string(cdr->dcontext, S_OR(c->macrocontext,c->context), sizeof(cdr->dcontext));
@@ -903,6 +909,25 @@
 	return 0;
 }
 
+int ast_cdr_setpeeraccount(struct ast_channel *chan, const char *account)
+{
+	struct ast_cdr *cdr = chan->cdr;
+	char buf[BUFSIZ/2] = "";
+	if (!ast_strlen_zero(chan->peeraccount))
+		ast_copy_string(buf, chan->peeraccount, sizeof(buf));
+
+	ast_string_field_set(chan, peeraccount, account);
+	for ( ; cdr ; cdr = cdr->next) {
+		if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
+			ast_copy_string(cdr->peeraccount, chan->peeraccount, sizeof(cdr->peeraccount));
+		}
+	}
+
+	/* Signal change of account code to manager */
+	manager_event(EVENT_FLAG_CALL, "NewPeerAccount", "Channel: %s\r\nUniqueid: %s\r\nPeerAccount: %s\r\nOldPeerAccount: %s\r\n", chan->name, chan->uniqueid, chan->peeraccount, buf);
+	return 0;
+}
+
 int ast_cdr_setamaflags(struct ast_channel *chan, const char *flag)
 {
 	struct ast_cdr *cdr;
@@ -954,6 +979,7 @@
 
 			/* Copy account code et-al */	
 			ast_copy_string(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode));
+			ast_copy_string(cdr->peeraccount, c->peeraccount, sizeof(cdr->peeraccount));
 			ast_copy_string(cdr->linkedid, c->linkedid, sizeof(cdr->linkedid));
 
 			/* Destination information */ /* XXX privilege macro* ? */

Modified: team/group/newcdr/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/channel.c?view=diff&rev=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/main/channel.c (original)
+++ team/group/newcdr/main/channel.c Fri May 16 19:36:54 2008
@@ -3779,6 +3779,32 @@
 	}
 }
 
+/* copy accountcode and peeraccount across during a link */
+static void ast_set_owners_and_peers(struct ast_channel *chan1,
+									 struct ast_channel *chan2)
+{
+	if (!ast_strlen_zero(chan1->accountcode) && ast_strlen_zero(chan2->peeraccount)) {
+		ast_log(LOG_DEBUG, "setting peeraccount to %s for %s from data on channel %s\n",
+				chan1->accountcode, chan2->name, chan1->name);
+		ast_string_field_set(chan2, peeraccount, chan1->accountcode);
+	}
+	if (!ast_strlen_zero(chan2->accountcode) && ast_strlen_zero(chan1->peeraccount)) {
+		ast_log(LOG_DEBUG, "setting peeraccount to %s for %s from data on channel %s\n",
+				chan2->accountcode, chan1->name, chan2->name);
+		ast_string_field_set(chan1, peeraccount, chan2->accountcode);
+	}
+	if (chan2 && !ast_strlen_zero(chan1->peeraccount) && ast_strlen_zero(chan2->accountcode)) {
+		ast_log(LOG_DEBUG, "setting accountcode to %s for %s from data on channel %s\n",
+				chan1->peeraccount, chan2->name, chan1->name);
+		ast_string_field_set(chan1, accountcode, chan1->peeraccount);
+	}
+	if (chan1 && !ast_strlen_zero(chan2->peeraccount) && ast_strlen_zero(chan1->accountcode)) {
+		ast_log(LOG_DEBUG, "setting accountcode to %s for %s from data on channel %s\n",
+				chan2->peeraccount, chan1->name, chan2->name);
+		ast_string_field_set(chan1, accountcode, chan2->peeraccount);
+	}
+}
+
 /*!
   \brief Masquerade a channel
 
@@ -3996,6 +4022,13 @@
 
 	/* Copy the music class */
 	ast_string_field_set(original, musicclass, clone->musicclass);
+
+	/* copy over accuntcode and set peeraccount across the bridge */
+	ast_string_field_set(original, accountcode, S_OR(clone->accountcode, ""));
+	if (original->_bridge) {
+		/* XXX - should we try to lock original->_bridge here? */
+		ast_string_field_set(original->_bridge, peeraccount, S_OR(clone->accountcode, ""));
+	}
 
 	ast_debug(1, "Putting channel %s in %d/%d formats\n", original->name, wformat, rformat);
 
@@ -4393,7 +4426,7 @@
 	c0->_bridge = c1;
 	c1->_bridge = c0;
 
-
+	ast_set_owners_and_peers(c0, c1);
 	ast_cel_report_event(c0, CEL_BRIDGE_START, NULL, NULL);
 
 	o0nativeformats = c0->nativeformats;

Modified: team/group/newcdr/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/cli.c?view=diff&rev=116881&r1=116880&r2=116881
==============================================================================
--- team/group/newcdr/main/cli.c (original)
+++ team/group/newcdr/main/cli.c Fri May 16 19:36:54 2008
@@ -632,9 +632,9 @@
 {
 #define FORMAT_STRING  "%-20.20s %-20.20s %-7.7s %-30.30s\n"
 #define FORMAT_STRING2 "%-20.20s %-20.20s %-7.7s %-30.30s\n"
-#define CONCISE_FORMAT_STRING  "%s!%s!%s!%d!%s!%s!%s!%s!%s!%d!%s!%s!%s\n"
-#define VERBOSE_FORMAT_STRING  "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
-#define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
+#define CONCISE_FORMAT_STRING  "%s!%s!%s!%d!%s!%s!%s!%s!%s!%s!%d!%s!%s!%s\n"
+#define VERBOSE_FORMAT_STRING  "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-11.11s %-20.20s\n"
+#define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-11.11s %-20.20s\n"
 
 	struct ast_channel *c = NULL;
 	int numchans = 0, concise = 0, verbose = 0, count = 0;
@@ -679,7 +679,7 @@
 			ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
 		else if (verbose)
 			ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data", 
-				"CallerID", "Duration", "Accountcode", "BridgedTo");
+				"CallerID", "Duration", "Accountcode", "PeerAccount", "BridgedTo");
 	}
 
 	while ((c = ast_channel_walk_locked(c)) != NULL) {
@@ -704,6 +704,7 @@
 					S_OR(c->data, ""),	/* XXX different from verbose ? */
 					S_OR(c->cid.cid_num, ""),
 					S_OR(c->accountcode, ""),
+					S_OR(c->peeraccount, ""),
 					c->amaflags, 
 					durbuf,
 					bc ? bc->name : "(None)",
@@ -715,6 +716,7 @@
 					S_OR(c->cid.cid_num, ""),
 					durbuf,
 					S_OR(c->accountcode, ""),
+					S_OR(c->peeraccount, ""),
 					bc ? bc->name : "(None)");
 			} else {
 				char locbuf[40] = "(None)";




More information about the svn-commits mailing list