Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Data Structures | Functions
refer.h File Reference

Out-of-call refer support. More...

#include "asterisk/vector.h"
#include "asterisk/frame.h"
Include dependency graph for refer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_refer_param
 
struct  ast_refer_params
 
struct  ast_refer_tech
 A refer technology. More...
 

Functions

struct ast_referast_refer_alloc (void)
 Allocate a refer. More...
 
struct ast_referast_refer_destroy (struct ast_refer *refer)
 Destroy an ast_refer. More...
 
const char * ast_refer_get_endpoint (const struct ast_refer *refer)
 Retrieve the endpoint associated with this refer. More...
 
const char * ast_refer_get_from (const struct ast_refer *refer)
 Retrieve the source of this refer. More...
 
const char * ast_refer_get_refer_to (const struct ast_refer *refer)
 Get the "refer-to" value of a refer. More...
 
const char * ast_refer_get_tech (const struct ast_refer *refer)
 Retrieve the technology associated with this refer. More...
 
const char * ast_refer_get_to (const struct ast_refer *refer)
 Retrieve the destination of this refer. More...
 
int ast_refer_get_to_self (const struct ast_refer *refer)
 Retrieve the "to_self" value of this refer. More...
 
const char * ast_refer_get_var (struct ast_refer *refer, const char *name)
 Get the specified variable on the refer. More...
 
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. More...
 
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. More...
 
struct ast_referast_refer_ref (struct ast_refer *refer)
 Bump a refer's ref count. More...
 
int ast_refer_send (struct ast_refer *refer)
 Send a refer directly to an endpoint. More...
 
int ast_refer_set_endpoint (struct ast_refer *refer, const char *fmt,...)
 Set the technology's endpoint associated with this refer. More...
 
int ast_refer_set_from (struct ast_refer *refer, const char *fmt,...)
 Set the 'from' URI of a refer. More...
 
int ast_refer_set_refer_to (struct ast_refer *refer, const char *fmt,...)
 Set the 'refer_to' URI of a refer. More...
 
int ast_refer_set_tech (struct ast_refer *refer, const char *fmt,...)
 Set the technology associated with this refer. More...
 
int ast_refer_set_to (struct ast_refer *refer, const char *fmt,...)
 Set the 'to' URI of a refer. More...
 
int ast_refer_set_to_self (struct ast_refer *refer, int val)
 Set the 'to_self' value of a refer. More...
 
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. More...
 
int ast_refer_tech_register (const struct ast_refer_tech *tech)
 Register a refer technology. More...
 
int ast_refer_tech_unregister (const struct ast_refer_tech *tech)
 Unregister a refer technology. More...
 
void ast_refer_var_iterator_destroy (struct ast_refer_var_iterator *iter)
 Destroy a refer variable iterator. More...
 
struct ast_refer_var_iteratorast_refer_var_iterator_init (const struct ast_refer *refer)
 Create a new refer variable iterator. More...
 
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. More...
 
void ast_refer_var_unref_current (struct ast_refer_var_iterator *iter)
 Unref a refer var from inside an iterator loop. More...
 

Detailed Description

Out-of-call refer support.

Author
Maximilian Fridrich m.fri.nosp@m.dric.nosp@m.h@com.nosp@m.mend.nosp@m..com

The purpose of this API is to provide support for refers that are not session based. The refers are passed into the Asterisk core to be routed through the dialplan or another interface and potentially sent back out through a refer technology that has been registered through this API.

Definition in file refer.h.

Function Documentation

◆ ast_refer_alloc()

struct ast_refer * ast_refer_alloc ( void  )

Allocate a refer.

Allocate a refer for the purposes of passing it into the Asterisk core to be routed through the dialplan. This refer must be destroyed using ast_refer_destroy().

Returns
A refer object. This function will return NULL if an allocation error occurs.

Definition at line 124 of file refer.c.

