<!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][16959] </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=16959">16959</a></dd>
<dt>Author</dt> <dd>sathieu</dd>
<dt>Date</dt> <dd>2010-03-10 07:49:53 -0600 (Wed, 10 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Skinny:
- allow several instances of the same device on different sockets
- move lines to table skinny_lines, as they need more params
- various small changes</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnymod_skinnyc">freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnymod_skinnyh">freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnyskinny_protocolc">freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnyskinny_protocolh">freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.h</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 (16958 => 16959)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-03-09 21:30:54 UTC (rev 16958)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-03-10 13:49:53 UTC (rev 16959)
</span><span class="lines">@@ -49,23 +49,41 @@
</span><span class="cx"> /*****************************************************************************/
</span><span class="cx"> static char devices_sql[] =
</span><span class="cx">         &quot;CREATE TABLE skinny_devices (\n&quot;
</span><del>-        &quot;   name           VARCHAR(16),\n&quot;
</del><ins>+        &quot;   name             VARCHAR(16),\n&quot;
</ins><span class="cx">         &quot;   user_id          INTEGER,\n&quot;
</span><span class="cx">         &quot;   instance         INTEGER,\n&quot;
</span><del>-        &quot;   ip               VARCHAR(255),\n&quot;
</del><ins>+        &quot;   ip               VARCHAR(15),\n&quot;
</ins><span class="cx">         &quot;   type             INTEGER,\n&quot;
</span><span class="cx">         &quot;   max_streams      INTEGER,\n&quot;
</span><span class="cx">         &quot;   port             INTEGER,\n&quot;
</span><span class="cx">         &quot;   codec_string     VARCHAR(255)\n&quot;
</span><span class="cx">         &quot;);\n&quot;;
</span><span class="cx"> 
</span><ins>+static char lines_sql[] =
+        &quot;CREATE TABLE skinny_lines (\n&quot;
+        &quot;   device_name          VARCHAR(16),\n&quot;
+        &quot;   device_instance      INTEGER,\n&quot;
+        &quot;   position             INTEGER,\n&quot;
+        &quot;   label                VARCHAR(40),\n&quot;
+        &quot;   value                VARCHAR(24),\n&quot;
+        &quot;   caller_name          VARCHAR(44),\n&quot;
+        &quot;   ring_on_idle         INTEGER,\n&quot;
+        &quot;   ring_on_active       INTEGER,\n&quot;
+        &quot;   busy_trigger         INTEGER,\n&quot;
+        &quot;   forward_all          VARCHAR(255),\n&quot;
+        &quot;   forward_busy         VARCHAR(255),\n&quot;
+        &quot;   forward_noanswer     VARCHAR(255),\n&quot;
+        &quot;   noanswer_duration    INTEGER\n&quot;
+        &quot;);\n&quot;;
+
</ins><span class="cx"> static char buttons_sql[] =
</span><span class="cx">         &quot;CREATE TABLE skinny_buttons (\n&quot;
</span><span class="cx">         &quot;   device_name      VARCHAR(16),\n&quot;
</span><ins>+        &quot;   device_instance  INTEGER,\n&quot;
</ins><span class="cx">         &quot;   position         INTEGER,\n&quot;
</span><span class="cx">         &quot;   type             INTEGER,\n&quot;
</span><span class="cx">         &quot;   label            VARCHAR(40),\n&quot;
</span><del>-        &quot;   value            VARCHAR(24),\n&quot;
</del><ins>+        &quot;   value            VARCHAR(255),\n&quot;
</ins><span class="cx">         &quot;   settings         VARCHAR(44)\n&quot;
</span><span class="cx">         &quot;);\n&quot;;
</span><span class="cx"> 
</span><span class="lines">@@ -148,9 +166,9 @@
</span><span class="cx">         helper.profile = profile;
</span><span class="cx">         
</span><span class="cx">         if ((sql = switch_mprintf(&quot;SELECT device_name, position, &quot;
</span><del>-                                                                &quot;(SELECT count(*) from skinny_buttons sb2 &quot;
-                                                                        &quot;WHERE sb2.device_name= sb1.device_name AND sb2.type='line' AND sb2.position &lt;= sb1.position) AS relative_position &quot;
-                                                                &quot;FROM skinny_buttons sb1 WHERE type='line' and value='%s'&quot;,
</del><ins>+                                                                &quot;(SELECT count(*) from skinny_lines sl2 &quot;
+                                                                        &quot;WHERE sl2.device_name= sl1.device_name AND sl2.device_instance= sl1.device_instance AND sl2.position &lt;= sl1.position) AS relative_position &quot;
+                                                                &quot;FROM skinny_lines sl1 WHERE value='%s'&quot;,
</ins><span class="cx">                                                                 dest))) {
</span><span class="cx">                 skinny_execute_sql_callback(profile, profile-&gt;listener_mutex, sql, skinny_profile_find_listener_callback, &amp;helper);
</span><span class="cx">                 switch_safe_free(sql);
</span><span class="lines">@@ -996,16 +1014,24 @@
</span><span class="cx">         
</span><span class="cx">                 if ((sql = switch_mprintf(
</span><span class="cx">                                 &quot;DELETE FROM skinny_devices &quot;
</span><del>-                                        &quot;WHERE name='%s'&quot;,
-                                listener-&gt;device_name))) {
</del><ins>+                                        &quot;WHERE name='%s' and instance=%d&quot;,
+                                listener-&gt;device_name, listener-&gt;device_instance))) {
</ins><span class="cx">                         skinny_execute_sql(profile, sql, profile-&gt;listener_mutex);
</span><span class="cx">                         switch_safe_free(sql);
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ((sql = switch_mprintf(
</span><ins>+                                &quot;DELETE FROM skinny_lines &quot;
+                                        &quot;WHERE device_name='%s' and device_instance=%d&quot;,
+                                listener-&gt;device_name, listener-&gt;device_instance))) {
+                        skinny_execute_sql(profile, sql, profile-&gt;listener_mutex);
+                        switch_safe_free(sql);
+                }
+
+                if ((sql = switch_mprintf(
</ins><span class="cx">                                 &quot;DELETE FROM skinny_buttons &quot;
</span><del>-                                        &quot;WHERE device_name='%s'&quot;,
-                                listener-&gt;device_name))) {
</del><ins>+                                        &quot;WHERE device_name='%s' and device_instance=%d&quot;,
+                                listener-&gt;device_name, listener-&gt;device_instance))) {
</ins><span class="cx">                         skinny_execute_sql(profile, sql, profile-&gt;listener_mutex);
</span><span class="cx">                         switch_safe_free(sql);
</span><span class="cx">                 }
</span><span class="lines">@@ -1438,10 +1464,12 @@
</span><span class="cx"> 
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, &quot;Connected ODBC DSN: %s\n&quot;, profile-&gt;odbc_dsn);
</span><span class="cx">                                         switch_odbc_handle_exec(profile-&gt;master_odbc, devices_sql, NULL, NULL);
</span><ins>+                                        switch_odbc_handle_exec(profile-&gt;master_odbc, lines_sql, NULL, NULL);
</ins><span class="cx">                                         switch_odbc_handle_exec(profile-&gt;master_odbc, buttons_sql, NULL, NULL);
</span><span class="cx">                                 } else {
</span><span class="cx">                                         if ((db = switch_core_db_open_file(profile-&gt;dbname))) {
</span><span class="cx">                                                 switch_core_db_test_reactive(db, &quot;SELECT * FROM skinny_devices&quot;, NULL, devices_sql);
</span><ins>+                                                switch_core_db_test_reactive(db, &quot;SELECT * FROM skinny_lines&quot;, NULL, lines_sql);
</ins><span class="cx">                                                 switch_core_db_test_reactive(db, &quot;SELECT * FROM skinny_buttons&quot;, NULL, buttons_sql);
</span><span class="cx">                                         } else {
</span><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Cannot Open SQL Database!\n&quot;);
</span><span class="lines">@@ -1451,6 +1479,7 @@
</span><span class="cx">                                 }
</span><span class="cx">                                 
</span><span class="cx">                                 skinny_execute_sql_callback(profile, profile-&gt;listener_mutex, &quot;DELETE FROM skinny_devices&quot;, NULL, NULL);
</span><ins>+                                skinny_execute_sql_callback(profile, profile-&gt;listener_mutex, &quot;DELETE FROM skinny_lines&quot;, NULL, NULL);
</ins><span class="cx">                                 skinny_execute_sql_callback(profile, profile-&gt;listener_mutex, &quot;DELETE FROM skinny_buttons&quot;, NULL, NULL);
</span><span class="cx"> 
</span><span class="cx">                                 switch_core_hash_insert(globals.profile_hash, profile-&gt;name, profile);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skinnymod_skinnyh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h (16958 => 16959)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h        2010-03-09 21:30:54 UTC (rev 16958)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h        2010-03-10 13:49:53 UTC (rev 16959)
</span><span class="lines">@@ -102,6 +102,7 @@
</span><span class="cx"> struct listener {
</span><span class="cx">         skinny_profile_t *profile;
</span><span class="cx">         char device_name[16];
</span><ins>+        uint32_t device_instance;
</ins><span class="cx">         switch_core_session_t *session[SKINNY_MAX_LINES];
</span><span class="cx">         uint32_t line_state[SKINNY_MAX_LINES]; /* See enum skinny_key_set */
</span><span class="cx"> 
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skinnyskinny_protocolc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c (16958 => 16959)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c        2010-03-09 21:30:54 UTC (rev 16958)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c        2010-03-10 13:49:53 UTC (rev 16959)
</span><span class="lines">@@ -138,6 +138,7 @@
</span><span class="cx"> SKINNY_DECLARE_STR2ID(skinny_str2ring_mode, SKINNY_RING_MODES, -1)
</span><span class="cx"> 
</span><span class="cx"> struct skinny_table SKINNY_BUTTONS[] = {
</span><ins>+        {&quot;Unknown&quot;, SKINNY_BUTTON_UNKNOWN},
</ins><span class="cx">         {&quot;LastNumberRedial&quot;, SKINNY_BUTTON_LAST_NUMBER_REDIAL},
</span><span class="cx">         {&quot;SpeedDial&quot;, SKINNY_BUTTON_SPEED_DIAL},
</span><span class="cx">         {&quot;Line&quot;, SKINNY_BUTTON_LINE},
</span><span class="lines">@@ -403,7 +404,7 @@
</span><span class="cx"> 
</span><span class="cx">         switch_event_create_subclass(&amp;event, event_id, subclass_name);
</span><span class="cx">         switch_assert(event);
</span><del>-        if ((sql = switch_mprintf(&quot;SELECT * FROM skinny_devices WHERE name='%s'&quot;, listener-&gt;device_name))) {
</del><ins>+        if ((sql = switch_mprintf(&quot;SELECT * FROM skinny_devices WHERE name='%s' AND instance=%d&quot;, listener-&gt;device_name, listener-&gt;device_instance))) {
</ins><span class="cx">                 skinny_execute_sql_callback(profile, profile-&gt;listener_mutex, sql, skinny_device_event_callback, event);
</span><span class="cx">                 switch_safe_free(sql);
</span><span class="cx">         }
</span><span class="lines">@@ -506,7 +507,7 @@
</span><span class="cx"> 
</span><span class="cx">                 channel = switch_core_session_get_channel(session);
</span><span class="cx"> 
</span><del>-                snprintf(name, sizeof(name), &quot;SKINNY/%s/%s/%d&quot;, listener-&gt;profile-&gt;name, listener-&gt;device_name, tech_pvt-&gt;line);
</del><ins>+                snprintf(name, sizeof(name), &quot;SKINNY/%s/%s:%d/%d&quot;, listener-&gt;profile-&gt;name, listener-&gt;device_name, listener-&gt;device_instance, tech_pvt-&gt;line);
</ins><span class="cx">                 switch_channel_set_name(channel, name);
</span><span class="cx"> 
</span><span class="cx">                 if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
</span><span class="lines">@@ -655,7 +656,7 @@
</span><span class="cx">                 helper-&gt;button-&gt;number = helper-&gt;pos;
</span><span class="cx">                 strncpy(helper-&gt;button-&gt;name,  argv[2], 24); /* label */
</span><span class="cx">                 strncpy(helper-&gt;button-&gt;shortname,  argv[3], 40); /* value */
</span><del>-                strncpy(helper-&gt;button-&gt;displayname,  argv[4], 44); /* settings */
</del><ins>+                strncpy(helper-&gt;button-&gt;displayname,  argv[4], 44); /* caller_name */
</ins><span class="cx">         }
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="lines">@@ -672,13 +673,12 @@
</span><span class="cx">         helper.button = switch_core_alloc(listener-&gt;pool, sizeof(struct line_stat_res_message));
</span><span class="cx">         
</span><span class="cx">         if ((sql = switch_mprintf(
</span><del>-                        &quot;SELECT '%d' AS wanted_position, position, label, value, settings &quot;
-                                &quot;FROM skinny_buttons &quot;
-                                &quot;WHERE device_name='%s' AND type=%d &quot;
</del><ins>+                        &quot;SELECT '%d' AS wanted_position, position, label, value, caller_name &quot;
+                                &quot;FROM skinny_lines &quot;
+                                &quot;WHERE device_name='%s' AND device_instance=%d &quot;
</ins><span class="cx">                                 &quot;ORDER BY position&quot;,
</span><span class="cx">                         instance,
</span><del>-                        listener-&gt;device_name,
-                        SKINNY_BUTTON_LINE
</del><ins>+                        listener-&gt;device_name, listener-&gt;device_instance
</ins><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(listener-&gt;profile, listener-&gt;profile-&gt;listener_mutex, sql, skinny_line_get_callback, &amp;helper);
</span><span class="cx">                 switch_safe_free(sql);
</span><span class="lines">@@ -718,10 +718,10 @@
</span><span class="cx">         if ((sql = switch_mprintf(
</span><span class="cx">                         &quot;SELECT '%d' AS wanted_position, position, label, value, settings &quot;
</span><span class="cx">                                 &quot;FROM skinny_buttons &quot;
</span><del>-                                &quot;WHERE device_name='%s' AND type=%d &quot;
</del><ins>+                                &quot;WHERE device_name='%s' AND device_instance=%d AND type=%d &quot;
</ins><span class="cx">                                 &quot;ORDER BY position&quot;,
</span><span class="cx">                         instance,
</span><del>-                        listener-&gt;device_name,
</del><ins>+                        listener-&gt;device_name, listener-&gt;device_instance,
</ins><span class="cx">                         SKINNY_BUTTON_SPEED_DIAL
</span><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(listener-&gt;profile, listener-&gt;profile-&gt;listener_mutex, sql, skinny_speed_dial_get_callback, &amp;helper);
</span><span class="lines">@@ -762,10 +762,11 @@
</span><span class="cx">         if ((sql = switch_mprintf(
</span><span class="cx">                         &quot;SELECT '%d' AS wanted_position, position, label, value, settings &quot;
</span><span class="cx">                                 &quot;FROM skinny_buttons &quot;
</span><del>-                                &quot;WHERE device_name='%s' AND type=%d &quot;
</del><ins>+                                &quot;WHERE device_name='%s' AND device_instance=%d AND type=%d &quot;
</ins><span class="cx">                                 &quot;ORDER BY position&quot;,
</span><span class="cx">                         instance,
</span><span class="cx">                         listener-&gt;device_name,
</span><ins>+                        listener-&gt;device_instance,
</ins><span class="cx">                         SKINNY_BUTTON_SERVICE_URL
</span><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(listener-&gt;profile, listener-&gt;profile-&gt;listener_mutex, sql, skinny_service_url_get_callback, &amp;helper);
</span><span class="lines">@@ -807,11 +808,12 @@
</span><span class="cx">         if ((sql = switch_mprintf(
</span><span class="cx">                         &quot;SELECT '%d' AS wanted_position, position, label, value, settings &quot;
</span><span class="cx">                                 &quot;FROM skinny_buttons &quot;
</span><del>-                                &quot;WHERE device_name='%s' AND NOT (type=%d OR type=%d OR type=%d) &quot;
</del><ins>+                                &quot;WHERE device_name='%s' AND device_instance=%d AND NOT (type=%d OR type=%d) &quot;
</ins><span class="cx">                                 &quot;ORDER BY position&quot;,
</span><span class="cx">                         instance,
</span><span class="cx">                         listener-&gt;device_name,
</span><del>-                        SKINNY_BUTTON_LINE, SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL
</del><ins>+                        listener-&gt;device_instance,
+                        SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL
</ins><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(listener-&gt;profile, listener-&gt;profile-&gt;listener_mutex, sql, skinny_feature_get_callback, &amp;helper);
</span><span class="cx">                 switch_safe_free(sql);
</span><span class="lines">@@ -1237,6 +1239,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         strcpy(listener-&gt;device_name, request-&gt;data.reg.device_name);
</span><ins>+        listener-&gt;device_instance = request-&gt;data.reg.instance;
</ins><span class="cx"> 
</span><span class="cx">         xskinny = switch_xml_child(xuser, &quot;skinny&quot;);
</span><span class="cx">         if (xskinny) {
</span><span class="lines">@@ -1247,19 +1250,45 @@
</span><span class="cx">                                 uint32_t type = skinny_str2button(switch_xml_attr_soft(xbutton, &quot;type&quot;));
</span><span class="cx">                                 const char *label = switch_xml_attr_soft(xbutton, &quot;label&quot;);
</span><span class="cx">                                 const char *value = switch_xml_attr_soft(xbutton, &quot;value&quot;);
</span><del>-                                const char *settings = switch_xml_attr_soft(xbutton, &quot;settings&quot;);
-                                if ((sql = switch_mprintf(
-                                                &quot;INSERT INTO skinny_buttons &quot;
-                                                        &quot;(device_name, position, type, label, value, settings) &quot;
-                                                        &quot;VALUES('%s', %d, %d, '%s', '%s', '%s')&quot;,
-                                                request-&gt;data.reg.device_name,
-                                                position,
-                                                type,
-                                                label,
-                                                value,
-                                                settings))) {
-                                        skinny_execute_sql(profile, sql, profile-&gt;listener_mutex);
-                                        switch_safe_free(sql);
</del><ins>+                                if(type ==  SKINNY_BUTTON_LINE) {
+                                        const char *caller_name = switch_xml_attr_soft(xbutton, &quot;caller-name&quot;);
+                                        uint32_t ring_on_idle = atoi(switch_xml_attr_soft(xbutton, &quot;ring-on-idle&quot;));
+                                        uint32_t ring_on_active = atoi(switch_xml_attr_soft(xbutton, &quot;ring-on-active&quot;));
+                                        uint32_t busy_trigger = atoi(switch_xml_attr_soft(xbutton, &quot;busy-trigger&quot;));
+                                        const char *forward_all = switch_xml_attr_soft(xbutton, &quot;forward-all&quot;);
+                                        const char *forward_busy = switch_xml_attr_soft(xbutton, &quot;forward-busy&quot;);
+                                        const char *forward_noanswer = switch_xml_attr_soft(xbutton, &quot;forward-noanswer&quot;);
+                                        uint32_t noanswer_duration = atoi(switch_xml_attr_soft(xbutton, &quot;noanswer-duration&quot;));
+                                        if ((sql = switch_mprintf(
+                                                        &quot;INSERT INTO skinny_lines &quot;
+                                                                &quot;(device_name, device_instance, position, &quot;
+                                                                &quot;label, value, caller_name, &quot;
+                                                                &quot;ring_on_idle, ring_on_active, busy_trigger, &quot;
+                                                              &quot;forward_all, forward_busy, forward_noanswer, noanswer_duration) &quot;
+                                                                &quot;VALUES('%s', %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d)&quot;,
+                                                        request-&gt;data.reg.device_name, request-&gt;data.reg.instance, position,
+                                                        label, value, caller_name,
+                                                        ring_on_idle, ring_on_active, busy_trigger,
+                                                      forward_all, forward_busy, forward_noanswer, noanswer_duration))) {
+                                                skinny_execute_sql(profile, sql, profile-&gt;listener_mutex);
+                                                switch_safe_free(sql);
+                                        }
+                                } else {
+                                        const char *settings = switch_xml_attr_soft(xbutton, &quot;settings&quot;);
+                                        if ((sql = switch_mprintf(
+                                                        &quot;INSERT INTO skinny_buttons &quot;
+                                                                &quot;(device_name, device_instance, position, type, label, value, settings) &quot;
+                                                                &quot;VALUES('%s', %d, %d, %d, '%s', '%s', '%s')&quot;,
+                                                        request-&gt;data.reg.device_name,
+                                                        request-&gt;data.reg.instance,
+                                                        position,
+                                                        type,
+                                                        label,
+                                                        value,
+                                                        settings))) {
+                                                skinny_execute_sql(profile, sql, profile-&gt;listener_mutex);
+                                                switch_safe_free(sql);
+                                        }
</ins><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="lines">@@ -1343,12 +1372,13 @@
</span><span class="cx"> 
</span><span class="cx">         if ((sql = switch_mprintf(
</span><span class="cx">                         &quot;SELECT name, user_id, instance, '' AS user_name, '' AS server_name, &quot;
</span><del>-                                &quot;(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type=%d) AS number_lines, &quot;
-                                &quot;(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type=%d) AS number_speed_dials &quot;
</del><ins>+                                &quot;(SELECT COUNT(*) FROM skinny_lines WHERE device_name='%s' AND device_instance=%d) AS number_lines, &quot;
+                                &quot;(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND device_instance=%d AND type=%d) AS number_speed_dials &quot;
</ins><span class="cx">                                 &quot;FROM skinny_devices WHERE name='%s' &quot;,
</span><span class="cx">                         listener-&gt;device_name,
</span><del>-                        SKINNY_BUTTON_LINE,
</del><ins>+                        listener-&gt;device_instance,
</ins><span class="cx">                         listener-&gt;device_name,
</span><ins>+                        listener-&gt;device_instance,
</ins><span class="cx">                         SKINNY_BUTTON_SPEED_DIAL,
</span><span class="cx">                         listener-&gt;device_name
</span><span class="cx">                         ))) {
</span><span class="lines">@@ -1433,9 +1463,10 @@
</span><span class="cx">         skinny_check_data_length(request, sizeof(request-&gt;data.as_uint16));
</span><span class="cx"> 
</span><span class="cx">         if ((sql = switch_mprintf(
</span><del>-                        &quot;UPDATE skinny_devices SET port='%d' WHERE name='%s'&quot;,
</del><ins>+                        &quot;UPDATE skinny_devices SET port=%d WHERE name='%s' and instance=%d&quot;,
</ins><span class="cx">                         request-&gt;data.as_uint16,
</span><del>-                        listener-&gt;device_name
</del><ins>+                        listener-&gt;device_name,
+                        listener-&gt;device_instance
</ins><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql(profile, sql, profile-&gt;listener_mutex);
</span><span class="cx">                 switch_safe_free(sql);
</span><span class="lines">@@ -1446,6 +1477,7 @@
</span><span class="cx"> struct button_template_helper {
</span><span class="cx">         skinny_message_t *message;
</span><span class="cx">         int count[SKINNY_BUTTON_UNDEFINED+1];
</span><ins>+        int max_position;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> int skinny_handle_button_template_request_callback(void *pArg, int argc, char **argv, char **columnNames)
</span><span class="lines">@@ -1453,26 +1485,19 @@
</span><span class="cx">         struct button_template_helper *helper = pArg;
</span><span class="cx">         skinny_message_t *message = helper-&gt;message;
</span><span class="cx">         /* char *device_name = argv[0]; */
</span><del>-        int position = atoi(argv[1]);
-        uint32_t type = atoi(argv[2]);
-        int i;
-        
-        if(type &gt; SKINNY_BUTTON_UNDEFINED) {
-                type = SKINNY_BUTTON_UNDEFINED;
-        }
-        /* fill buttons between previous one and current one */
-        for(i = message-&gt;data.button_template.button_count; i+1 &lt; position; i++) {
-                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;
-                message-&gt;data.button_template.button_count++;
-                message-&gt;data.button_template.total_button_count++;
-        }
</del><ins>+        /* uint32_t device_instance = argv[1]; */
+        int position = atoi(argv[2]);
+        uint32_t type = atoi(argv[3]);
+        /* int relative_position = atoi(argv[4]); */
</ins><span class="cx"> 
</span><del>-        message-&gt;data.button_template.btn[i].instance_number = ++helper-&gt;count[type];
</del><ins>+        message-&gt;data.button_template.btn[position-1].instance_number = ++helper-&gt;count[type];
</ins><span class="cx">         message-&gt;data.button_template.btn[position-1].button_definition = type;
</span><span class="cx"> 
</span><span class="cx">         message-&gt;data.button_template.button_count++;
</span><span class="cx">         message-&gt;data.button_template.total_button_count++;
</span><ins>+        if(position &gt; helper-&gt;max_position) {
+                helper-&gt;max_position = position;
+        }
</ins><span class="cx"> 
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="lines">@@ -1498,16 +1523,43 @@
</span><span class="cx">         message-&gt;data.button_template.total_button_count = 0;
</span><span class="cx">         
</span><span class="cx">         helper.message = message;
</span><ins>+
</ins><span class="cx">         /* Add buttons */
</span><span class="cx">         if ((sql = switch_mprintf(
</span><del>-                        &quot;SELECT device_name, position, type &quot;
-                                &quot;FROM skinny_buttons WHERE device_name='%s' ORDER BY position&quot;,
-                        listener-&gt;device_name
</del><ins>+                        &quot;SELECT device_name, device_instance, position, MIN(type, %d) AS type &quot;
+                                &quot;FROM skinny_buttons &quot;
+                                &quot;WHERE device_name='%s' AND device_instance=%d &quot;
+                                &quot;ORDER BY position&quot;,
+                        SKINNY_BUTTON_UNDEFINED,
+                        listener-&gt;device_name, listener-&gt;device_instance
</ins><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(profile, profile-&gt;listener_mutex, sql, skinny_handle_button_template_request_callback, &amp;helper);
</span><span class="cx">                 switch_safe_free(sql);
</span><span class="cx">         }
</span><span class="cx">         
</span><ins>+        /* Add lines */
+        if ((sql = switch_mprintf(
+                        &quot;SELECT device_name, device_instance, position, %d AS type &quot;
+                                &quot;FROM skinny_lines &quot;
+                                &quot;WHERE device_name='%s' AND device_instance=%d &quot;
+                                &quot;ORDER BY position&quot;,
+                        SKINNY_BUTTON_LINE,
+                        listener-&gt;device_name, listener-&gt;device_instance
+                        ))) {
+                skinny_execute_sql_callback(profile, profile-&gt;listener_mutex, sql, skinny_handle_button_template_request_callback, &amp;helper);
+                switch_safe_free(sql);
+        }
+        
+        /* Fill remaining buttons with Undefined */
+        for(int i = 0; i+1 &lt; helper.max_position; i++) {
+                if(message-&gt;data.button_template.btn[i].button_definition == SKINNY_BUTTON_UNKNOWN) {
+                        message-&gt;data.button_template.btn[i].instance_number = ++helper.count[SKINNY_BUTTON_UNDEFINED];
+                        message-&gt;data.button_template.btn[i].button_definition = SKINNY_BUTTON_UNDEFINED;
+                        message-&gt;data.button_template.button_count++;
+                        message-&gt;data.button_template.total_button_count++;
+                }
+        }
+
</ins><span class="cx">         skinny_send_reply(listener, message);
</span><span class="cx"> 
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skinnyskinny_protocolh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.h (16958 => 16959)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.h        2010-03-09 21:30:54 UTC (rev 16958)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.h        2010-03-10 13:49:53 UTC (rev 16959)
</span><span class="lines">@@ -705,6 +705,7 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> enum skinny_button_definition {
</span><ins>+        SKINNY_BUTTON_UNKNOWN = 0x00,
</ins><span class="cx">         SKINNY_BUTTON_LAST_NUMBER_REDIAL = 0x01,
</span><span class="cx">         SKINNY_BUTTON_SPEED_DIAL = 0x02,
</span><span class="cx">         SKINNY_BUTTON_LINE = 0x09,
</span><span class="lines">@@ -713,7 +714,7 @@
</span><span class="cx">         SKINNY_BUTTON_SERVICE_URL = 0x14,
</span><span class="cx">         SKINNY_BUTTON_UNDEFINED = 0xFF,
</span><span class="cx"> };
</span><del>-struct skinny_table SKINNY_BUTTONS[8];
</del><ins>+struct skinny_table SKINNY_BUTTONS[9];
</ins><span class="cx"> const char *skinny_button2str(uint32_t id);
</span><span class="cx"> uint32_t skinny_str2button(const char *str);
</span><span class="cx"> #define SKINNY_PUSH_STIMULI SKINNY_DECLARE_PUSH_MATCH(SKINNY_BUTTONS)
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>