[asterisk-commits] murf: trunk r59500 - in /trunk: ./ include/asterisk/ main/ res/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Mar 30 07:37:22 MST 2007


Author: murf
Date: Fri Mar 30 09:37:21 2007
New Revision: 59500

URL: http://svn.digium.com/view/asterisk?view=rev&rev=59500
Log:
Merged revisions 59486 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r59486 | murf | 2007-03-30 08:11:59 -0600 (Fri, 30 Mar 2007) | 1 line

These mods fix CDR issues from 8221, 8593, 8680, 8743, and perhaps others. Mainly with CDRs generated from transfer situations.
........

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/cdr.h
    trunk/main/cdr.c
    trunk/main/channel.c
    trunk/main/pbx.c
    trunk/res/res_features.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/cdr.h?view=diff&rev=59500&r1=59499&r2=59500
==============================================================================
--- trunk/include/asterisk/cdr.h (original)
+++ trunk/include/asterisk/cdr.h Fri Mar 30 09:37:21 2007
@@ -121,6 +121,12 @@
  */
 void ast_cdr_free(struct ast_cdr *cdr);
 
+/*! \brief Discard and free a CDR record 
+ * \param cdr ast_cdr structure to free
+ * Returns nothing important -- same as free, but no checks or complaints
+ */
+void ast_cdr_discard(struct ast_cdr *cdr);
+
 /*! \brief Initialize based on a channel
  * \param cdr Call Detail Record to use for channel
  * \param chan Channel to bind CDR with
@@ -269,6 +275,12 @@
  */
 char *ast_cdr_flags2str(int flags);
 
+/*! Move the non-null data from the "from" cdr to the "to" cdr
+ * \param to   the cdr to get the goodies
+ * \param from the cdr to give the goodies
+ */
+void ast_cdr_merge(struct ast_cdr *to, struct ast_cdr *from);
+
 int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
 int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
 

Modified: trunk/main/cdr.c
URL: http://svn.digium.com/view/asterisk/trunk/main/cdr.c?view=diff&rev=59500&r1=59499&r2=59500
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Fri Mar 30 09:37:21 2007
@@ -438,9 +438,113 @@
 	}
 }
 
