Wed Jan 8 2020 09:49:51

Asterisk developer's documentation


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