#include <netinet/in.h>
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_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) |
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) |
Definition in file dnsmgr.h.
int ast_dnsmgr_changed | ( | struct ast_dnsmgr_entry * | entry | ) |
Check is see if a dnsmgr entry has changed.
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 194 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().
00195 { 00196 int changed; 00197 00198 ast_mutex_lock(&entry->lock); 00199 00200 changed = entry->changed; 00201 entry->changed = 0; 00202 00203 ast_mutex_unlock(&entry->lock); 00204 00205 return changed; 00206 }
struct ast_dnsmgr_entry* ast_dnsmgr_get | ( | const char * | name, | |
struct in_addr * | result | |||
) |
Definition at line 87 of file dnsmgr.c.
References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_mutex_init(), ast_strlen_zero(), ast_dnsmgr_entry::list, and ast_dnsmgr_entry::result.
Referenced by ast_dnsmgr_lookup().
00088 { 00089 struct ast_dnsmgr_entry *entry; 00090 00091 if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name)))) 00092 return NULL; 00093 00094 entry->result = result; 00095 ast_mutex_init(&entry->lock); 00096 strcpy(entry->name, name); 00097 00098 AST_LIST_LOCK(&entry_list); 00099 AST_LIST_INSERT_HEAD(&entry_list, entry, list); 00100 AST_LIST_UNLOCK(&entry_list); 00101 00102 return entry; 00103 }
int ast_dnsmgr_lookup | ( | const char * | name, | |
struct in_addr * | result, | |||
struct ast_dnsmgr_entry ** | dnsmgr | |||
) |
Definition at line 120 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().
00121 { 00122 struct ast_hostent ahp; 00123 struct hostent *hp; 00124 00125 if (ast_strlen_zero(name) || !result || !dnsmgr) 00126 return -1; 00127 00128 if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name)) 00129 return 0; 00130 00131 if (option_verbose > 3) 00132 ast_verbose(VERBOSE_PREFIX_4 "doing dnsmgr_lookup for '%s'\n", name); 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)) 00137 return 0; 00138 00139 /* do a lookup now but add a manager so it will automagically get updated in the background */ 00140 if ((hp = ast_gethostbyname(name, &ahp))) 00141 memcpy(result, hp->h_addr, sizeof(result)); 00142 00143 /* if dnsmgr is not enable don't bother adding an entry */ 00144 if (!enabled) 00145 return 0; 00146 00147 if (option_verbose > 2) 00148 ast_verbose(VERBOSE_PREFIX_2 "adding dns manager for '%s'\n", name); 00149 *dnsmgr = ast_dnsmgr_get(name, result); 00150 return !*dnsmgr; 00151 }
int ast_dnsmgr_refresh | ( | struct ast_dnsmgr_entry * | entry | ) |
Force a refresh of a dnsmgr entry.
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 186 of file dnsmgr.c.
References dnsmgr_refresh().
Referenced by iax2_do_register().
00187 { 00188 return dnsmgr_refresh(entry, 0); 00189 }
void ast_dnsmgr_release | ( | struct ast_dnsmgr_entry * | entry | ) |
Definition at line 105 of file dnsmgr.c.
References AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_mutex_destroy(), ast_verbose(), free, ast_dnsmgr_entry::list, ast_dnsmgr_entry::lock, ast_dnsmgr_entry::name, option_verbose, and VERBOSE_PREFIX_4.
Referenced by delete_users(), and peer_destructor().
00106 { 00107 if (!entry) 00108 return; 00109 00110 AST_LIST_LOCK(&entry_list); 00111 AST_LIST_REMOVE(&entry_list, entry, list); 00112 AST_LIST_UNLOCK(&entry_list); 00113 if (option_verbose > 3) 00114 ast_verbose(VERBOSE_PREFIX_4 "removing dns manager for '%s'\n", entry->name); 00115 00116 ast_mutex_destroy(&entry->lock); 00117 free(entry); 00118 }