formatting cleanup (bug #4752)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6170 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
ef7ebdb3e8
commit
a246ce557a
1 changed files with 69 additions and 50 deletions
87
db.c
87
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())
|
||||
|
@ -114,8 +115,9 @@ int ast_db_deltree(const char *family, const char *keytree)
|
|||
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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -309,13 +317,15 @@ static int database_show(int fd, int argc, char *argv[])
|
|||
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);
|
||||
|
@ -350,13 +361,15 @@ static int database_showkey(int fd, int argc, char *argv[])
|
|||
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);
|
||||
|
@ -397,13 +412,15 @@ struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree)
|
|||
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)) {
|
||||
cur = malloc(sizeof(struct ast_db_entry) + strlen(keys) + strlen(values) + 2);
|
||||
if (cur) {
|
||||
|
@ -411,10 +428,11 @@ struct ast_db_entry *ast_db_gettree(const char *family, const char *keytree)
|
|||
cur->key = cur->data + strlen(values) + 1;
|
||||
strcpy(cur->data, values);
|
||||
strcpy(cur->key, keys);
|
||||
if (last)
|
||||
if (last) {
|
||||
last->next = cur;
|
||||
else
|
||||
} else {
|
||||
ret = cur;
|
||||
}
|
||||
last = cur;
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
|
Reference in a new issue