aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/asterisk/cdr.h12
-rw-r--r--main/cdr.c106
-rw-r--r--main/channel.c28
-rw-r--r--main/pbx.c8
-rw-r--r--res/res_features.c121
5 files changed, 273 insertions, 2 deletions
diff --git a/include/asterisk/cdr.h b/include/asterisk/cdr.h
index 9c081718d..e9f5f8f1e 100644
--- a/include/asterisk/cdr.h
+++ b/include/asterisk/cdr.h
@@ -121,6 +121,12 @@ struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
*/
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 @@ void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags);
*/
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);
diff --git a/main/cdr.c b/main/cdr.c
index 9c56f0fdd..6502e8c18 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -438,11 +438,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;
@@ -734,6 +838,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 eb5940060..7238b5fd3 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -731,6 +731,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);
@@ -2160,6 +2165,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);
}
}
@@ -2843,6 +2856,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 {
@@ -3297,6 +3319,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];
@@ -3354,6 +3377,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 7d716b2ed..d8aef64df 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -4574,6 +4574,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 {
@@ -4936,7 +4939,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 */
diff --git a/res/res_features.c b/res/res_features.c
index 4db65a7dd..6396ba193 100644
--- a/res/res_features.c
+++ b/res/res_features.c
@@ -172,6 +172,15 @@ struct ast_bridge_thread_obj
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 @@ static int builtin_blindtransfer(struct ast_channel *chan, struct ast_channel *p
}
/*! \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 @@ static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *call
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 ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
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();
@@ -1350,6 +1374,70 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
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 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
}
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 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
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 @@ static int park_exec(struct ast_channel *chan, void *data)
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 @@ static int park_exec(struct ast_channel *chan, void *data)
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);