[Asterisk-cvs] asterisk db.c,1.19,1.20

kpfleming at lists.digium.com kpfleming at lists.digium.com
Tue Jul 19 20:02:18 CDT 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv19727

Modified Files:
	db.c 
Log Message:
formatting cleanup (bug #4752)


Index: db.c
===================================================================
RCS file: /usr/cvsroot/asterisk/db.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- db.c	6 Jun 2005 22:12:18 -0000	1.19
+++ db.c	20 Jul 2005 00:09:39 -0000	1.20
@@ -64,8 +64,7 @@
 		return 1;
 	if (!strcasecmp(key, prefix))
 		return 1;
-	if ((strlen(key) > preflen) &&
-		!strncasecmp(key, prefix, preflen)) {
+	if ((strlen(key) > preflen) && !strncasecmp(key, prefix, preflen)) {
 		if (key[preflen] == '/')
 			return 1;
 	}
@@ -94,14 +93,16 @@
 	int pass;
 	
 	if (family) {
-		if (keytree)
+		if (keytree) {
 			snprintf(prefix, sizeof(prefix), "/%s/%s", family, keytree);
-		else
+		} else {
 			snprintf(prefix, sizeof(prefix), "/%s", family);
-	} else if (keytree)
+		}
+	} else if (keytree) {
 		return -1;
-	else
+	} else {
 		prefix[0] = '\0';
+	}
 	
 	ast_mutex_lock(&dblock);
 	if (dbinit()) 
@@ -110,12 +111,13 @@
 	memset(&key, 0, sizeof(key));
 	memset(&data, 0, sizeof(data));
 	pass = 0;
-	while(!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
+	while (!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
 		if (key.size) {
 			keys = key.data;
 			keys[key.size - 1] = '\0';
-		} else
+		} else {
 			keys = "<bad key>";
+		}
 		if (keymatch(keys, prefix)) {
 			astdb->del(astdb, &key, 0);
 		}
@@ -154,7 +156,7 @@
 
 int ast_db_get(const char *family, const char *keys, char *value, int valuelen)
 {
-	char fullkey[256]="";
+	char fullkey[256] = "";
 	DBT key, data;
 	int res, fullkeylen;
 
@@ -227,10 +229,11 @@
 	if (argc != 5)
 		return RESULT_SHOWUSAGE;
 	res = ast_db_put(argv[2], argv[3], argv[4]);
-	if (res) 
+	if (res)  {
 		ast_cli(fd, "Failed to update entry\n");
-	else
+	} else {
 		ast_cli(fd, "Updated database successfully\n");
+	}
 	return RESULT_SUCCESS;
 }
 
@@ -241,10 +244,11 @@
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	res = ast_db_get(argv[2], argv[3], tmp, sizeof(tmp));
-	if (res) 
+	if (res) {
 		ast_cli(fd, "Database entry not found.\n");
-	else
+	} else {
 		ast_cli(fd, "Value: %s\n", tmp);
+	}
 	return RESULT_SUCCESS;
 }
 
@@ -254,10 +258,11 @@
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	res = ast_db_del(argv[2], argv[3]);
-	if (res) 
+	if (res) {
 		ast_cli(fd, "Database entry does not exist.\n");
-	else
+	} else {
 		ast_cli(fd, "Database entry removed.\n");
+	}
 	return RESULT_SUCCESS;
 }
 
@@ -266,14 +271,16 @@
 	int res;
 	if ((argc < 3) || (argc > 4))
 		return RESULT_SHOWUSAGE;
-	if (argc == 4)
+	if (argc == 4) {
 		res = ast_db_deltree(argv[2], argv[3]);
-	else
+	} else {
 		res = ast_db_deltree(argv[2], NULL);
-	if (res) 
+	}
+	if (res) {
 		ast_cli(fd, "Database entries do not exist.\n");
-	else
+	} else {
 		ast_cli(fd, "Database entries removed.\n");
+	}
 	return RESULT_SUCCESS;
 }
 
