#include "asterisk/network.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 191 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().
00192 { 00193 int changed; 00194 00195 ast_mutex_lock(&entry->lock); 00196 00197 changed = entry->changed; 00198 entry->changed = 0; 00199 00200 ast_mutex_unlock(&entry->lock); 00201 00202 return changed; 00203 }
struct ast_dnsmgr_entry* ast_dnsmgr_get | ( | const char * | name, | |
struct in_addr * | result | |||
) |
Definition at line 85 of file dnsmgr.c.
References ast_calloc, ast_mutex_init(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), ast_dnsmgr_entry::list, and ast_dnsmgr_entry::result.
Referenced by ast_dnsmgr_lookup().
00086 { 00087 struct ast_dnsmgr_entry *entry; 00088 00089 if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, sizeof(*entry) + strlen(name)))) 00090 return NULL; 00091 00092 entry->result = result; 00093 ast_mutex_init(&entry->lock); 00094 strcpy(entry->name, name); 00095 memcpy(&entry->last, result, sizeof(entry->last)); 00096 00097 AST_RWLIST_WRLOCK(&entry_list); 00098 AST_RWLIST_INSERT_HEAD(&entry_list, entry, list); 00099 AST_RWLIST_UNLOCK(&entry_list); 00100 00101 return entry; 00102 }
int ast_dnsmgr_lookup | ( | const char * | name, | |
struct in_addr * | result, | |||
struct ast_dnsmgr_entry ** | dnsmgr | |||
) |
Definition at line 118 of file dnsmgr.c.
References ahp, ast_dnsmgr_get(), ast_gethostbyname(), ast_strlen_zero(), ast_verb, enabled, hp, and inet_aton().
Referenced by build_peer(), and iax2_append_register().
00119 { 00120 struct ast_hostent ahp; 00121 struct hostent *hp; 00122 00123 if (ast_strlen_zero(name) || !result || !dnsmgr) 00124 return -1; 00125 00126 if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name)) 00127 return 0; 00128 00129 ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name); 00130 00131 /* if it's actually an IP address and not a name, 00132 there's no need for a managed lookup */ 00133 if (inet_aton(name, result)) 00134 return 0; 00135 00136 /* do a lookup now but add a manager so it will automagically get updated in the background */ 00137 if ((hp = ast_gethostbyname(name, &ahp))) 00138 memcpy(result, hp->h_addr, sizeof(result)); 00139 00140 /* if dnsmgr is not enable don't bother adding an entry */ 00141 if (!enabled) 00142 return 0; 00143 00144 ast_verb(3, "adding dns manager for '%s'\n", name); 00145 *dnsmgr = ast_dnsmgr_get(name, result); 00146 return !*dnsmgr; 00147 }
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 183 of file dnsmgr.c.
References dnsmgr_refresh().
Referenced by iax2_do_register().
00184 { 00185 return dnsmgr_refresh(entry, 0); 00186 }
void ast_dnsmgr_release | ( | struct ast_dnsmgr_entry * | entry | ) |
Definition at line 104 of file dnsmgr.c.
References ast_free, ast_mutex_destroy(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_dnsmgr_entry::list, ast_dnsmgr_entry::lock, and ast_dnsmgr_entry::name.
Referenced by delete_users(), peer_destructor(), and sip_destroy_peer().
00105 { 00106 if (!entry) 00107 return; 00108 00109 AST_RWLIST_WRLOCK(&entry_list); 00110 AST_RWLIST_REMOVE(&entry_list, entry, list); 00111 AST_RWLIST_UNLOCK(&entry_list); 00112 ast_verb(4, "removing dns manager for '%s'\n", entry->name); 00113 00114 ast_mutex_destroy(&entry->lock); 00115 ast_free(entry); 00116 }