32 #include <pjsip_simple.h> 118 unsigned int device_state;
145 .
type =
"asterisk-devicestate-publisher",
163 .
type =
"asterisk-mwi-publisher",
182 .
type =
"application",
203 "{ s: s, s: s, s: s, s: i, s:s }",
204 "type",
"devicestate",
205 "device", dev_state->
device,
241 .
type =
"application",
262 "{ s: s, s: s, s: i, s: i, s:s }",
263 "type",
"mailboxstate",
311 if ((res = regcomp(regex, text, REG_EXTENDED | REG_ICASE | REG_NOSUB))) {
312 size_t len = regerror(res, regex,
NULL, 0);
314 regerror(res, regex, buf, len);
331 "asterisk-devicestate-publisher");
337 if (!publisher_state) {
340 datastore->data = publisher_state;
384 publisher_state = datastore->data;
415 if (!publisher_state) {
418 datastore->data = publisher_state;
462 publisher_state = datastore->data;
500 ast_debug(2,
"Received device state event for resource '%s' but it is not configured to accept them\n",
506 ast_debug(1,
"Received incomplete device state event for resource '%s'\n",
512 ast_debug(2,
"Received device state on resource '%s' for device '%s' but it has been filtered out\n",
534 ast_debug(2,
"Received mailbox state event for resource '%s' but it is not configured to accept them\n",
540 ast_debug(1,
"Received incomplete mailbox state event for resource '%s'\n",
546 ast_debug(2,
"Received mailbox state on resource '%s' for uniqueid '%s' but it has been filtered out\n",
552 mailbox =
strsep(&item_id,
"@");
572 ast_log(
LOG_ERROR,
"Received refresh request for devicestate on publication '%s' but publish '%s' is not available\n",
600 const char *eid, *
type;
616 ast_debug(2,
"Received unsupported content type for Asterisk event on resource '%s'\n",
623 ast_debug(1,
"Received unparseable JSON event for resource '%s'\n",
630 ast_debug(1,
"Received event without eid for resource '%s'\n",
638 ast_debug(1,
"Received event without type for resource '%s'\n",
641 }
else if (!strcmp(type,
"devicestate")) {
643 }
else if (!strcmp(type,
"refresh")) {
663 ast_log(
LOG_ERROR,
"Received refresh request for mwi state on publication '%s' but publish '%s' is not available\n",
691 const char *eid, *
type;
707 ast_debug(2,
"Received unsupported content type for Asterisk event on resource '%s'\n",
714 ast_debug(1,
"Received unparseable JSON event for resource '%s'\n",
721 ast_debug(1,
"Received event without eid for resource '%s'\n",
729 ast_debug(1,
"Received event without type for resource '%s'\n",
732 }
else if (!strcmp(type,
"mailboxstate")) {
734 }
else if (!strcmp(type,
"refresh")) {
773 .
type =
"application",
849 if (!strcmp(var->
name,
"device_state_filter")) {
853 }
else if (!strcmp(var->
name,
"mailbox_state_filter")) {
873 ast_log(
LOG_ERROR,
"Unable to register 'asterisk-publication' type with sorcery\n");
888 asterisk_devicestate_publication_handler.
event_name);
899 asterisk_devicestate_publisher_handler.
event_name);
941 .requires =
"res_pjsip,res_pjsip_outbound_publish,res_pjsip_pubsub",
static int asterisk_publication_mwi_refresh(struct ast_sip_publication *pub, struct asterisk_publication_config *config, struct ast_eid *pubsub_eid, struct ast_json *json)
const char * event_name
The name of the event this handler deals with.
Structure which contains Asterisk mailbox publisher state information.
Asterisk main include file. File version handling, generic pbx functions.
static const struct ast_datastore_info asterisk_devicestate_publisher_state_datastore
Datastore for attaching devicestate publisher state information.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
struct ast_json * ast_json_load_buf(const char *buffer, size_t buflen, struct ast_json_error *error)
Parse buffer with known length into a JSON object or array.
unsigned int mailbox_state
Accept inbound mailbox state events.
static int send_refresh_cb(void *obj, void *arg, int flags)
const ast_string_field mailboxstate_publish
Optional name of a mailbox state publish item, used to request the remote side update us...
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
static int build_regex(regex_t *regex, const char *text)
unsigned int mailbox_state_filter
Mailbox state should be filtered.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct stasis_cache * ast_mwi_state_cache(void)
Backend cache for ast_mwi_topic_cached().
regex_t device_state_regex
Regex used for filtering outbound device state.
#define ao2_callback(c, flags, cb_fn, arg)
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
enum ast_device_state state
int stasis_subscription_is_subscribed(const struct stasis_subscription *sub)
Returns whether a subscription is currently subscribed.
Structure for variables, used for configurations and for channel variables.
static int asterisk_publication_devicestate_refresh(struct ast_sip_publication *pub, struct asterisk_publication_config *config, struct ast_eid *pubsub_eid, struct ast_json *json)
static void asterisk_mwi_publisher_state_destroy(void *obj)
Destroy callback for Asterisk mwi publisher state information from datastore.
#define ast_json_dump_string(root)
Encode a JSON value to a compact string.
Perform no matching, return all objects.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
Type for a default handler that should do nothing.
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
Structure for a data store type.
struct ast_sip_outbound_publish_client * ast_sip_publish_client_get(const char *name)
Find a publish client using its name.
enum ast_devstate_cache cachable
int ast_sip_register_publish_handler(struct ast_sip_publish_handler *handler)
Register a publish handler.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ast_sorcery_apply_config(sorcery, name)
Return all matching objects.
static int asterisk_stop_devicestate_publishing(struct ast_sip_outbound_publish_client *client)
Structure for a data store object.
struct stasis_topic * ast_mwi_topic_all(void)
Get the Stasis Message Bus API topic for MWI messages.
struct ao2_container * stasis_cache_dump(struct stasis_cache *cache, struct stasis_message_type *type)
Dump cached items to a subscription for the ast_eid_default entity.
static int asterisk_start_mwi_publishing(struct ast_sip_outbound_publish *configuration, struct ast_sip_outbound_publish_client *client)
void ast_sip_publish_client_remove_datastore(struct ast_sip_outbound_publish_client *client, const char *name)
Remove a publication datastore from an event publisher.
An Entity ID is essentially a MAC address, brief and unique.
static void * asterisk_publication_config_alloc(const char *name)
Allocator function for Asterisk publication configuration.
int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2)
Compare two EIDs.
regex_t mailbox_state_regex
Regex used for filtering inbound mailbox state.
#define ast_strlen_zero(foo)
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
const char * ast_sorcery_object_get_extended(const void *object, const char *name)
Get an extended field value from a sorcery object.
struct stasis_subscription * device_state_subscription
Device state subscription.
static void asterisk_publisher_mwistate_cb(void *data, struct stasis_subscription *sub, struct stasis_message *msg)
Callback function for mailbox state events.
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags,...)
Register a field within an object with custom handlers.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
int ast_sip_publish_client_send(struct ast_sip_outbound_publish_client *client, const struct ast_sip_body *body)
Send an outgoing PUBLISH message using a client.
enum ast_device_state ast_devstate_val(const char *val)
Convert device state from text to integer value.
void ast_sip_unregister_event_publisher_handler(struct ast_sip_event_publisher_handler *handler)
Unregister a publish handler.
Outbound publish client state information (persists for lifetime of a publish)
struct ast_sip_publish_handler asterisk_devicestate_publication_handler
int ast_sorcery_object_unregister(struct ast_sorcery *sorcery, const char *type)
Unregister an object type.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_sip_event_publisher_handler asterisk_devicestate_publisher_handler
const struct ast_eid * eid
The EID of the server where this message originated.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
static int asterisk_publication_devicestate_state_change(struct ast_sip_publication *pub, pjsip_msg_body *body, enum ast_sip_publish_state state)
Callbacks that event publisher handlers will define.
struct ast_datastore * ast_sip_publish_client_get_datastore(struct ast_sip_outbound_publish_client *client, const char *name)
Retrieve an event publisher datastore.
const char * event_name
The name of the event this handler deals with.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
const char * ast_sip_publication_get_event_configuration(const struct ast_sip_publication *pub)
Given a publication, get the configuration name for the event type in use.
static int asterisk_publication_mailboxstate(struct ast_sip_publication *pub, struct asterisk_publication_config *config, struct ast_eid *pubsub_eid, struct ast_json *json)
unsigned int device_state_filter
Device state should be filtered.
int ast_str_to_eid(struct ast_eid *eid, const char *s)
Convert a string into an EID.
#define ast_strdupa(s)
duplicate a string in memory from the stack
struct ast_sip_outbound_publish_client * client
The publish client to send PUBLISH messages on.
unsigned int mailbox_state_filter
Mailbox state should be filtered.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
struct ast_sip_event_publisher_handler asterisk_mwi_publisher_handler
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
struct ast_sip_publish_handler asterisk_mwi_publication_handler
An entity with which Asterisk communicates.
static int cached_mwistate_cb(void *obj, void *arg, int flags)
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
static int asterisk_publication_new(struct ast_sip_endpoint *endpoint, const char *resource, const char *event_configuration)
#define stasis_subscribe(topic, callback, data)
static void asterisk_publication_send_refresh(void)
Internal function to send refresh requests to all publications.
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.
int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype)
Checks if the given content type matches type/subtype.
const char * ast_devstate_str(enum ast_device_state devstate) attribute_pure
Convert device state to text string that is easier to parse.
struct ast_sip_outbound_publish_client * client
The publish client to send PUBLISH messages on.
int ast_publish_device_state_full(const char *device, enum ast_device_state state, enum ast_devstate_cache cachable, struct ast_eid *eid)
Publish a device state update with EID.
struct stasis_cache * ast_device_state_cache(void)
Backend cache for ast_device_state_topic_cached()
int ast_sip_publish_client_add_datastore(struct ast_sip_outbound_publish_client *client, struct ast_datastore *datastore)
Add a datastore to a SIP event publisher.
#define SORCERY_OBJECT(details)
Macro which must be used at the beginning of each sorcery capable object.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
Type for default option handler for bools (ast_true/ast_false)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_sorcery_apply_default(sorcery, type, name, data)
struct ast_datastore * ast_sip_publish_client_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
Alternative for ast_datastore_alloc()
Outbound publish information.
static int asterisk_publication_mwi_state_change(struct ast_sip_publication *pub, pjsip_msg_body *body, enum ast_sip_publish_state state)
Callbacks that publication handlers will define.
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
static void asterisk_publication_config_destroy(void *obj)
Destructor function for Asterisk publication configuration.
unsigned int device_state_filter
Device state should be filtered.
#define ast_calloc(num, len)
A wrapper for calloc()
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static int regex_filter_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Structure which contains Asterisk publication information.
static int unload_module(void)
static void asterisk_devicestate_publisher_state_destroy(void *obj)
Destroy callback for Asterisk devicestate publisher state information from datastore.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
struct stasis_message_type * ast_mwi_state_type(void)
Get the Stasis Message Bus API message type for MWI messages.
Module has failed to load, may be in an inconsistent state.
struct stasis_subscription * mailbox_state_subscription
Mailbox state subscription.
Support for logging to various files, console and syslog Configuration in file logger.conf.
Structure which contains Asterisk device state publisher state information.
void ast_sip_unregister_publish_handler(struct ast_sip_publish_handler *handler)
Unregister a publish handler.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
struct ast_eid ast_eid_default
Global EID.
char * strsep(char **str, const char *delims)
static int cached_devstate_cb(void *obj, void *arg, int flags)
static const struct ast_datastore_info asterisk_mwi_publisher_state_datastore
Datastore for attaching devicestate publisher state information.
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
const ast_string_field uniqueid
static int asterisk_publication_devicestate(struct ast_sip_publication *pub, struct asterisk_publication_config *config, struct ast_eid *pubsub_eid, struct ast_json *json)
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
struct stasis_forward * sub
int ast_sip_register_event_publisher_handler(struct ast_sip_event_publisher_handler *handler)
Register an event publisher handler.
static int load_module(void)
Abstract JSON element (object, array, string, int, ...).
Type for default option handler for stringfields.
Structure representing a SIP publication.
static int asterisk_stop_mwi_publishing(struct ast_sip_outbound_publish_client *client)
The structure that contains device state.
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
static int asterisk_start_devicestate_publishing(struct ast_sip_outbound_publish *configuration, struct ast_sip_outbound_publish_client *client)
const ast_string_field devicestate_publish
Optional name of a device state publish item struct ast_string_field_mgr __field_mgr used to request ...
int ast_eid_is_empty(const struct ast_eid *eid)
Check if EID is empty.
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
static int reload_module(void)
The structure that contains MWI state.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
unsigned int device_state
Accept inbound device state events.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
regex_t device_state_regex
Regex used for filtering inbound device state.
void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects.
regex_t mailbox_state_regex
Regex used for filtering outbound mailbox state.
static void asterisk_publisher_devstate_cb(void *data, struct stasis_subscription *sub, struct stasis_message *msg)
Callback function for device state events.