| Asterisk - The Open Source Telephony Project GIT-master-27fb039
    | 
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"
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_endpoint * | ast_endpoint_create (const char *tech, const char *resource) | 
| Create an endpoint struct. | |
| struct ast_endpoint * | ast_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. | |
| 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_snapshot * | ast_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_topic * | ast_endpoint_topic (struct ast_endpoint *endpoint) | 
| Returns the topic for a specific endpoint. | |
| struct stasis_topic * | ast_endpoint_topic_cached (struct ast_endpoint *endpoint) | 
| Returns the topic for a specific endpoint. | |
| static struct stasis_message * | create_endpoint_snapshot_message (struct ast_endpoint *endpoint) | 
| 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) | 
| 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 44 of file main/endpoints.c.
| #define ENDPOINT_CHANNEL_BUCKETS 127 | 
Buckets for endpoint->channel mappings. Keep it prime!
Definition at line 41 of file main/endpoints.c.
| #define TECH_ENDPOINT_BUCKETS 11 | 
Buckets for technology endpoints.
Definition at line 47 of file main/endpoints.c.
| int ast_endpoint_add_channel | ( | struct ast_endpoint * | endpoint, | 
| struct ast_channel * | chan | ||
| ) | 
Adds a channel to the given endpoint.
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.
| endpoint | |
| chan | Channel. | 
| 0 | on success. | 
| Non-zero | on error. | 
Definition at line 156 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_endpoint_set(), 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 280 of file main/endpoints.c.
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().
| 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 79 of file main/endpoints.c.
References ao2_find, endpoints, OBJ_KEY, and tech_endpoints.
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 348 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 340 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 356 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 332 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 453 of file main/endpoints.c.
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().
| int ast_endpoint_remove_channel | ( | struct ast_endpoint * | endpoint, | 
| struct ast_channel * | chan | ||
| ) | 
Removes a channel from the given endpoint.
| endpoint | |
| chan | Channel. | 
| 0 | on success. | 
| Non-zero | on error. | 
Definition at line 174 of file main/endpoints.c.
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().
| 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 376 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(), and 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 364 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(), AST_TEST_DEFINE(), persistent_endpoint_find_or_create(), socket_process_helper(), 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 311 of file main/endpoints.c.
References ao2_cleanup, 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().
| 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 106 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 295 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 | 
Definition at line 444 of file main/endpoints.c.
References ao2_cleanup, endpoints, NULL, and tech_endpoints.
Referenced by ast_endpoint_init().
| 
 | static | 
Definition at line 142 of file main/endpoints.c.
References ao2_cleanup, ast_string_field_free_memory, ast_endpoint::channel_ids, NULL, stasis_cp_single_unsubscribe(), and ast_endpoint::topics.
Referenced by endpoint_internal_create().
| 
 | static | 
Definition at line 190 of file main/endpoints.c.
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().
| 
 | static | 
Definition at line 119 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_remove_channel(), ast_endpoint_set_max_channels(), ast_endpoint_set_state(), and endpoint_internal_create().
| 
 | static | 
Definition at line 388 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 49 of file main/endpoints.c.
Referenced by ami_registrations_endpoints(), ami_show_endpoints(), app_to_json(), ast_endpoint_find_by_id(), ast_endpoint_init(), ast_endpoint_shutdown(), ast_sip_get_endpoints(), cli_complete_endpoint(), create_mwi_subscriptions(), endpoint_cleanup(), endpoint_internal_create(), endpoints_scrape_cb(), load_all_endpoints(), load_module(), load_module(), sip_options_aor_observer_modified_task(), stasis_app_to_cli(), and unload_module().
| 
 | static | 
Definition at line 51 of file main/endpoints.c.
Referenced by ast_endpoint_find_by_id(), ast_endpoint_init(), endpoint_cleanup(), and endpoint_internal_create().