[mod_kazoo] add checks, fixes & defaults

* [mod_kazoo] set default on expand headers

* [mod_kazoo] use simple var reference in default config

* [mod_kazoo] fix kz_expand

* [mod_kazoo] check if profile for agent is valid

* [mod_kazoo] reorder code in kazoo endpoint
This commit is contained in:
lazedo 2020-03-06 13:56:07 +00:00 committed by GitHub
parent 90a7fc7125
commit 592689c253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 20 deletions

View File

@ -31,7 +31,7 @@
<definition name="timestamp">
<field name="Timestamp" type="expand"
value="${expr(ceil((${Event-Date-Timestamp} / 1000000) + $${UNIX_EPOCH_IN_GREGORIAN}))}"
value="${expr(ceil((${Event-Date-Timestamp} / 1000000) + ${UNIX_EPOCH_IN_GREGORIAN}))}"
serialize-as="number" />
</definition>
@ -54,7 +54,7 @@
<definition name="debug-call">
<filters>
<filter
name="${first-of(variable_debug_call|Call-Debug|#$${Call-Debug})}"
name="${first-of(variable_debug_call|Call-Debug|#${Call-Debug})}"
type="include" value="true" />
</filters>
<field name="Call-Debug" type="static" serialize-as="object">
@ -355,7 +355,7 @@
value="kazoo_event_name|Event-Subclass|Event-Name" />
<field name="Event-Date-Timestamp" as="Msg-ID" />
<field name="Timestamp" type="expand"
value="${expr(ceil((${Event-Date-Timestamp} / 1000000) + $${UNIX_EPOCH_IN_GREGORIAN}))}"
value="${expr(ceil((${Event-Date-Timestamp} / 1000000) + ${UNIX_EPOCH_IN_GREGORIAN}))}"
serialize-as="number" />
<field name="variable_sip_origination_call_uuid" as="Origination-Call-ID" />
<field name="Call-ID" type="first-of"
@ -651,7 +651,7 @@
<definition name="voice_dialplan">
<field name="fetch-info" type="reference" />
<field name="Timestamp" type="expand"
value="${expr(ceil((${Event-Date-Timestamp} / 1000000) + $${UNIX_EPOCH_IN_GREGORIAN}))}"
value="${expr(ceil((${Event-Date-Timestamp} / 1000000) + ${UNIX_EPOCH_IN_GREGORIAN}))}"
serialize-as="number" />
<field name="Unique-ID" as="Call-ID" />
<field name="variable_sip_invite_domain" as="Domain-Name" />

View File

@ -427,6 +427,8 @@ SWITCH_STANDARD_API(kz_expand_api)
switch_safe_free(mycmd);
return SWITCH_STATUS_GENERR;
}
} else {
input = mycmd;
}
p = kz_expand(input, uuid);

View File

