Asterisk - The Open Source Telephony Project  21.4.1
srv.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2013, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
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 /*
20  * DNS SRV record support
21  */
22 
23 #ifndef _ASTERISK_SRV_H
24 #define _ASTERISK_SRV_H
25 
26 /*!
27  * \file
28  *
29  * \brief Support for DNS SRV records, used in to locate SIP services.
30  *
31  * \note Note: This SRV record support will respect the priority and weight
32  * elements of the records that are returned, but there are no provisions
33  * for retrying or failover between records.
34  */
35 
36 /*! \brief An opaque type, for lookup usage */
37 struct srv_context;
38 
39 /*! \brief Retrieve set of SRV lookups, in order
40  *
41  * \param[in] context A pointer in which to hold the result
42  * \param[in] service The service name to look up
43  * \param[out] host Result host
44  * \param[out] port Associated TCP portnum
45  *
46  * \retval -1 Query failed
47  * \retval 0 Result exists in host and port
48  * \retval 1 No more results
49  */
50 extern int ast_srv_lookup(struct srv_context **context, const char *service, const char **host, unsigned short *port);
51 
52 /*! \brief Cleanup resources associated with ast_srv_lookup
53  *
54  * \param context Pointer passed into ast_srv_lookup
55  */
56 void ast_srv_cleanup(struct srv_context **context);
57 
58 /*! \brief Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup
59  *
60  * Only do SRV record lookup if you get a domain without a port. If you get a port #, it's a DNS host name.
61  *
62  * \param chan Ast channel
63  * \param host host name (return value)
64  * \param hostlen Length of string "host"
65  * \param port Port number (return value)
66  * \param service Service tag for SRV lookup (like "_sip._udp" or "_stun._udp"
67  */
68 extern int ast_get_srv(struct ast_channel *chan, char *host, int hostlen, int *port, const char *service);
69 
70 /*!
71  * \brief Get the number of records for a given SRV context
72  *
73  * \details
74  * This is meant to be used after calling ast_srv_lookup, so that
75  * one may retrieve the number of records returned during a specific
76  * SRV lookup.
77  *
78  * \param context The context returned by ast_srv_lookup
79  *
80  * \return Number of records in context
81  */
82 unsigned int ast_srv_get_record_count(struct srv_context *context);
83 
84 /*!
85  * \brief Retrieve details from a specific SRV record
86  *
87  * \details
88  * After calling ast_srv_lookup, the srv_context will contain
89  * the data from several records. You can retrieve the data
90  * of a specific one by asking for a specific record number. The
91  * records are sorted based on priority and secondarily based on
92  * weight. See RFC 2782 for the exact sorting rules.
93  *
94  * \param context The context returned by ast_srv_lookup
95  * \param record_num The 1-indexed record number to retrieve
96  * \param[out] host The host portion of the record
97  * \param[out] port The port portion of the record
98  * \param[out] priority The priority portion of the record
99  * \param[out] weight The weight portion of the record
100  *
101  * \retval -1 Failed to retrieve information.
102  * Likely due to an out of range record_num
103  * \retval 0 Success
104  */
105 int ast_srv_get_nth_record(struct srv_context *context, int record_num, const char **host,
106  unsigned short *port, unsigned short *priority, unsigned short *weight);
107 #endif /* _ASTERISK_SRV_H */
Main Channel structure associated with a channel.
void ast_srv_cleanup(struct srv_context **context)
Cleanup resources associated with ast_srv_lookup.
Definition: srv.c:248
int ast_srv_get_nth_record(struct srv_context *context, int record_num, const char **host, unsigned short *port, unsigned short *priority, unsigned short *weight)
Retrieve details from a specific SRV record.
Definition: srv.c:309
int ast_get_srv(struct ast_channel *chan, char *host, int hostlen, int *port, const char *service)
Lookup entry in SRV records Returns 1 if found, 0 if not found, -1 on hangup.
Definition: srv.c:260
unsigned int ast_srv_get_record_count(struct srv_context *context)
Get the number of records for a given SRV context.
Definition: srv.c:304
int ast_srv_lookup(struct srv_context **context, const char *service, const char **host, unsigned short *port)
Retrieve set of SRV lookups, in order.
Definition: srv.c:202