41 #define TECH_WILDCARD "__AST_ALL_TECH" 46 #define ENDPOINTS_NUM_BUCKETS 127 81 static void application_tuple_dtor(
void *obj)
92 size_t size =
sizeof(*tuple) + strlen(app_name) + 1;
126 size_t size =
sizeof(*sub) + strlen(token) + 1;
132 strcpy(sub->token, token);
164 const char *right_key = arg;
169 right_key = object_right->token;
172 cmp = strcmp(object_left->token, right_key);
179 cmp = strncmp(object_left->token, right_key, strlen(right_key));
230 || !strncasecmp(sub->token, buf, strlen(sub->token))
231 || !strncasecmp(sub->token, buf, strlen(sub->token))) {
245 ast_debug(1,
"No subscription found for %s\n", buf);
287 "variables", json_vars);
296 ast_debug(3,
"Dispatching message to subscription %s for endpoint %s\n",
302 tuple->
callback(endpoint_name, json_msg, tuple->
pvt);
314 const char *endpoint_name;
327 for (i = 0, j = 0; i <
AST_VECTOR_SIZE(&tech_subscriptions) && j < 2; i++) {
335 || !strncasecmp(sub->token, buf, strlen(sub->token))) {
337 matching_subscriptions[j++] =
sub;
345 matching_subscriptions[j++] =
sub;
349 for (i = 0; i < j; i++) {
350 sub = matching_subscriptions[i];
370 return !strcmp(sub->token, key) ? 1 : 0;
375 return !strcmp(item->
app_name, key) ? 1 : 0;
386 if (tuple && !strcmp(tuple->
app_name, app_name)) {
454 ast_debug(3,
"App '%s' unsubscribed to messages from endpoint '%s'\n", app_name, endpoint ?
ast_endpoint_get_id(endpoint) :
"-- ALL --");
478 ao2_link(endpoint_subscriptions, sub);
532 ao2_ref(endpoint_subscriptions, -1);
544 if (!endpoint_subscriptions) {
549 ao2_ref(endpoint_subscriptions, -1);
554 ao2_ref(endpoint_subscriptions, -1);
560 ao2_ref(endpoint_subscriptions, -1);
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
int ast_msg_handler_unregister(const struct ast_msg_handler *handler)
Unregister a ast_msg_handler.
#define ast_rwlock_rdlock(a)
static void message_subscription_dtor(void *obj)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static int application_tuple_cmp(struct application_tuple *item, const char *key)
const char * ast_msg_get_tech(const struct ast_msg *msg)
Retrieve the technology associated with this message.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
const char * ast_msg_get_endpoint(const struct ast_msg *msg)
Retrieve the endpoint associated with this message.
#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup)
Remove an element from a vector that matches the given comparison.
static int has_destination_cb(const struct ast_msg *msg)
The arg parameter is a search key, but is not an object.
#define ast_rwlock_destroy(rwlock)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
An external processor of received messages.
static int message_subscription_compare_cb(void *obj, void *arg, int flags)
static int handle_msg_cb(struct ast_msg *msg)
static struct message_subscription * message_subscription_alloc(const char *token)
const char * ast_endpoint_get_tech(const struct ast_endpoint *endpoint)
Gets the technology of the given endpoint.
int ast_msg_handler_register(const struct ast_msg_handler *handler)
Register a ast_msg_handler.
message_received_cb callback
int messaging_cleanup(void)
Tidy up the messaging layer.
#define TECH_WILDCARD
Subscription to all technologies.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Storage object for an application.
static struct aco_type item
static struct stasis_rest_handlers applications
REST handler for /api-docs/applications.json.
#define ao2_alloc_options(data_size, destructor_fn, options)
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
struct ast_endpoint * ast_endpoint_find_by_id(const char *id)
Finds the endpoint with the given tech[/resource] id.
Out-of-call text message support.
#define ast_rwlock_unlock(a)
const char * ast_msg_get_body(const struct ast_msg *msg)
Get the body of a message.
int ast_msg_var_iterator_next_received(const struct ast_msg *msg, struct ast_msg_var_iterator *iter, const char **name, const char **value)
Get the next variable name and value that was set on a received message.
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.
static struct ast_json * msg_to_json(struct ast_msg *msg)
void ast_msg_var_iterator_destroy(struct ast_msg_var_iterator *iter)
Destroy a message variable iterator.
const char * ast_endpoint_get_resource(const struct ast_endpoint *endpoint)
Gets the resource name of the given endpoint.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
#define ast_strlen_zero(foo)
const char * ast_msg_get_to(const struct ast_msg *msg)
Retrieve the destination of this message.
#define ast_debug(level,...)
Log a DEBUG message.
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
static struct ao2_container * endpoint_subscriptions
The subscriptions to endpoints.
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
void ast_msg_var_unref_current(struct ast_msg_var_iterator *iter)
Unref a message var from inside an iterator loop.
#define ao2_ref(o, delta)
int(* message_received_cb)(const char *endpoint_id, struct ast_json *json_msg, void *pvt)
Callback handler for when a message is received from the core.
int messaging_init(void)
Initialize the messaging layer.
#define ast_test_suite_event_notify(s, f,...)
static int message_subscription_hash_cb(const void *obj, const int flags)
static struct message_subscription * get_or_create_subscription(struct ast_endpoint *endpoint)
#define ao2_unlink(container, obj)
struct ast_msg_handler ari_msg_handler
const char * ast_msg_get_from(const struct ast_msg *msg)
Retrieve the source of this message.
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ao2_t_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn, tag)
Allocate and initialize a hash container with the desired number of buckets.
A subscription to some endpoint or technology.
Vector container support.
#define ao2_find(container, arg, flags)
static struct application_tuple * application_tuple_alloc(const char *app_name, message_received_cb callback, void *pvt)
static struct message_subscription * get_subscription(struct ast_endpoint *endpoint)
#define ast_rwlock_wrlock(a)
const char * name
Name of the message handler.
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
The arg parameter is an object of the same type.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Structure for rwlock and tracking information.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
static AST_VECTOR(struct message_subscription *)
The subscriptions to technologies.
void messaging_app_unsubscribe_endpoint(const char *app_name, const char *endpoint_id)
Subscribe for messages from a particular endpoint.
Stasis out-of-call text message support.
struct stasis_forward * sub
static void dispatch_message(struct message_subscription *sub, const char *endpoint_name, struct ast_json *json_msg)
static void msg_to_endpoint(const struct ast_msg *msg, char *buf, size_t len)
Abstract JSON element (object, array, string, int, ...).
#define ENDPOINTS_NUM_BUCKETS
Number of buckets for the endpoint_subscriptions container.
Search option field mask.
static int messaging_subscription_cmp(struct message_subscription *sub, const char *key)
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
const char * ast_endpoint_get_id(const struct ast_endpoint *endpoint)
Gets the tech/resource id of the given endpoint.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
static int is_app_subscribed(struct message_subscription *sub, const char *app_name)
#define ao2_link(container, obj)
struct ast_msg_var_iterator * ast_msg_var_iterator_init(const struct ast_msg *msg)
Create a new message variable iterator.