+/*! \brief the same as a cdr_free call, only with no checks; just get rid of it */
+void ast_cdr_discard(struct ast_cdr *cdr)
+{
+	while (cdr) {
+		struct ast_cdr *next = cdr->next;
+
+		ast_cdr_free_vars(cdr, 0);
+		free(cdr);
+		cdr = next;
+	}
+}
+
 struct ast_cdr *ast_cdr_alloc(void)
 {
 	return ast_calloc(1, sizeof(struct ast_cdr));
+}
+
+void ast_cdr_merge(struct ast_cdr *to, struct ast_cdr *from)
+{
+	if (!to || !from)
+		return;
+	if (!ast_tvzero(from->start)) {
+		if (!ast_tvzero(to->start)) {
+			if (ast_tvcmp(to->start, from->start) > 0 ) {
+				to->start = from->start; /* use the earliest time */
+				from->start = ast_tv(0,0); /* we actively "steal" these values */
+			} else {
+				ast_log(LOG_WARNING,"CDR start disagreement for %s\n", to->channel);
+			}
+		} else {
+			to->start = from->start;
+			from->start = ast_tv(0,0); /* we actively "steal" these values */
+		}
+	}
+	if (!ast_tvzero(from->end)) {
+		if (!ast_tvzero(to->end)) {
+			if (ast_tvcmp(to->end, from->end) < 0 ) {
+				to->end = from->end; /* use the latest time */
+				from->end = ast_tv(0,0); /* we actively "steal" these values */
+			} else {
+				ast_log(LOG_WARNING,"CDR end disagreement for %s\n", to->channel);
+			}
+		} else {
+			to->end = from->end;
+			from->end = ast_tv(0,0); /* we actively "steal" these values */
+			to->duration = to->end.tv_sec - to->start.tv_sec;
+			to->billsec = ast_tvzero(to->answer) ? 0 : to->end.tv_sec - to->answer.tv_sec;
+		}
+	}
+	if (!ast_tvzero(from->answer)) {
+		if (!ast_tvzero(to->answer)) {
+			if (ast_tvcmp(to->answer, from->answer) > 0 ) {
+				to->answer = from->answer; /* use the earliest time */
+				from->answer = ast_tv(0,0); /* we actively "steal" these values */
+			} else {
+				ast_log(LOG_WARNING,"CDR answer disagreement for %s\n", to->channel);
+			}
+		} else {
+			to->answer = from->answer;
+			from->answer = ast_tv(0,0); /* we actively "steal" these values */
+		}
+	}
+	if (to->disposition < from->disposition) {
+		to->disposition = from->disposition;
+		from->disposition = AST_CDR_NOANSWER;
+	}
+	if (ast_strlen_zero(to->lastapp) && !ast_strlen_zero(from->lastapp)) {
+		ast_copy_string(to->lastapp, from->lastapp, sizeof(to->lastapp));
+		from->lastapp[0] = 0; /* theft */
+	}
+	if (ast_strlen_zero(to->lastdata) && !ast_strlen_zero(from->lastdata)) {
+		ast_copy_string(to->lastdata, from->lastdata, sizeof(to->lastdata));
+		from->lastdata[0] = 0; /* theft */
+	}
+	if (ast_strlen_zero(to->dcontext) && !ast_strlen_zero(from->dcontext)) {
+		ast_copy_string(to->dcontext, from->dcontext, sizeof(to->dcontext));
+		from->dcontext[0] = 0; /* theft */
+	}
+	if (ast_strlen_zero(to->dstchannel) && !ast_strlen_zero(from->dstchannel)) {
+		ast_copy_string(to->dstchannel, from->dstchannel, sizeof(to->dstchannel));
+		from->dstchannel[0] = 0; /* theft */
+	}
+	if (ast_strlen_zero(to->channel) && !ast_strlen_zero(from->channel)) {
+		ast_copy_string(to->channel, from->channel, sizeof(to->channel));
+		from->channel[0] = 0; /* theft */
+	}
+	if (ast_strlen_zero(to->src) && !ast_strlen_zero(from->src)) {
+		ast_copy_string(to->src, from->src, sizeof(to->src));
+		from->src[0] = 0; /* theft */
+	}
+	if (ast_strlen_zero(to->dst) && !ast_strlen_zero(from->dst)) {
+		ast_copy_string(to->dst, from->dst, sizeof(to->dst));
+		from->dst[0] = 0; /* theft */
+	}
+	if (!to->amaflags && from->amaflags) {
+		to->amaflags = from->amaflags;
+		from->amaflags = 0; /* theft */
+	}
+	if (ast_strlen_zero(to->accountcode) && !ast_strlen_zero(from->accountcode)) {
+		ast_copy_string(to->accountcode, from->accountcode, sizeof(to->accountcode));
+		from->accountcode[0] = 0; /* theft */
+	}
+	if (ast_strlen_zero(to->userfield) && !ast_strlen_zero(from->userfield)) {
+		ast_copy_string(to->userfield, from->userfield, sizeof(to->userfield));
+		from->userfield[0] = 0; /* theft */
+	}
+	/* flags, varsead, ? */
 }
 
 void ast_cdr_start(struct ast_cdr *cdr)
@@ -734,6 +838,8 @@
 		if (ast_tvzero(cdr->start))
 			ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan);
 		ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
+		if (ast_test_flag(cdr, AST_CDR_FLAG_POST_DISABLED))
+			continue;
 		AST_LIST_LOCK(&be_list);
 		AST_LIST_TRAVERSE(&be_list, i, list) {
 			i->be(cdr);

Modified: trunk/main/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/main/channel.c?view=diff&rev=59500&r1=59499&r2=59500
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Fri Mar 30 09:37:21 2007
@@ -731,6 +731,11 @@
 			      S_OR(cid_name, "<unknown>"),
 			      tmp->uniqueid);
 	}
+
+	/* Experiment: under what conditions do we NOT want to track cdrs on channels? */
+	tmp->cdr = ast_cdr_alloc();
+	ast_cdr_init(tmp->cdr, tmp);
+	ast_cdr_start(tmp->cdr);
 	
 	headp = &tmp->varshead;
 	AST_LIST_HEAD_INIT_NOLOCK(headp);
