[asterisk-commits] murf: branch murf/bug8221-1.4 r47983 - in
/team/murf/bug8221-1.4: include/ast...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Nov 23 19:42:17 MST 2006
Author: murf
Date: Thu Nov 23 20:42:17 2006
New Revision: 47983
URL: http://svn.digium.com/view/asterisk?view=rev&rev=47983
Log:
Tested this code, works for 8221. But will it work for ALL cases perfectly...
Modified:
team/murf/bug8221-1.4/include/asterisk/cdr.h
team/murf/bug8221-1.4/main/cdr.c
team/murf/bug8221-1.4/main/channel.c
team/murf/bug8221-1.4/res/res_features.c
Modified: team/murf/bug8221-1.4/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/team/murf/bug8221-1.4/include/asterisk/cdr.h?view=diff&rev=47983&r1=47982&r2=47983
==============================================================================
--- team/murf/bug8221-1.4/include/asterisk/cdr.h (original)
+++ team/murf/bug8221-1.4/include/asterisk/cdr.h Thu Nov 23 20:42:17 2006
@@ -118,6 +118,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
@@ -266,6 +272,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: team/murf/bug8221-1.4/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug8221-1.4/main/cdr.c?view=diff&rev=47983&r1=47982&r2=47983
==============================================================================
--- team/murf/bug8221-1.4/main/cdr.c (original)
+++ team/murf/bug8221-1.4/main/cdr.c Thu Nov 23 20:42:17 2006
@@ -433,9 +433,104 @@
}
}
+/*! \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 */
+ ast_log(LOG_WARNING,"Merging START time from %s\n", from->channel);
+ }
+ }
+ if (!ast_tvzero(from->end)) {
+ if (!ast_tvzero(to->end)) {
+ if (ast_tvcmp(to->end, from->end) > 0 ) {
+ to->end = from->end; /* use the earliest 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 */
+ ast_log(LOG_WARNING,"Merging END time from %s\n", from->channel);
+ 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 */
+ ast_log(LOG_WARNING,"Merging ANSWER time from %s\n", from->channel);
+ }
+ }
+ if (to->disposition < from->disposition) {
+ to->disposition = from->disposition;
+ from->disposition = AST_CDR_NOANSWER;
+ }
+ if (!to->lastapp[0] && from->lastapp[0]) {
+ strcpy(to->lastapp, from->lastapp);
+ from->lastapp[0] = 0; /* theft */
+ }
+ if (!to->lastdata[0] && from->lastdata[0]) {
+ strcpy(to->lastdata, from->lastdata);
+ from->lastdata[0] = 0; /* theft */
+ }
+ if (!to->dcontext[0] && from->dcontext[0]) {
+ strcpy(to->dcontext, from->dcontext);
+ from->dcontext[0] = 0; /* theft */
+ }
+ if (!to->dstchannel[0] && from->dstchannel[0]) {
+ strcpy(to->dstchannel, from->dstchannel);
+ from->dstchannel[0] = 0; /* theft */
+ }
+ if (!to->amaflags && from->amaflags) {
+ to->amaflags = from->amaflags;
+ from->amaflags = 0; /* theft */
+ }
+ if (!to->accountcode[0] && from->accountcode[0]) {
+ strcpy(to->accountcode, from->accountcode);
+ from->accountcode[0] = 0; /* theft */
+ }
+ if (!to->userfield[0] && from->userfield[0]) {
+ strcpy(to->userfield, from->userfield);
+ from->userfield[0] = 0; /* theft */
+ }
+ /* amaflags, flags, varsead, dst, src? */
}
void ast_cdr_start(struct ast_cdr *cdr)
@@ -729,6 +824,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: team/murf/bug8221-1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug8221-1.4/main/channel.c?view=diff&rev=47983&r1=47982&r2=47983
==============================================================================
--- team/murf/bug8221-1.4/main/channel.c (original)
+++ team/murf/bug8221-1.4/main/channel.c Thu Nov 23 20:42:17 2006
@@ -1646,9 +1646,11 @@
if (chan->tech->answer)
res = chan->tech->answer(chan);
ast_setstate(chan, AST_STATE_UP);
+ ast_log(LOG_NOTICE,"posting Answer time to (ast_answer.ring) channel %s:%x\n", chan->name, (int)chan->cdr);
ast_cdr_answer(chan->cdr);
break;
case AST_STATE_UP:
+ ast_log(LOG_NOTICE,"posting Answer time to (ast_answer.up) channel %s:%x\n", chan->name, (int)chan->cdr);
ast_cdr_answer(chan->cdr);
break;
default:
@@ -2120,6 +2122,15 @@
} else {
/* Answer the CDR */
ast_setstate(chan, AST_STATE_UP);
+ ast_log(LOG_NOTICE,"posting Answer time to (__ast_read.answer) channel %s:%x\n", chan->name, (int)chan->cdr);
+ 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);
}
}
Modified: team/murf/bug8221-1.4/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug8221-1.4/res/res_features.c?view=diff&rev=47983&r1=47982&r2=47983
==============================================================================
--- team/murf/bug8221-1.4/res/res_features.c (original)
+++ team/murf/bug8221-1.4/res/res_features.c Thu Nov 23 20:42:17 2006
@@ -167,6 +167,15 @@
struct ast_bridge_config bconfig;
struct ast_channel *chan;
struct ast_channel *peer;
+};
+
+/*! this is the beginning of the bridge object. Here store all
+ * the data that is associated with the bridge itself. */
+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 */
@@ -1298,8 +1307,11 @@
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));
+ ast_log(LOG_NOTICE,"BEGIN bridge between %s and %s!\n", chan->name, peer->name);
config->start_time = ast_tvnow();
@@ -1308,7 +1320,8 @@
pbx_builtin_setvar_helper(peer, "BRIDGEPEER", chan->name);
} else if (chan)
pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", NULL);
-
+
+
if (monitor_ok) {
const char *monitor_exec;
struct ast_channel *src = NULL;
@@ -1347,6 +1360,97 @@
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_log(LOG_NOTICE,"Bridging call with BOTH sides holding a CDR!\n");
+ ast_log(LOG_NOTICE,"chan.cdr.name=%s, .dstchan=%s, .lastapp=%s, .start=%d, .answer=%d, .end=%d, dispos=%d\n",
+ chan->cdr->channel,
+ chan->cdr->dstchannel,
+ chan->cdr->lastapp,
+ (int)chan->cdr->start.tv_sec,
+ (int)chan->cdr->answer.tv_sec,
+ (int)chan->cdr->end.tv_sec,
+ (int)chan->cdr->disposition);
+ ast_log(LOG_NOTICE,"peer.cdr.name=%s, .dstchan=%s, .lastapp=%s, .start=%d, .answer=%d, .end=%d, .dispos=%d\n", peer->cdr->channel,
+ peer->cdr->dstchannel,
+ peer->cdr->lastapp,
+ (int)peer->cdr->start.tv_sec,
+ (int)peer->cdr->answer.tv_sec,
+ (int)peer->cdr->end.tv_sec,
+ (int)peer->cdr->disposition);
+ 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_log(LOG_NOTICE,"Discarding answered chan cdr.name=%s, .dstchan=%s, .lastapp=%s, .start=%d, .answer=%d, .end=%d, .dispos=%d\n", chan->cdr->channel,
+ chan->cdr->dstchannel,
+ chan->cdr->lastapp,
+ (int)chan->cdr->start.tv_sec,
+ (int)chan->cdr->answer.tv_sec,
+ (int)chan->cdr->end.tv_sec,
+ (int)chan->cdr->disposition);
+ 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_log(LOG_NOTICE,"Discarding answered peer cdr.name=%s, .dstchan=%s, .lastapp=%s, .start=%d, .answer=%d, .end=%d, .dispos=%d\n", peer->cdr->channel,
+ peer->cdr->dstchannel,
+ peer->cdr->lastapp,
+ (int)peer->cdr->start.tv_sec,
+ (int)peer->cdr->answer.tv_sec,
+ (int)peer->cdr->end.tv_sec,
+ (int)peer->cdr->disposition);
+ 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_log(LOG_WARNING,"Bridging call with NEITHER side holding a CDR!\n");
+
+ 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 */
+ }
+
for (;;) {
struct ast_channel *other; /* used later */
@@ -1413,6 +1517,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;
}
@@ -1502,6 +1617,25 @@
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_log(LOG_NOTICE,"Posting Bridged chan cdr.name=%s, .dstchan=%s, .lastapp=%s, .start=%d, .answer=%d, .end=%d, .dispos=%d\n", bridge_object.cdr->channel,
+ bridge_object.cdr->dstchannel,
+ bridge_object.cdr->lastapp,
+ (int)bridge_object.cdr->start.tv_sec,
+ (int)bridge_object.cdr->answer.tv_sec,
+ (int)bridge_object.cdr->end.tv_sec,
+ (int)bridge_object.cdr->disposition);
+ 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;
+ ast_log(LOG_NOTICE,"END bridge between %s and %s!\n", chan->name, peer->name);
return res;
}
@@ -1724,6 +1858,7 @@
struct ast_channel *peer=NULL;
struct parkeduser *pu, *pl=NULL;
struct ast_context *con;
+
int park;
struct ast_bridge_config config;
More information about the asterisk-commits
mailing list