[asterisk-commits] mjordan: branch mjordan/cdrs-of-doom r386233 - in /team/mjordan/cdrs-of-doom:...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 22 09:59:10 CDT 2013
Author: mjordan
Date: Mon Apr 22 09:59:05 2013
New Revision: 386233
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386233
Log:
Update with more tweaks from merges
Modified:
team/mjordan/cdrs-of-doom/addons/cdr_mysql.c
team/mjordan/cdrs-of-doom/apps/app_forkcdr.c
team/mjordan/cdrs-of-doom/cdr/cdr_adaptive_odbc.c
team/mjordan/cdrs-of-doom/cdr/cdr_pgsql.c
team/mjordan/cdrs-of-doom/funcs/func_cdr.c
team/mjordan/cdrs-of-doom/include/asterisk/cdr.h
team/mjordan/cdrs-of-doom/include/asterisk/channel.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/features.c
team/mjordan/cdrs-of-doom/main/manager.c
team/mjordan/cdrs-of-doom/main/manager_channels.c
team/mjordan/cdrs-of-doom/main/pbx.c
team/mjordan/cdrs-of-doom/res/res_config_sqlite.c
team/mjordan/cdrs-of-doom/tests/test_cdr.c
Modified: team/mjordan/cdrs-of-doom/addons/cdr_mysql.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/addons/cdr_mysql.c?view=diff&rev=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/addons/cdr_mysql.c (original)
+++ team/mjordan/cdrs-of-doom/addons/cdr_mysql.c Mon Apr 22 09:59:05 2013
@@ -251,7 +251,7 @@
char timestr[128];
ast_localtime(&tv, &tm, ast_str_strlen(cdrzone) ? ast_str_buffer(cdrzone) : NULL);
ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %T", &tm);
- ast_cdr_setvar(cdr, "calldate", timestr, 0);
+ ast_cdr_setvar(cdr, "calldate", timestr);
cdrname = "calldate";
} else {
cdrname = "start";
@@ -277,9 +277,9 @@
strstr(entry->type, "real") ||
strstr(entry->type, "numeric") ||
strstr(entry->type, "fixed"))) {
- ast_cdr_format_var(cdr, cdrname, &value, workspace, sizeof(workspace), 0, 1);
+ ast_cdr_format_var(cdr, cdrname, &value, workspace, sizeof(workspace), 1);
} else {
- ast_cdr_format_var(cdr, cdrname, &value, workspace, sizeof(workspace), 0, 0);
+ ast_cdr_format_var(cdr, cdrname, &value, workspace, sizeof(workspace), 0);
}
if (value) {
Modified: team/mjordan/cdrs-of-doom/apps/app_forkcdr.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/apps/app_forkcdr.c?view=diff&rev=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/apps/app_forkcdr.c (original)
+++ team/mjordan/cdrs-of-doom/apps/app_forkcdr.c Mon Apr 22 09:59:05 2013
@@ -55,19 +55,18 @@
not used, the answer time on the forked CDR will be the
answer time on the original CDR. If the channel is not
answered, this option has no effect.</para>
- <para>Note that this option only applies with the
- <literal>r</literal> option. The forked CDR is reset
- by default which will implicitly set the answer time to
- the current time if the channel is answered.</para>
+ <para>Note that this option is implicitly assumed by the
+ <literal>r</literal> option.</para>
</option>
<option name="e">
<para>End the original CDR.</para>
</option>
<option name="r">
- <para>Do <emphasis>NOT</emphasis> reset the forked CDR.
- By default, the forked CDR is reset. Resetting the CDR
- causes the start and answer times (if the channel is
- answered) to be set to the current time.</para>
+ <para>Reset the start and answer times on the forked CDR.
+ This will set the start and answer times (if the channel
+ is answered) to be set to the current time.</para>
+ <para>Note that this option implicitly assumes the
+ <literal>a</literal> option.</para>
</option>
<option name="v">
<para>Do not copy CDR variables and attributes from the
@@ -84,18 +83,7 @@
<description>
<para>Causes the Call Data Record engine to fork a new CDR starting
from the time the application is executed. The forked CDR will be
- linked to end of the CDRs associated with the channel.</para>
- <para>The forking operation proceeds as follows:</para>
- <para>1. A copy is made of the last CDR associated with the channel.
- All attributes and variables are copied over.</para>
- <para>2. The forked CDR is reset. This sets the start time to the
- current time. If the channel is answered, the answered time is set
- to the current time as well. This behavior can be altered using the
- <literal>r</literal> and <literal>a</literal> options.</para>
- <para>3. If the <literal>e</literal> option is set, the original
- CDR is finalized. Its end time is set to the current time. The
- disposition of the original CDR will reflect the state of the
- channel.</para>
+ linked to the end of the CDRs associated with the channel.</para>
</description>
<see-also>
<ref type="function">CDR</ref>
@@ -110,8 +98,7 @@
AST_APP_OPTIONS(forkcdr_exec_options, {
AST_APP_OPTION('a', AST_CDR_FLAG_SET_ANSWER),
AST_APP_OPTION('e', AST_CDR_FLAG_FINALIZE),
- AST_APP_OPTION('r', AST_CDR_FLAG_NORESET),
- AST_APP_OPTION('R', AST_CDR_FLAG_NORESET), /* Kept for backwards compatiblity */
+ AST_APP_OPTION('r', AST_CDR_FLAG_RESET),
AST_APP_OPTION('v', AST_CDR_FLAG_KEEP_VARS),
});
Modified: team/mjordan/cdrs-of-doom/cdr/cdr_adaptive_odbc.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/cdr/cdr_adaptive_odbc.c?view=diff&rev=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/cdr/cdr_adaptive_odbc.c (original)
+++ team/mjordan/cdrs-of-doom/cdr/cdr_adaptive_odbc.c Mon Apr 22 09:59:05 2013
@@ -433,7 +433,7 @@
ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S", &tm);
colptr = colbuf;
} else {
- ast_cdr_format_var(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), 0, datefield ? 0 : 1);
+ ast_cdr_format_var(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), datefield ? 0 : 1);
}
if (colptr) {
@@ -472,9 +472,9 @@
* form (but only when we're dealing with a character-based field).
*/
if (strcasecmp(entry->name, "disposition") == 0) {
- ast_cdr_format_var(cdr, entry->name, &colptr, colbuf, sizeof(colbuf), 0, 0);
+ ast_cdr_format_var(cdr, entry->name, &colptr, colbuf, sizeof(colbuf), 0);
} else if (strcasecmp(entry->name, "amaflags") == 0) {
- ast_cdr_format_var(cdr, entry->name, &colptr, colbuf, sizeof(colbuf), 0, 0);
+ ast_cdr_format_var(cdr, entry->name, &colptr, colbuf, sizeof(colbuf), 0);
}
/* Truncate too-long fields */
Modified: team/mjordan/cdrs-of-doom/cdr/cdr_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/cdr/cdr_pgsql.c?view=diff&rev=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/cdr/cdr_pgsql.c (original)
+++ team/mjordan/cdrs-of-doom/cdr/cdr_pgsql.c Mon Apr 22 09:59:05 2013
@@ -222,9 +222,9 @@
AST_RWLIST_RDLOCK(&psql_columns);
AST_RWLIST_TRAVERSE(&psql_columns, cur, list) {
/* For fields not set, simply skip them */
- ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
+ ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0);
if (strcmp(cur->name, "calldate") == 0 && !value) {
- ast_cdr_format_var(cdr, "start", &value, buf, sizeof(buf), 0, 0);
+ ast_cdr_format_var(cdr, "start", &value, buf, sizeof(buf), 0);
}
if (!value) {
if (cur->notnull && !cur->hasdefault) {
@@ -286,7 +286,7 @@
} else if (strcmp(cur->name, "duration") == 0 || strcmp(cur->name, "billsec") == 0) {
if (cur->type[0] == 'i') {
/* Get integer, no need to escape anything */
- ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
+ ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0);
LENGTHEN_BUF2(13);
ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", value);
} else if (strncmp(cur->type, "float", 5) == 0) {
@@ -302,18 +302,18 @@
} else if (strcmp(cur->name, "disposition") == 0 || strcmp(cur->name, "amaflags") == 0) {
if (strncmp(cur->type, "int", 3) == 0) {
/* Integer, no need to escape anything */
- ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0, 1);
+ ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 1);
LENGTHEN_BUF2(13);
ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", value);
} else {
/* Although this is a char field, there are no special characters in the values for these fields */
- ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
+ ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0);
LENGTHEN_BUF2(31);
ast_str_append(&sql2, 0, "%s'%s'", first ? "" : ",", value);
}
} else {
/* Arbitrary field, could be anything */
- ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
+ ast_cdr_format_var(cdr, cur->name, &value, buf, sizeof(buf), 0);
if (strncmp(cur->type, "int", 3) == 0) {
long long whatever;
if (value && sscanf(value, "%30lld", &whatever) == 1) {
Modified: team/mjordan/cdrs-of-doom/funcs/func_cdr.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/funcs/func_cdr.c?view=diff&rev=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/funcs/func_cdr.c (original)
+++ team/mjordan/cdrs-of-doom/funcs/func_cdr.c Mon Apr 22 09:59:05 2013
@@ -176,16 +176,13 @@
***/
enum cdr_option_flags {
- OPT_RECURSIVE = (1 << 0),
OPT_UNPARSED = (1 << 1),
OPT_LAST = (1 << 2),
- OPT_SKIPLOCKED = (1 << 3), /* DEPRECATE */
OPT_FLOAT = (1 << 4),
};
AST_APP_OPTIONS(cdr_func_options, {
AST_APP_OPTION('f', OPT_FLOAT),
- AST_APP_OPTION('r', OPT_RECURSIVE),
AST_APP_OPTION('u', OPT_UNPARSED),
});
@@ -272,7 +269,7 @@
ast_channel_unlock(chan);
}
} else {
- ast_cdr_setvar(ast_channel_name(chan), args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE));
+ ast_cdr_setvar(ast_channel_name(chan), args.variable, value);
}
return 0;
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=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/include/asterisk/cdr.h (original)
+++ team/mjordan/cdrs-of-doom/include/asterisk/cdr.h Mon Apr 22 09:59:05 2013
@@ -54,13 +54,13 @@
* state of a CDR object based on these flags.
*/
enum ast_cdr_options {
- AST_CDR_FLAG_KEEP_VARS = (1 << 0), /*< Copy variables during the operation */
+ AST_CDR_FLAG_KEEP_VARS = (1 << 0), /*< Copy variables during the operation */
AST_CDR_FLAG_DISABLE_DISPATCH = (1 << 1), /* Prevent a CDR from being dispatched */
- AST_CDR_FLAG_DISABLE = (1 << 2), /* Disable the CDR */
- AST_CDR_FLAG_PARTY_A = (1 << 3), /* Used to set a channel as party A */
- AST_CDR_FLAG_FINALIZE = (1 << 4), /* Finalize the recent CDRs */
- AST_CDR_FLAG_SET_ANSWER = (1 << 5), /* If the channel is answered, set the answer time to now */
- AST_CDR_FLAG_NORESET = (1 << 6), /* If set, don't reset the CDR */
+ AST_CDR_FLAG_DISABLE = (1 << 2), /* Disable the CDR */
+ AST_CDR_FLAG_PARTY_A = (1 << 3), /* Used to set a channel as party A */
+ AST_CDR_FLAG_FINALIZE = (1 << 4), /* Finalize the recent CDRs */
+ AST_CDR_FLAG_SET_ANSWER = (1 << 5), /* If the channel is answered, set the answer time to now */
+ AST_CDR_FLAG_RESET = (1 << 6), /* If set, set the start and answer time to now */
};
/*!
@@ -181,10 +181,9 @@
* \param ret Pointer to the formatted buffer
* \param workspace A pointer to the buffer to use to format the variable
* \param workspacelen The size of \ref workspace
- * \param recur If non-zero, search all CDRs in the chain for the specified variable
* \param raw If non-zero and a date/time is extraced, provide epoch seconds. Otherwise format as a date/time stamp
*/
-void ast_cdr_format_var(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw);
+void ast_cdr_format_var(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int raw);
/*!
* \since 12
@@ -192,13 +191,13 @@
*
* \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 value Buffer to hold the value
* \param length The size of the buffer
*
* \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 ast_cdr_getvar(const char *channel_name, const char *name, char *value, size_t length);
/*!
* \brief Set a variable on a CDR
@@ -206,13 +205,11 @@
* \param channel_name The channel to set the variable on
* \param name The name of the variable to set
* \param value The value of the variable to set
- * \param recur If non-zero, set the variable on every CDR in a chain. Otherwise,
- * only the most recent CDR's value will be set.
*
* \retval 0 on success
* \retval non-zero on failure
*/
-int ast_cdr_setvar(const char *channel_name, const char *name, const char *value, int recur);
+int ast_cdr_setvar(const char *channel_name, const char *name, const char *value);
/*!
* \since 12
@@ -220,11 +217,6 @@
*
* \param channel_name The name of the channel whose CDR should be forked
* \param options Options to control how the fork occurs.
- *
- * Forking a CDR will do the following:
- * - If the channel is non-existant or hung up, the call will fail.
- * -
- *
*
* \retval 0 on success
* \retval -1 on failure
Modified: team/mjordan/cdrs-of-doom/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/cdrs-of-doom/include/asterisk/channel.h?view=diff&rev=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/include/asterisk/channel.h (original)
+++ team/mjordan/cdrs-of-doom/include/asterisk/channel.h Mon Apr 22 09:59:05 2013
@@ -4219,12 +4219,4 @@
const char *dialstring,
const char *dialstatus);
-/*!
- * \since 12
- * \brief Publish a \ref ast_channel_snapshot for a particular channel
- *
- * \param chan The channel that should be published
- */
-void ast_publish_channel_state(struct ast_channel *chan);
-
#endif /* _ASTERISK_CHANNEL_H */
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=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/main/cdr.c (original)
+++ team/mjordan/cdrs-of-doom/main/cdr.c Mon Apr 22 09:59:05 2013
@@ -63,7 +63,9 @@
#include "asterisk/stringfields.h"
#include "asterisk/data.h"
#include "asterisk/config_options.h"
+#include "asterisk/json.h"
#include "asterisk/stasis.h"
+#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/astobj2.h"
@@ -307,17 +309,15 @@
void (* const init_function)(struct cdr_object *cdr);
void (* const process_party_a_update)(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot);
void (* const process_party_b_update)(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot);
- int (* const process_dial_message)(struct cdr_object *cdr, struct ast_channel_dial *dial_message);
+ int (* const process_dial_message)(struct cdr_object *cdr, struct ast_channel_snapshot *caller, struct ast_channel_snapshot *peer, const char *dial_status);
};
AST_MUTEX_DEFINE_STATIC(cdr_sched_lock);
-AST_MUTEX_DEFINE_STATIC(cdr_batch_lock);
-
static void base_process_party_a_update(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot);
static void single_state_init_function(struct cdr_object *cdr);
static void single_state_process_party_b_update(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot);
-static int single_state_process_dial_message(struct cdr_object *cdr, struct ast_channel_dial *dial_message);
+static int single_state_process_dial_message(struct cdr_object *cdr, struct ast_channel_snapshot *caller, struct ast_channel_snapshot *peer, const char *dial_status);
struct cdr_object_fn_table single_state_fn_table = {
.name = "Single",
@@ -328,7 +328,7 @@
};
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);
+static int dial_state_process_dial_message(struct cdr_object *cdr, struct ast_channel_snapshot *caller, struct ast_channel_snapshot *peer, const char *dial_status);
struct cdr_object_fn_table dial_state_fn_table = {
.name = "Dial",
@@ -380,7 +380,8 @@
AST_STRING_FIELD(name); /*< Channel name of party A. Cached here as the party A address may change */
AST_STRING_FIELD(bridge); /*< The bridge the party A happens to be in. */
);
- struct cdr_object *next;
+ struct cdr_object *next; /*< The next CDR object in the chain */
+ struct cdr_object *last; /*< The last CDR object in the chain */
};
@@ -439,6 +440,7 @@
if (!cdr) {
return NULL;
}
+ cdr->last = cdr;
if (ast_string_field_init(cdr, 64)) {
return NULL;
}
@@ -479,6 +481,7 @@
static struct cdr_object *cdr_object_create_and_append_cdr(struct cdr_object *cdr)
{
struct cdr_object *new_cdr;
+ struct cdr_object *it_cdr;
new_cdr = cdr_object_alloc(cdr->party_a.snapshot);
if (!new_cdr) {
@@ -491,9 +494,13 @@
new_cdr->party_a.flags = cdr->party_a.flags;
copy_vars(&new_cdr->party_a.variables, &cdr->party_a.variables);
- /* Fast forward to end of list */
- for (; cdr->next; cdr = cdr->next) { }
- cdr->next = new_cdr;
+ /* Append the CDR to the end of the list */
+ for (it_cdr = cdr; it_cdr->next; it_cdr = it_cdr->next) {
+ it_cdr->last = new_cdr;
+ }
+ it_cdr->last = new_cdr;
+ it_cdr->next = new_cdr;
+
return new_cdr;
}
@@ -756,14 +763,12 @@
return;
}
-static int single_state_process_dial_message(struct cdr_object *cdr, struct ast_channel_dial *message)
+static int single_state_process_dial_message(struct cdr_object *cdr, struct ast_channel_snapshot *caller, struct ast_channel_snapshot *peer, const char *dial_status)
{
RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);
- struct ast_channel_snapshot *caller = message->caller;
- struct ast_channel_snapshot *peer = message->peer;
/* We shouldn't get a Dial end without first transitioning to a dial state */
- ast_assert(ast_strlen_zero(message->dialstatus));
+ ast_assert(ast_strlen_zero(dial_status));
if (caller && !strcmp(cdr->party_a.snapshot->name, caller->name)) {
cdr_object_swap_snapshot(&cdr->party_a, caller);
@@ -819,11 +824,9 @@
}
}
-static int dial_state_process_dial_message(struct cdr_object *cdr, struct ast_channel_dial *dial_message)
+static int dial_state_process_dial_message(struct cdr_object *cdr, struct ast_channel_snapshot *caller, struct ast_channel_snapshot *peer, const char *dial_status)
{
RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);
- struct ast_channel_snapshot *caller = dial_message->caller;
- struct ast_channel_snapshot *peer = dial_message->peer;
struct ast_channel_snapshot *party_a;
if (caller) {
@@ -834,7 +837,7 @@
ast_assert(!strcmp(cdr->party_a.snapshot->name, party_a->name));
cdr_object_swap_snapshot(&cdr->party_a, party_a);
- if (ast_strlen_zero(dial_message->dialstatus)) {
+ if (ast_strlen_zero(dial_status)) {
/* If this isn't a dial end, don't process it here. A begin dial for
* a party A already in the dial state will be handled by the message
* router callback and add a new CDR for the party A */
@@ -849,16 +852,16 @@
}
/* Set the disposition based on the dial string. */
- if (!strcmp(dial_message->dialstatus, "ANSWER")) {
+ if (!strcmp(dial_status, "ANSWER")) {
/* TODO: if ANSWER, do NOTHING? */
return 0;
- } else if (!strcmp(dial_message->dialstatus, "BUSY")) {
+ } else if (!strcmp(dial_status, "BUSY")) {
cdr->disposition = AST_CDR_BUSY;
- } else if (!strcmp(dial_message->dialstatus, "CANCEL")) {
+ } else if (!strcmp(dial_status, "CANCEL")) {
cdr->disposition = AST_CDR_NOANSWER;
- } else if (!strcmp(dial_message->dialstatus, "CONGESTION")) {
+ } else if (!strcmp(dial_status, "CONGESTION")) {
cdr->disposition = AST_CDR_CONGESTION;
- } else if (!strcmp(dial_message->dialstatus, "FAILED")) {
+ } else if (!strcmp(dial_status, "FAILED")) {
cdr->disposition = AST_CDR_FAILED;
}
cdr_object_transition_state(cdr, &finalized_state_fn_table);
@@ -907,25 +910,38 @@
{
RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);
RAII_VAR(struct cdr_object *, cdr, NULL, ao2_cleanup);
- struct ast_channel_dial *payload = stasis_message_data(message);
+ struct ast_multi_channel_blob *payload = stasis_message_data(message);
+ struct ast_channel_snapshot *caller;
+ struct ast_channel_snapshot *peer;
struct ast_channel_snapshot *party_a;
struct ast_channel_snapshot *party_b;
struct cdr_object *it_cdr;
+ struct ast_json *dial_status_blob;
+ const char *dial_status = NULL;
int res = 1;
ast_assert(payload != NULL);
- if (payload->caller && payload->peer) {
- party_a = cdr_object_determine_party_a(payload->caller, payload->peer);
- } else if (payload->caller && !payload->peer) {
- party_a = payload->caller;
- } else if (!payload->caller && payload->peer) {
- party_a = payload->peer;
+ caller = ast_multi_channel_blob_get_channel(payload, "caller");
+ peer = ast_multi_channel_blob_get_channel(payload, "peer");
+ if (!peer && !caller) {
+ return;
+ }
+
+ dial_status_blob = ast_json_object_get(ast_multi_channel_blob_get_json(payload), "dialstatus");
+ if (!dial_status_blob) {
+ dial_status = ast_json_string_get(dial_status_blob);
+ }
+
+ if (caller && peer) {
+ party_a = cdr_object_determine_party_a(caller, peer);
+ } else if (caller) {
+ party_a = caller;
} else {
- ast_assert(0);
- return;
- }
- party_b = (party_a == payload->caller) ? payload->peer : payload->caller;
+ party_a = peer;
+ }
+
+ party_b = (party_a == caller) ? peer : caller;
cdr = cdr_object_find_or_create_cdr_by_channel(party_a);
if (!cdr) {
@@ -946,7 +962,7 @@
SCOPED_AO2LOCK(lock, cdr);
for (it_cdr = cdr; res && it_cdr; it_cdr = it_cdr->next) {
if (it_cdr->fn_table->process_dial_message) {
- res = it_cdr->fn_table->process_dial_message(it_cdr, payload);
+ res = it_cdr->fn_table->process_dial_message(it_cdr, party_a, party_b, dial_status);
}
}
/* If no CDR handled the dial message, make a new one */
@@ -957,7 +973,7 @@
if (!new_cdr) {
return;
}
- new_cdr->fn_table->process_dial_message(new_cdr, payload);
+ new_cdr->fn_table->process_dial_message(new_cdr, party_a, party_b, dial_status);
}
}
}
@@ -1002,7 +1018,7 @@
struct cdr_object *it_cdr;
ast_assert(update != NULL);
- if (ast_channel_snapshot() != update->type) {
+ if (ast_channel_snapshot_type() != update->type) {
return;
}
@@ -1179,17 +1195,17 @@
return newcdr;
}
-static const char *cdr_format_var_internal(struct ast_cdr *cdr, const char *name, int recur)
-{
+static const char *cdr_format_var_internal(struct ast_cdr *cdr, const char *name)
+{
+ struct ast_var_t *variables;
+ struct varshead *headp = &cdr->varshead;
+
if (ast_strlen_zero(name))
return NULL;
- for (; cdr; cdr = recur ? cdr->next : NULL) {
- struct ast_var_t *variables;
- struct varshead *headp = &cdr->varshead;
- AST_LIST_TRAVERSE(headp, variables, entries) {
- if (!strcasecmp(name, ast_var_name(variables)))
- return ast_var_value(variables);
+ AST_LIST_TRAVERSE(headp, variables, entries) {
+ if (!strcasecmp(name, ast_var_name(variables))) {
+ return ast_var_value(variables);
}
}
@@ -1210,7 +1226,7 @@
}
}
-void ast_cdr_format_var(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw)
+void ast_cdr_format_var(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int raw)
{
const char *fmt = "%Y-%m-%d %T";
const char *varbuf;
@@ -1272,7 +1288,7 @@
ast_copy_string(workspace, cdr->userfield, workspacelen);
else if (!strcasecmp(name, "sequence"))
snprintf(workspace, workspacelen, "%d", cdr->sequence);
- else if ((varbuf = cdr_format_var_internal(cdr, name, recur)))
+ else if ((varbuf = cdr_format_var_internal(cdr, name)))
ast_copy_string(workspace, varbuf, workspacelen);
else
workspace[0] = '\0';
@@ -1342,7 +1358,7 @@
"billsec", "disposition", "amaflags", "accountcode", "uniqueid", "linkedid",
"userfield", "sequence", NULL };
-int ast_cdr_setvar(const char *channel_name, const char *name, const char *value, int recur)
+int ast_cdr_setvar(const char *channel_name, const char *name, const char *value)
{
struct cdr_object *cdr;
struct ao2_iterator *it_cdrs;
@@ -1374,13 +1390,13 @@
return 0;
}
-static void cdr_object_format_var_internal(struct cdr_object *cdr, const char *name, char **value, size_t length)
+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);
+ ast_copy_string(value, ast_var_value(variable), length);
return;
}
}
@@ -1388,14 +1404,74 @@
*value = '\0';
}
-int ast_cdr_getvar(const char *channel_name, const char *name, char **value, size_t length)
+static int cdr_object_format_property(struct cdr_object *cdr_obj, const char *name, char *value, size_t length)
+{
+ struct ast_channel_snapshot *party_a = cdr_obj->party_a.snapshot;
+ struct ast_channel_snapshot *party_b = cdr_obj->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(cdr_obj->start, NULL, value, length);
+ } else if (!strcasecmp(name, "answer")) {
+ cdr_get_tv(cdr_obj->answer, NULL, value, length);
+ } else if (!strcasecmp(name, "end")) {
+ cdr_get_tv(cdr_obj->end, NULL, value, length);
+ } else if (!strcasecmp(name, "duration")) {
+ snprintf(value, length, "%ld", cdr_object_get_duration(cdr_obj));
+ } else if (!strcasecmp(name, "billsec")) {
+ snprintf(value, length, "%ld", cdr_object_get_billsec(cdr_obj));
+ } else if (!strcasecmp(name, "disposition")) {
+ snprintf(value, length, "%d", cdr_obj->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, cdr_obj->linkedid, length);
+ } else if (!strcasecmp(name, "userfield")) {
+ ast_copy_string(value, party_a->userfield, length);
+ } else if (!strcasecmp(name, "sequence")) {
+ snprintf(value, length, "%d", cdr_obj->sequence);
+ } else {
+ return 1;
+ }
+
+ return 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;
+ struct cdr_object *cdr_obj;
if (!cdr) {
ast_debug(3, "Unable to find CDR for channel %s\n", channel_name);
@@ -1408,70 +1484,16 @@
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);
+ cdr_obj = cdr->last;
+
+ if (cdr_object_format_property(cdr_obj, name, value, length)) {
+ /* Property failed; attempt variable */
+ cdr_object_format_var_internal(cdr_obj, 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)
{
@@ -1481,7 +1503,6 @@
struct cdr_object *it_cdr;
struct ast_var_t *variable;
const char *var;
- char *tmp;
char workspace[256];
int total = 0, x = 0, i;
@@ -1493,11 +1514,11 @@
ast_str_reset(*buf);
ao2_lock(cdr);
- for (; cdr; cdr = cdr->next) {
+ for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
if (++x > 1)
ast_str_append(buf, 0, "\n");
- AST_LIST_TRAVERSE(&cdr->party_a.variables, variable, entries) {
+ AST_LIST_TRAVERSE(&it_cdr->party_a.variables, variable, entries) {
if (!(var = ast_var_name(variable))) {
continue;
}
@@ -1511,16 +1532,17 @@
}
for (i = 0; cdr_readonly_vars[i]; i++) {
- workspace[0] = 0; /* null out the workspace, because the cdr_get_tv() won't write anything if time is NULL, so you get old vals */
- ast_cdr_format_var(cdr, cdr_readonly_vars[i], &tmp, workspace, sizeof(workspace), 0, 0);
- if (!tmp)
- continue;
-
- if (ast_str_append(buf, 0, "level %d: %s%c%s%c", x, cdr_readonly_vars[i], delim, tmp, sep) < 0) {
+ /* null out the workspace, because the cdr_get_tv() won't write anything if time is NULL, so you get old vals */
+ workspace[0] = 0;
+ cdr_object_format_property(it_cdr, cdr_readonly_vars[i], workspace, sizeof(workspace));
+
+ if (!ast_strlen_zero(workspace)
+ && ast_str_append(buf, 0, "level %d: %s%c%s%c", x, cdr_readonly_vars[i], delim, workspace, sep) < 0) {
ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
break;
- } else
+ } else {
total++;
+ }
}
}
@@ -1747,54 +1769,53 @@
ao2_find(active_cdrs_by_channel, channel_name, OBJ_KEY),
ao2_cleanup);
struct cdr_object *new_cdr;
- struct cdr_object *tail_cdr;
+ struct cdr_object *cdr_obj;
if (!cdr) {
return -1;
}
- /* FF to end of chain */
- for (tail_cdr = cdr; tail_cdr->next; tail_cdr = tail_cdr->next) { }
-
ao2_lock(cdr);
+ cdr_obj = cdr->last;
/* Copy over the basic CDR information. The Party A information is copied
* over automatically as part of the append
*/
- new_cdr = cdr_object_create_and_append_cdr(cdr);
+ new_cdr = cdr_object_create_and_append_cdr(cdr_obj);
if (!new_cdr) {
return -1;
}
- new_cdr->fn_table = tail_cdr->fn_table;
+ new_cdr->fn_table = cdr_obj->fn_table;
ast_string_field_set(new_cdr, bridge, cdr->bridge);
new_cdr->disposition = cdr->disposition;
new_cdr->flags = cdr->flags;
/* If there's a Party B, copy it over as well */
- if (tail_cdr->party_b.snapshot) {
- new_cdr->party_b.snapshot = tail_cdr->party_b.snapshot;
+ if (cdr_obj->party_b.snapshot) {
+ new_cdr->party_b.snapshot = cdr_obj->party_b.snapshot;
ao2_ref(new_cdr->party_b.snapshot, +1);
- strcpy(new_cdr->party_b.userfield, tail_cdr->party_b.userfield);
- new_cdr->party_b.flags = tail_cdr->party_b.flags;
+ strcpy(new_cdr->party_b.userfield, cdr_obj->party_b.userfield);
+ new_cdr->party_b.flags = cdr_obj->party_b.flags;
if (ast_test_flag(options, AST_CDR_FLAG_KEEP_VARS)) {
- copy_vars(&new_cdr->party_b.variables, &tail_cdr->party_b.variables);
- }
- }
- new_cdr->start = tail_cdr->start;
- new_cdr->answer = tail_cdr->answer;
+ copy_vars(&new_cdr->party_b.variables, &cdr_obj->party_b.variables);
+ }
+ }
+ new_cdr->start = cdr_obj->start;
+ new_cdr->answer = cdr_obj->answer;
/* Modify the times based on the flags passed in */
if (ast_test_flag(options, AST_CDR_FLAG_FINALIZE)) {
- cdr_object_transition_state(tail_cdr, &finalized_state_fn_table);
+ cdr_object_transition_state(cdr_obj, &finalized_state_fn_table);
}
if (ast_test_flag(options, AST_CDR_FLAG_SET_ANSWER)
&& new_cdr->party_a.snapshot->state == AST_STATE_UP) {
new_cdr->answer = ast_tvnow();
}
- if (!ast_test_flag(options, AST_CDR_FLAG_NORESET)) {
+ if (ast_test_flag(options, AST_CDR_FLAG_RESET)) {
new_cdr->answer = ast_tvnow();
new_cdr->start = ast_tvnow();
}
+ /* Create and append, by default, copies over the variables */
if (!ast_test_flag(options, AST_CDR_FLAG_KEEP_VARS)) {
cdr_free_vars(&new_cdr->party_a.variables);
}
@@ -1879,7 +1900,7 @@
/* manually reschedule from this point in time */
ast_mutex_lock(&cdr_sched_lock);
- cdr_sched = ast_sched_add(sched, batchtime * 1000, submit_scheduled_batch, NULL);
+ cdr_sched = ast_sched_add(sched, mod_cfg->general->batch_settings.size * 1000, submit_scheduled_batch, NULL);
ast_mutex_unlock(&cdr_sched_lock);
/* returning zero so the scheduler does not automatically reschedule */
return 0;
@@ -2216,8 +2237,8 @@
if (!stasis_router) {
return -1;
}
- stasis_message_router_add(stasis_router, stasis_cache_update(), handle_cache_update_message, NULL);
- stasis_message_router_add(stasis_router, ast_channel_dial_message(), handle_dial_message, NULL);
+ stasis_message_router_add(stasis_router, stasis_cache_update_type(), handle_cache_update_message, NULL);
+ stasis_message_router_add(stasis_router, ast_channel_dial_type(), handle_dial_message, NULL);
sched = ast_sched_context_create();
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=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/main/channel.c (original)
+++ team/mjordan/cdrs-of-doom/main/channel.c Mon Apr 22 09:59:05 2013
@@ -1176,7 +1176,7 @@
* a lot of data into this func to do it here!
*/
if (ast_get_channel_tech(tech) || (tech2 && ast_get_channel_tech(tech2))) {
- ast_publish_channel_state(tmp);
+ publish_channel_state(tmp);
}
ast_channel_internal_finalize(tmp);
@@ -2888,7 +2888,7 @@
ast_cc_offer(chan);
- ast_publish_channel_state(chan);
+ publish_channel_state(chan);
publish_cache_clear(chan);
ast_channel_unref(chan);
@@ -7153,7 +7153,7 @@
ast_channel_redirecting_set(original, ast_channel_redirecting(clonechan));
ast_channel_redirecting_set(clonechan, &exchange.redirecting);
- ast_publish_channel_state(original);
+ publish_channel_state(original);
/* Restore original timing file descriptor */
ast_channel_set_fd(original, AST_TIMING_FD, ast_channel_timingfd(original));
@@ -7316,7 +7316,7 @@
ast_channel_caller(chan)->ani.number.str = ast_strdup(cid_ani);
}
- ast_publish_channel_state(chan);
+ publish_channel_state(chan);
ast_channel_unlock(chan);
}
@@ -7342,7 +7342,7 @@
ast_channel_lock(chan);
ast_party_caller_set(ast_channel_caller(chan), caller, update);
- ast_publish_channel_state(chan);
+ publish_channel_state(chan);
ast_channel_unlock(chan);
}
@@ -7366,7 +7366,7 @@
* we override what they are saying the state is and things go amuck. */
ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE) ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), name);
- ast_publish_channel_state(chan);
+ publish_channel_state(chan);
return 0;
}
@@ -8657,7 +8657,6 @@
}
ast_stasis_channels_init();
- __channel_dial = stasis_message_type_create("ast_channel_dial");
ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel));
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=386233&r1=386232&r2=386233
==============================================================================
--- team/mjordan/cdrs-of-doom/main/channel_internal_api.c (original)
+++ team/mjordan/cdrs-of-doom/main/channel_internal_api.c Mon Apr 22 09:59:05 2013
@@ -463,7 +463,7 @@
ast_string_field_set(chan, accountcode, value);
/* Some things really like knowing when the accountcode changes. */
- ast_publish_channel_state(chan);
+ publish_channel_state(chan);
}
void ast_channel_linkedid_set(struct ast_channel *chan, const char *value)
@@ -568,7 +568,7 @@
return;
[... 231 lines stripped ...]
More information about the asterisk-commits
mailing list