<!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][16749] </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=16749">16749</a></dd>
<dt>Author</dt> <dd>sathieu</dd>
<dt>Date</dt> <dd>2010-02-24 05:58:00 -0600 (Wed, 24 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Skinny: Milestone 1 : device level (Register)

- handle RegisterMessage
- keep device infos (attached to listener)
- respond with RegisterAckMessage
- handle port message (do nothing)
- handle keepalive message (do nothing for now)

and:
- clean memory pools usage
- date_format is fixed length</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 (16748 => 16749)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-02-24 11:57:53 UTC (rev 16748)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-02-24 11:58:00 UTC (rev 16749)
</span><span class="lines">@@ -71,7 +71,7 @@
</span><span class="cx">         char *codec_rates[SWITCH_MAX_CODECS];
</span><span class="cx">         int codec_rates_last;
</span><span class="cx">         int keep_alive;
</span><del>-        char *date_format;
</del><ins>+        char date_format[6];
</ins><span class="cx">         /* data */
</span><span class="cx">         switch_event_node_t *heartbeat_node;
</span><span class="cx">         unsigned int flags;
</span><span class="lines">@@ -101,16 +101,43 @@
</span><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan);
</span><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string);
</span><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string);
</span><del>-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_date_format, globals.date_format);
</del><span class="cx"> 
</span><span class="cx"> /*****************************************************************************/
</span><span class="cx"> /* SKINNY TYPES */
</span><span class="cx"> /*****************************************************************************/
</span><ins>+
+#define KEEP_ALIVE_MESSAGE 0x0000
+
+#define REGISTER_MESSAGE 0x0001
+struct register_message {
+        char deviceName[16];
+        uint32_t userId;
+        uint32_t instance;
+        uint32_t ip;
+        uint32_t deviceType;
+        uint32_t maxStreams;
+};
+
+#define PORT_MESSAGE 0x0002
+
+#define REGISTER_ACK_MESSAGE 0x0081
+struct register_ack_message {
+        uint32_t keepAlive;
+        char dateFormat[6];
+        char reserved[2];
+        uint32_t secondaryKeepAlive;
+        char reserved2[4];
+};
+
</ins><span class="cx"> #define SKINNY_MESSAGE_FIELD_SIZE 4 /* 4-bytes field */
</span><span class="cx"> #define SKINNY_MESSAGE_HEADERSIZE 12 /* three 4-bytes fields */
</span><span class="cx"> #define SKINNY_MESSAGE_MAXSIZE 1000
</span><span class="cx"> 
</span><span class="cx"> union skinny_data {
</span><ins>+        struct register_message reg;
+        struct register_ack_message reg_ack;
+        
+        char as_char;
</ins><span class="cx">         void *raw;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -122,6 +149,18 @@
</span><span class="cx"> };
</span><span class="cx"> typedef struct skinny_message skinny_message_t;
</span><span class="cx"> 
</span><ins>+
+struct skinny_device {
+        char deviceName[16];
+        uint32_t userId;
+        uint32_t instance;
+        uint32_t ip;
+        uint32_t deviceType;
+        uint32_t maxStreams;
+        uint16_t port;
+};
+typedef struct skinny_device skinny_device_t;
+
</ins><span class="cx"> /*****************************************************************************/
</span><span class="cx"> /* LISTENERS TYPES */
</span><span class="cx"> /*****************************************************************************/
</span><span class="lines">@@ -131,6 +170,7 @@
</span><span class="cx"> } event_flag_t;
</span><span class="cx"> 
</span><span class="cx"> struct listener {
</span><ins>+        skinny_device_t *device;
</ins><span class="cx">         switch_socket_t *sock;
</span><span class="cx">         switch_memory_pool_t *pool;
</span><span class="cx">         switch_core_session_t *session;
</span><span class="lines">@@ -578,7 +618,7 @@
</span><span class="cx">         char *ptr;
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_SUCCESS;
</span><span class="cx"> 
</span><del>-        request = switch_core_alloc(module_pool, SKINNY_MESSAGE_MAXSIZE);
</del><ins>+        request = switch_core_alloc(listener-&gt;pool, SKINNY_MESSAGE_MAXSIZE);
</ins><span class="cx"> 
</span><span class="cx">         if (!request) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Unable to allocate memory.\n&quot;);
</span><span class="lines">@@ -656,9 +696,48 @@
</span><span class="cx"> static switch_status_t skinny_parse_request(listener_t *listener, skinny_message_t *request, skinny_message_t **rep)
</span><span class="cx"> {
</span><span class="cx">     skinny_message_t *reply;
</span><del>-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, &quot;Parsing request.\n&quot;);
</del><ins>+    skinny_device_t *device;
</ins><span class="cx">         reply = NULL;
</span><ins>+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
+                &quot;Received message of type %d.\n&quot;, request-&gt;type);
+        if(!listener-&gt;device &amp;&amp; request-&gt;type != REGISTER_MESSAGE) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+                        &quot;Device should send a register message first.\n&quot;);
+                return SWITCH_STATUS_FALSE;
+        }
+        device = listener-&gt;device;
</ins><span class="cx">         switch(request-&gt;type) {
</span><ins>+                case REGISTER_MESSAGE:
+                        /* TODO : check directory */
+                        if(listener-&gt;device) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+                                        &quot;Device already registred.\n&quot;);
+                                return SWITCH_STATUS_FALSE;
+                        }
+                        device = switch_core_alloc(listener-&gt;pool, sizeof(skinny_device_t));
+                        memcpy(device-&gt;deviceName, request-&gt;data.reg.deviceName, 16);
+                        device-&gt;userId = request-&gt;data.reg.userId;
+                        device-&gt;instance = request-&gt;data.reg.instance;
+                        device-&gt;ip = request-&gt;data.reg.ip;
+                        device-&gt;deviceType = request-&gt;data.reg.deviceType;
+                        device-&gt;maxStreams = request-&gt;data.reg.maxStreams;
+                        listener-&gt;device = device;
+
+                        reply = switch_core_alloc(listener-&gt;pool, 12+sizeof(reply-&gt;data.reg_ack));
+                        reply-&gt;type = REGISTER_ACK_MESSAGE;
+                        reply-&gt;length = 4 + sizeof(reply-&gt;data.reg_ack);
+                        reply-&gt;data.reg_ack.keepAlive = globals.keep_alive;
+                        memcpy(reply-&gt;data.reg_ack.dateFormat, globals.date_format, 6);
+                        reply-&gt;data.reg_ack.secondaryKeepAlive = globals.keep_alive;
+                        /* TODO send CapabilitiesReqMessage (and parse the CapabilitiesResMessage) */
+                        /* TODO event */
+                        break;
+                case PORT_MESSAGE:
+                        /* Nothing to do */
+                        break;
+                case KEEP_ALIVE_MESSAGE:
+                        /* TODO */
+                        break;
</ins><span class="cx">                 /* TODO */
</span><span class="cx">                 default:
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, 
</span><span class="lines">@@ -670,8 +749,13 @@
</span><span class="cx"> 
</span><span class="cx"> static switch_status_t skinny_send_reply(listener_t *listener, skinny_message_t *reply)
</span><span class="cx"> {
</span><del>-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, &quot;Sending reply.\n&quot;);
-        //TODO switch_socket_send(listener-&gt;sock, buf, &amp;len);
</del><ins>+        char *ptr;
+        switch_size_t len;
+        switch_assert(reply != NULL);
+        len = reply-&gt;length+4;
+        ptr = (char *) reply;
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, &quot;Sending reply (length=%d).\n&quot;, len);
+        switch_socket_send(listener-&gt;sock, ptr, &amp;len);
</ins><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -963,6 +1047,7 @@
</span><span class="cx">                 listener-&gt;sock = inbound_socket;
</span><span class="cx">                 listener-&gt;pool = listener_pool;
</span><span class="cx">                 listener_pool = NULL;
</span><ins>+                listener-&gt;device = NULL;
</ins><span class="cx"> 
</span><span class="cx">                 switch_mutex_init(&amp;listener-&gt;flag_mutex, SWITCH_MUTEX_NESTED, listener-&gt;pool);
</span><span class="cx"> 
</span><span class="lines">@@ -1031,7 +1116,7 @@
</span><span class="cx">                         } else if (!strcmp(var, &quot;keep-alive&quot;)) {
</span><span class="cx">                                 globals.keep_alive = atoi(val);
</span><span class="cx">                         } else if (!strcmp(var, &quot;date-format&quot;)) {
</span><del>-                                set_global_date_format(val);
</del><ins>+                                memcpy(globals.date_format, val, 6);
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -1064,10 +1149,10 @@
</span><span class="cx"> 
</span><span class="cx">         load_skinny_config();
</span><span class="cx"> 
</span><del>-        switch_mutex_init(&amp;globals.listener_mutex, SWITCH_MUTEX_NESTED, pool);
</del><ins>+        switch_mutex_init(&amp;globals.listener_mutex, SWITCH_MUTEX_NESTED, module_pool);
</ins><span class="cx"> 
</span><span class="cx">         memset(&amp;listen_list, 0, sizeof(listen_list));
</span><del>-        switch_mutex_init(&amp;listen_list.sock_mutex, SWITCH_MUTEX_NESTED, pool);
</del><ins>+        switch_mutex_init(&amp;listen_list.sock_mutex, SWITCH_MUTEX_NESTED, module_pool);
</ins><span class="cx"> 
</span><span class="cx">         if ((switch_event_bind_removable(modname, SWITCH_EVENT_HEARTBEAT, NULL, event_handler, NULL, &amp;globals.heartbeat_node) != SWITCH_STATUS_SUCCESS)) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Couldn't bind our heartbeat handler!\n&quot;);
</span><span class="lines">@@ -1116,7 +1201,6 @@
</span><span class="cx">         switch_safe_free(globals.dialplan);
</span><span class="cx">         switch_safe_free(globals.codec_string);
</span><span class="cx">         switch_safe_free(globals.codec_rates_string);
</span><del>-        switch_safe_free(globals.date_format);
</del><span class="cx">         
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>