Asterisk - The Open Source Telephony Project
18.5.0
|
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/stasis_message_router.h"
#include "asterisk/stringfields.h"
#include "asterisk/_private.h"
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. More... | |
struct ast_endpoint * | ast_endpoint_create (const char *tech, const char *resource) |
Create an endpoint struct. More... | |
struct ast_endpoint * | ast_endpoint_find_by_id (const char *id) |
Finds the endpoint with the given tech[/resource] id. More... | |
const char * | ast_endpoint_get_id (const struct ast_endpoint *endpoint) |
Gets the tech/resource id of the given endpoint. More... | |
const char * | ast_endpoint_get_resource (const struct ast_endpoint *endpoint) |
Gets the resource name of the given endpoint. More... | |
enum ast_endpoint_state | ast_endpoint_get_state (const struct ast_endpoint *endpoint) |
Gets the state of the given endpoint. More... | |
const char * | ast_endpoint_get_tech (const struct ast_endpoint *endpoint) |
Gets the technology of the given endpoint. More... | |
int | ast_endpoint_init (void) |
Endpoint support initialization. More... | |
void | ast_endpoint_set_max_channels (struct ast_endpoint *endpoint, int max_channels) |
Updates the maximum number of channels an endpoint supports. More... | |
void | ast_endpoint_set_state (struct ast_endpoint *endpoint, enum ast_endpoint_state state) |
Updates the state of the given endpoint. More... | |
void | ast_endpoint_shutdown (struct ast_endpoint *endpoint) |
Shutsdown an ast_endpoint. More... | |
struct ast_endpoint_snapshot * | ast_endpoint_snapshot_create (struct ast_endpoint *endpoint) |
Create a snapshot of an endpoint. More... | |
const char * | ast_endpoint_state_to_string (enum ast_endpoint_state state) |
Returns a string representation of the given endpoint state. More... | |
struct stasis_topic * | ast_endpoint_topic (struct ast_endpoint *endpoint) |
Returns the topic for a specific endpoint. More... | |
struct stasis_topic * | ast_endpoint_topic_cached (struct ast_endpoint *endpoint) |
Returns the topic for a specific endpoint. More... | |
static struct stasis_message * | create_endpoint_snapshot_message (struct ast_endpoint *endpoint) |
static void | endpoint_cache_clear (void *data, struct stasis_subscription *sub, struct stasis_message *message) |
Handler for channel snapshot update. More... | |
static void | endpoint_cleanup (void) |
static void | endpoint_dtor (void *obj) |
static struct ast_endpoint * | endpoint_internal_create (const char *tech, const char *resource) |
static void | endpoint_publish_snapshot (struct ast_endpoint *endpoint) |
static void | endpoint_snapshot_dtor (void *obj) |
static void | endpoint_subscription_change (void *data, struct stasis_subscription *sub, struct stasis_message *message) |
Variables | |
static struct ao2_container * | endpoints |
static struct ao2_container * | tech_endpoints |
Asterisk endpoint API.
Definition in file main/endpoints.c.
#define ENDPOINT_BUCKETS 127 |
Buckets for endpoint hash. Keep it prime!
Definition at line 45 of file main/endpoints.c.
Referenced by ast_endpoint_init().
#define ENDPOINT_CHANNEL_BUCKETS 127 |
Buckets for endpoint->channel mappings. Keep it prime!
Definition at line 42 of file main/endpoints.c.
Referenced by endpoint_internal_create().
#define TECH_ENDPOINT_BUCKETS 11 |
Buckets for technology endpoints.
Definition at line 48 of file main/endpoints.c.
Referenced by ast_endpoint_init().
int ast_endpoint_add_channel | ( | struct ast_endpoint * | endpoint, |
struct ast_channel * | chan | ||
) |
Adds a channel to the given endpoint.
The channel is automagically removed from the endpoint when it is disposed of.
endpoint | |
chan | Channel. |
0 | on success. |
Non-zero | on error. |
Definition at line 164 of file main/endpoints.c.
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_alloc_ap(), and AST_TEST_DEFINE().
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.
tech | Technology for this endpoint. |
resource | Name of this endpoint. |
NULL
on error. Definition at line 319 of file main/endpoints.c.
References ast_log, ast_strlen_zero, endpoint_internal_create(), LOG_ERROR, and NULL.
Referenced by AST_TEST_DEFINE(), build_peer(), persistent_endpoint_find_or_create(), register_verify(), skinny_device_alloc(), and xmpp_client_alloc().
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.
id | Tech[/resource] id to look for. |
NULL
if not found.Definition at line 82 of file main/endpoints.c.
References ao2_find, and OBJ_KEY.
Referenced by ast_ari_endpoints_list_by_tech(), endpoint_find(), and messaging_app_unsubscribe_endpoint().
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.
endpoint | The endpoint. |
NULL
if endpoint is NULL
. Definition at line 391 of file main/endpoints.c.
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().
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.
endpoint | The endpoint. |
NULL
if endpoint is NULL
. Definition at line 383 of file main/endpoints.c.
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(), chan_pjsip_devicestate(), endpoint_deleted_observer(), get_or_create_subscription(), get_subscription(), messaging_app_unsubscribe_endpoint(), persistent_endpoint_cmp(), and persistent_endpoint_hash().
enum ast_endpoint_state ast_endpoint_get_state | ( | const struct ast_endpoint * | endpoint | ) |
Gets the state of the given endpoint.
endpoint | The endpoint. |
AST_ENDPOINT_UNKNOWN
if endpoint is NULL
. Definition at line 399 of file main/endpoints.c.
References AST_ENDPOINT_UNKNOWN, and ast_endpoint::state.
Referenced by add_to_regcontext(), and ast_sip_persistent_endpoint_update_state().
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.).
endpoint | The endpoint. |
NULL
if endpoint is NULL
. Definition at line 375 of file main/endpoints.c.
References NULL, and ast_endpoint::tech.
Referenced by ast_sip_get_endpoint_snapshot(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), and get_subscription().
int ast_endpoint_init | ( | void | ) |
Endpoint support initialization.
Definition at line 496 of file main/endpoints.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_register_cleanup(), ENDPOINT_BUCKETS, endpoint_cleanup(), NULL, and TECH_ENDPOINT_BUCKETS.
Referenced by asterisk_daemon().
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.
endpoint | Endpoint to modify. |
max_channels | Maximum number of concurrent channels this endpoint supports. |
Definition at line 419 of file main/endpoints.c.
References ao2_lock, ao2_unlock, ast_assert, ast_strlen_zero, endpoint_publish_snapshot(), ast_endpoint::max_channels, NULL, and ast_endpoint::resource.
Referenced by AST_TEST_DEFINE().
void ast_endpoint_set_state | ( | struct ast_endpoint * | endpoint, |
enum ast_endpoint_state | state | ||
) |
Updates the state of the given endpoint.
endpoint | Endpoint to modify. |
state | New state. |
Definition at line 407 of file main/endpoints.c.
References ao2_lock, ao2_unlock, ast_assert, ast_strlen_zero, endpoint_publish_snapshot(), NULL, ast_endpoint::resource, and ast_endpoint::state.
Referenced by __expire_registry(), __iax2_poke_noanswer(), ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), expire_register(), handle_response_peerpoke(), parse_register_contact(), persistent_endpoint_find_or_create(), register_verify(), sip_poke_noanswer(), skinny_register(), skinny_session_cleanup(), socket_process_helper(), unload_module(), update_registry(), and xmpp_client_change_state().
void ast_endpoint_shutdown | ( | struct ast_endpoint * | endpoint | ) |
Shutsdown an ast_endpoint.
endpoint | Endpoint to shut down. |
Definition at line 350 of file main/endpoints.c.
References ao2_cleanup, ao2_ref, ao2_unlink, ast_endpoint_topic(), create_endpoint_snapshot_message(), NULL, RAII_VAR, ast_endpoint::router, stasis_cache_clear_create(), stasis_forward_cancel(), stasis_message_router_unsubscribe(), stasis_publish(), and ast_endpoint::tech_forward.
Referenced by AST_TEST_DEFINE(), peer_destructor(), persistent_endpoint_destroy(), sip_destroy_peer(), skinny_device_destroy(), and xmpp_client_destructor().
const char* ast_endpoint_state_to_string | ( | enum ast_endpoint_state | state | ) |
Returns a string representation of the given endpoint state.
state | Endpoint state. |
"?"
if state isn't in ast_endpoint_state. Definition at line 109 of file main/endpoints.c.
References AST_ENDPOINT_OFFLINE, AST_ENDPOINT_ONLINE, and AST_ENDPOINT_UNKNOWN.
Referenced by ast_endpoint_snapshot_to_json().
|
static |
Definition at line 334 of file main/endpoints.c.
References ao2_cleanup, ast_endpoint_snapshot_create(), ast_endpoint_snapshot_type(), NULL, RAII_VAR, and stasis_message_create().
Referenced by ast_endpoint_shutdown().
|
static |
Handler for channel snapshot update.
Definition at line 183 of file main/endpoints.c.
References ao2_lock, ao2_unlock, ast_assert, AST_FLAG_DEAD, ast_str_container_remove(), ast_test_flag, ast_channel_snapshot::base, ast_endpoint::channel_ids, endpoint_publish_snapshot(), ast_channel_snapshot::flags, ast_channel_snapshot_update::new_snapshot, NULL, stasis_message_data(), ast_channel_snapshot_base::uniqueid, and update().
Referenced by endpoint_internal_create().
|
static |
Definition at line 487 of file main/endpoints.c.
References ao2_cleanup, and NULL.
Referenced by ast_endpoint_init().
|
static |
Definition at line 145 of file main/endpoints.c.
References ao2_cleanup, ast_assert, ast_string_field_free_memory, ast_endpoint::channel_ids, NULL, ast_endpoint::router, stasis_cp_single_unsubscribe(), stasis_message_router_is_done(), and ast_endpoint::topics.
Referenced by endpoint_internal_create().
|
static |
Definition at line 214 of file main/endpoints.c.
References ao2_alloc, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_cleanup, ao2_find, ao2_link, ao2_ref, ast_asprintf, ast_channel_snapshot_type(), ast_endpoint_cache_all(), ast_endpoint_snapshot_type(), ast_endpoint_topic(), 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_cache_clear(), ENDPOINT_CHANNEL_BUCKETS, endpoint_dtor(), endpoint_publish_snapshot(), endpoint_subscription_change(), NULL, OBJ_KEY, RAII_VAR, 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_message_router_add(), stasis_message_router_create_pool, stasis_subscription_change_type(), and STASIS_SUBSCRIPTION_FILTER_SELECTIVE.
Referenced by ast_endpoint_create().
|
static |
Definition at line 122 of file main/endpoints.c.
References ao2_cleanup, ast_assert, ast_endpoint_snapshot_create(), ast_endpoint_snapshot_type(), ast_endpoint_topic(), NULL, RAII_VAR, stasis_message_create(), stasis_publish(), and ast_endpoint::topics.
Referenced by ast_endpoint_add_channel(), ast_endpoint_set_max_channels(), ast_endpoint_set_state(), endpoint_cache_clear(), and endpoint_internal_create().
|
static |
Definition at line 431 of file main/endpoints.c.
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().
|
static |
Definition at line 203 of file main/endpoints.c.
References ao2_cleanup, and stasis_subscription_final_message().
Referenced by endpoint_internal_create().
|
static |
Definition at line 50 of file main/endpoints.c.
Referenced by ami_registrations_endpoints(), ami_show_endpoints(), app_to_json(), ast_sip_get_endpoints(), cli_complete_endpoint(), create_mwi_subscriptions(), endpoints_scrape_cb(), load_all_endpoints(), load_module(), sip_options_aor_observer_modified_task(), stasis_app_to_cli(), and unload_module().
|
static |
Definition at line 52 of file main/endpoints.c.