From 5bdf8bcc1609830c920d91536ead73c0db3193ea Mon Sep 17 00:00:00 2001 From: Mathieu Parent Date: Fri, 21 May 2010 01:12:05 +0200 Subject: [PATCH] Skinny: More channel variables --- .../endpoints/mod_skinny/skinny_protocol.c | 8 -- .../endpoints/mod_skinny/skinny_protocol.h | 1 - src/mod/endpoints/mod_skinny/skinny_server.c | 78 ++++++++++++++++++- src/mod/endpoints/mod_skinny/skinny_server.h | 1 + 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/mod/endpoints/mod_skinny/skinny_protocol.c b/src/mod/endpoints/mod_skinny/skinny_protocol.c index aefbf7e31a..906083ba30 100644 --- a/src/mod/endpoints/mod_skinny/skinny_protocol.c +++ b/src/mod/endpoints/mod_skinny/skinny_protocol.c @@ -242,14 +242,6 @@ switch_status_t skinny_device_event(listener_t *listener, switch_event_t **ev, s return SWITCH_STATUS_SUCCESS; } -switch_status_t skinny_set_channel_variables(switch_channel_t *channel, listener_t *listener, uint32_t line_instance) -{ - switch_channel_set_variable(channel, "skinny_profile_name", listener->profile->name); - switch_channel_set_variable(channel, "skinny_device_name", listener->device_name); - switch_channel_set_variable_printf(channel, "skinny_device_instance", "%d", listener->device_instance); - switch_channel_set_variable_printf(channel, "skinny_line_instance", "%d", line_instance); - return SWITCH_STATUS_SUCCESS; -} /*****************************************************************************/ /*****************************************************************************/ diff --git a/src/mod/endpoints/mod_skinny/skinny_protocol.h b/src/mod/endpoints/mod_skinny/skinny_protocol.h index f9dbab474b..c330ebd017 100644 --- a/src/mod/endpoints/mod_skinny/skinny_protocol.h +++ b/src/mod/endpoints/mod_skinny/skinny_protocol.h @@ -640,7 +640,6 @@ char* skinny_codec2string(enum skinny_codecs skinnycodec); switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req); switch_status_t skinny_device_event(listener_t *listener, switch_event_t **ev, switch_event_types_t event_id, const char *subclass_name); -switch_status_t skinny_set_channel_variables(switch_channel_t *channel, listener_t *listener, uint32_t line_instance); switch_status_t skinny_session_walk_lines(skinny_profile_t *profile, char *channel_uuid, switch_core_db_callback_func_t callback, void *data); diff --git a/src/mod/endpoints/mod_skinny/skinny_server.c b/src/mod/endpoints/mod_skinny/skinny_server.c index 7c3c089e30..f808ab188c 100644 --- a/src/mod/endpoints/mod_skinny/skinny_server.c +++ b/src/mod/endpoints/mod_skinny/skinny_server.c @@ -117,7 +117,6 @@ switch_status_t skinny_create_incoming_session(listener_t *listener, uint32_t *l snprintf(name, sizeof(name), "SKINNY/%s/%s:%d/%d", listener->profile->name, listener->device_name, listener->device_instance, *line_instance_p); switch_channel_set_name(channel, name); - skinny_set_channel_variables(channel, listener, *line_instance_p); if (switch_core_session_thread_launch(nsession) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(nsession), SWITCH_LOG_CRIT, @@ -155,6 +154,7 @@ switch_status_t skinny_create_incoming_session(listener_t *listener, uint32_t *l skinny_execute_sql(listener->profile, sql, listener->profile->sql_mutex); switch_safe_free(sql); } + skinny_session_set_variables(nsession, listener, *line_instance_p); send_set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0, tech_pvt->call_id); send_set_speaker_mode(listener, SKINNY_SPEAKER_ON); @@ -411,11 +411,83 @@ switch_status_t skinny_session_send_call_info_all(switch_core_session_t *session struct skinny_session_send_call_info_all_helper helper = {0}; private_t *tech_pvt = switch_core_session_get_private(session); - helper.tech_pvt = switch_core_session_get_private(session); + helper.tech_pvt = tech_pvt; return skinny_session_walk_lines(tech_pvt->profile, switch_core_session_get_uuid(tech_pvt->session), skinny_session_send_call_info_all_callback, &helper); } +struct skinny_session_set_variables_helper { + private_t *tech_pvt; + switch_channel_t *channel; + uint32_t count; +}; + +int skinny_session_set_variables_callback(void *pArg, int argc, char **argv, char **columnNames) +{ + char *device_name = argv[0]; + uint32_t device_instance = atoi(argv[1]); + uint32_t position = atoi(argv[2]); + uint32_t line_instance = atoi(argv[3]); + char *label = argv[4]; + char *value = argv[5]; + char *caller_name = argv[6]; + /* uint32_t ring_on_idle = atoi(argv[7]); */ + /* uint32_t ring_on_active = atoi(argv[8]); */ + /* uint32_t busy_trigger = atoi(argv[9]); */ + /* char *forward_all = argv[10]; */ + /* char *forward_busy = argv[11]; */ + /* char *forward_noanswer = argv[12]; */ + /* uint32_t noanswer_duration = atoi(argv[13]); */ + /* char *channel_uuid = argv[14]; */ + /* uint32_t call_id = atoi(argv[15]); */ + /* uint32_t call_state = atoi(argv[16]); */ + + struct skinny_session_set_variables_helper *helper = pArg; + char *tmp; + + helper->count++; + switch_channel_set_variable_name_printf(helper->channel, device_name, "skinny_device_name_%d", helper->count); + if ((tmp = switch_mprintf("%d", device_instance))) { + switch_channel_set_variable_name_printf(helper->channel, tmp, "skinny_device_instance_%d", helper->count); + switch_safe_free(tmp); + } + if ((tmp = switch_mprintf("%d", position))) { + switch_channel_set_variable_name_printf(helper->channel, tmp, "skinny_line_position_%d", helper->count); + switch_safe_free(tmp); + } + if ((tmp = switch_mprintf("%d", line_instance))) { + switch_channel_set_variable_name_printf(helper->channel, tmp, "skinny_line_instance_%d", helper->count); + switch_safe_free(tmp); + } + switch_channel_set_variable_name_printf(helper->channel, label, "skinny_line_label_%d", helper->count); + switch_channel_set_variable_name_printf(helper->channel, value, "skinny_line_value_%d", helper->count); + switch_channel_set_variable_name_printf(helper->channel, caller_name, "skinny_line_caller_name_%d", helper->count); + + return 0; +} + +switch_status_t skinny_session_set_variables(switch_core_session_t *session, listener_t *listener, uint32_t line_instance) +{ + switch_status_t status; + struct skinny_session_set_variables_helper helper = {0}; + + helper.tech_pvt = switch_core_session_get_private(session); + helper.channel = switch_core_session_get_channel(session); + helper.count = 0; + + switch_channel_set_variable(helper.channel, "skinny_profile_name", helper.tech_pvt->profile->name); + if (listener) { + switch_channel_set_variable(helper.channel, "skinny_device_name", listener->device_name); + switch_channel_set_variable_printf(helper.channel, "skinny_device_instance", "%d", listener->device_instance); + switch_channel_set_variable_printf(helper.channel, "skinny_line_instance", "%d", line_instance); + } + status = skinny_session_walk_lines(helper.tech_pvt->profile, + switch_core_session_get_uuid(helper.tech_pvt->session), skinny_session_set_variables_callback, &helper); + + switch_channel_set_variable_printf(helper.channel, "skinny_lines_count", "%d", helper.count); + return status; +} + struct skinny_ring_lines_helper { private_t *tech_pvt; switch_core_session_t *remote_session; @@ -501,6 +573,8 @@ switch_call_cause_t skinny_ring_lines(private_t *tech_pvt, switch_core_session_t status = skinny_session_walk_lines(tech_pvt->profile, switch_core_session_get_uuid(tech_pvt->session), skinny_ring_lines_callback, &helper); + skinny_session_set_variables(tech_pvt->session, NULL, 0); + if (status != SWITCH_STATUS_SUCCESS) { return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } else if (helper.lines_count == 0) { diff --git a/src/mod/endpoints/mod_skinny/skinny_server.h b/src/mod/endpoints/mod_skinny/skinny_server.h index f0218da5fe..5d7e8d9a49 100644 --- a/src/mod/endpoints/mod_skinny/skinny_server.h +++ b/src/mod/endpoints/mod_skinny/skinny_server.h @@ -40,6 +40,7 @@ skinny_action_t skinny_session_dest_match_pattern(switch_core_session_t *session switch_status_t skinny_session_process_dest(switch_core_session_t *session, listener_t *listener, uint32_t line_instance, char *dest, char append_dest, uint32_t backspace); switch_status_t skinny_session_send_call_info(switch_core_session_t *session, listener_t *listener, uint32_t line_instance); switch_status_t skinny_session_send_call_info_all(switch_core_session_t *session); +switch_status_t skinny_session_set_variables(switch_core_session_t *session, listener_t *listener, uint32_t line_instance); switch_call_cause_t skinny_ring_lines(private_t *tech_pvt, switch_core_session_t *remote_session); switch_status_t skinny_session_ring_out(switch_core_session_t *session, listener_t *listener, uint32_t line_instance); switch_status_t skinny_session_answer(switch_core_session_t *session, listener_t *listener, uint32_t line_instance);