]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_hash: add realm filter to hash_dump db command so that you can quickly dump all...
authorMichael S Collins <msc@freeswitch.org>
Tue, 19 Apr 2011 01:43:24 +0000 (18:43 -0700)
committerMichael S Collins <msc@freeswitch.org>
Tue, 19 Apr 2011 01:43:24 +0000 (18:43 -0700)
src/mod/applications/mod_hash/mod_hash.c

index e3f01cec960df57ca49bd2e3254f2bdd9829c4cc..cfabf5477a45fe3d273ee0d7c20c91fc55e0287d 100644 (file)
@@ -531,16 +531,33 @@ SWITCH_STANDARD_API(hash_api_function)
        return SWITCH_STATUS_SUCCESS;
 }
 
-#define HASH_DUMP_SYNTAX "all|limit|db"
+#define HASH_DUMP_SYNTAX "all|limit|db [<realm>]"
 SWITCH_STANDARD_API(hash_dump_function) 
 {
        int mode;
        switch_hash_index_t *hi;
+       int argc = 0;
+       char *argv[4] = { 0 };
+       char *mydata = NULL;
+       int realm = 0;
+       char *realmvalue = NULL;
        
-       if (zstr(cmd)) {
+       if (!zstr(cmd)) {
+               mydata = strdup(cmd);
+               switch_assert(mydata);
+               argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+       } else {
+               realmvalue = "test";
+               realm = 0;
                stream->write_function(stream, "Usage: "HASH_DUMP_SYNTAX"\n");
                return SWITCH_STATUS_SUCCESS;
-       }
+       }       
+
+       cmd = strdup(argv[0]);
+       if (argc == 2) {
+               realm = 1;
+               realmvalue = switch_mprintf("%s_", argv[1]);
+       } 
        
        if (!strcmp(cmd, "all")) {
                mode = 3;
@@ -553,7 +570,6 @@ SWITCH_STANDARD_API(hash_dump_function)
                return SWITCH_STATUS_SUCCESS;
        }
        
-       
        if (mode & 1) {
                switch_thread_rwlock_rdlock(globals.limit_hash_rwlock);
                for (hi = switch_hash_first(NULL, globals.limit_hash); hi; hi = switch_hash_next(hi)) {
@@ -577,8 +593,13 @@ SWITCH_STANDARD_API(hash_dump_function)
                        const void *key;
                        switch_ssize_t keylen;
                        switch_hash_this(hi, &key, &keylen, &val);
-
-                       stream->write_function(stream, "D/%s/%s\n", key, (char*)val);
+                       if (realm) {
+                               if (strstr(key, realmvalue)) {
+                                       stream->write_function(stream, "D/%s/%s\n", key, (char*)val);
+                               }
+                       } else {
+                               stream->write_function(stream, "D/%s/%s\n", key, (char*)val);
+                       }
                }
                switch_thread_rwlock_unlock(globals.db_hash_rwlock);
        }