Wed Oct 28 11:53:17 2009

Asterisk developer's documentation


srv.h File Reference

Support for DNS SRV records, used in to locate SIP services. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int ast_get_srv (struct ast_channel *chan, char *host, int hostlen, int *port, const char *service)


Detailed Description

Support for DNS SRV records, used in to locate SIP services.

Note:
Note: This SRV record support will respect the priority and weight elements of the records that are returned, but there are no provisions for retrying or failover between records.

Definition in file srv.h.


Function Documentation

int ast_get_srv ( struct ast_channel chan,
char *  host,
int  hostlen,
int *  port,
const char *  service 
)

Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup Only do SRV record lookup if you get a domain without a port. If you get a port #, it's a DNS host name.

Parameters:
chan Ast channel
host host name (return value)
hostlen Length of string "host"
port Port number (return value)
service Service tag for SRV lookup (like "_sip._udp" or "_stun._udp"

Definition at line 200 of file srv.c.

References ast_autoservice_start(), ast_autoservice_stop(), ast_copy_string(), ast_free, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_REMOVE_HEAD, ast_search_dns(), ast_verb, srv_context::entries, srv_context::have_weights, srv_entry::host, srv_entry::port, process_weights(), and srv_callback().

Referenced by ast_get_ip_or_srv(), and create_addr().

00201 {
00202    struct srv_context context = { .entries = AST_LIST_HEAD_NOLOCK_INIT_VALUE };
00203    struct srv_entry *current;
00204    int ret;
00205 
00206    if (chan && ast_autoservice_start(chan) < 0)
00207       return -1;
00208 
00209    ret = ast_search_dns(&context, service, C_IN, T_SRV, srv_callback);
00210 
00211    if (context.have_weights)
00212       process_weights(&context);
00213 
00214    if (chan)
00215       ret |= ast_autoservice_stop(chan);
00216 
00217    /* TODO: there could be a "." entry in the returned list of
00218       answers... if so, this requires special handling */
00219 
00220    /* the list of entries will be sorted in the proper selection order
00221       already, so we just need the first one (if any) */
00222 
00223    if ((ret > 0) && (current = AST_LIST_REMOVE_HEAD(&context.entries, list))) {
00224       ast_copy_string(host, current->host, hostlen);
00225       *port = current->port;
00226       ast_free(current);
00227       ast_verb(4, "ast_get_srv: SRV lookup for '%s' mapped to host %s, port %d\n",
00228                 service, host, *port);
00229    } else {
00230       host[0] = '\0';
00231       *port = -1;
00232    }
00233 
00234    while ((current = AST_LIST_REMOVE_HEAD(&context.entries, list)))
00235       ast_free(current);
00236 
00237    return ret;
00238 }


Generated on Wed Oct 28 11:53:17 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6