Asterisk - The Open Source Telephony Project  18.5.0
dnsmgr.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Kevin P. Fleming <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief Background DNS update manager
21  */
22 
23 #ifndef _ASTERISK_DNSMGR_H
24 #define _ASTERISK_DNSMGR_H
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 #include "asterisk/netsock2.h"
31 #include "asterisk/srv.h"
32 
33 /*!
34  * \brief A DNS manager entry
35  *
36  * This is an opaque type.
37  */
38 struct ast_dnsmgr_entry;
39 
40 typedef void (*dns_update_func)(struct ast_sockaddr *old_addr, struct ast_sockaddr *new_addr, void *data);
41 
42 /*!
43  * \brief Allocate a new DNS manager entry
44  *
45  * \param name the hostname
46  * \param result where the DNS manager should store the IP address as it refreshes it.
47  * \param service
48  *
49  * \details
50  * This function allocates a new DNS manager entry object, and fills it with the
51  * provided hostname and IP address. This function does not force an initial lookup
52  * of the IP address. So, generally, this should be used when the initial address
53  * is already known.
54  *
55  * \return a DNS manager entry
56  * \version 1.6.1 result changed from struct in_addr to struct sockaddr_in to store port number
57  * \version 1.8.0 result changed from struct ast_sockaddr_in to ast_sockaddr for IPv6 support
58  */
59 struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct ast_sockaddr *result, const char *service);
60 
61 /*!
62  * \brief Allocate a new DNS manager entry
63  *
64  * \param name the hostname
65  * \param result where the DNS manager should store the IP address as it refreshes it.
66  * \param service
67  * \param family Address family to filter DNS addresses.
68  *
69  * \details
70  * This function allocates a new DNS manager entry object, and fills it with the
71  * provided hostname and IP address. This function does not force an initial lookup
72  * of the IP address. So, generally, this should be used when the initial address
73  * is already known.
74  *
75  * \return a DNS manager entry
76  */
77 struct ast_dnsmgr_entry *ast_dnsmgr_get_family(const char *name, struct ast_sockaddr *result, const char *service, unsigned int family);
78 
79 /*!
80  * \brief Free a DNS manager entry
81  *
82  * \param entry the DNS manager entry to free
83  *
84  * \return nothing
85  */
87 
88 /*!
89  * \brief Allocate and initialize a DNS manager entry
90  *
91  * \param name the hostname
92  * \param result where to store the IP address as the DNS manager refreshes it.
93  * The address family is used as an input parameter to filter the returned addresses.
94  * If it is 0, both IPv4 and IPv6 addresses can be returned.
95  * \param dnsmgr Where to store the allocate DNS manager entry
96  * \param service
97  *
98  * \note
99  * This function allocates a new DNS manager entry object, and fills it with
100  * the provided hostname and IP address. This function _does_ force an initial
101  * lookup, so it may block for some period of time.
102  *
103  * \retval 0 success
104  * \retval non-zero failure
105  * \version 1.6.1 result changed from struct in_addr to struct aockaddr_in to store port number
106  */
107 int ast_dnsmgr_lookup(const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service);
108 
109 /*!
110  * \brief Allocate and initialize a DNS manager entry, with update callback
111  *
112  * \param name the hostname
113  * \param result The addr which is intended to be updated in the update callback when DNS manager calls it on refresh.
114  * The address family is used as an input parameter to filter the returned addresses.
115  * If it is 0, both IPv4 and IPv6 addresses can be returned.
116  * \param dnsmgr Where to store the allocate DNS manager entry
117  * \param service
118  * \param func The update callback function
119  * The update callback will be called when DNS manager detects that an IP address has been changed.
120  * Instead of updating the addr itself, DNS manager will call this callback function with the old
121  * and new addresses. It is the responsibility of the callback to perform any updates
122  * \param data A pointer to data that will be passed through to the callback function
123  *
124  * \note
125  * This function allocates a new DNS manager entry object, and fills it with
126  * the provided hostname and IP address. This function _does_ force an initial
127  * lookup, so it may block for some period of time.
128  *
129  * \retval 0 success
130  * \retval non-zero failure
131  */
132 int ast_dnsmgr_lookup_cb(const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service, dns_update_func func, void *data);
133 
134 /*!
135  * \brief Force a refresh of a dnsmgr entry
136  *
137  * \retval non-zero if the result is different than the previous result
138  * \retval zero if the result is the same as the previous result
139  */
141 
142 /*!
143  * \brief Check is see if a dnsmgr entry has changed
144  *
145  * \retval non-zero if the dnsmgr entry has changed since the last call to
146  * this function
147  * \retval zero if the dnsmgr entry has not changed since the last call to
148  * this function
149  */
151 
152 #if defined(__cplusplus) || defined(c_plusplus)
153 }
154 #endif /* c_plusplus */
155 
156 #endif /* ASTERISK_DNSMGR_H */
Support for DNS SRV records, used in to locate SIP services.
void(* dns_update_func)(struct ast_sockaddr *old_addr, struct ast_sockaddr *new_addr, void *data)
Definition: dnsmgr.h:40
enum ast_cc_service_type service
Definition: chan_sip.c:949
struct ast_dnsmgr_entry * ast_dnsmgr_get(const char *name, struct ast_sockaddr *result, const char *service)
Allocate a new DNS manager entry.
Definition: dnsmgr.c:131
Definition: dnsmgr.c:66
unsigned int family
Definition: dnsmgr.c:72
int ast_dnsmgr_refresh(struct ast_dnsmgr_entry *entry)
Force a refresh of a dnsmgr entry.
Definition: dnsmgr.c:239
Socket address structure.
Definition: netsock2.h:97
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
Free a DNS manager entry.
Definition: dnsmgr.c:136
Network socket handling.
void * data
Definition: dnsmgr.c:76
static const char name[]
Definition: cdr_mysql.c:74
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.
Definition: dnsmgr.c:191
static PGresult * result
Definition: cel_pgsql.c:88
int ast_dnsmgr_changed(struct ast_dnsmgr_entry *entry)
Check is see if a dnsmgr entry has changed.
Definition: dnsmgr.c:247
Definition: search.h:40
int ast_dnsmgr_lookup_cb(const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service, dns_update_func func, void *data)
Allocate and initialize a DNS manager entry, with update callback.
Definition: dnsmgr.c:196
struct ast_dnsmgr_entry * ast_dnsmgr_get_family(const char *name, struct ast_sockaddr *result, const char *service, unsigned int family)
Allocate a new DNS manager entry.
Definition: dnsmgr.c:106