Merged revisions 34159-34160 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r34159 | kpfleming | 2006-06-14 17:17:37 -0500 (Wed, 14 Jun 2006) | 2 lines

use existing dial string parser for strings supplied to iax2_devicestate, because they can be complete dial strings, not just device names

........
r34160 | kpfleming | 2006-06-14 17:22:21 -0500 (Wed, 14 Jun 2006) | 2 lines

coding style cleanups on queue interface handling code that was committed for the last release

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@34161 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2006-06-14 22:35:49 +00:00
parent 8fd35365f5
commit 11dac47877
2 changed files with 98 additions and 108 deletions

View File

@@ -506,8 +506,7 @@ static void *changethread(void *data)
technology = ast_strdupa(sc->dev);
loc = strchr(technology, '/');
if (loc) {
*loc = '\0';
loc++;
*loc++ = '\0';
} else {
free(sc);
return NULL;
@@ -520,19 +519,27 @@ static void *changethread(void *data)
}
AST_LIST_UNLOCK(&interfaces);
if (curint) {
if (!curint) {
if (option_debug)
ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", technology, loc, sc->state, devstate2str(sc->state));
free(sc);
return NULL;
}
if (option_debug)
ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s)\n", technology, loc, sc->state, devstate2str(sc->state));
AST_LIST_LOCK(&queues);
AST_LIST_TRAVERSE(&queues, q, list) {
ast_mutex_lock(&q->lock);
cur = q->members;
while(cur) {
if (!strcasecmp(sc->dev, cur->interface)) {
for (cur = q->members; cur; cur = cur->next) {
if (strcasecmp(sc->dev, cur->interface))
continue;
if (cur->status != sc->state) {
cur->status = sc->state;
if (!q->maskmemberstatus) {
if (q->maskmemberstatus)
continue;
manager_event(EVENT_FLAG_AGENT, "QueueMemberStatus",
"Queue: %s\r\n"
"Location: %s\r\n"
@@ -546,17 +553,10 @@ static void *changethread(void *data)
cur->penalty, cur->calls, (int)cur->lastcall, cur->status, cur->paused);
}
}
}
cur = cur->next;
}
ast_mutex_unlock(&q->lock);
}
AST_LIST_UNLOCK(&queues);
} else {
if (option_debug)
ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", technology, loc, sc->state, devstate2str(sc->state));
}
free(sc);
return NULL;
}
@@ -568,7 +568,9 @@ static int statechange_queue(const char *dev, int state, void *ign)
pthread_t t;
pthread_attr_t attr;
if ((sc = ast_calloc(1, sizeof(*sc) + strlen(dev) + 1))) {
if (!(sc = ast_calloc(1, sizeof(*sc) + strlen(dev) + 1)))
return 0;
sc->state = state;
strcpy(sc->dev, dev);
pthread_attr_init(&attr);
@@ -577,7 +579,7 @@ static int statechange_queue(const char *dev, int state, void *ign)
ast_log(LOG_WARNING, "Failed to create update thread!\n");
free(sc);
}
}
return 0;
}
@@ -656,7 +658,7 @@ static void clear_queue(struct ast_call_queue *q)
static int add_to_interfaces(char *interface)
{
struct ast_member_interfaces *curint, *newint;
struct ast_member_interfaces *curint;
AST_LIST_LOCK(&interfaces);
AST_LIST_TRAVERSE(&interfaces, curint, list) {
@@ -664,14 +666,17 @@ static int add_to_interfaces(char *interface)
break;
}
if (!curint) {
if (curint) {
AST_LIST_UNLOCK(&interfaces);
return 0;
}
if (option_debug)
ast_log(LOG_DEBUG, "Adding %s to the list of interfaces that make up all of our queue members.\n", interface);
if ((newint = ast_calloc(1, sizeof(*newint)))) {
ast_copy_string(newint->interface, interface, sizeof(newint->interface));
AST_LIST_INSERT_HEAD(&interfaces, newint, list);
}
if ((curint = ast_calloc(1, sizeof(*curint)))) {
ast_copy_string(curint->interface, interface, sizeof(curint->interface));
AST_LIST_INSERT_HEAD(&interfaces, curint, list);
}
AST_LIST_UNLOCK(&interfaces);
@@ -687,32 +692,34 @@ static int interface_exists_global(char *interface)
AST_LIST_LOCK(&queues);
AST_LIST_TRAVERSE(&queues, q, list) {
ast_mutex_lock(&q->lock);
for (mem = q->members; mem; mem = mem->next)
if (!strcasecmp(interface, mem->interface)) {
ast_mutex_unlock(&q->lock);
for (mem = q->members; mem && !ret; mem = mem->next) {
if (!strcasecmp(interface, mem->interface))
ret = 1;
break;
}
ast_mutex_unlock(&q->lock);
if (ret)
break;
}
AST_LIST_UNLOCK(&queues);
return ret;
}
static int remove_from_interfaces(char *interface)
{
struct ast_member_interfaces *curint;
AST_LIST_LOCK(&interfaces);
AST_LIST_TRAVERSE_SAFE_BEGIN(&interfaces, curint, list) {
if (!strcasecmp(curint->interface, interface) && !interface_exists_global(interface)) {
if (!strcasecmp(curint->interface, interface)) {
if (!interface_exists_global(interface)) {
if (option_debug)
ast_log(LOG_DEBUG, "Removing %s from the list of interfaces that make up all of our queue members.\n", interface);
AST_LIST_REMOVE_CURRENT(&interfaces, list);
free(curint);
}
break;
}
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&interfaces);
@@ -725,14 +732,9 @@ static void clear_and_free_interfaces(void)
struct ast_member_interfaces *curint;
AST_LIST_LOCK(&interfaces);
AST_LIST_TRAVERSE_SAFE_BEGIN(&interfaces, curint, list) {
AST_LIST_REMOVE_CURRENT(&interfaces, list);
while ((curint = AST_LIST_REMOVE_HEAD(&interfaces, list)))
free(curint);
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&interfaces);
return;
}
/*! \brief Configure a queue parameter.

View File

@@ -9509,35 +9509,26 @@ struct ast_custom_function iaxpeer_function = {
/*! \brief Part of the device state notification system ---*/
static int iax2_devicestate(void *data)
{
char *dest = (char *) data;
struct parsed_dial_string pds;
char *tmp = ast_strdupa(data);
struct iax2_peer *p;
int found = 0;
char *ext, *host;
char tmp[256];
int res = AST_DEVICE_INVALID;
ast_copy_string(tmp, dest, sizeof(tmp));
host = strchr(tmp, '@');
if (host) {
*host = '\0';
host++;
ext = tmp;
} else {
host = tmp;
ext = NULL;
}
parse_dial_string(tmp, &pds);
if (ast_strlen_zero(pds.peer))
return res;
if (option_debug > 2)
ast_log(LOG_DEBUG, "Checking device state for device %s\n", dest);
ast_log(LOG_DEBUG, "Checking device state for device %s\n", pds.peer);
/* SLD: FIXME: second call to find_peer during registration */
p = find_peer(host, 1);
if (p) {
found++;
if (!(p = find_peer(pds.peer, 1)))
return res;
res = AST_DEVICE_UNAVAILABLE;
if (option_debug > 2)
ast_log(LOG_DEBUG, "iax2_devicestate(%s): Found peer. What's device state of %s? addr=%d, defaddr=%d maxms=%d, lastms=%d\n",
host, dest, p->addr.sin_addr.s_addr, p->defaddr.sin_addr.s_addr, p->maxms, p->lastms);
ast_log(LOG_DEBUG, "iax2_devicestate: Found peer. What's device state of %s? addr=%d, defaddr=%d maxms=%d, lastms=%d\n",
pds.peer, p->addr.sin_addr.s_addr, p->defaddr.sin_addr.s_addr, p->maxms, p->lastms);
if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) &&
(!p->maxms || ((p->lastms > -1) && (p->historicms <= p->maxms)))) {
@@ -9547,13 +9538,10 @@ static int iax2_devicestate(void *data)
/* let the core figure out whether it is in use or not */
res = AST_DEVICE_UNKNOWN;
}
} else {
if (option_debug > 2)
ast_log(LOG_DEBUG, "Devicestate: Can't find peer %s.\n", host);
}
if (p && ast_test_flag(p, IAX_TEMPONLY))
if (ast_test_flag(p, IAX_TEMPONLY))
destroy_peer(p);
return res;
}