#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 198 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().
00199 { 00200 int changed; 00201 00202 ast_mutex_lock(&entry->lock); 00203 00204 changed = entry->changed; 00205 entry->changed = 0; 00206 00207 ast_mutex_unlock(&entry->lock); 00208 00209 return changed; 00210 }
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 memcpy(&entry->last, result, sizeof(entry->last)); 00100 00101 AST_LIST_LOCK(&entry_list); 00102 AST_LIST_INSERT_HEAD(&entry_list, entry, list); 00103 AST_LIST_UNLOCK(&entry_list); 00104 00105 return entry; 00106 }
int ast_dnsmgr_lookup | ( | const char * | name, | |
struct in_addr * | result, | |||
struct ast_dnsmgr_entry ** | dnsmgr | |||
) |
Definition at line 123 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().
00124 { 00125 struct ast_hostent ahp; 00126 struct hostent *hp; 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 (option_verbose > 3) 00135 ast_verbose(VERBOSE_PREFIX_4 "doing dnsmgr_lookup for '%s'\n", name); 00136 00137 /* if it's actually an IP address and not a name, 00138 there's no need for a managed lookup */ 00139 if (inet_aton(name, result)) 00140 return 0; 00141 00142 /* do a lookup now but add a manager so it will automagically get updated in the background */ 00143 if ((hp = ast_gethostbyname(name, &ahp))) 00144 memcpy(result, hp->h_addr, sizeof(result)); 00145 00146 /* if dnsmgr is not enable don't bother adding an entry */ 00147 if (!enabled) 00148 return 0; 00149 00150 if (option_verbose > 2) 00151 ast_verbose(VERBOSE_PREFIX_2 "adding dns manager for '%s'\n", name); 00152 *dnsmgr = ast_dnsmgr_get(name, result); 00153 return !*dnsmgr; 00154 }
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 190 of file dnsmgr.c.
References dnsmgr_refresh().
Referenced by iax2_do_register().
00191 { 00192 return dnsmgr_refresh(entry, 0); 00193 }
void ast_dnsmgr_release | ( | struct ast_dnsmgr_entry * | entry | ) |
Definition at line 108 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 peer_destructor().
00109 { 00110 if (!entry) 00111 return; 00112 00113 AST_LIST_LOCK(&entry_list); 00114 AST_LIST_REMOVE(&entry_list, entry, list); 00115 AST_LIST_UNLOCK(&entry_list); 00116 if (option_verbose > 3) 00117 ast_verbose(VERBOSE_PREFIX_4 "removing dns manager for '%s'\n", entry->name); 00118 00119 ast_mutex_destroy(&entry->lock); 00120 free(entry); 00121 }