<!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][14665] </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=14665">14665</a></dd>
<dt>Author</dt> <dd>rupa</dd>
<dt>Date</dt> <dd>2009-08-28 11:18:51 -0500 (Fri, 28 Aug 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>add memcache support (limit_memcache and friends)</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_limitmod_limitc">freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodapplicationsmod_limitmod_limitc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c (14664 => 14665)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c        2009-08-28 14:31:26 UTC (rev 14664)
+++ freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c        2009-08-28 16:18:51 UTC (rev 14665)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx">  * Ken Rice &lt;krice at suspicious dot org
</span><span class="cx">  * Mathieu Rene &lt;mathieu.rene@gmail.com&gt;
</span><span class="cx">  * Bret McDanel &lt;trixter AT 0xdecafbad.com&gt;
</span><ins>+ * Rupa Schomaker &lt;rupa@rupa.com&gt;
</ins><span class="cx">  *
</span><span class="cx">  * mod_limit.c -- Resource Limit Module
</span><span class="cx">  *
</span><span class="lines">@@ -359,6 +360,55 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static switch_status_t memcache_state_handler(switch_core_session_t *session) 
+{
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+        switch_channel_state_t state = switch_channel_get_state(channel);
+        int argc = 0;
+        char *argv[32] = { 0 };
+        char *pvt = switch_channel_get_private(channel, &quot;limit_keys&quot;);
+        char *mydata = NULL;
+        int i = 0;
+
+        char *hashkey = NULL;
+        uint32_t total_usage = 0;
+        char *cmd = NULL;
+        switch_stream_handle_t stream = { 0 };
+        SWITCH_STANDARD_STREAM(stream);
+        
+        switch_assert(pvt);
+        
+        /* The call is either hung up, or is going back into the dialplan, decrement appropriate couters */
+        if (state &gt;= CS_HANGUP || state == CS_ROUTING) {        
+
+                /* Loop through the channel's keys which contains mapping to all the limits referenced by that channel */
+                mydata = switch_core_session_strdup(session, pvt);
+                argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
+                for (i = 0; i &lt; argc; i++) {
+                        hashkey = argv[i];
+                        cmd = switch_core_session_sprintf(session, &quot;decrement limit:%s_total 1&quot;, hashkey);
+                        switch_api_execute(&quot;memcache&quot;, cmd, session, &amp;stream);
+                        if (strncmp(&quot;-ERR&quot;, stream.data, 4)) {
+                                total_usage = atoi(stream.data);
+                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Usage for %s is now %d\n&quot;, (const char*)hashkey, total_usage);
+                        } else {
+                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Error from mod_memcache %s.&quot;, (const char *) stream.data);
+                                goto end;
+                        }
+                        
+                        stream.end = stream.data;
+                }
+                        
+                /* Remove handler */
+                switch_core_event_hook_remove_state_change(session, memcache_state_handler);
+                switch_channel_set_private(channel, &quot;limit_keys&quot;, NULL);
+        }
+        
+end:
+        switch_safe_free(stream.data);
+        return SWITCH_STATUS_SUCCESS;
+}
+
</ins><span class="cx"> struct callback {
</span><span class="cx">         char *buf;
</span><span class="cx">         size_t len;
</span><span class="lines">@@ -1152,6 +1202,350 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/* \brief Enforces limit_memcache restrictions
+ * \param session current session
+ * \param realm limit realm
+ * \param id limit id
+ * \param max maximum count
+ * \param interval interval for rate limiting
+ * \return SWITCH_TRUE if the access is allowed, SWITCH_FALSE if it isnt
+ */
+static switch_bool_t do_limit_memcache(switch_core_session_t *session, const char *realm, const char *id, int max, int interval)
+{
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+        char *hashkey = NULL;
+        switch_bool_t status = SWITCH_TRUE;
+        uint8_t increment = 1;
+        uint32_t total_usage = 0;
+        uint32_t rate_usage = 0;
+        char *cmd = NULL;
+        char *pvt = NULL;
+        int argc = 0;
+        int i = 0;
+        char *argv[32] = { 0 };
+        char *mydata = NULL;
+        
+        switch_stream_handle_t stream = { 0 };
+        
+        if (switch_loadable_module_exists(&quot;mod_memcache&quot;) != SWITCH_STATUS_SUCCESS) {
+                status = SWITCH_TRUE;
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;mod_memcache is not loaded.&quot;);
+                goto end;
+        }
+        
+        SWITCH_STANDARD_STREAM(stream);
+        hashkey = switch_core_session_sprintf(session, &quot;%s_%s&quot;, realm, id);
+        
+        /* Did we already run on this channel before? */
+        if ((pvt = switch_channel_get_private(channel, &quot;limit_keys&quot;)))
+        {
+                /* Yes, but check if we did that realm+id
+                   If we didnt, allow incrementing the counter.
+                   If we did, dont touch it but do the validation anyways
+                 */
+                mydata = switch_core_session_strdup(session, pvt);
+                argc = switch_separate_string(mydata, ',', argv, (sizeof(argv) / sizeof(argv[0])));
+                for (i = 0; i &lt; argc; i++) {
+                        if (!strcmp(hashkey, argv[i])) {
+                                increment = 0;
+                                break;
+                        }
+                }
+        }
+        
+        cmd = switch_core_session_sprintf(session, &quot;get limit:%s_total&quot;, hashkey);
+        switch_api_execute(&quot;memcache&quot;, cmd, session, &amp;stream);
+        if (strncmp(&quot;-ERR&quot;, stream.data, 4)) {
+                total_usage = atoi(stream.data);
+        } else if (!strncmp(&quot;-ERR NOT FOUND&quot;, stream.data, 14)) {
+                total_usage = 0;
+        } else {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Error from mod_memcache %s.&quot;, (const char *) stream.data);
+                status = SWITCH_TRUE;
+                goto end;
+        }
+        
+        stream.end = stream.data;
+
+        if (interval &gt; 0) {
+                cmd = switch_core_session_sprintf(session, &quot;increment limit:%s_rate 1 %d&quot;, hashkey, interval);
+                switch_api_execute(&quot;memcache&quot;, cmd, session, &amp;stream);
+                if (strncmp(&quot;-ERR&quot;, stream.data, 4)) {
+                        rate_usage = atoi(stream.data);
+                } else {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Error from mod_memcache %s.&quot;, (const char *) stream.data);
+                        status = SWITCH_TRUE;
+                        goto end;
+                }
+                if ((max &gt;= 0) &amp;&amp; (rate_usage &gt; (uint32_t)max)) {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Usage for %s exceeds maximum rate of %d/%ds, now at %d\n&quot;, hashkey, max, interval, rate_usage);
+                        status = SWITCH_FALSE;
+                        goto end;
+                }
+        } else if ((max &gt;= 0) &amp;&amp; (total_usage + increment &gt; (uint32_t)max)) {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Usage for %s is already at max value (%d)\n&quot;, hashkey, total_usage);
+                status = SWITCH_FALSE;
+                goto end;
+        }
+        
+        stream.end = stream.data;
+
+        if (increment) {
+                cmd = switch_core_session_sprintf(session, &quot;increment limit:%s_total 1&quot;, hashkey);
+                switch_api_execute(&quot;memcache&quot;, cmd, session, &amp;stream);
+                if (strncmp(&quot;-ERR&quot;, stream.data, 4)) {
+                        total_usage = atoi(stream.data);
+                } else {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Error from mod_memcache %s.&quot;, (const char *) stream.data);
+                        status = SWITCH_TRUE;
+                        goto end;
+                }
+                if (max == -1) {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Usage for %s is now %d\n&quot;, hashkey, total_usage);
+                } else if (interval == 0) {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Usage for %s is now %d/%d\n&quot;, hashkey, total_usage, max);        
+                } else {
+                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Usage for %s is now %d/%d for the last %d seconds\n&quot;, hashkey, rate_usage, max, interval);
+                }
+
+                limit_fire_event(realm, id, total_usage, rate_usage, max, max &gt;=0 ? (uint32_t)max : 0);
+        }
+
+        /* Save current usage &amp; rate into channel variables so it can be used later in the dialplan, or added to CDR records */
+        {
+                const char *susage = switch_core_session_sprintf(session, &quot;%d&quot;, total_usage);
+                const char *srate = switch_core_session_sprintf(session, &quot;%d&quot;, rate_usage);
+
+                switch_channel_set_variable(channel, &quot;limit_usage&quot;, susage);
+                switch_channel_set_variable(channel, switch_core_session_sprintf(session, &quot;limit_usage_%s&quot;, hashkey), susage);
+
+                switch_channel_set_variable(channel, &quot;limit_rate&quot;, srate);
+                switch_channel_set_variable(channel, switch_core_session_sprintf(session, &quot;limit_rate_%s&quot;, hashkey), srate);
+        }
+        
+        if (pvt &amp;&amp; increment) {
+                pvt = switch_core_session_sprintf(session, &quot;%s,%s&quot;, pvt, hashkey);
+        } else {
+                /* This is the first limit check on this channel, create a hashtable, set our prviate data and add a state handler */
+                pvt = (char *) hashkey;
+        }
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, &quot;hash_keys: %s\n&quot;, pvt);
+        switch_channel_set_private(channel, &quot;limit_keys&quot;, pvt);
+
+        switch_core_event_hook_add_state_change(session, memcache_state_handler);
+
+end:        
+        switch_safe_free(stream.data);
+        return status;
+}
+
+/* !\brief Releases usage of a limit_hash-controlled ressource  */
+static void limit_memcache_release(switch_core_session_t *session, const char *realm, const char *id)
+{
+        char *hashkey = NULL;
+        uint32_t total_usage = 0;
+        char *cmd = NULL;
+        switch_stream_handle_t stream = { 0 };
+        SWITCH_STANDARD_STREAM(stream);
+        
+        if (switch_loadable_module_exists(&quot;mod_memcache&quot;) != SWITCH_STATUS_SUCCESS) {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;mod_memcache is not loaded.&quot;);
+                goto end;
+        }
+
+        hashkey = switch_core_session_sprintf(session, &quot;%s_%s&quot;, realm, id);
+        
+        cmd = switch_core_session_sprintf(session, &quot;decrement limit:%s_total 1&quot;, hashkey);
+        switch_api_execute(&quot;memcache&quot;, cmd, session, &amp;stream);
+        if (strncmp(&quot;-ERR&quot;, stream.data, 4)) {
+                total_usage = atoi(stream.data);
+        } else if (!strncmp(&quot;-ERR NOT FOUND&quot;, stream.data, 14)) {
+                total_usage = 0;
+        } else {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Error from mod_memcache %s.&quot;, (const char *) stream.data);
+                goto end;
+        }
+
+        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, &quot;Usage for %s is now %d\n&quot;, (const char*)hashkey, total_usage);
+
+end:
+        switch_safe_free(stream.data);
+}
+
+#define LIMITMEMCACHE_USAGE &quot;&lt;realm&gt; &lt;id&gt; [&lt;max&gt;[/interval]] [number [dialplan [context]]]&quot;
+#define LIMITMEMCACHE_DESC &quot;limit access to a resource and transfer to an extension if the limit is exceeded&quot;
+SWITCH_STANDARD_APP(limit_memcache_function)
+{
+        int argc = 0;
+        char *argv[6] = { 0 };
+        char *mydata = NULL;
+        char *realm = NULL;
+        char *id = NULL;
+        char *xfer_exten = NULL;
+        int max = -1;
+        int interval = 0;
+        char *szinterval = NULL;
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+
+        /* Parse application data  */
+        if (!switch_strlen_zero(data)) {
+                mydata = switch_core_session_strdup(session, data);
+                argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+        }
+        
+        if (argc &lt; 2) {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, &quot;USAGE: limit_memcache %s\n&quot;, LIMITMEMCACHE_USAGE);
+                return;
+        }
+        
+        realm = argv[0];
+        id = argv[1];
+        
+        /* If max is omitted, only act as a counter and skip maximum checks */
+        if (argc &gt; 2) {
+                if ((szinterval = strchr(argv[2], '/')))
+                {
+                        *szinterval++ = '\0';
+                        interval = atoi(szinterval);
+                }
+                
+                max = atoi(argv[2]);
+                
+                if (max &lt; 0) {
+                        max = 0;
+                }
+        }
+
+        if (argc &gt; 3) {
+                xfer_exten = argv[3];
+        } else {
+                xfer_exten = limit_def_xfer_exten;
+        }
+        
+        if (!do_limit_memcache(session, realm, id, max, interval)) {
+                /* Limit exceeded */
+                if (*xfer_exten == '!') {
+                        switch_channel_hangup(channel, switch_channel_str2cause(xfer_exten+1));
+                } else {
+                        switch_ivr_session_transfer(session, xfer_exten, argv[4], argv[5]);
+                }
+        }
+}
+
+
+#define LIMITMEMCACHEEXECUTE_USAGE &quot;&lt;realm&gt; &lt;id&gt; [&lt;max&gt;[/interval]] [application] [application arguments]&quot;
+#define LIMITMEMCACHEEXECUTE_DESC &quot;limit access to a resource. the specified application will only be executed if the resource is available&quot;
+SWITCH_STANDARD_APP(limit_memcache_execute_function)
+{
+        int argc = 0;
+        char *argv[5] = { 0 };
+        char *mydata = NULL;
+        char *realm = NULL;
+        char *id = NULL;
+        char *app = NULL;
+        char *app_arg = NULL;
+        int max = -1;
+        int interval = 0;
+        char *szinterval = NULL;
+
+        /* Parse application data  */
+        if (!switch_strlen_zero(data)) {
+                mydata = switch_core_session_strdup(session, data);
+                argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+        }
+        
+        if (argc &lt; 2) {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, &quot;USAGE: limit_memcache_execute %s\n&quot;, LIMITMEMCACHEEXECUTE_USAGE);
+                return;
+        }
+        
+        realm = argv[0];
+        id = argv[1];
+        
+        /* If max is omitted, only act as a counter and skip maximum checks */
+        if (argc &gt; 2) {
+                if ((szinterval = strchr(argv[2], '/')))
+                {
+                        *szinterval++ = '\0';
+                        interval = atoi(szinterval);
+                }
+                
+                max = atoi(argv[2]);
+                
+                if (max &lt; 0) {
+                        max = 0;
+                }
+        }
+
+
+        app = argv[3];
+        app_arg = argv[4];
+
+        if (switch_strlen_zero(app)) {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Missing application\n&quot;);
+                return;
+        }
+
+        if (do_limit_memcache(session, realm, id, max, interval)) {
+                switch_core_session_execute_application(session, app, app_arg);
+                limit_memcache_release(session, realm, id);
+        }
+}
+
+
+#define LIMIT_MEMCACHE_USAGE_USAGE &quot;&lt;realm&gt; &lt;id&gt;&quot;
+SWITCH_STANDARD_API(limit_memcache_usage_function)
+{
+        int argc = 0;
+        char *argv[3] = { 0 };
+        char *mydata = NULL;
+        uint32_t count = 0;
+        char *apicmd = NULL;
+        switch_bool_t status = SWITCH_TRUE;
+        switch_stream_handle_t apistream = { 0 };
+
+        SWITCH_STANDARD_STREAM(apistream);
+        if (switch_loadable_module_exists(&quot;mod_memcache&quot;) != SWITCH_STATUS_SUCCESS) {
+                status = SWITCH_TRUE;
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;mod_memcache is not loaded.&quot;);
+                stream-&gt;write_function(stream, &quot;-ERR mod_memcache not loaded&quot;);
+                goto end;
+        }
+
+        if (!switch_strlen_zero(cmd)) {
+                mydata = strdup(cmd);
+                switch_assert(mydata);
+                argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+        }
+        
+        if (argc &lt; 2) {
+                stream-&gt;write_function(stream, &quot;USAGE: limit_memcache_usage %s\n&quot;, LIMIT_MEMCACHE_USAGE_USAGE);
+                goto end;
+        }
+        
+        apicmd = switch_mprintf(&quot;get limit:%s_%s_total&quot;, argv[0], argv[1]);
+        switch_api_execute(&quot;memcache&quot;, apicmd, session, &amp;apistream);
+        if (strncmp(&quot;-ERR&quot;, apistream.data, 4)) {
+                count = atoi(apistream.data);
+        } else if (!strncmp(&quot;-ERR NOT FOUND&quot;, apistream.data, 14)) {
+                count = 0;
+        } else {
+                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Error from mod_memcache %s.&quot;, (const char *) apistream.data);
+                status = SWITCH_TRUE;
+                goto end;
+        }
+        
+        stream-&gt;write_function(stream, &quot;%d&quot;, count);
+        
+end:
+        switch_safe_free(mydata);
+        switch_safe_free(apistream.data);
+        switch_safe_free(apicmd);
+        
+        return SWITCH_STATUS_SUCCESS;
+}
+
+
</ins><span class="cx"> SWITCH_MODULE_LOAD_FUNCTION(mod_limit_load)
</span><span class="cx"> {
</span><span class="cx">         switch_status_t status;
</span><span class="lines">@@ -1187,11 +1581,14 @@
</span><span class="cx">         SWITCH_ADD_APP(app_interface, &quot;limit&quot;, &quot;Limit&quot;, LIMIT_DESC, limit_function, LIMIT_USAGE, SAF_SUPPORT_NOMEDIA);
</span><span class="cx">         SWITCH_ADD_APP(app_interface, &quot;limit_hash&quot;, &quot;Limit (hash)&quot;, LIMITHASH_DESC, limit_hash_function, LIMITHASH_USAGE, SAF_SUPPORT_NOMEDIA);
</span><span class="cx">         SWITCH_ADD_APP(app_interface, &quot;limit_hash_execute&quot;, &quot;Limit (hash)&quot;, LIMITHASHEXECUTE_USAGE, limit_hash_execute_function, LIMITHASHEXECUTE_USAGE, SAF_SUPPORT_NOMEDIA);
</span><ins>+        SWITCH_ADD_APP(app_interface, &quot;limit_memcache&quot;, &quot;Limit (memcache)&quot;, LIMITMEMCACHE_DESC, limit_memcache_function, LIMITMEMCACHE_USAGE, SAF_SUPPORT_NOMEDIA);
+        SWITCH_ADD_APP(app_interface, &quot;limit_memcache_execute&quot;, &quot;Limit (memcache)&quot;, LIMITMEMCACHEEXECUTE_USAGE, limit_memcache_execute_function, LIMITMEMCACHEEXECUTE_USAGE, SAF_SUPPORT_NOMEDIA);
</ins><span class="cx">         SWITCH_ADD_APP(app_interface, &quot;db&quot;, &quot;Insert to the db&quot;, DB_DESC, db_function, DB_USAGE, SAF_SUPPORT_NOMEDIA);
</span><span class="cx">         SWITCH_ADD_APP(app_interface, &quot;hash&quot;, &quot;Insert into the hashtable&quot;, HASH_DESC, hash_function, HASH_USAGE, SAF_SUPPORT_NOMEDIA)
</span><span class="cx">         SWITCH_ADD_APP(app_interface, &quot;group&quot;, &quot;Manage a group&quot;, GROUP_DESC, group_function, GROUP_USAGE, SAF_SUPPORT_NOMEDIA);
</span><span class="cx"> 
</span><span class="cx">         SWITCH_ADD_API(commands_api_interface, &quot;limit_hash_usage&quot;, &quot;Gets the usage count of a limited resource&quot;, limit_hash_usage_function,  LIMIT_HASH_USAGE_USAGE);
</span><ins>+        SWITCH_ADD_API(commands_api_interface, &quot;limit_memcache_usage&quot;, &quot;Gets the usage count of a limited resource&quot;, limit_memcache_usage_function,  LIMIT_MEMCACHE_USAGE_USAGE);
</ins><span class="cx">         SWITCH_ADD_API(commands_api_interface, &quot;limit_usage&quot;, &quot;Gets the usage count of a limited resource&quot;, limit_usage_function, &quot;&lt;realm&gt; &lt;id&gt;&quot;);
</span><span class="cx">         SWITCH_ADD_API(commands_api_interface, &quot;db&quot;, &quot;db get/set&quot;, db_api_function, &quot;[insert|delete|select]/&lt;realm&gt;/&lt;key&gt;/&lt;value&gt;&quot;);
</span><span class="cx">         switch_console_set_complete(&quot;add db insert&quot;);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>