Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
refer.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2023, Commend International
5 *
6 * Maximilian Fridrich <m.fridrich@commend.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 * \file
21 *
22 * \brief Out-of-call refer support
23 *
24 * \author Maximilian Fridrich <m.fridrich@commend.com>
25 *
26 * The purpose of this API is to provide support for refers that
27 * are not session based. The refers are passed into the Asterisk core
28 * to be routed through the dialplan or another interface and potentially
29 * sent back out through a refer technology that has been registered
30 * through this API.
31 */
32
33#ifndef __AST_REFER_H__
34#define __AST_REFER_H__
35
36#if defined(__cplusplus) || defined(c_plusplus)
37extern "C" {
38#endif
39
40#include "asterisk/vector.h"
41#include "asterisk/frame.h"
42
43struct ast_channel;
44
45/*!
46 * \brief A refer structure.
47 *
48 * This is an opaque type that represents a refer.
49 */
50struct ast_refer;
51
52/*!
53 * \brief A refer technology
54 *
55 * A refer technology is capable of transmitting text refers.
56 */
58 /*!
59 * \brief Name of this refer technology
60 *
61 * This is the name that comes at the beginning of a URI for refers
62 * that should be sent to this refer technology implementation.
63 * For example, refers sent to "pjsip:m.fridrich@commend.com" would be
64 * passed to the ast_refer_tech with a name of "pjsip".
65 */
66 const char * const name;
67 /*!
68 * \brief Send a refer.
69 *
70 * \param refer The refer to send
71 *
72 * The fields of the ast_refer are guaranteed not to change during the
73 * duration of this function call.
74 *
75 * \retval 0 success
76 * \retval non-zero failure
77 */
78 int (* const refer_send)(const struct ast_refer *refer);
79};
80
82 const char *param_name;
83 const char *param_value;
84};
85
87
88/*!
89 * \brief Register a refer technology
90 *
91 * \retval 0 success
92 * \retval non-zero failure
93 */
94int ast_refer_tech_register(const struct ast_refer_tech *tech);
95
96/*!
97 * \brief Unregister a refer technology.
98 *
99 * \retval 0 success
100 * \retval non-zero failure
101 */
102int ast_refer_tech_unregister(const struct ast_refer_tech *tech);
103
104/*!
105 * \brief Allocate a refer.
106 *
107 * Allocate a refer for the purposes of passing it into the Asterisk core
108 * to be routed through the dialplan. This refer must be destroyed using
109 * ast_refer_destroy().
110 *
111 * \return A refer object. This function will return NULL if an allocation
112 * error occurs.
113 */
114struct ast_refer *ast_refer_alloc(void);
115
116/*!
117 * \brief Destroy an ast_refer
118 *
119 * \retval NULL always.
120 */
121struct ast_refer *ast_refer_destroy(struct ast_refer *refer);
122
123/*!
124 * \brief Bump a refer's ref count
125 */
126struct ast_refer *ast_refer_ref(struct ast_refer *refer);
127
128/*!
129 * \brief Set the 'to' URI of a refer
130 *
131 * \retval 0 success
132 * \retval -1 failure
133 */
134int __attribute__((format(printf, 2, 3)))
135 ast_refer_set_to(struct ast_refer *refer, const char *fmt, ...);
136
137/*!
138 * \brief Set the 'from' URI of a refer
139 *
140 * \retval 0 success
141 * \retval -1 failure
142 */
143int __attribute__((format(printf, 2, 3)))
144 ast_refer_set_from(struct ast_refer *refer, const char *fmt, ...);
145
146/*!
147 * \brief Set the 'refer_to' URI of a refer
148 *
149 * \retval 0 success
150 * \retval -1 failure
151 */
152int __attribute__((format(printf, 2, 3)))
153 ast_refer_set_refer_to(struct ast_refer *refer, const char *fmt, ...);
154
155/*!
156 * \brief Set the 'to_self' value of a refer
157 *
158 * \retval 0 success
159 * \retval -1 failure
160 */
161int ast_refer_set_to_self(struct ast_refer *refer, int val);
162
163/*!
164 * \brief Set the technology associated with this refer
165 *
166 * \retval 0 success
167 * \retval -1 failure
168 */
169int __attribute__((format(printf, 2, 3)))
170 ast_refer_set_tech(struct ast_refer *refer, const char *fmt, ...);
171
172/*!
173 * \brief Set the technology's endpoint associated with this refer
174 *
175 * \retval 0 success
176 * \retval -1 failure
177 */
178int __attribute__((format(printf, 2, 3)))
179 ast_refer_set_endpoint(struct ast_refer *refer, const char *fmt, ...);
180
181/*!
182 * \brief Set a variable on the refer being sent to a refer tech directly.
183 * \note Setting a variable that already exists overwrites the existing variable value
184 *
185 * \param refer
186 * \param name Name of variable to set
187 * \param value Value of variable to set
188 *
189 * \retval 0 success
190 * \retval -1 failure
191 */
192int ast_refer_set_var_outbound(struct ast_refer *refer, const char *name, const char *value);
193
194/*!
195 * \brief Get the specified variable on the refer and unlink it from the container of variables
196 * \note The return value must be freed by the caller.
197 *
198 * \param refer
199 * \param name Name of variable to get
200 *
201 * \return The value associated with variable "name". NULL if variable not found.
202 */
203char *ast_refer_get_var_and_unlink(struct ast_refer *refer, const char *name);
204
205/*!
206 * \brief Get the specified variable on the refer
207 * \note The return value is valid only as long as the ast_refer is valid. Hold a reference
208 * to the refer if you plan on storing the return value. It is possible to re-set the
209 * same refer var name (with ast_refer_set_var_outbound passing the variable name)
210 * while holding a pointer to the result of this function.
211 *
212 * \param refer
213 * \param name Name of variable to get
214 *
215 * \return The value associated with variable "name". NULL if variable not found.
216 */
217const char *ast_refer_get_var(struct ast_refer *refer, const char *name);
218
219/*!
220 * \brief Get the "refer-to" value of a refer.
221 * \note The return value is valid only as long as the ast_refer is valid. Hold a reference
222 * to the refer if you plan on storing the return value.
223 *
224 * \param refer The refer to get the "refer-to" value from
225 *
226 * \return The "refer-to" value of the refer, encoded in UTF-8.
227 */
228const char *ast_refer_get_refer_to(const struct ast_refer *refer);
229
230/*!
231 * \brief Retrieve the source of this refer
232 *
233 * \param refer The refer to get the soure from
234 *
235 * \return The source of the refer
236 * \retval NULL or empty string if the refer has no source
237 */
238const char *ast_refer_get_from(const struct ast_refer *refer);
239
240/*!
241 * \brief Retrieve the destination of this refer
242 *
243 * \param refer The refer to get the destination from
244 *
245 * \return The destination of the refer
246 * \retval NULL or empty string if the refer has no destination
247 */
248const char *ast_refer_get_to(const struct ast_refer *refer);
249
250/*!
251 * \brief Retrieve the "to_self" value of this refer
252 *
253 * \param refer The refer to get the destination from
254 *
255 * \return The to_self value of the refer
256 */
257int ast_refer_get_to_self(const struct ast_refer *refer);
258
259/*!
260 * \brief Retrieve the technology associated with this refer
261 *
262 * \param refer The refer to get the technology from
263 *
264 * \return The technology of the refer
265 * \retval NULL or empty string if the refer has no associated technology
266 */
267const char *ast_refer_get_tech(const struct ast_refer *refer);
268
269/*!
270 * \brief Retrieve the endpoint associated with this refer
271 *
272 * \param refer The refer to get the endpoint from
273 *
274 * \return The endpoint associated with the refer
275 * \retval NULL or empty string if the refer has no associated endpoint
276 */
277const char *ast_refer_get_endpoint(const struct ast_refer *refer);
278
279/*!
280 * \brief Send a refer directly to an endpoint.
281 *
282 * Regardless of the return value of this function, this function will take
283 * care of ensuring that the refer object is properly destroyed when needed.
284 *
285 * \retval 0 refer successfully queued to be sent out
286 * \retval non-zero failure, refer not get sent out.
287 */
288int ast_refer_send(struct ast_refer *refer);
289
290/*!
291 * \brief Opaque iterator for refer variables
292 */
294
295/*!
296 * \brief Create a new refer variable iterator
297 * \param refer A refer whose variables are to be iterated over
298 *
299 * \return An opaque pointer to the new iterator
300 */
302
303/*!
304 * \brief Get the next variable name and value
305 *
306 * \param iter An iterator created with ast_refer_var_iterator_init
307 * \param name A pointer to the name result pointer
308 * \param value A pointer to the value result pointer
309 *
310 * \note The refcount to iter->current_used must be decremented by the caller
311 * by calling ast_refer_var_unref_current.
312 *
313 * \retval 0 No more entries
314 * \retval 1 Valid entry
315 */
316int ast_refer_var_iterator_next(struct ast_refer_var_iterator *iter, const char **name, const char **value);
317
318/*!
319 * \brief Destroy a refer variable iterator
320 * \param iter Iterator to be destroyed
321 */
323
324/*!
325 * \brief Unref a refer var from inside an iterator loop
326 */
328
329/*!
330 * \brief Notify a transfer request.
331 * \param originating_chan The channel that received the transfer request
332 * \param referred_by Information about the requesting identity
333 * \param exten The extension for blind transfers
334 * \param protocol_id Technology specific replace indication
335 * \param dest The identified replace target for attended requests.
336 * \param params List of protocol specific params.
337 * \param state The state of the transfer
338 */
339int ast_refer_notify_transfer_request(struct ast_channel *originating_chan, const char *referred_by, const char *exten,
340 const char *protocol_id, struct ast_channel *dest, struct ast_refer_params *params,
342
343/*!
344 * @}
345 */
346
347#if defined(__cplusplus) || defined(c_plusplus)
348}
349#endif
350
351#endif /* __AST_REFER_H__ */
static const char name[]
Definition: format_mp3.c:68
Asterisk internal frame definitions.
ast_control_transfer
void ast_refer_var_unref_current(struct ast_refer_var_iterator *iter)
Unref a refer var from inside an iterator loop.
Definition: refer.c:372
int ast_refer_tech_unregister(const struct ast_refer_tech *tech)
Unregister a refer technology.
Definition: refer.c:492
const char * ast_refer_get_to(const struct ast_refer *refer)
Retrieve the destination of this refer.
Definition: refer.c:231
int ast_refer_var_iterator_next(struct ast_refer_var_iterator *iter, const char **name, const char **value)
Get the next variable name and value.
Definition: refer.c:351
struct ast_refer_var_iterator * ast_refer_var_iterator_init(const struct ast_refer *refer)
Create a new refer variable iterator.
Definition: refer.c:337
struct ast_refer * ast_refer_alloc(void)
Allocate a refer.
Definition: refer.c:124
const char * ast_refer_get_from(const struct ast_refer *refer)
Retrieve the source of this refer.
Definition: refer.c:226
const char * ast_refer_get_var(struct ast_refer *refer, const char *name)
Get the specified variable on the refer.
Definition: refer.c:317
int ast_refer_set_var_outbound(struct ast_refer *refer, const char *name, const char *value)
Set a variable on the refer being sent to a refer tech directly.
Definition: refer.c:312
const char * ast_refer_get_endpoint(const struct ast_refer *refer)
Retrieve the endpoint associated with this refer.
Definition: refer.c:246
char * ast_refer_get_var_and_unlink(struct ast_refer *refer, const char *name)
Get the specified variable on the refer and unlink it from the container of variables.
Definition: refer.c:269
int ast_refer_set_endpoint(struct ast_refer *refer, const char *fmt,...)
Set the technology's endpoint associated with this refer.
Definition: refer.c:210
int ast_refer_set_from(struct ast_refer *refer, const char *fmt,...)
Set the 'from' URI of a refer.
Definition: refer.c:171
struct ast_refer * ast_refer_destroy(struct ast_refer *refer)
Destroy an ast_refer.
Definition: refer.c:154
int ast_refer_notify_transfer_request(struct ast_channel *originating_chan, const char *referred_by, const char *exten, const char *protocol_id, struct ast_channel *dest, struct ast_refer_params *params, enum ast_control_transfer state)
Notify a transfer request.
Definition: refer.c:541
int ast_refer_set_refer_to(struct ast_refer *refer, const char *fmt,...)
Set the 'refer_to' URI of a refer.
Definition: refer.c:182
const char * ast_refer_get_refer_to(const struct ast_refer *refer)
Get the "refer-to" value of a refer.
Definition: refer.c:221
int ast_refer_set_tech(struct ast_refer *refer, const char *fmt,...)
Set the technology associated with this refer.
Definition: refer.c:199
int ast_refer_tech_register(const struct ast_refer_tech *tech)
Register a refer technology.
Definition: refer.c:448
int ast_refer_set_to_self(struct ast_refer *refer, int val)
Set the 'to_self' value of a refer.
Definition: refer.c:193
int ast_refer_send(struct ast_refer *refer)
Send a refer directly to an endpoint.
Definition: refer.c:413
struct ast_refer * ast_refer_ref(struct ast_refer *refer)
Bump a refer's ref count.
Definition: refer.c:148
int ast_refer_set_to(struct ast_refer *refer, const char *fmt,...)
Set the 'to' URI of a refer.
Definition: refer.c:160
int ast_refer_get_to_self(const struct ast_refer *refer)
Retrieve the "to_self" value of this refer.
Definition: refer.c:236
void ast_refer_var_iterator_destroy(struct ast_refer_var_iterator *iter)
Destroy a refer variable iterator.
Definition: refer.c:378
const char * ast_refer_get_tech(const struct ast_refer *refer)
Retrieve the technology associated with this refer.
Definition: refer.c:241
Main Channel structure associated with a channel.
const char * param_value
Definition: refer.h:83
const char * param_name
Definition: refer.h:82
A refer technology.
Definition: refer.h:57
int(*const refer_send)(const struct ast_refer *refer)
Send a refer.
Definition: refer.h:78
const char *const name
Name of this refer technology.
Definition: refer.h:66
A refer.
Definition: refer.c:59
Definition: ast_expr2.c:325
int value
Definition: syslog.c:37
Vector container support.
#define AST_VECTOR(name, type)
Define a vector structure.
Definition: vector.h:44