<!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][15971] </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=15971">15971</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-12-15 13:22:57 -0600 (Tue, 15 Dec 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>convert mod_fifo to cache_db</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_fifomod_fifoc">freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodapplicationsmod_fifomod_fifoc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c (15970 => 15971)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c        2009-12-15 18:45:29 UTC (rev 15970)
+++ freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c        2009-12-15 19:22:57 UTC (rev 15971)
</span><span class="lines">@@ -277,50 +277,53 @@
</span><span class="cx">         char hostname[256];
</span><span class="cx">         char *dbname;
</span><span class="cx">         char *odbc_dsn;
</span><ins>+        char *odbc_user;
+        char *odbc_pass;
</ins><span class="cx">         int node_thread_running;
</span><span class="cx">         switch_odbc_handle_t *master_odbc;
</span><span class="cx"> } globals;
</span><span class="cx">
</span><span class="cx">
</span><ins>+switch_cache_db_handle_t *fifo_get_db_handle(void)
+{
+        switch_cache_db_connection_options_t options = { {0} };
+        switch_cache_db_handle_t *dbh = NULL;
+        
+        if (globals.odbc_dsn && globals.odbc_user && globals.odbc_pass) {
+                options.odbc_options.dsn = globals.odbc_dsn;
+                options.odbc_options.user = globals.odbc_user;
+                options.odbc_options.pass = globals.odbc_pass;
+
+                if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+                return dbh;
+        } else {
+                options.core_db_options.db_path = globals.dbname;
+                if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+                return dbh;
+        }
+}
+
+
</ins><span class="cx"> static switch_status_t fifo_execute_sql(char *sql, switch_mutex_t *mutex)
</span><span class="cx"> {
</span><del>-        switch_core_db_t *db;
-        switch_status_t status = SWITCH_STATUS_SUCCESS;
-        char *err_str;
</del><ins>+        switch_cache_db_handle_t *dbh = NULL;
+        switch_status_t status = SWITCH_STATUS_FALSE;
</ins><span class="cx">
</span><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_lock(mutex);
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if (switch_odbc_available() && globals.odbc_dsn) {
-                switch_odbc_statement_handle_t stmt;
-                if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
-                        
-                        err_str = switch_odbc_handle_get_error(globals.master_odbc, stmt);
-                        if (!zstr(err_str)) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
-                        }
-                        switch_safe_free(err_str);
-                        status = SWITCH_STATUS_FALSE;
-                }
-                switch_odbc_statement_handle_free(&stmt);
-        } else {
-                if (!(db = switch_core_db_open_file(globals.dbname))) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
-                        status = SWITCH_STATUS_FALSE;
-                        goto end;
-                }
-
-                err_str = NULL;
-                switch_core_db_exec(db, sql, NULL, NULL, &err_str);
-                if (err_str) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error [%s]\n[%s]\n", sql, err_str);
-                        free(err_str);
-                }
-                switch_core_db_close(db);
</del><ins>+        if (!(dbh = fifo_get_db_handle())) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+                goto end;
</ins><span class="cx">         }
</span><span class="cx">
</span><ins>+        status = switch_cache_db_execute_sql(dbh, sql, NULL);
+
</ins><span class="cx"> end:
</span><ins>+        
+        switch_cache_db_release_db_handle(&dbh);
+
</ins><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_unlock(mutex);
</span><span class="cx">         }
</span><span class="lines">@@ -331,34 +334,29 @@
</span><span class="cx"> static switch_bool_t fifo_execute_sql_callback(switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
</span><span class="cx"> {
</span><span class="cx">         switch_bool_t ret = SWITCH_FALSE;
</span><del>-        switch_core_db_t *db;
</del><span class="cx">         char *errmsg = NULL;
</span><del>-
</del><ins>+        switch_cache_db_handle_t *dbh = NULL;
+        
</ins><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_lock(mutex);
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if (switch_odbc_available() && globals.odbc_dsn) {
-                switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata, NULL);
-        } else {
-                if (!(db = switch_core_db_open_file(globals.dbname))) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
-                        goto end;
-                }
</del><ins>+        if (!(dbh = fifo_get_db_handle())) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+ goto end;
+ }
+        
+        switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
</ins><span class="cx">
</span><del>-                switch_core_db_exec(db, sql, callback, pdata, &errmsg);
-
-                if (errmsg) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
-                        free(errmsg);
-                }
-
-                if (db) {
-                        switch_core_db_close(db);
-                }
</del><ins>+        if (errmsg) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+                free(errmsg);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx"> end:
</span><ins>+
+        switch_cache_db_release_db_handle(&dbh);
+
</ins><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_unlock(mutex);
</span><span class="cx">         }
</span><span class="lines">@@ -1877,10 +1875,10 @@
</span><span class="cx">         switch_xml_t cfg, xml, fifo, fifos, member, settings, param;
</span><span class="cx">         char *odbc_user = NULL;
</span><span class="cx">         char *odbc_pass = NULL;
</span><del>-        switch_core_db_t *db;
</del><span class="cx">         switch_status_t status = SWITCH_STATUS_SUCCESS;        
</span><span class="cx">         char *sql;
</span><span class="cx">         switch_bool_t delete_all_outbound_member_on_startup = SWITCH_FALSE;
</span><ins>+        switch_cache_db_handle_t *dbh = NULL;
</ins><span class="cx">
</span><span class="cx">         gethostname(globals.hostname, sizeof(globals.hostname));
</span><span class="cx">
</span><span class="lines">@@ -1896,14 +1894,14 @@
</span><span class="cx">
</span><span class="cx">                         var = (char *) switch_xml_attr_soft(param, "name");
</span><span class="cx">                         val = (char *) switch_xml_attr_soft(param, "value");
</span><del>-
</del><ins>+                        
</ins><span class="cx">                         if (!strcasecmp(var, "odbc-dsn") && !zstr(val)) {
</span><span class="cx">                                 if (switch_odbc_available()) {
</span><span class="cx">                                         globals.odbc_dsn = switch_core_strdup(globals.pool, val);
</span><del>-                                        if ((odbc_user = strchr(globals.odbc_dsn, ':'))) {
</del><ins>+                                        if ((globals.odbc_user = strchr(globals.odbc_dsn, ':'))) {
</ins><span class="cx">                                                 *odbc_user++ = '\0';
</span><del>-                                                if ((odbc_pass = strchr(odbc_user, ':'))) {
-                                                        *odbc_pass++ = '\0';
</del><ins>+                                                if ((globals.odbc_pass = strchr(globals.odbc_user, ':'))) {
+                                                        *globals.odbc_pass++ = '\0';
</ins><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><span class="cx">                                 } else {
</span><span class="lines">@@ -1919,34 +1917,15 @@
</span><span class="cx">                 globals.dbname = "fifo";
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if (switch_odbc_available() && globals.odbc_dsn) {
-                if (!(globals.master_odbc = switch_odbc_handle_new(globals.odbc_dsn, odbc_user, odbc_pass))) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
-                        status = SWITCH_STATUS_FALSE;
-                        goto done;
-                }
-                if (switch_odbc_handle_connect(globals.master_odbc) != SWITCH_ODBC_SUCCESS) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
-                        status = SWITCH_STATUS_FALSE;
-                        goto done;
-                }
</del><ins>+        
</ins><span class="cx">
</span><del>-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.odbc_dsn);
-                if (switch_odbc_handle_exec(globals.master_odbc, "delete from fifo_outbound", NULL) != SWITCH_STATUS_SUCCESS) {
-                        if (switch_odbc_handle_exec(globals.master_odbc, (char *)outbound_sql, NULL) != SWITCH_STATUS_SUCCESS) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Create SQL Database!\n");
-                        }
-                }
-        } else {
-                if ((db = switch_core_db_open_file(globals.dbname))) {
-                        switch_core_db_test_reactive(db, "delete from fifo_outbound where static = 1", NULL, (char *)outbound_sql);
-                } else {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
-                        status = SWITCH_STATUS_FALSE;
-                        goto done;
-                }
-                switch_core_db_close(db);
</del><ins>+        if (!(dbh = fifo_get_db_handle())) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot open DB!\n");
+                goto done;
</ins><span class="cx">         }
</span><ins>+        
+        switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1", "drop table fifo_outbound", outbound_sql);
+        switch_cache_db_release_db_handle(&dbh);
</ins><span class="cx">
</span><span class="cx">         if (reload) {
</span><span class="cx">                 switch_hash_index_t *hi;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>