@@ -2160,6 +2165,14 @@
 				} else {
 					/* Answer the CDR */
 					ast_setstate(chan, AST_STATE_UP);
+					if (!chan->cdr) { /* up till now, this insertion hasn't been done. Therefore,
+										 to keep from throwing off the basic order of the universe,
+										 we will try to keep this cdr from getting posted. */
+						chan->cdr = ast_cdr_alloc();
+						ast_cdr_init(chan->cdr, chan);
+						ast_cdr_start(chan->cdr);
+					}
+					
 					ast_cdr_answer(chan->cdr);
 				}
 			}
@@ -2843,6 +2856,15 @@
 	}
 	ast_set_callerid(chan, cid_num, cid_name, cid_num);
 
+	
+
+	if (!chan->cdr) { /* up till now, this insertion hasn't been done. Therefore,
+				to keep from throwing off the basic order of the universe,
+				we will try to keep this cdr from getting posted. */
+		chan->cdr = ast_cdr_alloc();
+		ast_cdr_init(chan->cdr, chan);
+		ast_cdr_start(chan->cdr);
+	}
 	if (ast_call(chan, data, 0)) {	/* ast_call failed... */
 		ast_log(LOG_NOTICE, "Unable to call channel %s/%s\n", type, (char *)data);
 	} else {
@@ -3297,6 +3319,7 @@
 	struct ast_channel *clone = original->masq;
 	struct ast_channel_spy_list *spy_list = NULL;
 	struct ast_channel_spy *spy = NULL;
+	struct ast_cdr *cdr;
 	int rformat = original->readformat;
 	int wformat = original->writeformat;
 	char newn[100];
@@ -3353,6 +3376,11 @@
 	t = original->tech;
 	original->tech = clone->tech;
 	clone->tech = t;
+
+	/* Swap the cdrs */
+	cdr = original->cdr;
+	original->cdr = clone->cdr;
+	clone->cdr = cdr;
 
 	t_pvt = original->tech_pvt;
 	original->tech_pvt = clone->tech_pvt;

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=59500&r1=59499&r2=59500
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Fri Mar 30 09:37:21 2007
@@ -4574,6 +4574,9 @@
 		   the PBX, we have to make a new channel, masquerade, and start the PBX
 		   at the new location */
 		struct ast_channel *tmpchan = ast_channel_alloc(0, chan->_state, 0, 0, "AsyncGoto/%s", chan->name);
+		if (chan->cdr) {
+			tmpchan->cdr = ast_cdr_dup(chan->cdr);
+		}
 		if (!tmpchan)
 			res = -1;
 		else {
@@ -4936,7 +4939,10 @@
 	if (!chan)
 		return -1;  /* failure */
 
-	chan->cdr = ast_cdr_alloc();   /* allocate a cdr for the channel */
+	if (!chan->cdr) {
+		chan->cdr = ast_cdr_alloc();   /* allocate a cdr for the channel */
+		ast_log(LOG_NOTICE, "=====PBX_OUTGOING_CDR_FAILED ALLOCS CHANNEL CDR for %s\n", chan->name);
+	}
 
 	if (!chan->cdr) {
 		/* allocation of the cdr failed */

Modified: trunk/res/res_features.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_features.c?view=diff&rev=59500&r1=59499&r2=59500
==============================================================================
--- trunk/res/res_features.c (original)
+++ trunk/res/res_features.c Fri Mar 30 09:37:21 2007
@@ -172,6 +172,15 @@
 	struct ast_channel *peer;
 };
 
+
+
+struct ast_bridge
+{
+	struct ast_cdr *cdr; /* previously, cdrs were associated only with channels, and things
+							could get incredibly perverse when bridging occurred, especially
+						    when the same channel got used in multiple "legs" of a call */
+};
+
 /*! \brief store context, priority and extension */
 static void set_c_e_p(struct ast_channel *chan, const char *context, const char *ext, int pri)
 {
@@ -683,9 +692,16 @@
 		}
 		/*! \todo XXX Maybe we should have another message here instead of invalid extension XXX */
 	} else if (ast_exists_extension(transferee, transferer_real_context, xferto, 1, transferer->cid.cid_num)) {
-		pbx_builtin_setvar_helper(peer, "BLINDTRANSFER", chan->name);
+		pbx_builtin_setvar_helper(peer, "BLINDTRANSFER", transferee->name);
 		pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", peer->name);
 		res=finishup(transferee);
+		if (!transferer->cdr) {
+			transferer->cdr=ast_cdr_alloc();
+			ast_cdr_init(transferer->cdr, transferer); /* initilize our channel's cdr */
+			ast_cdr_start(transferer->cdr);
+		}
+		ast_cdr_setdestchan(transferer->cdr, transferee->name);
+		ast_cdr_setapp(transferer->cdr, "BLINDTRANSFER","");
 		if (!transferee->pbx) {
 			/* Doh!  Use our handy async_goto functions */
 			if (option_verbose > 2) 
@@ -1131,6 +1147,12 @@
 		ast_set_callerid(chan, cid_num, cid_name, cid_num);
 		ast_channel_inherit_variables(caller, chan);	
 		pbx_builtin_setvar_helper(chan, "TRANSFERERNAME", caller->name);
+		if (!chan->cdr) {
+			chan->cdr=ast_cdr_alloc();
+			ast_cdr_init(chan->cdr, chan); /* initilize our channel's cdr */
+			ast_cdr_start(chan->cdr);
+		}
+			
 		if (!ast_call(chan, data, timeout)) {
 			struct timeval started;
 			int x, len = 0;
@@ -1301,8 +1323,10 @@
 	int hadfeatures=0;
 	struct ast_option_header *aoh;
 	struct ast_bridge_config backup_config;
+	struct ast_bridge bridge_object;
 
 	memset(&backup_config, 0, sizeof(backup_config));
+	memset(&bridge_object, 0, sizeof(bridge_object));
 
 	config->start_time = ast_tvnow();
 
@@ -1349,6 +1373,70 @@
 		/* free the peer's cdr without ast_cdr_free complaining */
 		free(peer->cdr);
 		peer->cdr = NULL;
+	}
+
+	/* arrange the cdrs */
+	bridge_object.cdr = ast_cdr_alloc();
+	if (chan->cdr && peer->cdr) { /* both of them? merge */
+		ast_cdr_init(bridge_object.cdr,chan); /* seems more logicaller to use the  destination as a base, but, really, it's random */
+		ast_cdr_start(bridge_object.cdr); /* now is the time to start */
+		/* absorb the channel cdr */
+		ast_cdr_merge(bridge_object.cdr, chan->cdr);
+		ast_cdr_discard(chan->cdr); /* no posting these guys */
+		chan->cdr = NULL;
+		
+		/* absorb the peer cdr */
+		ast_cdr_merge(bridge_object.cdr, peer->cdr);
+		ast_cdr_discard(peer->cdr); /* no posting these guys */
+		peer->cdr = NULL;
+	} else if (chan->cdr) {
+		/* take the cdr from the channel - literally */
+		ast_cdr_init(bridge_object.cdr,chan);
+		if (chan->cdr->disposition!=AST_CDR_ANSWERED) {
+			ast_cdr_end(chan->cdr);
+			ast_cdr_detach(chan->cdr); /* post the existing cdr, we will be starting a fresh new cdr presently */
+			chan->cdr = ast_cdr_alloc();
+			ast_cdr_init(chan->cdr,chan); /* a fresh new one its place */
+			ast_cdr_start(chan->cdr); /* now is the time to start */
+		} else {
+			/* absorb this data */
+			ast_cdr_merge(bridge_object.cdr, chan->cdr);
+			ast_cdr_discard(chan->cdr); /* no posting these guys */
+			chan->cdr = NULL;
+		}
+		peer->cdr = ast_cdr_alloc();
+		ast_cdr_init(peer->cdr, peer);
+	} else if (peer->cdr) {
+		/* take the cdr from the peer - literally */
+		ast_cdr_init(bridge_object.cdr,peer);
+		if (peer->cdr->disposition != AST_CDR_ANSWERED) {
+			ast_cdr_end(peer->cdr);
+			ast_cdr_detach(peer->cdr); /* post the existing cdr, we will be starting a fresh new cdr presently */
+			peer->cdr = ast_cdr_alloc();
+			ast_cdr_init(peer->cdr,peer); /* a fresh new one its place */
+			ast_cdr_start(peer->cdr); /* now is the time to start */
+		} else {
+			/* absorb this data */
+			ast_cdr_merge(bridge_object.cdr, chan->cdr);
+			ast_cdr_discard(chan->cdr); /* no posting these guys */
+			chan->cdr = NULL;
+		}
+		chan->cdr = ast_cdr_alloc();
+		ast_cdr_init(chan->cdr, chan);
+	} else {
+		/* make up a new cdr */
+		ast_cdr_init(bridge_object.cdr,chan); /* eh, just pick one of them */
+		chan->cdr = ast_cdr_alloc();
+		ast_cdr_init(chan->cdr, chan);
+		peer->cdr = ast_cdr_alloc();
+		ast_cdr_init(peer->cdr, peer);
+		ast_cdr_start(peer->cdr); /* now is the time to start */
+	}
+	if (ast_strlen_zero(bridge_object.cdr->dstchannel)) {
+	       	if (strcmp(bridge_object.cdr->channel, peer->name) != 0)
+			ast_cdr_setdestchan(bridge_object.cdr, peer->name);
+		else
+			ast_cdr_setdestchan(bridge_object.cdr, chan->name);
 	}
 	for (;;) {
 		struct ast_channel *other;	/* used later */
@@ -1416,6 +1504,17 @@
 		}
 		if (res < 0) {
 			ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", chan->name, peer->name);
+			/* whoa!! don't go running off without cleaning up your mess! */
+			ast_cdr_merge(bridge_object.cdr,chan->cdr);
+			ast_cdr_merge(bridge_object.cdr,peer->cdr);
+			ast_cdr_failed(bridge_object.cdr);
+			ast_cdr_end(bridge_object.cdr);
+			ast_cdr_detach(bridge_object.cdr);
+			bridge_object.cdr = NULL;
+			ast_cdr_free(chan->cdr); /* no posting these guys */
+			ast_cdr_free(peer->cdr);
+			chan->cdr = NULL;
+			peer->cdr = NULL;
 			return -1;
 		}
 		
@@ -1505,6 +1604,17 @@
 		if (f)
 			ast_frfree(f);
 	}
+	/* before leaving, post the cdr we accumulated */
+	/* whoa!! don't go running off without cleaning up your mess! */
+	ast_cdr_merge(bridge_object.cdr,chan->cdr);
+	ast_cdr_merge(bridge_object.cdr,peer->cdr);
+	ast_cdr_end(bridge_object.cdr);
+	ast_cdr_detach(bridge_object.cdr);
+	bridge_object.cdr = NULL;
+	ast_cdr_discard(chan->cdr); /* no posting these guys */
+	ast_cdr_discard(peer->cdr);
+	chan->cdr = NULL;
+	peer->cdr = NULL;
 	return res;
 }
 
@@ -1737,6 +1847,7 @@
 	struct ast_channel *peer=NULL;
 	struct parkeduser *pu, *pl=NULL;
 	struct ast_context *con;
+
 	int park;
 	struct ast_bridge_config config;
 
@@ -1830,6 +1941,14 @@
 		if (option_verbose > 2) 
 			ast_verbose(VERBOSE_PREFIX_3 "Channel %s connected to parked call %d\n", chan->name, park);
 
+		pbx_builtin_setvar_helper(chan, "PARKEDCHANNEL", peer->name);
+		ast_cdr_setdestchan(chan->cdr, peer->name);
+#ifdef NOT_NECC
+		ast_log(LOG_NOTICE,"Channel name is %s, and the cdr channel name is '%s'\n", chan->name, chan->cdr->channel);
+		if (!ast_strlen_zero(chan->name) && ast_strlen_zero(chan->cdr->channel)) {
+			ast_copy_string(chan->cdr->channel, chan->name, sizeof(chan->cdr->channel));
+		}
+#endif
 		memset(&config, 0, sizeof(struct ast_bridge_config));
 		if ((parkedcalltransfers == AST_FEATURE_FLAG_BYCALLEE) || (parkedcalltransfers == AST_FEATURE_FLAG_BYBOTH))
 			ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);



More information about the asterisk-commits mailing list