Thu Apr 28 2011 16:57:09

Asterisk developer's documentation


dnsmgr.h File Reference

Background DNS update manager. More...

#include "asterisk/network.h"
#include "asterisk/srv.h"
#include "asterisk/srv.h"
Include dependency graph for dnsmgr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int ast_dnsmgr_changed (struct ast_dnsmgr_entry *entry)
 Check is see if a dnsmgr entry has changed.
struct ast_dnsmgr_entryast_dnsmgr_get (const char *name, struct sockaddr_in *result, const char *service)
 Allocate a new DNS manager entry.
int ast_dnsmgr_lookup (const char *name, struct sockaddr_in *result, struct ast_dnsmgr_entry **dnsmgr, const char *service)
 Allocate and initialize a DNS manager entry.
int ast_dnsmgr_refresh (struct ast_dnsmgr_entry *entry)
 Force a refresh of a dnsmgr entry.
void ast_dnsmgr_release (struct ast_dnsmgr_entry *entry)
 Free a DNS manager entry.

Detailed Description

Background DNS update manager.

Definition in file dnsmgr.h.


Function Documentation

int ast_dnsmgr_changed ( struct ast_dnsmgr_entry entry)

Check is see if a dnsmgr entry has changed.

Return values:
non-zeroif the dnsmgr entry has changed since the last call to this function
zeroif the dnsmgr entry has not changed since the last call to this function

Definition at line 193 of file dnsmgr.c.

References ast_mutex_lock(), ast_mutex_unlock(), ast_dnsmgr_entry::changed, and ast_dnsmgr_entry::lock.

Referenced by iax2_do_register().

{
   int changed;

   ast_mutex_lock(&entry->lock);

   changed = entry->changed;
   entry->changed = 0;

   ast_mutex_unlock(&entry->lock);
   
   return changed;
}
struct ast_dnsmgr_entry* ast_dnsmgr_get ( const char *  name,
struct sockaddr_in *  result,
const char *  service 
) [read]

Allocate a new DNS manager entry.

Parameters:
namethe hostname
resultwhere the DNS manager should store the IP address as it refreshes it. it.

This function allocates a new DNS manager entry object, and fills it with the provided hostname and IP address. This function does not force an initial lookup of the IP address. So, generally, this should be used when the initial address is already known.

Returns:
a DNS manager entry
Version:
1.6.1 result changed from struct in_addr to struct sockaddr_in to store port number

Definition at line 86 of file dnsmgr.c.

References ast_calloc, ast_mutex_init(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), ast_dnsmgr_entry::lock, ast_dnsmgr_entry::result, and ast_dnsmgr_entry::service.

Referenced by ast_dnsmgr_lookup().

{
   struct ast_dnsmgr_entry *entry;
   int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0);

   if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, total_size)))
      return NULL;

   entry->result = result;
   ast_mutex_init(&entry->lock);
   strcpy(entry->name, name);
   if (service) {
      entry->service = ((char *) entry) + sizeof(*entry) + strlen(name);
      strcpy(entry->service, service);
   }

   AST_RWLIST_WRLOCK(&entry_list);
   AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
   AST_RWLIST_UNLOCK(&entry_list);

   return entry;
}
int ast_dnsmgr_lookup ( const char *  name,
struct sockaddr_in *  result,
struct ast_dnsmgr_entry **  dnsmgr,
const char *  service 
)

Allocate and initialize a DNS manager entry.

Parameters:
namethe hostname
resultwhere to store the IP address as the DNS manager refreshes it
dnsmgrWhere to store the allocate DNS manager entry

This function allocates a new DNS manager entry object, and fills it with the provided hostname and IP address. This function _does_ force an initial lookup, so it may block for some period of time.

Return values:
0success
non-zerofailure
Version:
1.6.1 result changed from struct in_addr to struct aockaddr_in to store port number

Definition at line 126 of file dnsmgr.c.

References ast_dnsmgr_get(), ast_get_ip_or_srv(), ast_strlen_zero(), ast_verb, enabled, and inet_aton().

Referenced by __sip_subscribe_mwi_do(), build_peer(), iax2_append_register(), and transmit_register().

{
   if (ast_strlen_zero(name) || !result || !dnsmgr)
      return -1;

   if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name))
      return 0;

   /* if it's actually an IP address and not a name,
      there's no need for a managed lookup */
   if (inet_aton(name, &result->sin_addr)) {
      result->sin_family = AF_INET;
      return 0;
      }

   ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);

   /* do a lookup now but add a manager so it will automagically get updated in the background */
   ast_get_ip_or_srv(result, name, service);
   
   /* if dnsmgr is not enable don't bother adding an entry */
   if (!enabled)
      return 0;
   
   ast_verb(3, "adding dns manager for '%s'\n", name);
   *dnsmgr = ast_dnsmgr_get(name, result, service);
   return !*dnsmgr;
}
int ast_dnsmgr_refresh ( struct ast_dnsmgr_entry entry)

Force a refresh of a dnsmgr entry.

Return values:
non-zeroif the result is different than the previous result
zeroif the result is the same as the previous result

Definition at line 185 of file dnsmgr.c.

References dnsmgr_refresh().

Referenced by iax2_do_register(), and sip_reg_timeout().

{
   return dnsmgr_refresh(entry, 0);
}
void ast_dnsmgr_release ( struct ast_dnsmgr_entry entry)

Free a DNS manager entry.

Parameters:
entrythe DNS manager entry to free
Returns:
nothing

Definition at line 109 of file dnsmgr.c.

References ast_free, ast_mutex_destroy(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, and ast_dnsmgr_entry::lock.

Referenced by delete_users(), peer_destructor(), sip_destroy_peer(), sip_registry_destroy(), and sip_subscribe_mwi_destroy().

{
   if (!entry)
      return;

   AST_RWLIST_WRLOCK(&entry_list);
   AST_RWLIST_REMOVE(&entry_list, entry, list);
   AST_RWLIST_UNLOCK(&entry_list);
   ast_verb(4, "removing dns manager for '%s'\n", entry->name);

   ast_mutex_destroy(&entry->lock);
   ast_free(entry);
}