]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Make max argument optional on the limit app, set the limit_usage variable with the...
authorMathieu Rene <mrene@avgs.ca>
Thu, 12 Feb 2009 21:19:52 +0000 (21:19 +0000)
committerMathieu Rene <mrene@avgs.ca>
Thu, 12 Feb 2009 21:19:52 +0000 (21:19 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11955 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_limit/mod_limit.c

index 0c267656ea571f698c523bad2d950f7da7b481f5..94015ef7d2304f84968f373be30801b26fe2da54 100644 (file)
@@ -701,7 +701,7 @@ SWITCH_STANDARD_APP(group_function)
        }
 }
 
-#define LIMIT_USAGE "<realm> <id> <max> [number  [dialplan [context]]]"
+#define LIMIT_USAGE "<realm> <id> [<max> [number  [dialplan [context]]]]"
 #define LIMIT_DESC "limit access to a resource and transfer to an extension if the limit is exceeded"
 static char *limit_def_xfer_exten = "limit_exceeded";
 
@@ -727,14 +727,23 @@ SWITCH_STANDARD_APP(limit_function)
 
        if (argc < 3) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: limit %s\n", LIMIT_USAGE);
-               return;
+               goto done;
        }
 
        switch_mutex_lock(globals.mutex);
 
        realm = argv[0];
        id = argv[1];
-       max = atoi(argv[2]);
+       
+       if (argc > 2) {
+               max = atoi(argv[2]);
+               if (max < 0) {
+                       max = 0; 
+               }
+       }
+       else {
+               max = -1;
+       }
 
        if (argc >= 4) {
                xfer_exten = argv[3];
@@ -742,9 +751,6 @@ SWITCH_STANDARD_APP(limit_function)
                xfer_exten = limit_def_xfer_exten;
        }
 
-       if (max < 0) {
-               max = 0;
-       }
        
        new_channel = !switch_channel_get_variable(channel, "limit_realm");
        switch_channel_set_variable(channel, "limit_realm", realm);
@@ -758,7 +764,7 @@ SWITCH_STANDARD_APP(limit_function)
        switch_safe_free(sql);
        got = atoi(buf);
 
-       if (got + 1 > max) {
+       if (max > 0 && got + 1 > max) {
                switch_ivr_session_transfer(session, xfer_exten, argv[4], argv[5]);
                goto done;
        }
@@ -771,8 +777,11 @@ SWITCH_STANDARD_APP(limit_function)
                                           switch_core_session_get_uuid(session));
        limit_execute_sql(sql, NULL);
        switch_safe_free(sql);
+       
+       switch_channel_set_variable(channel, "limit_usage", switch_core_session_sprintf(session, "%d", ++got));
 
   done:
+       switch_safe_free(mydata);
        switch_mutex_unlock(globals.mutex);
 }