Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:47 2009

## 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

struct ast_dnsmgr_entry * | ast_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 |
| ) |  |  | `[read]`

Definition at line 81 of file dnsmgr.c.

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

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 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    struct ast_hostent ahp;
    00116    struct hostent *hp;
    00117
    00118    if (ast_strlen_zero(name) || !result || !dnsmgr)
    00119       return -1;
    00120
    00121    if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name))
    00122       return 0;
    00123
    00124    if (option_verbose > 3)
    00125       ast_verbose(VERBOSE_PREFIX_3 "doing lookup for '%s'\n", name);
    00126
    00127    /* if it's actually an IP address and not a name,
    00128       there's no need for a managed lookup */
    00129    if (inet_aton(name, result))
    00130       return 0;
    00131
    00132    /* do a lookup now but add a manager so it will automagically get updated in the background */
    00133    if ((hp = ast_gethostbyname(name, &ahp)))
    00134       memcpy(result, hp->h_addr, sizeof(result));
    00135
    00136    /* if dnsmgr is not enable don't bother adding an entry */
    00137    if (!enabled)
    00138       return 0;
    00139
    00140    if (option_verbose > 2)
    00141       ast_verbose(VERBOSE_PREFIX_2 "adding manager for '%s'\n", name);
    00142    *dnsmgr = ast_dnsmgr_get(name, result);
    00143    return !*dnsmgr;
    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, and free.

Referenced by 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 }