[Freeswitch-svn] [commit] r13007 - freeswitch/trunk/src/mod/applications/mod_limit

FreeSWITCH SVN mrene at freeswitch.org
Sun Apr 12 11:35:09 PDT 2009


Author: mrene
Date: Sun Apr 12 13:35:09 2009
New Revision: 13007

Log:
mod_limit: Add more error checking to hash api/app

Modified:
   freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c

Modified: freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c	Sun Apr 12 13:35:09 2009
@@ -537,6 +537,8 @@
 	char *hash_key = NULL;
 	char *value = NULL;
 	
+	switch_mutex_lock(globals.db_hash_mutex);
+	
 	if (!switch_strlen_zero(data)) {
 		mydata = strdup(data);
 		switch_assert(mydata);
@@ -544,14 +546,15 @@
 	}
 	
 	if (argc < 3 || !argv[0]) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: hash %s\n", HASH_USAGE);
-		goto end;
+		goto usage;
 	}
 	
 	hash_key = switch_mprintf("%s_%s", argv[1], argv[2]);
 	
-	switch_mutex_lock(globals.db_hash_mutex);
 	if (!strcasecmp(argv[0], "insert")) {
+		if (argc < 4) {
+			goto usage;
+		}
 		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
 			free(value);
 			switch_core_hash_delete(globals.db_hash, hash_key);
@@ -564,10 +567,17 @@
 			switch_safe_free(value);
 			switch_core_hash_delete(globals.db_hash, hash_key);
 		}
+	} else {
+		goto usage;
 	}
-	switch_mutex_unlock(globals.db_hash_mutex);
 	
-end:
+	goto done;
+
+usage:
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "USAGE: hash %s\n", HASH_USAGE);
+
+done:
+	switch_mutex_unlock(globals.db_hash_mutex);
 	switch_safe_free(mydata);
 	switch_safe_free(hash_key);
 }
@@ -590,16 +600,14 @@
 	}
 	
 	if (argc < 3 || !argv[0]) {
-		stream->write_function(stream, "-ERR Usage: hash %s\n", HASH_API_USAGE);
-		goto end;
+		goto usage;
 	}
 	
 	hash_key = switch_mprintf("%s_%s", argv[1], argv[2]);
 	
 	if (!strcasecmp(argv[0], "insert")) {
 		if (argc < 4) {
-			stream->write_function(stream, "-ERR Usage: hash %s\n", HASH_API_USAGE);
-			goto end;
+			goto usage;
 		}
 		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
 			switch_safe_free(value);
@@ -613,15 +621,24 @@
 		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
 			switch_safe_free(value);
 			switch_core_hash_delete(globals.db_hash, hash_key);
+			stream->write_function(stream, "+OK\n");
+		} else {
+			stream->write_function(stream, "-ERR Not found\n");
 		}
-		stream->write_function(stream, "+OK\n");
 	} else if (!strcasecmp(argv[0], "select")) {
 		if ((value = switch_core_hash_find(globals.db_hash, hash_key))) {
 			stream->write_function(stream, "%s", value);
 		}
+	} else {
+		goto usage;
 	}
 	
-end:
+	goto done;
+	
+usage:
+	stream->write_function(stream, "-ERR Usage: hash %s\n", HASH_API_USAGE);
+	
+done:
 	switch_mutex_unlock(globals.db_hash_mutex);
 	switch_safe_free(mydata);
 	switch_safe_free(hash_key);



More information about the Freeswitch-svn mailing list