</settings>
- <X-PRE-PROCESS cmd="set" data="UNIX_EPOCH_IN_GREGORIAN=62167219200" />
-
<variables>
<variable name="UNIX_EPOCH_IN_GREGORIAN" value="62167219200"/>
</variables>
<definitions>
<definition name="debug-call">
<filters>
- <filter name="variable_debug_call" type="exclude" value="true" />
+ <filter name="${first-of(variable_debug_call|Call-Debug|#$${Call-Debug})}" type="include" value="true" />
</filters>
<field name="Call-Debug" type="static" serialize-as="object">
<fields verbose="true" />
</field>
</definition>
+ <definition name="transfer-history">
+ <filters>
+ <filter name="variable_transfer_history" type="include" compare="exists" />
+ </filters>
+ <field name="Transfer-History" type="expand" value="${kz_json_history(${variable_transfer_history})}" serialize-as="raw"/>
+ </definition>
+
+ <definition name="transfer-source">
+ <filters>
+ <filter name="variable_transfer_source" type="include" compare="exists" />
+ </filters>
+ <field name="Transfer-Source" type="expand" value="${kz_json_history(variable_transfer_source)}" serialize-as="raw"/>
+ </definition>
+
+ <definition name="interaction-id">
+ <field name="variable_Call-Interaction-ID" as="Call-Interaction-ID" />
+ <field name="Call-Interaction-Is-Root" type="static" value="true" serialize-as="boolean">
+ <filters>
+ <filter name="variable_Call-Interaction-ID" type="include" compare="field" value="variable_Original-Call-Interaction-ID" />
+ <field name="${first-of(Event-Subclass|Event-Name|#none)}" type="include" compare="list" value="CHANNEL_DESTROY|KZ_CDR"/>
+ </filters>
+ </field>
+ </definition>
+
<definition name="Metaflow-Control">
<field name="Metaflow-Control" type="static" serialize-as="object">
<filters>
</filters>
</field>
- <field name="Call-Interaction-ID" type="expand"
- value="${expr(ceil((${Event-Date-Timestamp} / 1000000) + $${UNIX_EPOCH_IN_GREGORIAN}))}-${regex(${create_uuid()}|^([^-]*)|%1)}">
- <filters>
- <filter name="Unique-ID" type="include" compare="exists" />
- <filter name="ecallmgr_Call-Interaction-ID" type="exclude"
- compare="exists" />
- <filter name="variable_ecallmgr_Call-Interaction-ID" type="exclude"
- compare="exists" />
- <filter name="variable_sip_h_X-ecallmgr_Call-Interaction-ID"
- type="exclude" compare="exists" />
- </filters>
- </field>
+ <!-- <field name="variable_Call-Interaction-ID" as="Call-Interaction-ID" /> -->
+ <field name="interaction-id" type="reference" />
+
<field name="variable_presence_id" as="Presence-ID" />
<field name="redirect" type="group">
<field name="hangup-fields" type="reference" />
<field name="variable_Media-Recordings" as="Media-Recordings" />
<field name="debug-call" type="reference" />
+ <field name="transfer-history" type="reference" />
</fields>
<filters>
<log name="info" value="SWITCH_LOG_INFO" />
<log name="success" value="SWITCH_LOG_INFO" />
<log name="time" value="SWITCH_LOG_INFO" />
- <log name="filtered-event" value="SWITCH_LOG_INFO" />
- <log name="filtered-field" value="SWITCH_LOG_INFO" />
</logging>
</profile>
<log name="info" value="SWITCH_LOG_INFO" />
<log name="success" value="SWITCH_LOG_INFO" />
<log name="time" value="SWITCH_LOG_INFO" />
- <log name="filtered-event" value="SWITCH_LOG_INFO" />
- <log name="filtered-field" value="SWITCH_LOG_INFO" />
</logging>
</profile>
#define MAX_FIRST_OF 25
+#define MAX_HISTORY 50
+#define HST_ARRAY_DELIM "|:"
+#define HST_ITEM_DELIM ':'
+
+static void process_history_item(char* value, cJSON *json)
+{
+ char *argv[4] = { 0 };
+ char *item = strdup(value);
+ int argc = switch_separate_string(item, HST_ITEM_DELIM, argv, (sizeof(argv) / sizeof(argv[0])));
+ cJSON *jitem = cJSON_CreateObject();
+ char *epoch = NULL, *callid = NULL, *type = NULL;
+ int add = 0;
+ if(argc == 4) {
+ add = 1;
+ epoch = argv[0];
+ callid = argv[1];
+ type = argv[2];
+
+ if(!strncmp(type, "bl_xfer", 7)) {
+ char *split = strchr(argv[3], '/');
+ if(split) *(split++) = '\0';
+ cJSON_AddItemToObject(jitem, "Call-ID", cJSON_CreateString(callid));
+ cJSON_AddItemToObject(jitem, "Type", cJSON_CreateString("blind"));
+ cJSON_AddItemToObject(jitem, "Extension", cJSON_CreateString(argv[3]));
+ } else if(!strncmp(type, "att_xfer", 8)) {
+ char *split = strchr(argv[3], '/');
+ if(split) {
+ *(split++) = '\0';
+ cJSON_AddItemToObject(jitem, "Call-ID", cJSON_CreateString(callid));
+ cJSON_AddItemToObject(jitem, "Type", cJSON_CreateString("attended"));
+ cJSON_AddItemToObject(jitem, "Transferee", cJSON_CreateString(argv[3]));
+ cJSON_AddItemToObject(jitem, "Transferer", cJSON_CreateString(split));
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TRANSFER TYPE '%s' NOT HANDLED => %s\n", type, item);
+ add = 0;
+ }
+ } else if(!strncmp(type, "uuid_br", 7)) {
+ cJSON_AddItemToObject(jitem, "Call-ID", cJSON_CreateString(callid));
+ cJSON_AddItemToObject(jitem, "Type", cJSON_CreateString("bridge"));
+ cJSON_AddItemToObject(jitem, "Other-Leg", cJSON_CreateString(argv[3]));
+
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TRANSFER TYPE '%s' NOT HANDLED => %s\n", type, item);
+ add = 0;
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TRANSFER TYPE SPLIT ERROR %i => %s\n", argc, item);
+ }
+ if(add) {
+ cJSON_AddItemToObject(json, epoch, jitem);
+ } else {
+ cJSON_Delete(jitem);
+ }
+ switch_safe_free(item);
+}
+
+SWITCH_STANDARD_API(kz_json_history) {
+ char *mycmd = NULL, *argv[MAX_HISTORY] = { 0 };
+ int n, argc = 0;
+ cJSON *json = cJSON_CreateObject();
+ char* output = NULL;
+ switch_event_header_t *header = NULL;
+ if (!zstr(cmd) && (mycmd = strdup(cmd))) {
+ if (!strncmp(mycmd, "ARRAY::", 7)) {
+ mycmd += 7;
+ argc = switch_separate_string_string(mycmd, HST_ARRAY_DELIM, argv, (sizeof(argv) / sizeof(argv[0])));
+ for(n=0; n < argc; n++) {
+ process_history_item(argv[n], json);
+ }
+ } else if (strchr(mycmd, HST_ITEM_DELIM)) {
+ process_history_item(mycmd, json);
+ } else if (stream->param_event) {
+ header = switch_event_get_header_ptr(stream->param_event, mycmd);
+ if (header != NULL) {
+ if(header->idx) {
+ for(n = 0; n < header->idx; n++) {
+ process_history_item(header->array[n], json);
+ }
+ } else {
+ process_history_item(header->value, json);
+ }
+
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TRANSFER HISTORY HEADER NOT FOUND => %s\n", mycmd);
+ }
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "TRANSFER HISTORY NOT PARSED => %s\n", mycmd);
+ }
+ }
+ output = cJSON_PrintUnformatted(json);
+ stream->write_function(stream, "%s", output);
+ switch_safe_free(output);
+ cJSON_Delete(json);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_STANDARD_API(kz_first_of) {
char delim = '|';
char *mycmd = NULL, *argv[MAX_FIRST_OF] = { 0 };
switch_console_set_complete("add kz_uuid_setvar_encoded ::console::list_uuid");
SWITCH_ADD_API(api_interface, "kz_http_put", KZ_HTTP_PUT_DESC, kz_http_put, KZ_HTTP_PUT_SYNTAX);
SWITCH_ADD_API(api_interface, "first-of", KZ_FIRST_OF_DESC, kz_first_of, KZ_FIRST_OF_SYNTAX);
+ SWITCH_ADD_API(api_interface, "kz_json_history", KZ_FIRST_OF_DESC, kz_json_history, KZ_FIRST_OF_SYNTAX);
}
cur->compare = FILTER_COMPARE_EXISTS;
} else if (!strncmp(compare, "regex", 5)) {
cur->compare = FILTER_COMPARE_REGEX;
+ } else if (!strncmp(compare, "field", 5)) {
+ cur->compare = FILTER_COMPARE_FIELD;
}
}
kazoo_config_event_handler(definitions, profiles, xml_profile, NULL);
}
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unable to locate a event-handler profile for kazoo\n" );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to locate a event-handler profile for kazoo\n" );
}
} else {
destroy_config(&profiles);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unable to locate event-handlers section for kazoo\n" );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "unable to locate event-handlers section for kazoo, using default\n" );
}
return profiles;
kazoo_config_fetch_handler(definitions, profiles, xml_profile, NULL);
}
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Unable to locate a fetch-handler profile for kazoo\n" );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to locate a fetch-handler profile for kazoo\n" );
}
} else {
destroy_config(&profiles);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unable to locate fetch-handlers section for kazoo\n" );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "unable to locate fetch-handlers section for kazoo, using default\n" );
}
return profiles;
char *name = (char *) switch_xml_attr_soft(cfg, "name");
if (zstr(name)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load kazoo profile. Check definition missing name attr\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to load kazoo profile, check definition missing name attr\n");
return SWITCH_STATUS_GENERR;
}
kazoo_config_fields_loop(root, root->pool, cfg, &definition->head);
if ( switch_core_hash_insert(root->hash, name, (void *) definition) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to insert new definition [%s] into kazoo definitions hash\n", name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed to insert new definition [%s] into kazoo definitions hash\n", name);
return SWITCH_STATUS_GENERR;
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Definition[%s] Successfully configured\n", definition->name);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "definition[%s] successfully configured\n", definition->name);
return SWITCH_STATUS_SUCCESS;
}
}
} else {
destroy_config(&definitions);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "no definitions section for kazoo\n" );
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "unable to locate definitions section for kazoo, using default\n" );
}
return definitions;
kazoo_json_term json_encoding;
int enable_legacy;
-// char *profile_vars_prefixes[KZ_MAX_SEPARATE_STRINGS];
-// char *kazoo_var_prefixes[KZ_MAX_SEPARATE_STRINGS];
-// char *profile_vars_prefixes;
-// char *kazoo_var_prefixes;
char **profile_vars_prefixes;
char **kazoo_var_prefixes;
kazoo_globals.port = 0;
kazoo_globals.io_fault_tolerance = 10;
kazoo_globals.json_encoding = ERLANG_TUPLE;
- kazoo_globals.enable_legacy = SWITCH_TRUE;
+ kazoo_globals.enable_legacy = SWITCH_FALSE;
if ((child = switch_xml_child(cfg, "settings"))) {
switch_status_t kazoo_config_handlers(switch_xml_t cfg)
{
switch_xml_t def = NULL;
+ switch_xml_t child, param;
char* xml = NULL;
kazoo_config_ptr definitions = NULL, fetch_handlers = NULL, event_handlers = NULL;
kazoo_event_profile_ptr events = NULL;
kz_xml_process(def);
kz_xml_process(cfg);
+ if ((child = switch_xml_child(cfg, "variables"))) {
+ for (param = switch_xml_child(child, "variable"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
+ if(var && val) {
+ switch_core_set_variable(var, val);
+ }
+ }
+ } else if ((child = switch_xml_child(def, "variables"))) {
+ for (param = switch_xml_child(child, "variable"); param; param = param->next) {
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
+ if(var && val) {
+ switch_core_set_variable(var, val);
+ }
+ }
+ }
+
definitions = kazoo_config_definitions(cfg);
if(definitions == NULL) {
- definitions = kazoo_config_definitions(def);
+ if(kazoo_globals.definitions == NULL) {
+ definitions = kazoo_config_definitions(def);
+ } else {
+ definitions = kazoo_globals.definitions;
+ }
}
fetch_handlers = kazoo_config_fetch_handlers(definitions, cfg);
if(fetch_handlers == NULL) {
- fetch_handlers = kazoo_config_fetch_handlers(definitions, def);
+ if(kazoo_globals.fetch_handlers == NULL) {
+ fetch_handlers = kazoo_config_fetch_handlers(definitions, def);
+ } else {
+ fetch_handlers = kazoo_globals.fetch_handlers;
+ }
}
event_handlers = kazoo_config_event_handlers(definitions, cfg);
if(event_handlers == NULL) {
- event_handlers = kazoo_config_event_handlers(definitions, def);
+ if(kazoo_globals.event_handlers == NULL) {
+ event_handlers = kazoo_config_event_handlers(definitions, def);
+ } else {
+ event_handlers = kazoo_globals.event_handlers;
+ }
}
if(event_handlers != NULL) {
if(events == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to get default handler for events\n");
- destroy_config(&event_handlers);
- destroy_config(&fetch_handlers);
- destroy_config(&definitions);
+ if(kazoo_globals.event_handlers != event_handlers) destroy_config(&event_handlers);
+ if(kazoo_globals.fetch_handlers != fetch_handlers) destroy_config(&fetch_handlers);
+ if(kazoo_globals.definitions != definitions) destroy_config(&definitions);
switch_xml_free(def);
switch_safe_free(xml);
return SWITCH_STATUS_GENERR;
}
- bind_event_profiles(events->events);
- kazoo_globals.events = events;
+ if(kazoo_globals.events != events) {
+ bind_event_profiles(events->events);
+ kazoo_globals.events = events;
+ }
- destroy_config(&kazoo_globals.event_handlers);
- kazoo_globals.event_handlers = event_handlers;
+ if(kazoo_globals.event_handlers != event_handlers) {
+ kazoo_config_ptr tmp = kazoo_globals.event_handlers;
+ kazoo_globals.event_handlers = event_handlers;
+ destroy_config(&tmp);
+ }
- rebind_fetch_profiles(fetch_handlers);
- destroy_config(&kazoo_globals.fetch_handlers);
- kazoo_globals.fetch_handlers = fetch_handlers;
+ if(kazoo_globals.fetch_handlers != fetch_handlers) {
+ kazoo_config_ptr tmp = kazoo_globals.fetch_handlers;
+ kazoo_globals.fetch_handlers = fetch_handlers;
+ rebind_fetch_profiles(fetch_handlers);
+ destroy_config(&tmp);
+ }
- destroy_config(&kazoo_globals.definitions);
- kazoo_globals.definitions = definitions;
+ if(kazoo_globals.definitions != definitions) {
+ kazoo_config_ptr tmp = kazoo_globals.definitions;
+ kazoo_globals.definitions = definitions;
+ destroy_config(&tmp);
+ }
switch_xml_free(def);
FILTER_COMPARE_LIST,
FILTER_COMPARE_VALUE,
FILTER_COMPARE_PREFIX,
- FILTER_COMPARE_EXISTS
+ FILTER_COMPARE_EXISTS,
+ FILTER_COMPARE_FIELD
+
} kazoo_filter_compare_type;
typedef enum {
FIELD_PREFIX,
FIELD_OBJECT,
FIELD_GROUP,
- FIELD_REFERENCE,
+ FIELD_REFERENCE
} kazoo_field_type;
{
switch_event_header_t *header;
int hasValue = 0, n;
- char *value;
+ char *value = NULL, *expr = NULL;
switch(filter->compare) {
break;
case FILTER_COMPARE_VALUE:
- value = switch_event_get_header_nil(evt, filter->name);
- hasValue = !strcmp(value, filter->value);
+ if (*filter->name == '$') {
+ value = expr = kz_event_expand_headers(evt, filter->name);
+ } else {
+ value = switch_event_get_header(evt, filter->name);
+ }
+ hasValue = value ? !strcmp(value, filter->value) : 0;
+ break;
+
+ case FILTER_COMPARE_FIELD:
+ if (*filter->name == '$') {
+ value = expr = kz_event_expand_headers(evt, filter->name);
+ } else {
+ value = switch_event_get_header(evt, filter->name);
+ }
+ hasValue = value ? !strcmp(value, switch_event_get_header_nil(evt, filter->value)) : 0;
break;
case FILTER_COMPARE_PREFIX:
break;
case FILTER_COMPARE_LIST:
- value = switch_event_get_header(evt, filter->name);
+ if (*filter->name == '$') {
+ value = expr = kz_event_expand_headers(evt, filter->name);
+ } else {
+ value = switch_event_get_header(evt, filter->name);
+ }
if(value) {
for(n = 0; n < filter->list.size; n++) {
if(!strncmp(value, filter->list.value[n], strlen(filter->list.value[n]))) {
break;
}
+ switch_safe_free(expr);
+
return hasValue;
}
switch(section) {
case SWITCH_XML_SECTION_CONFIG:
add_fetch_handler(ei_node, pid, kazoo_globals.config_fetch_binding);
- if(!kazoo_globals.config_fetched)
+ if(!kazoo_globals.config_fetched) {
+ kazoo_globals.config_fetched = 1;
fetch_config();
+ }
break;
case SWITCH_XML_SECTION_DIRECTORY:
add_fetch_handler(ei_node, pid, kazoo_globals.directory_fetch_binding);
*/
#include "mod_kazoo.h"
+#define INTERACTION_VARIABLE "Call-Interaction-ID"
+
static const char *bridge_variables[] = {
"Call-Control-Queue",
"Call-Control-PID",
"Call-Control-Node",
- "ecallmgr_Call-Interaction-ID",
+ INTERACTION_VARIABLE,
"ecallmgr_Ecallmgr-Node",
"sip_h_k-cid",
"Switch-URI",
/*.on_exchange_media */ NULL,
/*.on_soft_execute */ NULL,
/*.on_consume_media */ NULL,
- /*.on_hibernate */ NULL
+ /*.on_hibernate */ NULL,
+ /*.on_reset */ NULL,
+ /*.on_park */ NULL,
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ NULL
};
static void kz_tweaks_handle_bridge_variables(switch_event_t *event)
const char *b_leg = switch_event_get_header(event, "Bridge-B-Unique-ID");
int i;
+ if (kazoo_globals.enable_legacy) return;
+
if (a_leg && (a_session = switch_core_session_force_locate(a_leg)) != NULL) {
switch_channel_t *a_channel = switch_core_session_get_channel(a_session);
if(switch_channel_get_variable_dup(a_channel, bridge_variables[0], SWITCH_FALSE, -1) == NULL) {
if(b_leg && (b_session = switch_core_session_force_locate(b_leg)) != NULL) {
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
for(i = 0; bridge_variables[i] != NULL; i++) {
- const char *val = switch_channel_get_variable_dup(b_channel, bridge_variables[i], SWITCH_TRUE, -1);
+ const char *val = switch_channel_get_variable_dup(b_channel, bridge_variables[i], SWITCH_FALSE, -1);
switch_channel_set_variable(a_channel, bridge_variables[i], val);
- switch_safe_strdup(val);
}
switch_core_session_rwunlock(b_session);
}
switch_channel_t *b_channel = switch_core_session_get_channel(b_session);
if(switch_channel_get_variable_dup(b_channel, bridge_variables[0], SWITCH_FALSE, -1) == NULL) {
for(i = 0; bridge_variables[i] != NULL; i++) {
- const char *val = switch_channel_get_variable_dup(b_channel, bridge_variables[i], SWITCH_TRUE, -1);
+ const char *val = switch_channel_get_variable_dup(a_channel, bridge_variables[i], SWITCH_FALSE, -1);
switch_channel_set_variable(b_channel, bridge_variables[i], val);
- switch_safe_strdup(val);
}
}
switch_core_session_rwunlock(b_session);
const char *peer_uuid = switch_event_get_header(event, "Unique-ID");
int processed = 0;
+ if (kazoo_globals.enable_legacy) return;
+
+
if(a_leg_call_id && replaced_call_id) {
const char *call_id = switch_event_get_header(event, "Bridge-B-Unique-ID");
switch_core_session_t *session = NULL;
const char *a_leg_call_id = switch_event_get_header(event, "variable_sip_replaces_a-leg");
const char *peer_uuid = switch_event_get_header(event, "Unique-ID");
+ if (kazoo_globals.enable_legacy) return;
+
if(a_leg_call_id && replaced_call_id) {
switch_core_session_t *call_session = NULL;
const char *call_id = switch_event_get_header(event, "Bridge-B-Unique-ID");
static void kz_tweaks_channel_bridge_event_handler(switch_event_t *event)
{
+ if (kazoo_globals.enable_legacy) return;
+
kz_tweaks_handle_bridge_replaces_call_id(event);
kz_tweaks_handle_bridge_replaces(event);
kz_tweaks_handle_bridge_variables(event);
{
const char *uuid = switch_event_get_header(event, "Unique-ID");
const char *replaced_by = switch_event_get_header(event, "att_xfer_replaced_by");
+ if (kazoo_globals.enable_legacy) return;
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "REPLACED : %s , %s\n", uuid, replaced_by);
}
{
const char *uuid = switch_event_get_header(event, "Unique-ID");
const char *peer_uuid = switch_event_get_header(event, "intercepted_by");
+
+ if (kazoo_globals.enable_legacy) return;
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "INTERCEPTED : %s => %s\n", uuid, peer_uuid);
}
const char *func = switch_event_get_header(event, "Event-Calling-Function");
const char *line = switch_event_get_header(event, "Event-Calling-Line-Number");
+ if (kazoo_globals.enable_legacy) return;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TRANSFEROR : %s , %s , %s, %s, %s , %s , %s \n", uuid, orig_call_id, dest_peer_uuid, dest_call_id, file, func, line);
if ((uuid_session = switch_core_session_force_locate(uuid)) != NULL) {
switch_channel_t *uuid_channel = switch_core_session_get_channel(uuid_session);
- const char* interaction_id = switch_channel_get_variable_dup(uuid_channel, "ecallmgr_Call-Interaction-ID", SWITCH_TRUE, -1);
+ const char* interaction_id = switch_channel_get_variable_dup(uuid_channel, INTERACTION_VARIABLE, SWITCH_TRUE, -1);
// set to uuid & peer_uuid
if(interaction_id != NULL) {
switch_core_session_t *session = NULL;
if(dest_call_id && (session = switch_core_session_force_locate(dest_call_id)) != NULL) {
switch_channel_t *channel = switch_core_session_get_channel(session);
- const char* prv_interaction_id = switch_channel_get_variable_dup(channel, "ecallmgr_Call-Interaction-ID", SWITCH_TRUE, -1);
+ const char* prv_interaction_id = switch_channel_get_variable_dup(channel, INTERACTION_VARIABLE, SWITCH_TRUE, -1);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "LOCATING UUID PRV : %s : %s\n", prv_interaction_id, interaction_id);
- switch_channel_set_variable(channel, "ecallmgr_Call-Interaction-ID", interaction_id);
+ switch_channel_set_variable(channel, INTERACTION_VARIABLE, interaction_id);
if (switch_event_create(&evt, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, evt);
switch_event_fire(&evt);
}
if(dest_peer_uuid && (session = switch_core_session_force_locate(dest_peer_uuid)) != NULL) {
switch_channel_t *channel = switch_core_session_get_channel(session);
- const char* prv_interaction_id = switch_channel_get_variable_dup(channel, "ecallmgr_Call-Interaction-ID", SWITCH_TRUE, -1);
+ const char* prv_interaction_id = switch_channel_get_variable_dup(channel, INTERACTION_VARIABLE, SWITCH_TRUE, -1);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "LOCATING PEER UUID PRV : %s : %s\n", prv_interaction_id, interaction_id);
- switch_channel_set_variable(channel, "ecallmgr_Call-Interaction-ID", interaction_id);
+ switch_channel_set_variable(channel, INTERACTION_VARIABLE, interaction_id);
if (switch_event_create(&evt, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, evt);
switch_event_fire(&evt);
{
const char *uuid = switch_event_get_header(event, "Unique-ID");
const char *replaced_by_uuid = switch_event_get_header(event, "att_xfer_replaced_call_id");
+
+ if (kazoo_globals.enable_legacy) return;
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TRANSFEREE : %s replaced by %s\n", uuid, replaced_by_uuid);
}
static void kz_tweaks_handle_caller_id(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
- const char *token = switch_channel_get_variable(channel, "acl_token");
switch_caller_profile_t* caller = switch_channel_get_caller_profile(channel);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "CHECKING CALLER-ID\n");
- if (token) {
+ if (caller && switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) {
const char* val = NULL;
if((val=switch_caller_get_field_by_name(caller, "Endpoint-Caller-ID-Name"))) {
caller->caller_id_name = val;
}
}
+/*
static switch_status_t kz_tweaks_handle_auth_token(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
return SWITCH_STATUS_SUCCESS;
}
+*/
static switch_status_t kz_tweaks_handle_nightmare_xfer(switch_core_session_t *session)
{
switch_core_session_t *replace_session = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session);
- switch_event_t *event;
const char *replaced_call_id = switch_channel_get_variable(channel, "sip_replaces_call_id");
const char *core_uuid = switch_channel_get_variable(channel, "sip_h_X-FS-From-Core-UUID");
const char *partner_uuid = switch_channel_get_variable(channel, "sip_h_X-FS-Refer-Partner-UUID");
const char *interaction_id = switch_channel_get_variable(channel, "sip_h_X-FS-Call-Interaction-ID");
if(core_uuid && partner_uuid && replaced_call_id && interaction_id) {
- switch_channel_set_variable(channel, "ecallmgr_Call-Interaction-ID", interaction_id);
- if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {
- switch_channel_event_set_data(channel, event);
- switch_event_fire(&event);
- }
+ switch_channel_set_variable(channel, INTERACTION_VARIABLE, interaction_id);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "checking nightmare xfer tweak for %s\n", switch_channel_get_uuid(channel));
if ((replace_session = switch_core_session_locate(replaced_call_id))) {
switch_channel_t *replaced_call_channel = switch_core_session_get_channel(replace_session);
- switch_channel_set_variable(replaced_call_channel, "ecallmgr_Call-Interaction-ID", interaction_id);
- if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {
- switch_channel_event_set_data(replaced_call_channel, event);
- switch_event_fire(&event);
- }
+ switch_channel_set_variable(replaced_call_channel, INTERACTION_VARIABLE, interaction_id);
switch_core_session_rwunlock(replace_session);
}
if ((replace_session = switch_core_session_locate(partner_uuid))) {
switch_channel_t *replaced_call_channel = switch_core_session_get_channel(replace_session);
- switch_channel_set_variable(replaced_call_channel, "ecallmgr_Call-Interaction-ID", interaction_id);
- if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS) {
- switch_channel_event_set_data(replaced_call_channel, event);
- switch_event_fire(&event);
- }
+ switch_channel_set_variable(replaced_call_channel, INTERACTION_VARIABLE, interaction_id);
switch_core_session_rwunlock(replace_session);
}
}
}
+static void kz_tweaks_handle_interaction_id(switch_core_session_t *session)
+{
+ const char *expr = "${expr(ceil((${Event-Date-Timestamp} / 1000000) + $${UNIX_EPOCH_IN_GREGORIAN}))}-${regex(${create_uuid()}|^([^-]*)|%1)}";
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ char * val = kz_expand(expr);
+
+ if (val) {
+ switch_channel_set_variable(channel, "Original-"INTERACTION_VARIABLE, val);
+ switch_channel_set_variable(channel, INTERACTION_VARIABLE, val);
+ }
+
+ switch_safe_free(val);
+
+}
+
static switch_status_t kz_tweaks_register_handle_xfer(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
static switch_status_t kz_tweaks_on_init(switch_core_session_t *session)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
+ if (kazoo_globals.enable_legacy) return SWITCH_STATUS_SUCCESS;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "checking tweaks for %s\n", switch_channel_get_uuid(channel));
switch_channel_set_flag(channel, CF_VERBOSE_EVENTS);
+ kz_tweaks_handle_interaction_id(session);
kz_tweaks_handle_switch_uri(session);
kz_tweaks_handle_caller_id(session);
- kz_tweaks_handle_auth_token(session);
+// kz_tweaks_handle_auth_token(session);
kz_tweaks_handle_nightmare_xfer(session);
kz_tweaks_handle_replaces_id(session);
kz_tweaks_handle_loopback(session);
/*.on_hibernate */ NULL,
/*.on_reset */ NULL,
/*.on_park */ NULL,
- /*.on_reporting */ NULL
+ /*.on_reporting */ NULL,
+ /*.on_destroy */ NULL
};
static void kz_tweaks_register_state_handlers()
{
+ kz_tweaks_state_handlers.flags = SSH_FLAG_PRE_EXEC;
switch_core_add_state_handler(&kz_tweaks_state_handlers);
}
switch_event_unbind_callback(kz_tweaks_channel_transferee_event_handler);
}
+void kz_tweaks_add_core_variables()
+{
+ switch_core_set_variable("UNIX_EPOCH_IN_GREGORIAN", "62167219200");
+}
+
void kz_tweaks_start()
{
+ kz_tweaks_add_core_variables();
kz_tweaks_register_state_handlers();
kz_tweaks_bind_events();
}