| Asterisk - The Open Source Telephony Project GIT-master-27fb039
    | 
#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. | |
| int | ast_mwi_add_observer (struct ast_mwi_observer *observer) | 
| Add an observer to receive MWI state related events. | |
| struct ast_mwi_publisher * | ast_mwi_add_publisher (const char *mailbox) | 
| Add an MWI state publisher to the mailbox. | |
| struct ast_mwi_subscriber * | ast_mwi_add_subscriber (const char *mailbox) | 
| Add an MWI state subscriber to the mailbox. | |
| 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. | |
| struct ast_mwi_state * | ast_mwi_create (const char *mailbox, const char *context) | 
| Create a ast_mwi_state object. | |
| 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. | |
| 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. | |
| void | ast_mwi_remove_observer (struct ast_mwi_observer *observer) | 
| Remove an MWI state observer. | |
| struct stasis_cache * | ast_mwi_state_cache (void) | 
| Backend cache for ast_mwi_topic_cached(). | |
| void | ast_mwi_state_callback_all (on_mwi_state handler, void *data) | 
| For each managed mailbox call the given handler. | |
| void | ast_mwi_state_callback_subscribed (on_mwi_state handler, void *data) | 
| For each managed mailbox that has a subscriber call the given handler. | |
| 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. | |
| struct ast_mwi_state * | ast_mwi_subscriber_data (struct ast_mwi_subscriber *sub) | 
| Retrieves the state data object associated with the MWI subscriber. | |
| struct stasis_subscription * | ast_mwi_subscriber_subscription (struct ast_mwi_subscriber *sub) | 
| Retrieve the stasis MWI topic subscription if available. | |
| struct stasis_topic * | ast_mwi_subscriber_topic (struct ast_mwi_subscriber *sub) | 
| Retrieves the MWI subscriber's topic. | |
| struct stasis_topic * | ast_mwi_topic (const char *uniqueid) | 
| Get the Stasis Message Bus API topic for MWI messages on a unique ID. | |
| struct stasis_topic * | ast_mwi_topic_all (void) | 
| Get the Stasis Message Bus API topic for MWI messages. | |
| struct stasis_topic * | ast_mwi_topic_cached (void) | 
| Get the Stasis Message Bus API caching topic for MWI messages. | |
| void * | ast_mwi_unsubscribe (struct ast_mwi_subscriber *sub) | 
| Unsubscribe from the stasis topic and MWI. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| STASIS_MESSAGE_TYPE_DEFN (ast_mwi_state_type,.to_event=mwi_to_event,) | |
| Define Stasis Message Bus API message types for MWI. | |
| 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 | 
| Define Stasis Message Bus API topic objects. | |
| 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 404 of file mwi.c.
References ao2_cleanup, ast_eid_default, ast_mwi_state_cache(), ast_mwi_state_type(), ast_mwi_state::eid, mwi_state_create_message(), mwi_state_manager, 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 301 of file mwi.c.
References mwi_state_manager, observer, and 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 | 
| NULl | on error | 
Definition at line 295 of file mwi.c.
References mwi_state_manager, and 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 | 
| NULL | on error | 
Definition at line 229 of file mwi.c.
References mwi_state_manager, and stasis_state_add_subscriber().
| 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.
The blob JSON object requires a "type" field describing the blob. It should also be treated as immutable and not modified after it is put into the message.
| mwi_state | MWI state associated with the update | 
| message_type | The type of message to create | 
| blob | JSON object representing the data. | 
| NULL | on error | 
Definition at line 467 of file mwi.c.
References ao2_alloc, ao2_ref, ast_assert, ast_json_ref(), ast_mwi_blob::blob, mwi_blob_dtor(), ast_mwi_blob::mwi_state, NULL, and stasis_message_create().
Referenced by notify_new_message().
| struct ast_mwi_state * ast_mwi_create | ( | const char * | mailbox, | 
| const char * | context | ||
| ) | 
Create a ast_mwi_state object.
| [in] | mailbox | The mailbox identifier string. | 
| [in] | context | The context this mailbox resides in (NULL or "" if only using mailbox) | 
| NULL | on error | 
Definition at line 152 of file mwi.c.
References mwi_create_state().
Referenced by notify_new_message().
| 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 358 of file mwi.c.
References ao2_ref, stasis_message::eid, 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 375 of file mwi.c.
References ao2_ref, stasis_message::eid, mwi_state_create_message(), mwi_state_manager, 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 307 of file mwi.c.
References mwi_state_manager, observer, and stasis_state_remove_observer().
Referenced by stop_poll_thread(), and subscriptions_destroy().
| struct stasis_cache * ast_mwi_state_cache | ( | void | ) | 
Backend cache for ast_mwi_topic_cached().
Definition at line 94 of file mwi.c.
References mwi_state_cache.
Referenced by ast_delete_mwi_state_full(), asterisk_publication_mwi_refresh(), asterisk_start_mwi_publishing(), has_voicemail(), load_module(), unistim_send_mwi_to_peer(), and update_registry().
| 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 338 of file mwi.c.
References d, mwi_handler_data::data, handle_mwi_state(), handler(), mwi_state_manager, 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 348 of file mwi.c.
References d, mwi_handler_data::data, handle_mwi_state(), handler(), mwi_state_manager, 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 | 
| NULL | on error | 
Definition at line 235 of file mwi.c.
References ast_mwi_state_type(), ast_mwi_subscriber_subscription(), callback(), mwi_state_manager, NULL, stasis_state_subscribe_pool(), stasis_subscription_accept_message_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), and sub.
Referenced by build_peer(), 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 | 
Definition at line 269 of file mwi.c.
References mwi_retrieve_then_create_state(), stasis_state_subscriber_data(), stasis_state_subscriber_id(), and sub.
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 | 
| NULL | if no subscription available | 
Definition at line 277 of file mwi.c.
References stasis_state_subscriber_subscription(), and sub.
Referenced by 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 | 
Definition at line 264 of file mwi.c.
References stasis_state_subscriber_topic(), and sub.
| struct stasis_topic * ast_mwi_topic | ( | const char * | uniqueid | ) | 
Get the Stasis Message Bus API topic for MWI messages on a unique ID.
| uniqueid | The unique id for which to get the topic | 
| NULL | if it failed to be found or allocated | 
Definition at line 104 of file mwi.c.
References mwi_state_manager, and stasis_state_topic().
Referenced by notify_new_message().
| struct stasis_topic * ast_mwi_topic_all | ( | void | ) | 
Get the Stasis Message Bus API topic for MWI messages.
| NULL | if it has not been allocated | 
Definition at line 89 of file mwi.c.
References mwi_state_manager, and stasis_state_all_topic().
Referenced by asterisk_start_mwi_publishing(), load_module(), manager_mwi_init(), mwi_init(), and xmpp_init_event_distribution().
| struct stasis_topic * ast_mwi_topic_cached | ( | void | ) | 
Get the Stasis Message Bus API caching topic for MWI messages.
| NULL | if it has not been allocated | 
Definition at line 99 of file mwi.c.
References mwi_topic_cached, and stasis_caching_get_topic().
| void * ast_mwi_unsubscribe | ( | struct ast_mwi_subscriber * | sub | ) | 
Unsubscribe from the stasis topic and MWI.
| sub | An MWI subscriber | 
Definition at line 254 of file mwi.c.
References stasis_state_unsubscribe(), and sub.
Referenced by destroy_dahdi_pvt(), and peer_destructor().
| 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 | 
Definition at line 259 of file mwi.c.
References stasis_state_unsubscribe_and_join(), and sub.
Referenced by subscriptions_destroy(), 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 393 of file mwi.c.
References ast_mwi_publish_by_mailbox(), and stasis_message::eid.
Referenced by asterisk_publication_mailboxstate(), publish_mwi_to_stasis(), and xmpp_pubsub_handle_event().
| 
 | static | 
