Sat Sep 16 07:28:17 2006

Asterisk developer's documentation


dnsmgr.h File Reference

Background DNS update manager. More...

#include <netinet/in.h>

Go to the source code of this file.

Functions

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)
void ast_dnsmgr_release (struct ast_dnsmgr_entry *entry)


Detailed Description

Background DNS update manager.

Definition in file dnsmgr.h.


Function Documentation

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

Definition at line 81 of file dnsmgr.c.

References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_strlen_zero(), calloc, and list.

Referenced by ast_dnsmgr_lookup().

00082 {
00083    struct ast_dnsmgr_entry *entry;
00084 
00085    if (!result || ast_strlen_zero(name))
00086       return NULL;
00087 
00088    entry = calloc(1, sizeof(*entry) + strlen(name));
00089    if (!entry)
00090       return NULL;
00091 
00092    entry->result = result;
00093    strcpy(entry->name, name);
00094 
00095    AST_LIST_LOCK(&entry_list);
00096    AST_LIST_INSERT_HEAD(&entry_list, entry, list);
00097    AST_LIST_UNLOCK(&entry_list);
00098 
00099    return entry;
00100 }

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

Definition at line 113 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_3.

Referenced by build_peer().

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

void ast_dnsmgr_release ( struct ast_dnsmgr_entry entry  ) 

Definition at line 102 of file dnsmgr.c.

References AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, free, and list.

Referenced by destroy_peer(), and sip_destroy_peer().

00103 {
00104    if (!entry)
00105       return;
00106 
00107    AST_LIST_LOCK(&entry_list);
00108    AST_LIST_REMOVE(&entry_list, entry, list);
00109    AST_LIST_UNLOCK(&entry_list);
00110    free(entry);
00111 }


Generated on Sat Sep 16 07:28:17 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.7