#include "asterisk/netsock2.h"
#include "asterisk/srv.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 ast_sockaddr *result, const char *service) |
Allocate a new DNS manager entry. | |
int | ast_dnsmgr_lookup (const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service) |
Allocate and initialize a DNS manager entry. | |
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) |
Free a DNS manager 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 193 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().
00194 { 00195 int changed; 00196 00197 ast_mutex_lock(&entry->lock); 00198 00199 changed = entry->changed; 00200 entry->changed = 0; 00201 00202 ast_mutex_unlock(&entry->lock); 00203 00204 return changed; 00205 }
struct ast_dnsmgr_entry* ast_dnsmgr_get | ( | const char * | name, | |
struct ast_sockaddr * | result, | |||
const char * | service | |||
) |
Allocate a new DNS manager entry.
name | the hostname | |
result | where the DNS manager should store the IP address as it refreshes it. | |
service | This function allocates a new DNS manager entry object, and fills it with the provided hostname and IP address. This function does not force an initial lookup of the IP address. So, generally, this should be used when the initial address is already known. |
1.8.0 result changed from struct ast_sockaddr_in to ast_sockaddr for IPv6 support
Definition at line 86 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, ast_dnsmgr_entry::lock, ast_dnsmgr_entry::name, ast_dnsmgr_entry::result, and ast_dnsmgr_entry::service.
Referenced by ast_dnsmgr_lookup().
00087 { 00088 struct ast_dnsmgr_entry *entry; 00089 int total_size = sizeof(*entry) + strlen(name) + (service ? strlen(service) + 1 : 0); 00090 00091 if (!result || ast_strlen_zero(name) || !(entry = ast_calloc(1, total_size))) { 00092 return NULL; 00093 } 00094 00095 entry->result = result; 00096 ast_mutex_init(&entry->lock); 00097 strcpy(entry->name, name); 00098 if (service) { 00099 entry->service = ((char *) entry) + sizeof(*entry) + strlen(name); 00100 strcpy(entry->service, service); 00101 } 00102 00103 AST_RWLIST_WRLOCK(&entry_list); 00104 AST_RWLIST_INSERT_HEAD(&entry_list, entry, list); 00105 AST_RWLIST_UNLOCK(&entry_list); 00106 00107 return entry; 00108 }
int ast_dnsmgr_lookup | ( | const char * | name, | |
struct ast_sockaddr * | result, | |||
struct ast_dnsmgr_entry ** | dnsmgr, | |||
const char * | service | |||
) |
Allocate and initialize a DNS manager entry.
name | the hostname | |
result | where to store the IP address as the DNS manager refreshes it. The address family is used as an input parameter to filter the returned adresses. if it is 0, both IPv4 * and IPv6 addresses can be returned. | |
dnsmgr | Where to store the allocate DNS manager entry | |
service | This function allocates a new DNS manager entry object, and fills it with the provided hostname and IP address. This function _does_ force an initial lookup, so it may block for some period of time. |
0 | success | |
non-zero | failure |
Definition at line 124 of file dnsmgr.c.
References ast_dnsmgr_get(), ast_get_ip_or_srv(), ast_strlen_zero(), ast_verb, enabled, and ast_dnsmgr_entry::result.
Referenced by __sip_subscribe_mwi_do(), build_peer(), iax2_append_register(), and transmit_register().
00125 { 00126 if (ast_strlen_zero(name) || !result || !dnsmgr) { 00127 return -1; 00128 } 00129 00130 if (*dnsmgr && !strcasecmp((*dnsmgr)->name, name)) { 00131 return 0; 00132 } 00133 00134 ast_verb(4, "doing dnsmgr_lookup for '%s'\n", name); 00135 00136 /* do a lookup now but add a manager so it will automagically get updated in the background */ 00137 ast_get_ip_or_srv(result, name, service); 00138 00139 /* if dnsmgr is not enable don't bother adding an entry */ 00140 if (!enabled) { 00141 return 0; 00142 } 00143 00144 ast_verb(3, "adding dns manager for '%s'\n", name); 00145 *dnsmgr = ast_dnsmgr_get(name, result, service); 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 185 of file dnsmgr.c.
References dnsmgr_refresh().
Referenced by build_peer(), iax2_do_register(), and sip_reg_timeout().
00186 { 00187 return dnsmgr_refresh(entry, 0); 00188 }
void ast_dnsmgr_release | ( | struct ast_dnsmgr_entry * | entry | ) |
Free a DNS manager entry.
entry | the DNS manager entry to free |
Definition at line 110 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(), sip_destroy_peer(), sip_registry_destroy(), and sip_subscribe_mwi_destroy().
00111 { 00112 if (!entry) 00113 return; 00114 00115 AST_RWLIST_WRLOCK(&entry_list); 00116 AST_RWLIST_REMOVE(&entry_list, entry, list); 00117 AST_RWLIST_UNLOCK(&entry_list); 00118 ast_verb(4, "removing dns manager for '%s'\n", entry->name); 00119 00120 ast_mutex_destroy(&entry->lock); 00121 ast_free(entry); 00122 }