diff options
author | murf <murf@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-03-30 14:11:59 +0000 |
---|---|---|
committer | murf <murf@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-03-30 14:11:59 +0000 |
commit | 3bbd029dc1830cd9c95e80d40b94b497e8eb03ce (patch) | |
tree | 371ceb6ca44bb4823cf9edd0950c46a27e43b866 /main | |
parent | 9b58ce234b81070f69a8b7b5eb46630fb5643f89 (diff) |
These mods fix CDR issues from 8221, 8593, 8680, 8743, and perhaps others. Mainly with CDRs generated from transfer situations.
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@59486 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/cdr.c | 106 | ||||
-rw-r--r-- | main/channel.c | 28 | ||||
-rw-r--r-- | main/pbx.c | 8 |
3 files changed, 141 insertions, 1 deletions
diff --git a/main/cdr.c b/main/cdr.c index 6aef9b51e..5b0c8b148 100644 --- a/main/cdr.c +++ b/main/cdr.c @@ -433,11 +433,115 @@ void ast_cdr_free(struct ast_cdr *cdr) } } +/*! \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) { char *chan; @@ -729,6 +833,8 @@ static void post_cdr(struct ast_cdr *cdr) 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); diff --git a/main/channel.c b/main/channel.c index eecf0e64c..d92fa0c7a 100644 --- a/main/channel.c +++ b/main/channel.c @@ -822,6 +822,11 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_ 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); @@ -2216,6 +2221,14 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio) } 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); } } @@ -2895,6 +2908,15 @@ struct ast_channel *__ast_request_and_dial(const char *type, int format, void *d } 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 { @@ -3354,6 +3376,7 @@ int ast_do_masquerade(struct ast_channel *original) 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]; @@ -3408,6 +3431,11 @@ int ast_do_masquerade(struct ast_channel *original) 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; clone->tech_pvt = t_pvt; diff --git a/main/pbx.c b/main/pbx.c index a6e5f2d7d..e8dbb491e 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -4559,6 +4559,9 @@ int ast_async_goto(struct ast_channel *chan, const char *context, const char *ex 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 { @@ -4921,7 +4924,10 @@ static int ast_pbx_outgoing_cdr_failed(void) 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 */ |