[asterisk-commits] mjordan: branch mjordan/cdrs-of-doom r384972 - in /team/mjordan/cdrs-of-doom:...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 8 11:54:28 CDT 2013
Author: mjordan
Date: Mon Apr 8 11:54:24 2013
New Revision: 384972
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384972
Log:
Re-enable automerge, update from weekend
Modified:
team/mjordan/cdrs-of-doom/ (props changed)
team/mjordan/cdrs-of-doom/include/asterisk/cdr.h
team/mjordan/cdrs-of-doom/main/cdr.c
team/mjordan/cdrs-of-doom/main/channel.c
team/mjordan/cdrs-of-doom/main/channel_internal_api.c
team/mjordan/cdrs-of-doom/main/cli.c
Propchange: team/mjordan/cdrs-of-doom/
------------------------------------------------------------------------------
automerge = *
Modified: team/mjordan/cdrs-of-doom/include/asterisk/cdr.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/include/asterisk/cdr.h?view=diff&rev=384972&r1=384971&r2=384972
==============================================================================
--- team/mjordan/cdrs-of-doom/include/asterisk/cdr.h (original)
+++ team/mjordan/cdrs-of-doom/include/asterisk/cdr.h Mon Apr 8 11:54:24 2013
@@ -188,19 +188,17 @@
/*!
* \since 12
- * \brief Retrieve a CDR variable from a channel's CDR
+ * \brief Retrieve a CDR variable from a channel's current CDR
*
* \param channel_name The name of the party A channel that the CDR is associated with
* \param name The name of the variable to retrieve
* \param value A buffer to format the output into
* \param length The size of the buffer
- * \param recur If non-zero recursively search through the buffer for the value starting at the first CDR.
- * Otherwise, the most recent CDR is used.
*
* \retval 0 on success
* \retval non-zero on failure
*/
-int ast_cdr_getvar(const char *channel_name, const char *name, char **value, size_t length, int recur);
+int ast_cdr_getvar(const char *channel_name, const char *name, char **value, size_t length);
/*!
* \brief Set a variable on a CDR
@@ -259,7 +257,7 @@
*/
int ast_cdr_reset(const char *channel_name, struct ast_flags *options);
-int ast_cdr_serialize_variables(struct ast_cdr *cdr, struct ast_str **buf, char delim, char sep, int recur);
+int ast_cdr_serialize_variables(const char *channel_name, struct ast_str **buf, char delim, char sep);
int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
Modified: team/mjordan/cdrs-of-doom/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/main/cdr.c?view=diff&rev=384972&r1=384971&r2=384972
==============================================================================
--- team/mjordan/cdrs-of-doom/main/cdr.c (original)
+++ team/mjordan/cdrs-of-doom/main/cdr.c Mon Apr 8 11:54:24 2013
@@ -283,8 +283,6 @@
static int cdr_sequence = 0;
-static int cdr_seq_inc(struct ast_cdr *cdr);
-
static struct ast_sched_context *sched;
static int cdr_sched = -1;
static pthread_t cdr_thread = AST_PTHREADT_NULL;
@@ -326,13 +324,12 @@
.process_dial_message = single_state_process_dial_message,
};
-static void dial_state_init_function(struct cdr_object *cdr);
static void dial_state_process_party_b_update(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot);
static int dial_state_process_dial_message(struct cdr_object *cdr, struct ast_channel_dial *dial_message);
struct cdr_object_fn_table dial_state_fn_table = {
.name = "Dial",
- .init_function = dial_state_init_function,
+ .init_function = NULL,
.process_party_a_update = base_process_party_a_update,
.process_party_b_update = dial_state_process_party_b_update,
.process_dial_message = dial_state_process_dial_message,
@@ -349,11 +346,9 @@
.process_dial_message = NULL,
};
-static void hangup_state_init_function(struct cdr_object *cdr);
-
struct cdr_object_fn_table hangup_state_fn_table = {
.name = "Hangup",
- .init_function = hangup_state_init_function,
+ .init_function = NULL,
.process_party_a_update = NULL,
.process_party_b_update = NULL,
.process_dial_message = NULL,
@@ -497,6 +492,34 @@
for (; cdr->next; cdr = cdr->next) { }
cdr->next = new_cdr;
return new_cdr;
+}
+
+static long cdr_object_get_duration(struct cdr_object *cdr)
+{
+ if (ast_tvzero(cdr->end)) {
+ return (long)(ast_tvdiff_ms(ast_tvnow(), cdr->start) / 1000);
+ } else {
+ return (long)(ast_tvdiff_ms(cdr->end, cdr->start) / 1000);
+ }
+}
+
+static long cdr_object_get_billsec(struct cdr_object *cdr)
+{
+ RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);
+ long int ms;
+
+ if (ast_tvzero(cdr->answer)) {
+ return 0;
+ }
+ ms = ast_tvdiff_ms(cdr->end, cdr->answer);
+ if (ast_test_flag(&mod_cfg->general->settings, CDR_INITIATED_SECONDS)
+ && (ms % 1000 >= 500)) {
+ ms = (ms / 1000) + 1;
+ } else {
+ ms = ms / 1000;
+ }
+
+ return ms;
}
static struct ast_cdr *cdr_object_create_public_records(struct cdr_object *cdr)
@@ -546,10 +569,8 @@
cdr_copy->end = cdr->end;
/* Durations */
- cdr_copy->billsec = ast_tvzero(cdr->answer) ?
- (long)(ast_tvdiff_ms(cdr->end, cdr->start) / 1000) :
- (long)(ast_tvdiff_ms(cdr->end, cdr->answer) / 1000);
- cdr_copy->duration = (long)(ast_tvdiff_ms(cdr->end, cdr->start) / 1000);
+ cdr_copy->billsec = cdr_object_get_billsec(cdr);
+ cdr_copy->duration = cdr_object_get_duration(cdr);
ast_copy_string(cdr_copy->linkedid, cdr->linkedid, sizeof(cdr_copy->linkedid));
cdr_copy->disposition = cdr->disposition;
@@ -1169,7 +1190,7 @@
}
}
- return NULL;
+ return '\0';
}
static void cdr_get_tv(struct timeval when, const char *fmt, char *buf, int bufsize)
@@ -1339,16 +1360,10 @@
}
while ((cdr = ao2_iterator_next(it_cdrs))) {
- {
- SCOPED_AO2LOCK(lock, cdr);
- for (; cdr; cdr = cdr->next) {
- if (!cdr->next && !recur) {
- cdr_object_setvar(cdr, channel_name, name, value);
- } else if (recur) {
- cdr_object_setvar(cdr, channel_name, name, value);
- }
- }
- }
+ ao2_lock(cdr);
+ for (; cdr->next; cdr = cdr->next) { }
+ cdr_object_setvar(cdr, channel_name, name, value);
+ ao2_unlock(cdr);
ao2_ref(cdr, -1);
}
ao2_iterator_destroy(it_cdrs);
@@ -1356,111 +1371,135 @@
return 0;
}
-int ast_cdr_getvar(const char *channel_name, const char *name, char **value, size_t length, int recur)
+static void cdr_object_format_var_internal(struct cdr_object *cdr, const char *name, char **value, size_t length)
+{
+ struct ast_var_t *variable;
+
+ AST_LIST_TRAVERSE(&cdr->party_a.variables, variable, entries) {
+ if (!strcasecmp(name, ast_var_name(variable))) {
+ ast_copy_string(*value, ast_var_value(variable), length);
+ return;
+ }
+ }
+
+ *value = '\0';
+}
+
+int ast_cdr_getvar(const char *channel_name, const char *name, char **value, size_t length)
{
RAII_VAR(struct cdr_object *, cdr,
ao2_find(active_cdrs_by_channel, channel_name, OBJ_KEY),
ao2_cleanup);
+ struct ast_channel_snapshot *party_a;
+ struct ast_channel_snapshot *party_b;
+ struct cdr_object *it_cdr;
if (!cdr) {
ast_debug(3, "Unable to find CDR for channel %s\n", channel_name);
return 1;
}
- {
- SCOPED_AO2LOCK(lock, cdr);
- if (!strcasecmp(name, "clid")) {
- ast_callerid_merge(*value, length, cdr->party_a->caller_name, cdr->party_a->caller_number, "");
- } else if (!strcasecmp(name, "src")) {
- ast_copy_string(*value, cdr->party_a->caller_number, length);
- } else if (!strcasecmp(name, "dst"))
- ast_copy_string(*value, cdr->party_a->exten, length);
- } else if (!strcasecmp(name, "dcontext"))
- ast_copy_string(*value, cdr->party_a->context, length);
- } else if (!strcasecmp(name, "channel"))
- ast_copy_string(*value, cdr->party_a->name, length);
- } else if (!strcasecmp(name, "dstchannel"))
- if (cdr->party_b) {
- ast_copy_string(*value, cdr->party_b->name, length);
- } else {
- ast_copy_string(*value, "", length);
- }
- } else if (!strcasecmp(name, "lastapp")) {
- ast_copy_string(*value, cdr->party_a->appl, length);
- } else if (!strcasecmp(name, "lastdata")) {
- ast_copy_string(*value, cdr->party_a->data, length);
- } else if (!strcasecmp(name, "start")) {
- cdr_get_tv(cdr->start, raw ? NULL : fmt, workspace, length);
- } else if (!strcasecmp(name, "answer")) {
- cdr_get_tv(cdr->answer, raw ? NULL : fmt, workspace, length);
- } else if (!strcasecmp(name, "end")) {
- cdr_get_tv(cdr->end, raw ? NULL : fmt, workspace, length);
- } else if (!strcasecmp(name, "duration")) {
- snprintf(workspace, workspacelen, "%ld", cdr->end.tv_sec != 0 ? cdr->duration : (long)ast_tvdiff_ms(ast_tvnow(), cdr->start) / 1000);
- } else if (!strcasecmp(name, "billsec")) {
- snprintf(workspace, workspacelen, "%ld", (cdr->billsec || !ast_tvzero(cdr->end) || ast_tvzero(cdr->answer)) ? cdr->billsec : (long)ast_tvdiff_ms(ast_tvnow(), cdr->answer) / 1000);
- } else if (!strcasecmp(name, "disposition")) {
- if (raw) {
- snprintf(workspace, workspacelen, "%ld", cdr->disposition);
- } else {
- ast_copy_string(workspace, ast_cdr_disp2str(cdr->disposition), length);
- }
- } else if (!strcasecmp(name, "amaflags")) {
- if (raw) {
- snprintf(workspace, workspacelen, "%ld", cdr->amaflags);
- } else {
- ast_copy_string(workspace, ast_channel_amaflags2string(cdr->amaflags), length);
- }
- } else if (!strcasecmp(name, "accountcode")) {
- ast_copy_string(*value, cdr->party_a->accountcode, length);
- } else if (!strcasecmp(name, "peeraccount")) {
- if (cdr->party_b) {
- ast_copy_string(*value, cdr->party_b->peeraccount, length);
- } else {
- ast_copy_string(*value, "", length);
- }
- } else if (!strcasecmp(name, "uniqueid")) {
- ast_copy_string(*value, cdr->party_a->uniqueid, length);
- } else if (!strcasecmp(name, "linkedid")) {
- ast_copy_string(*value, cdr->linkedid, length);
- } else if (!strcasecmp(name, "userfield")) {
- ast_copy_string(*value, cdr->userfield, length);
- } else if (!strcasecmp(name, "sequence")) {
- snprintf(workspace, workspacelen, "%d", cdr->sequence);
- }
- else if ((varbuf = cdr_format_var_internal(cdr, name, recur)))
- ast_copy_string(workspace, varbuf, length);
- else
- workspace[0] = '\0';
-
- if (!ast_strlen_zero(workspace))
- *ret = workspace;
-
- }
-}
-
-
-
-int ast_cdr_serialize_variables(struct ast_cdr *cdr, struct ast_str **buf, char delim, char sep, int recur)
-{
- struct ast_var_t *variables;
+ if (ast_strlen_zero(name)) {
+ return 1;
+ }
+
+ ao2_lock(cdr);
+
+ /* FF to last CDR */
+ for (it_cdr = cdr; it_cdr->next; it_cdr = it_cdr->next) { }
+ party_a = it_cdr->party_a.snapshot;
+ party_b = it_cdr->party_b.snapshot;
+
+ if (!strcasecmp(name, "clid")) {
+ ast_callerid_merge(*value, length, party_a->caller_name, party_a->caller_number, "");
+ } else if (!strcasecmp(name, "src")) {
+ ast_copy_string(*value, party_a->caller_number, length);
+ } else if (!strcasecmp(name, "dst")) {
+ ast_copy_string(*value, party_a->exten, length);
+ } else if (!strcasecmp(name, "dcontext")) {
+ ast_copy_string(*value, party_a->context, length);
+ } else if (!strcasecmp(name, "channel")) {
+ ast_copy_string(*value, party_a->name, length);
+ } else if (!strcasecmp(name, "dstchannel")) {
+ if (party_b) {
+ ast_copy_string(*value, party_b->name, length);
+ } else {
+ ast_copy_string(*value, "", length);
+ }
+ } else if (!strcasecmp(name, "lastapp")) {
+ ast_copy_string(*value, party_a->appl, length);
+ } else if (!strcasecmp(name, "lastdata")) {
+ ast_copy_string(*value, party_a->data, length);
+ } else if (!strcasecmp(name, "start")) {
+ cdr_get_tv(it_cdr->start, NULL, *value, length);
+ } else if (!strcasecmp(name, "answer")) {
+ cdr_get_tv(it_cdr->answer, NULL, *value, length);
+ } else if (!strcasecmp(name, "end")) {
+ cdr_get_tv(it_cdr->end, NULL, *value, length);
+ } else if (!strcasecmp(name, "duration")) {
+ snprintf(*value, length, "%ld", cdr_object_get_duration(it_cdr));
+ } else if (!strcasecmp(name, "billsec")) {
+ snprintf(*value, length, "%ld", cdr_object_get_billsec(it_cdr));
+ } else if (!strcasecmp(name, "disposition")) {
+ snprintf(*value, length, "%d", it_cdr->disposition);
+ } else if (!strcasecmp(name, "amaflags")) {
+ snprintf(*value, length, "%d", party_a->amaflags);
+ } else if (!strcasecmp(name, "accountcode")) {
+ ast_copy_string(*value, party_a->accountcode, length);
+ } else if (!strcasecmp(name, "peeraccount")) {
+ if (party_b) {
+ ast_copy_string(*value, party_b->accountcode, length);
+ } else {
+ ast_copy_string(*value, "", length);
+ }
+ } else if (!strcasecmp(name, "uniqueid")) {
+ ast_copy_string(*value, party_a->uniqueid, length);
+ } else if (!strcasecmp(name, "linkedid")) {
+ ast_copy_string(*value, it_cdr->linkedid, length);
+ } else if (!strcasecmp(name, "userfield")) {
+ ast_copy_string(*value, party_a->userfield, length);
+ } else if (!strcasecmp(name, "sequence")) {
+ snprintf(*value, length, "%d", it_cdr->sequence);
+ } else {
+ cdr_object_format_var_internal(it_cdr, name, value, length);
+ }
+ ao2_unlock(cdr);
+
+ return 0;
+}
+
+
+
+int ast_cdr_serialize_variables(const char *channel_name, struct ast_str **buf, char delim, char sep)
+{
+ RAII_VAR(struct cdr_object *, cdr,
+ ao2_find(active_cdrs_by_channel, channel_name, OBJ_KEY),
+ ao2_cleanup);
+ struct cdr_object *it_cdr;
+ struct ast_var_t *variable;
const char *var;
char *tmp;
char workspace[256];
int total = 0, x = 0, i;
+ if (!cdr) {
+ ast_debug(3, "Unable to find CDR for channel %s\n", channel_name);
+ return 1;
+ }
+
ast_str_reset(*buf);
- for (; cdr; cdr = recur ? cdr->next : NULL) {
+ ao2_lock(cdr);
+ for (; cdr; cdr = cdr->next) {
if (++x > 1)
ast_str_append(buf, 0, "\n");
- AST_LIST_TRAVERSE(&cdr->varshead, variables, entries) {
- if (!(var = ast_var_name(variables))) {
+ AST_LIST_TRAVERSE(&cdr->party_a.variables, variable, entries) {
+ if (!(var = ast_var_name(variable))) {
continue;
}
- if (ast_str_append(buf, 0, "level %d: %s%c%s%c", x, var, delim, S_OR(ast_var_value(variables), ""), sep) < 0) {
+ if (ast_str_append(buf, 0, "level %d: %s%c%s%c", x, var, delim, S_OR(ast_var_value(variable), ""), sep) < 0) {
ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
break;
}
@@ -1488,7 +1527,8 @@
static void cdr_free_vars(struct varshead *headp)
{
- struct varshead *headp = &cdr->varshead;
+ struct ast_var_t *vardata;
+
while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries))) {
ast_var_delete(vardata);
}
@@ -1499,7 +1539,7 @@
while (cdr) {
struct ast_cdr *next = cdr->next;
- cdr_free_vars(cdr);
+ cdr_free_vars(&cdr->varshead);
ast_free(cdr);
cdr = next;
}
@@ -1514,20 +1554,18 @@
}
-
-
-
/* set cid info for one record */
-static void set_one_cid(struct ast_cdr *cdr, struct ast_channel *c)
-{
+/*static void set_one_cid(struct ast_cdr *cdr, struct ast_channel *c)
+{
+
const char *num;
if (!cdr) {
return;
}
-
+ */
/* Grab source from ANI or normal Caller*ID */
- num = S_COR(ast_channel_caller(c)->ani.number.valid, ast_channel_caller(c)->ani.number.str,
+ /* num = S_COR(ast_channel_caller(c)->ani.number.valid, ast_channel_caller(c)->ani.number.str,
S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, NULL));
ast_callerid_merge(cdr->clid, sizeof(cdr->clid),
S_COR(ast_channel_caller(c)->id.name.valid, ast_channel_caller(c)->id.name.str, NULL), num, "");
@@ -1540,7 +1578,7 @@
if (ast_channel_dialed(c)->subaddress.valid) {
ast_cdr_setvar(cdr, "calledsubaddr", S_OR(ast_channel_dialed(c)->subaddress.str, ""), 0);
}
-}
+}*/
const char *ast_cdr_disp2str(int disposition)
{
@@ -1574,7 +1612,7 @@
for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
if (it_cdr->party_b.snapshot
&& !strcmp(it_cdr->party_b.snapshot->name, info->channel_name)) {
- strcpy(it_cdr->party_b->userfield, info->userfield);
+ strcpy(it_cdr->party_b.userfield, info->userfield);
}
}
return 0;
@@ -1632,26 +1670,27 @@
int ast_cdr_disable(const char *channel_name)
{
RAII_VAR(struct cdr_object *, cdr,
- ao2_find(active_channels_by_cdr, channel_name, OBJ_KEY),
+ ao2_find(active_cdrs_by_channel, channel_name, OBJ_KEY),
ao2_cleanup);
+ struct cdr_object *it_cdr;
if (!cdr) {
return -1;
}
- {
- SCOPED_AO2LOCK(lock, cdr);
- for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
- ast_set_flag(&it_cdr->flags, AST_CDR_FLAG_DISABLE);
- }
- }
+ ao2_lock(cdr);
+ for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
+ ast_set_flag(&it_cdr->flags, AST_CDR_FLAG_DISABLE);
+ }
+ ao2_unlock(cdr);
+
return 0;
}
int ast_cdr_reset(const char *channel_name, struct ast_flags *options)
{
RAII_VAR(struct cdr_object *, cdr,
- ao2_find(active_channels_by_cdr, channel_name, OBJ_KEY),
+ ao2_find(active_cdrs_by_channel, channel_name, OBJ_KEY),
ao2_cleanup);
struct ast_var_t *vardata;
struct cdr_object *it_cdr;
@@ -1670,13 +1709,13 @@
if (ast_test_flag(options, AST_CDR_FLAG_DISABLE_DISPATCH)) {
if (!it_cdr->next) {
- ast_set_flag(&it_cdr->flags, AST_CDR_FLAG_DISABLE_DISPATCH));
+ ast_set_flag(&it_cdr->flags, AST_CDR_FLAG_DISABLE_DISPATCH);
}
continue;
}
/* clear variables */
- if (!ast_test_flag(&flags, AST_CDR_FLAG_KEEP_VARS)) {
+ if (!ast_test_flag(options, AST_CDR_FLAG_KEEP_VARS)) {
while ((vardata = AST_LIST_REMOVE_HEAD(&it_cdr->party_a.variables, entries))) {
ast_var_delete(vardata);
}
Modified: team/mjordan/cdrs-of-doom/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/main/channel.c?view=diff&rev=384972&r1=384971&r2=384972
==============================================================================
--- team/mjordan/cdrs-of-doom/main/channel.c (original)
+++ team/mjordan/cdrs-of-doom/main/channel.c Mon Apr 8 11:54:24 2013
@@ -6962,7 +6962,6 @@
} exchange;
struct ast_channel *clonechan, *chans[2];
struct ast_channel *bridged;
- struct ast_cdr *cdr;
struct ast_datastore *xfer_ds;
struct xfer_masquerade_ds *xfer_colp;
struct ast_format rformat;
Modified: team/mjordan/cdrs-of-doom/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/main/channel_internal_api.c?view=diff&rev=384972&r1=384971&r2=384972
==============================================================================
--- team/mjordan/cdrs-of-doom/main/channel_internal_api.c (original)
+++ team/mjordan/cdrs-of-doom/main/channel_internal_api.c Mon Apr 8 11:54:24 2013
@@ -556,12 +556,12 @@
chan->sending_dtmf_tv = value;
}
-int ast_channel_amaflags(const struct ast_channel *chan)
+enum ama_flags ast_channel_amaflags(const struct ast_channel *chan)
{
return chan->amaflags;
}
-void ast_channel_amaflags_set(struct ast_channel *chan, int value)
+void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value)
{
if (chan->amaflags == value) {
return;
Modified: team/mjordan/cdrs-of-doom/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/main/cli.c?view=diff&rev=384972&r1=384971&r2=384972
==============================================================================
--- team/mjordan/cdrs-of-doom/main/cli.c (original)
+++ team/mjordan/cdrs-of-doom/main/cli.c Mon Apr 8 11:54:24 2013
@@ -1533,7 +1533,7 @@
ast_str_append(&output, 0, " Variables:\n%s\n", ast_str_buffer(obuf));
}
- if (ast_cdr_serialize_variables(ast_channel_name(c), &obuf, '=', '\n', 1)) {
+ if (ast_cdr_serialize_variables(ast_channel_name(c), &obuf, '=', '\n')) {
ast_str_append(&output, 0, " CDR Variables:\n%s\n", ast_str_buffer(obuf));
}
More information about the asterisk-commits
mailing list