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

<h3>Log Message</h3>
<pre>Skinny: Milestone 0 : no-op module (conf and event)

Based on mod_reference.

- example conf files
- load configuration file conf/autoload_configs/skinny.conf.xml
- listen to reloadxml events</pre>

<h3>Added 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="addfile"><h4>Added: freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c (0 => 16746)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c                                (rev 0)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-02-24 11:57:37 UTC (rev 16746)
</span><span class="lines">@@ -0,0 +1,638 @@
</span><ins>+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2010, Mathieu Parent &lt;math.parent@gmail.com&gt;
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the &quot;License&quot;); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an &quot;AS IS&quot; basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Mathieu Parent &lt;math.parent@gmail.com&gt;
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Mathieu Parent &lt;math.parent@gmail.com&gt;
+ *
+ *
+ * mod_skinny.c -- Skinny Call Control Protocol (SCCP) Endpoint Module
+ *
+ */
+#include &lt;switch.h&gt;
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_skinny_load);
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skinny_shutdown);
+SWITCH_MODULE_RUNTIME_FUNCTION(mod_skinny_runtime);
+
+SWITCH_MODULE_DEFINITION(mod_skinny, mod_skinny_load, mod_skinny_shutdown, mod_skinny_runtime);
+
+
+switch_endpoint_interface_t *skinny_endpoint_interface;
+static switch_memory_pool_t *module_pool = NULL;
+static int running = 1;
+
+typedef enum {
+        TFLAG_IO = (1 &lt;&lt; 0),
+        TFLAG_INBOUND = (1 &lt;&lt; 1),
+        TFLAG_OUTBOUND = (1 &lt;&lt; 2),
+        TFLAG_DTMF = (1 &lt;&lt; 3),
+        TFLAG_VOICE = (1 &lt;&lt; 4),
+        TFLAG_HANGUP = (1 &lt;&lt; 5),
+        TFLAG_LINEAR = (1 &lt;&lt; 6),
+        TFLAG_CODEC = (1 &lt;&lt; 7),
+        TFLAG_BREAK = (1 &lt;&lt; 8)
+} TFLAGS;
+
+typedef enum {
+        GFLAG_MY_CODEC_PREFS = (1 &lt;&lt; 0)
+} GFLAGS;
+
+static struct {
+    /* prefs */
+        int debug;
+        char *ip;
+        int port;
+        char *dialplan;
+        char *codec_string;
+        char *codec_order[SWITCH_MAX_CODECS];
+        int codec_order_last;
+        char *codec_rates_string;
+        char *codec_rates[SWITCH_MAX_CODECS];
+        int codec_rates_last;
+        int keep_alive;
+        char *date_format;
+    /* data */
+        switch_event_node_t *node;
+        unsigned int flags;
+        int calls;
+        switch_mutex_t *mutex;
+} globals;
+
+struct private_object {
+        unsigned int flags;
+        switch_codec_t read_codec;
+        switch_codec_t write_codec;
+        switch_frame_t read_frame;
+        unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+        switch_core_session_t *session;
+        switch_caller_profile_t *caller_profile;
+        switch_mutex_t *mutex;
+        switch_mutex_t *flag_mutex;
+        //switch_thread_cond_t *cond;
+};
+
+typedef struct private_object private_t;
+
+
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_date_format, globals.date_format);
+
+static switch_status_t channel_on_init(switch_core_session_t *session);
+static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_destroy(switch_core_session_t *session);
+static switch_status_t channel_on_routing(switch_core_session_t *session);
+static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
+static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
+                                                                                                        switch_caller_profile_t *outbound_profile,
+                                                                                                        switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause);
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
+static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
+
+
+static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
+{
+        tech_pvt-&gt;read_frame.data = tech_pvt-&gt;databuf;
+        tech_pvt-&gt;read_frame.buflen = sizeof(tech_pvt-&gt;databuf);
+        switch_mutex_init(&amp;tech_pvt-&gt;mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+        switch_mutex_init(&amp;tech_pvt-&gt;flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+        switch_core_session_set_private(session, tech_pvt);
+        tech_pvt-&gt;session = session;
+}
+
+/* 
+   State methods they get called when the state changes to the specific state 
+   returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
+   so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
+*/
+static switch_status_t channel_on_init(switch_core_session_t *session)
+{
+        switch_channel_t *channel;
+        private_t *tech_pvt = NULL;
+
+        tech_pvt = switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+        switch_set_flag_locked(tech_pvt, TFLAG_IO);
+
+        /* Move channel's state machine to ROUTING. This means the call is trying
+           to get from the initial start where the call because, to the point
+           where a destination has been identified. If the channel is simply
+           left in the initial state, nothing will happen. */
+        switch_channel_set_state(channel, CS_ROUTING);
+        switch_mutex_lock(globals.mutex);
+        globals.calls++;
+        switch_mutex_unlock(globals.mutex);
+
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;%s CHANNEL INIT\n&quot;, switch_channel_get_name(channel));
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_routing(switch_core_session_t *session)
+{
+        switch_channel_t *channel = NULL;
+        private_t *tech_pvt = NULL;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;%s CHANNEL ROUTING\n&quot;, switch_channel_get_name(channel));
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_execute(switch_core_session_t *session)
+{
+
+        switch_channel_t *channel = NULL;
+        private_t *tech_pvt = NULL;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;%s CHANNEL EXECUTE\n&quot;, switch_channel_get_name(channel));
+
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_destroy(switch_core_session_t *session)
+{
+        switch_channel_t *channel = NULL;
+        private_t *tech_pvt = NULL;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = switch_core_session_get_private(session);
+
+        if (tech_pvt) {
+                if (switch_core_codec_ready(&amp;tech_pvt-&gt;read_codec)) {
+                        switch_core_codec_destroy(&amp;tech_pvt-&gt;read_codec);
+                }
+                
+                if (switch_core_codec_ready(&amp;tech_pvt-&gt;write_codec)) {
+                        switch_core_codec_destroy(&amp;tech_pvt-&gt;write_codec);
+                }
+        }
+
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;%s CHANNEL DESTROY\n&quot;, switch_channel_get_name(channel));
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+
+static switch_status_t channel_on_hangup(switch_core_session_t *session)
+{
+        switch_channel_t *channel = NULL;
+        private_t *tech_pvt = NULL;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+
+        switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+        switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+        //switch_thread_cond_signal(tech_pvt-&gt;cond);
+
+
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;%s CHANNEL HANGUP\n&quot;, switch_channel_get_name(channel));
+        switch_mutex_lock(globals.mutex);
+        globals.calls--;
+        if (globals.calls &lt; 0) {
+                globals.calls = 0;
+        }
+        switch_mutex_unlock(globals.mutex);
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig)
+{
+        switch_channel_t *channel = NULL;
+        private_t *tech_pvt = NULL;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+
+        switch (sig) {
+        case SWITCH_SIG_KILL:
+                switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+                switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+                switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
+                //switch_thread_cond_signal(tech_pvt-&gt;cond);
+                break;
+        case SWITCH_SIG_BREAK:
+                switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
+                break;
+        default:
+                break;
+        }
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_exchange_media(switch_core_session_t *session)
+{
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;CHANNEL LOOPBACK\n&quot;);
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_soft_execute(switch_core_session_t *session)
+{
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;CHANNEL TRANSMIT\n&quot;);
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
+{
+        private_t *tech_pvt = switch_core_session_get_private(session);
+        switch_assert(tech_pvt != NULL);
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
+{
+        switch_channel_t *channel = NULL;
+        private_t *tech_pvt = NULL;
+        //switch_time_t started = switch_time_now();
+        //unsigned int elapsed;
+        switch_byte_t *data;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+        tech_pvt-&gt;read_frame.flags = SFF_NONE;
+        *frame = NULL;
+
+        while (switch_test_flag(tech_pvt, TFLAG_IO)) {
+
+                if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
+                        switch_clear_flag(tech_pvt, TFLAG_BREAK);
+                        goto cng;
+                }
+
+                if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
+                        return SWITCH_STATUS_FALSE;
+                }
+
+                if (switch_test_flag(tech_pvt, TFLAG_IO) &amp;&amp; switch_test_flag(tech_pvt, TFLAG_VOICE)) {
+                        switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+                        if (!tech_pvt-&gt;read_frame.datalen) {
+                                continue;
+                        }
+                        *frame = &amp;tech_pvt-&gt;read_frame;
+#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
+                        if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
+                                switch_swap_linear((*frame)-&gt;data, (int) (*frame)-&gt;datalen / 2);
+                        }
+#endif
+                        return SWITCH_STATUS_SUCCESS;
+                }
+
+                switch_cond_next();
+        }
+
+
+        return SWITCH_STATUS_FALSE;
+
+  cng:
+        data = (switch_byte_t *) tech_pvt-&gt;read_frame.data;
+        data[0] = 65;
+        data[1] = 0;
+        tech_pvt-&gt;read_frame.datalen = 2;
+        tech_pvt-&gt;read_frame.flags = SFF_CNG;
+        *frame = &amp;tech_pvt-&gt;read_frame;
+        return SWITCH_STATUS_SUCCESS;
+
+}
+
+static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
+{
+        switch_channel_t *channel = NULL;
+        private_t *tech_pvt = NULL;
+        //switch_frame_t *pframe;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+
+        if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
+                return SWITCH_STATUS_FALSE;
+        }
+#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
+        if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
+                switch_swap_linear(frame-&gt;data, (int) frame-&gt;datalen / 2);
+        }
+#endif
+
+
+        return SWITCH_STATUS_SUCCESS;
+
+}
+
+static switch_status_t channel_answer_channel(switch_core_session_t *session)
+{
+        private_t *tech_pvt;
+        switch_channel_t *channel = NULL;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+
+static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
+{
+        switch_channel_t *channel;
+        private_t *tech_pvt;
+
+        channel = switch_core_session_get_channel(session);
+        assert(channel != NULL);
+
+        tech_pvt = (private_t *) switch_core_session_get_private(session);
+        assert(tech_pvt != NULL);
+
+        switch (msg-&gt;message_id) {
+        case SWITCH_MESSAGE_INDICATE_ANSWER:
+                {
+                        channel_answer_channel(session);
+                }
+                break;
+        default:
+                break;
+        }
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
+   that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
+*/
+static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
+                                                                                                        switch_caller_profile_t *outbound_profile,
+                                                                                                        switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause)
+{
+        if ((*new_session = switch_core_session_request(skinny_endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, pool)) != 0) {
+                private_t *tech_pvt;
+                switch_channel_t *channel;
+                switch_caller_profile_t *caller_profile;
+
+                switch_core_session_add_stream(*new_session, NULL);
+                if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
+                        channel = switch_core_session_get_channel(*new_session);
+                        tech_init(tech_pvt, *new_session);
+                } else {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_CRIT, &quot;Hey where is my memory pool?\n&quot;);
+                        switch_core_session_destroy(new_session);
+                        return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                }
+
+                if (outbound_profile) {
+                        char name[128];
+
+                        snprintf(name, sizeof(name), &quot;SKINNY/%s&quot;, outbound_profile-&gt;destination_number);
+                        switch_channel_set_name(channel, name);
+
+                        caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
+                        switch_channel_set_caller_profile(channel, caller_profile);
+                        tech_pvt-&gt;caller_profile = caller_profile;
+                } else {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(*new_session), SWITCH_LOG_ERROR, &quot;Doh! no caller profile\n&quot;);
+                        switch_core_session_destroy(new_session);
+                        return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                }
+
+
+
+                switch_channel_set_flag(channel, CF_OUTBOUND);
+                switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
+                switch_channel_set_state(channel, CS_INIT);
+                return SWITCH_CAUSE_SUCCESS;
+        }
+
+        return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+
+}
+
+static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event)
+{
+        struct private_object *tech_pvt = switch_core_session_get_private(session);
+        char *body = switch_event_get_body(event);
+        switch_assert(tech_pvt != NULL);
+
+        if (!body) {
+                body = &quot;&quot;;
+        }
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+
+
+switch_state_handler_table_t skinny_state_handlers = {
+        /*.on_init */ channel_on_init,
+        /*.on_routing */ channel_on_routing,
+        /*.on_execute */ channel_on_execute,
+        /*.on_hangup */ channel_on_hangup,
+        /*.on_exchange_media */ channel_on_exchange_media,
+        /*.on_soft_execute */ channel_on_soft_execute,
+        /*.on_consume_media*/ NULL,
+        /*.on_hibernate*/ NULL,
+        /*.on_reset*/ NULL,
+        /*.on_park*/ NULL,
+        /*.on_reporting*/ NULL,
+        /*.on_destroy*/ channel_on_destroy
+
+};
+
+switch_io_routines_t skinny_io_routines = {
+        /*.outgoing_channel */ channel_outgoing_channel,
+        /*.read_frame */ channel_read_frame,
+        /*.write_frame */ channel_write_frame,
+        /*.kill_channel */ channel_kill_channel,
+        /*.send_dtmf */ channel_send_dtmf,
+        /*.receive_message */ channel_receive_message,
+        /*.receive_event */ channel_receive_event
+};
+
+static switch_status_t load_skinny_config(void)
+{
+        char *cf = &quot;skinny.conf&quot;;
+        switch_xml_t cfg, xml, settings, param;
+
+        memset(&amp;globals, 0, sizeof(globals));
+        switch_mutex_init(&amp;globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
+        if (!(xml = switch_xml_open_cfg(cf, &amp;cfg, NULL))) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Open of %s failed\n&quot;, cf);
+                return SWITCH_STATUS_TERM;
+        }
+
+        if ((settings = switch_xml_child(cfg, &quot;settings&quot;))) {
+                for (param = switch_xml_child(settings, &quot;param&quot;); param; param = param-&gt;next) {
+                        char *var = (char *) switch_xml_attr_soft(param, &quot;name&quot;);
+                        char *val = (char *) switch_xml_attr_soft(param, &quot;value&quot;);
+
+                        if (!strcmp(var, &quot;debug&quot;)) {
+                                globals.debug = atoi(val);
+                        } else if (!strcmp(var, &quot;ip&quot;)) {
+                                set_global_ip(val);
+                        } else if (!strcmp(var, &quot;port&quot;)) {
+                                globals.port = atoi(val);
+                        } else if (!strcmp(var, &quot;dialplan&quot;)) {
+                                set_global_dialplan(val);
+                        } else if (!strcmp(var, &quot;codec-prefs&quot;)) {
+                                set_global_codec_string(val);
+                                globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
+                        } else if (!strcmp(var, &quot;codec-master&quot;)) {
+                                if (!strcasecmp(val, &quot;us&quot;)) {
+                                        switch_set_flag(&amp;globals, GFLAG_MY_CODEC_PREFS);
+                                }
+                        } else if (!strcmp(var, &quot;codec-rates&quot;)) {
+                                set_global_codec_rates_string(val);
+                                globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
+                        } else if (!strcmp(var, &quot;keep-alive&quot;)) {
+                                globals.keep_alive = atoi(val);
+                        } else if (!strcmp(var, &quot;date-format&quot;)) {
+                                set_global_date_format(val);
+                        }
+                }
+        }
+        if (!globals.dialplan) {
+                set_global_dialplan(&quot;default&quot;);
+        }
+
+        if (!globals.port) {
+                globals.port = 2000;
+        }
+
+        switch_xml_free(xml);
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
+static void event_handler(switch_event_t *event)
+{
+        if (event-&gt;event_id == SWITCH_EVENT_RELOADXML) {
+                if (load_skinny_config() != SWITCH_STATUS_SUCCESS) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Failed to reload config file\n&quot;);
+                }
+        }
+}
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_skinny_load)
+{
+
+        module_pool = pool;
+
+        memset(&amp;globals, 0, sizeof(globals));
+
+        load_skinny_config();
+
+        /* connect my internal structure to the blank pointer passed to me */
+        *module_interface = switch_loadable_module_create_module_interface(pool, modname);
+        skinny_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
+        skinny_endpoint_interface-&gt;interface_name = &quot;skinny&quot;;
+        skinny_endpoint_interface-&gt;io_routines = &amp;skinny_io_routines;
+        skinny_endpoint_interface-&gt;state_handler = &amp;skinny_state_handlers;
+
+        if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &amp;globals.node) != SWITCH_STATUS_SUCCESS)) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Couldn't bind our reloadxml handler!\n&quot;);
+                /* Not such severe to prevent loading */
+        }
+
+
+        /* indicate that the module should continue to be loaded */
+        return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_MODULE_RUNTIME_FUNCTION(mod_skinny_runtime)
+{
+    /* TODO: create listeners */
+        return SWITCH_STATUS_TERM;
+}
+
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skinny_shutdown)
+{
+        switch_event_unbind(&amp;globals.node);
+
+        int x = 0;
+
+        running = -1;
+
+        while (running) {
+                if (x++ &gt; 100) {
+                        break;
+                }
+                switch_yield(20000);
+        }
+        
+        /* Free dynamically allocated strings */
+        switch_safe_free(globals.ip);
+        switch_safe_free(globals.dialplan);
+        switch_safe_free(globals.codec_string);
+        switch_safe_free(globals.codec_rates_string);
+        switch_safe_free(globals.date_format);
+        
+        return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
+ */
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>