Mon May 14 04:48:24 2007

Asterisk developer's documentation


dnsmgr.h File Reference

Background DNS update manager. More...

#include <netinet/in.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.
ast_dnsmgr_entryast_dnsmgr_get (const char *name, struct in_addr *result)
int ast_dnsmgr_lookup (const char *name, struct in_addr *result, struct ast_dnsmgr_entry **dnsmgr)
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)


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

00198 {
00199    int changed;
00200 
00201    ast_mutex_lock(&entry->lock);
00202 
00203    changed = entry->changed;
00204    entry->changed = 0;
00205 
00206    ast_mutex_unlock(&entry->lock);
00207    
00208    return changed;
00209 }

struct ast_dnsmgr_entry* ast_dnsmgr_get ( const char *  name,
struct in_addr *  result 
)

Definition at line 89 of file dnsmgr.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_mutex_init(), ast_strlen_zero(), and ast_dnsmgr_entry::result.

Referenced by ast_dnsmgr_lookup().

00090 {
00091    struct ast_dnsmgr_entry *entry;
00092 
00093    if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name))))
00094       return NULL;
00095 
00096    entry->result = result;
00097    ast_mutex_init(&entry->lock);
00098    strcpy(entry->name, name);
00099 
00100    AST_LIST_LOCK(&entry_list);
00101    AST_LIST_INSERT_HEAD(&entry_list, entry, list);
00102    AST_LIST_UNLOCK(&entry_list);
00103 
00104    return entry;
00105 }

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

Definition at line 122 of file dnsmgr.c.

References ahp, ast_dnsmgr_get(), ast_gethostbyname(), ast_strlen_zero(), ast_verbose(), enabled, hp, option_verbose, VERBOSE_PREFIX_2, and VERBOSE_PREFIX_4.

Referenced by build_peer(), and iax2_register().

00123 {
00124    if (ast_strlen_zero(name) || !result || !dnsmgr)
00125       return -1;
00126 
00127    if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name))
00128       return 0;
00129 
00130    if (option_verbose > 3)
00131       ast_verbose(VERBOSE_PREFIX_4 "doing dnsmgr_lookup for '%s'\n", name);
00132 
00133    /* if it's actually an IP address and not a name,
00134       there's no need for a managed lookup */
00135    if (inet_aton(name, result))
00136       return 0;
00137 
00138    /* if the manager is disabled, do a direct lookup and return the result,
00139       otherwise register a managed lookup for the name */
00140    if (!enabled) {
00141       struct ast_hostent ahp;
00142       struct hostent *hp;
00143 
00144       if ((hp = ast_gethostbyname(name, &ahp)))
00145          memcpy(result, hp->h_addr, sizeof(result));
00146       return 0;
00147    } else {
00148       if (option_verbose > 2)
00149          ast_verbose(VERBOSE_PREFIX_2 "adding dns manager for '%s'\n", name);
00150       *dnsmgr = ast_dnsmgr_get(name, result);
00151       return !*dnsmgr;
00152    }
00153 }

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

References dnsmgr_refresh().

Referenced by iax2_do_register().

00190 {
00191    return dnsmgr_refresh(entry, 0);
00192 }

void ast_dnsmgr_release ( struct ast_dnsmgr_entry entry  ) 

Definition at line 107 of file dnsmgr.c.

References AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_mutex_destroy(), ast_verbose(), free, ast_dnsmgr_entry::lock, option_verbose, and VERBOSE_PREFIX_4.

Referenced by delete_users(), and destroy_peer().

00108 {
00109    if (!entry)
00110       return;
00111 
00112    AST_LIST_LOCK(&entry_list);
00113    AST_LIST_REMOVE(&entry_list, entry, list);
00114    AST_LIST_UNLOCK(&entry_list);
00115    if (option_verbose > 3)
00116       ast_verbose(VERBOSE_PREFIX_4 "removing dns manager for '%s'\n", entry->name);
00117 
00118    ast_mutex_destroy(&entry->lock);
00119    free(entry);
00120 }


Generated on Mon May 14 04:48:25 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1