125{
126 struct ast_refer *refer;
127
128 if (!(refer = ao2_alloc_options(sizeof(*refer), refer_destructor, AO2_ALLOC_OPT_LOCK_NOLOCK))) {
129 return NULL;
130 }
131
132 if (ast_string_field_init(refer, 128)) {
133 ao2_ref(refer, -1);
134 return NULL;
135 }
136
139 if (!refer->vars) {
140 ao2_ref(refer, -1);
141 return NULL;
142 }
143 refer->to_self = 0;
144
145 return refer;
146}
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
static int refer_data_cmp_fn(void *obj, void *arg, int flags)
Definition: refer.c:84
static void refer_destructor(void *obj)
Definition: refer.c:116
#define NULL
Definition: resample.c:96
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
A refer.
Definition: refer.c:59
struct ao2_container * vars
Definition: refer.c:75
int to_self
Definition: refer.c:73

References AO2_ALLOC_OPT_LOCK_MUTEX, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_container_alloc_list, ao2_ref, ast_string_field_init, NULL, refer_data_cmp_fn(), refer_destructor(), ast_refer::to_self, and ast_refer::vars.

Referenced by send_refer().

◆ ast_refer_destroy()

struct ast_refer * ast_refer_destroy ( struct ast_refer refer)

Destroy an ast_refer.

Return values
NULLalways.

Definition at line 154 of file refer.c.

155{
156 ao2_ref(refer, -1);
157 return NULL;
158}

References ao2_ref, and NULL.

Referenced by refer_data_destroy(), and send_refer().

◆ ast_refer_get_endpoint()

const char * ast_refer_get_endpoint ( const struct ast_refer refer)

Retrieve the endpoint associated with this refer.

Parameters
referThe refer to get the endpoint from
Returns
The endpoint associated with the refer
Return values
NULLor empty string if the refer has no associated endpoint

Definition at line 246 of file refer.c.

247{
248 return refer->endpoint;
249}
const ast_string_field endpoint
Definition: refer.c:71

References ast_refer::endpoint.

◆ ast_refer_get_from()

const char * ast_refer_get_from ( const struct ast_refer refer)

Retrieve the source of this refer.

Parameters
referThe refer to get the soure from
Returns
The source of the refer
Return values
NULLor empty string if the refer has no source

Definition at line 226 of file refer.c.

227{
228 return refer->from;
229}
const ast_string_field from
Definition: refer.c:71

References ast_refer::from.

Referenced by refer_data_create().

◆ ast_refer_get_refer_to()

const char * ast_refer_get_refer_to ( const struct ast_refer refer)

Get the "refer-to" value of a refer.

Note
The return value is valid only as long as the ast_refer is valid. Hold a reference to the refer if you plan on storing the return value.
Parameters
referThe refer to get the "refer-to" value from
Returns
The "refer-to" value of the refer, encoded in UTF-8.

Definition at line 221 of file refer.c.

222{
223 return refer->refer_to;
224}
const ast_string_field refer_to
Definition: refer.c:71

References ast_refer::refer_to.

Referenced by refer_data_create().

◆ ast_refer_get_tech()

const char * ast_refer_get_tech ( const struct ast_refer refer)

Retrieve the technology associated with this refer.

Parameters
referThe refer to get the technology from
Returns
The technology of the refer
Return values
NULLor empty string if the refer has no associated technology

Definition at line 241 of file refer.c.

242{
243 return refer->tech;
244}
const ast_string_field tech
Definition: refer.c:71

References ast_refer::tech.

◆ ast_refer_get_to()

const char * ast_refer_get_to ( const struct ast_refer refer)

Retrieve the destination of this refer.

Parameters
referThe refer to get the destination from
Returns
The destination of the refer
Return values
NULLor empty string if the refer has no destination

Definition at line 231 of file refer.c.

232{
233 return refer->to;
234}
const ast_string_field to
Definition: refer.c:71

References ast_refer::to.

Referenced by refer_data_create(), and sip_refer_send().

◆ ast_refer_get_to_self()

int ast_refer_get_to_self ( const struct ast_refer refer)

Retrieve the "to_self" value of this refer.

Parameters
referThe refer to get the destination from
Returns
The to_self value of the refer

Definition at line 236 of file refer.c.

237{
238 return refer->to_self;
239}

References ast_refer::to_self.

Referenced by refer_data_create().

◆ ast_refer_get_var()

const char * ast_refer_get_var ( struct ast_refer refer,
const char *  name 
)

Get the specified variable on the refer.

