Fri Feb 10 06:35:58 2012

Asterisk developer's documentation


dnsmgr.h File Reference

Background DNS update manager. More...

#include "asterisk/netsock2.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.

Typedefs

typedef void(* dns_update_func )(struct ast_sockaddr *old_addr, struct ast_sockaddr *new_addr, void *data)

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 ast_sockaddr *result, const char *service)
 Allocate a new DNS manager entry.
struct ast_dnsmgr_entryast_dnsmgr_get_family (const char *name, struct ast_sockaddr *result, const char *service, unsigned int family)
 Allocate a new DNS manager entry.
int ast_dnsmgr_lookup (const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service)
 Allocate and initialize a DNS manager entry.
int ast_dnsmgr_lookup_cb (const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service, dns_update_func func, void *data)
 Allocate and initialize a DNS manager entry, with update callback.
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.


Typedef Documentation

typedef void(* dns_update_func)(struct ast_sockaddr *old_addr, struct ast_sockaddr *new_addr, void *data)

Definition at line 40 of 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-zero if the dnsmgr entry has changed since the last call to this function
zero if the dnsmgr entry has not changed since the last call to this function

Definition at line 235 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().

00236 {
00237    int changed;
00238 
00239    ast_mutex_lock(&entry->lock);
00240 
00241    changed = entry->changed;
00242    entry->changed = 0;
00243 
00244    ast_mutex_unlock(&entry->lock);
00245 
00246    return changed;
00247 }

struct ast_dnsmgr_entry* ast_dnsmgr_get ( const char *  name,
struct ast_sockaddr result,
const char *  service 
) [read]

Allocate a new DNS manager entry.

Parameters:
name the hostname
result where the DNS manager should store the IP address as it refreshes it.
service 
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

1.8.0 result changed from struct ast_sockaddr_in to ast_sockaddr for IPv6 support

Definition at line 117 of file dnsmgr.c.

References ast_dnsmgr_get_family().

00118 {
00119    return ast_dnsmgr_get_family(name, result, service, 0);
00120 }

struct ast_dnsmgr_entry* ast_dnsmgr_get_family ( const char *  name,
struct ast_sockaddr result,
const char *  service,
unsigned int  family 
) [read]

Allocate a new DNS manager entry.

Parameters:
name the hostname
result where the DNS manager should store the IP address as it refreshes it.
service 
family Address family to filter DNS addresses.
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

Definition at line 92 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::family, ast_dnsmgr_entry::lock, ast_dnsmgr_entry::name, ast_dnsmgr_entry::result, and ast_dnsmgr_entry::service.

Referenced by ast_dnsmgr_get(), and internal_dnsmgr_lookup().

00093 {
00094    struct ast_dnsmgr_entry *entry;
00095    int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0);
00096 
00097    if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, total_size))) {
00098       return NULL;
00099    }
00100 
00101    entry->result = result;
00102    ast_mutex_init(&entry->lock);
00103    strcpy(entry->name, name);
00104    if (service) {
00105       entry->service = ((char *) entry) + sizeof(*entry) + strlen(name);
00106       strcpy(entry->service, service);
00107    }
00108    entry->family = family;
00109 
00110    AST_RWLIST_WRLOCK(&entry_list);
00111    AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
00112    AST_RWLIST_UNLOCK(&entry_list);
00113 
00114    return entry;
00115 }

int ast_dnsmgr_lookup ( const char *  name,
struct ast_sockaddr result,
struct ast_dnsmgr_entry **  dnsmgr,
const char *  service 
)

Allocate and initialize a DNS manager entry.

Parameters:
name the hostname
result where to store the IP address as the DNS manager refreshes it. The address family is used as an input parameter to filter the returned addresses. If it is 0, both IPv4 and IPv6 addresses can be returned.
dnsmgr Where to store the allocate DNS manager entry
service 
Note:
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:
0 success
non-zero failure
Version:
1.6.1 result changed from struct in_addr to struct aockaddr_in to store port number

Definition at line 177 of file dnsmgr.c.

References internal_dnsmgr_lookup().

Referenced by build_peer(), and iax2_append_register().

00178 {
00179    return internal_dnsmgr_lookup(name, result, dnsmgr, service, NULL, NULL);
00180 }

int ast_dnsmgr_lookup_cb ( const char *  name,
struct ast_sockaddr result,
struct ast_dnsmgr_entry **  dnsmgr,
const char *  service,
dns_update_func  func,
void *  data 
)

Allocate and initialize a DNS manager entry, with update callback.

Parameters:
name the hostname
result The addr which is intended to be updated in the update callback when DNS manager calls it on refresh. The address family is used as an input parameter to filter the returned addresses. If it is 0, both IPv4 and IPv6 addresses can be returned.
dnsmgr Where to store the allocate DNS manager entry
service 
func The update callback function The update callback will be called when DNS manager detects that an IP address has been changed. Instead of updating the addr itself, DNS manager will call this callback function with the old and new addresses. It is the responsibility of the callback to perform any updates
data A pointer to data that will be passed through to the callback function
Note:
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:
0 success
non-zero failure

Definition at line 182 of file dnsmgr.c.

References internal_dnsmgr_lookup().

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

00183 {
00184    return internal_dnsmgr_lookup(name, result, dnsmgr, service, func, data);
00185 }

int ast_dnsmgr_refresh ( struct ast_dnsmgr_entry entry  ) 

Force a refresh of a dnsmgr entry.

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

Definition at line 227 of file dnsmgr.c.

References dnsmgr_refresh().

Referenced by build_peer(), iax2_do_register(), and sip_reg_timeout().

00228 {
00229    return dnsmgr_refresh(entry, 0);
00230 }

void ast_dnsmgr_release ( struct ast_dnsmgr_entry entry  ) 

Free a DNS manager entry.

Parameters:
entry the DNS manager entry to free
Returns:
nothing

Definition at line 122 of file dnsmgr.c.

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

Referenced by cleanup_all_regs(), delete_users(), match_and_cleanup_peer_sched(), peer_destructor(), and unload_module().

00123 {
00124    if (!entry) {
00125       return;
00126    }
00127 
00128    AST_RWLIST_WRLOCK(&entry_list);
00129    AST_RWLIST_REMOVE(&entry_list, entry, list);
00130    AST_RWLIST_UNLOCK(&entry_list);
00131    ast_verb(4, "removing dns manager for '%s'\n", entry->name);
00132 
00133    ast_mutex_destroy(&entry->lock);
00134    ast_free(entry);
00135 }


Generated on Fri Feb 10 06:35:58 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6