several changes via kpflemings review

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@59522 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Steve Murphy
2007-03-30 17:51:17 +00:00
parent 9c69e34f62
commit 798039b4d8
5 changed files with 131 additions and 105 deletions

View File

@@ -114,13 +114,13 @@ struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
/*! \brief Free a CDR record /*! \brief Free a CDR record
* \param cdr ast_cdr structure to free * \param cdr ast_cdr structure to free
* Returns nothing important * Returns nothing
*/ */
void ast_cdr_free(struct ast_cdr *cdr); void ast_cdr_free(struct ast_cdr *cdr);
/*! \brief Discard and free a CDR record /*! \brief Discard and free a CDR record
* \param cdr ast_cdr structure to free * \param cdr ast_cdr structure to free
* Returns nothing important -- same as free, but no checks or complaints * Returns nothing -- same as free, but no checks or complaints
*/ */
void ast_cdr_discard(struct ast_cdr *cdr); void ast_cdr_discard(struct ast_cdr *cdr);
@@ -162,7 +162,7 @@ void ast_cdr_unregister(const char *name);
/*! /*!
* \param cdr the cdr you wish to associate with the call * \param cdr the cdr you wish to associate with the call
* Starts all CDR stuff necessary for monitoring a call * Starts all CDR stuff necessary for monitoring a call
* Returns nothing important * Returns nothing
*/ */
void ast_cdr_start(struct ast_cdr *cdr); void ast_cdr_start(struct ast_cdr *cdr);
@@ -177,21 +177,21 @@ void ast_cdr_answer(struct ast_cdr *cdr);
/*! Busy a call */ /*! Busy a call */
/*! /*!
* \param cdr the cdr you wish to associate with the call * \param cdr the cdr you wish to associate with the call
* Returns nothing important * Returns nothing
*/ */
void ast_cdr_busy(struct ast_cdr *cdr); void ast_cdr_busy(struct ast_cdr *cdr);
/*! Fail a call */ /*! Fail a call */
/*! /*!
* \param cdr the cdr you wish to associate with the call * \param cdr the cdr you wish to associate with the call
* Returns nothing important * Returns nothing
*/ */
void ast_cdr_failed(struct ast_cdr *cdr); void ast_cdr_failed(struct ast_cdr *cdr);
/*! Save the result of the call based on the AST_CAUSE_* */ /*! Save the result of the call based on the AST_CAUSE_* */
/*! /*!
* \param cdr the cdr you wish to associate with the call * \param cdr the cdr you wish to associate with the call
* Returns nothing important * Returns nothing
* \param cause the AST_CAUSE_* * \param cause the AST_CAUSE_*
*/ */
int ast_cdr_disposition(struct ast_cdr *cdr, int cause); int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
@@ -200,7 +200,7 @@ int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
/*! /*!
* \param cdr the cdr you have associated the call with * \param cdr the cdr you have associated the call with
* Registers the end of call time in the cdr structure. * Registers the end of call time in the cdr structure.
* Returns nothing important * Returns nothing
*/ */
void ast_cdr_end(struct ast_cdr *cdr); void ast_cdr_end(struct ast_cdr *cdr);

View File

