- convert the list of dundi mappings to use the list macros
- change an instance of malloc+memset to use ast_calloc, instead git-svn-id: http://svn.digium.com/svn/asterisk/trunk@23468 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
parent
02d013ed45
commit
4fba9b433c
|
@ -211,7 +211,7 @@ struct dundi_request {
|
||||||
struct dundi_request *next;
|
struct dundi_request *next;
|
||||||
} *requests;
|
} *requests;
|
||||||
|
|
||||||
static struct dundi_mapping {
|
struct dundi_mapping {
|
||||||
char dcontext[AST_MAX_EXTENSION];
|
char dcontext[AST_MAX_EXTENSION];
|
||||||
char lcontext[AST_MAX_EXTENSION];
|
char lcontext[AST_MAX_EXTENSION];
|
||||||
int weight;
|
int weight;
|
||||||
|
@ -219,8 +219,8 @@ static struct dundi_mapping {
|
||||||
int tech;
|
int tech;
|
||||||
int dead;
|
int dead;
|
||||||
char dest[AST_MAX_EXTENSION];
|
char dest[AST_MAX_EXTENSION];
|
||||||
struct dundi_mapping *next;
|
AST_LIST_ENTRY(dundi_mapping) list;
|
||||||
} *mappings = NULL;
|
};
|
||||||
|
|
||||||
struct dundi_peer {
|
struct dundi_peer {
|
||||||
dundi_eid eid;
|
dundi_eid eid;
|
||||||
|
@ -263,6 +263,7 @@ struct dundi_peer {
|
||||||
};
|
};
|
||||||
|
|
||||||
AST_LIST_HEAD_STATIC(peers, dundi_peer);
|
AST_LIST_HEAD_STATIC(peers, dundi_peer);
|
||||||
|
AST_LIST_HEAD_NOLOCK_STATIC(mappings, dundi_mapping);
|
||||||
|
|
||||||
static struct dundi_precache_queue *pcq;
|
static struct dundi_precache_queue *pcq;
|
||||||
|
|
||||||
|
@ -953,11 +954,9 @@ static int dundi_prop_precache(struct dundi_transaction *trans, struct dundi_ies
|
||||||
totallen = sizeof(struct dundi_query_state);
|
totallen = sizeof(struct dundi_query_state);
|
||||||
/* Count matching map entries */
|
/* Count matching map entries */
|
||||||
mapcount = 0;
|
mapcount = 0;
|
||||||
cur = mappings;
|
AST_LIST_TRAVERSE(&mappings, cur, list) {
|
||||||
while(cur) {
|
|
||||||
if (!strcasecmp(cur->dcontext, ccontext))
|
if (!strcasecmp(cur->dcontext, ccontext))
|
||||||
mapcount++;
|
mapcount++;
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no maps, return -1 immediately */
|
/* If no maps, return -1 immediately */
|
||||||
|
@ -996,16 +995,14 @@ static int dundi_prop_precache(struct dundi_transaction *trans, struct dundi_ies
|
||||||
/* Append mappings */
|
/* Append mappings */
|
||||||
x = 0;
|
x = 0;
|
||||||
st->maps = (struct dundi_mapping *)s;
|
st->maps = (struct dundi_mapping *)s;
|
||||||
cur = mappings;
|
AST_LIST_TRAVERSE(&mappings, cur, list) {
|
||||||
while(cur) {
|
|
||||||
if (!strcasecmp(cur->dcontext, ccontext)) {
|
if (!strcasecmp(cur->dcontext, ccontext)) {
|
||||||
if (x < mapcount) {
|
if (x < mapcount) {
|
||||||
st->maps[x] = *cur;
|
st->maps[x] = *cur;
|
||||||
st->maps[x].next = NULL;
|
st->maps[x].list.next = NULL;
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
st->nummaps = mapcount;
|
st->nummaps = mapcount;
|
||||||
ast_log(LOG_DEBUG, "Forwarding precache for '%s@%s'!\n", ies->called_number, ies->called_context);
|
ast_log(LOG_DEBUG, "Forwarding precache for '%s@%s'!\n", ies->called_number, ies->called_context);
|
||||||
|
@ -1039,19 +1036,16 @@ static int dundi_answer_query(struct dundi_transaction *trans, struct dundi_ies
|
||||||
struct dundi_ie_data ied;
|
struct dundi_ie_data ied;
|
||||||
char *s;
|
char *s;
|
||||||
struct dundi_mapping *cur;
|
struct dundi_mapping *cur;
|
||||||
int mapcount;
|
int mapcount = 0;
|
||||||
int skipfirst = 0;
|
int skipfirst = 0;
|
||||||
|
|
||||||
pthread_t lookupthread;
|
pthread_t lookupthread;
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
totallen = sizeof(struct dundi_query_state);
|
totallen = sizeof(struct dundi_query_state);
|
||||||
/* Count matching map entries */
|
/* Count matching map entries */
|
||||||
mapcount = 0;
|
AST_LIST_TRAVERSE(&mappings, cur, list) {
|
||||||
cur = mappings;
|
|
||||||
while(cur) {
|
|
||||||
if (!strcasecmp(cur->dcontext, ccontext))
|
if (!strcasecmp(cur->dcontext, ccontext))
|
||||||
mapcount++;
|
mapcount++;
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
/* If no maps, return -1 immediately */
|
/* If no maps, return -1 immediately */
|
||||||
if (!mapcount)
|
if (!mapcount)
|
||||||
|
@ -1088,16 +1082,14 @@ static int dundi_answer_query(struct dundi_transaction *trans, struct dundi_ies
|
||||||
/* Append mappings */
|
/* Append mappings */
|
||||||
x = 0;
|
x = 0;
|
||||||
st->maps = (struct dundi_mapping *)s;
|
st->maps = (struct dundi_mapping *)s;
|
||||||
cur = mappings;
|
AST_LIST_TRAVERSE(&mappings, cur, list) {
|
||||||
while(cur) {
|
|
||||||
if (!strcasecmp(cur->dcontext, ccontext)) {
|
if (!strcasecmp(cur->dcontext, ccontext)) {
|
||||||
if (x < mapcount) {
|
if (x < mapcount) {
|
||||||
st->maps[x] = *cur;
|
st->maps[x] = *cur;
|
||||||
st->maps[x].next = NULL;
|
st->maps[x].list.next = NULL;
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
st->nummaps = mapcount;
|
st->nummaps = mapcount;
|
||||||
ast_log(LOG_DEBUG, "Answering query for '%s@%s'!\n", ies->called_number, ies->called_context);
|
ast_log(LOG_DEBUG, "Answering query for '%s@%s'!\n", ies->called_number, ies->called_context);
|
||||||
|
@ -2596,10 +2588,10 @@ static int dundi_show_mappings(int fd, int argc, char *argv[])
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
AST_LIST_LOCK(&peers);
|
AST_LIST_LOCK(&peers);
|
||||||
ast_cli(fd, FORMAT2, "DUNDi Cntxt", "Weight", "Local Cntxt", "Options", "Tech", "Destination");
|
ast_cli(fd, FORMAT2, "DUNDi Cntxt", "Weight", "Local Cntxt", "Options", "Tech", "Destination");
|
||||||
for (map = mappings;map;map = map->next) {
|
AST_LIST_TRAVERSE(&mappings, map, list) {
|
||||||
ast_cli(fd, FORMAT, map->dcontext, map->weight,
|
ast_cli(fd, FORMAT, map->dcontext, map->weight,
|
||||||
ast_strlen_zero(map->lcontext) ? "<none>" : map->lcontext,
|
ast_strlen_zero(map->lcontext) ? "<none>" : map->lcontext,
|
||||||
dundi_flags2str(fs, sizeof(fs), map->options), tech2str(map->tech), map->dest);
|
dundi_flags2str(fs, sizeof(fs), map->options), tech2str(map->tech), map->dest);
|
||||||
}
|
}
|
||||||
AST_LIST_UNLOCK(&peers);
|
AST_LIST_UNLOCK(&peers);
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
@ -3662,17 +3654,17 @@ static void dundi_precache_full(void)
|
||||||
struct dundi_mapping *cur;
|
struct dundi_mapping *cur;
|
||||||
struct ast_context *con;
|
struct ast_context *con;
|
||||||
struct ast_exten *e;
|
struct ast_exten *e;
|
||||||
cur = mappings;
|
|
||||||
while(cur) {
|
AST_LIST_TRAVERSE(&mappings, cur, list) {
|
||||||
ast_log(LOG_NOTICE, "Should precache context '%s'\n", cur->dcontext);
|
ast_log(LOG_NOTICE, "Should precache context '%s'\n", cur->dcontext);
|
||||||
ast_lock_contexts();
|
ast_lock_contexts();
|
||||||
con = ast_walk_contexts(NULL);
|
con = ast_walk_contexts(NULL);
|
||||||
while(con) {
|
while (con) {
|
||||||
if (!strcasecmp(cur->lcontext, ast_get_context_name(con))) {
|
if (!strcasecmp(cur->lcontext, ast_get_context_name(con))) {
|
||||||
/* Found the match, now queue them all up */
|
/* Found the match, now queue them all up */
|
||||||
ast_lock_context(con);
|
ast_lock_context(con);
|
||||||
e = ast_walk_context_extensions(con, NULL);
|
e = ast_walk_context_extensions(con, NULL);
|
||||||
while(e) {
|
while (e) {
|
||||||
reschedule_precache(ast_get_extension_name(e), cur->dcontext, 0);
|
reschedule_precache(ast_get_extension_name(e), cur->dcontext, 0);
|
||||||
e = ast_walk_context_extensions(con, e);
|
e = ast_walk_context_extensions(con, e);
|
||||||
}
|
}
|
||||||
|
@ -3681,7 +3673,6 @@ static void dundi_precache_full(void)
|
||||||
con = ast_walk_contexts(con);
|
con = ast_walk_contexts(con);
|
||||||
}
|
}
|
||||||
ast_unlock_contexts();
|
ast_unlock_contexts();
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3691,8 +3682,8 @@ static int dundi_precache_internal(const char *context, const char *number, int
|
||||||
struct dundi_hint_metadata hmd;
|
struct dundi_hint_metadata hmd;
|
||||||
struct dundi_result dr2[MAX_RESULTS];
|
struct dundi_result dr2[MAX_RESULTS];
|
||||||
struct timeval start;
|
struct timeval start;
|
||||||
struct dundi_mapping *maps=NULL, *cur;
|
struct dundi_mapping *maps = NULL, *cur;
|
||||||
int nummaps;
|
int nummaps = 0;
|
||||||
int foundanswers;
|
int foundanswers;
|
||||||
int foundcache, skipped, ttlms, ms;
|
int foundcache, skipped, ttlms, ms;
|
||||||
if (!context)
|
if (!context)
|
||||||
|
@ -3700,22 +3691,17 @@ static int dundi_precache_internal(const char *context, const char *number, int
|
||||||
ast_log(LOG_DEBUG, "Precache internal (%s@%s)!\n", number, context);
|
ast_log(LOG_DEBUG, "Precache internal (%s@%s)!\n", number, context);
|
||||||
|
|
||||||
AST_LIST_LOCK(&peers);
|
AST_LIST_LOCK(&peers);
|
||||||
nummaps = 0;
|
AST_LIST_TRAVERSE(&mappings, cur, list) {
|
||||||
cur = mappings;
|
|
||||||
while(cur) {
|
|
||||||
if (!strcasecmp(cur->dcontext, context))
|
if (!strcasecmp(cur->dcontext, context))
|
||||||
nummaps++;
|
nummaps++;
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
if (nummaps) {
|
if (nummaps) {
|
||||||
maps = alloca(nummaps * sizeof(struct dundi_mapping));
|
maps = alloca(nummaps * sizeof(*maps));
|
||||||
nummaps = 0;
|
nummaps = 0;
|
||||||
if (maps) {
|
if (maps) {
|
||||||
cur = mappings;
|
AST_LIST_TRAVERSE(&mappings, cur, list) {
|
||||||
while(cur) {
|
|
||||||
if (!strcasecmp(cur->dcontext, context))
|
if (!strcasecmp(cur->dcontext, context))
|
||||||
maps[nummaps++] = *cur;
|
maps[nummaps++] = *cur;
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3900,11 +3886,10 @@ static void mark_peers(void)
|
||||||
static void mark_mappings(void)
|
static void mark_mappings(void)
|
||||||
{
|
{
|
||||||
struct dundi_mapping *map;
|
struct dundi_mapping *map;
|
||||||
|
|
||||||
AST_LIST_LOCK(&peers);
|
AST_LIST_LOCK(&peers);
|
||||||
map = mappings;
|
AST_LIST_TRAVERSE(&mappings, map, list) {
|
||||||
while(map) {
|
|
||||||
map->dead = 1;
|
map->dead = 1;
|
||||||
map = map->next;
|
|
||||||
}
|
}
|
||||||
AST_LIST_UNLOCK(&peers);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
@ -3956,22 +3941,16 @@ static void prune_peers(void)
|
||||||
|
|
||||||
static void prune_mappings(void)
|
static void prune_mappings(void)
|
||||||
{
|
{
|
||||||
struct dundi_mapping *map, *prev, *next;
|
struct dundi_mapping *map;
|
||||||
|
|
||||||
AST_LIST_LOCK(&peers);
|
AST_LIST_LOCK(&peers);
|
||||||
map = mappings;
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&mappings, map, list) {
|
||||||
prev = NULL;
|
|
||||||
while(map) {
|
|
||||||
next = map->next;
|
|
||||||
if (map->dead) {
|
if (map->dead) {
|
||||||
if (prev)
|
AST_LIST_REMOVE_CURRENT(&mappings, list);
|
||||||
prev->next = map->next;
|
|
||||||
else
|
|
||||||
mappings = map->next;
|
|
||||||
destroy_map(map);
|
destroy_map(map);
|
||||||
} else
|
}
|
||||||
prev = map;
|
|
||||||
map = next;
|
|
||||||
}
|
}
|
||||||
|
AST_LIST_TRAVERSE_SAFE_END
|
||||||
AST_LIST_UNLOCK(&peers);
|
AST_LIST_UNLOCK(&peers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4007,22 +3986,18 @@ static void build_mapping(char *name, char *value)
|
||||||
int y;
|
int y;
|
||||||
t = ast_strdupa(value);
|
t = ast_strdupa(value);
|
||||||
if (t) {
|
if (t) {
|
||||||
map = mappings;
|
AST_LIST_TRAVERSE(&mappings, map, list) {
|
||||||
while(map) {
|
|
||||||
/* Find a double match */
|
/* Find a double match */
|
||||||
if (!strcasecmp(map->dcontext, name) &&
|
if (!strcasecmp(map->dcontext, name) &&
|
||||||
(!strncasecmp(map->lcontext, value, strlen(map->lcontext)) &&
|
(!strncasecmp(map->lcontext, value, strlen(map->lcontext)) &&
|
||||||
(!value[strlen(map->lcontext)] ||
|
(!value[strlen(map->lcontext)] ||
|
||||||
(value[strlen(map->lcontext)] == ','))))
|
(value[strlen(map->lcontext)] == ','))))
|
||||||
break;
|
break;
|
||||||
map = map->next;
|
|
||||||
}
|
}
|
||||||
if (!map) {
|
if (!map) {
|
||||||
map = malloc(sizeof(struct dundi_mapping));
|
map = ast_calloc(1, sizeof(*map));
|
||||||
if (map) {
|
if (map) {
|
||||||
memset(map, 0, sizeof(struct dundi_mapping));
|
AST_LIST_INSERT_HEAD(&mappings, map, list);
|
||||||
map->next = mappings;
|
|
||||||
mappings = map;
|
|
||||||
map->dead = 1;
|
map->dead = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue