Asterisk - The Open Source Telephony Project GIT-master-773870a
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
endpoints.c File Reference

Asterisk endpoint API. More...

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/endpoints.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/stringfields.h"
#include "asterisk/_private.h"
Include dependency graph for main/endpoints.c:

Go to the source code of this file.

Data Structures

struct  ast_endpoint
 

Macros

#define ENDPOINT_BUCKETS   127
 
#define ENDPOINT_CHANNEL_BUCKETS   127
 
#define TECH_ENDPOINT_BUCKETS   11
 

Functions

int ast_endpoint_add_channel (struct ast_endpoint *endpoint, struct ast_channel *chan)
 Adds a channel to the given endpoint.
 
struct ast_endpointast_endpoint_create (const char *tech, const char *resource)
 Create an endpoint struct.
 
struct ast_endpointast_endpoint_find_by_id (const char *id)
 Finds the endpoint with the given tech[/resource] id.
 
const char * ast_endpoint_get_id (const struct ast_endpoint *endpoint)
 Gets the tech/resource id of the given endpoint.
 
const char * ast_endpoint_get_resource (const struct ast_endpoint *endpoint)
 Gets the resource name of the given endpoint.
 
struct ast_endpoint_snapshotast_endpoint_get_snapshot (struct ast_endpoint *endpoint)
 Gets the latest snapshot of the given endpoint.
 
enum ast_endpoint_state ast_endpoint_get_state (const struct ast_endpoint *endpoint)
 Gets the state of the given endpoint.
 
const char * ast_endpoint_get_tech (const struct ast_endpoint *endpoint)
 Gets the technology of the given endpoint.
 
int ast_endpoint_init (void)
 Endpoint support initialization.
 
int ast_endpoint_remove_channel (struct ast_endpoint *endpoint, struct ast_channel *chan)
 Removes a channel from the given endpoint.
 
void ast_endpoint_set_max_channels (struct ast_endpoint *endpoint, int max_channels)
 Updates the maximum number of channels an endpoint supports.
 
void ast_endpoint_set_state (struct ast_endpoint *endpoint, enum ast_endpoint_state state)
 Updates the state of the given endpoint.
 
void ast_endpoint_shutdown (struct ast_endpoint *endpoint)
 Shutsdown an ast_endpoint.
 
struct ast_endpoint_snapshotast_endpoint_snapshot_create (struct ast_endpoint *endpoint)
 Create a snapshot of an endpoint.
 
const char * ast_endpoint_state_to_string (enum ast_endpoint_state state)
 Returns a string representation of the given endpoint state.
 
struct stasis_topicast_endpoint_topic (struct ast_endpoint *endpoint)
 Returns the topic for a specific endpoint.
 
struct stasis_topicast_endpoint_topic_cached (struct ast_endpoint *endpoint)
 Returns the topic for a specific endpoint.
 
static struct stasis_messagecreate_endpoint_snapshot_message (struct ast_endpoint *endpoint)
 
static void endpoint_cleanup (void)
 
static void endpoint_dtor (void *obj)
 
static struct ast_endpointendpoint_internal_create (const char *tech, const char *resource)
 
static void endpoint_publish_snapshot (struct ast_endpoint *endpoint)
 
static void endpoint_snapshot_dtor (void *obj)
 

Variables

static struct ao2_containerendpoints
 
static struct ao2_containertech_endpoints
 

Detailed Description

Asterisk endpoint API.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file main/endpoints.c.

Macro Definition Documentation

◆ ENDPOINT_BUCKETS

#define ENDPOINT_BUCKETS   127

Buckets for endpoint hash. Keep it prime!

Definition at line 44 of file main/endpoints.c.

◆ ENDPOINT_CHANNEL_BUCKETS

#define ENDPOINT_CHANNEL_BUCKETS   127

Buckets for endpoint->channel mappings. Keep it prime!

Definition at line 41 of file main/endpoints.c.

◆ TECH_ENDPOINT_BUCKETS

#define TECH_ENDPOINT_BUCKETS   11

Buckets for technology endpoints.

Definition at line 47 of file main/endpoints.c.

Function Documentation

◆ ast_endpoint_add_channel()

int ast_endpoint_add_channel ( struct ast_endpoint endpoint,
struct ast_channel chan 
)

Adds a channel to the given endpoint.

Since
12

This updates the endpoint's statistics, as well as forwarding all of the channel's messages to the endpoint's topic.

The channel is automagically removed from the endpoint when it is disposed of.

Parameters
endpoint
chanChannel.
Return values
0on success.
Non-zeroon error.

Definition at line 165 of file main/endpoints.c.

167{
168 ast_assert(chan != NULL);
169 ast_assert(endpoint != NULL);
171
172 ast_channel_forward_endpoint(chan, endpoint);
173
174 ao2_lock(endpoint);
176 ao2_unlock(endpoint);
177
179
180 return 0;
181}
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
const char * ast_channel_uniqueid(const struct ast_channel *chan)
int ast_channel_forward_endpoint(struct ast_channel *chan, struct ast_endpoint *endpoint)
Forward channel stasis messages to the given endpoint.
static void endpoint_publish_snapshot(struct ast_endpoint *endpoint)
#define NULL
Definition resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
Definition strings.c:205
struct ao2_container * channel_ids
const ast_string_field resource
#define ast_assert(a)
Definition utils.h:779

References ao2_lock, ao2_unlock, ast_assert, ast_channel_forward_endpoint(), ast_channel_uniqueid(), ast_str_container_add(), ast_strlen_zero(), ast_endpoint::channel_ids, endpoint_publish_snapshot(), NULL, and ast_endpoint::resource.

Referenced by ast_channel_endpoint_set(), and AST_TEST_DEFINE().

◆ ast_endpoint_create()

struct ast_endpoint * ast_endpoint_create ( const char *  tech,
const char *  resource 
)

Create an endpoint struct.

The endpoint is created with a state of UNKNOWN and max_channels of -1 (unlimited). While ast_endpoint is AO2 managed, you have to shut it down with ast_endpoint_shutdown() to clean up references from subscriptions.

Parameters
techTechnology for this endpoint.
resourceName of this endpoint.
Returns
Newly created endpoint.
Return values
NULLon error.
Since
12

Definition at line 289 of file main/endpoints.c.

290{
291 if (ast_strlen_zero(tech)) {
292 ast_log(LOG_ERROR, "Endpoint tech cannot be empty\n");
293 return NULL;
294 }
295
296 if (ast_strlen_zero(resource)) {
297 ast_log(LOG_ERROR, "Endpoint resource cannot be empty\n");
298 return NULL;
299 }
300
301 return endpoint_internal_create(tech, resource);
302}
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
static struct ast_endpoint * endpoint_internal_create(const char *tech, const char *resource)

References ast_log, ast_strlen_zero(), endpoint_internal_create(), LOG_ERROR, NULL, ast_endpoint::resource, and ast_endpoint::tech.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), build_peer(), persistent_endpoint_find_or_create(), and xmpp_client_alloc().

◆ ast_endpoint_find_by_id()

struct ast_endpoint * ast_endpoint_find_by_id ( const char *  id)

Finds the endpoint with the given tech[/resource] id.

Endpoints are refcounted, so ao2_cleanup() when you're done.

Note
The resource portion of an ID is optional. If not provided, an aggregate endpoint for the entire technology is returned. These endpoints must not be modified, but can be subscribed to in order to receive updates for all endpoints of a given technology.
Parameters
idTech[/resource] id to look for.
Returns
Associated endpoint.
Return values
NULLif not found.
Since
12

Definition at line 81 of file main/endpoints.c.

82{
83 struct ast_endpoint *endpoint = ao2_find(endpoints, id, OBJ_KEY);
84
85 if (!endpoint) {
86 endpoint = ao2_find(tech_endpoints, id, OBJ_KEY);
87 }
88
89 return endpoint;
90}
#define OBJ_KEY
Definition astobj2.h:1151
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
static struct ao2_container * tech_endpoints
static struct ao2_container * endpoints

References ao2_find, endpoints, OBJ_KEY, and tech_endpoints.

Referenced by ast_ari_endpoints_list_by_tech(), endpoint_find(), and messaging_app_unsubscribe_endpoint().

◆ ast_endpoint_get_id()

const char * ast_endpoint_get_id ( const struct ast_endpoint endpoint)

Gets the tech/resource id of the given endpoint.

This is unique across all endpoints, and immutable.

Parameters
endpointThe endpoint.
Returns
Tech/resource id of the endpoint.
Return values
NULLif endpoint is NULL.
Since
12

Definition at line 358 of file main/endpoints.c.

359{
360 if (!endpoint) {
361 return NULL;
362 }
363 return endpoint->id;
364}
const ast_string_field id

References ast_endpoint::id, and NULL.

Referenced by app_subscribe_endpoint(), forwards_create_endpoint(), get_or_create_subscription(), get_subscription(), messaging_app_subscribe_endpoint(), and messaging_app_unsubscribe_endpoint().

◆ ast_endpoint_get_resource()

const char * ast_endpoint_get_resource ( const struct ast_endpoint endpoint)

Gets the resource name of the given endpoint.

This is unique for the endpoint's technology, and immutable.

Note
If the endpoint being queried is a technology aggregate endpoint, this will be an empty string.
Parameters
endpointThe endpoint.
Returns
Resource name of the endpoint.
Return values
NULLif endpoint is NULL.
Since
12

Definition at line 350 of file main/endpoints.c.

351{
352 if (!endpoint) {
353 return NULL;
354 }
355 return endpoint->resource;
356}

References NULL, and ast_endpoint::resource.

Referenced by add_to_regcontext(), ast_sip_get_endpoint_snapshot(), ast_sip_persistent_endpoint_publish_contact_state(), ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), endpoint_deleted_observer(), get_or_create_subscription(), get_subscription(), messaging_app_unsubscribe_endpoint(), persistent_endpoint_cmp(), and persistent_endpoint_hash().

◆ ast_endpoint_get_snapshot()

struct ast_endpoint_snapshot * ast_endpoint_get_snapshot ( struct ast_endpoint endpoint)

Gets the latest snapshot of the given endpoint.

Parameters
endpointThe endpoint.
Returns
Latest snapshot of the endpoint.
Return values
NULLif endpoint is NULL.
Since
20.19.0
22.9.0
23.3.0

Definition at line 374 of file main/endpoints.c.

375{
376 struct ast_endpoint_snapshot *snapshot;
377
378 if (!endpoint) {
379 return NULL;
380 }
381
382 ao2_lock(endpoint);
383 snapshot = ao2_bump(endpoint->snapshot);
384 ao2_unlock(endpoint);
385
386 return snapshot;
387}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
A snapshot of an endpoint's state.
struct ast_endpoint_snapshot * snapshot

References ao2_bump, ao2_lock, ao2_unlock, NULL, and ast_endpoint::snapshot.

Referenced by chan_pjsip_devicestate().

◆ ast_endpoint_get_state()

enum ast_endpoint_state ast_endpoint_get_state ( const struct ast_endpoint endpoint)

Gets the state of the given endpoint.

Parameters
endpointThe endpoint.
Returns
state.
Return values
AST_ENDPOINT_UNKNOWNif endpoint is NULL.
Since
13.4

Definition at line 366 of file main/endpoints.c.

367{
368 if (!endpoint) {
370 }
371 return endpoint->state;
372}
@ AST_ENDPOINT_UNKNOWN
Definition endpoints.h:53
enum ast_endpoint_state state

References AST_ENDPOINT_UNKNOWN, and ast_endpoint::state.

Referenced by add_to_regcontext(), and ast_sip_persistent_endpoint_update_state().

◆ ast_endpoint_get_tech()

const char * ast_endpoint_get_tech ( const struct ast_endpoint endpoint)

Gets the technology of the given endpoint.

