[asterisk-commits] kpfleming: branch kpfleming/SRV-priority-handling r87064 - /team/kpfleming/SR...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Oct 25 17:13:48 CDT 2007
Author: kpfleming
Date: Thu Oct 25 17:13:48 2007
New Revision: 87064
URL: http://svn.digium.com/view/asterisk?view=rev&rev=87064
Log:
handle the "." magic value for SRV targets again, and get ready to include weight in sorting calculations
Modified:
team/kpfleming/SRV-priority-handling/main/srv.c
Modified: team/kpfleming/SRV-priority-handling/main/srv.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/SRV-priority-handling/main/srv.c?view=diff&rev=87064&r1=87063&r2=87064
==============================================================================
--- team/kpfleming/SRV-priority-handling/main/srv.c (original)
+++ team/kpfleming/SRV-priority-handling/main/srv.c Thu Oct 25 17:13:48 2007
@@ -61,11 +61,15 @@
unsigned short priority;
unsigned short weight;
unsigned short port;
+ unsigned int weight_sum;
AST_LIST_ENTRY(srv_entry) list;
char host[1];
};
-AST_LIST_HEAD_NOLOCK(srv_entries, srv_entry);
+struct srv_context {
+ unsigned int have_weights:1;
+ AST_LIST_HEAD_NOLOCK(srv_entries, srv_entry) entries;
+};
static int parse_srv(unsigned char *answer, int len, unsigned char *msg, struct srv_entry **result)
{
@@ -90,10 +94,16 @@
return -1;
}
+ /* the magic value "." for the target domain means that this service
+ is *NOT* available at the domain we searched */
+ if (!strcmp(repl, "."))
+ return -1;
+
if (!(entry = ast_calloc(1, sizeof(*entry) + strlen(repl))))
return -1;
entry->priority = ntohs(srv->priority);
+ entry->weight = ntohs(srv->weight);
entry->port = ntohs(srv->port);
strcpy(entry->host, repl);
@@ -104,22 +114,23 @@
static int srv_callback(void *context, unsigned char *answer, int len, unsigned char *fullanswer)
{
- struct srv_entries *c = (struct srv_entries *) context;
+ struct srv_context *c = (struct srv_context *) context;
struct srv_entry *entry = NULL;
struct srv_entry *current;
- if (parse_srv(answer, len, fullanswer, &entry)) {
- ast_log(LOG_WARNING, "Failed to parse srv\n");
+ if (parse_srv(answer, len, fullanswer, &entry))
return -1;
- }
- AST_LIST_TRAVERSE_SAFE_BEGIN(c, current, list) {
+ if (entry->weight)
+ c->have_weights = 1;
+
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&c->entries, current, list) {
/* insert this entry just before the first existing
entry with a higher priority */
if (current->priority <= entry->priority)
continue;
- AST_LIST_INSERT_BEFORE_CURRENT(c, entry, list);
+ AST_LIST_INSERT_BEFORE_CURRENT(&c->entries, entry, list);
entry = NULL;
break;
}
@@ -128,14 +139,14 @@
/* if we didn't find a place to insert the entry before an existing
entry, then just add it to the end */
if (entry)
- AST_LIST_INSERT_TAIL(c, entry, list);
+ AST_LIST_INSERT_TAIL(&c->entries, entry, list);
return 0;
}
int ast_get_srv(struct ast_channel *chan, char *host, int hostlen, int *port, const char *service)
{
- struct srv_entries context = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
+ struct srv_context context = { .entries = AST_LIST_HEAD_NOLOCK_INIT_VALUE };
struct srv_entry *current;
int ret;
@@ -153,7 +164,7 @@
/* the list of entries will be sorted in the proper selection order
already, so we just need the first one (if any) */
- if ((ret > 0) && (current = AST_LIST_REMOVE_HEAD(&context, list))) {
+ if ((ret > 0) && (current = AST_LIST_REMOVE_HEAD(&context.entries, list))) {
ast_copy_string(host, current->host, hostlen);
*port = current->port;
ast_free(current);
@@ -166,7 +177,7 @@
*port = -1;
}
- while ((current = AST_LIST_REMOVE_HEAD(&context, list)))
+ while ((current = AST_LIST_REMOVE_HEAD(&context.entries, list)))
ast_free(current);
return ret;
More information about the asterisk-commits
mailing list