Note
The return value is valid only as long as the ast_refer is valid. Hold a reference to the refer if you plan on storing the return value. It is possible to re-set the same refer var name (with ast_refer_set_var_outbound passing the variable name) while holding a pointer to the result of this function.
Parameters
refer
nameName of variable to get
Returns
The value associated with variable "name". NULL if variable not found.

Definition at line 317 of file refer.c.

318{
319 struct refer_data *data;
320 const char *val = NULL;
321
322 if (!(data = refer_data_find(refer->vars, name))) {
323 return NULL;
324 }
325
326 val = data->value;
327 ao2_ref(data, -1);
328
329 return val;
330}
static const char name[]
Definition: format_mp3.c:68
static struct refer_data * refer_data_find(struct ao2_container *vars, const char *name)
Definition: refer.c:264
char * value
Definition: refer.c:51
struct ast_refer * refer
Definition: ast_expr2.c:325

References ao2_ref, name, NULL, refer_data::refer, refer_data_find(), refer_data::value, and ast_refer::vars.

◆ ast_refer_get_var_and_unlink()

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.

Note
The return value must be freed by the caller.
Parameters
refer
nameName of variable to get
Returns
The value associated with variable "name". NULL if variable not found.

Definition at line 269 of file refer.c.

270{
271 struct refer_data *data;
272 char *val = NULL;
273
274 if (!(data = ao2_find(refer->vars, name, OBJ_SEARCH_KEY | OBJ_UNLINK))) {
275 return NULL;
276 }
277
278 val = ast_strdup(data->value);
279 ao2_ref(data, -1);
280
281 return val;
282}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
@ OBJ_UNLINK
Definition: astobj2.h:1039
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101

References ao2_find, ao2_ref, ast_strdup, name, NULL, OBJ_SEARCH_KEY, OBJ_UNLINK, refer_data::refer, refer_data::value, and ast_refer::vars.

Referenced by refer_send().

◆ ast_refer_notify_transfer_request()

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.

Parameters
originating_chanThe channel that received the transfer request
referred_byInformation about the requesting identity
extenThe extension for blind transfers
protocol_idTechnology specific replace indication
destThe identified replace target for attended requests.
paramsList of protocol specific params.
stateThe state of the transfer

Definition at line 541 of file refer.c.

545{
546 RAII_VAR(struct ast_ari_transfer_message *, transfer_message, NULL, ao2_cleanup);
547 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
548 RAII_VAR(struct ast_bridge *, source_bridge, NULL, ao2_cleanup);
549 RAII_VAR(struct ast_bridge *, dest_bridge, NULL, ao2_cleanup);
550
551 transfer_message = ast_ari_transfer_message_create(source, referred_by, exten, protocol_id, dest, params, state);
552 if (!transfer_message) {
553 return -1;
554 }
555 source_bridge = ast_bridge_transfer_acquire_bridge(source);
556 if (source_bridge) {
558
559 ast_bridge_lock(source_bridge);
560 transfer_message->source_bridge = ast_bridge_get_snapshot(source_bridge);
561 peer = ast_bridge_peer_nolock(source_bridge, source);
562 if (peer) {
563 ast_channel_lock(peer);
564 transfer_message->source_peer = ao2_bump(ast_channel_snapshot(peer));
565 ast_channel_unlock(peer);
566 }
567 ast_bridge_unlock(source_bridge);
568 }
569
570 if (dest) {
571 dest_bridge = ast_bridge_transfer_acquire_bridge(dest);
572 if (dest_bridge) {
574
575 ast_bridge_lock(dest_bridge);
576 transfer_message->dest_bridge = ast_bridge_get_snapshot(dest_bridge);
577 peer = ast_bridge_peer_nolock(dest_bridge, dest);
578 if (peer) {
579 ast_channel_lock(peer);
580 transfer_message->dest_peer = ao2_bump(ast_channel_snapshot(peer));
581 ast_channel_unlock(peer);
582 }
583 ast_bridge_unlock(dest_bridge);
584 }
585 }
586
588 if (msg) {
589 ast_channel_lock(source);
590 stasis_publish(ast_channel_topic(source), msg);
591 ast_channel_unlock(source);
592 }
593
594 return 0;
595}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:485
struct ast_channel * ast_bridge_peer_nolock(struct ast_bridge *bridge, struct ast_channel *chan)
Get the channel's bridge peer only if the bridge is two-party.
Definition: bridge.c:4116
struct ast_bridge * ast_bridge_transfer_acquire_bridge(struct ast_channel *chan)
Acquire the channel's bridge for transfer purposes.
Definition: bridge.c:4477
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition: bridge.h:474
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
#define ast_channel_lock(chan)
Definition: channel.h:2970
struct ast_channel_snapshot * ast_channel_snapshot(const struct ast_channel *chan)
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:3017
#define ast_channel_unlock(chan)
Definition: channel.h:2971
struct stasis_message_type * ast_channel_transfer_request_type(void)
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition: stasis.c:1538
struct ast_bridge_snapshot * ast_bridge_get_snapshot(struct ast_bridge *bridge)
Returns the current snapshot for the bridge.
struct ast_ari_transfer_message * ast_ari_transfer_message_create(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)
Message published during an "ARI" transfer.
Structure that contains information about a bridge.
Definition: bridge.h:353
Main Channel structure associated with a channel.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References ao2_bump, ao2_cleanup, ast_ari_transfer_message_create(), ast_bridge_get_snapshot(), ast_bridge_lock, ast_bridge_peer_nolock(), ast_bridge_transfer_acquire_bridge(), ast_bridge_unlock, ast_channel_cleanup, ast_channel_lock, ast_channel_snapshot(), ast_channel_topic(), ast_channel_transfer_request_type(), ast_channel_unlock, NULL, RAII_VAR, stasis_message_create(), and stasis_publish().