This is an immutable string describing the channel provider technology (SIP, IAX2, etc.).

Parameters
endpointThe endpoint.
Returns
Tec of the endpoint.
Return values
NULLif endpoint is NULL.
Since
12

Definition at line 342 of file main/endpoints.c.

343{
344 if (!endpoint) {
345 return NULL;
346 }
347 return endpoint->tech;
348}
const ast_string_field tech

References NULL, and ast_endpoint::tech.

Referenced by ast_sip_get_endpoint_snapshot(), AST_TEST_DEFINE(), and get_subscription().

◆ ast_endpoint_init()

int ast_endpoint_init ( void  )

Endpoint support initialization.

Returns
0 on success.
Non-zero on error.

Definition at line 478 of file main/endpoints.c.

479{
481
483 ast_endpoint_hash_fn, NULL, ast_endpoint_cmp_fn);
484 if (!endpoints) {
485 return -1;
486 }
487
489 TECH_ENDPOINT_BUCKETS, ast_endpoint_hash_fn, NULL, ast_endpoint_cmp_fn);
490 if (!tech_endpoints) {
491 return -1;
492 }
493
494 return 0;
495}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition clicompat.c:19
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition astobj2.h:363
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition astobj2.h:1303
#define ENDPOINT_BUCKETS
static void endpoint_cleanup(void)
#define TECH_ENDPOINT_BUCKETS

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_register_cleanup(), ENDPOINT_BUCKETS, endpoint_cleanup(), endpoints, NULL, TECH_ENDPOINT_BUCKETS, and tech_endpoints.

Referenced by asterisk_daemon().

◆ ast_endpoint_remove_channel()

int ast_endpoint_remove_channel ( struct ast_endpoint endpoint,
struct ast_channel chan 
)

Removes a channel from the given endpoint.

Since
23.1.0
22.7.0
20.17.0
Parameters
endpoint
chanChannel.
Return values
0on success.
Non-zeroon error.

Definition at line 183 of file main/endpoints.c.

185{
186 ast_assert(chan != NULL);
187 ast_assert(endpoint != NULL);
189
190 ao2_lock(endpoint);
192 ao2_unlock(endpoint);
193
195
196 return 0;
197}
void ast_str_container_remove(struct ao2_container *str_container, const char *remove)
Removes a string from a string container allocated by ast_str_container_alloc.
Definition strings.c:221

References ao2_lock, ao2_unlock, ast_assert, ast_channel_uniqueid(), ast_str_container_remove(), ast_strlen_zero(), ast_endpoint::channel_ids, endpoint_publish_snapshot(), NULL, and ast_endpoint::resource.

Referenced by ast_channel_endpoint_set(), and AST_TEST_DEFINE().

◆ ast_endpoint_set_max_channels()

void ast_endpoint_set_max_channels ( struct ast_endpoint endpoint,
int  max_channels 
)

Updates the maximum number of channels an endpoint supports.

Set to -1 for unlimited channels.

Parameters
endpointEndpoint to modify.
max_channelsMaximum number of concurrent channels this endpoint supports.

Definition at line 401 of file main/endpoints.c.

403{
404 ast_assert(endpoint != NULL);
406
407 ao2_lock(endpoint);
408 endpoint->max_channels = max_channels;
409 ao2_unlock(endpoint);
411}
int max_channels
Max channels for this endpoint. -1 means unlimited or unknown.

References ao2_lock, ao2_unlock, ast_assert, ast_strlen_zero(), endpoint_publish_snapshot(), ast_endpoint_snapshot::max_channels, ast_endpoint::max_channels, NULL, and ast_endpoint::resource.

Referenced by AST_TEST_DEFINE(), and AST_TEST_DEFINE().

◆ ast_endpoint_set_state()

void ast_endpoint_set_state ( struct ast_endpoint endpoint,
enum ast_endpoint_state  state 
)

Updates the state of the given endpoint.

Parameters
endpointEndpoint to modify.
stateNew state.
Since
12

Definition at line 389 of file main/endpoints.c.

