Asterisk - The Open Source Telephony Project
18.5.0
|
#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/mwi.h"
#include "asterisk/stasis_channels.h"
Go to the source code of this file.
Data Structures | |
struct | ast_mwi_publisher |
struct | ast_mwi_subscriber |
struct | mwi_handler_data |
Functions | |
int | ast_delete_mwi_state_full (const char *mailbox, const char *context, struct ast_eid *eid) |
Delete MWI state cached by stasis with all parameters. More... | |
int | ast_mwi_add_observer (struct ast_mwi_observer *observer) |
Add an observer to receive MWI state related events. More... | |
struct ast_mwi_publisher * | ast_mwi_add_publisher (const char *mailbox) |
Add an MWI state publisher to the mailbox. More... | |
struct ast_mwi_subscriber * | ast_mwi_add_subscriber (const char *mailbox) |
Add an MWI state subscriber to the mailbox. More... | |
struct stasis_message * | ast_mwi_blob_create (struct ast_mwi_state *mwi_state, struct stasis_message_type *message_type, struct ast_json *blob) |
Creates a ast_mwi_blob message. More... | |
struct ast_mwi_state * | ast_mwi_create (const char *mailbox, const char *context) |
Create a ast_mwi_state object. More... | |
int | ast_mwi_publish (struct ast_mwi_publisher *pub, int urgent_msgs, int new_msgs, int old_msgs, const char *channel_id, struct ast_eid *eid) |
Publish MWI for the given mailbox. More... | |
int | ast_mwi_publish_by_mailbox (const char *mailbox, const char *context, int urgent_msgs, int new_msgs, int old_msgs, const char *channel_id, struct ast_eid *eid) |
Publish MWI for the given mailbox. More... | |
void | ast_mwi_remove_observer (struct ast_mwi_observer *observer) |
Remove an MWI state observer. More... | |
struct stasis_cache * | ast_mwi_state_cache (void) |
Backend cache for ast_mwi_topic_cached(). More... | |
void | ast_mwi_state_callback_all (on_mwi_state handler, void *data) |
For each managed mailbox call the given handler. More... | |
void | ast_mwi_state_callback_subscribed (on_mwi_state handler, void *data) |
For each managed mailbox that has a subscriber call the given handler. More... | |
struct ast_mwi_subscriber * | ast_mwi_subscribe_pool (const char *mailbox, stasis_subscription_cb callback, void *data) |
Add an MWI state subscriber, and stasis subscription to the mailbox. More... | |
struct ast_mwi_state * | ast_mwi_subscriber_data (struct ast_mwi_subscriber *sub) |
Retrieves the state data object associated with the MWI subscriber. More... | |
struct stasis_subscription * | ast_mwi_subscriber_subscription (struct ast_mwi_subscriber *sub) |
Retrieve the stasis MWI topic subscription if available. More... | |
struct stasis_topic * | ast_mwi_subscriber_topic (struct ast_mwi_subscriber *sub) |
Retrieves the MWI subscriber's topic. More... | |
struct stasis_topic * | ast_mwi_topic (const char *uniqueid) |
Get the Stasis Message Bus API topic for MWI messages on a unique ID. More... | |
struct stasis_topic * | ast_mwi_topic_all (void) |
Get the Stasis Message Bus API topic for MWI messages. More... | |
struct stasis_topic * | ast_mwi_topic_cached (void) |
Get the Stasis Message Bus API caching topic for MWI messages. More... | |
void * | ast_mwi_unsubscribe (struct ast_mwi_subscriber *sub) |
Unsubscribe from the stasis topic and MWI. More... | |
void * | ast_mwi_unsubscribe_and_join (struct ast_mwi_subscriber *sub) |
Unsubscribe from the stasis topic, block until the final message is received, and then unsubscribe from MWI. More... | |
int | ast_publish_mwi_state_full (const char *mailbox, const char *context, int new_msgs, int old_msgs, const char *channel_id, struct ast_eid *eid) |
Publish a MWI state update via stasis with all parameters. More... | |
static int | handle_mwi_state (const char *id, struct stasis_message *msg, void *user_data) |
static void | mwi_blob_dtor (void *obj) |
static void | mwi_cleanup (void) |
static struct ast_mwi_state * | mwi_create_state (const char *mailbox, const char *context, int urgent_msgs, int new_msgs, int old_msgs) |
int | mwi_init (void) |
Initialize the mwi core. More... | |
static struct ast_mwi_state * | mwi_retrieve_then_create_state (const char *mailbox) |
static struct stasis_message * | mwi_state_create_message (const char *mailbox, const char *context, int urgent_msgs, int new_msgs, int old_msgs, const char *channel_id, struct ast_eid *eid) |
static void | mwi_state_dtor (void *obj) |
static const char * | mwi_state_get_id (struct stasis_message *message) |
static struct ast_event * | mwi_to_event (struct stasis_message *message) |
Convert a MWI stasis_message to a ast_event. More... | |
STASIS_MESSAGE_TYPE_DEFN (ast_mwi_state_type,.to_event=mwi_to_event,) | |
STASIS_MESSAGE_TYPE_DEFN (ast_mwi_vm_app_type) | |
Variables | |
static struct stasis_cache * | mwi_state_cache |
static struct stasis_state_manager * | mwi_state_manager |
static struct stasis_caching_topic * | mwi_topic_cached |
int ast_delete_mwi_state_full | ( | const char * | mailbox, |
const char * | context, | ||
struct ast_eid * | eid | ||
) |
Delete MWI state cached by stasis with all parameters.
[in] | mailbox | The mailbox identifier string. |
[in] | context | The context this mailbox resides in (NULL or "" if only using mailbox) |
[in] | eid | The EID of the server that originally published the message |
0 | Success |
-1 | Failure |
Definition at line 399 of file mwi.c.
References ao2_cleanup, ast_eid_default, ast_mwi_state_cache(), ast_mwi_state_type(), mwi_state_create_message(), NULL, RAII_VAR, stasis_cache_clear_create(), stasis_cache_get_by_eid(), stasis_message_data(), stasis_state_remove_publish_by_id(), and ast_mwi_state::uniqueid.
Referenced by free_user_final(), and mwi_handle_unsubscribe2().
int ast_mwi_add_observer | ( | struct ast_mwi_observer * | observer | ) |
Add an observer to receive MWI state related events.
observer | The observer handling events |
0 | if successfully registered, -1 otherwise |
Definition at line 296 of file mwi.c.
References stasis_state_add_observer().
Referenced by start_poll_thread(), and subscriptions_create().
struct ast_mwi_publisher* ast_mwi_add_publisher | ( | const char * | mailbox | ) |
Add an MWI state publisher to the mailbox.
Adding a publisher to a mailbox will create a stasis topic for the mailbox if one does not already exist. A publisher can be removed by releasing its reference. Doing so releases its underlying reference to the MWI state.
mailbox | The mailbox id to publish to |
An | MWI publisher object |
NULl | on error |
Definition at line 290 of file mwi.c.
References stasis_state_add_publisher().
Referenced by publishers_create().
struct ast_mwi_subscriber* ast_mwi_add_subscriber | ( | const char * | mailbox | ) |
Add an MWI state subscriber to the mailbox.
Adding a subscriber to a mailbox will create a stasis topic for the mailbox if one does not already exist. It does not however subscribe to the topic itself. This is done separately using a call to stasis_subscribe or stasis_subscribe_pool.
A subscriber can be removed by releasing its reference. Doing so releases its underlying reference to the MWI state. It does not unsubscribe from the topic. Unsubscribing from a topic should be done prior to unsubscribing the state.
mailbox | The subscription state mailbox id |
An | MWI subscriber object |
NULL | on error |
Definition at line 224 of file mwi.c.
References stasis_state_add_subscriber().
int ast_mwi_publish | ( | struct ast_mwi_publisher * | publisher, |
int | urgent_msgs, | ||
int | new_msgs, | ||
int | old_msgs, | ||
const char * | channel_id, | ||
struct ast_eid * | eid | ||
) |
Publish MWI for the given mailbox.
publisher | The publisher to publish a mailbox update on |
urgent_msgs | The number of urgent messages in this mailbox |
new_msgs | The number of new messages in this mailbox |
old_msgs | The number of old messages in this mailbox |
channel_id | A unique identifier for a channel associated with this change in mailbox state |
eid | The EID of the server that originally published the message |
0 | on success |
-1 | on failure |
Definition at line 353 of file mwi.c.
References ao2_ref, mwi_state_create_message(), NULL, stasis_state_publish(), and stasis_state_publisher_id().
Referenced by explicit_publish_cb().
int ast_mwi_publish_by_mailbox | ( | const char * | mailbox, |
const char * | context, | ||
int | urgent_msgs, | ||
int | new_msgs, | ||
int | old_msgs, | ||
const char * | channel_id, | ||
struct ast_eid * | eid | ||
) |
Publish MWI for the given mailbox.
mailbox | The mailbox identifier string. |
context | The context this mailbox resides in (NULL or "" if only using mailbox) |
urgent_msgs | The number of urgent messages in this mailbox |
new_msgs | The number of new messages in this mailbox |
old_msgs | The number of old messages in this mailbox |
channel_id | A unique identifier for a channel associated with this change in mailbox state |
eid | The EID of the server that originally published the message |
0 | on success |
-1 | on failure |
Definition at line 370 of file mwi.c.
References ao2_ref, mwi_state_create_message(), NULL, stasis_message_data(), stasis_state_publish_by_id(), and ast_mwi_state::uniqueid.
Referenced by ast_publish_mwi_state_full(), and implicit_publish_cb().
void ast_mwi_remove_observer | ( | struct ast_mwi_observer * | observer | ) |
Remove an MWI state observer.
observer | The observer being removed |
Definition at line 302 of file mwi.c.
References stasis_state_remove_observer().
Referenced by stop_poll_thread(), and subscriptions_destroy().
void ast_mwi_state_callback_all | ( | on_mwi_state | handler, |
void * | data | ||
) |
For each managed mailbox call the given handler.
handler | The mwi state handler to call for each managed mailbox |
data | User to data to pass on to the handler |
Definition at line 333 of file mwi.c.
References handle_mwi_state(), handler(), mwi_handler_data::handler, and stasis_state_callback_all().
Referenced by actual_load_config(), manager_voicemail_refresh(), publish(), and unload_module().
void ast_mwi_state_callback_subscribed | ( | on_mwi_state | handler, |
void * | data | ||
) |
For each managed mailbox that has a subscriber call the given handler.
handler | The mwi state handler to call for each managed mailbox |
data | User to data to pass on to the handler |
Definition at line 343 of file mwi.c.
References handle_mwi_state(), handler(), mwi_handler_data::handler, and stasis_state_callback_subscribed().
Referenced by mb_poll_thread().
struct ast_mwi_subscriber* ast_mwi_subscribe_pool | ( | const char * | mailbox, |
stasis_subscription_cb | callback, | ||
void * | data | ||
) |
Add an MWI state subscriber, and stasis subscription to the mailbox.
Adding a subscriber to a mailbox will create a stasis topic for the mailbox if one does not already exist. Once successfully create the underlying stasis topic is then subscribed to as well.
A subscriber can be removed by releasing its reference. Doing so releases its underlying reference to the MWI state. It does not unsubscribe from the topic. Unsubscribing from a topic should be done prior to unsubscribing the state.
mailbox | The subscription state mailbox id |
callback | The stasis subscription callback |
data | A user data object passed to the stasis subscription |
An | MWI subscriber object |
NULL | on error |
Definition at line 230 of file mwi.c.
References ast_mwi_state_type(), ast_mwi_subscriber_subscription(), NULL, stasis_state_subscribe_pool(), stasis_subscription_accept_message_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), and sub.
Referenced by add_peer_mwi_subs(), build_gateway(), build_peer(), config_line(), mkintf(), mwi_stasis_subscription_alloc(), and subscriptions_create().
struct ast_mwi_state* ast_mwi_subscriber_data | ( | struct ast_mwi_subscriber * | sub | ) |
Retrieves the state data object associated with the MWI subscriber.
sub | An MWI subscriber |
The | state data object |
Definition at line 264 of file mwi.c.
References mwi_retrieve_then_create_state(), stasis_state_subscriber_data(), and stasis_state_subscriber_id().
Referenced by get_message_count(), handle_validate(), mwi_handle_subscribe(), and mwi_handle_unsubscribe().
struct stasis_subscription* ast_mwi_subscriber_subscription | ( | struct ast_mwi_subscriber * | sub | ) |
Retrieve the stasis MWI topic subscription if available.
sub | An MWI subscriber |
The | subscriber's stasis subscription |
NULL | if no subscription available |
Definition at line 272 of file mwi.c.
References stasis_state_subscriber_subscription().
Referenced by add_peer_mwi_subs(), ast_mwi_subscribe_pool(), and mwi_stasis_subscription_alloc().
struct stasis_topic* ast_mwi_subscriber_topic | ( | struct ast_mwi_subscriber * | sub | ) |
Retrieves the MWI subscriber's topic.
sub | An MWI subscriber |
A | stasis topic subscribed to by the subscriber |
Definition at line 259 of file mwi.c.
References stasis_state_subscriber_topic().
void* ast_mwi_unsubscribe | ( | struct ast_mwi_subscriber * | sub | ) |
Unsubscribe from the stasis topic and MWI.
sub | An MWI subscriber |
NULL |
Definition at line 249 of file mwi.c.
References stasis_state_unsubscribe().
Referenced by destroy_dahdi_pvt(), destroy_endpoint(), peer_destructor(), and skinny_reload().
void* ast_mwi_unsubscribe_and_join | ( | struct ast_mwi_subscriber * | sub | ) |
Unsubscribe from the stasis topic, block until the final message is received, and then unsubscribe from MWI.
sub | An MWI subscriber |
NULL |
Definition at line 254 of file mwi.c.
References stasis_state_unsubscribe_and_join().
Referenced by destroy_mailbox(), subscriptions_destroy(), unload_module(), and unsubscribe_stasis().
int ast_publish_mwi_state_full | ( | const char * | mailbox, |
const char * | context, | ||
int | new_msgs, | ||
int | old_msgs, | ||
const char * | channel_id, | ||
struct ast_eid * | eid | ||
) |
Publish a MWI state update via stasis with all parameters.
[in] | mailbox | The mailbox identifier string. |
[in] | context | The context this mailbox resides in (NULL or "" if only using mailbox) |
[in] | new_msgs | The number of new messages in this mailbox |
[in] | old_msgs | The number of old messages in this mailbox |
[in] | channel_id | A unique identifier for a channel associated with this change in mailbox state |
[in] | eid | The EID of the server that originally published the message |
0 | Success |
-1 | Failure |
Definition at line 388 of file mwi.c.
References ast_mwi_publish_by_mailbox().
Referenced by asterisk_publication_mailboxstate(), publish_mwi_to_stasis(), and xmpp_pubsub_handle_event().
|
static |
Definition at line 313 of file mwi.c.
References ao2_ref, d, mwi_handler_data::data, mwi_handler_data::handler, mwi_create_state(), NULL, and stasis_message_data().
Referenced by ast_mwi_state_callback_all(), and ast_mwi_state_callback_subscribed().
|
static |
Definition at line 454 of file mwi.c.
References ao2_cleanup, ast_json_unref(), ast_mwi_blob::blob, and ast_mwi_blob::mwi_state.
Referenced by ast_mwi_blob_create().
|
static |
Definition at line 491 of file mwi.c.
References ao2_cleanup, ast_mwi_state_type(), ast_mwi_vm_app_type(), NULL, stasis_caching_unsubscribe_and_join(), and STASIS_MESSAGE_TYPE_CLEANUP.
Referenced by mwi_init().
|
static |
Definition at line 105 of file mwi.c.
References ao2_alloc, ao2_ref, ast_assert, ast_log, ast_string_field_build, ast_string_field_init, ast_string_field_set, ast_strlen_zero, LOG_ERROR, mwi_state_dtor(), ast_mwi_state::new_msgs, NULL, ast_mwi_state::old_msgs, ast_mwi_state::uniqueid, and ast_mwi_state::urgent_msgs.
Referenced by ast_mwi_create(), handle_mwi_state(), mwi_retrieve_then_create_state(), and mwi_state_create_message().
|
static |
Definition at line 138 of file mwi.c.
References ast_app_inboxcount2(), mwi_create_state(), ast_mwi_state::new_msgs, NULL, ast_mwi_state::old_msgs, and ast_mwi_state::urgent_msgs.
Referenced by ast_mwi_subscriber_data().
|
static |
Definition at line 169 of file mwi.c.
References ao2_cleanup, ast_channel_snapshot_get_latest(), ast_eid_default, ast_mwi_state_type(), ast_strlen_zero, stasis_message::eid, ast_mwi_state::eid, mwi_create_state(), NULL, ast_mwi_state::snapshot, and stasis_message_create_full().
Referenced by ast_delete_mwi_state_full(), ast_mwi_publish(), and ast_mwi_publish_by_mailbox().
|
static |
Definition at line 77 of file mwi.c.
References ao2_cleanup, ast_string_field_free_memory, NULL, and ast_mwi_state::snapshot.
Referenced by mwi_create_state().
|
static |
Definition at line 441 of file mwi.c.
References ast_mwi_state_type(), NULL, stasis_message_data(), stasis_message_type(), stasis_subscription_change_type(), ast_mwi_state::uniqueid, and stasis_subscription_change::uniqueid.
Referenced by mwi_init().
|
static |
Convert a MWI stasis_message to a ast_event.
Definition at line 38 of file mwi.c.
References AST_EVENT_IE_CONTEXT, AST_EVENT_IE_EID, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_MWI, ast_event_new(), ast_mwi_state_type(), ast_mwi_vm_app_type(), ast_strdupa, ast_strlen_zero, context, ast_mwi_state::eid, mailbox, ast_mwi_state::new_msgs, NULL, ast_mwi_state::old_msgs, stasis_message_data(), STASIS_MESSAGE_TYPE_DEFN(), strsep(), and ast_mwi_state::uniqueid.
STASIS_MESSAGE_TYPE_DEFN | ( | ast_mwi_state_type | , |
. | to_event = mwi_to_event |
||
) |
Referenced by mwi_to_event().
STASIS_MESSAGE_TYPE_DEFN | ( | ast_mwi_vm_app_type | ) |
|
static |
Definition at line 33 of file mwi.c.
Referenced by ast_mwi_state_cache().
|
static |
|
static |