Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Stasis out-of-call text message support. More...
#include "asterisk.h"
#include "asterisk/message.h"
#include "asterisk/endpoints.h"
#include "asterisk/astobj2.h"
#include "asterisk/vector.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/test.h"
#include "messaging.h"
Go to the source code of this file.
Data Structures | |
struct | application_tuple |
Storage object for an application. More... | |
struct | message_subscription |
A subscription to some endpoint or technology. More... | |
Macros | |
#define | ENDPOINTS_NUM_BUCKETS 127 |
Number of buckets for the endpoint_subscriptions container. More... | |
#define | TECH_WILDCARD "__AST_ALL_TECH" |
Subscription to all technologies. More... | |
Functions | |
static struct application_tuple * | application_tuple_alloc (const char *app_name, message_received_cb callback, void *pvt) |
static int | application_tuple_cmp (struct application_tuple *item, const char *key) |
static void | application_tuple_dtor (void *obj) |
static void | dispatch_message (struct message_subscription *sub, const char *endpoint_name, struct ast_json *json_msg) |
static struct message_subscription * | get_or_create_subscription (struct ast_endpoint *endpoint) |
static struct message_subscription * | get_subscription (struct ast_endpoint *endpoint) |
static int | handle_msg_cb (struct ast_msg *msg) |
static int | has_destination_cb (const struct ast_msg *msg) |
static int | is_app_subscribed (struct message_subscription *sub, const char *app_name) |
static struct message_subscription * | message_subscription_alloc (const char *token) |
static int | message_subscription_compare_cb (void *obj, void *arg, int flags) |
static void | message_subscription_dtor (void *obj) |
static int | message_subscription_hash_cb (const void *obj, const int flags) |
int | messaging_app_subscribe_endpoint (const char *app_name, struct ast_endpoint *endpoint, message_received_cb callback, void *pvt) |
Subscribe an application to an endpoint for messages. More... | |
void | messaging_app_unsubscribe_endpoint (const char *app_name, const char *endpoint_id) |
Subscribe for messages from a particular endpoint. More... | |
int | messaging_cleanup (void) |
Tidy up the messaging layer. More... | |
int | messaging_init (void) |
Initialize the messaging layer. More... | |
static int | messaging_subscription_cmp (struct message_subscription *sub, const char *key) |
static void | msg_to_endpoint (const struct ast_msg *msg, char *buf, size_t len) |
static struct ast_json * | msg_to_json (struct ast_msg *msg) |
Variables | |
struct ast_msg_handler | ari_msg_handler |
static struct ao2_container * | endpoint_subscriptions |
The subscriptions to endpoints. More... | |
struct { | |
size_t current | |
struct message_subscription ** elems | |
size_t max | |
} | tech_subscriptions |
The subscriptions to technologies. More... | |
static ast_rwlock_t | tech_subscriptions_lock |
RWLock for tech_subscriptions . More... | |
Stasis out-of-call text message support.
Definition in file messaging.c.
#define ENDPOINTS_NUM_BUCKETS 127 |
Number of buckets for the endpoint_subscriptions container.
Definition at line 46 of file messaging.c.
#define TECH_WILDCARD "__AST_ALL_TECH" |
Subscription to all technologies.
Definition at line 41 of file messaging.c.
|
static |
Definition at line 89 of file messaging.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, app_name(), application_tuple::app_name, application_tuple_dtor(), ast_assert, application_tuple::callback, NULL, and application_tuple::pvt.
Referenced by messaging_app_subscribe_endpoint().
|
static |
Definition at line 373 of file messaging.c.
References item.
Referenced by messaging_app_unsubscribe_endpoint().
|
static |
Definition at line 81 of file messaging.c.
References ao2_cleanup, and application_tuple::pvt.
Referenced by application_tuple_alloc().
|
static |
Definition at line 292 of file messaging.c.
References ast_debug, AST_VECTOR_GET, AST_VECTOR_SIZE, application_tuple::callback, application_tuple::pvt, and sub.
Referenced by handle_msg_cb().
|
static |
Definition at line 459 of file messaging.c.
References ao2_link, ao2_ref, ast_endpoint_get_id(), ast_endpoint_get_resource(), ast_rwlock_unlock, ast_rwlock_wrlock, ast_strlen_zero(), AST_VECTOR_APPEND, endpoint_subscriptions, get_subscription(), message_subscription_alloc(), NULL, sub, tech_subscriptions, tech_subscriptions_lock, and TECH_WILDCARD.
Referenced by messaging_app_subscribe_endpoint().
|
static |
Definition at line 394 of file messaging.c.
References ao2_bump, ao2_find, ast_endpoint_get_id(), ast_endpoint_get_resource(), ast_endpoint_get_tech(), ast_rwlock_rdlock, ast_rwlock_unlock, ast_strlen_zero(), AST_VECTOR_GET, AST_VECTOR_SIZE, endpoint_subscriptions, NULL, OBJ_SEARCH_KEY, sub, tech_subscriptions, tech_subscriptions_lock, and TECH_WILDCARD.
Referenced by get_or_create_subscription(), and messaging_app_unsubscribe_endpoint().
|
static |
Definition at line 306 of file messaging.c.
References ao2_find, ao2_ref, ast_json_unref(), ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, buf, dispatch_message(), endpoint_subscriptions, msg_to_endpoint(), msg_to_json(), OBJ_SEARCH_KEY, result, sub, tech_subscriptions, tech_subscriptions_lock, and TECH_WILDCARD.
|
static |
Definition at line 213 of file messaging.c.
References ao2_find, ao2_ref, ast_debug, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, buf, endpoint_subscriptions, match(), msg_to_endpoint(), OBJ_SEARCH_KEY, sub, tech_subscriptions, tech_subscriptions_lock, and TECH_WILDCARD.
|
static |
Definition at line 378 of file messaging.c.
References app_name(), application_tuple::app_name, AST_VECTOR_GET, AST_VECTOR_SIZE, and sub.
Referenced by messaging_app_subscribe_endpoint(), and messaging_app_unsubscribe_endpoint().
|
static |
Definition at line 123 of file messaging.c.
References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_alloc_options, message_subscription_dtor(), NULL, sub, and message_subscription::token.
Referenced by get_or_create_subscription().
|
static |
AO2 comparison function for message_subscription
Definition at line 160 of file messaging.c.
References CMP_MATCH, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, OBJ_SEARCH_PARTIAL_KEY, and message_subscription::token.
Referenced by messaging_init().
|
static |
Definition at line 109 of file messaging.c.
References ao2_cleanup, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, and sub.
Referenced by message_subscription_alloc().
|
static |
AO2 hash function for message_subscription
Definition at line 138 of file messaging.c.
References ast_assert, ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and sub.
Referenced by messaging_init().
int messaging_app_subscribe_endpoint | ( | const char * | app_name, |
struct ast_endpoint * | endpoint, | ||
message_received_cb | callback, | ||
void * | pvt | ||
) |
Subscribe an application to an endpoint for messages.
app_name | The name of the Stasis Message Bus API application to subscribe to endpoint |
endpoint | The endpoint object to subscribe to |
callback | The callback to call when a message is received |
pvt | An ao2 ref counted object that will be passed to the callback. |
0 | subscription was successful |
-1 | subscription failed |
Definition at line 493 of file messaging.c.
References ao2_cleanup, ao2_lock, ao2_ref, ao2_unlock, app_name(), application_tuple_alloc(), ast_debug, ast_endpoint_get_id(), ast_test_suite_event_notify, AST_VECTOR_APPEND, application_tuple::callback, get_or_create_subscription(), is_app_subscribed(), NULL, application_tuple::pvt, RAII_VAR, and sub.
Referenced by app_subscribe_endpoint().
void messaging_app_unsubscribe_endpoint | ( | const char * | app_name, |
const char * | endpoint_id | ||
) |
Subscribe for messages from a particular endpoint.
app_name | Name of the stasis application to unsubscribe from messaging |
endpoint_id | The ID of the endpoint we no longer care about |
Definition at line 423 of file messaging.c.
References ao2_cleanup, ao2_lock, ao2_ref, ao2_unlink, ao2_unlock, app_name(), application_tuple_cmp(), ast_debug, ast_endpoint_find_by_id(), ast_endpoint_get_id(), ast_endpoint_get_resource(), ast_rwlock_unlock, ast_rwlock_wrlock, ast_strlen_zero(), ast_test_suite_event_notify, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_CMP_UNORDERED, AST_VECTOR_SIZE, endpoint_subscriptions, get_subscription(), is_app_subscribed(), messaging_subscription_cmp(), NULL, RAII_VAR, sub, tech_subscriptions, tech_subscriptions_lock, and TECH_WILDCARD.
Referenced by unsubscribe().
int messaging_cleanup | ( | void | ) |
Tidy up the messaging layer.
0 | success |
-1 | failure |
Definition at line 529 of file messaging.c.
References ao2_ref, ari_msg_handler, ast_msg_handler_unregister(), ast_rwlock_destroy, AST_VECTOR_FREE, endpoint_subscriptions, tech_subscriptions, and tech_subscriptions_lock.
Referenced by unload_module().
int messaging_init | ( | void | ) |
Initialize the messaging layer.
0 | success |
-1 | failure |
Definition at line 539 of file messaging.c.
References AO2_ALLOC_OPT_LOCK_RWLOCK, ao2_ref, ao2_t_container_alloc_hash, ari_msg_handler, ast_msg_handler_register(), ast_rwlock_destroy, ast_rwlock_init, AST_VECTOR_FREE, AST_VECTOR_INIT, endpoint_subscriptions, ENDPOINTS_NUM_BUCKETS, message_subscription_compare_cb(), message_subscription_hash_cb(), NULL, tech_subscriptions, and tech_subscriptions_lock.
Referenced by load_module().
|
static |
Definition at line 368 of file messaging.c.
References sub.
Referenced by messaging_app_unsubscribe_endpoint().
|
static |
Definition at line 200 of file messaging.c.
References ast_msg_get_endpoint(), ast_msg_get_tech(), ast_strlen_zero(), buf, len(), and S_OR.
Referenced by handle_msg_cb(), and has_destination_cb().
Definition at line 252 of file messaging.c.
References ast_json_object_create(), ast_json_object_set(), ast_json_pack(), ast_json_string_create(), ast_json_unref(), ast_msg_get_body(), ast_msg_get_from(), ast_msg_get_to(), ast_msg_var_iterator_destroy(), ast_msg_var_iterator_init(), ast_msg_var_iterator_next_received(), ast_msg_var_unref_current(), name, NULL, and value.
Referenced by handle_msg_cb().
struct ast_msg_handler ari_msg_handler |
Definition at line 362 of file messaging.c.
Referenced by messaging_cleanup(), and messaging_init().
size_t current |
Definition at line 75 of file messaging.c.
struct message_subscription* * elems |
Definition at line 75 of file messaging.c.
|
static |
The subscriptions to endpoints.
Definition at line 67 of file messaging.c.
Referenced by get_or_create_subscription(), get_subscription(), handle_msg_cb(), has_destination_cb(), messaging_app_unsubscribe_endpoint(), messaging_cleanup(), and messaging_init().
size_t max |
Definition at line 75 of file messaging.c.
struct { ... } tech_subscriptions |
The subscriptions to technologies.
Referenced by get_or_create_subscription(), get_subscription(), handle_msg_cb(), has_destination_cb(), messaging_app_unsubscribe_endpoint(), messaging_cleanup(), and messaging_init().
|
static |
RWLock for tech_subscriptions
.
Definition at line 78 of file messaging.c.
Referenced by get_or_create_subscription(), get_subscription(), handle_msg_cb(), has_destination_cb(), messaging_app_unsubscribe_endpoint(), messaging_cleanup(), and messaging_init().