391{
392 ast_assert(endpoint != NULL);
394
395 ao2_lock(endpoint);
396 endpoint->state = state;
397 ao2_unlock(endpoint);
399}

References ao2_lock, ao2_unlock, ast_assert, ast_strlen_zero(), endpoint_publish_snapshot(), NULL, ast_endpoint::resource, ast_endpoint_snapshot::state, and ast_endpoint::state.

Referenced by __expire_registry(), __iax2_poke_noanswer(), ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), persistent_endpoint_find_or_create(), socket_process_helper(), update_registry(), and xmpp_client_change_state().

◆ ast_endpoint_shutdown()

void ast_endpoint_shutdown ( struct ast_endpoint endpoint)

Shutsdown an ast_endpoint.

Parameters
endpointEndpoint to shut down.
Since
12

Definition at line 320 of file main/endpoints.c.

321{
322 RAII_VAR(struct stasis_message *, clear_msg, NULL, ao2_cleanup);
323
324 if (endpoint == NULL) {
325 return;
326 }
327
328 ao2_unlink(endpoints, endpoint);
329 endpoint->tech_forward = stasis_forward_cancel(endpoint->tech_forward);
330
331 clear_msg = create_endpoint_snapshot_message(endpoint);
332 if (clear_msg) {
335 if (message) {
337 }
338 }
339 ao2_ref(endpoint, -1);
340}
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition astobj2.h:1578
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
struct stasis_topic * ast_endpoint_topic(struct ast_endpoint *endpoint)
Returns the topic for a specific endpoint.
static struct stasis_message * create_endpoint_snapshot_message(struct ast_endpoint *endpoint)
struct stasis_message * stasis_cache_clear_create(struct stasis_message *message)
A message which instructs the caching topic to remove an entry from its cache.
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition stasis.c:1615
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition stasis.c:1578
struct stasis_forward * tech_forward
#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:981

References ao2_cleanup, ao2_ref, ao2_unlink, ast_endpoint_topic(), create_endpoint_snapshot_message(), endpoints, NULL, RAII_VAR, stasis_cache_clear_create(), stasis_forward_cancel(), stasis_publish(), and ast_endpoint::tech_forward.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), peer_destructor(), persistent_endpoint_destroy(), and xmpp_client_destructor().

◆ ast_endpoint_state_to_string()

const char * ast_endpoint_state_to_string ( enum ast_endpoint_state  state)

Returns a string representation of the given endpoint state.

Parameters
stateEndpoint state.
Returns
String representation of state.
Return values
?if state isn't in ast_endpoint_state.

Definition at line 108 of file main/endpoints.c.

109{
110 switch (state) {
112 return "unknown";
114 return "offline";
116 return "online";
117 }
118 return "?";
119}
@ AST_ENDPOINT_OFFLINE
Definition endpoints.h:55
@ AST_ENDPOINT_ONLINE
Definition endpoints.h:57

References AST_ENDPOINT_OFFLINE, AST_ENDPOINT_ONLINE, and AST_ENDPOINT_UNKNOWN.

Referenced by ast_endpoint_snapshot_to_json().

◆ create_endpoint_snapshot_message()

static struct stasis_message * create_endpoint_snapshot_message ( struct ast_endpoint endpoint)
static

Definition at line 304 of file main/endpoints.c.

305{
306 RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
307
309 return NULL;
310 }
311
312 snapshot = ast_endpoint_snapshot_create(endpoint);
313 if (!snapshot) {
314 return NULL;
315 }
316
318}
struct stasis_message_type * ast_endpoint_snapshot_type(void)
Message type for ast_endpoint_snapshot.
struct ast_endpoint_snapshot * ast_endpoint_snapshot_create(struct ast_endpoint *endpoint)
Create a snapshot of an endpoint.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.

References ao2_cleanup, ast_endpoint_snapshot_create(), ast_endpoint_snapshot_type(), NULL, RAII_VAR, and stasis_message_create().

Referenced by ast_endpoint_shutdown().

◆ endpoint_cleanup()