@@ -166,8 +166,11 @@ void ast_cdr_unregister(const char *name)
*/ */
struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr) struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr)
{ {
struct ast_cdr *newcdr = ast_cdr_alloc(); struct ast_cdr *newcdr;
if (!cdr) /* don't die if we get a null cdr pointer */
return NULL;
newcdr = ast_cdr_alloc();
if (!newcdr) if (!newcdr)
return NULL; return NULL;
@@ -217,6 +220,9 @@ void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *wor
const char *fmt = "%Y-%m-%d %T"; const char *fmt = "%Y-%m-%d %T";
const char *varbuf; const char *varbuf;
if (!cdr) /* don't die if the cdr is null */
return;
*ret = NULL; *ret = NULL;
/* special vars (the ones from the struct ast_cdr when requested by name) /* special vars (the ones from the struct ast_cdr when requested by name)
I'd almost say we should convert all the stringed vals to vars */ I'd almost say we should convert all the stringed vals to vars */
@@ -288,6 +294,9 @@ int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int
struct varshead *headp; struct varshead *headp;
int x; int x;
if (!cdr) /* don't die if the cdr is null */
return -1;
for(x = 0; cdr_readonly_vars[x]; x++) { for(x = 0; cdr_readonly_vars[x]; x++) {
if (!strcasecmp(name, cdr_readonly_vars[x])) { if (!strcasecmp(name, cdr_readonly_vars[x])) {
ast_log(LOG_ERROR, "Attempt to set the '%s' read-only variable!.\n", name); ast_log(LOG_ERROR, "Attempt to set the '%s' read-only variable!.\n", name);
@@ -328,6 +337,9 @@ int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr)
const char *var, *val; const char *var, *val;
int x = 0; int x = 0;
if (!to_cdr || !from_cdr) /* don't die if one of the pointers is null */
return 0;
headpa = &from_cdr->varshead; headpa = &from_cdr->varshead;
headpb = &to_cdr->varshead; headpb = &to_cdr->varshead;
@@ -403,6 +415,8 @@ void ast_cdr_free_vars(struct ast_cdr *cdr, int recur)
/*! \brief print a warning if cdr already posted */ /*! \brief print a warning if cdr already posted */
static void check_post(struct ast_cdr *cdr) static void check_post(struct ast_cdr *cdr)
{ {
if (!cdr)
return;
if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED)) if (ast_test_flag(cdr, AST_CDR_FLAG_POSTED))
ast_log(LOG_NOTICE, "CDR on channel '%s' already posted\n", S_OR(cdr->channel, "<unknown>")); ast_log(LOG_NOTICE, "CDR on channel '%s' already posted\n", S_OR(cdr->channel, "<unknown>"));
} }
@@ -410,6 +424,8 @@ static void check_post(struct ast_cdr *cdr)
/*! \brief print a warning if cdr already started */ /*! \brief print a warning if cdr already started */
static void check_start(struct ast_cdr *cdr) static void check_start(struct ast_cdr *cdr)
{ {
if (!cdr)
return;
if (!ast_tvzero(cdr->start)) if (!ast_tvzero(cdr->start))
ast_log(LOG_NOTICE, "CDR on channel '%s' already started\n", S_OR(cdr->channel, "<unknown>")); ast_log(LOG_NOTICE, "CDR on channel '%s' already started\n", S_OR(cdr->channel, "<unknown>"));
} }
@@ -447,7 +463,10 @@ void ast_cdr_discard(struct ast_cdr *cdr)
struct ast_cdr *ast_cdr_alloc(void) struct ast_cdr *ast_cdr_alloc(void)
{ {
return ast_calloc(1, sizeof(struct ast_cdr)); struct ast_cdr *x = ast_calloc(1, sizeof(struct ast_cdr));
if (!x)
ast_log(LOG_ERROR,"Allocation Failure for a CDR!\n");
return x;
} }
void ast_cdr_merge(struct ast_cdr *to, struct ast_cdr *from) void ast_cdr_merge(struct ast_cdr *to, struct ast_cdr *from)
@@ -646,7 +665,8 @@ static void set_one_cid(struct ast_cdr *cdr, struct ast_channel *c)
{ {
/* Grab source from ANI or normal Caller*ID */ /* Grab source from ANI or normal Caller*ID */
const char *num = S_OR(c->cid.cid_ani, c->cid.cid_num); const char *num = S_OR(c->cid.cid_ani, c->cid.cid_num);
if (!cdr)
return;
if (!ast_strlen_zero(c->cid.cid_name)) { if (!ast_strlen_zero(c->cid.cid_name)) {
if (!ast_strlen_zero(num)) /* both name and number */ if (!ast_strlen_zero(num)) /* both name and number */
snprintf(cdr->clid, sizeof(cdr->clid), "\"%s\" <%s>", c->cid.cid_name, num); snprintf(cdr->clid, sizeof(cdr->clid), "\"%s\" <%s>", c->cid.cid_name, num);
@@ -997,6 +1017,9 @@ void ast_cdr_detach(struct ast_cdr *cdr)
struct ast_cdr_batch_item *newtail; struct ast_cdr_batch_item *newtail;
int curr; int curr;
if (!cdr)
return;
/* maybe they disabled CDR stuff completely, so just drop it */ /* maybe they disabled CDR stuff completely, so just drop it */
if (!enabled) { if (!enabled) {
if (option_debug) if (option_debug)

View File

@@ -823,7 +823,7 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
tmp->uniqueid); tmp->uniqueid);
} }
/* Experiment: under what conditions do we NOT want to track cdrs on channels? */ /* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */
tmp->cdr = ast_cdr_alloc(); tmp->cdr = ast_cdr_alloc();
ast_cdr_init(tmp->cdr, tmp); ast_cdr_init(tmp->cdr, tmp);
ast_cdr_start(tmp->cdr); ast_cdr_start(tmp->cdr);

View File

@@ -4924,11 +4924,6 @@ static int ast_pbx_outgoing_cdr_failed(void)
if (!chan) if (!chan)
return -1; /* failure */ return -1; /* failure */
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) { if (!chan->cdr) {
/* allocation of the cdr failed */ /* allocation of the cdr failed */
ast_channel_free(chan); /* free the channel */ ast_channel_free(chan); /* free the channel */

View File

@@ -171,13 +171,6 @@ struct ast_bridge_thread_obj
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 */ /*! \brief store context, priority and extension */
static void set_c_e_p(struct ast_channel *chan, const char *context, const char *ext, int pri) static void set_c_e_p(struct ast_channel *chan, const char *context, const char *ext, int pri)
{ {
@@ -694,11 +687,15 @@ static int builtin_blindtransfer(struct ast_channel *chan, struct ast_channel *p
res=finishup(transferee); res=finishup(transferee);
if (!transferer->cdr) { if (!transferer->cdr) {
transferer->cdr=ast_cdr_alloc(); transferer->cdr=ast_cdr_alloc();
ast_cdr_init(transferer->cdr, transferer); /* initilize our channel's cdr */ if (transferer) {
ast_cdr_start(transferer->cdr); ast_cdr_init(transferer->cdr, transferer); /* initilize our channel's cdr */
ast_cdr_start(transferer->cdr);
}
}
if (transferer->cdr) {
ast_cdr_setdestchan(transferer->cdr, transferee->name);
ast_cdr_setapp(transferer->cdr, "BLINDTRANSFER","");
} }
ast_cdr_setdestchan(transferer->cdr, transferee->name);
ast_cdr_setapp(transferer->cdr, "BLINDTRANSFER","");
if (!transferee->pbx) { if (!transferee->pbx) {
/* Doh! Use our handy async_goto functions */ /* Doh! Use our handy async_goto functions */
if (option_verbose > 2) if (option_verbose > 2)
@@ -1146,8 +1143,10 @@ static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *call
pbx_builtin_setvar_helper(chan, "TRANSFERERNAME", caller->name); pbx_builtin_setvar_helper(chan, "TRANSFERERNAME", caller->name);
if (!chan->cdr) { if (!chan->cdr) {
chan->cdr=ast_cdr_alloc(); chan->cdr=ast_cdr_alloc();
ast_cdr_init(chan->cdr, chan); /* initilize our channel's cdr */ if (chan->cdr) {
ast_cdr_start(chan->cdr); ast_cdr_init(chan->cdr, chan); /* initilize our channel's cdr */
ast_cdr_start(chan->cdr);
}
} }
if (!ast_call(chan, data, timeout)) { if (!ast_call(chan, data, timeout)) {
@@ -1320,10 +1319,9 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
int hadfeatures=0; int hadfeatures=0;
struct ast_option_header *aoh; struct ast_option_header *aoh;
struct ast_bridge_config backup_config; struct ast_bridge_config backup_config;
struct ast_bridge bridge_object; struct ast_cdr *bridge_cdr;
memset(&backup_config, 0, sizeof(backup_config)); memset(&backup_config, 0, sizeof(backup_config));
memset(&bridge_object, 0, sizeof(bridge_object));
config->start_time = ast_tvnow(); config->start_time = ast_tvnow();
@@ -1373,67 +1371,79 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
} }
/* arrange the cdrs */ /* arrange the cdrs */
bridge_object.cdr = ast_cdr_alloc(); bridge_cdr = ast_cdr_alloc();
if (chan->cdr && peer->cdr) { /* both of them? merge */ if (bridge_cdr) {
ast_cdr_init(bridge_object.cdr,chan); /* seems more logicaller to use the destination as a base, but, really, it's random */ if (chan->cdr && peer->cdr) { /* both of them? merge */
ast_cdr_start(bridge_object.cdr); /* now is the time to start */ ast_cdr_init(bridge_cdr,chan); /* seems more logicaller to use the destination as a base, but, really, it's random */
/* absorb the channel cdr */ ast_cdr_start(bridge_cdr); /* now is the time to start */
ast_cdr_merge(bridge_object.cdr, chan->cdr); /* absorb the channel cdr */
ast_cdr_discard(chan->cdr); /* no posting these guys */ ast_cdr_merge(bridge_cdr, chan->cdr);
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 */ ast_cdr_discard(chan->cdr); /* no posting these guys */
chan->cdr = NULL; chan->cdr = NULL;
}
peer->cdr = ast_cdr_alloc(); /* absorb the peer cdr */
ast_cdr_init(peer->cdr, peer); ast_cdr_merge(bridge_cdr, peer->cdr);
} else if (peer->cdr) { ast_cdr_discard(peer->cdr); /* no posting these guys */
/* take the cdr from the peer - literally */ peer->cdr = NULL;
ast_cdr_init(bridge_object.cdr,peer); } else if (chan->cdr) {
if (peer->cdr->disposition != AST_CDR_ANSWERED) { /* take the cdr from the channel - literally */
ast_cdr_end(peer->cdr); ast_cdr_init(bridge_cdr,chan);
ast_cdr_detach(peer->cdr); /* post the existing cdr, we will be starting a fresh new cdr presently */ 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();
if (chan->cdr) {
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_cdr, chan->cdr);
ast_cdr_discard(chan->cdr); /* no posting these guys */
chan->cdr = NULL;
}
peer->cdr = ast_cdr_alloc(); peer->cdr = ast_cdr_alloc();
ast_cdr_init(peer->cdr,peer); /* a fresh new one its place */ if (peer->cdr)
ast_cdr_start(peer->cdr); /* now is the time to start */ ast_cdr_init(peer->cdr, peer);
} else if (peer->cdr) {
/* take the cdr from the peer - literally */
ast_cdr_init(bridge_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();
if (peer->cdr) {
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_cdr, chan->cdr);
ast_cdr_discard(chan->cdr); /* no posting these guys */
chan->cdr = NULL;
}
chan->cdr = ast_cdr_alloc();
if (chan->cdr)
ast_cdr_init(chan->cdr, chan);
} else { } else {
/* absorb this data */ /* make up a new cdr */
ast_cdr_merge(bridge_object.cdr, chan->cdr); ast_cdr_init(bridge_cdr,chan); /* eh, just pick one of them */
ast_cdr_discard(chan->cdr); /* no posting these guys */ chan->cdr = ast_cdr_alloc();
chan->cdr = NULL; if (chan->cdr) {
ast_cdr_init(chan->cdr, chan);
}
peer->cdr = ast_cdr_alloc();
if (chan->cdr) {
ast_cdr_init(peer->cdr, peer);
ast_cdr_start(peer->cdr); /* now is the time to start */
}
}
if (ast_strlen_zero(bridge_cdr->dstchannel)) {
if (strcmp(bridge_cdr->channel, peer->name) != 0)
ast_cdr_setdestchan(bridge_cdr, peer->name);
else
ast_cdr_setdestchan(bridge_cdr, chan->name);
} }
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 (;;) { for (;;) {
struct ast_channel *other; /* used later */ struct ast_channel *other; /* used later */
@@ -1502,12 +1512,14 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
if (res < 0) { if (res < 0) {
ast_log(LOG_WARNING, "Bridge failed on channels %s and %s\n", chan->name, peer->name); 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! */ /* whoa!! don't go running off without cleaning up your mess! */
ast_cdr_merge(bridge_object.cdr,chan->cdr); if (bridge_cdr) {
ast_cdr_merge(bridge_object.cdr,peer->cdr); ast_cdr_merge(bridge_cdr,chan->cdr);
ast_cdr_failed(bridge_object.cdr); ast_cdr_merge(bridge_cdr,peer->cdr);
ast_cdr_end(bridge_object.cdr); ast_cdr_failed(bridge_cdr);
ast_cdr_detach(bridge_object.cdr); ast_cdr_end(bridge_cdr);
bridge_object.cdr = NULL; ast_cdr_detach(bridge_cdr);
bridge_cdr = NULL;
}
ast_cdr_free(chan->cdr); /* no posting these guys */ ast_cdr_free(chan->cdr); /* no posting these guys */
ast_cdr_free(peer->cdr); ast_cdr_free(peer->cdr);
chan->cdr = NULL; chan->cdr = NULL;
@@ -1603,11 +1615,13 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
} }
/* before leaving, post the cdr we accumulated */ /* before leaving, post the cdr we accumulated */
/* whoa!! don't go running off without cleaning up your mess! */ /* whoa!! don't go running off without cleaning up your mess! */
ast_cdr_merge(bridge_object.cdr,chan->cdr); if (bridge_cdr) {
ast_cdr_merge(bridge_object.cdr,peer->cdr); ast_cdr_merge(bridge_cdr,chan->cdr);
ast_cdr_end(bridge_object.cdr); ast_cdr_merge(bridge_cdr,peer->cdr);
ast_cdr_detach(bridge_object.cdr); ast_cdr_end(bridge_cdr);
bridge_object.cdr = NULL; ast_cdr_detach(bridge_cdr);
bridge_cdr = NULL;
}
ast_cdr_discard(chan->cdr); /* no posting these guys */ ast_cdr_discard(chan->cdr); /* no posting these guys */
ast_cdr_discard(peer->cdr); ast_cdr_discard(peer->cdr);
chan->cdr = NULL; chan->cdr = NULL;
@@ -1930,12 +1944,6 @@ static int park_exec(struct ast_channel *chan, void *data)
pbx_builtin_setvar_helper(chan, "PARKEDCHANNEL", peer->name); pbx_builtin_setvar_helper(chan, "PARKEDCHANNEL", peer->name);
ast_cdr_setdestchan(chan->cdr, 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)); memset(&config, 0, sizeof(struct ast_bridge_config));
ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT); ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT); ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);