Referenced by ari_notify().

◆ ast_refer_ref()

struct ast_refer * ast_refer_ref ( struct ast_refer refer)

Bump a refer's ref count.

Definition at line 148 of file refer.c.

149{
150 ao2_ref(refer, 1);
151 return refer;
152}

References ao2_ref.

Referenced by refer_data_create().

◆ ast_refer_send()

int ast_refer_send ( struct ast_refer refer)

Send a refer directly to an endpoint.

Regardless of the return value of this function, this function will take care of ensuring that the refer object is properly destroyed when needed.

Return values
0refer successfully queued to be sent out
non-zerofailure, refer not get sent out.

Definition at line 413 of file refer.c.

414{
415 char *tech_name = NULL;
416 const struct ast_refer_tech *refer_tech;
417 int res = -1;
418
419 if (ast_strlen_zero(refer->to)) {
420 ao2_ref(refer, -1);
421 return -1;
422 }
423
424 tech_name = ast_strdupa(refer->to);
425 tech_name = strsep(&tech_name, ":");
426
429
430 if (!refer_tech) {
431 ast_log(LOG_ERROR, "Unknown refer tech: %s\n", tech_name);
433 ao2_ref(refer, -1);
434 return -1;
435 }
436
437 ao2_lock(refer);
438 res = refer_tech->refer_send(refer);
439 ao2_unlock(refer);
440
442
443 ao2_ref(refer, -1);
444
445 return res;
446}
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define LOG_ERROR
#define ast_rwlock_rdlock(a)
Definition: lock.h:239
#define ast_rwlock_unlock(a)
Definition: lock.h:238
static ast_rwlock_t refer_techs_lock
Lock for refer_techs vector.
Definition: refer.c:79
static const struct ast_refer_tech * refer_find_by_tech_name(const char *tech_name)
Definition: refer.c:398
static const struct ast_refer_tech refer_tech
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
A refer technology.
Definition: refer.h:57
int(*const refer_send)(const struct ast_refer *refer)
Send a refer.
Definition: refer.h:78

References ao2_lock, ao2_ref, ao2_unlock, ast_log, ast_rwlock_rdlock, ast_rwlock_unlock, ast_strdupa, ast_strlen_zero(), LOG_ERROR, NULL, refer_find_by_tech_name(), ast_refer_tech::refer_send, refer_tech, refer_techs_lock, strsep(), and ast_refer::to.

Referenced by send_refer().

◆ ast_refer_set_endpoint()

int ast_refer_set_endpoint ( struct ast_refer refer,
const char *  fmt,
  ... 
)

Set the technology's endpoint associated with this refer.

