<!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">         "CREATE TABLE skinny_devices (\n"
</span><del>-        " name VARCHAR(16),\n"
</del><ins>+        " name VARCHAR(16),\n"
</ins><span class="cx">         " user_id INTEGER,\n"
</span><span class="cx">         " instance INTEGER,\n"
</span><del>-        " ip VARCHAR(255),\n"
</del><ins>+        " ip VARCHAR(15),\n"
</ins><span class="cx">         " type INTEGER,\n"
</span><span class="cx">         " max_streams INTEGER,\n"
</span><span class="cx">         " port INTEGER,\n"
</span><span class="cx">         " codec_string VARCHAR(255)\n"
</span><span class="cx">         ");\n";
</span><span class="cx">
</span><ins>+static char lines_sql[] =
+        "CREATE TABLE skinny_lines (\n"
+        " device_name VARCHAR(16),\n"
+        " device_instance INTEGER,\n"
+        " position INTEGER,\n"
+        " label VARCHAR(40),\n"
+        " value VARCHAR(24),\n"
+        " caller_name VARCHAR(44),\n"
+        " ring_on_idle INTEGER,\n"
+        " ring_on_active INTEGER,\n"
+        " busy_trigger INTEGER,\n"
+        " forward_all VARCHAR(255),\n"
+        " forward_busy VARCHAR(255),\n"
+        " forward_noanswer VARCHAR(255),\n"
+        " noanswer_duration INTEGER\n"
+        ");\n";
+
</ins><span class="cx"> static char buttons_sql[] =
</span><span class="cx">         "CREATE TABLE skinny_buttons (\n"
</span><span class="cx">         " device_name VARCHAR(16),\n"
</span><ins>+        " device_instance INTEGER,\n"
</ins><span class="cx">         " position INTEGER,\n"
</span><span class="cx">         " type INTEGER,\n"
</span><span class="cx">         " label VARCHAR(40),\n"
</span><del>-        " value VARCHAR(24),\n"
</del><ins>+        " value VARCHAR(255),\n"
</ins><span class="cx">         " settings VARCHAR(44)\n"
</span><span class="cx">         ");\n";
</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("SELECT device_name, position, "
</span><del>-                                                                "(SELECT count(*) from skinny_buttons sb2 "
-                                                                        "WHERE sb2.device_name= sb1.device_name AND sb2.type='line' AND sb2.position <= sb1.position) AS relative_position "
-                                                                "FROM skinny_buttons sb1 WHERE type='line' and value='%s'",
</del><ins>+                                                                "(SELECT count(*) from skinny_lines sl2 "
+                                                                        "WHERE sl2.device_name= sl1.device_name AND sl2.device_instance= sl1.device_instance AND sl2.position <= sl1.position) AS relative_position "
+                                                                "FROM skinny_lines sl1 WHERE value='%s'",
</ins><span class="cx">                                                                 dest))) {
</span><span class="cx">                 skinny_execute_sql_callback(profile, profile->listener_mutex, sql, skinny_profile_find_listener_callback, &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">                                 "DELETE FROM skinny_devices "
</span><del>-                                        "WHERE name='%s'",
-                                listener->device_name))) {
</del><ins>+                                        "WHERE name='%s' and instance=%d",
+                                listener->device_name, listener->device_instance))) {
</ins><span class="cx">                         skinny_execute_sql(profile, sql, profile->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>+                                "DELETE FROM skinny_lines "
+                                        "WHERE device_name='%s' and device_instance=%d",
+                                listener->device_name, listener->device_instance))) {
+                        skinny_execute_sql(profile, sql, profile->listener_mutex);
+                        switch_safe_free(sql);
+                }
+
+                if ((sql = switch_mprintf(
</ins><span class="cx">                                 "DELETE FROM skinny_buttons "
</span><del>-                                        "WHERE device_name='%s'",
-                                listener->device_name))) {
</del><ins>+                                        "WHERE device_name='%s' and device_instance=%d",
+                                listener->device_name, listener->device_instance))) {
</ins><span class="cx">                         skinny_execute_sql(profile, sql, profile->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, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
</span><span class="cx">                                         switch_odbc_handle_exec(profile->master_odbc, devices_sql, NULL, NULL);
</span><ins>+                                        switch_odbc_handle_exec(profile->master_odbc, lines_sql, NULL, NULL);
</ins><span class="cx">                                         switch_odbc_handle_exec(profile->master_odbc, buttons_sql, NULL, NULL);
</span><span class="cx">                                 } else {
</span><span class="cx">                                         if ((db = switch_core_db_open_file(profile->dbname))) {
</span><span class="cx">                                                 switch_core_db_test_reactive(db, "SELECT * FROM skinny_devices", NULL, devices_sql);
</span><ins>+                                                switch_core_db_test_reactive(db, "SELECT * FROM skinny_lines", NULL, lines_sql);
</ins><span class="cx">                                                 switch_core_db_test_reactive(db, "SELECT * FROM skinny_buttons", NULL, buttons_sql);
</span><span class="cx">                                         } else {
</span><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
</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->listener_mutex, "DELETE FROM skinny_devices", NULL, NULL);
</span><ins>+                                skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_lines", NULL, NULL);
</ins><span class="cx">                                 skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_buttons", NULL, NULL);
</span><span class="cx">
</span><span class="cx">                                 switch_core_hash_insert(globals.profile_hash, profile->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>+        {"Unknown", SKINNY_BUTTON_UNKNOWN},
</ins><span class="cx">         {"LastNumberRedial", SKINNY_BUTTON_LAST_NUMBER_REDIAL},
</span><span class="cx">         {"SpeedDial", SKINNY_BUTTON_SPEED_DIAL},
</span><span class="cx">         {"Line", SKINNY_BUTTON_LINE},
</span><span class="lines">@@ -403,7 +404,7 @@
</span><span class="cx">
</span><span class="cx">         switch_event_create_subclass(&event, event_id, subclass_name);
</span><span class="cx">         switch_assert(event);
</span><del>-        if ((sql = switch_mprintf("SELECT * FROM skinny_devices WHERE name='%s'", listener->device_name))) {
</del><ins>+        if ((sql = switch_mprintf("SELECT * FROM skinny_devices WHERE name='%s' AND instance=%d", listener->device_name, listener->device_instance))) {
</ins><span class="cx">                 skinny_execute_sql_callback(profile, profile->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), "SKINNY/%s/%s/%d", listener->profile->name, listener->device_name, tech_pvt->line);
</del><ins>+                snprintf(name, sizeof(name), "SKINNY/%s/%s:%d/%d", listener->profile->name, listener->device_name, listener->device_instance, tech_pvt->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->button->number = helper->pos;
</span><span class="cx">                 strncpy(helper->button->name, argv[2], 24); /* label */
</span><span class="cx">                 strncpy(helper->button->shortname, argv[3], 40); /* value */
</span><del>-                strncpy(helper->button->displayname, argv[4], 44); /* settings */
</del><ins>+                strncpy(helper->button->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->pool, sizeof(struct line_stat_res_message));
</span><span class="cx">         
</span><span class="cx">         if ((sql = switch_mprintf(
</span><del>-                        "SELECT '%d' AS wanted_position, position, label, value, settings "
-                                "FROM skinny_buttons "
-                                "WHERE device_name='%s' AND type=%d "
</del><ins>+                        "SELECT '%d' AS wanted_position, position, label, value, caller_name "
+                                "FROM skinny_lines "
+                                "WHERE device_name='%s' AND device_instance=%d "
</ins><span class="cx">                                 "ORDER BY position",
</span><span class="cx">                         instance,
</span><del>-                        listener->device_name,
-                        SKINNY_BUTTON_LINE
</del><ins>+                        listener->device_name, listener->device_instance
</ins><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_line_get_callback, &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">                         "SELECT '%d' AS wanted_position, position, label, value, settings "
</span><span class="cx">                                 "FROM skinny_buttons "
</span><del>-                                "WHERE device_name='%s' AND type=%d "
</del><ins>+                                "WHERE device_name='%s' AND device_instance=%d AND type=%d "
</ins><span class="cx">                                 "ORDER BY position",
</span><span class="cx">                         instance,
</span><del>-                        listener->device_name,
</del><ins>+                        listener->device_name, listener->device_instance,
</ins><span class="cx">                         SKINNY_BUTTON_SPEED_DIAL
</span><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_speed_dial_get_callback, &helper);
</span><span class="lines">@@ -762,10 +762,11 @@
</span><span class="cx">         if ((sql = switch_mprintf(
</span><span class="cx">                         "SELECT '%d' AS wanted_position, position, label, value, settings "
</span><span class="cx">                                 "FROM skinny_buttons "
</span><del>-                                "WHERE device_name='%s' AND type=%d "
</del><ins>+                                "WHERE device_name='%s' AND device_instance=%d AND type=%d "
</ins><span class="cx">                                 "ORDER BY position",
</span><span class="cx">                         instance,
</span><span class="cx">                         listener->device_name,
</span><ins>+                        listener->device_instance,
</ins><span class="cx">                         SKINNY_BUTTON_SERVICE_URL
</span><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_service_url_get_callback, &helper);
</span><span class="lines">@@ -807,11 +808,12 @@
</span><span class="cx">         if ((sql = switch_mprintf(
</span><span class="cx">                         "SELECT '%d' AS wanted_position, position, label, value, settings "
</span><span class="cx">                                 "FROM skinny_buttons "
</span><del>-                                "WHERE device_name='%s' AND NOT (type=%d OR type=%d OR type=%d) "
</del><ins>+                                "WHERE device_name='%s' AND device_instance=%d AND NOT (type=%d OR type=%d) "
</ins><span class="cx">                                 "ORDER BY position",
</span><span class="cx">                         instance,
</span><span class="cx">                         listener->device_name,
</span><del>-                        SKINNY_BUTTON_LINE, SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL
</del><ins>+                        listener->device_instance,
+                        SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL
</ins><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_feature_get_callback, &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->device_name, request->data.reg.device_name);
</span><ins>+        listener->device_instance = request->data.reg.instance;
</ins><span class="cx">
</span><span class="cx">         xskinny = switch_xml_child(xuser, "skinny");
</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, "type"));
</span><span class="cx">                                 const char *label = switch_xml_attr_soft(xbutton, "label");
</span><span class="cx">                                 const char *value = switch_xml_attr_soft(xbutton, "value");
</span><del>-                                const char *settings = switch_xml_attr_soft(xbutton, "settings");
-                                if ((sql = switch_mprintf(
-                                                "INSERT INTO skinny_buttons "
-                                                        "(device_name, position, type, label, value, settings) "
-                                                        "VALUES('%s', %d, %d, '%s', '%s', '%s')",
-                                                request->data.reg.device_name,
-                                                position,
-                                                type,
-                                                label,
-                                                value,
-                                                settings))) {
-                                        skinny_execute_sql(profile, sql, profile->listener_mutex);
-                                        switch_safe_free(sql);
</del><ins>+                                if(type == SKINNY_BUTTON_LINE) {
+                                        const char *caller_name = switch_xml_attr_soft(xbutton, "caller-name");
+                                        uint32_t ring_on_idle = atoi(switch_xml_attr_soft(xbutton, "ring-on-idle"));
+                                        uint32_t ring_on_active = atoi(switch_xml_attr_soft(xbutton, "ring-on-active"));
+                                        uint32_t busy_trigger = atoi(switch_xml_attr_soft(xbutton, "busy-trigger"));
+                                        const char *forward_all = switch_xml_attr_soft(xbutton, "forward-all");
+                                        const char *forward_busy = switch_xml_attr_soft(xbutton, "forward-busy");
+                                        const char *forward_noanswer = switch_xml_attr_soft(xbutton, "forward-noanswer");
+                                        uint32_t noanswer_duration = atoi(switch_xml_attr_soft(xbutton, "noanswer-duration"));
+                                        if ((sql = switch_mprintf(
+                                                        "INSERT INTO skinny_lines "
+                                                                "(device_name, device_instance, position, "
+                                                                "label, value, caller_name, "
+                                                                "ring_on_idle, ring_on_active, busy_trigger, "
+                                                         "forward_all, forward_busy, forward_noanswer, noanswer_duration) "
+                                                                "VALUES('%s', %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d)",
+                                                        request->data.reg.device_name, request->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->listener_mutex);
+                                                switch_safe_free(sql);
+                                        }
+                                } else {
+                                        const char *settings = switch_xml_attr_soft(xbutton, "settings");
+                                        if ((sql = switch_mprintf(
+                                                        "INSERT INTO skinny_buttons "
+                                                                "(device_name, device_instance, position, type, label, value, settings) "
+                                                                "VALUES('%s', %d, %d, %d, '%s', '%s', '%s')",
+                                                        request->data.reg.device_name,
+                                                        request->data.reg.instance,
+                                                        position,
+                                                        type,
+                                                        label,
+                                                        value,
+                                                        settings))) {
+                                                skinny_execute_sql(profile, sql, profile->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">                         "SELECT name, user_id, instance, '' AS user_name, '' AS server_name, "
</span><del>-                                "(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type=%d) AS number_lines, "
-                                "(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type=%d) AS number_speed_dials "
</del><ins>+                                "(SELECT COUNT(*) FROM skinny_lines WHERE device_name='%s' AND device_instance=%d) AS number_lines, "
+                                "(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND device_instance=%d AND type=%d) AS number_speed_dials "
</ins><span class="cx">                                 "FROM skinny_devices WHERE name='%s' ",
</span><span class="cx">                         listener->device_name,
</span><del>-                        SKINNY_BUTTON_LINE,
</del><ins>+                        listener->device_instance,
</ins><span class="cx">                         listener->device_name,
</span><ins>+                        listener->device_instance,
</ins><span class="cx">                         SKINNY_BUTTON_SPEED_DIAL,
</span><span class="cx">                         listener->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->data.as_uint16));
</span><span class="cx">
</span><span class="cx">         if ((sql = switch_mprintf(
</span><del>-                        "UPDATE skinny_devices SET port='%d' WHERE name='%s'",
</del><ins>+                        "UPDATE skinny_devices SET port=%d WHERE name='%s' and instance=%d",
</ins><span class="cx">                         request->data.as_uint16,
</span><del>-                        listener->device_name
</del><ins>+                        listener->device_name,
+                        listener->device_instance
</ins><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql(profile, sql, profile->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->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 > SKINNY_BUTTON_UNDEFINED) {
-                type = SKINNY_BUTTON_UNDEFINED;
-        }
-        /* fill buttons between previous one and current one */
-        for(i = message->data.button_template.button_count; i+1 < position; i++) {
-                message->data.button_template.btn[i].instance_number = ++helper->count[SKINNY_BUTTON_UNDEFINED];
-                message->data.button_template.btn[i].button_definition = SKINNY_BUTTON_UNDEFINED;
-                message->data.button_template.button_count++;
-                message->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->data.button_template.btn[i].instance_number = ++helper->count[type];
</del><ins>+        message->data.button_template.btn[position-1].instance_number = ++helper->count[type];
</ins><span class="cx">         message->data.button_template.btn[position-1].button_definition = type;
</span><span class="cx">
</span><span class="cx">         message->data.button_template.button_count++;
</span><span class="cx">         message->data.button_template.total_button_count++;
</span><ins>+        if(position > helper->max_position) {
+                helper->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->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>-                        "SELECT device_name, position, type "
-                                "FROM skinny_buttons WHERE device_name='%s' ORDER BY position",
-                        listener->device_name
</del><ins>+                        "SELECT device_name, device_instance, position, MIN(type, %d) AS type "
+                                "FROM skinny_buttons "
+                                "WHERE device_name='%s' AND device_instance=%d "
+                                "ORDER BY position",
+                        SKINNY_BUTTON_UNDEFINED,
+                        listener->device_name, listener->device_instance
</ins><span class="cx">                         ))) {
</span><span class="cx">                 skinny_execute_sql_callback(profile, profile->listener_mutex, sql, skinny_handle_button_template_request_callback, &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(
+                        "SELECT device_name, device_instance, position, %d AS type "
+                                "FROM skinny_lines "
+                                "WHERE device_name='%s' AND device_instance=%d "
+                                "ORDER BY position",
+                        SKINNY_BUTTON_LINE,
+                        listener->device_name, listener->device_instance
+                        ))) {
+                skinny_execute_sql_callback(profile, profile->listener_mutex, sql, skinny_handle_button_template_request_callback, &helper);
+                switch_safe_free(sql);
+        }
+        
+        /* Fill remaining buttons with Undefined */
+        for(int i = 0; i+1 < helper.max_position; i++) {
+                if(message->data.button_template.btn[i].button_definition == SKINNY_BUTTON_UNKNOWN) {
+                        message->data.button_template.btn[i].instance_number = ++helper.count[SKINNY_BUTTON_UNDEFINED];
+                        message->data.button_template.btn[i].button_definition = SKINNY_BUTTON_UNDEFINED;
+                        message->data.button_template.button_count++;
+                        message->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>