@@ -294,8 +301,9 @@
 	} else if (argc == 2) {
 		/* Neither */
 		prefix[0] = '\0';
-	} else
+	} else {
 		return RESULT_SHOWUSAGE;
+	}
 	ast_mutex_lock(&dblock);
 	if (dbinit()) {
 		ast_mutex_unlock(&dblock);
@@ -305,17 +313,19 @@
 	memset(&key, 0, sizeof(key));
 	memset(&data, 0, sizeof(data));
 	pass = 0;
-	while(!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
+	while (!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
 		if (key.size) {
 			keys = key.data;
 			keys[key.size - 1] = '\0';
-		} else
+		} else {
 			keys = "<bad key>";
+		}
 		if (data.size) {
 			values = data.data;
 			values[data.size - 1]='\0';
-		} else
+		} else {
 			values = "<bad value>";
+		}
 		if (keymatch(keys, prefix)) {
 				ast_cli(fd, "%-50s: %-25s\n", keys, values);
 		}
@@ -335,8 +345,9 @@
 	if (argc == 3) {
 		/* Key only */
 		snprintf(suffix, sizeof(suffix), "/%s", argv[2]);
-	} else
+	} else {
 		return RESULT_SHOWUSAGE;
+	}
 	ast_mutex_lock(&dblock);
 	if (dbinit()) {
 		ast_mutex_unlock(&dblock);
@@ -346,17 +357,19 @@
 	memset(&key, 0, sizeof(key));
 	memset(&data, 0, sizeof(data));
 	pass = 0;
-	while(!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
+	while (!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
 		if (key.size) {
 			keys = key.data;
 			keys[key.size - 1] = '\0';
-		} else
+		} else {
 			keys = "<bad key>";
+		}
 		if (data.size) {
 			values = data.data;
 			values[data.size - 1]='\0';
-		} else
+		} else {
 			values = "<bad value>";
+		}
 		if (subkeymatch(keys, suffix)) {
 				ast_cli(fd, "%-50s: %-25s\n", keys, values);
 		}
@@ -376,14 +389,16 @@
 	struct ast_db_entry *cur, *ret=NULL;
 
 	if (family && !ast_strlen_zero(family)) {
-		if (keytree && !ast_strlen_zero(keytree))
+		if (keytree && !ast_strlen_zero(keytree)) {
 			/* Family and key tree */
 			snprintf(prefix, sizeof(prefix), "/%s/%s", family, prefix);
-		else
+		} else {
 			/* Family only */
 			snprintf(prefix, sizeof(prefix), "/%s", family);
-	} else
+		}
+	} else {
 		prefix[0] = '\0';
+	}
 	ast_mutex_lock(&dblock);
 	if (dbinit()) {
 		ast_mutex_unlock(&dblock);
@@ -393,30 +408,33 @@
 	memset(&key, 0, sizeof(key));
 	memset(&data, 0, sizeof(data));
 	pass = 0;
-	while(!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
+	while (!(res = astdb->seq(astdb, &key, &data, pass++ ? R_NEXT : R_FIRST))) {
 		if (key.size) {
 			keys = key.data;
 			keys[key.size - 1] = '\0';
-		} else
+		} else {
 			keys = "<bad key>";
+		}
 		if (data.size) {
 			values = data.data;
-			values[data.size - 1]='\0';
-		} else
+			values[data.size - 1] = '\0';
+		} else {
 			values = "<bad value>";
+		}
 		if (keymatch(keys, prefix)) {
-				cur = malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2);
-				if (cur) {
-					cur->next = NULL;
-					cur->key = cur->data + strlen(values) + 1;
-					strcpy(cur->data, values);
-					strcpy(cur->key, keys);
-					if (last)
-						last->next = cur;
-					else
-						ret = cur;
-					last = cur;
+			cur = malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2);
+			if (cur) {
+				cur->next = NULL;
+				cur->key = cur->data + strlen(values) + 1;
+				strcpy(cur->data, values);
+				strcpy(cur->key, keys);
+				if (last) {
+					last->next = cur;
+				} else {
+					ret = cur;
 				}
+				last = cur;
+			}
 		}
 	}
 	ast_mutex_unlock(&dblock);
@@ -426,7 +444,7 @@
 void ast_db_freetree(struct ast_db_entry *dbe)
 {
 	struct ast_db_entry *last;
-	while(dbe) {
+	while (dbe) {
 		last = dbe;
 		dbe = dbe->next;
 		free(last);
@@ -501,10 +519,11 @@
 	}
 
 	res = ast_db_put(family, key, val);
-	if (res)
+	if (res) {
 		astman_send_error(s, m, "Failed to update entry");
-	else 
+	} else {
 		astman_send_ack(s, m, "Updated database successfully");
+	}
 	return 0;
 }
 
@@ -525,9 +544,9 @@
 	}
 
 	res = ast_db_get(family, key, tmp, sizeof(tmp));
-	if (res)
+	if (res) {
 		astman_send_error(s, m, "Database entry not found");
-	else {
+	} else {
 		astman_send_ack(s, m, "Result will follow");
 		ast_cli(s->fd, "Event: DBGetResponse\r\n"
 				"Family: %s\r\n"




More information about the svn-commits mailing list