Thu Apr 28 2011 17:14:03

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:
chanAst channel
hosthost name (return value)
hostlenLength of string "host"
portPort number (return value)
serviceService 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().

{
   struct srv_context context = { .entries = AST_LIST_HEAD_NOLOCK_INIT_VALUE };
   struct srv_entry *current;
   int ret;

   if (chan && ast_autoservice_start(chan) < 0)
      return -1;

   ret = ast_search_dns(&context, service, C_IN, T_SRV, srv_callback);

   if (context.have_weights)
      process_weights(&context);

   if (chan)
      ret |= ast_autoservice_stop(chan);

   /* TODO: there could be a "." entry in the returned list of
      answers... if so, this requires special handling */

   /* 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.entries, list))) {
      ast_copy_string(host, current->host, hostlen);
      *port = current->port;
      ast_free(current);
      ast_verb(4, "ast_get_srv: SRV lookup for '%s' mapped to host %s, port %d\n",
                service, host, *port);
   } else {
      host[0] = '\0';
      *port = -1;
   }

   while ((current = AST_LIST_REMOVE_HEAD(&context.entries, list)))
      ast_free(current);

   return ret;
}