static void endpoint_cleanup ( void  )
static

Definition at line 469 of file main/endpoints.c.

References ao2_cleanup, endpoints, NULL, and tech_endpoints.

Referenced by ast_endpoint_init().

◆ endpoint_dtor()

static void endpoint_dtor ( void *  obj)
static

Definition at line 148 of file main/endpoints.c.

149{
150 struct ast_endpoint *endpoint = obj;
151
153 endpoint->topics = NULL;
154
155 ao2_cleanup(endpoint->channel_ids);
156 endpoint->channel_ids = NULL;
157
158 ao2_cleanup(endpoint->snapshot);
159 endpoint->snapshot = NULL;
160
162}
void stasis_cp_single_unsubscribe(struct stasis_cp_single *one)
Stops caching and forwarding messages.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
struct stasis_cp_single * topics

References ao2_cleanup, ast_string_field_free_memory, ast_endpoint::channel_ids, NULL, ast_endpoint::snapshot, stasis_cp_single_unsubscribe(), and ast_endpoint::topics.

Referenced by endpoint_internal_create().

◆ endpoint_internal_create()

static struct ast_endpoint * endpoint_internal_create ( const char *  tech,
const char *  resource 
)
static

Definition at line 199 of file main/endpoints.c.

200{
201 RAII_VAR(struct ast_endpoint *, endpoint, NULL, ao2_cleanup);
202 RAII_VAR(struct ast_endpoint *, tech_endpoint, NULL, ao2_cleanup);
203
204 /* Get/create the technology endpoint */
205 if (!ast_strlen_zero(resource)) {
206 tech_endpoint = ao2_find(tech_endpoints, tech, OBJ_KEY);
207 if (!tech_endpoint) {
208 tech_endpoint = endpoint_internal_create(tech, NULL);
209 if (!tech_endpoint) {
210 return NULL;
211 }
212 }
213 }
214
215 endpoint = ao2_alloc(sizeof(*endpoint), endpoint_dtor);
216 if (!endpoint) {
217 return NULL;
218 }
219
220 endpoint->max_channels = -1;
221 endpoint->state = AST_ENDPOINT_UNKNOWN;
222
223 if (ast_string_field_init(endpoint, 80) != 0) {
224 return NULL;
225 }
226 ast_string_field_set(endpoint, tech, tech);
227 ast_string_field_set(endpoint, resource, S_OR(resource, ""));
228 ast_string_field_build(endpoint, id, "%s%s%s",
229 tech,
230 !ast_strlen_zero(resource) ? "/" : "",
231 S_OR(resource, ""));
232
233 /* All access to channel_ids should be covered by the endpoint's
234 * lock; no extra lock needed. */
235 endpoint->channel_ids = ast_str_container_alloc_options(
237 if (!endpoint->channel_ids) {
238 return NULL;
239 }
240
241 if (!ast_strlen_zero(resource)) {
242 char *topic_name;
243 int ret;
244
245 ret = ast_asprintf(&topic_name, "endpoint:%s", endpoint->id);
246 if (ret < 0) {
247 return NULL;
248 }
249
251 topic_name);
252 ast_free(topic_name);
253 if (!endpoint->topics) {
254 return NULL;
255 }
258
259 endpoint->tech_forward = stasis_forward_all(stasis_cp_single_topic(endpoint->topics),
260 stasis_cp_single_topic(tech_endpoint->topics));
261
263 ao2_link(endpoints, endpoint);
264 } else {
265 char *topic_name;
266 int ret;
267
268 ret = ast_asprintf(&topic_name, "endpoint:%s", endpoint->id);
269 if (ret < 0) {
270 return NULL;
271 }
272
274 topic_name);
275 ast_free(topic_name);
276 if (!endpoint->topics) {
277 return NULL;
278 }
281
282 ao2_link(tech_endpoints, endpoint);
283 }
284
285 ao2_ref(endpoint, +1);
286 return endpoint;
287}
#define ast_free(a)
Definition astmm.h:180
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition astmm.h:267
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
struct stasis_cp_all * ast_endpoint_cache_all(void)
#define ENDPOINT_CHANNEL_BUCKETS
static void endpoint_dtor(void *obj)
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
Definition stasis.h:297
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition stasis.c:1645
struct stasis_topic * stasis_cp_single_topic(struct stasis_cp_single *one)
Get the topic for this instance.
int stasis_cp_single_set_filter(struct stasis_cp_single *one, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a cache.
struct stasis_cp_single * stasis_cp_sink_create(struct stasis_cp_all *all, const char *name)
Create a sink in the cache pattern.
struct stasis_cp_single * stasis_cp_single_create(struct stasis_cp_all *all, const char *name)
Create the 'one' side of the cache pattern.
int stasis_cp_single_accept_message_type(struct stasis_cp_single *one, struct stasis_message_type *type)
Indicate to an instance that we are interested in a message type.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
struct ao2_container * ast_str_container_alloc_options(enum ao2_alloc_opts opts, int buckets)
Allocates a hash container for bare strings.
Definition strings.c:200

References ao2_alloc, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_cleanup, ao2_find, ao2_link, ao2_ref, ast_asprintf, ast_endpoint_cache_all(), ast_endpoint_snapshot_type(), AST_ENDPOINT_UNKNOWN, ast_free, ast_str_container_alloc_options(), ast_string_field_build, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ENDPOINT_CHANNEL_BUCKETS, endpoint_dtor(), endpoint_internal_create(), endpoint_publish_snapshot(), endpoints, NULL, OBJ_KEY, RAII_VAR, ast_endpoint::resource, S_OR, stasis_cp_single_accept_message_type(), stasis_cp_single_create(), stasis_cp_single_set_filter(), stasis_cp_single_topic(), stasis_cp_sink_create(), stasis_forward_all(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, ast_endpoint::tech, and tech_endpoints.

Referenced by ast_endpoint_create(), and endpoint_internal_create().

◆ endpoint_publish_snapshot()

static void endpoint_publish_snapshot ( struct ast_endpoint endpoint)
static

Definition at line 121 of file main/endpoints.c.

122{
123 RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
125
126 ast_assert(endpoint != NULL);
127 ast_assert(endpoint->topics != NULL);
128
130 return;
131 }
132
133 snapshot = ast_endpoint_snapshot_create(endpoint);
134 if (!snapshot) {
135 return;
136 }
138 if (!message) {
139 return;
140 }
142
143 ao2_lock(endpoint);
144 ao2_replace(endpoint->snapshot, snapshot);
145 ao2_unlock(endpoint);
146}
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition astobj2.h:501

References ao2_cleanup, ao2_lock, ao2_replace, ao2_unlock, ast_assert, ast_endpoint_snapshot_create(), ast_endpoint_snapshot_type(), ast_endpoint_topic(), NULL, RAII_VAR, ast_endpoint::snapshot, stasis_message_create(), stasis_publish(), and ast_endpoint::topics.

Referenced by ast_endpoint_add_channel(), ast_endpoint_remove_channel(), ast_endpoint_set_max_channels(), ast_endpoint_set_state(), and endpoint_internal_create().

◆ endpoint_snapshot_dtor()

static void endpoint_snapshot_dtor ( void *  obj)
static

Definition at line 413 of file main/endpoints.c.

414{
415 struct ast_endpoint_snapshot *snapshot = obj;
416 int channel;
417
418 ast_assert(snapshot != NULL);
419
420 for (channel = 0; channel < snapshot->num_channels; channel++) {
421 ao2_ref(snapshot->channel_ids[channel], -1);
422 }
423
425}

References ao2_ref, ast_assert, ast_string_field_free_memory, ast_endpoint_snapshot::channel_ids, NULL, and ast_endpoint_snapshot::num_channels.

Referenced by ast_endpoint_snapshot_create().

Variable Documentation

◆ endpoints

struct ao2_container* endpoints
static

◆ tech_endpoints

struct ao2_container* tech_endpoints
static