Return values
0success
-1failure

Definition at line 210 of file refer.c.

211{
212 va_list ap;
213
214 va_start(ap, fmt);
215 ast_string_field_build_va(refer, endpoint, fmt, ap);
216 va_end(ap);
217
218 return 0;
219}
#define ast_string_field_build_va(x, field, fmt, args)
Set a field to a complex (built) value.
Definition: stringfields.h:591

References ast_string_field_build_va, and ast_refer::endpoint.

◆ ast_refer_set_from()

int ast_refer_set_from ( struct ast_refer refer,
const char *  fmt,
  ... 
)

Set the 'from' URI of a refer.

Return values
0success
-1failure

Definition at line 171 of file refer.c.

172{
173 va_list ap;
174
175 va_start(ap, fmt);
176 ast_string_field_build_va(refer, from, fmt, ap);
177 va_end(ap);
178
179 return 0;
180}

References ast_string_field_build_va, and ast_refer::from.

Referenced by send_refer().

◆ ast_refer_set_refer_to()

int ast_refer_set_refer_to ( struct ast_refer refer,
const char *  fmt,
  ... 
)

Set the 'refer_to' URI of a refer.

Return values
0success
-1failure

Definition at line 182 of file refer.c.

183{
184 va_list ap;
185
186 va_start(ap, fmt);
187 ast_string_field_build_va(refer, refer_to, fmt, ap);
188 va_end(ap);
189
190 return 0;
191}

References ast_string_field_build_va, and ast_refer::refer_to.

Referenced by send_refer().

◆ ast_refer_set_tech()

int ast_refer_set_tech ( struct ast_refer refer,
const char *  fmt,
  ... 
)

Set the technology associated with this refer.

Return values
0success
-1failure

Definition at line 199 of file refer.c.

200{
201 va_list ap;
202
203 va_start(ap, fmt);
204 ast_string_field_build_va(refer, tech, fmt, ap);
205 va_end(ap);
206
207 return 0;
208}

References ast_string_field_build_va, and ast_refer::tech.

◆ ast_refer_set_to()

int ast_refer_set_to ( struct ast_refer refer,
const char *  fmt,
  ... 
)

Set the 'to' URI of a refer.

Return values
0success
-1failure

Definition at line 160 of file refer.c.

161{
162 va_list ap;
163
164 va_start(ap, fmt);
165 ast_string_field_build_va(refer, to, fmt, ap);
166 va_end(ap);
167
168 return 0;
169}

References ast_string_field_build_va, and ast_refer::to.

Referenced by send_refer().

◆ ast_refer_set_to_self()

int ast_refer_set_to_self ( struct ast_refer refer,
int  val 
)

Set the 'to_self' value of a refer.

Return values
0success
-1failure

Definition at line 193 of file refer.c.

194{
195 refer->to_self = val;
196 return 0;
197}

References ast_refer::to_self.

Referenced by send_refer().

◆ ast_refer_set_var_outbound()

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.

Note
Setting a variable that already exists overwrites the existing variable value
Parameters
refer
nameName of variable to set
valueValue of variable to set
Return values
0success
-1failure

Definition at line 312 of file refer.c.

313{
314 return refer_set_var_full(refer, name, value);
315}
static int refer_set_var_full(struct ast_refer *refer, const char *name, const char *value)
Definition: refer.c:284
int value
Definition: syslog.c:37

References name, refer_data::refer, refer_set_var_full(), and value.

Referenced by send_refer().

◆ ast_refer_tech_register()

int ast_refer_tech_register ( const struct ast_refer_tech tech)

Register a refer technology.

Return values
0success
non-zerofailure

Definition at line 448 of file refer.c.

449{
450 const struct ast_refer_tech *match;
451
453
455 if (match) {
456 ast_log(LOG_ERROR, "Refer technology already registered for '%s'\n",
457 tech->name);
459 return -1;
460 }
461
462 if (AST_VECTOR_APPEND(&refer_techs, tech)) {
463 ast_log(LOG_ERROR, "Failed to register refer technology for '%s'\n",
464 tech->name);
466 return -1;
467 }
468 ast_verb(5, "Refer technology '%s' registered.\n", tech->name);
469
471
472 return 0;
473}
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2387
#define ast_verb(level,...)
#define ast_rwlock_wrlock(a)
Definition: lock.h:240
struct @384 refer_techs
Vector of refer technologies.
const char *const name
Name of this refer technology.
Definition: refer.h:66
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256

References ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_APPEND, ast_verb, LOG_ERROR, match(), ast_refer_tech::name, refer_find_by_tech_name(), refer_techs, and refer_techs_lock.

Referenced by load_module().

◆ ast_refer_tech_unregister()

int ast_refer_tech_unregister ( const struct ast_refer_tech tech)

Unregister a refer technology.

Return values
0success
non-zerofailure

Definition at line 492 of file refer.c.

493{
494 int match;
495
500
501 if (match) {
502 ast_log(LOG_ERROR, "No '%s' refer technology found.\n", tech->name);
503 return -1;
504 }
505
506 ast_verb(5, "Refer technology '%s' unregistered.\n", tech->name);
507
508 return 0;
509}
static int refer_tech_cmp(const struct ast_refer_tech *vec_elem, const struct ast_refer_tech *srch)
Comparison callback for ast_refer_tech vector removal.
Definition: refer.c:484
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
Definition: vector.h:571
#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup)
Remove an element from a vector that matches the given comparison.
Definition: vector.h:488

References ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_CMP_UNORDERED, ast_verb, LOG_ERROR, match(), ast_refer_tech::name, refer_tech_cmp(), refer_techs, and refer_techs_lock.

Referenced by load_module().

◆ ast_refer_var_iterator_destroy()

void ast_refer_var_iterator_destroy ( struct ast_refer_var_iterator iter)

Destroy a refer variable iterator.

Parameters
iterIterator to be destroyed

Definition at line 378 of file refer.c.

379{
380 if (iter) {
383 ast_free(iter);
384 }
385}
#define ast_free(a)
Definition: astmm.h:180
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
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
struct ao2_iterator iter
Definition: refer.c:333

References ao2_iterator_destroy(), ast_free, ast_refer_var_unref_current(), and ast_refer_var_iterator::iter.

Referenced by vars_to_headers().

◆ ast_refer_var_iterator_init()

struct ast_refer_var_iterator * ast_refer_var_iterator_init ( const struct ast_refer refer)

Create a new refer variable iterator.

Parameters
referA refer whose variables are to be iterated over
Returns
An opaque pointer to the new iterator

Definition at line 337 of file refer.c.

338{
340
341 iter = ast_calloc(1, sizeof(*iter));
342 if (!iter) {
343 return NULL;
344 }
345
346 iter->iter = ao2_iterator_init(refer->vars, 0);
347
348 return iter;
349}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

References ao2_iterator_init(), ast_calloc, ast_refer_var_iterator::iter, NULL, and ast_refer::vars.

Referenced by vars_to_headers().

◆ ast_refer_var_iterator_next()

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.

Parameters
iterAn iterator created with ast_refer_var_iterator_init
nameA pointer to the name result pointer
valueA pointer to the value result pointer
Note
The refcount to iter->current_used must be decremented by the caller by calling ast_refer_var_unref_current.
Return values
0No more entries
1Valid entry

Definition at line 351 of file refer.c.

352{
353 struct refer_data *data;
354
355 if (!iter) {
356 return 0;
357 }
358
359 data = ao2_iterator_next(&iter->iter);
360 if (!data) {
361 return 0;
362 }
363
364 *name = data->name;
365 *value = data->value;
366
367 iter->current_used = data;
368
369 return 1;
370}
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
struct refer_data * current_used
Definition: refer.c:334
char * name
Definition: refer.c:49

References ao2_iterator_next, ast_refer_var_iterator::current_used, ast_refer_var_iterator::iter, name, refer_data::name, refer_data::value, and value.

Referenced by vars_to_headers().

◆ ast_refer_var_unref_current()

void ast_refer_var_unref_current ( struct ast_refer_var_iterator iter)

Unref a refer var from inside an iterator loop.

Definition at line 372 of file refer.c.

373{
375 iter->current_used = NULL;
376}

References ao2_cleanup, ast_refer_var_iterator::current_used, and NULL.

Referenced by ast_refer_var_iterator_destroy(), and vars_to_headers().