Wed Jan 27 20:02:38 2016

Asterisk developer's documentation


dnsmgr.h File Reference

Background DNS update manager. More...

#include "asterisk/netsock2.h"
#include "asterisk/srv.h"

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 238 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().

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

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 121 of file dnsmgr.c.

References ast_dnsmgr_get_family().

00122 {
00123    return ast_dnsmgr_get_family(name, result, service, 0);
00124 }

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 96 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().

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

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 180 of file dnsmgr.c.

References internal_dnsmgr_lookup().

Referenced by build_peer(), and iax2_append_register().

00181 {
00182    return internal_dnsmgr_lookup(name, result, dnsmgr, service, NULL, NULL);
00183 }

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 185 of file dnsmgr.c.

References internal_dnsmgr_lookup().

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

00186 {
00187    return internal_dnsmgr_lookup(name, result, dnsmgr, service, func, data);
00188 }

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 230 of file dnsmgr.c.

References dnsmgr_refresh().

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

00231 {
00232    return dnsmgr_refresh(entry, 0);
00233 }

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 126 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().

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


Generated on 27 Jan 2016 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1