]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Skinny: More channel variables
authorMathieu Parent <math.parent@gmail.com>
Thu, 20 May 2010 23:12:05 +0000 (01:12 +0200)
committerMathieu Parent <math.parent@gmail.com>
Thu, 20 May 2010 23:12:40 +0000 (01:12 +0200)
src/mod/endpoints/mod_skinny/skinny_protocol.c
src/mod/endpoints/mod_skinny/skinny_protocol.h
src/mod/endpoints/mod_skinny/skinny_server.c
src/mod/endpoints/mod_skinny/skinny_server.h

index aefbf7e31a2c0611200d3ffda740709124ed77af..906083ba30d65a50f5609da0d2fafec10733d626 100644 (file)
@@ -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;
-}
 
 /*****************************************************************************/
 /*****************************************************************************/
index f9dbab474be0e99861c3ce3d1b0f5096f27d642d..c330ebd017820ddb400f39a1a3edc651d8c63bdc 100644 (file)
@@ -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);
 
index 7c3c089e30f9751638deae7b28a1895215ed9d48..f808ab188c656fae0ceb7a2588ea6628a8168587 100644 (file)
@@ -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) {
index f0218da5fe85808d8b80312c7b7df439fab3df46..5d7e8d9a490edbf3c632b21784d9741a566c78c1 100644 (file)
@@ -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);