<!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][17350] </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=17350">17350</a></dd>
<dt>Author</dt> <dd>math.parent</dd>
<dt>Date</dt> <dd>2010-04-20 15:40:21 -0500 (Tue, 20 Apr 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Skinny: Initial patterns dialplan implementation.

More info on mod_skinny wiki page</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>
</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 (17349 => 17350)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-04-20 20:39:20 UTC (rev 17349)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-04-20 20:40:21 UTC (rev 17350)
</span><span class="lines">@@ -107,21 +107,23 @@
</span><span class="cx">         switch_assert(profile);
</span><span class="cx">         stream-&gt;write_function(stream, &quot;%s\n&quot;, line);
</span><span class="cx">         /* prefs */
</span><del>-        stream-&gt;write_function(stream, &quot;Name             \t%s\n&quot;, profile-&gt;name);
-        stream-&gt;write_function(stream, &quot;Domain Name      \t%s\n&quot;, profile-&gt;domain);
-        stream-&gt;write_function(stream, &quot;IP               \t%s\n&quot;, profile-&gt;ip);
-        stream-&gt;write_function(stream, &quot;Port             \t%d\n&quot;, profile-&gt;port);
-        stream-&gt;write_function(stream, &quot;Dialplan         \t%s\n&quot;, profile-&gt;dialplan);
-        stream-&gt;write_function(stream, &quot;Context          \t%s\n&quot;, profile-&gt;context);
-        stream-&gt;write_function(stream, &quot;Keep-Alive       \t%d\n&quot;, profile-&gt;keep_alive);
-        stream-&gt;write_function(stream, &quot;Date-Format      \t%s\n&quot;, profile-&gt;date_format);
-        stream-&gt;write_function(stream, &quot;DBName           \t%s\n&quot;, profile-&gt;dbname ? profile-&gt;dbname : switch_str_nil(profile-&gt;odbc_dsn));
-        stream-&gt;write_function(stream, &quot;Debug            \t%d\n&quot;, profile-&gt;debug);
</del><ins>+        stream-&gt;write_function(stream, &quot;Name              \t%s\n&quot;, profile-&gt;name);
+        stream-&gt;write_function(stream, &quot;Domain Name       \t%s\n&quot;, profile-&gt;domain);
+        stream-&gt;write_function(stream, &quot;IP                \t%s\n&quot;, profile-&gt;ip);
+        stream-&gt;write_function(stream, &quot;Port              \t%d\n&quot;, profile-&gt;port);
+        stream-&gt;write_function(stream, &quot;Dialplan          \t%s\n&quot;, profile-&gt;dialplan);
+        stream-&gt;write_function(stream, &quot;Context           \t%s\n&quot;, profile-&gt;context);
+        stream-&gt;write_function(stream, &quot;Patterns-Dialplan \t%s\n&quot;, profile-&gt;patterns_dialplan);
+        stream-&gt;write_function(stream, &quot;Patterns-Context  \t%s\n&quot;, profile-&gt;patterns_context);
+        stream-&gt;write_function(stream, &quot;Keep-Alive        \t%d\n&quot;, profile-&gt;keep_alive);
+        stream-&gt;write_function(stream, &quot;Date-Format       \t%s\n&quot;, profile-&gt;date_format);
+        stream-&gt;write_function(stream, &quot;DBName            \t%s\n&quot;, profile-&gt;dbname ? profile-&gt;dbname : switch_str_nil(profile-&gt;odbc_dsn));
+        stream-&gt;write_function(stream, &quot;Debug             \t%d\n&quot;, profile-&gt;debug);
</ins><span class="cx">         /* stats */
</span><del>-        stream-&gt;write_function(stream, &quot;CALLS-IN         \t%d\n&quot;, profile-&gt;ib_calls);
-        stream-&gt;write_function(stream, &quot;FAILED-CALLS-IN  \t%d\n&quot;, profile-&gt;ib_failed_calls);
-        stream-&gt;write_function(stream, &quot;CALLS-OUT        \t%d\n&quot;, profile-&gt;ob_calls);
-        stream-&gt;write_function(stream, &quot;FAILED-CALLS-OUT \t%d\n&quot;, profile-&gt;ob_failed_calls);
</del><ins>+        stream-&gt;write_function(stream, &quot;CALLS-IN          \t%d\n&quot;, profile-&gt;ib_calls);
+        stream-&gt;write_function(stream, &quot;FAILED-CALLS-IN   \t%d\n&quot;, profile-&gt;ib_failed_calls);
+        stream-&gt;write_function(stream, &quot;CALLS-OUT         \t%d\n&quot;, profile-&gt;ob_calls);
+        stream-&gt;write_function(stream, &quot;FAILED-CALLS-OUT  \t%d\n&quot;, profile-&gt;ob_failed_calls);
</ins><span class="cx">         /* listener */
</span><span class="cx">         stream-&gt;write_function(stream, &quot;Listener-Threads \t%d\n&quot;, profile-&gt;listener_threads);
</span><span class="cx">         stream-&gt;write_function(stream, &quot;%s\n&quot;, line);
</span><span class="lines">@@ -1429,6 +1431,10 @@
</span><span class="cx">                 profile-&gt;dialplan = switch_core_strdup(profile-&gt;pool, val);
</span><span class="cx">         } else if (!strcasecmp(var, &quot;context&quot;)) {
</span><span class="cx">                 profile-&gt;context = switch_core_strdup(profile-&gt;pool, val);
</span><ins>+        } else if (!strcasecmp(var, &quot;patterns-dialplan&quot;)) {
+                profile-&gt;patterns_dialplan = switch_core_strdup(profile-&gt;pool, val);
+        } else if (!strcasecmp(var, &quot;patterns-context&quot;)) {
+                profile-&gt;patterns_context = switch_core_strdup(profile-&gt;pool, val);
</ins><span class="cx">         } else if (!strcasecmp(var, &quot;date-format&quot;)) {
</span><span class="cx">                 strncpy(profile-&gt;date_format, val, 6);
</span><span class="cx">         } else if (!strcasecmp(var, &quot;odbc-dsn&quot;) &amp;&amp; !zstr(val)) {
</span><span class="lines">@@ -1499,6 +1505,10 @@
</span><span class="cx">                                                 skinny_profile_set(profile, &quot;dialplan&quot;, val);
</span><span class="cx">                                         } else if (!strcmp(var, &quot;context&quot;)) {
</span><span class="cx">                                                 skinny_profile_set(profile, &quot;context&quot;, val);
</span><ins>+                                        } else if (!strcmp(var, &quot;patterns-dialplan&quot;)) {
+                                                skinny_profile_set(profile, &quot;patterns-dialplan&quot;, val);
+                                        } else if (!strcmp(var, &quot;patterns-context&quot;)) {
+                                                skinny_profile_set(profile, &quot;patterns-context&quot;, val);
</ins><span class="cx">                                         } else if (!strcmp(var, &quot;keep-alive&quot;)) {
</span><span class="cx">                                                 profile-&gt;keep_alive = atoi(val);
</span><span class="cx">                                         } else if (!strcmp(var, &quot;date-format&quot;)) {
</span><span class="lines">@@ -1511,13 +1521,21 @@
</span><span class="cx">                                 } /* param */
</span><span class="cx">                 
</span><span class="cx">                                 if (!profile-&gt;dialplan) {
</span><del>-                                        skinny_profile_set(profile, &quot;dialplan&quot;,&quot;default&quot;);
</del><ins>+                                        skinny_profile_set(profile, &quot;dialplan&quot;,&quot;XML&quot;);
</ins><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="cx">                                 if (!profile-&gt;context) {
</span><del>-                                        skinny_profile_set(profile, &quot;context&quot;,&quot;public&quot;);
</del><ins>+                                        skinny_profile_set(profile, &quot;context&quot;,&quot;default&quot;);
</ins><span class="cx">                                 }
</span><span class="cx"> 
</span><ins>+                                if (!profile-&gt;patterns_dialplan) {
+                                        skinny_profile_set(profile, &quot;patterns-dialplan&quot;,&quot;XML&quot;);
+                                }
+
+                                if (!profile-&gt;patterns_context) {
+                                        skinny_profile_set(profile, &quot;patterns-context&quot;,&quot;skinny-patterns&quot;);
+                                }
+
</ins><span class="cx">                                 if (profile-&gt;port == 0) {
</span><span class="cx">                                         profile-&gt;port = 2000;
</span><span class="cx">                                 }
</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 (17349 => 17350)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h        2010-04-20 20:39:20 UTC (rev 17349)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.h        2010-04-20 20:40:21 UTC (rev 17350)
</span><span class="lines">@@ -64,6 +64,8 @@
</span><span class="cx">     unsigned int port;
</span><span class="cx">     char *dialplan;
</span><span class="cx">     char *context;
</span><ins>+    char *patterns_dialplan;
+    char *patterns_context;
</ins><span class="cx">     uint32_t keep_alive;
</span><span class="cx">     char date_format[6];
</span><span class="cx">     int debug;
</span><span class="lines">@@ -99,6 +101,12 @@
</span><span class="cx"> };
</span><span class="cx"> typedef struct skinny_device_type_params skinny_device_type_params_t;
</span><span class="cx"> 
</span><ins>+typedef enum {
+        SKINNY_ACTION_ROUTE,
+        SKINNY_ACTION_DROP,
+        SKINNY_ACTION_WAIT
+} skinny_action_t;
+
</ins><span class="cx"> /*****************************************************************************/
</span><span class="cx"> /* LISTENERS TYPES */
</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 (17349 => 17350)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c        2010-04-20 20:39:20 UTC (rev 17349)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/skinny_protocol.c        2010-04-20 20:40:21 UTC (rev 17350)
</span><span class="lines">@@ -500,12 +500,13 @@
</span><span class="cx">                     &quot;Error Locking Session\n&quot;);
</span><span class="cx">                 goto error;
</span><span class="cx">         }
</span><ins>+        /* First create the caller profile in the patterns Dialplan */
</ins><span class="cx">         if (!(tech_pvt-&gt;caller_profile = switch_caller_profile_new(switch_core_session_get_pool(nsession),
</span><del>-                                                                                                                  NULL, listener-&gt;profile-&gt;dialplan, 
</del><ins>+                                                                                                                  NULL, listener-&gt;profile-&gt;patterns_dialplan, 
</ins><span class="cx">                                                                                                                   button-&gt;shortname, button-&gt;name, 
</span><span class="cx">                                                                                                                   listener-&gt;remote_ip, NULL, NULL, NULL,
</span><span class="cx">                                                                                                                   &quot;skinny&quot; /* modname */,
</span><del>-                                                                                                                  listener-&gt;profile-&gt;context, 
</del><ins>+                                                                                                                  listener-&gt;profile-&gt;patterns_context, 
</ins><span class="cx">                                                                                                                   &quot;&quot;)) != 0) {
</span><span class="cx">             switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(nsession), SWITCH_LOG_CRIT, 
</span><span class="cx">                                 &quot;Error Creating Session caller profile\n&quot;);
</span><span class="lines">@@ -548,6 +549,75 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+skinny_action_t skinny_session_dest_match_pattern(switch_core_session_t *session, char **data)
+{
+        skinny_action_t action = SKINNY_ACTION_DROP;
+        switch_channel_t *channel = NULL;
+        private_t *tech_pvt = NULL;
+
+        switch_assert(session);
+        
+        channel = switch_core_session_get_channel(session);
+        tech_pvt = switch_core_session_get_private(session);
+
+        /* this part of the code is similar to switch_core_standard_on_routing() */
+        if (!zstr(tech_pvt-&gt;profile-&gt;patterns_dialplan)) {
+                switch_dialplan_interface_t *dialplan_interface = NULL;
+                switch_caller_extension_t *extension = NULL;
+                char *expanded = NULL;
+                char *dpstr = NULL;
+                char *dp[25];
+                int argc, x;
+
+                if ((dpstr = switch_core_session_strdup(session, tech_pvt-&gt;profile-&gt;patterns_dialplan))) {
+                        expanded = switch_channel_expand_variables(channel, dpstr);
+                        argc = switch_separate_string(expanded, ',', dp, (sizeof(dp) / sizeof(dp[0])));
+                        for (x = 0; x &lt; argc; x++) {
+                                char *dpname = dp[x];
+                                char *dparg = NULL;
+
+                                if (dpname) {
+                                        if ((dparg = strchr(dpname, ':'))) {
+                                                *dparg++ = '\0';
+                                        }
+                                } else {
+                                        continue;
+                                }
+                                if (!(dialplan_interface = switch_loadable_module_get_dialplan_interface(dpname))) {
+                                        continue;
+                                }
+
+                                extension = dialplan_interface-&gt;hunt_function(session, dparg, NULL);
+                                UNPROTECT_INTERFACE(dialplan_interface);
+
+                                if (extension) {
+                                        goto found;
+                                }
+                        }
+                }
+found:
+                while (extension &amp;&amp; extension-&gt;current_application) {
+                        switch_caller_application_t *current_application = extension-&gt;current_application;
+
+                        extension-&gt;current_application = extension-&gt;current_application-&gt;next;
+
+                        if (!strcmp(current_application-&gt;application_name, &quot;skinny-route&quot;)) {
+                                action = SKINNY_ACTION_ROUTE;
+                        } else if (!strcmp(current_application-&gt;application_name, &quot;skinny-drop&quot;)) {
+                                action = SKINNY_ACTION_DROP;
+                        } else if (!strcmp(current_application-&gt;application_name, &quot;skinny-wait&quot;)) {
+                                action = SKINNY_ACTION_WAIT;
+                                *data = switch_core_session_strdup(session, current_application-&gt;application_data);
+                        } else {
+                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, 
+                                                        &quot;Unknown skinny dialplan application %s\n&quot;, current_application-&gt;application_name);
+                        }
+                }
+        }
+        return action;
+}
+
+
</ins><span class="cx"> struct skinny_session_process_dest_helper {
</span><span class="cx">         private_t *tech_pvt;
</span><span class="cx">         listener_t *listener;
</span><span class="lines">@@ -597,8 +667,11 @@
</span><span class="cx"> 
</span><span class="cx"> switch_status_t skinny_session_process_dest(switch_core_session_t *session, listener_t *listener, uint32_t line_instance, char *dest, char append_dest, uint32_t backspace)
</span><span class="cx"> {
</span><ins>+        skinny_action_t action;
</ins><span class="cx">         switch_channel_t *channel = NULL;
</span><span class="cx">         private_t *tech_pvt = NULL;
</span><ins>+        char *data = NULL;
+        struct skinny_session_process_dest_helper helper = {0};
</ins><span class="cx"> 
</span><span class="cx">         switch_assert(session);
</span><span class="cx">         switch_assert(listener);
</span><span class="lines">@@ -633,19 +706,32 @@
</span><span class="cx">             tech_pvt-&gt;caller_profile-&gt;destination_number = switch_core_strdup(tech_pvt-&gt;caller_profile-&gt;pool,
</span><span class="cx">                 dest);
</span><span class="cx">         }
</span><del>-        /* TODO Number is complete -&gt; check against dialplan */
-        if ((strlen(tech_pvt-&gt;caller_profile-&gt;destination_number) &gt;= 4) || dest) {
-                struct skinny_session_process_dest_helper helper = {0};
-                send_dialed_number(listener, tech_pvt-&gt;caller_profile-&gt;destination_number, line_instance, tech_pvt-&gt;call_id);
-            skinny_line_set_state(listener, line_instance, tech_pvt-&gt;call_id, SKINNY_PROCEED);
-            skinny_send_call_info(session, listener, line_instance);
</del><ins>+        if(dest) {
+                action = SKINNY_ACTION_ROUTE;
+        } else {
+                action = skinny_session_dest_match_pattern(session, &amp;data);
+        }
+        switch(action) {
+                case SKINNY_ACTION_ROUTE:
+                        tech_pvt-&gt;caller_profile-&gt;dialplan = switch_core_strdup(tech_pvt-&gt;caller_profile-&gt;pool, listener-&gt;profile-&gt;dialplan);
+                        tech_pvt-&gt;caller_profile-&gt;context = switch_core_strdup(tech_pvt-&gt;caller_profile-&gt;pool, listener-&gt;profile-&gt;context);
+                        send_dialed_number(listener, tech_pvt-&gt;caller_profile-&gt;destination_number, line_instance, tech_pvt-&gt;call_id);
+                        skinny_line_set_state(listener, line_instance, tech_pvt-&gt;call_id, SKINNY_PROCEED);
+                        skinny_send_call_info(session, listener, line_instance);
</ins><span class="cx"> 
</span><del>-            skinny_session_start_media(session, listener, line_instance);
-            
-                helper.tech_pvt = tech_pvt;
-                helper.listener = listener;
-                helper.line_instance = line_instance;
-                skinny_session_walk_lines(tech_pvt-&gt;profile, switch_core_session_get_uuid(session), skinny_session_process_dest_callback, &amp;helper);
</del><ins>+                        skinny_session_start_media(session, listener, line_instance);
+                        
+                        helper.tech_pvt = tech_pvt;
+                        helper.listener = listener;
+                        helper.line_instance = line_instance;
+                        skinny_session_walk_lines(tech_pvt-&gt;profile, switch_core_session_get_uuid(session), skinny_session_process_dest_callback, &amp;helper);
+                        break;
+                case SKINNY_ACTION_WAIT:
+                        /* for now, wait forever */
+                        break;
+                case SKINNY_ACTION_DROP:
+                default:
+                        switch_channel_hangup(channel, SWITCH_CAUSE_UNALLOCATED_NUMBER);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>