<!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][17086] </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=17086">17086</a></dd>
<dt>Author</dt> <dd>rupa</dd>
<dt>Date</dt> <dd>2010-03-24 11:17:58 -0500 (Wed, 24 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>merge branch up to 17085</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchbranchesrupa_limitconfautoload_configsnibblebillconfxml">freeswitch/branches/rupa_limit/conf/autoload_configs/nibblebill.conf.xml</a></li>
<li><a href="#freeswitchbranchesrupa_limitsrcincludeswitch_coreh">freeswitch/branches/rupa_limit/src/include/switch_core.h</a></li>
<li><a href="#freeswitchbranchesrupa_limitsrcincludeswitch_typesh">freeswitch/branches/rupa_limit/src/include/switch_types.h</a></li>
<li><a href="#freeswitchbranchesrupa_limitsrcmodapplicationsmod_dptoolsmod_dptoolsc">freeswitch/branches/rupa_limit/src/mod/applications/mod_dptools/mod_dptools.c</a></li>
<li><a href="#freeswitchbranchesrupa_limitsrcmodapplicationsmod_hashmod_hashc">freeswitch/branches/rupa_limit/src/mod/applications/mod_hash/mod_hash.c</a></li>
<li><a href="#freeswitchbranchesrupa_limitsrcmodapplicationsmod_nibblebillmod_nibblebillc">freeswitch/branches/rupa_limit/src/mod/applications/mod_nibblebill/mod_nibblebill.c</a></li>
<li><a href="#freeswitchbranchesrupa_limitsrcmodendpointsmod_skypopenalsadummyc">freeswitch/branches/rupa_limit/src/mod/endpoints/mod_skypopen/alsa/dummy.c</a></li>
<li><a href="#freeswitchbranchesrupa_limitsrcswitch_core_hashc">freeswitch/branches/rupa_limit/src/switch_core_hash.c</a></li>
<li><a href="#freeswitchbranchesrupa_limitsrcswitch_limitc">freeswitch/branches/rupa_limit/src/switch_limit.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchbranchesrupa_limitconfautoload_configsnibblebillconfxml"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/conf/autoload_configs/nibblebill.conf.xml (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/conf/autoload_configs/nibblebill.conf.xml        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/conf/autoload_configs/nibblebill.conf.xml        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -16,7 +16,21 @@
</span><span class="cx">     &lt;!-- The column name for the unique ID identifying the account --&gt;
</span><span class="cx">     &lt;param name=&quot;db_column_account&quot; value=&quot;id&quot;/&gt;
</span><span class="cx"> 
</span><ins>+    &lt;!-- Custom SQL for loading current balance - overrides column names
+         channel vars are interpreted.
+         field nibble_balance is used for balance info
</ins><span class="cx"> 
</span><ins>+    &lt;param name=&quot;custom_sql_lookup&quot; value=&quot;SELECT cash AS nibble_balance FROM accounts WHERE account_code='${nibble_account}'&quot;/&gt;
+    --&gt;
+
+    &lt;!-- Custom SQL for loading current balance - overrides column names
+         channel vars are interpreted.
+         nibble_increment is the amount to update
+
+    &lt;param name=&quot;custom_sql_save&quot; value=&quot;UPDATE accounts SET cash=cash-${nibble_increment} WHERE account_code='${nibble_account}'&quot;/&gt;
+    --&gt;
+
+
</ins><span class="cx">     &lt;!-- Default heartbeat interval. Set to 'off' for no heartbeat (i.e. bill only at end of call) --&gt;
</span><span class="cx">     &lt;param name=&quot;global_heartbeat&quot; value=&quot;60&quot;/&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="freeswitchbranchesrupa_limitsrcincludeswitch_coreh"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/src/include/switch_core.h (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/src/include/switch_core.h        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/src/include/switch_core.h        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -1202,6 +1202,14 @@
</span><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex);
</span><span class="cx"> 
</span><span class="cx"> /*! 
</span><ins>+  \brief Delete data from a hash based on callback function
+  \param hash the hash to delete from
+  \param callback the function to call which returns SWITCH_TRUE to delete, SWITCH_FALSE to preserve
+  \return SWITCH_STATUS_SUCCESS if any data is deleted
+*/
+SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_multi(_In_ switch_hash_t *hash, _In_ switch_hash_delete_callback_t callback, _In_opt_ void *pData);
+
+/*! 
</ins><span class="cx">   \brief Retrieve data from a given hash
</span><span class="cx">   \param hash the hash to retrieve from
</span><span class="cx">   \param key the key to retrieve
</span></span></pre></div>
<a id="freeswitchbranchesrupa_limitsrcincludeswitch_typesh"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/src/include/switch_types.h (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/src/include/switch_types.h        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/src/include/switch_types.h        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -1562,6 +1562,8 @@
</span><span class="cx"> typedef switch_caller_extension_t *(*switch_dialplan_hunt_function_t) (switch_core_session_t *, void *, switch_caller_profile_t *);
</span><span class="cx"> #define SWITCH_STANDARD_DIALPLAN(name) static switch_caller_extension_t *name (switch_core_session_t *session, void *arg, switch_caller_profile_t *caller_profile)
</span><span class="cx"> 
</span><ins>+typedef switch_bool_t (*switch_hash_delete_callback_t) (_In_ const void *key, _In_ const void *val, _In_opt_ void *pData);
+#define SWITCH_HASH_DELETE_FUNC(name) static switch_bool_t name (const void *key, const void *val, void *pData)
</ins><span class="cx"> 
</span><span class="cx"> typedef struct switch_scheduler_task switch_scheduler_task_t;
</span><span class="cx"> 
</span></span></pre></div>
<a id="freeswitchbranchesrupa_limitsrcmodapplicationsmod_dptoolsmod_dptoolsc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/src/mod/applications/mod_dptools/mod_dptools.c (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/src/mod/applications/mod_dptools/mod_dptools.c        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/src/mod/applications/mod_dptools/mod_dptools.c        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -3014,7 +3014,7 @@
</span><span class="cx">                         max = -1;
</span><span class="cx">                 } else {
</span><span class="cx">                         char *szinterval = NULL;
</span><del>-                        if ((szinterval = strchr(argv[2], '/'))) {
</del><ins>+                        if ((szinterval = strchr(argv[3], '/'))) {
</ins><span class="cx">                                 *szinterval++ = '\0';
</span><span class="cx">                                 interval = atoi(szinterval);
</span><span class="cx">                         }
</span></span></pre></div>
<a id="freeswitchbranchesrupa_limitsrcmodapplicationsmod_hashmod_hashc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/src/mod/applications/mod_hash/mod_hash.c (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/src/mod/applications/mod_hash/mod_hash.c        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/src/mod/applications/mod_hash/mod_hash.c        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -91,6 +91,7 @@
</span><span class="cx">         /* Check if that realm+resource has ever been checked */
</span><span class="cx">         if (!(item = (limit_hash_item_t *) switch_core_hash_find(globals.limit_hash, hashkey))) {
</span><span class="cx">                 /* No, create an empty structure and add it, then continue like as if it existed */
</span><ins>+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10, &quot;Creating new limit structure: key: %s\n&quot;, hashkey);
</ins><span class="cx">                 item = (limit_hash_item_t *) malloc(sizeof(limit_hash_item_t));
</span><span class="cx">                 switch_assert(item);
</span><span class="cx">                 memset(item, 0, sizeof(limit_hash_item_t));
</span><span class="lines">@@ -105,7 +106,7 @@
</span><span class="cx">                  */
</span><span class="cx">                 increment = !switch_core_hash_find(pvt-&gt;hash, hashkey);
</span><span class="cx">         } else {
</span><del>-                /* This is the first limit check on this channel, create a hashtable, set our prviate data and add a state handler */
</del><ins>+                /* This is the first limit check on this channel, create a hashtable, set our prviate data */
</ins><span class="cx">                 pvt = (limit_hash_private_t *) switch_core_session_alloc(session, sizeof(limit_hash_private_t));
</span><span class="cx">                 memset(pvt, 0, sizeof(limit_hash_private_t));
</span><span class="cx">                 switch_core_hash_init(&amp;pvt-&gt;hash, switch_core_session_get_pool(session));
</span><span class="lines">@@ -116,6 +117,8 @@
</span><span class="cx">                 if (item-&gt;last_check &lt;= (now - interval)) {
</span><span class="cx">                         item-&gt;rate_usage = 1;
</span><span class="cx">                         item-&gt;last_check = now;
</span><ins>+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG10, &quot;Usage for %s reset to 1\n&quot;,
+                                                          hashkey);
</ins><span class="cx">                 } else {
</span><span class="cx">                         /* Always increment rate when its checked as it doesnt depend on the channel */
</span><span class="cx">                         item-&gt;rate_usage++;
</span><span class="lines">@@ -197,7 +200,7 @@
</span><span class="cx">                         item-&gt;total_usage--;
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Usage for %s is now %d\n&quot;, (const char *) key, item-&gt;total_usage);
</span><span class="cx"> 
</span><del>-                        if (item-&gt;total_usage == 0) {
</del><ins>+                        if (item-&gt;total_usage == 0 &amp;&amp; item-&gt;rate_usage == 0) {
</ins><span class="cx">                                 /* Noone is using this item anymore */
</span><span class="cx">                                 switch_core_hash_delete(globals.limit_hash, (const char *) key);
</span><span class="cx">                                 free(item);
</span><span class="lines">@@ -214,7 +217,7 @@
</span><span class="cx"> 
</span><span class="cx">                         switch_core_hash_delete(pvt-&gt;hash, hashkey);
</span><span class="cx"> 
</span><del>-                        if (item-&gt;total_usage == 0) {
</del><ins>+                        if (item-&gt;total_usage == 0 &amp;&amp; item-&gt;rate_usage == 0) {
</ins><span class="cx">                                 /* Noone is using this item anymore */
</span><span class="cx">                                 switch_core_hash_delete(globals.limit_hash, (const char *) hashkey);
</span><span class="cx">                                 free(item);
</span></span></pre></div>
<a id="freeswitchbranchesrupa_limitsrcmodapplicationsmod_nibblebillmod_nibblebillc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/src/mod/applications/mod_nibblebill/mod_nibblebill.c (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/src/mod/applications/mod_nibblebill/mod_nibblebill.c        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/src/mod/applications/mod_nibblebill/mod_nibblebill.c        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx"> #include &lt;switch.h&gt;
</span><span class="cx"> 
</span><span class="cx"> /* Defaults */
</span><del>-static char SQL_LOOKUP[] = &quot;SELECT %s FROM %s WHERE %s='%s'&quot;;
</del><ins>+static char SQL_LOOKUP[] = &quot;SELECT %s AS nibble_balance FROM %s WHERE %s='%s'&quot;;
</ins><span class="cx"> static char SQL_SAVE[] = &quot;UPDATE %s SET %s=%s-%f WHERE %s='%s'&quot;;
</span><span class="cx"> 
</span><span class="cx"> typedef struct {
</span><span class="lines">@@ -101,6 +101,8 @@
</span><span class="cx">         char *db_table;
</span><span class="cx">         char *db_column_cash;
</span><span class="cx">         char *db_column_account;
</span><ins>+        char *custom_sql_save;
+        char *custom_sql_lookup;
</ins><span class="cx">         switch_odbc_handle_t *master_odbc;
</span><span class="cx"> } globals;
</span><span class="cx"> 
</span><span class="lines">@@ -125,16 +127,23 @@
</span><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_db_table, globals.db_table);
</span><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_db_column_cash, globals.db_column_cash);
</span><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_db_column_account, globals.db_column_account);
</span><ins>+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_custom_sql_save, globals.custom_sql_save);
+SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_custom_sql_lookup, globals.custom_sql_lookup);
</ins><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_percall_action, globals.percall_action);
</span><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_lowbal_action, globals.lowbal_action);
</span><span class="cx"> SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_nobal_action, globals.nobal_action);
</span><span class="cx"> 
</span><span class="cx"> static int nibblebill_callback(void *pArg, int argc, char **argv, char **columnNames)
</span><span class="cx"> {
</span><ins>+        int i = 0;
</ins><span class="cx">         nibblebill_results_t *cbt = (nibblebill_results_t *) pArg;
</span><span class="cx"> 
</span><del>-        cbt-&gt;balance = (float) atof(argv[0]);
-
</del><ins>+        for (i = 0; i &lt; argc; i++) {
+                if (!strcasecmp(columnNames[i], &quot;nibble_balance&quot;)) {
+                        cbt-&gt;balance = (float) atof(argv[0]);
+                }
+        }
+        
</ins><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -167,6 +176,10 @@
</span><span class="cx">                                 set_global_db_column_cash(val);
</span><span class="cx">                         } else if (!strcasecmp(var, &quot;db_column_account&quot;)) {
</span><span class="cx">                                 set_global_db_column_account(val);
</span><ins>+                        } else if (!strcasecmp(var, &quot;custom_sql_save&quot;)) {
+                                set_global_custom_sql_save(val);
+                        } else if (!strcasecmp(var, &quot;custom_sql_lookup&quot;)) {
+                                set_global_custom_sql_lookup(val);
</ins><span class="cx">                         } else if (!strcasecmp(var, &quot;percall_action&quot;)) {
</span><span class="cx">                                 set_global_percall_action(val);
</span><span class="cx">                         } else if (!strcasecmp(var, &quot;percall_max_amt&quot;)) {
</span><span class="lines">@@ -285,17 +298,29 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> /* At this time, billing never succeeds if you don't have a database. */
</span><del>-static switch_status_t bill_event(float billamount, const char *billaccount)
</del><ins>+static switch_status_t bill_event(float billamount, const char *billaccount, switch_channel_t *channel)
</ins><span class="cx"> {
</span><del>-        char sql[1024] = &quot;&quot;;
-        switch_odbc_statement_handle_t stmt;
</del><ins>+        switch_stream_handle_t sql_stream = { 0 };
+        char *sql = NULL;
+        switch_odbc_statement_handle_t stmt = NULL;
+        SWITCH_STANDARD_STREAM(sql_stream);
</ins><span class="cx"> 
</span><span class="cx">         if (!switch_odbc_available()) {
</span><del>-                return SWITCH_STATUS_SUCCESS;
</del><ins>+                goto end;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        switch_snprintf(sql, 1024, SQL_SAVE, globals.db_table, globals.db_column_cash, globals.db_column_cash, billamount, globals.db_column_account,
-                                        billaccount);
</del><ins>+        if (globals.custom_sql_save) {
+                if (switch_string_var_check_const(globals.custom_sql_save) || switch_string_has_escaped_data(globals.custom_sql_save)) {
+                        switch_channel_set_variable_printf(channel, &quot;nibble_increment&quot;, &quot;%f&quot;, billamount, SWITCH_FALSE);
+                        sql = switch_channel_expand_variables(channel, globals.custom_sql_save);
+                } else {
+                        sql = globals.custom_sql_save;
+                }
+        } else {
+                sql_stream.write_function(&amp;sql_stream, SQL_SAVE, globals.db_table, globals.db_column_cash, globals.db_column_cash, billamount, globals.db_column_account,
+                                                billaccount);
+                sql = sql_stream.data;
+        }
</ins><span class="cx">         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;Doing update query\n[%s]\n&quot;, sql);
</span><span class="cx"> 
</span><span class="cx">         if (switch_odbc_handle_exec(globals.master_odbc, sql, &amp;stmt, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="lines">@@ -306,40 +331,63 @@
</span><span class="cx">         } else {
</span><span class="cx">                 /* TODO: Failover to a flat/text file if DB is unavailable */
</span><span class="cx"> 
</span><del>-                return SWITCH_STATUS_SUCCESS;
</del><ins>+                goto end;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_odbc_statement_handle_free(&amp;stmt);
</span><span class="cx"> 
</span><ins>+end:
+        if (sql != globals.custom_sql_save) {
+                switch_safe_free(sql);
+        }
</ins><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-static float get_balance(const char *billaccount)
</del><ins>+static float get_balance(const char *billaccount, switch_channel_t *channel)
</ins><span class="cx"> {
</span><del>-        char sql[1024] = &quot;&quot;;
</del><ins>+        switch_stream_handle_t sql_stream = { 0 };
+        char *sql = NULL;
</ins><span class="cx">         nibblebill_results_t pdata;
</span><span class="cx">         float balance = 0.00f;
</span><ins>+        SWITCH_STANDARD_STREAM(sql_stream);
</ins><span class="cx"> 
</span><span class="cx">         if (!switch_odbc_available()) {
</span><del>-                return -1.00f;
</del><ins>+                balance = -1.00f;
+                goto end;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         memset(&amp;pdata, 0, sizeof(pdata));
</span><del>-        snprintf(sql, 1024, SQL_LOOKUP, globals.db_column_cash, globals.db_table, globals.db_column_account, billaccount);
</del><span class="cx"> 
</span><ins>+        if (globals.custom_sql_lookup) {
+                if (switch_string_var_check_const(globals.custom_sql_lookup) || switch_string_has_escaped_data(globals.custom_sql_lookup)) {
+                        sql = switch_channel_expand_variables(channel, globals.custom_sql_lookup);
+                } else {
+                        sql = globals.custom_sql_lookup;
+                }
+        } else {
+                sql_stream.write_function(&amp;sql_stream, SQL_LOOKUP, globals.db_column_cash, globals.db_table, globals.db_column_account, billaccount);
+                sql = sql_stream.data;
+        }
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;Doing lookup query\n[%s]\n&quot;, sql);
+        
</ins><span class="cx">         if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, nibblebill_callback, &amp;pdata, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error running this query: [%s]\n&quot;, sql);
</span><span class="cx">                 /* Return -1 for safety */
</span><span class="cx"> 
</span><del>-                return -1.00f;
</del><ins>+                balance = -1.00f;
+                goto end;
</ins><span class="cx">         } else {
</span><span class="cx">                 /* Successfully retrieved! */
</span><span class="cx">                 balance = pdata.balance;
</span><span class="cx"> 
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;Retrieved current balance for account %s (balance = %f)\n&quot;, billaccount, balance);
</span><span class="cx">         }
</span><del>-
</del><ins>+        
+end:
+        if (sql != globals.custom_sql_lookup) {
+                switch_safe_free(sql);
+        }
</ins><span class="cx">         return balance;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -408,7 +456,7 @@
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Not billing %s - call is not in answered state\n&quot;, billaccount);
</span><span class="cx"> 
</span><span class="cx">                 /* See if this person has enough money left to continue the call */
</span><del>-                balance = get_balance(billaccount);
</del><ins>+                balance = get_balance(billaccount, channel);
</ins><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;Comparing %f to hangup balance of %f\n&quot;, balance, nobal_amt);
</span><span class="cx">                 if (balance &lt;= nobal_amt) {
</span><span class="cx">                         /* Not enough money - reroute call to nobal location */
</span><span class="lines">@@ -464,7 +512,7 @@
</span><span class="cx">                                                   uuid, nibble_data-&gt;total);
</span><span class="cx"> 
</span><span class="cx">                 /* DO ODBC BILLING HERE and reset counters if it's successful! */
</span><del>-                if (bill_event(billamount, billaccount) == SWITCH_STATUS_SUCCESS) {
</del><ins>+                if (bill_event(billamount, billaccount, channel) == SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">                         /* Increment total cost */
</span><span class="cx">                         nibble_data-&gt;total += billamount;
</span><span class="cx"> 
</span><span class="lines">@@ -491,7 +539,7 @@
</span><span class="cx">                 /* don't verify balance and transfer to nobal if we're done with call */
</span><span class="cx">                 if (switch_channel_get_state(channel) != CS_REPORTING &amp;&amp; switch_channel_get_state(channel) != CS_HANGUP) {
</span><span class="cx">                         /* See if this person has enough money left to continue the call */
</span><del>-                        balance = get_balance(billaccount);
</del><ins>+                        balance = get_balance(billaccount, channel);
</ins><span class="cx">                         if (balance &lt;= nobal_amt) {
</span><span class="cx">                                 /* Not enough money - reroute call to nobal location */
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, &quot;Balance of %f fell below allowed amount of %f! (Account %s)\n&quot;,
</span><span class="lines">@@ -719,7 +767,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /* Add or remove amount from adjusted billing here. Note, we bill the OPPOSITE */
</span><del>-        if (bill_event(-amount, billaccount) == SWITCH_STATUS_SUCCESS) {
</del><ins>+        if (bill_event(-amount, billaccount, channel) == SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Recorded adjustment to %s for $%f\n&quot;, billaccount, amount);
</span><span class="cx">         } else {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Failed to record adjustment to %s for $%f\n&quot;, billaccount, amount);
</span><span class="lines">@@ -846,7 +894,7 @@
</span><span class="cx"> 
</span><span class="cx">         billaccount = switch_channel_get_variable(channel, &quot;nibble_account&quot;);
</span><span class="cx">         if (billaccount) {
</span><del>-                switch_channel_set_variable_printf(channel, &quot;nibble_current_balance&quot;, &quot;%f&quot;, get_balance(billaccount));
</del><ins>+                switch_channel_set_variable_printf(channel, &quot;nibble_current_balance&quot;, &quot;%f&quot;, get_balance(billaccount, channel));
</ins><span class="cx">         }                        
</span><span class="cx">         
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span></span></pre></div>
<a id="freeswitchbranchesrupa_limitsrcmodendpointsmod_skypopenalsadummyc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/src/mod/endpoints/mod_skypopen/alsa/dummy.c (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/src/mod/endpoints/mod_skypopen/alsa/dummy.c        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/src/mod/endpoints/mod_skypopen/alsa/dummy.c        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -18,7 +18,7 @@
</span><span class="cx">  *
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#include &lt;sound/driver.h&gt;                //giova
</del><ins>+//#include &lt;sound/driver.h&gt;                //giova
</ins><span class="cx"> #include &lt;linux/init.h&gt;
</span><span class="cx"> #include &lt;linux/err.h&gt;
</span><span class="cx"> #include &lt;linux/platform_device.h&gt;
</span><span class="lines">@@ -106,6 +106,7 @@
</span><span class="cx">         struct snd_pcm_substream *substream;
</span><span class="cx">         struct snd_dummy_pcm *dpcm;
</span><span class="cx">         int started;
</span><ins>+        int elapsed;
</ins><span class="cx"> };
</span><span class="cx"> static struct giovadpcm giovadpcms[MAX_PCM_SUBSTREAMS];
</span><span class="cx"> 
</span><span class="lines">@@ -127,8 +128,8 @@
</span><span class="cx"> 
</span><span class="cx"> struct snd_dummy_pcm {
</span><span class="cx">         struct snd_dummy *dummy;
</span><del>-        spinlock_t lock;
-        struct timer_list timer;
</del><ins>+        //spinlock_t lock;
+        //struct timer_list timer;
</ins><span class="cx">         unsigned int pcm_buffer_size;
</span><span class="cx">         unsigned int pcm_period_size;
</span><span class="cx">         unsigned int pcm_bps;                /* bytes per second */
</span><span class="lines">@@ -171,6 +172,7 @@
</span><span class="cx">                 }
</span><span class="cx">                 if (giovadpcms[i].dpcm == dpcm) {
</span><span class="cx">                         giovadpcms[i].started = 0;
</span><ins>+                        giovadpcms[i].elapsed = 0;
</ins><span class="cx">                         found = 1;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -234,6 +236,7 @@
</span><span class="cx">         giovatimer.expires = 1 + jiffies;
</span><span class="cx">         add_timer(&amp;giovatimer);
</span><span class="cx"> 
</span><ins>+        spin_lock_bh(&amp;giovalock);
</ins><span class="cx">         for (i = 0; i &lt; giovaindex + 1; i++) {
</span><span class="cx"> 
</span><span class="cx">                 if (i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS) {
</span><span class="lines">@@ -246,18 +249,38 @@
</span><span class="cx">                         printk(&quot;giova: timer_func %d %d NULL: continue\n&quot;, __LINE__, i);
</span><span class="cx">                         continue;
</span><span class="cx">                 }
</span><del>-                spin_lock_bh(&amp;dpcm-&gt;lock);
-                dpcm-&gt;pcm_irq_pos += dpcm-&gt;pcm_bps;
-                dpcm-&gt;pcm_buf_pos += dpcm-&gt;pcm_bps;
</del><ins>+                //spin_lock_bh(&amp;dpcm-&gt;lock);
+                dpcm-&gt;pcm_irq_pos += dpcm-&gt;pcm_bps * 1;
+                dpcm-&gt;pcm_buf_pos += dpcm-&gt;pcm_bps * 1;
</ins><span class="cx">                 dpcm-&gt;pcm_buf_pos %= dpcm-&gt;pcm_buffer_size * dpcm-&gt;pcm_hz;
</span><span class="cx">                 if (dpcm-&gt;pcm_irq_pos &gt;= dpcm-&gt;pcm_period_size * dpcm-&gt;pcm_hz) {
</span><span class="cx">                         dpcm-&gt;pcm_irq_pos %= dpcm-&gt;pcm_period_size * dpcm-&gt;pcm_hz;
</span><del>-                        spin_unlock_bh(&amp;dpcm-&gt;lock);
-                        snd_pcm_period_elapsed(dpcm-&gt;substream);
</del><ins>+                        //spin_unlock_bh(&amp;dpcm-&gt;lock);
+                        //snd_pcm_period_elapsed(dpcm-&gt;substream);
+                        giovadpcms[i].elapsed = 1;
</ins><span class="cx">                 } else {
</span><del>-                        spin_unlock_bh(&amp;dpcm-&gt;lock);
</del><ins>+                        //spin_unlock_bh(&amp;dpcm-&gt;lock);
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><ins>+        spin_unlock_bh(&amp;giovalock);
+        for (i = 0; i &lt; giovaindex + 1; i++) {
+
+                if (i &gt; MAX_PCM_SUBSTREAMS || giovaindex &gt; MAX_PCM_SUBSTREAMS) {
+                        printk(&quot;giova, %s:%d, i=%d, giovaindex=%d dpcm=%p\n&quot;, __FILE__, __LINE__, i, giovaindex, dpcm);
+                }
+                if (giovadpcms[i].started != 1)
+                        continue;
+                dpcm = giovadpcms[i].dpcm;
+                if (dpcm == NULL) {
+                        printk(&quot;giova: timer_func %d %d NULL: continue\n&quot;, __LINE__, i);
+                        continue;
+                }
+                if (giovadpcms[i].elapsed){
+                        snd_pcm_period_elapsed(dpcm-&gt;substream);
+                        giovadpcms[i].elapsed = 0;
+                }
+        }
+
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream)
</span><span class="lines">@@ -265,7 +288,8 @@
</span><span class="cx">         struct snd_pcm_runtime *runtime = substream-&gt;runtime;
</span><span class="cx">         struct snd_dummy_pcm *dpcm = runtime-&gt;private_data;
</span><span class="cx"> 
</span><del>-        return bytes_to_frames(runtime, dpcm-&gt;pcm_buf_pos / dpcm-&gt;pcm_hz);
</del><ins>+        //return bytes_to_frames(runtime, dpcm-&gt;pcm_buf_pos / dpcm-&gt;pcm_hz);
+        return (dpcm-&gt;pcm_buf_pos / dpcm-&gt;pcm_hz) / 2;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static struct snd_pcm_hardware snd_card_dummy_playback = {
</span><span class="lines">@@ -277,7 +301,7 @@
</span><span class="cx">         .channels_min = USE_CHANNELS_MIN,
</span><span class="cx">         .channels_max = USE_CHANNELS_MAX,
</span><span class="cx">         .buffer_bytes_max = MAX_BUFFER_SIZE,
</span><del>-        .period_bytes_min = 64,
</del><ins>+        .period_bytes_min = 256,
</ins><span class="cx">         .period_bytes_max = MAX_PERIOD_SIZE,
</span><span class="cx">         .periods_min = USE_PERIODS_MIN,
</span><span class="cx">         .periods_max = USE_PERIODS_MAX,
</span><span class="lines">@@ -293,7 +317,7 @@
</span><span class="cx">         .channels_min = USE_CHANNELS_MIN,
</span><span class="cx">         .channels_max = USE_CHANNELS_MAX,
</span><span class="cx">         .buffer_bytes_max = MAX_BUFFER_SIZE,
</span><del>-        .period_bytes_min = 64,
</del><ins>+        .period_bytes_min = 256,
</ins><span class="cx">         .period_bytes_max = MAX_PERIOD_SIZE,
</span><span class="cx">         .periods_min = USE_PERIODS_MIN,
</span><span class="cx">         .periods_max = USE_PERIODS_MAX,
</span><span class="lines">@@ -313,6 +337,7 @@
</span><span class="cx">                 }
</span><span class="cx">                 if ((giovadpcms[i].dpcm == runtime-&gt;private_data)) {
</span><span class="cx">                         giovadpcms[i].started = 0;
</span><ins>+                        giovadpcms[i].elapsed = 0;
</ins><span class="cx">                 } else {
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -342,8 +367,8 @@
</span><span class="cx">                 printk(&quot;giova, %s:%d, giovaindex=%d NO MEMORY!!!!\n&quot;, __FILE__, __LINE__, giovaindex);
</span><span class="cx">                 return dpcm;
</span><span class="cx">         }
</span><del>-        init_timer(&amp;dpcm-&gt;timer);
-        spin_lock_init(&amp;dpcm-&gt;lock);
</del><ins>+        //init_timer(&amp;dpcm-&gt;timer);
+        //spin_lock_init(&amp;dpcm-&gt;lock);
</ins><span class="cx">         dpcm-&gt;substream = substream;
</span><span class="cx"> 
</span><span class="cx">         spin_lock_bh(&amp;giovalock);
</span><span class="lines">@@ -376,6 +401,7 @@
</span><span class="cx">                 if (giovadpcms[i].substream == substream) {
</span><span class="cx">                         giovadpcms[i].dpcm = dpcm;
</span><span class="cx">                         giovadpcms[i].started = 0;
</span><ins>+                        giovadpcms[i].elapsed = 0;
</ins><span class="cx">                         found = 1;
</span><span class="cx">                         break;
</span><span class="cx">                 }
</span><span class="lines">@@ -630,14 +656,14 @@
</span><span class="cx">         int idx, err;
</span><span class="cx">         int dev = devptr-&gt;id;
</span><span class="cx"> 
</span><del>-        card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_dummy)); //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below
-        if (card == NULL) //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below
-                return -ENOMEM; //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below
</del><ins>+        //card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_dummy)); //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below
+        //if (card == NULL) //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below
+                //return -ENOMEM; //giova if this gives you problems, comment it out and remove comment from the 4 lines commented below
</ins><span class="cx"> 
</span><del>-        //giova err = snd_card_create(index[dev], id[dev], THIS_MODULE,
-        //giova sizeof(struct snd_dummy), &amp;card);
-        //giova if (err &lt; 0)
-        //giova return err;
</del><ins>+        err = snd_card_create(index[dev], id[dev], THIS_MODULE,
+        sizeof(struct snd_dummy), &amp;card);
+        if (err &lt; 0)
+        return err;
</ins><span class="cx"> 
</span><span class="cx">         dummy = card-&gt;private_data;
</span><span class="cx">         dummy-&gt;card = card;
</span><span class="lines">@@ -741,13 +767,14 @@
</span><span class="cx">                         giovadpcms[i].substream = NULL;
</span><span class="cx">                         giovadpcms[i].dpcm = NULL;
</span><span class="cx">                         giovadpcms[i].started = 0;
</span><ins>+                        giovadpcms[i].elapsed = 0;
</ins><span class="cx">                 }
</span><span class="cx">                 init_timer(&amp;giovatimer);
</span><span class="cx">                 giovatimer.data = (unsigned long) &amp;giovadpcms;
</span><span class="cx">                 giovatimer.function = snd_card_dummy_pcm_timer_function;
</span><span class="cx">                 giovatimer.expires = 1 + jiffies;
</span><span class="cx">                 add_timer(&amp;giovatimer);
</span><del>-                printk(&quot;snd-dummy skypopen driver version: 3, %s:%d working on a machine with %dHZ kernel\n&quot;, __FILE__, __LINE__, HZ);
</del><ins>+                printk(&quot;snd-dummy skypopen driver version: 5, %s:%d working on a machine with %dHZ kernel\n&quot;, __FILE__, __LINE__, HZ);
</ins><span class="cx">                 spin_unlock_bh(&amp;giovalock);
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="freeswitchbranchesrupa_limitsrcswitch_core_hashc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/src/switch_core_hash.c (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/src/switch_core_hash.c        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/src/switch_core_hash.c        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -117,6 +117,42 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_multi(switch_hash_t *hash, switch_hash_delete_callback_t callback, void *pData) {
+
+        switch_hash_index_t *hi = NULL;
+        switch_event_t *event = NULL;
+        switch_event_header_t *header = NULL;
+        switch_status_t status = SWITCH_STATUS_GENERR;
+        
+        switch_event_create_subclass(&amp;event, SWITCH_EVENT_CLONE, NULL);
+        switch_assert(event);
+        
+        /* iterate through the hash, call callback, if callback returns true, put the key on the list (event)
+           When done, iterate through the list deleting hash entries
+         */
+        
+        for (hi = switch_hash_first(NULL, hash); hi; hi = switch_hash_next(hi)) {
+                const void *key;
+                void *val;
+                switch_hash_this(hi, &amp;key, NULL, &amp;val);
+                if (callback(key, val, pData)) {
+                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;delete&quot;, (const char *) key);
+                }
+        }
+        
+        /* now delete them */
+        for (header = event-&gt;headers; header; header = header-&gt;next) {
+                if (switch_core_hash_delete(hash, header-&gt;value) == SWITCH_STATUS_SUCCESS) {
+                        status = SWITCH_STATUS_SUCCESS;
+                }
+        }
+
+        switch_event_destroy(&amp;event);
+        
+        return status;
+}
+
+
</ins><span class="cx"> SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash_t *hash, const char *key)
</span><span class="cx"> {
</span><span class="cx">         return sqlite3HashFind(&amp;hash-&gt;table, key, (int) strlen(key) + 1);
</span></span></pre></div>
<a id="freeswitchbranchesrupa_limitsrcswitch_limitc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/rupa_limit/src/switch_limit.c (17085 => 17086)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/rupa_limit/src/switch_limit.c        2010-03-24 16:11:24 UTC (rev 17085)
+++ freeswitch/branches/rupa_limit/src/switch_limit.c        2010-03-24 16:17:58 UTC (rev 17086)
</span><span class="lines">@@ -119,6 +119,9 @@
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Limit subsystem %s not found!\n&quot;, backend);
</span><span class="cx">                 switch_goto_status(SWITCH_STATUS_GENERR, end);
</span><span class="cx">         }
</span><ins>+
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;incr called: %s_%s max:%d, interval:%d\n&quot;,
+                                          realm, resource, max, interval);
</ins><span class="cx">         
</span><span class="cx">         if ((status = limit-&gt;incr(session, realm, resource, max, interval)) == SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                 /* race condition? what if another leg is doing the same thing? */
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>