<!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->write_function(stream, "%s\n", line);
</span><span class="cx">         /* prefs */
</span><del>-        stream->write_function(stream, "Name \t%s\n", profile->name);
-        stream->write_function(stream, "Domain Name \t%s\n", profile->domain);
-        stream->write_function(stream, "IP \t%s\n", profile->ip);
-        stream->write_function(stream, "Port \t%d\n", profile->port);
-        stream->write_function(stream, "Dialplan \t%s\n", profile->dialplan);
-        stream->write_function(stream, "Context \t%s\n", profile->context);
-        stream->write_function(stream, "Keep-Alive \t%d\n", profile->keep_alive);
-        stream->write_function(stream, "Date-Format \t%s\n", profile->date_format);
-        stream->write_function(stream, "DBName \t%s\n", profile->dbname ? profile->dbname : switch_str_nil(profile->odbc_dsn));
-        stream->write_function(stream, "Debug \t%d\n", profile->debug);
</del><ins>+        stream->write_function(stream, "Name \t%s\n", profile->name);
+        stream->write_function(stream, "Domain Name \t%s\n", profile->domain);
+        stream->write_function(stream, "IP \t%s\n", profile->ip);
+        stream->write_function(stream, "Port \t%d\n", profile->port);
+        stream->write_function(stream, "Dialplan \t%s\n", profile->dialplan);
+        stream->write_function(stream, "Context \t%s\n", profile->context);
+        stream->write_function(stream, "Patterns-Dialplan \t%s\n", profile->patterns_dialplan);
+        stream->write_function(stream, "Patterns-Context \t%s\n", profile->patterns_context);
+        stream->write_function(stream, "Keep-Alive \t%d\n", profile->keep_alive);
+        stream->write_function(stream, "Date-Format \t%s\n", profile->date_format);
+        stream->write_function(stream, "DBName \t%s\n", profile->dbname ? profile->dbname : switch_str_nil(profile->odbc_dsn));
+        stream->write_function(stream, "Debug \t%d\n", profile->debug);
</ins><span class="cx">         /* stats */
</span><del>-        stream->write_function(stream, "CALLS-IN \t%d\n", profile->ib_calls);
-        stream->write_function(stream, "FAILED-CALLS-IN \t%d\n", profile->ib_failed_calls);
-        stream->write_function(stream, "CALLS-OUT \t%d\n", profile->ob_calls);
-        stream->write_function(stream, "FAILED-CALLS-OUT \t%d\n", profile->ob_failed_calls);
</del><ins>+        stream->write_function(stream, "CALLS-IN \t%d\n", profile->ib_calls);
+        stream->write_function(stream, "FAILED-CALLS-IN \t%d\n", profile->ib_failed_calls);
+        stream->write_function(stream, "CALLS-OUT \t%d\n", profile->ob_calls);
+        stream->write_function(stream, "FAILED-CALLS-OUT \t%d\n", profile->ob_failed_calls);
</ins><span class="cx">         /* listener */
</span><span class="cx">         stream->write_function(stream, "Listener-Threads \t%d\n", profile->listener_threads);
</span><span class="cx">         stream->write_function(stream, "%s\n", line);
</span><span class="lines">@@ -1429,6 +1431,10 @@
</span><span class="cx">                 profile->dialplan = switch_core_strdup(profile->pool, val);
</span><span class="cx">         } else if (!strcasecmp(var, "context")) {
</span><span class="cx">                 profile->context = switch_core_strdup(profile->pool, val);
</span><ins>+        } else if (!strcasecmp(var, "patterns-dialplan")) {
+                profile->patterns_dialplan = switch_core_strdup(profile->pool, val);
+        } else if (!strcasecmp(var, "patterns-context")) {
+                profile->patterns_context = switch_core_strdup(profile->pool, val);
</ins><span class="cx">         } else if (!strcasecmp(var, "date-format")) {
</span><span class="cx">                 strncpy(profile->date_format, val, 6);
</span><span class="cx">         } else if (!strcasecmp(var, "odbc-dsn") && !zstr(val)) {
</span><span class="lines">@@ -1499,6 +1505,10 @@
</span><span class="cx">                                                 skinny_profile_set(profile, "dialplan", val);
</span><span class="cx">                                         } else if (!strcmp(var, "context")) {
</span><span class="cx">                                                 skinny_profile_set(profile, "context", val);
</span><ins>+                                        } else if (!strcmp(var, "patterns-dialplan")) {
+                                                skinny_profile_set(profile, "patterns-dialplan", val);
+                                        } else if (!strcmp(var, "patterns-context")) {
+                                                skinny_profile_set(profile, "patterns-context", val);
</ins><span class="cx">                                         } else if (!strcmp(var, "keep-alive")) {
</span><span class="cx">                                                 profile->keep_alive = atoi(val);
</span><span class="cx">                                         } else if (!strcmp(var, "date-format")) {
</span><span class="lines">@@ -1511,13 +1521,21 @@
</span><span class="cx">                                 } /* param */
</span><span class="cx">                 
</span><span class="cx">                                 if (!profile->dialplan) {
</span><del>-                                        skinny_profile_set(profile, "dialplan","default");
</del><ins>+                                        skinny_profile_set(profile, "dialplan","XML");
</ins><span class="cx">                                 }
</span><span class="cx">
</span><span class="cx">                                 if (!profile->context) {
</span><del>-                                        skinny_profile_set(profile, "context","public");
</del><ins>+                                        skinny_profile_set(profile, "context","default");
</ins><span class="cx">                                 }
</span><span class="cx">
</span><ins>+                                if (!profile->patterns_dialplan) {
+                                        skinny_profile_set(profile, "patterns-dialplan","XML");
+                                }
+
+                                if (!profile->patterns_context) {
+                                        skinny_profile_set(profile, "patterns-context","skinny-patterns");
+                                }
+
</ins><span class="cx">                                 if (profile->port == 0) {
</span><span class="cx">                                         profile->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">                  "Error Locking Session\n");
</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->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(nsession),
</span><del>-                                                                                                         NULL, listener->profile->dialplan,
</del><ins>+                                                                                                         NULL, listener->profile->patterns_dialplan,
</ins><span class="cx">                                                                                                          button->shortname, button->name,
</span><span class="cx">                                                                                                          listener->remote_ip, NULL, NULL, NULL,
</span><span class="cx">                                                                                                          "skinny" /* modname */,
</span><del>-                                                                                                         listener->profile->context,
</del><ins>+                                                                                                         listener->profile->patterns_context,
</ins><span class="cx">                                                                                                          "")) != 0) {
</span><span class="cx">          switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(nsession), SWITCH_LOG_CRIT,
</span><span class="cx">          "Error Creating Session caller profile\n");
</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->profile->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->profile->patterns_dialplan))) {
+                        expanded = switch_channel_expand_variables(channel, dpstr);
+                        argc = switch_separate_string(expanded, ',', dp, (sizeof(dp) / sizeof(dp[0])));
+                        for (x = 0; x < 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->hunt_function(session, dparg, NULL);
+                                UNPROTECT_INTERFACE(dialplan_interface);
+
+                                if (extension) {
+                                        goto found;
+                                }
+                        }
+                }
+found:
+                while (extension && extension->current_application) {
+                        switch_caller_application_t *current_application = extension->current_application;
+
+                        extension->current_application = extension->current_application->next;
+
+                        if (!strcmp(current_application->application_name, "skinny-route")) {
+                                action = SKINNY_ACTION_ROUTE;
+                        } else if (!strcmp(current_application->application_name, "skinny-drop")) {
+                                action = SKINNY_ACTION_DROP;
+                        } else if (!strcmp(current_application->application_name, "skinny-wait")) {
+                                action = SKINNY_ACTION_WAIT;
+                                *data = switch_core_session_strdup(session, current_application->application_data);
+                        } else {
+                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
+                                         "Unknown skinny dialplan application %s\n", current_application->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->caller_profile->destination_number = switch_core_strdup(tech_pvt->caller_profile->pool,
</span><span class="cx">          dest);
</span><span class="cx">         }
</span><del>-        /* TODO Number is complete -> check against dialplan */
-        if ((strlen(tech_pvt->caller_profile->destination_number) >= 4) || dest) {
-                struct skinny_session_process_dest_helper helper = {0};
-                send_dialed_number(listener, tech_pvt->caller_profile->destination_number, line_instance, tech_pvt->call_id);
-         skinny_line_set_state(listener, line_instance, tech_pvt->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, &data);
+        }
+        switch(action) {
+                case SKINNY_ACTION_ROUTE:
+                        tech_pvt->caller_profile->dialplan = switch_core_strdup(tech_pvt->caller_profile->pool, listener->profile->dialplan);
+                        tech_pvt->caller_profile->context = switch_core_strdup(tech_pvt->caller_profile->pool, listener->profile->context);
+                        send_dialed_number(listener, tech_pvt->caller_profile->destination_number, line_instance, tech_pvt->call_id);
+                        skinny_line_set_state(listener, line_instance, tech_pvt->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->profile, switch_core_session_get_uuid(session), skinny_session_process_dest_callback, &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->profile, switch_core_session_get_uuid(session), skinny_session_process_dest_callback, &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>