提交 fdd2acfb authored 作者: lazedo's avatar lazedo

FS-11791 [mod_kazoo] fixes & improvements

* tweak configuration
* customized att_xfer
* json_api with uuid support
上级 8df9ac43
...@@ -112,11 +112,13 @@ ...@@ -112,11 +112,13 @@
<filter name="variable_sip_refer_to" type="include" compare="exists" /> <filter name="variable_sip_refer_to" type="include" compare="exists" />
</filters> </filters>
</field> </field>
<field name="Referred-By" type="expand" value="sip:${regex(${variable_sip_h_Referred-By}|&lt;sips?:(.*)&gt;|%1)}"> <field name="variable_sip_h_Referred-By" as="Referred-By"/>
<!-- <field name="Referred-By" type="expand" value="sip:${regex(${variable_sip_h_Referred-By}|&lt;sips?:(.*)&gt;|%1)}">
<filters> <filters>
<filter name="variable_sip_h_Referred-By" type="include" compare="exists" /> <filter name="variable_sip_h_Referred-By" type="include" compare="exists" />
</filters> </filters>
</field> </field>
-->
<!-- <field name="variable_Call-Interaction-ID" as="Call-Interaction-ID" /> --> <!-- <field name="variable_Call-Interaction-ID" as="Call-Interaction-ID" /> -->
<field name="interaction-id" type="reference" /> <field name="interaction-id" type="reference" />
...@@ -882,6 +884,7 @@ ...@@ -882,6 +884,7 @@
name="variable_Call-Control-Queue" /> name="variable_Call-Control-Queue" />
<filter type="include" compare="exists" <filter type="include" compare="exists"
name="Application-UUID-Name" /> name="Application-UUID-Name" />
<filter type="exclude" name="Application-UUID-Name" value="set" />
<filter type="exclude" name="Application" value="set" /> <filter type="exclude" name="Application" value="set" />
<filter name="Application" value="park" /> <filter name="Application" value="park" />
<filter name="Application" value="export" /> <filter name="Application" value="export" />
...@@ -903,7 +906,7 @@ ...@@ -903,7 +906,7 @@
value="Application-Response|variable_originate_disposition|variable_endpoint_disposition|#NONE" /> value="Application-Response|variable_originate_disposition|variable_endpoint_disposition|#NONE" />
<field name="Disposition" type="first-of" <field name="Disposition" type="first-of"
value="variable_originate_disposition|variable_endpoint_disposition" /> value="variable_originate_disposition|variable_endpoint_disposition" />
<field name="Bridge-Hangup-Cause" type="first-of" value="variable_last_bridge_hangup_cause|variable_bridge_hangup_cause" /> <field name="Bridge-Hangup-Cause" type="first-of" value="variable_bridge_hangup_cause|variable_last_bridge_hangup_cause" />
<field name="debug-call" type="reference" /> <field name="debug-call" type="reference" />
</fields> </fields>
...@@ -1033,6 +1036,8 @@ ...@@ -1033,6 +1036,8 @@
<field name="Resigning-Peer-UUID"/> <field name="Resigning-Peer-UUID"/>
<field name="Acquired-UUID"/> <field name="Acquired-UUID"/>
<field name="Acquired-UUID" as="Replaced-By"/> <field name="Acquired-UUID" as="Replaced-By"/>
<field name="Connecting-Leg-A-UUID" />
<field name="Connecting-Leg-B-UUID" />
</fields> </fields>
</event> </event>
...@@ -1071,6 +1076,15 @@ ...@@ -1071,6 +1076,15 @@
</fields> </fields>
</event> </event>
<event name="CHANNEL_METAFLOW">
<fields verbose="false">
<field name="call_event" type="reference" />
<field name="from-to" type="reference" />
<field name="user-agent" type="reference" />
<field name="Metaflow-Collected-Digits"/>
</fields>
</event>
</events> </events>
</profile> </profile>
</event-handlers> </event-handlers>
......
...@@ -139,6 +139,24 @@ struct ei_xml_agent_s { ...@@ -139,6 +139,24 @@ struct ei_xml_agent_s {
}; };
typedef enum {
KZ_TWEAK_INTERACTION_ID,
KZ_TWEAK_EXPORT_VARS,
KZ_TWEAK_SWITCH_URI,
KZ_TWEAK_REPLACES_CALL_ID,
KZ_TWEAK_LOOPBACK_VARS,
KZ_TWEAK_CALLER_ID,
KZ_TWEAK_TRANSFERS,
KZ_TWEAK_BRIDGE,
KZ_TWEAK_BRIDGE_REPLACES_ALEG,
KZ_TWEAK_BRIDGE_REPLACES_CALL_ID,
KZ_TWEAK_BRIDGE_VARIABLES,
KZ_TWEAK_RESTORE_CALLER_ID_ON_BLIND_XFER,
/* No new flags below this line */
KZ_TWEAK_MAX
} kz_tweak_t;
struct globals_s { struct globals_s {
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
switch_atomic_t threads; switch_atomic_t threads;
...@@ -164,8 +182,6 @@ struct globals_s { ...@@ -164,8 +182,6 @@ struct globals_s {
char *hostname; char *hostname;
char *ei_cookie; char *ei_cookie;
char *ei_nodename; char *ei_nodename;
// char *kazoo_var_prefix;
// int var_prefix_length;
uint32_t flags; uint32_t flags;
int send_all_headers; int send_all_headers;
int send_all_private_headers; int send_all_private_headers;
...@@ -184,11 +200,13 @@ struct globals_s { ...@@ -184,11 +200,13 @@ struct globals_s {
kazoo_config_ptr fetch_handlers; kazoo_config_ptr fetch_handlers;
kazoo_json_term json_encoding; kazoo_json_term json_encoding;
int enable_legacy;
char **profile_vars_prefixes; char **profile_vars_prefixes;
char **kazoo_var_prefixes; char **kazoo_var_prefixes;
int tweaks_restore_caller_id; int legacy_events;
uint8_t tweaks[KZ_TWEAK_MAX];
}; };
typedef struct globals_s globals_t; typedef struct globals_s globals_t;
extern globals_t kazoo_globals; extern globals_t kazoo_globals;
...@@ -254,6 +272,12 @@ switch_status_t kazoo_config_handlers(switch_xml_t cfg); ...@@ -254,6 +272,12 @@ switch_status_t kazoo_config_handlers(switch_xml_t cfg);
/* runtime */ /* runtime */
SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime); SWITCH_MODULE_RUNTIME_FUNCTION(mod_kazoo_runtime);
#define kz_test_tweak(flag) (kazoo_globals.tweaks[flag] ? 1 : 0)
#define kz_set_tweak(flag) kazoo_globals.tweaks[flag] = 1
#define kz_clear_tweak(flag) kazoo_globals.tweaks[flag] = 0
#endif /* KAZOO_EI_H */ #endif /* KAZOO_EI_H */
/* For Emacs: /* For Emacs:
......
...@@ -113,8 +113,22 @@ switch_status_t kazoo_ei_config(switch_xml_t cfg) { ...@@ -113,8 +113,22 @@ switch_status_t kazoo_ei_config(switch_xml_t cfg) {
kazoo_globals.port = 0; kazoo_globals.port = 0;
kazoo_globals.io_fault_tolerance = 10; kazoo_globals.io_fault_tolerance = 10;
kazoo_globals.json_encoding = ERLANG_TUPLE; kazoo_globals.json_encoding = ERLANG_TUPLE;
kazoo_globals.enable_legacy = SWITCH_FALSE;
kazoo_globals.tweaks_restore_caller_id = SWITCH_TRUE; kazoo_globals.legacy_events = SWITCH_FALSE;
kz_set_tweak(KZ_TWEAK_INTERACTION_ID);
kz_set_tweak(KZ_TWEAK_EXPORT_VARS);
kz_set_tweak(KZ_TWEAK_SWITCH_URI);
kz_set_tweak(KZ_TWEAK_REPLACES_CALL_ID);
kz_set_tweak(KZ_TWEAK_LOOPBACK_VARS);
kz_set_tweak(KZ_TWEAK_CALLER_ID);
kz_set_tweak(KZ_TWEAK_TRANSFERS);
kz_set_tweak(KZ_TWEAK_BRIDGE);
kz_set_tweak(KZ_TWEAK_BRIDGE_REPLACES_ALEG);
kz_set_tweak(KZ_TWEAK_BRIDGE_REPLACES_CALL_ID);
kz_set_tweak(KZ_TWEAK_BRIDGE_VARIABLES);
kz_set_tweak(KZ_TWEAK_RESTORE_CALLER_ID_ON_BLIND_XFER);
if ((child = switch_xml_child(cfg, "settings"))) { if ((child = switch_xml_child(cfg, "settings"))) {
...@@ -186,12 +200,24 @@ switch_status_t kazoo_ei_config(switch_xml_t cfg) { ...@@ -186,12 +200,24 @@ switch_status_t kazoo_ei_config(switch_xml_t cfg) {
if(!strcmp(val, "map")) { if(!strcmp(val, "map")) {
kazoo_globals.json_encoding = ERLANG_MAP; kazoo_globals.json_encoding = ERLANG_MAP;
} }
} else if (!strcmp(var, "enable-legacy")) { } else if (!strcmp(var, "legacy-events")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set enable-legacy: %s\n", val); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set legacy-events: %s\n", val);
kazoo_globals.enable_legacy = switch_true(val); kazoo_globals.legacy_events = switch_true(val);
} else if (!strcmp(var, "tweaks-restore-caller-id")) { }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Set tweaks-restore-caller-id: %s\n", val); }
kazoo_globals.tweaks_restore_caller_id = switch_true(val); }
if ((child = switch_xml_child(cfg, "tweaks"))) {
for (param = switch_xml_child(child, "tweak"); param; param = param->next) {
kz_tweak_t tweak = KZ_TWEAK_MAX;
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if(var && val && kz_name_tweak(var, &tweak) == SWITCH_STATUS_SUCCESS) {
if(switch_true(val)) {
kz_set_tweak(tweak);
} else {
kz_clear_tweak(tweak);
}
} }
} }
} }
......
...@@ -201,6 +201,8 @@ static void event_handler(switch_event_t *event) { ...@@ -201,6 +201,8 @@ static void event_handler(switch_event_t *event) {
ei_x_encode_version(ebuf); ei_x_encode_version(ebuf);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Target-Node", event_binding->stream->node->peer_nodename);
if(event_stream->node->legacy) { if(event_stream->node->legacy) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Switch-Nodename", kazoo_globals.ei_cnode.thisnodename); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Switch-Nodename", kazoo_globals.ei_cnode.thisnodename);
res = encode_event_old(event, ebuf); res = encode_event_old(event, ebuf);
......
...@@ -64,7 +64,8 @@ static char *REQUEST_ATOMS[] = { ...@@ -64,7 +64,8 @@ static char *REQUEST_ATOMS[] = {
"fetch_reply", "fetch_reply",
"config", "config",
"bgapi4", "bgapi4",
"api4" "api4",
"json_api"
}; };
typedef enum { typedef enum {
...@@ -86,6 +87,7 @@ typedef enum { ...@@ -86,6 +87,7 @@ typedef enum {
REQUEST_CONFIG, REQUEST_CONFIG,
REQUEST_BGAPI4, REQUEST_BGAPI4,
REQUEST_API4, REQUEST_API4,
REQUEST_JSON_API,
REQUEST_MAX REQUEST_MAX
} request_atoms_t; } request_atoms_t;
...@@ -925,10 +927,10 @@ static switch_status_t handle_request_api4(ei_node_t *ei_node, erlang_pid *pid, ...@@ -925,10 +927,10 @@ static switch_status_t handle_request_api4(ei_node_t *ei_node, erlang_pid *pid,
status = api_exec_stream(cmd, arg, &stream, &reply); status = api_exec_stream(cmd, arg, &stream, &reply);
if (status == SWITCH_STATUS_SUCCESS) { if (status == SWITCH_STATUS_SUCCESS) {
ei_x_encode_tuple_header(buf, 2); ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "ok"); ei_x_encode_atom(rbuf, "ok");
} else { } else {
ei_x_encode_tuple_header(buf, (stream.param_event ? 3 : 2)); ei_x_encode_tuple_header(rbuf, (stream.param_event ? 3 : 2));
ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "error");
} }
...@@ -951,6 +953,61 @@ static switch_status_t handle_request_api4(ei_node_t *ei_node, erlang_pid *pid, ...@@ -951,6 +953,61 @@ static switch_status_t handle_request_api4(ei_node_t *ei_node, erlang_pid *pid,
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status_t handle_request_json_api(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf)
{
char *arg;
cJSON *jcmd = NULL;
switch_core_session_t *session = NULL;
const char *uuid = NULL;
char *response = NULL;
const char *parse_end = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (ei_decode_string_or_binary(buf->buff, &buf->index, &arg)) {
return erlang_response_badarg(rbuf);
}
jcmd = cJSON_ParseWithOpts(arg, &parse_end, 0);
if (!jcmd) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "json api error: %s\n", parse_end);
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "parse_error");
_ei_x_encode_string(rbuf, parse_end);
return status;
}
if ((uuid = cJSON_GetObjectCstr(jcmd, "uuid"))) {
if (!(session = switch_core_session_locate(uuid))) {
return erlang_response_baduuid(rbuf);
}
}
status = switch_json_api_execute(jcmd, session, NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "json api (%i): %s\n", status , arg);
response = cJSON_PrintUnformatted(jcmd);
ei_x_encode_tuple_header(rbuf, 2);
if (status == SWITCH_STATUS_SUCCESS) {
ei_x_encode_atom(rbuf, "ok");
} else {
ei_x_encode_atom(rbuf, "error");
}
_ei_x_encode_string(rbuf, response);
switch_safe_free(response);
cJSON_Delete(jcmd);
switch_safe_free(arg);
if (session) {
switch_core_session_rwunlock(session);
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t handle_request_api(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) { static switch_status_t handle_request_api(ei_node_t *ei_node, erlang_pid *pid, ei_x_buff *buf, ei_x_buff *rbuf) {
char cmd[MAXATOMLEN + 1]; char cmd[MAXATOMLEN + 1];
char *arg; char *arg;
...@@ -963,7 +1020,7 @@ static switch_status_t handle_request_api(ei_node_t *ei_node, erlang_pid *pid, e ...@@ -963,7 +1020,7 @@ static switch_status_t handle_request_api(ei_node_t *ei_node, erlang_pid *pid, e
return erlang_response_badarg(rbuf); return erlang_response_badarg(rbuf);
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "exec: %s(%s)\n", cmd, arg); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "exec: %s(%s)\n", cmd, arg);
if (rbuf) { if (rbuf) {
char *reply; char *reply;
...@@ -1100,12 +1157,12 @@ static switch_status_t handle_kazoo_request(ei_node_t *ei_node, erlang_pid *pid, ...@@ -1100,12 +1157,12 @@ static switch_status_t handle_kazoo_request(ei_node_t *ei_node, erlang_pid *pid,
} }
if (ei_decode_atom_safe(buf->buff, &buf->index, atom)) { if (ei_decode_atom_safe(buf->buff, &buf->index, atom)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Recieved mod_kazoo message that did not contain a command (ensure you are using Kazoo v2.14+).\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received mod_kazoo message that did not contain a command (ensure you are using Kazoo v2.14+).\n");
return erlang_response_badarg(rbuf); return erlang_response_badarg(rbuf);
} }
if (find_request(atom, &request) != SWITCH_STATUS_SUCCESS) { if (find_request(atom, &request) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Recieved mod_kazoo message for unimplemented feature (ensure you are using Kazoo v2.14+): %s\n", atom); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received mod_kazoo message for unimplemented feature (ensure you are using Kazoo v2.14+): %s\n", atom);
return erlang_response_badarg(rbuf); return erlang_response_badarg(rbuf);
} }
...@@ -1146,6 +1203,8 @@ static switch_status_t handle_kazoo_request(ei_node_t *ei_node, erlang_pid *pid, ...@@ -1146,6 +1203,8 @@ static switch_status_t handle_kazoo_request(ei_node_t *ei_node, erlang_pid *pid,
return handle_request_bgapi4(ei_node, pid, buf, rbuf); return handle_request_bgapi4(ei_node, pid, buf, rbuf);
case REQUEST_API4: case REQUEST_API4:
return handle_request_api4(ei_node, pid, buf, rbuf); return handle_request_api4(ei_node, pid, buf, rbuf);
case REQUEST_JSON_API:
return handle_request_json_api(ei_node, pid, buf, rbuf);
default: default:
return erlang_response_notimplemented(rbuf); return erlang_response_notimplemented(rbuf);
} }
...@@ -1168,7 +1227,7 @@ static switch_status_t handle_mod_kazoo_request(ei_node_t *ei_node, erlang_msg * ...@@ -1168,7 +1227,7 @@ static switch_status_t handle_mod_kazoo_request(ei_node_t *ei_node, erlang_msg *
ei_decode_tuple_header(buf->buff, &buf->index, &arity); ei_decode_tuple_header(buf->buff, &buf->index, &arity);
if (ei_decode_atom_safe(buf->buff, &buf->index, atom)) { if (ei_decode_atom_safe(buf->buff, &buf->index, atom)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Recieved erlang message tuple that did not start with an atom (ensure you are using Kazoo v2.14+).\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received erlang message tuple that did not start with an atom (ensure you are using Kazoo v2.14+).\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
...@@ -1224,7 +1283,7 @@ static switch_status_t handle_mod_kazoo_request(ei_node_t *ei_node, erlang_msg * ...@@ -1224,7 +1283,7 @@ static switch_status_t handle_mod_kazoo_request(ei_node_t *ei_node, erlang_msg *
return status; return status;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Recieved inappropriate erlang message (ensure you are using Kazoo v2.14+)\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received inappropriate erlang message (ensure you are using Kazoo v2.14+)\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
} }
...@@ -1547,7 +1606,7 @@ switch_status_t new_kazoo_node(int nodefd, ErlConnect *conn) { ...@@ -1547,7 +1606,7 @@ switch_status_t new_kazoo_node(int nodefd, ErlConnect *conn) {
ei_node->nodefd = nodefd; ei_node->nodefd = nodefd;
ei_node->peer_nodename = switch_core_strdup(ei_node->pool, conn->nodename); ei_node->peer_nodename = switch_core_strdup(ei_node->pool, conn->nodename);
ei_node->created_time = switch_micro_time_now(); ei_node->created_time = switch_micro_time_now();
ei_node->legacy = kazoo_globals.enable_legacy; ei_node->legacy = kazoo_globals.legacy_events;
ei_node->event_stream_framing = kazoo_globals.event_stream_framing; ei_node->event_stream_framing = kazoo_globals.event_stream_framing;
/* store the IP and node name we are talking with */ /* store the IP and node name we are talking with */
......
...@@ -57,6 +57,8 @@ void add_kz_endpoints(switch_loadable_module_interface_t **module_interface); ...@@ -57,6 +57,8 @@ void add_kz_endpoints(switch_loadable_module_interface_t **module_interface);
/* kazoo_tweaks.c */ /* kazoo_tweaks.c */
void kz_tweaks_start(); void kz_tweaks_start();
void kz_tweaks_stop(); void kz_tweaks_stop();
SWITCH_DECLARE(const char *) kz_tweak_name(kz_tweak_t tweak);
SWITCH_DECLARE(switch_status_t) kz_name_tweak(const char *name, kz_tweak_t *type);
/* kazoo_node.c */ /* kazoo_node.c */
void add_kz_node(switch_loadable_module_interface_t **module_interface); void add_kz_node(switch_loadable_module_interface_t **module_interface);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论