]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_kazoo] add checks, fixes & defaults
authorlazedo <luis.azedo@factorlusitano.com>
Fri, 6 Mar 2020 13:56:07 +0000 (13:56 +0000)
committerGitHub <noreply@github.com>
Fri, 6 Mar 2020 13:56:07 +0000 (17:56 +0400)
* [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

src/mod/event_handlers/mod_kazoo/kazoo.conf.xml
src/mod/event_handlers/mod_kazoo/kazoo_commands.c
src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c
src/mod/event_handlers/mod_kazoo/kazoo_endpoints.c
src/mod/event_handlers/mod_kazoo/kazoo_fetch_agent.c

index 353db1b0c132df8d120981f084ae65390f081e1b..4422af121baf72b498973c5614f4ee3169ffd283 100644 (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">
                                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"
                <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" />
index bf954d1e6cba527d54b5370ea1722a60f6f49109..bf191127c2fd309ebb9af776e57d62a19e000e16 100644 (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);
index 80457216269622884ac122cc48fdd0539d85021c..4301d1576850d278b08315216f3d22ba484bb164 100644 (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);
index 2e111db3af3e35212ca42babb9cc3d57915c0864..cb2b28cb261f825bc1d511b011ce0558df8856d2 100644 (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;
index 0b9efe45d094a6f7d477b83bfb3ede2b9e2c1be8..5023e393440436428ed8ab6db5b7b680ce1b57aa 100644 (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");