aboutsummaryrefslogtreecommitdiffstats
path: root/db.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-20 00:09:39 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-20 00:09:39 +0000
commita246ce557ac01eb6216269c745bda4df49684c5e (patch)
treeb864620e987754bbafb7e7be511bc3598b45e691 /db.c
parentef7ebdb3e89819b5eb92f638086e843ba7a805b8 (diff)
formatting cleanup (bug #4752)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6170 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'db.c')
-rwxr-xr-xdb.c119
1 files changed, 69 insertions, 50 deletions
diff --git a/db.c b/db.c
index 3a3c96c2e..707f57e2b 100755
--- a/db.c
+++ b/db.c
@@ -64,8 +64,7 @@ static inline int keymatch(const char *key, const char *prefix)
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 ast_db_deltree(const char *family, const char *keytree)
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 @@ int ast_db_deltree(const char *family, const char *keytree)
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_put(const char *family, const char *keys, char *value)
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 @@ static int database_put(int fd, int argc, char *argv[])
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 @@ static int database_get(int fd, int argc, char *argv[])
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 @@ static int database_del(int fd, int argc, char *argv[])
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 @@ static int database_deltree(int fd, int argc, char *argv[])
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 @@ static int database_show(int fd, int argc, char *argv[])
} 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 @@ static int database_show(int fd, int argc, char *argv[])
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 @@ static int database_showkey(int fd, int argc, char *argv[])
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 @@ static int database_showkey(int fd, int argc, char *argv[])
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 *ast_db_gettree(const char *family, const char *keytree)
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 @@ struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree)
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 @@ struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree)
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 @@ static int manager_dbput(struct mansession *s, struct message *m)
}
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 @@ static int manager_dbget(struct mansession *s, struct message *m)
}
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"