<!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][14889] </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=14889">14889</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-09-16 15:09:27 -0500 (Wed, 16 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre><a href="http://jira.freeswitch.org/browse/BOUNTY-9">BOUNTY-9</a> (Thank you Xpander Communications)</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeswitch_module_interfacesh">freeswitch/trunk/src/include/switch_module_interfaces.h</a></li>
<li><a href="#freeswitchtrunksrcincludeswitch_typesh">freeswitch/trunk/src/include/switch_types.h</a></li>
<li><a href="#freeswitchtrunksrcincludeswitch_utilsh">freeswitch/trunk/src/include/switch_utils.h</a></li>
<li><a href="#freeswitchtrunksrcswitch_core_filec">freeswitch/trunk/src/switch_core_file.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcincludeswitch_module_interfacesh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_module_interfaces.h (14888 => 14889)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_module_interfaces.h        2009-09-16 19:24:32 UTC (rev 14888)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h        2009-09-16 20:09:27 UTC (rev 14889)
</span><span class="lines">@@ -333,6 +333,8 @@
</span><span class="cx">         const char *file;
</span><span class="cx">         const char *func;
</span><span class="cx">         int line;
</span><ins>+        char *file_path;
+        char *spool_path;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> /*! \brief Abstract interface to an asr module */
</span></span></pre></div>
<a id="freeswitchtrunksrcincludeswitch_typesh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_types.h (14888 => 14889)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_types.h        2009-09-16 19:24:32 UTC (rev 14888)
+++ freeswitch/trunk/src/include/switch_types.h        2009-09-16 20:09:27 UTC (rev 14889)
</span><span class="lines">@@ -110,6 +110,7 @@
</span><span class="cx"> #define SWITCH_PATH_SEPARATOR "/"
</span><span class="cx"> #endif
</span><span class="cx"> #define SWITCH_URL_SEPARATOR "://"
</span><ins>+#define SWITCH_AUDIO_SPOOL_PATH_VARIABLE "audio_spool_path"
</ins><span class="cx"> #define SWITCH_BRIDGE_HANGUP_CAUSE_VARIABLE "bridge_hangup_cause"
</span><span class="cx"> #define SWITCH_READ_TERMINATOR_USED_VARIABLE "read_terminator_used"
</span><span class="cx"> #define SWITCH_SEND_SILENCE_WHEN_IDLE_VARIABLE "send_silence_when_idle"
</span></span></pre></div>
<a id="freeswitchtrunksrcincludeswitch_utilsh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_utils.h (14888 => 14889)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_utils.h        2009-09-16 19:24:32 UTC (rev 14888)
+++ freeswitch/trunk/src/include/switch_utils.h        2009-09-16 20:09:27 UTC (rev 14889)
</span><span class="lines">@@ -66,11 +66,9 @@
</span><span class="cx"> codec->implementation->iananame, \
</span><span class="cx"> codec->implementation->samples_per_second, \
</span><span class="cx"> codec->implementation->microseconds_per_packet / 1000)
</span><del>-#ifdef WIN32
-#define switch_is_file_path(file) (file && (*file == '\\' || *(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR)))
-#else
-#define switch_is_file_path(file) (file && ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)))
-#endif
</del><ins>+
+
+
</ins><span class="cx"> /*!
</span><span class="cx"> \brief Test for NULL or zero length string
</span><span class="cx"> \param s the string to test
</span><span class="lines">@@ -553,6 +551,30 @@
</span><span class="cx"> SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *from, const char *headers, const char *body, const char *file);
</span><span class="cx"> SWITCH_DECLARE(char *) switch_find_end_paren(const char *s, char open, char close);
</span><span class="cx">
</span><ins>+
+static inline switch_bool_t switch_is_file_path(const char *file)
+{
+        const char *e;
+        int r;
+
+        if (*file == '[' && *(file + 1) == *SWITCH_PATH_SEPARATOR) {
+                if ((e = switch_find_end_paren(file, '[', ']'))) {
+                        file = e + 1;
+                }
+        }
+
+#ifdef WIN32
+        r = (file && (*file == '\\' || *(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR)));
+#else
+        r = (file && ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR)));
+#endif
+
+        return r ? SWITCH_TRUE : SWITCH_FALSE;
+        
+}
+
+
+
</ins><span class="cx"> SWITCH_DECLARE(int) switch_parse_cidr(const char *string, uint32_t *ip, uint32_t *mask, uint32_t *bitp);
</span><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_network_list_create(switch_network_list_t **list, const char *name, switch_bool_t default_type, switch_memory_pool_t *pool);
</span><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_network_list_add_cidr_token(switch_network_list_t *list, const char *cidr_str, switch_bool_t ok, const char *token);
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_core_filec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core_file.c (14888 => 14889)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core_file.c        2009-09-16 19:24:32 UTC (rev 14888)
+++ freeswitch/trunk/src/switch_core_file.c        2009-09-16 20:09:27 UTC (rev 14889)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx">         switch_status_t status;
</span><span class="cx">         char stream_name[128] = "";
</span><span class="cx">         char *rhs = NULL;
</span><ins>+        const char *spool_path = NULL;
</ins><span class="cx">
</span><span class="cx">         if (switch_test_flag(fh, SWITCH_FILE_OPEN)) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Handle already open\n");
</span><span class="lines">@@ -56,6 +57,39 @@
</span><span class="cx">                 return SWITCH_STATUS_FALSE;
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        if (pool) {
+                fh->memory_pool = pool;
+        } else {
+                if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+                        UNPROTECT_INTERFACE(fh->file_interface);
+                        return status;
+                }
+                switch_set_flag(fh, SWITCH_FILE_FLAG_FREE_POOL);
+        }
+
+        fh->file_path = switch_core_strdup(fh->memory_pool, file_path);
+        
+        if ((flags & SWITCH_FILE_FLAG_WRITE)) {
+                char *p = fh->file_path, *e;
+                
+                if (*p == '[' && *(p + 1) == *SWITCH_PATH_SEPARATOR) {
+                        e = switch_find_end_paren(p, '[', ']');
+                        
+                        if (e) {
+                                *e = '\0';
+                                spool_path = p + 1;
+                                fh->file_path = e + 1;
+                        }
+                }
+
+                if (!spool_path) {
+                        spool_path = switch_core_get_variable(SWITCH_AUDIO_SPOOL_PATH_VARIABLE);
+                }
+                
+                file_path = fh->file_path;
+
+        }
+
</ins><span class="cx">         if ((rhs = strstr(file_path, SWITCH_URL_SEPARATOR))) {
</span><span class="cx">                 switch_copy_string(stream_name, file_path, (rhs + 1) - file_path);
</span><span class="cx">                 ext = stream_name;
</span><span class="lines">@@ -63,29 +97,28 @@
</span><span class="cx">         } else {
</span><span class="cx">                 if ((ext = strrchr(file_path, '.')) == 0) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown file Format [%s]\n", file_path);
</span><del>-                        return SWITCH_STATUS_FALSE;
</del><ins>+                        switch_goto_status(SWITCH_STATUS_FALSE, end);
</ins><span class="cx">                 }
</span><span class="cx">                 ext++;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ((fh->file_interface = switch_loadable_module_get_file_interface(ext)) == 0) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid file format [%s] for [%s]!\n", ext, file_path);
</span><del>-                return SWITCH_STATUS_GENERR;
</del><ins>+                switch_goto_status(SWITCH_STATUS_GENERR, end);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         fh->file = file;
</span><span class="cx">         fh->func = func;
</span><span class="cx">         fh->line = line;
</span><del>-
</del><span class="cx">         fh->flags = flags;
</span><del>-        if (pool) {
-                fh->memory_pool = pool;
-        } else {
-                if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
-                        UNPROTECT_INTERFACE(fh->file_interface);
-                        return status;
-                }
-                switch_set_flag(fh, SWITCH_FILE_FLAG_FREE_POOL);
</del><ins>+        
+        if (spool_path) {
+                char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
+                switch_uuid_t uuid;
+                switch_uuid_get(&uuid);
+                switch_uuid_format(uuid_str, &uuid);
+                
+                fh->spool_path = switch_core_sprintf(fh->memory_pool, "%s%s%s.%s", spool_path, SWITCH_PATH_SEPARATOR, uuid_str, ext);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (rhs) {
</span><span class="lines">@@ -104,12 +137,26 @@
</span><span class="cx">                 fh->channels = 1;
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        file_path = fh->spool_path ? fh->spool_path : fh->file_path;
+
+
</ins><span class="cx">         if ((status = fh->file_interface->file_open(fh, file_path)) != SWITCH_STATUS_SUCCESS) {
</span><ins>+                if (fh->spool_path) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Spool dir is set. Make sure [%s] is also a valid path\n", fh->spool_path);
+                }
</ins><span class="cx">                 UNPROTECT_INTERFACE(fh->file_interface);
</span><del>-                return status;
</del><ins>+                switch_goto_status(status, end);
</ins><span class="cx">         }
</span><span class="cx">
</span><ins>+        if ((status = switch_file_exists(file_path, fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "File [%s] not created!\n", fh->spool_path);
+                fh->file_interface->file_close(fh);
+                UNPROTECT_INTERFACE(fh->file_interface);
+                switch_goto_status(status, end);
+        }
</ins><span class="cx">
</span><ins>+
+
</ins><span class="cx">         if ((flags & SWITCH_FILE_FLAG_READ)) {
</span><span class="cx">                 fh->native_rate = fh->samplerate;
</span><span class="cx">         } else {
</span><span class="lines">@@ -135,6 +182,12 @@
</span><span class="cx">
</span><span class="cx">         switch_set_flag(fh, SWITCH_FILE_OPEN);
</span><span class="cx">
</span><ins>+ end:
+        
+        if (switch_test_flag(fh, SWITCH_FILE_FLAG_FREE_POOL)) {
+                switch_core_destroy_memory_pool(&fh->memory_pool);
+        }
+
</ins><span class="cx">         return status;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -449,6 +502,21 @@
</span><span class="cx">
</span><span class="cx">         switch_resample_destroy(&fh->resampler);
</span><span class="cx">
</span><ins>+
+        if (fh->spool_path) {
+                char *command;
+
+#ifdef _MSC_VER
+                command = switch_mprintf("move %s %s", fh->spool_path, fh->file_path);
+#else
+                command = switch_mprintf("/bin/mv %s %s", fh->spool_path, fh->file_path);
+#endif
+                system(command);
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Copy spooled file [%s] to [%s]\n", fh->spool_path, fh->file_path);
+                free(command);
+        }
+
+
</ins><span class="cx">         UNPROTECT_INTERFACE(fh->file_interface);
</span><span class="cx">
</span><span class="cx">         if (switch_test_flag(fh, SWITCH_FILE_FLAG_FREE_POOL)) {
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>