#include <asterisk/options.h>
#include <asterisk/astdb.h>
#include <asterisk/cli.h>
+#include <asterisk/utils.h>
#include "db1-ast/include/db.h"
#include "asterisk.h"
#include "astconf.h"
static inline int keymatch(const char *key, const char *prefix)
{
- if (!strlen(prefix))
+ int preflen = strlen(prefix);
+ if (!preflen)
return 1;
if (!strcasecmp(key, prefix))
return 1;
- if ((strlen(key) > strlen(prefix)) &&
- !strncasecmp(key, prefix, strlen(prefix))) {
- if (key[strlen(prefix)] == '/')
+ if ((strlen(key) > preflen) &&
+ !strncasecmp(key, prefix, preflen)) {
+ if (key[preflen] == '/')
return 1;
}
return 0;
{
char fullkey[256];
DBT key, data;
- int res;
+ int res, fullkeylen;
ast_mutex_lock(&dblock);
if (dbinit()) {
return -1;
}
- snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
+ fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = fullkey;
- key.size = strlen(fullkey) + 1;
+ key.size = fullkeylen + 1;
data.data = value;
data.size = strlen(value) + 1;
res = astdb->put(astdb, &key, &data, 0);
{
char fullkey[256]="";
DBT key, data;
- int res;
+ int res, fullkeylen;
ast_mutex_lock(&dblock);
if (dbinit()) {
return -1;
}
- snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
+ fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
memset(value, 0, valuelen);
key.data = fullkey;
- key.size = strlen(fullkey) + 1;
+ key.size = fullkeylen + 1;
res = astdb->get(astdb, &key, &data, 0);
{
char fullkey[256];
DBT key;
- int res;
+ int res, fullkeylen;
ast_mutex_lock(&dblock);
if (dbinit()) {
return -1;
}
- snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
+ fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
memset(&key, 0, sizeof(key));
key.data = fullkey;
- key.size = strlen(fullkey) + 1;
+ key.size = fullkeylen + 1;
res = astdb->del(astdb, &key, 0);
astdb->sync(astdb, 0);
struct ast_db_entry *last = NULL;
struct ast_db_entry *cur, *ret=NULL;
- if (family && strlen(family)) {
- if (keytree && strlen(keytree))
+ if (family && !ast_strlen_zero(family)) {
+ if (keytree && !ast_strlen_zero(keytree))
/* Family and key tree */
snprintf(prefix, sizeof(prefix), "/%s/%s", family, prefix);
else