Definition at line 318 of file mwi.c.
References ao2_ref, d, 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 459 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 496 of file mwi.c.
References ao2_cleanup, ast_mwi_state_type(), ast_mwi_vm_app_type(), mwi_state_cache, mwi_state_manager, mwi_topic_cached, NULL, stasis_caching_unsubscribe_and_join(), and STASIS_MESSAGE_TYPE_CLEANUP.
Referenced by mwi_init().
| 
 | static | 
Definition at line 109 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().
| int mwi_init | ( | void | ) | 
Initialize the mwi core.
| 0 | Success | 
| -1 | Failure | 
Definition at line 507 of file mwi.c.
References ast_mwi_state_type(), ast_mwi_topic_all(), ast_mwi_vm_app_type(), ast_register_cleanup(), mwi_cleanup(), mwi_state_cache, mwi_state_get_id(), mwi_state_manager, mwi_topic_cached, stasis_cache_create(), stasis_caching_topic_create(), STASIS_MESSAGE_TYPE_INIT, and stasis_state_manager_create().
Referenced by asterisk_daemon().
| 
 | static | 
Definition at line 142 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 174 of file mwi.c.
References ao2_cleanup, ast_channel_snapshot_get_latest(), ast_eid_default, ast_mwi_state_type(), ast_strlen_zero(), ast_mwi_state::eid, stasis_message::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 81 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 446 of file mwi.c.
References ast_mwi_state_type(), NULL, stasis_message_data(), 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 40 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_strdupa, ast_strlen_zero(), ast_mwi_state::eid, ast_mwi_state::new_msgs, NULL, ast_mwi_state::old_msgs, stasis_message_data(), strsep(), and ast_mwi_state::uniqueid.
| STASIS_MESSAGE_TYPE_DEFN | ( | ast_mwi_state_type | , | 
| . | to_event = mwi_to_event | ||
| ) | 
Define Stasis Message Bus API message types for MWI.
| STASIS_MESSAGE_TYPE_DEFN | ( | ast_mwi_vm_app_type | ) | 
| 
 | static | 
Definition at line 34 of file mwi.c.
Referenced by ast_mwi_state_cache(), mwi_cleanup(), and mwi_init().
| 
 | static | 
Define Stasis Message Bus API topic objects.
Definition at line 33 of file mwi.c.
Referenced by ast_delete_mwi_state_full(), ast_mwi_add_observer(), ast_mwi_add_publisher(), ast_mwi_add_subscriber(), ast_mwi_publish_by_mailbox(), ast_mwi_remove_observer(), ast_mwi_state_callback_all(), ast_mwi_state_callback_subscribed(), ast_mwi_subscribe_pool(), ast_mwi_topic(), ast_mwi_topic_all(), mwi_cleanup(), and mwi_init().
| 
 | static | 
Definition at line 35 of file mwi.c.
Referenced by ast_mwi_topic_cached(), mwi_cleanup(), and mwi_init().