Wed Oct 28 11:52:19 2009

Asterisk developer's documentation


dnsmgr.h File Reference

Background DNS update manager. More...

#include "asterisk/network.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-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 191 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().

00192 {
00193    int changed;
00194 
00195    ast_mutex_lock(&entry->lock);
00196 
00197    changed = entry->changed;
00198    entry->changed = 0;
00199 
00200    ast_mutex_unlock(&entry->lock);
00201    
00202    return changed;
00203 }

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:
name the hostname
result where 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 88 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::last, ast_dnsmgr_entry::lock, ast_dnsmgr_entry::name, ast_dnsmgr_entry::result, and ast_dnsmgr_entry::service.

Referenced by ast_dnsmgr_lookup().

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

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:
name the hostname
result where to store the IP address as the DNS manager refreshes it
dnsmgr Where 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:
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 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 build_peer(), iax2_append_register(), and transmit_register().

00127 {
00128    if (ast_strlen_zero(name) || !result || !dnsmgr)
00129       return -1;
00130 
00131    if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name))
00132       return 0;
00133 
00134    /* if it's actually an IP address and not a name,
00135       there's no need for a managed lookup */
00136    if (inet_aton(name, &result->sin_addr))
00137       return 0;
00138 
00139    ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name);
00140 
00141    /* do a lookup now but add a manager so it will automagically get updated in the background */
00142    ast_get_ip_or_srv(result, name, service);
00143    
00144    /* if dnsmgr is not enable don't bother adding an entry */
00145    if (!enabled)
00146       return 0;
00147    
00148    ast_verb(3, "adding dns manager for '%s'\n", name);
00149    *dnsmgr = ast_dnsmgr_get(name, result, service);
00150    return !*dnsmgr;
00151 }

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

References dnsmgr_refresh().

Referenced by iax2_do_register(), and sip_reg_timeout().

00184 {
00185    return dnsmgr_refresh(entry, 0);
00186 }

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 112 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 delete_users(), peer_destructor(), sip_destroy_peer(), and sip_registry_destroy().

00113 {
00114    if (!entry)
00115       return;
00116 
00117    AST_RWLIST_WRLOCK(&entry_list);
00118    AST_RWLIST_REMOVE(&entry_list, entry, list);
00119    AST_RWLIST_UNLOCK(&entry_list);
00120    ast_verb(4, "removing dns manager for '%s'\n", entry->name);
00121 
00122    ast_mutex_destroy(&entry->lock);
00123    ast_free(entry);
00124 }


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