[asterisk-commits] nadi: branch nadi/trunk-cm r43976 - in
/team/nadi/trunk-cm: include/asterisk/...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Sep 29 05:37:20 MST 2006
Author: nadi
Date: Fri Sep 29 07:37:20 2006
New Revision: 43976
URL: http://svn.digium.com/view/asterisk?rev=43976&view=rev
Log:
configman now uses the hash implementation from hash.h.
Modified:
team/nadi/trunk-cm/include/asterisk/configman.h
team/nadi/trunk-cm/include/asterisk/hash.h
team/nadi/trunk-cm/main/configman.c
team/nadi/trunk-cm/main/hash.c
Modified: team/nadi/trunk-cm/include/asterisk/configman.h
URL: http://svn.digium.com/view/asterisk/team/nadi/trunk-cm/include/asterisk/configman.h?rev=43976&r1=43975&r2=43976&view=diff
==============================================================================
--- team/nadi/trunk-cm/include/asterisk/configman.h (original)
+++ team/nadi/trunk-cm/include/asterisk/configman.h Fri Sep 29 07:37:20 2006
@@ -112,6 +112,11 @@
*
* Returns non-zero if next points to the id after prev, or zero if there
* is no subsequent id.
+ * Example for KTYPE_INT:
+ * int next, *prev = NULL;
+ * for (; cm_get_next_id(mycm, mysec_id, prev, &next); prev = &next) {
+ * .. <next> is your traversing id ..
+ * }
*/
int cm_get_next_id (cm_t *cm, int sec_id, void *prev, void *next);
Modified: team/nadi/trunk-cm/include/asterisk/hash.h
URL: http://svn.digium.com/view/asterisk/team/nadi/trunk-cm/include/asterisk/hash.h?rev=43976&r1=43975&r2=43976&view=diff
==============================================================================
--- team/nadi/trunk-cm/include/asterisk/hash.h (original)
+++ team/nadi/trunk-cm/include/asterisk/hash.h Fri Sep 29 07:37:20 2006
@@ -42,6 +42,20 @@
int eq_int (int a, int b);
#define __AST_HASH(name, ktype, vtype) \
+struct name { \
+ struct { \
+ char _used; \
+ ktype _key; \
+ vtype _val; \
+ } *_data; \
+ size_t _size; \
+ size_t _length; \
+ ast_mutex_t _lock; \
+ int (*_hash_f)(ktype, size_t); \
+ int (*_eq_f) (ktype, ktype); \
+}
+
+#define __AST_HASH_NOLOCK(name, ktype, vtype) \
struct name { \
struct { \
ktype _key; \
@@ -50,7 +64,6 @@
} *_data; \
size_t _size; \
size_t _length; \
- ast_mutex_t _lock; \
int (*_hash_f)(ktype, size_t); \
int (*_eq_f) (ktype, ktype); \
}
@@ -58,8 +71,14 @@
#define AST_HASH_INT(name, type) \
__AST_HASH(name, int, type)
+#define AST_HASH_INT_NOLOCK(name, type) \
+ __AST_HASH_NOLOCK(name, int, type)
+
#define AST_HASH_STR(name, type) \
__AST_HASH(name, char*, type)
+
+#define AST_HASH_STR_NOLOCK(name, type) \
+ __AST_HASH_NOLOCK(name, char*, type)
@@ -122,70 +141,76 @@
#define AST_HASH_INSERT_NOLOCK(hash, key, val) \
({ \
- int pos = (hash)->_hash_f(key, (hash)->_size); \
- int end = pos; \
- int re = -1; \
+ int _pos = (hash)->_hash_f(key, (hash)->_size); \
+ int _end = _pos; \
+ int _re = -1; \
do { \
- if (!(hash)->_data[pos]._used) { \
- (hash)->_data[pos]._key = key; \
- (hash)->_data[pos]._val = val; \
- (hash)->_data[pos]._used = 1; \
+ if (!(hash)->_data[_pos]._used) { \
+ (hash)->_data[_pos]._key = key; \
+ (hash)->_data[_pos]._val = val; \
+ (hash)->_data[_pos]._used = 1; \
++(hash)->_length; \
- re = 0; \
+ _re = 0; \
break; \
} \
- pos = (pos + 1) % (hash)->_size; \
- } while (pos != end); \
- re; \
+ _pos = (_pos + 1) % (hash)->_size; \
+ } while (_pos != _end); \
+ _re; \
})
#define AST_HASH_INSERT(hash, key, val) \
({ \
- int re; \
- AST_HASH_LOCK((hash)); \
- re = AST_HASH_INSERT_NOLOCK(hash, key, val);\
+ int _re; \
+ AST_HASH_LOCK((hash)); \
+ _re = AST_HASH_INSERT_NOLOCK(hash, key, val);\
AST_HASH_UNLOCK((hash)); \
- re; \
-})
+ _re; \
+})
+
+
+
#define AST_HASH_LOOKUP_NOLOCK(hash, key, val) \
({ \
- int pos = (hash)->_hash_f(key, (hash)->_size); \
- int end = pos; \
- int re = -1; \
+ int _pos = (hash)->_hash_f(key, (hash)->_size); \
+ int _end = _pos; \
+ int _re = -1; \
do { \
- if ((hash)->_data[pos]._used && \
- (hash)->_eq_f((hash)->_data[pos]._key, key)) { \
- val = (hash)->_data[pos]._val; \
- re = 0; \
+ if ((hash)->_data[_pos]._used && \
+ (hash)->_eq_f((hash)->_data[_pos]._key, key)) { \
+ val = (hash)->_data[_pos]._val; \
+ _re = 0; \
} \
- pos = (pos + 1) % (hash)->_size; \
- } while (pos != end); \
- re; \
+ _pos = (_pos + 1) % (hash)->_size; \
+ } while (_pos != _end); \
+ _re; \
})
#define AST_HASH_LOOKUP(hash, key, val) \
({ \
- int re; \
- AST_HASH_LOCK((hash)); \
- re = AST_HASH_LOOKUP_NOLOCK(hash, key, val);\
+ int _re; \
+ AST_HASH_LOCK((hash)); \
+ _re = AST_HASH_LOOKUP_NOLOCK(hash, key, val);\
AST_HASH_UNLOCK((hash)); \
- re; \
-})
+ _re; \
+})
+
+
+
#define AST_HASH_REMOVE_NOLOCK(hash, key) \
do { \
- int pos = (hash)->_hash_f((key), (hash)->_size); \
- int end = pos; \
+ int _pos = (hash)->_hash_f((key), (hash)->_size); \
+ int _end = _pos; \
do { \
- if ((hash)->_data[pos]._used && \
- (hash)->_eq_f((hash)->_data[pos]._key, (key))) { \
- (hash)->_data[pos]._used = 0; \
+ if ((hash)->_data[_pos]._used && \
+ (hash)->_eq_f((hash)->_data[_pos]._key, (key))) { \
+ (hash)->_data[_pos]._used = 0; \
--(hash)->_length; \
break; \
} \
- pos = (pos + 1) % (hash)->_size; \
- } while (pos != end); \
+ _pos = (_pos + 1) % (hash)->_size; \
+ } while (_pos != _end); \
} while (0) \
#define AST_HASH_REMOVE(hash, key) \
Modified: team/nadi/trunk-cm/main/configman.c
URL: http://svn.digium.com/view/asterisk/team/nadi/trunk-cm/main/configman.c?rev=43976&r1=43975&r2=43976&view=diff
==============================================================================
--- team/nadi/trunk-cm/main/configman.c (original)
+++ team/nadi/trunk-cm/main/configman.c Fri Sep 29 07:37:20 2006
@@ -28,7 +28,6 @@
*/
/* TODO:
- * - get rid of the hash code by implementing ast_hash or similar.
* - write macros for easier variable access (cm_get_bool, cm_get_int, cm_get_strlist, cm_get_intlist, ...)
* - handle return values for *alloc, strdup, ast_cli_register
*/
@@ -83,8 +82,8 @@
#define ERROR_CMF(cm,fmt,...) \
ast_log(LOG_ERROR, "%s [%s]: " fmt, (cm)->modname, (cm)->filename, ##__VA_ARGS__)
-#define LOCK(cm) ast_mutex_lock(&((cm)->lock))
-#define UNLOCK(cm) ast_mutex_unlock(&((cm)->lock))
+#define LOCK(cm) ast_mutex_lock(&((cm)->lock))
+#define UNLOCK(cm) ast_mutex_unlock(&((cm)->lock))
#define HASHSIZE 512
@@ -95,25 +94,16 @@
static char VALUES[] = "values";
typedef union {
- char * c;
- int i;
-} cm_hash_key_t;
+ AST_HASH_INT_NOLOCK(, int) i;
+ AST_HASH_STR_NOLOCK(, int) c;
+} cm_hash_t;
typedef union {
- int i;
- void * p;
-} cm_hash_value_t;
-
-typedef struct {
- int used;
- cm_hash_key_t key;
- cm_hash_value_t val;
-} cm_hash_entry_t;
-
-typedef struct {
- cm_hash_entry_t data[HASHSIZE];
- size_t length;
-} cm_hash_t;
+ int i;
+ char * c;
+} cm_key_t;
+
+static AST_HASH_STR(cm_obj_hash_t, cm_t *) cm_obj_hash;
enum cm_state {
CM_NULL = 0,
@@ -137,96 +127,9 @@
const cm_section_t * secs;
cm_matrix_t * vals;
cm_hash_t ** hashes;
- cm_hash_key_t ** key_lists;
+ cm_key_t ** key_arrays;
struct ast_cli_entry clis[3];
};
-
-static AST_HASH_STR(cm_obj_hash_t, cm_t *) cm_obj_hash;
-
-static inline int __joaat_hash (char *key, size_t len)
-{
- int hash = 0;
- size_t i;
-
- for (i = 0; i < len; ++i) {
- hash += key[i];
- hash += (hash << 10);
- hash ^= (hash >> 6);
- }
- hash += (hash << 3);
- hash ^= (hash >> 11);
- hash += (hash << 15);
- hash %= HASHSIZE;
-
- if (hash < 0)
- hash *= -1;
-
- return hash;
-}
-
-static inline int __hash_insert (cm_hash_t *hash, int pos, cm_hash_key_t key, cm_hash_value_t val)
-{
- int end = pos;
-
- do {
- if (!hash->data[pos].used) {
- hash->data[pos].key = key;
- hash->data[pos].val = val;
- hash->data[pos].used = 1;
- ++hash->length;
- return 0;
- }
- pos = (pos + 1) % HASHSIZE;
- } while (pos != end);
-
- return -1;
-}
-
-static int __hash_insert_int (cm_hash_t *hash, int key, cm_hash_value_t val)
-{
- int pos = __joaat_hash((char *)&key, sizeof(int));
-
- return __hash_insert(hash, pos, (cm_hash_key_t)key, val);
-}
-
-static int __hash_insert_string (cm_hash_t *hash, char *key, cm_hash_value_t val)
-{
- int pos = __joaat_hash(key, strlen(key));
-
- return __hash_insert(hash, pos, (cm_hash_key_t)key, val);
-}
-
-static int __hash_lookup_int (cm_hash_t *hash, int key, cm_hash_value_t *val)
-{
- int pos = __joaat_hash((char *)&key, sizeof(int));
- int end = pos;
-
- do {
- if (hash->data[pos].used && hash->data[pos].key.i == key) {
- *val = hash->data[pos].val;
- return 0;
- }
- pos = (pos + 1) % HASHSIZE;
- } while (pos != end);
-
- return -1;
-}
-
-static int __hash_lookup_string (cm_hash_t *hash, char *key, cm_hash_value_t *val)
-{
- int pos = __joaat_hash(key, strlen(key));
- int end = pos;
-
- do {
- if (hash->data[pos].used && !strcmp(hash->data[pos].key.c, key)) {
- *val = hash->data[pos].val;
- return 0;
- }
- pos = (pos + 1) % HASHSIZE;
- } while (pos != end);
-
- return -1;
-}
static int __get_col (const cm_section_t *sec, char *name)
{
@@ -248,7 +151,7 @@
va_list ap;
int id_int;
char * id_string;
- cm_hash_value_t val;
+ int val;
if (!cm)
goto err1;
@@ -267,7 +170,7 @@
va_end(ap);
if (!cm->hashes[sec_id])
goto err2;
- if (__hash_lookup_int(cm->hashes[sec_id], id_int, &val))
+ if (AST_HASH_LOOKUP_NOLOCK(&cm->hashes[sec_id]->i, id_int, val))
goto err2;
break;
case KTYPE_STRING:
@@ -276,7 +179,7 @@
va_end(ap);
if (!cm->hashes[sec_id])
goto err2;
- if (__hash_lookup_string(cm->hashes[sec_id], id_string, &val))
+ if (AST_HASH_LOOKUP_NOLOCK(&cm->hashes[sec_id]->c, id_string, val))
goto err2;
break;
}
@@ -294,10 +197,10 @@
int cm_get (cm_t *cm, char *buf, size_t size, int sec_id, int elem_id, ...)
{
va_list ap;
- int id_int;
+ int id_int,
+ row = 0;
char * val,
* id_string;
- cm_hash_value_t row;
if (!cm)
goto err1;
@@ -325,7 +228,7 @@
va_end(ap);
if (!cm->hashes[sec_id])
goto err2;
- if (__hash_lookup_int(cm->hashes[sec_id], id_int, &row))
+ if (AST_HASH_LOOKUP_NOLOCK(&cm->hashes[sec_id]->i, id_int, row))
goto err2;
break;
case KTYPE_STRING:
@@ -334,12 +237,12 @@
va_end(ap);
if (!cm->hashes[sec_id])
goto err2;
- if (__hash_lookup_string(cm->hashes[sec_id], id_string, &row))
+ if (AST_HASH_LOOKUP_NOLOCK(&cm->hashes[sec_id]->c, id_string, row))
goto err2;
break;
}
- val = cm->vals[sec_id].rows[row.i][elem_id];
+ val = cm->vals[sec_id].rows[row][elem_id];
if (!val)
val = cm->vals[sec_id].rows[0][elem_id];
if (!val || !memccpy(buf, val, 0, size)) {
@@ -425,8 +328,10 @@
switch (sec->key_type) {
case KTYPE_INTEGER:
- if (!*hash)
+ if (!*hash) {
*hash = calloc(1, sizeof(cm_hash_t));
+ AST_HASH_INIT_INT_NOLOCK(&(*hash)->i, HASHSIZE);
+ }
pos = __get_col(sec, sec->key_field);
if (pos < 0)
ERROR_CM(cm, "missing key field \"%s\" in section structure!\n", sec->key_field);
@@ -443,11 +348,11 @@
continue;
if (sscanf(token, "%d-%d", &start, &end) >= 2) {
for (; start <= end; start++) {
- if (__hash_insert_int(*hash, start, (cm_hash_value_t)i))
+ if (AST_HASH_INSERT_NOLOCK(&(*hash)->i, start, i))
WARNING_CMF(cm, "failed to hash integer key: %d\n", start);
}
} else if (sscanf(token, "%d", &start)) {
- if (__hash_insert_int(*hash, start, (cm_hash_value_t)i))
+ if (AST_HASH_INSERT_NOLOCK(&(*hash)->i, start, i))
WARNING_CMF(cm, "failed to hash integer key: %d\n", start);
} else
WARNING_PARSE_NV(cm, sec->directives[pos].name, matrix->rows[i][pos], sec->section_name);
@@ -457,8 +362,10 @@
}
break;
case KTYPE_STRING:
- if (!*hash)
+ if (!*hash) {
*hash = calloc(1, sizeof(cm_hash_t));
+ AST_HASH_INIT_STR_NOLOCK(&(*hash)->c, HASHSIZE);
+ }
pos = __get_col(sec, sec->key_field);
if (pos < 0)
ERROR_CM(cm, "missing key field \"%s\" in section structure!\n", sec->key_field);
@@ -469,8 +376,8 @@
sec->key_field,
matrix->rows[i][0] ? matrix->rows[i][0] : sec->section_name);
else {
- if (__hash_insert_string(*hash, matrix->rows[i][pos], (cm_hash_value_t)i))
- WARNING_CMF(cm, "failed to hash string key: %s\n", matrix->rows[matrix->num_rows - 1][pos]);
+ if (AST_HASH_INSERT_NOLOCK(&(*hash)->c, matrix->rows[i][pos], i))
+ WARNING_CMF(cm, "failed to hash string key: %s\n", matrix->rows[i][pos]);
}
}
break;
@@ -495,63 +402,65 @@
matrix->rows[0][0] = sec->default_name ? strdup(sec->default_name) : strdup(sec->section_name);
for (i = 1; i < sec->num_directives; ++i)
- if (!matrix->rows[0][i] && sec->directives[i].def && *sec->directives[i].def)
+ if (!matrix->rows[0][i] && sec->directives[i].def)
matrix->rows[0][i] = strdup(sec->directives[i].def);
}
-static inline void __key_list_insert_sorted_int (cm_hash_key_t *key_list, cm_hash_key_t key)
+static inline void __keys_insert_sorted_int (cm_key_t *keys, int key)
{
int i,
a,
b;
- for (i = 0; key_list[i].i != -1 && key_list[i].i <= key.i; ++i);
-
- b = key_list[i].i;
- key_list[i].i = key.i;
+ for (i = 0; keys[i].i != -1 && keys[i].i <= key; ++i);
+
+ b = keys[i].i;
+ keys[i].i = key;
for (++i; b != -1; ++i) {
- a = key_list[i].i;
- key_list[i].i = b;
+ a = keys[i].i;
+ keys[i].i = b;
b = a;
}
}
-static inline void __key_list_insert_sorted_string (cm_hash_key_t *key_list, cm_hash_key_t key)
+static inline void __keys_insert_sorted_string (cm_key_t *keys, char *key)
{
int i;
char * a,
* b;
- for (i = 0; key_list[i].c && strcasecmp(key_list[i].c, key.c) <= 0; ++i);
-
- b = key_list[i].c;
- key_list[i].c = key.c;
+ for (i = 0; keys[i].c && strcasecmp(keys[i].c, key) <= 0; ++i);
+
+ b = keys[i].c;
+ keys[i].c = key;
for (++i; b; ++i) {
- a = key_list[i].c;
- key_list[i].c = b;
+ a = keys[i].c;
+ keys[i].c = b;
b = a;
}
}
-static void __init_key_list (cm_t *cm, cm_hash_t *hash, cm_hash_key_t **key_list, enum ktype type)
-{
- int i;
-
- *key_list = calloc(hash->length, sizeof(key_list));
-
- if (type == KTYPE_INTEGER)
- for (i = 0; i < hash->length; ++i)
- (*key_list)[i].i = -1;
-
- for (i = 0; i < HASHSIZE; ++i) {
- if (hash->data[i].used) {
- if (type == KTYPE_INTEGER)
- __key_list_insert_sorted_int(*key_list, hash->data[i].key);
- else
- __key_list_insert_sorted_string(*key_list, hash->data[i].key);
- }
+static void __init_keys (cm_t *cm, cm_hash_t *hash, cm_key_t **keys, enum ktype type)
+{
+ int i,
+ id_int,
+ val;
+ char * id_string;
+
+ if (type == KTYPE_INTEGER) {
+ *keys = calloc(AST_HASH_LENGTH_NOLOCK(&hash->i), sizeof(cm_key_t));
+ for (i = 0; i < AST_HASH_LENGTH_NOLOCK(&hash->i); ++i)
+ (*keys)[i].i = -1;
+ AST_HASH_TRAVERSE_NOLOCK(&hash->i, id_int, val, i)
+ __keys_insert_sorted_int(*keys, id_int);
+ }
+
+ if (type == KTYPE_STRING) {
+ *keys = calloc(AST_HASH_LENGTH_NOLOCK(&hash->c), sizeof(cm_key_t));
+ AST_HASH_TRAVERSE_NOLOCK(&hash->c, id_string, val, i)
+ __keys_insert_sorted_string(*keys, id_string);
}
}
@@ -559,7 +468,7 @@
{
int i,
retval = 0;
- cm_hash_key_t * key_list;
+ cm_key_t * keys;
cm_hash_t * hash;
if (!cm)
@@ -571,9 +480,9 @@
goto err2;
hash = cm->hashes[sec_id];
- key_list = cm->key_lists[sec_id];
+ keys = cm->key_arrays[sec_id];
- if (!hash->length)
+ if (!AST_HASH_LENGTH_NOLOCK(&hash->i))
goto err2;
switch (cm->secs[sec_id].key_type) {
@@ -581,23 +490,23 @@
goto err2;
case KTYPE_INTEGER:
if (!prev || *(int *)prev < 0) {
- *(int *)next = key_list[0].i;
+ *(int *)next = keys[0].i;
} else {
- for (i = 0; i < hash->length && key_list[i].i != *(int *)prev; ++i);
- if (i >= (hash->length - 1))
+ for (i = 0; i < AST_HASH_LENGTH_NOLOCK(&hash->i) && keys[i].i != *(int *)prev; ++i);
+ if (i >= (AST_HASH_LENGTH_NOLOCK(&hash->i) - 1))
goto err2;
- *(int *)next = key_list[i + 1].i;
+ *(int *)next = keys[i + 1].i;
}
retval = 1;
break;
case KTYPE_STRING:
if (!prev || !*(char **)prev) {
- *(char **)next = key_list[0].c;
+ *(char **)next = keys[0].c;
} else {
- for (i = 0; i < hash->length && strcasecmp(key_list[i].c, *(char **)prev); ++i);
- if (i >= (hash->length - 1))
+ for (i = 0; i < AST_HASH_LENGTH_NOLOCK(&hash->c) && strcasecmp(keys[i].c, *(char **)prev); ++i);
+ if (i >= (AST_HASH_LENGTH_NOLOCK(&hash->c) - 1))
goto err2;
- *(char **)next = key_list[i + 1].c;
+ *(char **)next = keys[i + 1].c;
}
retval = 1;
break;
@@ -670,12 +579,12 @@
static char * __complete_keys (cm_t *cm, const cm_section_t *sec, const char *word, int state)
{
- cm_hash_key_t * key_list;
- int which = 0,
- wordlen = strlen(word),
- len,
- i;
- char buf[32];
+ cm_key_t * keys;
+ int which = 0,
+ wordlen = strlen(word),
+ len,
+ i;
+ char buf[32];
for (i = 0; i < cm->num_secs; ++i)
if (&cm->secs[i] == sec)
@@ -683,14 +592,14 @@
if (i == cm->num_secs)
return NULL;
- len = cm->hashes[i]->length;
- key_list = cm->key_lists[i];
+ len = AST_HASH_LENGTH_NOLOCK(&cm->hashes[i]->i);
+ keys = cm->key_arrays[i];
if (sec->key_type == KTYPE_STRING) {
for (i = 0; i < len; ++i) {
- if (!wordlen || !strncmp(word, key_list[i].c, wordlen)) {
+ if (!wordlen || !strncmp(word, keys[i].c, wordlen)) {
if (++which > state) {
- return strdup(key_list[i].c);
+ return strdup(keys[i].c);
}
}
}
@@ -698,11 +607,11 @@
if (!wordlen) {
if (state >= len)
return NULL;
- snprintf(buf, sizeof(buf), "%d", key_list[state].i);
+ snprintf(buf, sizeof(buf), "%d", keys[state].i);
return strdup(buf);
}
for (i = 0; i < len; ++i) {
- snprintf(buf, sizeof(buf), "%d", key_list[i].i);
+ snprintf(buf, sizeof(buf), "%d", keys[i].i);
if (!strncmp(word, buf, wordlen)) {
if (++which > state) {
return strdup(buf);
@@ -896,11 +805,11 @@
static void __show_config_values_list (int fd, cm_t *cm, int sec_id)
{
- cm_hash_key_t * key_list;
- cm_hash_value_t row;
- int len,
- i;
- char id[128];
+ cm_key_t * keys;
+ int len,
+ row = 0,
+ i;
+ char id[128];
switch (cm->secs[sec_id].key_type) {
case KTYPE_NONE:
@@ -908,23 +817,23 @@
__show_config_values(fd, cm, sec_id, 0);
break;
case KTYPE_INTEGER:
- len = cm->hashes[sec_id]->length;
- key_list = cm->key_lists[sec_id];
+ len = AST_HASH_LENGTH_NOLOCK(&cm->hashes[sec_id]->i);
+ keys = cm->key_arrays[sec_id];
for (i = 0; i < len; ++i) {
- if (!__hash_lookup_int(cm->hashes[sec_id], key_list[i].i, &row)) {
- snprintf(id, sizeof(id), "%d", key_list[i].i);
+ if (!AST_HASH_LOOKUP_NOLOCK(&cm->hashes[sec_id]->i, keys[i].i, row)) {
+ snprintf(id, sizeof(id), "%d", keys[i].i);
__show_config_values_header(fd, id);
- __show_config_values(fd, cm, sec_id, row.i);
+ __show_config_values(fd, cm, sec_id, row);
}
}
break;
case KTYPE_STRING:
- len = cm->hashes[sec_id]->length;
- key_list = cm->key_lists[sec_id];
+ len = AST_HASH_LENGTH_NOLOCK(&cm->hashes[sec_id]->c);
+ keys = cm->key_arrays[sec_id];
for (i = 0; i < len; ++i) {
- if (!__hash_lookup_string(cm->hashes[sec_id], key_list[i].c, &row)) {
- __show_config_values_header(fd, key_list[i].c);
- __show_config_values(fd, cm, sec_id, row.i);
+ if (!AST_HASH_LOOKUP_NOLOCK(&cm->hashes[sec_id]->c, keys[i].c, row)) {
+ __show_config_values_header(fd, keys[i].c);
+ __show_config_values(fd, cm, sec_id, row);
}
}
break;
@@ -933,12 +842,12 @@
static int cli_show_config_values (int fd, int argc, char *argv[])
{
- cm_t * cm;
- int err = RESULT_SHOWUSAGE,
- i,
- sec_id = -1,
- id_int;
- cm_hash_value_t row;
+ cm_t * cm;
+ int err = RESULT_SHOWUSAGE,
+ i,
+ sec_id = -1,
+ id_int,
+ row = 0;
if (argc < 4 || argc > 6)
return err;
@@ -968,20 +877,20 @@
goto out;
case KTYPE_INTEGER:
if (sscanf(argv[5], "%d", &id_int) != 1 ||
- __hash_lookup_int(cm->hashes[sec_id], id_int, &row)) {
+ AST_HASH_LOOKUP_NOLOCK(&cm->hashes[sec_id]->i, id_int, row)) {
ast_cli(fd, "Unknown ID: %s\n", argv[5]);
goto out;
}
break;
case KTYPE_STRING:
- if (__hash_lookup_string(cm->hashes[sec_id], argv[5], &row)) {
+ if (AST_HASH_LOOKUP_NOLOCK(&cm->hashes[sec_id]->c, argv[5], row)) {
ast_cli(fd, "Unknown ID: %s\n", argv[5]);
goto out;
}
break;
}
__show_config_values_header(fd, argv[5]);
- __show_config_values(fd, cm, sec_id, row.i);
+ __show_config_values(fd, cm, sec_id, row);
}
if (argc == 5)
@@ -1065,7 +974,7 @@
__fill_defaults(cm, &cm->secs[i], &cm->vals[i]);
if (cm->secs[i].key_type == KTYPE_INTEGER || cm->secs[i].key_type == KTYPE_STRING) {
__hash_categories(cm, &cm->secs[i], &cm->vals[i], &cm->hashes[i]);
- __init_key_list(cm, cm->hashes[i], &cm->key_lists[i], cm->secs[i].key_type);
+ __init_keys(cm, cm->hashes[i], &cm->key_arrays[i], cm->secs[i].key_type);
}
}
@@ -1143,14 +1052,16 @@
free(cm->filename);
for (i = 0; i < cm->num_secs; ++i) {
__destroy_matrix(&cm->vals[i], cm->secs[i].num_directives);
- if (cm->hashes[i])
+ if (cm->hashes[i]) {
+ AST_HASH_DESTROY_NOLOCK(&cm->hashes[i]->i);
free(cm->hashes[i]);
- if (cm->key_lists[i])
- free(cm->key_lists[i]);
- }
- }
-
- free(cm->key_lists);
+ }
+ if (cm->key_arrays[i])
+ free(cm->key_arrays[i]);
+ }
+ }
+
+ free(cm->key_arrays);
free(cm->hashes);
free(cm->vals);
free(cm->modname);
@@ -1189,8 +1100,8 @@
if (!cm->hashes)
goto err5;
- cm->key_lists = calloc(cm->num_secs, sizeof(cm_hash_entry_t *));
- if (!cm->key_lists)
+ cm->key_arrays = calloc(cm->num_secs, sizeof(cm_hash_t *));
+ if (!cm->key_arrays)
goto err6;
cm->clis[0].cmda[0] = cm->modname;
@@ -1269,7 +1180,7 @@
int ast_configman_init (void)
{
- AST_HASH_INIT_STR(&cm_obj_hash, 512);
+ AST_HASH_INIT_STR(&cm_obj_hash, HASHSIZE);
ast_cli_register_multiple(configman_clis, sizeof(configman_clis) / sizeof(struct ast_cli_entry));
ast_register_atexit(ast_configman_exit);
Modified: team/nadi/trunk-cm/main/hash.c
URL: http://svn.digium.com/view/asterisk/team/nadi/trunk-cm/main/hash.c?rev=43976&r1=43975&r2=43976&view=diff
==============================================================================
--- team/nadi/trunk-cm/main/hash.c (original)
+++ team/nadi/trunk-cm/main/hash.c Fri Sep 29 07:37:20 2006
@@ -40,9 +40,10 @@
int joaat_hash (char *key, size_t size)
{
int hash = 0;
+ int len = strlen(key);
size_t i;
- for (i = 0; i < size; ++i) {
+ for (i = 0; i < len; ++i) {
hash += key[i];
hash += (hash << 10);
hash ^= (hash >> 6);
More information about the asterisk-commits
mailing list