@ -131,6 +131,7 @@ switch_status_t kazoo_ei_config(switch_xml_t cfg) {
kazoo_globals.json_encoding = ERLANG_TUPLE;
kazoo_globals.legacy_events = SWITCH_FALSE;
kazoo_globals.expand_headers_on_fetch = SWITCH_TRUE;
kz_set_tweak(KZ_TWEAK_INTERACTION_ID);
kz_set_tweak(KZ_TWEAK_EXPORT_VARS);

View File

@ -56,20 +56,9 @@ static void kz_tweaks_variables_to_event(switch_core_session_t *session, switch_
}
}
/* kazoo endpoint */
switch_endpoint_interface_t *kz_endpoint_interface;
static switch_call_cause_t kz_endpoint_outgoing_channel(switch_core_session_t *session,
switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
switch_call_cause_t *cancel_cause);
switch_io_routines_t kz_endpoint_io_routines = {
/*.outgoing_channel */ kz_endpoint_outgoing_channel
};
static switch_call_cause_t kz_endpoint_outgoing_channel(switch_core_session_t *session,
switch_event_t *var_event,
switch_caller_profile_t *outbound_profile,
switch_caller_profile_t *outbound_profile_in,
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags,
switch_call_cause_t *cancel_cause)
{
@ -97,14 +86,15 @@ static switch_call_cause_t kz_endpoint_outgoing_channel(switch_core_session_t *s
char *cid_num_override = NULL;
switch_event_t *event = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_caller_profile_t *outbound_profile = NULL;
if (zstr(outbound_profile->destination_number)) {
if (zstr(outbound_profile_in->destination_number)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "NO DESTINATION NUMBER\n");
goto done;
}
user = strdup(outbound_profile->destination_number);
user = strdup(outbound_profile_in->destination_number);
if (!user)
goto done;
@ -382,6 +372,32 @@ static switch_call_cause_t kz_endpoint_outgoing_channel(switch_core_session_t *s
goto done;
}
//
outbound_profile = outbound_profile_in;
/*
outbound_profile = switch_caller_profile_dup(outbound_profile_in->pool, outbound_profile_in);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG1, "CHECKING CALLER-ID\n");
if ((x_params = switch_xml_child(x_user, "profile-variables"))) {
const char* val = NULL;
outbound_profile->soft = NULL;
for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
const char *pvar = switch_xml_attr(x_param, "name");
const char *val = switch_xml_attr(x_param, "value");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG1, "setting profile var %s = %s\n", pvar, val);
switch_caller_profile_set_var(outbound_profile, pvar, val);
}
// * TODO * verify onnet/offnet
if((val=switch_caller_get_field_by_name(outbound_profile, "Endpoint-Caller-ID-Name"))) {
outbound_profile->callee_id_name = val;
outbound_profile->orig_caller_id_name = val;
}
if((val=switch_caller_get_field_by_name(outbound_profile, "Endpoint-Caller-ID-Number"))) {
outbound_profile->callee_id_number = val;
outbound_profile->orig_caller_id_number = val;
}
}
*/
status = switch_ivr_originate(session, new_session, &cause, d_dest, timelimit, NULL,
cid_name_override, cid_num_override, outbound_profile, var_event, myflags,
cancel_cause, NULL);
@ -409,17 +425,20 @@ static switch_call_cause_t kz_endpoint_outgoing_channel(switch_core_session_t *s
}
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG1, "CHECKING CALLER-ID\n");
if ((x_params = switch_xml_child(x_user, "profile-variables"))) {
switch_caller_profile_t *cp = NULL;
switch_caller_profile_t *cp = switch_channel_get_caller_profile(new_channel);
const char* val = NULL;
cp->soft = NULL;
for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
const char *pvar = switch_xml_attr(x_param, "name");
const char *val = switch_xml_attr(x_param, "value");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_DEBUG1, "setting profile var %s = %s\n", pvar, val);
switch_channel_set_profile_var(new_channel, pvar, val);
//switch_caller_profile_set_var(cp, pvar, val);
}
cp = switch_channel_get_caller_profile(new_channel);
// * TODO * verify onnet/offnet
if((val=switch_caller_get_field_by_name(cp, "Endpoint-Caller-ID-Name"))) {
cp->callee_id_name = val;
cp->orig_caller_id_name = val;
@ -466,7 +485,15 @@ static switch_call_cause_t kz_endpoint_outgoing_channel(switch_core_session_t *s
}
/* kazoo endpoint */
switch_io_routines_t kz_endpoint_io_routines = {
/*.outgoing_channel */ kz_endpoint_outgoing_channel
};
void add_kz_endpoints(switch_loadable_module_interface_t **module_interface) {
switch_endpoint_interface_t *kz_endpoint_interface;
kz_endpoint_interface = (switch_endpoint_interface_t *) switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
kz_endpoint_interface->interface_name = "kz";
kz_endpoint_interface->io_routines = &kz_endpoint_io_routines;

View File

@ -147,6 +147,14 @@ static switch_xml_t fetch_handler(const char *section, const char *tag_name, con
return xml;
}
/* no profile, no work required */
if (!profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "weird case where client is available but there's no profile for %s. try reloading mod_kazoo.\n"
,section);
switch_thread_rwlock_unlock(agent->lock);
return xml;
}
if(event == NULL) {
if (switch_event_create(&event, SWITCH_EVENT_GENERAL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error creating event for fetch handler\n");