<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16782] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16782">16782</a></dd>
<dt>Author</dt> <dd>sathieu</dd>
<dt>Date</dt> <dd>2010-02-24 06:04:36 -0600 (Wed, 24 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Skinny: M3: Calls management: ingoing call

Following scenario:
- offhook a specific line
- compose 4 digits</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnymod_skinnyc">freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_skinnymod_skinnyc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c (16781 => 16782)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-02-24 12:04:25 UTC (rev 16781)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-02-24 12:04:36 UTC (rev 16782)
</span><span class="lines">@@ -52,6 +52,7 @@
</span><span class="cx">         char *ip;
</span><span class="cx">         unsigned int port;
</span><span class="cx">         char *dialplan;
</span><ins>+        char *context;
</ins><span class="cx">         uint32_t keep_alive;
</span><span class="cx">         char date_format[6];
</span><span class="cx">         /* db */
</span><span class="lines">@@ -143,7 +144,9 @@
</span><span class="cx">         TFLAG_BREAK = (1 &lt;&lt; 8),
</span><span class="cx">         
</span><span class="cx">         TFLAG_READING = (1 &lt;&lt; 9),
</span><del>-        TFLAG_WRITING = (1 &lt;&lt; 10)
</del><ins>+        TFLAG_WRITING = (1 &lt;&lt; 10),
+        
+        TFLAG_WAITING_DEST = (1 &lt;&lt; 11)
</ins><span class="cx"> } TFLAGS;
</span><span class="cx"> 
</span><span class="cx"> typedef enum {
</span><span class="lines">@@ -163,6 +166,7 @@
</span><span class="cx">         uint32_t line;
</span><span class="cx">         uint32_t call_id;
</span><span class="cx">         uint32_t party_id;
</span><ins>+        char dest[10];
</ins><span class="cx">         /* codec */
</span><span class="cx">         char *iananame;        
</span><span class="cx">         switch_codec_t read_codec;
</span><span class="lines">@@ -293,7 +297,7 @@
</span><span class="cx"> /* SoftKeyEventMessage */
</span><span class="cx"> #define SOFT_KEY_EVENT_MESSAGE 0x0026
</span><span class="cx"> struct soft_key_event_message {
</span><del>-        uint32_t soft_key_event;
</del><ins>+        uint32_t event;
</ins><span class="cx">         uint32_t line_instance;
</span><span class="cx">         uint32_t callreference;
</span><span class="cx"> };
</span><span class="lines">@@ -872,6 +876,8 @@
</span><span class="cx">                 return SWITCH_STATUS_FALSE;\
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+static switch_status_t skinny_send_call_info(switch_core_session_t *session);
+
</ins><span class="cx"> static switch_status_t start_tone(listener_t *listener,
</span><span class="cx">         uint32_t tone,
</span><span class="cx">         uint32_t reserved,
</span><span class="lines">@@ -982,6 +988,7 @@
</span><span class="cx">         stream-&gt;write_function(stream, &quot;IP               \t%s\n&quot;, profile-&gt;ip);
</span><span class="cx">         stream-&gt;write_function(stream, &quot;Port             \t%d\n&quot;, profile-&gt;port);
</span><span class="cx">         stream-&gt;write_function(stream, &quot;Dialplan         \t%s\n&quot;, profile-&gt;dialplan);
</span><ins>+        stream-&gt;write_function(stream, &quot;Context          \t%s\n&quot;, profile-&gt;context);
</ins><span class="cx">         stream-&gt;write_function(stream, &quot;Keep-Alive       \t%d\n&quot;, profile-&gt;keep_alive);
</span><span class="cx">         stream-&gt;write_function(stream, &quot;Date-Format      \t%s\n&quot;, profile-&gt;date_format);
</span><span class="cx">         /* db */
</span><span class="lines">@@ -1377,6 +1384,8 @@
</span><span class="cx"> 
</span><span class="cx">         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;%s CHANNEL HANGUP\n&quot;, switch_channel_get_name(channel));
</span><span class="cx"> 
</span><ins>+        listener-&gt;session[tech_pvt-&gt;line] = NULL;
+
</ins><span class="cx">         stop_tone(listener, tech_pvt-&gt;line, tech_pvt-&gt;call_id);
</span><span class="cx">         set_lamp(listener, SKINNY_BUTTON_LINE, tech_pvt-&gt;line, SKINNY_LAMP_OFF);
</span><span class="cx">         clear_prompt_status(listener, tech_pvt-&gt;line, tech_pvt-&gt;call_id);
</span><span class="lines">@@ -1427,7 +1436,6 @@
</span><span class="cx">                 switch_clear_flag_locked(tech_pvt, TFLAG_IO);
</span><span class="cx">                 switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
</span><span class="cx">                 switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
</span><del>-                //switch_thread_cond_sigpnal(tech_pvt-&gt;cond);
</del><span class="cx">                 break;
</span><span class="cx">         case SWITCH_SIG_BREAK:
</span><span class="cx">                 switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
</span><span class="lines">@@ -1704,28 +1712,7 @@
</span><span class="cx">                 SKINNY_KEY_SET_RING_IN, 0xffff);
</span><span class="cx">         display_prompt_status(tech_pvt-&gt;listener, 0, &quot;\200\027tel&quot;, tech_pvt-&gt;line, tech_pvt-&gt;call_id);
</span><span class="cx">         /* displayprinotifiymessage */
</span><del>-        send_call_info(tech_pvt-&gt;listener,
-                &quot;TODO&quot;, /* char calling_party_name[40], */
-                &quot;TODO&quot;, /* char calling_party[24], */
-                &quot;TODO&quot;, /* char called_party_name[40], */
-                &quot;TODO&quot;, /* char called_party[24], */
-                tech_pvt-&gt;line, /* uint32_t line_instance, */
-                tech_pvt-&gt;call_id, /* uint32_t call_id, */
-                SKINNY_OUTBOUND_CALL, /* uint32_t call_type, */
-                &quot;TODO&quot;, /* char original_called_party_name[40], */
-                &quot;TODO&quot;, /* char original_called_party[24], */
-                &quot;TODO&quot;, /* char last_redirecting_party_name[40], */
-                &quot;TODO&quot;, /* char last_redirecting_party[24], */
-                0, /* uint32_t original_called_party_redirect_reason, */
-                0, /* uint32_t last_redirecting_reason, */
-                &quot;TODO&quot;, /* char calling_party_voice_mailbox[24], */
-                &quot;TODO&quot;, /* char called_party_voice_mailbox[24], */
-                &quot;TODO&quot;, /* char original_called_party_voice_mailbox[24], */
-                &quot;TODO&quot;, /* char last_redirecting_voice_mailbox[24], */
-                1, /* uint32_t call_instance, */
-                1, /* uint32_t call_security_status, */
-                0 /* uint32_t party_pi_restriction_bits */
-        );
</del><ins>+        skinny_send_call_info(nsession);
</ins><span class="cx">         set_lamp(tech_pvt-&gt;listener, SKINNY_BUTTON_LINE, tech_pvt-&gt;line, SKINNY_LAMP_BLINK);
</span><span class="cx">         set_ringer(tech_pvt-&gt;listener, SKINNY_RING_OUTSIDE, SKINNY_RING_FOREVER, 0);
</span><span class="cx"> 
</span><span class="lines">@@ -1991,6 +1978,83 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static switch_status_t skinny_send_call_info(switch_core_session_t *session)
+{
+        private_t *tech_pvt;
+        listener_t *listener;
+        
+        tech_pvt = switch_core_session_get_private(session);
+        switch_assert(tech_pvt != NULL);
+        
+        listener = tech_pvt-&gt;listener;
+        switch_assert(listener != NULL);
+
+        send_call_info(tech_pvt-&gt;listener,
+                &quot;TODO&quot;, /* char calling_party_name[40], */
+                &quot;TODO&quot;, /* char calling_party[24], */
+                &quot;TODO&quot;, /* char called_party_name[40], */
+                &quot;TODO&quot;, /* char called_party[24], */
+                tech_pvt-&gt;line, /* uint32_t line_instance, */
+                tech_pvt-&gt;call_id, /* uint32_t call_id, */
+                SKINNY_OUTBOUND_CALL, /* uint32_t call_type, */
+                &quot;TODO&quot;, /* char original_called_party_name[40], */
+                &quot;TODO&quot;, /* char original_called_party[24], */
+                &quot;TODO&quot;, /* char last_redirecting_party_name[40], */
+                &quot;TODO&quot;, /* char last_redirecting_party[24], */
+                0, /* uint32_t original_called_party_redirect_reason, */
+                0, /* uint32_t last_redirecting_reason, */
+                &quot;TODO&quot;, /* char calling_party_voice_mailbox[24], */
+                &quot;TODO&quot;, /* char called_party_voice_mailbox[24], */
+                &quot;TODO&quot;, /* char original_called_party_voice_mailbox[24], */
+                &quot;TODO&quot;, /* char last_redirecting_voice_mailbox[24], */
+                1, /* uint32_t call_instance, */
+                1, /* uint32_t call_security_status, */
+                0 /* uint32_t party_pi_restriction_bits */
+        );
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t skinny_answer(switch_core_session_t *session)
+{
+        private_t *tech_pvt;
+        listener_t *listener;
+        
+        tech_pvt = switch_core_session_get_private(session);
+        switch_assert(tech_pvt != NULL);
+        
+        listener = tech_pvt-&gt;listener;
+        switch_assert(listener != NULL);
+
+        set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0); /* TODO : here ? */
+        stop_tone(listener, tech_pvt-&gt;line, tech_pvt-&gt;call_id);
+        open_receive_channel(listener,
+                tech_pvt-&gt;call_id, /* uint32_t conference_id, */
+                0, /* uint32_t pass_thru_party_id, */
+                20, /* uint32_t packets, */
+                SKINNY_CODEC_ULAW_64K, /* uint32_t payload_capacity, */
+                0, /* uint32_t echo_cancel_type, */
+                0, /* uint32_t g723_bitrate, */
+                0, /* uint32_t conference_id2, */
+                0 /* uint32_t reserved[10] */
+        );
+        send_call_state(listener,
+                SKINNY_CONNECTED,
+                tech_pvt-&gt;line,
+                tech_pvt-&gt;call_id);
+        send_select_soft_keys(listener,
+                tech_pvt-&gt;line,
+                tech_pvt-&gt;call_id,
+                SKINNY_KEY_SET_CONNECTED,
+                0xffff);
+        display_prompt_status(listener,
+                0,
+                &quot;\200\030&quot;,
+                tech_pvt-&gt;line,
+                tech_pvt-&gt;call_id);
+        skinny_send_call_info(session);
+        return SWITCH_STATUS_SUCCESS;
+}
+
</ins><span class="cx"> /* Message helpers */
</span><span class="cx"> static switch_status_t start_tone(listener_t *listener,
</span><span class="cx">         uint32_t tone,
</span><span class="lines">@@ -2615,19 +2679,19 @@
</span><span class="cx">         
</span><span class="cx">         /* fill buttons between previous one and current one */
</span><span class="cx">         for(i = message-&gt;data.button_template.button_count; i+1 &lt; position; i++) {
</span><del>-                message-&gt;data.button_template.btn[i].instance_number = ++helper-&gt;count[0xff];
-                message-&gt;data.button_template.btn[i].button_definition = 0xff; /* None */
</del><ins>+                message-&gt;data.button_template.btn[i].instance_number = ++helper-&gt;count[SKINNY_BUTTON_UNDEFINED];
+                message-&gt;data.button_template.btn[i].button_definition = SKINNY_BUTTON_UNDEFINED;
</ins><span class="cx">                 message-&gt;data.button_template.button_count++;
</span><span class="cx">                 message-&gt;data.button_template.total_button_count++;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         if (!strcasecmp(type, &quot;line&quot;)) {
</span><del>-                message-&gt;data.button_template.btn[i].instance_number = ++helper-&gt;count[0x09];
-                message-&gt;data.button_template.btn[position-1].button_definition = 0x09; /* Line */
</del><ins>+                message-&gt;data.button_template.btn[i].instance_number = ++helper-&gt;count[SKINNY_BUTTON_LINE];
+                message-&gt;data.button_template.btn[position-1].button_definition = SKINNY_BUTTON_LINE;
</ins><span class="cx">         } else if (!strcasecmp(type, &quot;speed-dial&quot;)) {
</span><del>-                message-&gt;data.button_template.btn[i].instance_number = ++helper-&gt;count[0x02];
-                message-&gt;data.button_template.btn[position-1].button_definition = 0x02; /* speeddial */
</del><ins>+                message-&gt;data.button_template.btn[i].instance_number = ++helper-&gt;count[SKINNY_BUTTON_SPEED_DIAL];
+                message-&gt;data.button_template.btn[position-1].button_definition = SKINNY_BUTTON_SPEED_DIAL;
</ins><span class="cx">         } else {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
</span><span class="cx">                         &quot;Unknown button type %s for device %s.\n&quot;, type, device_name);
</span><span class="lines">@@ -2862,6 +2926,90 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static switch_status_t skinny_handle_soft_key_event_message(listener_t *listener, skinny_message_t *request)
+{
+        switch_core_session_t *session;
+        switch_channel_t *channel;
+        private_t *tech_pvt;
+
+        switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+        skinny_profile_t *profile;
+        uint32_t line;
+
+        switch_assert(listener-&gt;profile);
+        switch_assert(listener-&gt;device_name);
+
+        profile = listener-&gt;profile;
+
+        skinny_check_data_length(request, sizeof(request-&gt;data.soft_key_event));
+
+        if(request-&gt;data.soft_key_event.line_instance) {
+                line = request-&gt;data.soft_key_event.line_instance;
+        } else {
+                line = 1;
+        }
+
+        if(!listener-&gt;session[line]) { /*the line is not busy */
+                switch(request-&gt;data.soft_key_event.event) {
+                        case SOFTKEY_NEWCALL:
+
+                                if (!(session = switch_core_session_request(skinny_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, NULL))) {
+                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Error Creating Session\n&quot;);
+                                        goto error;
+                                }
+
+                                if (!(tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(*tech_pvt)))) {
+                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, &quot;Error Creating Session private object\n&quot;);
+                                        goto error;
+                                }
+
+                                switch_core_session_add_stream(session, NULL);
+
+                                tech_pvt-&gt;listener = listener;
+                                tech_pvt-&gt;line = line;
+
+                                tech_init(tech_pvt, session);
+
+                                switch_set_flag_locked(tech_pvt, TFLAG_WAITING_DEST);
+
+                                set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0);
+                                set_speaker_mode(listener, SKINNY_SPEAKER_ON);
+                                set_lamp(listener, SKINNY_BUTTON_LINE, tech_pvt-&gt;line, SKINNY_LAMP_ON);
+                                send_call_state(listener,
+                                        SKINNY_OFF_HOOK,
+                                        tech_pvt-&gt;line,
+                                        tech_pvt-&gt;call_id);
+                                send_select_soft_keys(listener, tech_pvt-&gt;line, tech_pvt-&gt;call_id,
+                                        SKINNY_KEY_SET_OFF_HOOK, 0xffff);
+                                display_prompt_status(listener,
+                                        0,
+                                        &quot;\200\000&quot;,
+                                        tech_pvt-&gt;line,
+                                        tech_pvt-&gt;call_id);
+                                activate_call_plane(listener, tech_pvt-&gt;line);
+                                start_tone(listener, SKINNY_TONE_DIALTONE, 0, tech_pvt-&gt;line, tech_pvt-&gt;call_id);
+
+                                channel = switch_core_session_get_channel(session);
+
+                                listener-&gt;session[line] = session;
+
+                                break;
+                        default:
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
+                                        &quot;Unknown SoftKeyEvent type: %d.\n&quot;, request-&gt;data.soft_key_event.event);
+                }
+        }
+        goto done;
+error:
+        if (session) {
+                switch_core_session_destroy(&amp;session);
+        }
+
+done:
+        return status;
+}
+
</ins><span class="cx"> static switch_status_t skinny_handle_off_hook_message(listener_t *listener, skinny_message_t *request)
</span><span class="cx"> {
</span><span class="cx">         skinny_profile_t *profile;
</span><span class="lines">@@ -2880,34 +3028,7 @@
</span><span class="cx">                 line = 1;
</span><span class="cx">         }
</span><span class="cx">         if(listener-&gt;session[line]) { /*answering a call */
</span><del>-                private_t *tech_pvt = NULL;
-                tech_pvt = switch_core_session_get_private(listener-&gt;session[line]);
-                set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0); /* TODO : here ? */
-                stop_tone(listener, tech_pvt-&gt;line, tech_pvt-&gt;call_id);
-                open_receive_channel(listener,
-                        tech_pvt-&gt;call_id, /* uint32_t conference_id, */
-                        0, /* uint32_t pass_thru_party_id, */
-                        20, /* uint32_t packets, */
-                        SKINNY_CODEC_ULAW_64K, /* uint32_t payload_capacity, */
-                        0, /* uint32_t echo_cancel_type, */
-                        0, /* uint32_t g723_bitrate, */
-                        0, /* uint32_t conference_id2, */
-                        0 /* uint32_t reserved[10] */
-                );
-                send_call_state(listener,
-                        SKINNY_CONNECTED,
-                        tech_pvt-&gt;line,
-                        tech_pvt-&gt;call_id);
-                send_select_soft_keys(listener,
-                        tech_pvt-&gt;line,
-                        tech_pvt-&gt;call_id,
-                        SKINNY_KEY_SET_CONNECTED,
-                        0xffff);
-                display_prompt_status(listener,
-                        0,
-                        &quot;\200\030&quot;,
-                        1,
-                        tech_pvt-&gt;call_id);
</del><ins>+                skinny_answer(listener-&gt;session[line]);
</ins><span class="cx">         }
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="lines">@@ -3007,7 +3128,7 @@
</span><span class="cx"> 
</span><span class="cx"> static switch_status_t skinny_handle_keypad_button_message(listener_t *listener, skinny_message_t *request)
</span><span class="cx"> {
</span><del>-        uint32_t line;
</del><ins>+        uint32_t line = 0;
</ins><span class="cx"> 
</span><span class="cx">         skinny_check_data_length(request, sizeof(request-&gt;data.keypad_button));
</span><span class="cx"> 
</span><span class="lines">@@ -3025,7 +3146,7 @@
</span><span class="cx">         if(listener-&gt;session[line]) {
</span><span class="cx">                 switch_channel_t *channel = NULL;
</span><span class="cx">                 private_t *tech_pvt = NULL;
</span><del>-                switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0)};
</del><ins>+                char digit = '\0';
</ins><span class="cx"> 
</span><span class="cx">                 channel = switch_core_session_get_channel(listener-&gt;session[line]);
</span><span class="cx">                 assert(channel != NULL);
</span><span class="lines">@@ -3033,22 +3154,77 @@
</span><span class="cx">                 tech_pvt = switch_core_session_get_private(listener-&gt;session[line]);
</span><span class="cx">                 assert(tech_pvt != NULL);
</span><span class="cx">                 
</span><del>-                /* TODO check call_id and line */
-
</del><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener-&gt;session[line]), SWITCH_LOG_DEBUG, &quot;SEND DTMF ON CALL %d [%d]\n&quot;, tech_pvt-&gt;call_id, request-&gt;data.keypad_button.button);
</span><span class="cx"> 
</span><span class="cx">                 if (request-&gt;data.keypad_button.button == 14) {
</span><del>-                        dtmf.digit = '*';
-                        switch_channel_queue_dtmf(channel, &amp;dtmf);
</del><ins>+                        digit = '*';
</ins><span class="cx">                 } else if (request-&gt;data.keypad_button.button == 15) {
</span><del>-                        dtmf.digit = '#';
-                        switch_channel_queue_dtmf(channel, &amp;dtmf);
</del><ins>+                        digit = '#';
</ins><span class="cx">                 } else if (request-&gt;data.keypad_button.button &gt;= 0 &amp;&amp; request-&gt;data.keypad_button.button &lt;= 9) {
</span><del>-                        dtmf.digit = '0' + request-&gt;data.keypad_button.button;
-                        switch_channel_queue_dtmf(channel, &amp;dtmf);
</del><ins>+                        digit = '0' + request-&gt;data.keypad_button.button;
</ins><span class="cx">                 } else {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener-&gt;session[line]), SWITCH_LOG_WARNING, &quot;UNKNOW DTMF RECEIVED ON CALL %d [%d]\n&quot;, tech_pvt-&gt;call_id, request-&gt;data.keypad_button.button);
</span><span class="cx">                 }
</span><ins>+
+                /* TODO check call_id and line */
+
+                if(switch_test_flag(tech_pvt, TFLAG_WAITING_DEST)) {
+                        char name[128];
+                        switch_channel_t *channel;
+                        char *cid_name = &quot;TODO-soft_key_event&quot;; /* TODO */
+                        char *cid_num = &quot;00000&quot;; /* TODO */
+                        if(strlen(tech_pvt-&gt;dest) == 0) {/* first digit */
+                                stop_tone(listener, tech_pvt-&gt;line, tech_pvt-&gt;call_id);
+                                send_select_soft_keys(listener, tech_pvt-&gt;line, tech_pvt-&gt;call_id,
+                                        SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT, 0xffff);
+                        }
+                        
+                        tech_pvt-&gt;dest[strlen(tech_pvt-&gt;dest)] = digit;
+                        
+                        if(strlen(tech_pvt-&gt;dest) &gt;= 4) { /* TODO Number is complete */
+                                switch_clear_flag_locked(tech_pvt, TFLAG_WAITING_DEST);
+                                if (!(tech_pvt-&gt;caller_profile = switch_caller_profile_new(switch_core_session_get_pool(listener-&gt;session[line]),
+                                                                                                                                                  NULL, listener-&gt;profile-&gt;dialplan, cid_name, cid_num, listener-&gt;remote_ip, NULL, NULL, NULL, modname, listener-&gt;profile-&gt;context, tech_pvt-&gt;dest)) != 0) {
+                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener-&gt;session[line]), SWITCH_LOG_CRIT, &quot;Error Creating Session caller profile\n&quot;);
+                                        goto error;
+                                }
+
+                                channel = switch_core_session_get_channel(listener-&gt;session[line]);
+                                snprintf(name, sizeof(name), &quot;SKINNY/%s/%s/%d&quot;, listener-&gt;profile-&gt;name, listener-&gt;device_name, line);
+                                switch_channel_set_name(channel, name);
+
+                                switch_channel_set_caller_profile(channel, tech_pvt-&gt;caller_profile);
+
+                                if (switch_channel_get_state(channel) == CS_NEW) {
+                                        switch_channel_set_state(channel, CS_INIT);
+                                }
+
+                                if (switch_core_session_thread_launch(listener-&gt;session[line]) != SWITCH_STATUS_SUCCESS) {
+                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener-&gt;session[line]), SWITCH_LOG_CRIT, &quot;Error Creating Session thread\n&quot;);
+                                        goto error;
+                                }
+
+                                send_select_soft_keys(listener,
+                                        tech_pvt-&gt;line,
+                                        tech_pvt-&gt;call_id,
+                                        SKINNY_KEY_SET_CONNECTED,
+                                        0xffff);
+                                send_dialed_number(listener, tech_pvt-&gt;dest, tech_pvt-&gt;line, tech_pvt-&gt;call_id);
+                                skinny_answer(listener-&gt;session[line]);
+
+                                goto done;
+error:
+                        return SWITCH_STATUS_FALSE;
+done:
+                        return SWITCH_STATUS_SUCCESS;
+                        }
+                } else {
+                        if(digit != '\0') {
+                                switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0)};
+                                dtmf.digit = digit;
+                                switch_channel_queue_dtmf(channel, &amp;dtmf);
+                        }
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="lines">@@ -3058,7 +3234,7 @@
</span><span class="cx"> {
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_SUCCESS;
</span><span class="cx">         skinny_profile_t *profile;
</span><del>-        uint32_t line;
</del><ins>+        uint32_t line = 0;
</ins><span class="cx"> 
</span><span class="cx">         switch_assert(listener-&gt;profile);
</span><span class="cx">         switch_assert(listener-&gt;device_name);
</span><span class="lines">@@ -3145,6 +3321,8 @@
</span><span class="cx">                 /* live phase */
</span><span class="cx">                 case KEEP_ALIVE_MESSAGE:
</span><span class="cx">                         return skinny_handle_keep_alive_message(listener, request);
</span><ins>+                case SOFT_KEY_EVENT_MESSAGE:
+                        return skinny_handle_soft_key_event_message(listener, request);
</ins><span class="cx">                 case OFF_HOOK_MESSAGE:
</span><span class="cx">                         return skinny_handle_off_hook_message(listener, request);
</span><span class="cx">                 case OPEN_RECEIVE_CHANNEL_ACK_MESSAGE:
</span><span class="lines">@@ -3156,11 +3334,6 @@
</span><span class="cx">                 /* end phase */
</span><span class="cx">                 case UNREGISTER_MESSAGE:
</span><span class="cx">                         return skinny_handle_unregister(listener, request);
</span><del>-                case 0xABCDEF: /* the following commands are to avoid compile warnings (which are errors) */
-activate_call_plane(listener, 1 /* line */);
-send_dialed_number(listener, 0 /* called_party */, 1 /* line */, 0 /* call_id */);
-start_tone(listener, SKINNY_TONE_DIALTONE, 0, 0, 0);
-
</del><span class="cx">                 default:
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
</span><span class="cx">                                 &quot;Unknown request type: %x (length=%d).\n&quot;, request-&gt;type, request-&gt;length);
</span><span class="lines">@@ -3559,6 +3732,8 @@
</span><span class="cx">                 profile-&gt;ip = switch_core_strdup(module_pool, val);
</span><span class="cx">         } else if (!strcasecmp(var, &quot;dialplan&quot;)) {
</span><span class="cx">                 profile-&gt;dialplan = switch_core_strdup(module_pool, val);
</span><ins>+        } else if (!strcasecmp(var, &quot;context&quot;)) {
+                profile-&gt;context = switch_core_strdup(module_pool, val);
</ins><span class="cx">         } else if (!strcasecmp(var, &quot;odbc-dsn&quot;) &amp;&amp; !zstr(val)) {
</span><span class="cx">                 if (switch_odbc_available()) {
</span><span class="cx">                         profile-&gt;odbc_dsn = switch_core_strdup(module_pool, val);
</span><span class="lines">@@ -3642,6 +3817,8 @@
</span><span class="cx">                                                 profile-&gt;port = atoi(val);
</span><span class="cx">                                         } else if (!strcmp(var, &quot;dialplan&quot;)) {
</span><span class="cx">                                                 skinny_profile_set(profile, &quot;dialplan&quot;, val);
</span><ins>+                                        } else if (!strcmp(var, &quot;context&quot;)) {
+                                                skinny_profile_set(profile, &quot;context&quot;, val);
</ins><span class="cx">                                         } else if (!strcmp(var, &quot;keep-alive&quot;)) {
</span><span class="cx">                                                 profile-&gt;keep_alive = atoi(val);
</span><span class="cx">                                         } else if (!strcmp(var, &quot;date-format&quot;)) {
</span><span class="lines">@@ -3653,6 +3830,10 @@
</span><span class="cx">                                         skinny_profile_set(profile, &quot;dialplan&quot;,&quot;default&quot;);
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><ins>+                                if (!profile-&gt;context) {
+                                        skinny_profile_set(profile, &quot;context&quot;,&quot;public&quot;);
+                                }
+
</ins><span class="cx">                                 if (!profile-&gt;port) {
</span><span class="cx">                                         profile-&gt;port = 2000;
</span><span class="cx">                                 }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>