Asterisk - The Open Source Telephony Project GIT-master-d856a3e
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
res_pjsip_pubsub.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_simple.h>
#include <pjlib.h>
#include "asterisk/mwi.h"
#include "asterisk/res_pjsip_pubsub.h"
#include "asterisk/module.h"
#include "asterisk/linkedlists.h"
#include "asterisk/astobj2.h"
#include "asterisk/datastore.h"
#include "asterisk/uuid.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/sched.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/callerid.h"
#include "asterisk/manager.h"
#include "asterisk/cli.h"
#include "asterisk/test.h"
#include "res_pjsip/include/res_pjsip_private.h"
#include "asterisk/res_pjsip_presence_xml.h"
Include dependency graph for res_pjsip_pubsub.c:

Go to the source code of this file.

Data Structures

struct  ast_sip_publication
 Structure representing a SIP publication. More...
 
struct  ast_sip_publication_resource
 Structure representing a publication resource. More...
 
struct  ast_sip_subscription
 Structure representing a "virtual" SIP subscription. More...
 
struct  body_generators
 
struct  body_part
 A multipart body part and meta-information. More...
 
struct  body_part_list
 Type declaration for container of body part structures. More...
 
struct  body_supplements
 
struct  cli_sub_complete_parms
 
struct  cli_sub_parms
 
struct  initial_notify_data
 
struct  persistence_recreate_data
 
struct  publish_handlers
 
struct  resource_list
 Resource list configuration item. More...
 
struct  resource_tree
 A resource tree. More...
 
struct  resources
 A vector of strings commonly used throughout this module. More...
 
struct  simple_message_summary
 
struct  sip_subscription_tree
 A tree of SIP subscriptions. More...
 
struct  subscription_handlers
 
struct  subscription_persistence
 Structure used for persisting an inbound subscription. More...
 
struct  subscriptions
 
struct  tree_node
 A node for a resource tree. More...
 

Macros

#define AMI_SHOW_SUBSCRIPTIONS_INBOUND   "PJSIPShowSubscriptionsInbound"
 
#define AMI_SHOW_SUBSCRIPTIONS_OUTBOUND   "PJSIPShowSubscriptionsOutbound"
 
#define CLI_LIST_SUB_FORMAT_ENTRY   "%-30.30s %-30.30s %6d %s\n"
 
#define CLI_LIST_SUB_FORMAT_HEADER   "%-30.30s %-30.30s %6.6s %s\n"
 
#define CLI_SHOW_SUB_FORMAT_ENTRY
 
#define CLI_SHOW_SUB_FORMAT_HEADER
 
#define DATASTORE_BUCKETS   53
 Number of buckets for subscription datastore. More...
 
#define DEFAULT_EXPIRES   3600
 Default expiration for subscriptions. More...
 
#define DEFAULT_PUBLISH_EXPIRES   3600
 Default expiration time for PUBLISH if one is not specified. More...
 
#define MAX_REGEX_ERROR_LEN   128
 
#define MOD_DATA_MSG   "sub_msg"
 
#define MOD_DATA_PERSISTENCE   "sub_persistence"
 
#define NEW_SUBSCRIBE(notifier, endpoint, resource, rdata)   notifier->new_subscribe_with_rdata ? notifier->new_subscribe_with_rdata(endpoint, resource, rdata) : notifier->new_subscribe(endpoint, resource)
 
#define PUBLICATIONS_BUCKETS   37
 Number of buckets for publications (on a per handler) More...
 
#define RESOURCE_LIST_INIT_SIZE   4
 

Typedefs

typedef int(* on_subscription_t) (struct sip_subscription_tree *sub, void *arg)
 

Enumerations

enum  sip_persistence_update_type { SUBSCRIPTION_PERSISTENCE_SEND_REQUEST = 0 , SUBSCRIPTION_PERSISTENCE_CREATED , SUBSCRIPTION_PERSISTENCE_RECREATED , SUBSCRIPTION_PERSISTENCE_REFRESHED }
 
enum  sip_publish_type {
  SIP_PUBLISH_UNKNOWN , SIP_PUBLISH_INITIAL , SIP_PUBLISH_REFRESH , SIP_PUBLISH_MODIFY ,
  SIP_PUBLISH_REMOVE
}
 The types of PUBLISH messages defined in RFC 3903. More...
 
enum  sip_subscription_tree_state { SIP_SUB_TREE_NORMAL = 0 , SIP_SUB_TREE_TERMINATE_PENDING , SIP_SUB_TREE_TERMINATE_IN_PROGRESS , SIP_SUB_TREE_TERMINATED }
 The state of the subscription tree. More...
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void add_rlmi_resource (pj_pool_t *pool, pj_xml_node *rlmi, const pjsip_generic_string_hdr *cid, const char *resource_name, const pjsip_sip_uri *resource_uri, pjsip_evsub_state state)
 Add a resource XML element to an RLMI body. More...
 
static void add_subscription (struct sip_subscription_tree *obj)
 
static struct body_partallocate_body_part (pj_pool_t *pool, const struct ast_sip_subscription *sub)
 Allocate and initialize a body part structure. More...
 
static struct ast_sip_subscriptionallocate_subscription (const struct ast_sip_subscription_handler *handler, const char *resource, const char *display_name, struct sip_subscription_tree *tree)
 
static struct sip_subscription_treeallocate_subscription_tree (struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
 
static int allocate_tdata_buffer (pjsip_tx_data *tdata)
 Pre-allocate a buffer for the transmission. More...
 
static int ami_show_resource_lists (struct mansession *s, const struct message *m)
 
static int ami_show_subscriptions_inbound (struct mansession *s, const struct message *m)
 
static int ami_show_subscriptions_outbound (struct mansession *s, const struct message *m)
 
static int ami_subscription_detail (struct sip_subscription_tree *sub_tree, struct ast_sip_ami *ami, const char *event)
 
static int ami_subscription_detail_inbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static int ami_subscription_detail_outbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static int apply_list_configuration (struct ast_sorcery *sorcery)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
struct ast_sip_subscriptionast_sip_create_subscription (const struct ast_sip_subscription_handler *handler, struct ast_sip_endpoint *endpoint, const char *resource)
 Create a new ast_sip_subscription structure. More...
 
int ast_sip_publication_add_datastore (struct ast_sip_publication *publication, struct ast_datastore *datastore)
 Add a datastore to a SIP publication. More...
 
struct ast_datastoreast_sip_publication_get_datastore (struct ast_sip_publication *publication, const char *name)
 Retrieve a publication datastore. More...
 
struct ao2_containerast_sip_publication_get_datastores (const struct ast_sip_publication *publication)
 Get the datastores container for a publication. More...
 
struct ast_sip_endpointast_sip_publication_get_endpoint (struct ast_sip_publication *pub)
 Given a publication, get the associated endpoint. More...
 
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. More...
 
const char * ast_sip_publication_get_resource (const struct ast_sip_publication *pub)
 Given a publication, get the resource the publication is to. More...
 
void ast_sip_publication_remove_datastore (struct ast_sip_publication *publication, const char *name)
 Remove a publication datastore from the publication. More...
 
int ast_sip_pubsub_generate_body_content (const char *type, const char *subtype, struct ast_sip_body_data *data, struct ast_str **str)
 Generate body content for a PUBLISH or NOTIFY. More...
 
static int ast_sip_pubsub_has_eventlist_support (pjsip_rx_data *rdata)
 Check if the rdata has a Supported header containing 'eventlist'. More...
 
int ast_sip_pubsub_is_body_generator_registered (const char *type, const char *subtype)
 Is a body generator registered for the given type/subtype. More...
 
int ast_sip_pubsub_register_body_generator (struct ast_sip_pubsub_body_generator *generator)
 Register a body generator with the pubsub core. More...
 
int ast_sip_pubsub_register_body_supplement (struct ast_sip_pubsub_body_supplement *supplement)
 Register a body generator with the pubsub core. More...
 
void ast_sip_pubsub_unregister_body_generator (struct ast_sip_pubsub_body_generator *generator)
 Unregister a body generator with the pubsub core. More...
 
void ast_sip_pubsub_unregister_body_supplement (struct ast_sip_pubsub_body_supplement *supplement)
 Unregister a body generator with the pubsub core. More...
 
int ast_sip_register_publish_handler (struct ast_sip_publish_handler *handler)
 Register a publish handler. More...
 
int ast_sip_register_subscription_handler (struct ast_sip_subscription_handler *handler)
 Register a subscription handler. More...
 
int ast_sip_subscription_add_datastore (struct ast_sip_subscription *subscription, struct ast_datastore *datastore)
 Add a datastore to a SIP subscription. More...
 
struct ast_datastoreast_sip_subscription_alloc_datastore (const struct ast_datastore_info *info, const char *uid)
 Alternative for ast_datastore_alloc() More...
 
void ast_sip_subscription_destroy (struct ast_sip_subscription *sub)
 Alert the pubsub core that the subscription is ready for destruction. More...
 
const char * ast_sip_subscription_get_body_subtype (struct ast_sip_subscription *sub)
 Get the body subtype used for this subscription. More...
 
const char * ast_sip_subscription_get_body_type (struct ast_sip_subscription *sub)
 Get the body type used for this subscription. More...
 
struct ast_datastoreast_sip_subscription_get_datastore (struct ast_sip_subscription *subscription, const char *name)
 Retrieve a subscription datastore. More...
 
struct ao2_containerast_sip_subscription_get_datastores (const struct ast_sip_subscription *subscription)
 Get the datastores container for a subscription. More...
 
pjsip_dialog * ast_sip_subscription_get_dialog (struct ast_sip_subscription *sub)
 Get the pjsip dialog that is associated with this subscription. More...
 
struct ast_sip_endpointast_sip_subscription_get_endpoint (struct ast_sip_subscription *sub)
 Get the endpoint that is associated with this subscription. More...
 
void * ast_sip_subscription_get_header (const struct ast_sip_subscription *sub, const char *header)
 Get a header value for a subscription. More...
 
void ast_sip_subscription_get_local_uri (struct ast_sip_subscription *sub, char *buf, size_t size)
 Retrieve the local URI for this subscription. More...
 
const struct ast_jsonast_sip_subscription_get_persistence_data (const struct ast_sip_subscription *subscription)
 Retrieve persistence data for a subscription. More...
 
void ast_sip_subscription_get_remote_uri (struct ast_sip_subscription *sub, char *buf, size_t size)
 Retrive the remote URI for this subscription. More...
 
const char * ast_sip_subscription_get_resource_name (struct ast_sip_subscription *sub)
 Get the name of the subscribed resource. More...
 
struct ast_taskprocessorast_sip_subscription_get_serializer (struct ast_sip_subscription *sub)
 Get the serializer for the subscription. More...
 
pjsip_sip_uri * ast_sip_subscription_get_sip_uri (struct ast_sip_subscription *sub)
 Retrieve the local sip uri for this subscription. More...
 
int ast_sip_subscription_is_terminated (const struct ast_sip_subscription *sub)
 Get whether the subscription has been terminated or not. More...
 
int ast_sip_subscription_notify (struct ast_sip_subscription *sub, struct ast_sip_body_data *notify_data, int terminate)
 Notify a SIP subscription of a state change. More...
 
void ast_sip_subscription_remove_datastore (struct ast_sip_subscription *subscription, const char *name)
 Remove a subscription datastore from the subscription. More...
 
void ast_sip_subscription_set_persistence_data (struct ast_sip_subscription *subscription, struct ast_json *persistence_data)
 Set persistence data for a subscription. More...
 
void ast_sip_unregister_publish_handler (struct ast_sip_publish_handler *handler)
 Unregister a publish handler. More...
 
void ast_sip_unregister_subscription_handler (struct ast_sip_subscription_handler *handler)
 Unregister a subscription handler. More...
 
static void build_body_part (pj_pool_t *pool, struct ast_sip_subscription *sub, struct body_part_list *parts, unsigned int use_full_state)
 Create a multipart body part for a subscribed resource. More...
 
static void build_node_children (struct ast_sip_endpoint *endpoint, const struct ast_sip_subscription_handler *handler, struct resource_list *list, struct tree_node *parent, struct resources *visited, pjsip_rx_data *rdata)
 Build child nodes for a given parent. More...
 
static int build_resource_tree (struct ast_sip_endpoint *endpoint, const struct ast_sip_subscription_handler *handler, const char *resource, struct resource_tree *tree, int has_eventlist_support, pjsip_rx_data *rdata)
 Build a resource tree. More...
 
static pjsip_multipart_part * build_rlmi_body (pj_pool_t *pool, struct ast_sip_subscription *sub, struct body_part_list *body_parts, unsigned int full_state)
 Create an RLMI body part for a multipart resource list body. More...
 
static void clean_sub_tree (pjsip_evsub *evsub)
 Callback sequence for subscription terminate: More...
 
static char * cli_complete_subscription_callid (struct ast_cli_args *a)
 
static int cli_complete_subscription_common (struct sip_subscription_tree *sub_tree, struct cli_sub_complete_parms *cli)
 
static int cli_complete_subscription_inbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static int cli_complete_subscription_outbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static int cli_list_subscriptions_detail (struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)
 
static int cli_list_subscriptions_inbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static char * cli_list_subscriptions_inout (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int cli_list_subscriptions_outbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static int cli_show_subscription_common (struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)
 
static int cli_show_subscription_inbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static char * cli_show_subscription_inout (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int cli_show_subscription_outbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static int cli_show_subscriptions_detail (struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)
 
static int cli_show_subscriptions_inbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static char * cli_show_subscriptions_inout (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int cli_show_subscriptions_outbound (struct sip_subscription_tree *sub_tree, void *arg)
 
static unsigned int cli_subscription_expiry (struct sip_subscription_tree *sub_tree)
 
static int cmp_strings (char *s1, char *s2)
 Compare strings for equality checking for NULL. More...
 
static int cmp_subscription_childrens (struct ast_sip_subscription *s1, struct ast_sip_subscription *s2)
 compares the childrens of two ast_sip_subscription s1 and s2 More...
 
static pjsip_msg_body * create_multipart_body (pj_pool_t *pool)
 Create and initialize the PJSIP multipart body structure for a resource list subscription. More...
 
static pjsip_require_hdr * create_require_eventlist (pj_pool_t *pool)
 Shortcut method to create a Require: eventlist header. More...
 
static struct sip_subscription_treecreate_subscription_tree (const struct ast_sip_subscription_handler *handler, struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *resource, struct ast_sip_pubsub_body_generator *generator, struct resource_tree *tree, pj_status_t *dlg_status, struct subscription_persistence *persistence)
 Create a subscription tree based on a resource tree. More...
 
static struct ast_sip_subscriptioncreate_virtual_subscriptions (const struct ast_sip_subscription_handler *handler, const char *resource, struct ast_sip_pubsub_body_generator *generator, struct sip_subscription_tree *tree, struct tree_node *current)
 Create a tree of virtual subscriptions based on a resource tree node. More...
 
static void destroy_subscription (struct ast_sip_subscription *sub)
 
static void destroy_subscriptions (struct ast_sip_subscription *root)
 
static int destroy_subscriptions_task (void *obj)
 
static enum sip_publish_type determine_sip_publish_type (pjsip_rx_data *rdata, pjsip_generic_string_hdr *etag_hdr, unsigned int *expires, int *entity_id)
 
static int exceptional_accept (const pj_str_t *accept)
 Is the Accept header from the SUBSCRIBE in the list of exceptions? More...
 
static struct ast_sip_pubsub_body_generatorfind_body_generator (char accept[AST_SIP_MAX_ACCEPT][64], size_t num_accept, const char *body_type)
 
static struct ast_sip_pubsub_body_generatorfind_body_generator_accept (const char *accept)
 
static struct ast_sip_pubsub_body_generatorfind_body_generator_type_subtype (const char *type, const char *subtype)
 
static struct ast_sip_pubsub_body_generatorfind_body_generator_type_subtype_nolock (const char *type, const char *subtype)
 
static struct ast_sip_publish_handlerfind_pub_handler (const char *event)
 
static struct ast_sip_subscription_handlerfind_sub_handler_for_event_name (const char *event_name)
 
static int for_each_subscription (on_subscription_t on_subscription, void *arg)
 
static int format_ami_resource_lists (void *obj, void *arg, int flags)
 
static void free_body_parts (struct body_part_list *parts)
 Destroy a list of body parts. More...
 
static pjsip_generic_string_hdr * generate_content_id_hdr (pj_pool_t *pool, const struct ast_sip_subscription *sub)
 Create a Content-ID header. More...
 
static int generate_initial_notify (struct ast_sip_subscription *sub)
 
static pjsip_msg_body * generate_list_body (pj_pool_t *pool, struct ast_sip_subscription *sub, unsigned int force_full_state)
 Create a resource list body for NOTIFY requests. More...
 
static pjsip_msg_body * generate_notify_body (pj_pool_t *pool, struct ast_sip_subscription *root, unsigned int force_full_state)
 Create the body for a NOTIFY request. More...
 
static int have_visited (const char *resource, struct resources *visited)
 Determine if this resource has been visited already. More...
 
static int initial_notify_task (void *obj)
 
static int item_in_vector (const struct resource_list *list, const char *item)
 
static int list_item_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int list_item_to_str (const void *obj, const intptr_t *args, char **buf)
 
static int load_module (void)
 
static int parse_simple_message_summary (char *body, struct simple_message_summary *summary)
 
static int persistence_endpoint_str2struct (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int persistence_endpoint_struct2str (const void *obj, const intptr_t *args, char **buf)
 
static int persistence_expires_str2struct (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int persistence_expires_struct2str (const void *obj, const intptr_t *args, char **buf)
 
static int persistence_generator_data_str2struct (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int persistence_generator_data_struct2str (const void *obj, const intptr_t *args, char **buf)
 
static int persistence_tag_str2struct (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int persistence_tag_struct2str (const void *obj, const intptr_t *args, char **buf)
 
static int publication_cmp_fn (void *obj, void *arg, int flags)
 
static void publication_destroy_fn (void *obj)
 Internal destructor for publications. More...
 
static int publication_hash_fn (const void *obj, const int flags)
 
static void * publication_resource_alloc (const char *name)
 Allocator for publication resource. More...
 
static void publication_resource_destroy (void *obj)
 Destructor for publication resource. More...
 
static void publish_add_handler (struct ast_sip_publish_handler *handler)
 
static int publish_expire (const void *data)
 
static int publish_expire_callback (void *data)
 
static struct ast_sip_publicationpublish_request_initial (struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, struct ast_sip_publish_handler *handler)
 
static void pubsub_on_client_refresh (pjsip_evsub *sub)
 
static void pubsub_on_evsub_state (pjsip_evsub *evsub, pjsip_event *event)
 PJSIP callback when underlying SIP subscription changes state. More...
 
static int pubsub_on_refresh_timeout (void *userdata)
 
static pj_bool_t pubsub_on_rx_mwi_notify_request (pjsip_rx_data *rdata)
 
static void pubsub_on_rx_notify (pjsip_evsub *sub, pjsip_rx_data *rdata, int *p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body)
 
static pj_bool_t pubsub_on_rx_notify_request (pjsip_rx_data *rdata)
 
static pj_bool_t pubsub_on_rx_publish_request (pjsip_rx_data *rdata)
 
static void pubsub_on_rx_refresh (pjsip_evsub *evsub, pjsip_rx_data *rdata, int *p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body)
 Called whenever an in-dialog SUBSCRIBE is received. More...
 
static pj_bool_t pubsub_on_rx_request (pjsip_rx_data *rdata)
 Opaque structure representing an RFC 3265 SIP subscription. More...
 
static pj_bool_t pubsub_on_rx_subscribe_request (pjsip_rx_data *rdata)
 
static void pubsub_on_server_timeout (pjsip_evsub *sub)
 
static void remove_subscription (struct sip_subscription_tree *obj)
 
static int resource_endpoint_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int resource_event_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static void * resource_list_alloc (const char *name)
 
static int resource_list_apply_handler (const struct ast_sorcery *sorcery, void *obj)
 
static void resource_list_destructor (void *obj)
 
static void resource_tree_destroy (struct resource_tree *tree)
 Destroy a resource tree. More...
 
static struct resource_listretrieve_resource_list (const char *resource, const char *event)
 Helper function for retrieving a resource list for a given event. More...
 
static void * rlmi_clone_data (pj_pool_t *pool, const void *data, unsigned len)
 
static int rlmi_print_body (struct pjsip_msg_body *msg_body, char *buf, pj_size_t size)
 
static int sched_cb (const void *data)
 
static int schedule_notification (struct sip_subscription_tree *sub_tree)
 
static int send_notify (struct sip_subscription_tree *sub_tree, unsigned int force_full_state)
 Send a NOTIFY request to a subscriber. More...
 
static int serialized_pubsub_on_client_refresh (void *userdata)
 
static int serialized_pubsub_on_refresh_timeout (void *userdata)
 
static int serialized_send_notify (void *userdata)
 
static void set_state_terminated (struct ast_sip_subscription *sub)
 
static void shutdown_subscriptions (struct ast_sip_subscription *sub)
 
static struct ast_sip_publicationsip_create_publication (struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *resource, const char *event_configuration_name)
 
static int sip_publication_respond (struct ast_sip_publication *pub, int status_code, pjsip_rx_data *rdata)
 
static int sip_subscription_accept (struct sip_subscription_tree *sub_tree, pjsip_rx_data *rdata, int response)
 
static int sip_subscription_send_request (struct sip_subscription_tree *sub_tree, pjsip_tx_data *tdata)
 
static void sip_subscription_to_ami (struct sip_subscription_tree *sub_tree, struct ast_str **buf)
 
static void sub_add_handler (struct ast_sip_subscription_handler *handler)
 
static int sub_persistence_recreate (void *obj)
 
static int sub_tree_subscription_terminate_cb (void *data)
 
static void sub_tree_transport_cb (void *data)
 
static struct ast_sip_pubsub_body_generatorsubscription_get_generator_from_rdata (pjsip_rx_data *rdata, const struct ast_sip_subscription_handler *handler)
 Retrieve a body generator using the Accept header of an rdata message. More...
 
static struct ast_sip_subscription_handlersubscription_get_handler_from_rdata (pjsip_rx_data *rdata, const char *endpoint)
 Retrieve a handler using the Event header of an rdata message. More...
 
static void * subscription_persistence_alloc (const char *name)
 Allocator for subscription persistence. More...
 
static struct subscription_persistencesubscription_persistence_create (struct sip_subscription_tree *sub_tree)
 Function which creates initial persistence information of a subscription in sorcery. More...
 
static void subscription_persistence_destroy (void *obj)
 Destructor for subscription persistence. More...
 
static void subscription_persistence_event_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 Event callback which fires subscription persistence recreation when the system is fully booted. More...
 
static int subscription_persistence_load (void *data)
 Function which loads and recreates persisted subscriptions upon startup when the system is fully booted. More...
 
static int subscription_persistence_recreate (void *obj, void *arg, int flags)
 Callback function to perform the actual recreation of a subscription. More...
 
static void subscription_persistence_remove (struct sip_subscription_tree *sub_tree)
 Function which removes persistence of a subscription from sorcery. More...
 
static void subscription_persistence_update (struct sip_subscription_tree *sub_tree, pjsip_rx_data *rdata, enum sip_persistence_update_type type)
 Function which updates persistence information of a subscription in sorcery. More...
 
static void subscription_setup_dialog (struct sip_subscription_tree *sub_tree, pjsip_dialog *dlg)
 
static void subscription_tree_destructor (void *obj)
 
static int subscription_unreference_dialog (void *obj)
 
static struct tree_nodetree_node_alloc (const char *resource, struct resources *visited, unsigned int full_state, const char *display_name)
 Allocate a tree node. More...
 
static void tree_node_destroy (struct tree_node *node)
 Destructor for a tree node. More...
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "PJSIP event resource" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, .requires = "res_pjsip", }
 
const char * accept_exceptions []
 Accept headers that are exceptions to the rule. More...
 
static const struct ast_module_infoast_module_info = &__mod_info
 
struct body_generators body_generators = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
struct body_supplements body_supplements = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static struct ast_cli_entry cli_commands []
 
static int esc_etag_counter
 
const pjsip_method pjsip_publish_method
 Defined method for PUBLISH. More...
 
struct publish_handlers publish_handlers = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static pjsip_evsub_user pubsub_cb
 
static struct pjsip_module pubsub_module
 
static pjsip_media_type rlmi_media_type
 
static struct ast_sched_contextsched
 Scheduler used for automatically expiring publications. More...
 
static const char * sip_subscription_roles_map []
 
static const pj_str_t str_event_name = { "Event", 5 }
 
static char * sub_tree_state_description []
 
struct subscription_handlers subscription_handlers = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
struct subscriptions subscriptions = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 

Macro Definition Documentation

◆ AMI_SHOW_SUBSCRIPTIONS_INBOUND

#define AMI_SHOW_SUBSCRIPTIONS_INBOUND   "PJSIPShowSubscriptionsInbound"

Definition at line 4374 of file res_pjsip_pubsub.c.

◆ AMI_SHOW_SUBSCRIPTIONS_OUTBOUND

#define AMI_SHOW_SUBSCRIPTIONS_OUTBOUND   "PJSIPShowSubscriptionsOutbound"

Definition at line 4375 of file res_pjsip_pubsub.c.

◆ CLI_LIST_SUB_FORMAT_ENTRY

#define CLI_LIST_SUB_FORMAT_ENTRY   "%-30.30s %-30.30s %6d %s\n"

Definition at line 4761 of file res_pjsip_pubsub.c.

◆ CLI_LIST_SUB_FORMAT_HEADER

#define CLI_LIST_SUB_FORMAT_HEADER   "%-30.30s %-30.30s %6.6s %s\n"

Definition at line 4760 of file res_pjsip_pubsub.c.

◆ CLI_SHOW_SUB_FORMAT_ENTRY

#define CLI_SHOW_SUB_FORMAT_ENTRY
Value:
"Endpoint: %s/%s\n" \
"Resource: %s/%s\n" \
" Expiry: %8d %s\n\n"

Definition at line 4618 of file res_pjsip_pubsub.c.

◆ CLI_SHOW_SUB_FORMAT_HEADER

#define CLI_SHOW_SUB_FORMAT_HEADER
Value:
"Endpoint: <Endpoint/Caller-ID.............................................>\n" \
"Resource: <Resource/Event.................................................>\n" \
" Expiry: <Expiry> <Call-id..............................................>\n" \
"===========================================================================\n\n"

Definition at line 4613 of file res_pjsip_pubsub.c.

◆ DATASTORE_BUCKETS

#define DATASTORE_BUCKETS   53

Number of buckets for subscription datastore.

Definition at line 259 of file res_pjsip_pubsub.c.

◆ DEFAULT_EXPIRES

#define DEFAULT_EXPIRES   3600

Default expiration for subscriptions.

Definition at line 262 of file res_pjsip_pubsub.c.

◆ DEFAULT_PUBLISH_EXPIRES

#define DEFAULT_PUBLISH_EXPIRES   3600

Default expiration time for PUBLISH if one is not specified.

Definition at line 256 of file res_pjsip_pubsub.c.

◆ MAX_REGEX_ERROR_LEN

#define MAX_REGEX_ERROR_LEN   128

Definition at line 4377 of file res_pjsip_pubsub.c.

◆ MOD_DATA_MSG

#define MOD_DATA_MSG   "sub_msg"

Definition at line 245 of file res_pjsip_pubsub.c.

◆ MOD_DATA_PERSISTENCE

#define MOD_DATA_PERSISTENCE   "sub_persistence"

Definition at line 244 of file res_pjsip_pubsub.c.

◆ NEW_SUBSCRIBE

#define NEW_SUBSCRIBE (   notifier,
  endpoint,
  resource,
  rdata 
)    notifier->new_subscribe_with_rdata ? notifier->new_subscribe_with_rdata(endpoint, resource, rdata) : notifier->new_subscribe(endpoint, resource)

Definition at line 1021 of file res_pjsip_pubsub.c.

◆ PUBLICATIONS_BUCKETS

#define PUBLICATIONS_BUCKETS   37

Number of buckets for publications (on a per handler)

Definition at line 253 of file res_pjsip_pubsub.c.

◆ RESOURCE_LIST_INIT_SIZE

#define RESOURCE_LIST_INIT_SIZE   4

Definition at line 4993 of file res_pjsip_pubsub.c.

Typedef Documentation

◆ on_subscription_t

typedef int(* on_subscription_t) (struct sip_subscription_tree *sub, void *arg)

Definition at line 1839 of file res_pjsip_pubsub.c.

Enumeration Type Documentation

◆ sip_persistence_update_type

Enumerator
SUBSCRIPTION_PERSISTENCE_SEND_REQUEST 

Called from send request

SUBSCRIPTION_PERSISTENCE_CREATED 

Subscription created from initial client request

SUBSCRIPTION_PERSISTENCE_RECREATED 

Subscription recreated by asterisk on startup

SUBSCRIPTION_PERSISTENCE_REFRESHED 

Subscription created from client refresh

Definition at line 540 of file res_pjsip_pubsub.c.

540 {
541 /*! Called from send request */
543 /*! Subscription created from initial client request */
545 /*! Subscription recreated by asterisk on startup */
547 /*! Subscription created from client refresh */
549};
@ SUBSCRIPTION_PERSISTENCE_CREATED
@ SUBSCRIPTION_PERSISTENCE_SEND_REQUEST
@ SUBSCRIPTION_PERSISTENCE_REFRESHED
@ SUBSCRIPTION_PERSISTENCE_RECREATED

◆ sip_publish_type

The types of PUBLISH messages defined in RFC 3903.

Enumerator
SIP_PUBLISH_UNKNOWN 

Unknown.

This actually is not defined in RFC 3903. We use this as a constant to indicate that an incoming PUBLISH does not fit into any of the other categories and is thus invalid.

SIP_PUBLISH_INITIAL 

Initial.

The first PUBLISH sent. This will contain a non-zero Expires header as well as a body that indicates the current state of the endpoint that has sent the message. The initial PUBLISH is the only type of PUBLISH to not contain a Sip-If-Match header in it.

SIP_PUBLISH_REFRESH 

Refresh.

Used to keep a published state from expiring. This will contain a non-zero Expires header but no body since its purpose is not to update state.

SIP_PUBLISH_MODIFY 

Modify.

Used to change state from its previous value. This will contain a body updating the published state. May or may not contain an Expires header.

SIP_PUBLISH_REMOVE 

Remove.

Used to remove published state from an ESC. This will contain an Expires header set to 0 and likely no body.

Definition at line 274 of file res_pjsip_pubsub.c.

274 {
275 /*!
276 * \brief Unknown
277 *
278 * \details
279 * This actually is not defined in RFC 3903. We use this as a constant
280 * to indicate that an incoming PUBLISH does not fit into any of the
281 * other categories and is thus invalid.
282 */
284
285 /*!
286 * \brief Initial
287 *
288 * \details
289 * The first PUBLISH sent. This will contain a non-zero Expires header
290 * as well as a body that indicates the current state of the endpoint
291 * that has sent the message. The initial PUBLISH is the only type
292 * of PUBLISH to not contain a Sip-If-Match header in it.
293 */
295
296 /*!
297 * \brief Refresh
298 *
299 * \details
300 * Used to keep a published state from expiring. This will contain a
301 * non-zero Expires header but no body since its purpose is not to
302 * update state.
303 */
305
306 /*!
307 * \brief Modify
308 *
309 * \details
310 * Used to change state from its previous value. This will contain
311 * a body updating the published state. May or may not contain an
312 * Expires header.
313 */
315
316 /*!
317 * \brief Remove
318 *
319 * \details
320 * Used to remove published state from an ESC. This will contain
321 * an Expires header set to 0 and likely no body.
322 */
324};
@ SIP_PUBLISH_REMOVE
Remove.
@ SIP_PUBLISH_REFRESH
Refresh.
@ SIP_PUBLISH_UNKNOWN
Unknown.
@ SIP_PUBLISH_MODIFY
Modify.
@ SIP_PUBLISH_INITIAL
Initial.

◆ sip_subscription_tree_state

The state of the subscription tree.

Enumerator
SIP_SUB_TREE_NORMAL 

Normal operation

SIP_SUB_TREE_TERMINATE_PENDING 

A terminate has been requested by Asterisk, the client, or pjproject

SIP_SUB_TREE_TERMINATE_IN_PROGRESS 

The terminate is in progress

SIP_SUB_TREE_TERMINATED 

The terminate process has finished and the subscription tree is no longer valid

Definition at line 415 of file res_pjsip_pubsub.c.

415 {
416 /*! Normal operation */
418 /*! A terminate has been requested by Asterisk, the client, or pjproject */
420 /*! The terminate is in progress */
422 /*! The terminate process has finished and the subscription tree is no longer valid */
424};
@ SIP_SUB_TREE_TERMINATE_PENDING
@ SIP_SUB_TREE_TERMINATED
@ SIP_SUB_TREE_NORMAL
@ SIP_SUB_TREE_TERMINATE_IN_PROGRESS

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 5960 of file res_pjsip_pubsub.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 5960 of file res_pjsip_pubsub.c.

◆ add_rlmi_resource()

static void add_rlmi_resource ( pj_pool_t *  pool,
pj_xml_node *  rlmi,
const pjsip_generic_string_hdr *  cid,
const char *  resource_name,
const pjsip_sip_uri *  resource_uri,
pjsip_evsub_state  state 
)
static

Add a resource XML element to an RLMI body.

Each resource element represents a subscribed resource in the list. This function currently will unconditionally add an instance element to each created resource element. Instance elements refer to later parts in the multipart body.

Parameters
poolPJLIB allocation pool
rlmi
cidContent-ID header of the resource
resource_nameName of the resource
resource_uriURI of the resource
stateState of the subscribed resource

Definition at line 2071 of file res_pjsip_pubsub.c.

2073{
2074 static pj_str_t cid_name = { "cid", 3 };
2075 pj_xml_node *resource;
2076 pj_xml_node *name;
2077 pj_xml_node *instance;
2078 pj_xml_attr *cid_attr;
2079 char id[6];
2080 char uri[PJSIP_MAX_URL_SIZE];
2081 char name_sanitized[PJSIP_MAX_URL_SIZE];
2082
2083 /* This creates a string representing the Content-ID without the enclosing < > */
2084 const pj_str_t cid_stripped = {
2085 .ptr = cid->hvalue.ptr + 1,
2086 .slen = cid->hvalue.slen - 2,
2087 };
2088
2089 resource = ast_sip_presence_xml_create_node(pool, rlmi, "resource");
2090 name = ast_sip_presence_xml_create_node(pool, resource, "name");
2091 instance = ast_sip_presence_xml_create_node(pool, resource, "instance");
2092
2093 pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, resource_uri, uri, sizeof(uri));
2094 ast_sip_presence_xml_create_attr(pool, resource, "uri", uri);
2095
2096 ast_sip_sanitize_xml(resource_name, name_sanitized, sizeof(name_sanitized));
2097 pj_strdup2(pool, &name->content, name_sanitized);
2098
2099 ast_generate_random_string(id, sizeof(id));
2100
2101 ast_sip_presence_xml_create_attr(pool, instance, "id", id);
2102 ast_sip_presence_xml_create_attr(pool, instance, "state",
2103 state == PJSIP_EVSUB_STATE_TERMINATED ? "terminated" : "active");
2104
2105 /* Use the PJLIB-util XML library directly here since we are using a
2106 * pj_str_t
2107 */
2108
2109 cid_attr = pj_xml_attr_new(pool, &cid_name, &cid_stripped);
2110 pj_xml_add_attr(instance, cid_attr);
2111}
static const char name[]
Definition: format_mp3.c:68
void ast_sip_sanitize_xml(const char *input, char *output, size_t len)
Replace offensive XML characters with XML entities.
Definition: presence_xml.c:29
pj_xml_node * ast_sip_presence_xml_create_node(pj_pool_t *pool, pj_xml_node *parent, const char *name)
Create XML node.
Definition: presence_xml.c:152
pj_xml_attr * ast_sip_presence_xml_create_attr(pj_pool_t *pool, pj_xml_node *node, const char *name, const char *value)
Create XML attribute.
Definition: presence_xml.c:140
char * ast_generate_random_string(char *buf, size_t size)
Create a pseudo-random string of a fixed length.
Definition: strings.c:226

References ast_generate_random_string(), ast_sip_presence_xml_create_attr(), ast_sip_presence_xml_create_node(), ast_sip_sanitize_xml(), and name.

Referenced by build_rlmi_body().

◆ add_subscription()

static void add_subscription ( struct sip_subscription_tree obj)
static

Definition at line 1204 of file res_pjsip_pubsub.c.

1205{
1209}
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741

References AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by ast_sip_create_subscription(), and create_subscription_tree().

◆ allocate_body_part()

static struct body_part * allocate_body_part ( pj_pool_t *  pool,
const struct ast_sip_subscription sub 
)
static

Allocate and initialize a body part structure.

Parameters
poolPJLIB allocation pool
subSubscription representing a subscribed resource

Definition at line 2279 of file res_pjsip_pubsub.c.

2280{
2281 struct body_part *bp;
2282
2283 bp = ast_calloc(1, sizeof(*bp));
2284 if (!bp) {
2285 return NULL;
2286 }
2287
2288 bp->cid = generate_content_id_hdr(pool, sub);
2289 bp->resource = sub->resource;
2290 bp->state = sub->subscription_state;
2291 bp->uri = sub->uri;
2292 bp->display_name = sub->display_name;
2293
2294 return bp;
2295}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
struct stasis_forward * sub
Definition: res_corosync.c:240
static pjsip_generic_string_hdr * generate_content_id_hdr(pj_pool_t *pool, const struct ast_sip_subscription *sub)
Create a Content-ID header.
#define NULL
Definition: resample.c:96
A multipart body part and meta-information.
pjsip_evsub_state state
const char * display_name
const char * resource
pjsip_generic_string_hdr * cid
pjsip_sip_uri * uri

References ast_calloc, body_part::cid, body_part::display_name, generate_content_id_hdr(), NULL, body_part::resource, body_part::state, sub, and body_part::uri.

Referenced by build_body_part().

◆ allocate_subscription()

static struct ast_sip_subscription * allocate_subscription ( const struct ast_sip_subscription_handler handler,
const char *  resource,
const char *  display_name,
struct sip_subscription_tree tree 
)
static

Definition at line 1263 of file res_pjsip_pubsub.c.

1265{
1266 struct ast_sip_subscription *sub;
1267 pjsip_msg *msg;
1268 pjsip_sip_uri *request_uri;
1269
1271 if (!msg) {
1272 ast_log(LOG_ERROR, "No dialog message saved for SIP subscription. Cannot allocate subscription for resource %s\n", resource);
1273 return NULL;
1274 }
1275
1276 sub = ast_calloc(1, sizeof(*sub) + strlen(resource) + 1);
1277 if (!sub) {
1278 return NULL;
1279 }
1280 strcpy(sub->resource, resource); /* Safe */
1281
1282 sub->display_name = ast_strdup(display_name);
1283
1284 sub->datastores = ast_datastores_alloc();
1285 if (!sub->datastores) {
1287 return NULL;
1288 }
1289
1290 sub->body_text = ast_str_create(128);
1291 if (!sub->body_text) {
1293 return NULL;
1294 }
1295
1296 sub->uri = pjsip_sip_uri_create(tree->dlg->pool, PJ_FALSE);
1297 request_uri = pjsip_uri_get_uri(msg->line.req.uri);
1298 pjsip_sip_uri_assign(tree->dlg->pool, sub->uri, request_uri);
1299 pj_strdup2(tree->dlg->pool, &sub->uri->user, resource);
1300
1301 /* If there is any persistence information available for this subscription that was persisted
1302 * then make it available so that the NOTIFY has the correct state.
1303 */
1304
1307 }
1308
1309 sub->handler = handler;
1310 sub->subscription_state = PJSIP_EVSUB_STATE_ACTIVE;
1311 sub->tree = ao2_bump(tree);
1312
1313 return sub;
1314}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_log
Definition: astobj2.c:42
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
struct ao2_container * ast_datastores_alloc(void)
Allocate a specialized data stores container.
Definition: datastore.c:99
#define LOG_ERROR
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
#define ast_sip_mod_data_get(mod_data, id, key)
Using the dictionary stored in mod_data array at a given id, retrieve the value associated with the g...
Definition: res_pjsip.h:2948
static struct pjsip_module pubsub_module
#define MOD_DATA_MSG
static void destroy_subscription(struct ast_sip_subscription *sub)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
Structure representing a "virtual" SIP subscription.
struct sip_subscription_tree * tree
struct subscription_persistence * persistence
struct ast_json * generator_data
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition: test_ari.c:59

References ao2_bump, ast_calloc, ast_datastores_alloc(), ast_json_object_get(), ast_json_ref(), ast_log, ast_sip_mod_data_get, ast_str_create, ast_strdup, destroy_subscription(), ast_sip_subscription::display_name, sip_subscription_tree::dlg, subscription_persistence::generator_data, handler(), LOG_ERROR, MOD_DATA_MSG, NULL, sip_subscription_tree::persistence, pubsub_module, ast_sip_subscription::resource, sub, and ast_sip_subscription::tree.

Referenced by ast_sip_create_subscription(), and create_virtual_subscriptions().

◆ allocate_subscription_tree()

static struct sip_subscription_tree * allocate_subscription_tree ( struct ast_sip_endpoint endpoint,
pjsip_rx_data *  rdata 
)
static

Definition at line 1445 of file res_pjsip_pubsub.c.

1446{
1447 struct sip_subscription_tree *sub_tree;
1448
1449 sub_tree = ao2_alloc(sizeof *sub_tree, subscription_tree_destructor);
1450 if (!sub_tree) {
1451 return NULL;
1452 }
1453
1455
1456 if (rdata) {
1457 /*
1458 * We must continue using the serializer that the original
1459 * SUBSCRIBE came in on for the dialog. There may be
1460 * retransmissions already enqueued in the original
1461 * serializer that can result in reentrancy and message
1462 * sequencing problems.
1463 */
1465 } else {
1466 char tps_name[AST_TASKPROCESSOR_MAX_NAME + 1];
1467
1468 /* Create name with seq number appended. */
1469 ast_taskprocessor_build_name(tps_name, sizeof(tps_name), "pjsip/pubsub/%s",
1471
1472 sub_tree->serializer = ast_sip_create_serializer(tps_name);
1473 }
1474 if (!sub_tree->serializer) {
1475 ao2_ref(sub_tree, -1);
1476 return NULL;
1477 }
1478
1479 sub_tree->endpoint = ao2_bump(endpoint);
1480 sub_tree->notify_sched_id = -1;
1481
1482 return sub_tree;
1483}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
struct ast_taskprocessor * ast_sip_get_distributor_serializer(pjsip_rx_data *rdata)
Determine the distributor serializer for the SIP message.
struct ast_taskprocessor * ast_sip_create_serializer(const char *name)
Create a new serializer for SIP tasks.
Definition: res_pjsip.c:2094
#define ast_module_ref(mod)
Hold a reference to the module.
Definition: module.h:457
static void subscription_tree_destructor(void *obj)
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
struct ast_module * self
Definition: module.h:356
A tree of SIP subscriptions.
struct ast_sip_endpoint * endpoint
struct ast_taskprocessor * serializer
void ast_taskprocessor_build_name(char *buf, unsigned int size, const char *format,...)
Build a taskprocessor name with a sequence number on the end.
#define AST_TASKPROCESSOR_MAX_NAME
Suggested maximum taskprocessor name length (less null terminator).
Definition: taskprocessor.h:61

References ao2_alloc, ao2_bump, ao2_ref, ast_module_ref, ast_sip_create_serializer(), ast_sip_get_distributor_serializer(), ast_sorcery_object_get_id(), ast_taskprocessor_build_name(), AST_TASKPROCESSOR_MAX_NAME, sip_subscription_tree::endpoint, sip_subscription_tree::notify_sched_id, NULL, ast_module_info::self, sip_subscription_tree::serializer, and subscription_tree_destructor().

Referenced by ast_sip_create_subscription(), and create_subscription_tree().

◆ allocate_tdata_buffer()

static int allocate_tdata_buffer ( pjsip_tx_data *  tdata)
static

Pre-allocate a buffer for the transmission.

Typically, we let PJSIP do this step for us when we send a request. PJSIP's buffer allocation algorithm is to allocate a buffer of PJSIP_MAX_PKT_LEN bytes and attempt to write the packet to the allocated buffer. If the buffer is too small to hold the packet, then we get told the message is too long to be sent.

When dealing with SIP NOTIFY, especially with RLS, it is possible to exceed PJSIP_MAX_PKT_LEN. Rather than accepting the limitation imposed on us by default, we instead take the strategy of pre-allocating the buffer, testing for ourselves if the message will fit, and resizing the buffer as required.

The limit we impose is double that of the maximum packet length.

Parameters
tdataThe tdata onto which to allocate a buffer
Return values
0Success
-1The message is too large

Definition at line 2008 of file res_pjsip_pubsub.c.

2009{
2010 int buf_size;
2011 int size = -1;
2012 char *buf;
2013
2014 for (buf_size = PJSIP_MAX_PKT_LEN; size == -1 && buf_size < (PJSIP_MAX_PKT_LEN * 2); buf_size *= 2) {
2015 buf = pj_pool_alloc(tdata->pool, buf_size);
2016 size = pjsip_msg_print(tdata->msg, buf, buf_size);
2017 }
2018
2019 if (size == -1) {
2020 return -1;
2021 }
2022
2023 tdata->buf.start = buf;
2024 tdata->buf.cur = tdata->buf.start;
2025 tdata->buf.end = tdata->buf.start + buf_size;
2026
2027 return 0;
2028}
char buf[BUFSIZE]
Definition: eagi_proxy.c:66

References buf.

Referenced by sip_subscription_send_request().

◆ ami_show_resource_lists()

static int ami_show_resource_lists ( struct mansession s,
const struct message m 
)
static

Definition at line 4351 of file res_pjsip_pubsub.c.

4352{
4353 struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
4354 struct ao2_container *lists;
4355
4356 lists = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "resource_list",
4358
4359 if (!lists || !ao2_container_count(lists)) {
4360 astman_send_error(s, m, "No resource lists found\n");
4361 return 0;
4362 }
4363
4364 astman_send_listack(s, m, "A listing of resource lists follows, presented as ResourceListDetail events",
4365 "start");
4366
4368
4369 astman_send_list_complete_start(s, m, "ResourceListDetailComplete", ami.count);
4371 return 0;
4372}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
@ OBJ_NODATA
Definition: astobj2.h:1044
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition: manager.c:2011
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:1969
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition: manager.c:2047
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition: manager.c:1630
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition: manager.c:2055
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
static int format_ami_resource_lists(void *obj, void *arg, int flags)
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition: sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition: sorcery.h:123
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.
Definition: sorcery.c:1897
Generic container type.
AMI variable container.
Definition: res_pjsip.h:3047
struct mansession * s
Definition: res_pjsip.h:3049
const struct message * m
Definition: res_pjsip.h:3051

References ao2_callback, ao2_container_count(), AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sip_get_sorcery(), ast_sorcery_retrieve_by_fields(), astman_get_header(), astman_send_error(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), ast_sip_ami::count, format_ami_resource_lists(), ast_sip_ami::m, NULL, OBJ_NODATA, and ast_sip_ami::s.

Referenced by load_module().

◆ ami_show_subscriptions_inbound()

static int ami_show_subscriptions_inbound ( struct mansession s,
const struct message m 
)
static

Definition at line 4301 of file res_pjsip_pubsub.c.

4302{
4303 struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
4304
4305 astman_send_listack(s, m, "Following are Events for each inbound Subscription",
4306 "start");
4307
4309
4310 astman_send_list_complete_start(s, m, "InboundSubscriptionDetailComplete", ami.count);
4312 return 0;
4313}
static int ami_subscription_detail_inbound(struct sip_subscription_tree *sub_tree, void *arg)
static int for_each_subscription(on_subscription_t on_subscription, void *arg)

References ami_subscription_detail_inbound(), astman_get_header(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), ast_sip_ami::count, for_each_subscription(), ast_sip_ami::m, and ast_sip_ami::s.

Referenced by load_module().

◆ ami_show_subscriptions_outbound()

static int ami_show_subscriptions_outbound ( struct mansession s,
const struct message m 
)
static

Definition at line 4315 of file res_pjsip_pubsub.c.

4316{
4317 struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
4318
4319 astman_send_listack(s, m, "Following are Events for each outbound Subscription",
4320 "start");
4321
4323
4324 astman_send_list_complete_start(s, m, "OutboundSubscriptionDetailComplete", ami.count);
4326 return 0;
4327}
static int ami_subscription_detail_outbound(struct sip_subscription_tree *sub_tree, void *arg)

References ami_subscription_detail_outbound(), astman_get_header(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), ast_sip_ami::count, for_each_subscription(), ast_sip_ami::m, and ast_sip_ami::s.

Referenced by load_module().

◆ ami_subscription_detail()

static int ami_subscription_detail ( struct sip_subscription_tree sub_tree,
struct ast_sip_ami ami,
const char *  event 
)
static

Definition at line 4270 of file res_pjsip_pubsub.c.

4273{
4274 struct ast_str *buf;
4275
4277 if (!buf) {
4278 return -1;
4279 }
4280
4281 sip_subscription_to_ami(sub_tree, &buf);
4282 astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
4283 ast_free(buf);
4284
4285 ++ami->count;
4286 return 0;
4287}
#define ast_free(a)
Definition: astmm.h:180
void astman_append(struct mansession *s, const char *fmt,...)
Definition: manager.c:1890
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
static void sip_subscription_to_ami(struct sip_subscription_tree *sub_tree, struct ast_str **buf)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
Support for dynamic strings.
Definition: strings.h:623
Definition: astman.c:222

References ast_free, ast_sip_create_ami_event(), ast_str_buffer(), astman_append(), buf, ast_sip_ami::count, ast_sip_ami::s, and sip_subscription_to_ami().

Referenced by ami_subscription_detail_inbound(), and ami_subscription_detail_outbound().

◆ ami_subscription_detail_inbound()

static int ami_subscription_detail_inbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4289 of file res_pjsip_pubsub.c.

4290{
4291 return sub_tree->role == AST_SIP_NOTIFIER ? ami_subscription_detail(
4292 sub_tree, arg, "InboundSubscriptionDetail") : 0;
4293}
static int ami_subscription_detail(struct sip_subscription_tree *sub_tree, struct ast_sip_ami *ami, const char *event)
@ AST_SIP_NOTIFIER
enum ast_sip_subscription_role role

References ami_subscription_detail(), AST_SIP_NOTIFIER, and sip_subscription_tree::role.

Referenced by ami_show_subscriptions_inbound().

◆ ami_subscription_detail_outbound()

static int ami_subscription_detail_outbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4295 of file res_pjsip_pubsub.c.

4296{
4297 return sub_tree->role == AST_SIP_SUBSCRIBER ? ami_subscription_detail(
4298 sub_tree, arg, "OutboundSubscriptionDetail") : 0;
4299}
@ AST_SIP_SUBSCRIBER

References ami_subscription_detail(), AST_SIP_SUBSCRIBER, and sip_subscription_tree::role.

Referenced by ami_show_subscriptions_outbound().

◆ apply_list_configuration()

static int apply_list_configuration ( struct ast_sorcery sorcery)
static

Definition at line 5100 of file res_pjsip_pubsub.c.

5101{
5102 ast_sorcery_apply_default(sorcery, "resource_list", "config",
5103 "pjsip.conf,criteria=type=resource_list");
5106 return -1;
5107 }
5108
5109 ast_sorcery_object_field_register(sorcery, "resource_list", "type", "",
5110 OPT_NOOP_T, 0, 0);
5111 ast_sorcery_object_field_register(sorcery, "resource_list", "event", "",
5113 ast_sorcery_object_field_register(sorcery, "resource_list", "full_state", "no",
5114 OPT_BOOL_T, 1, FLDSET(struct resource_list, full_state));
5115 ast_sorcery_object_field_register(sorcery, "resource_list", "notification_batch_interval",
5116 "0", OPT_UINT_T, 0, FLDSET(struct resource_list, notification_batch_interval));
5117 ast_sorcery_object_field_register_custom(sorcery, "resource_list", "list_item",
5119 ast_sorcery_object_field_register(sorcery, "resource_list", "resource_display_name", "no",
5120 OPT_BOOL_T, 1, FLDSET(struct resource_list, resource_display_name));
5121
5122 ast_sorcery_reload_object(sorcery, "resource_list");
5123
5124 return 0;
5125}
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
#define CHARFLDSET(type, field)
A helper macro to pass the appropriate arguments to aco_option_register for OPT_CHAR_ARRAY_T.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_CHAR_ARRAY_T
Type for default option handler for character array strings.
static struct ast_sorcery * sorcery
static int resource_list_apply_handler(const struct ast_sorcery *sorcery, void *obj)
static int list_item_to_str(const void *obj, const intptr_t *args, char **buf)
static int list_item_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
static void * resource_list_alloc(const char *name)
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
#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.
Definition: sorcery.h:1005
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
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.
Definition: sorcery.c:1442
Resource list configuration item.

References ast_sorcery_apply_default, ast_sorcery_object_field_register, ast_sorcery_object_field_register_custom, ast_sorcery_object_register, ast_sorcery_reload_object(), CHARFLDSET, FLDSET, resource_list::full_state, list_item_handler(), list_item_to_str(), resource_list::notification_batch_interval, NULL, OPT_BOOL_T, OPT_CHAR_ARRAY_T, OPT_NOOP_T, OPT_UINT_T, resource_list::resource_display_name, resource_list_alloc(), resource_list_apply_handler(), and sorcery.

Referenced by load_module().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 5960 of file res_pjsip_pubsub.c.

◆ ast_sip_create_subscription()

struct ast_sip_subscription * ast_sip_create_subscription ( const struct ast_sip_subscription_handler handler,
struct ast_sip_endpoint endpoint,
const char *  resource 
)

Create a new ast_sip_subscription structure.

When a subscriber wishes to create a subscription, it may call this function to allocate resources and to send the initial SUBSCRIBE out.

Parameters
handlerThe subscriber that is making the request.
endpointThe endpoint to whome the SUBSCRIBE will be sent.
resourceThe resource to place in the SUBSCRIBE's Request-URI.

Definition at line 1909 of file res_pjsip_pubsub.c.

1911{
1912 struct ast_sip_subscription *sub;
1913 pjsip_dialog *dlg;
1914 struct ast_sip_contact *contact;
1915 pj_str_t event;
1916 pjsip_tx_data *tdata;
1917 pjsip_evsub *evsub;
1918 struct sip_subscription_tree *sub_tree = NULL;
1919
1921 if (!sub_tree) {
1922 return NULL;
1923 }
1924
1925 sub = allocate_subscription(handler, resource, NULL, sub_tree);
1926 if (!sub) {
1927 ao2_cleanup(sub_tree);
1928 return NULL;
1929 }
1930
1932 if (!contact || ast_strlen_zero(contact->uri)) {
1933 ast_log(LOG_WARNING, "No contacts configured for endpoint %s. Unable to create SIP subsription\n",
1935 ao2_ref(sub_tree, -1);
1936 ao2_cleanup(contact);
1937 return NULL;
1938 }
1939
1941 ao2_cleanup(contact);
1942 if (!dlg) {
1943 ast_log(LOG_WARNING, "Unable to create dialog for SIP subscription\n");
1944 ao2_ref(sub_tree, -1);
1945 return NULL;
1946 }
1947
1948 pj_cstr(&event, handler->event_name);
1949 pjsip_evsub_create_uac(dlg, &pubsub_cb, &event, 0, &sub_tree->evsub);
1950 subscription_setup_dialog(sub_tree, dlg);
1951
1952 evsub = sub_tree->evsub;
1953
1954 if (pjsip_evsub_initiate(evsub, NULL, -1, &tdata) == PJ_SUCCESS) {
1955 pjsip_evsub_send_request(sub_tree->evsub, tdata);
1956 } else {
1957 /* pjsip_evsub_terminate will result in pubsub_on_evsub_state,
1958 * being called and terminating the subscription. Therefore, we don't
1959 * need to decrease the reference count of sub here.
1960 */
1961 pjsip_evsub_terminate(evsub, PJ_TRUE);
1962 ao2_ref(sub_tree, -1);
1963 return NULL;
1964 }
1965
1966 add_subscription(sub_tree);
1967
1968 return sub;
1969}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define LOG_WARNING
struct ast_sip_contact * ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list)
Retrieve the first bound contact from a list of AORs.
Definition: location.c:304
pjsip_dialog * ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user)
General purpose method for creating a UAC dialog with an endpoint.
Definition: res_pjsip.c:964
static struct ast_sip_subscription * allocate_subscription(const struct ast_sip_subscription_handler *handler, const char *resource, const char *display_name, struct sip_subscription_tree *tree)
static pjsip_evsub_user pubsub_cb
static void add_subscription(struct sip_subscription_tree *obj)
static void subscription_setup_dialog(struct sip_subscription_tree *sub_tree, pjsip_dialog *dlg)
static struct sip_subscription_tree * allocate_subscription_tree(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Contact associated with an address of record.
Definition: res_pjsip.h:392
const ast_string_field uri
Definition: res_pjsip.h:414
const ast_string_field aors
Definition: res_pjsip.h:992

References add_subscription(), allocate_subscription(), allocate_subscription_tree(), ao2_cleanup, ao2_ref, ast_sip_endpoint::aors, ast_log, ast_sip_create_dialog_uac(), ast_sip_location_retrieve_contact_from_aor_list(), ast_sorcery_object_get_id(), ast_strlen_zero(), sip_subscription_tree::dlg, sip_subscription_tree::endpoint, sip_subscription_tree::evsub, handler(), LOG_WARNING, NULL, pubsub_cb, sub, subscription_setup_dialog(), and ast_sip_contact::uri.

◆ ast_sip_publication_add_datastore()

int ast_sip_publication_add_datastore ( struct ast_sip_publication publication,
struct ast_datastore datastore 
)

Add a datastore to a SIP publication.

Note that SIP uses reference counted datastores. The datastore passed into this function must have been allocated using ao2_alloc() or there will be serious problems.

Parameters
publicationThe publication to add the datastore to
datastoreThe datastore to be added to the subscription
Return values
0Success
-1Failure

Definition at line 2713 of file res_pjsip_pubsub.c.

2714{
2715 return ast_datastores_add(publication->datastores, datastore);
2716}
int ast_datastores_add(struct ao2_container *datastores, struct ast_datastore *datastore)
Add a data store to a container.
Definition: datastore.c:105
struct ao2_container * datastores

References ast_datastores_add(), and ast_sip_publication::datastores.

◆ ast_sip_publication_get_datastore()

struct ast_datastore * ast_sip_publication_get_datastore ( struct ast_sip_publication publication,
const char *  name 
)

Retrieve a publication datastore.

The datastore retrieved will have its reference count incremented. When the caller is done with the datastore, the reference counted needs to be decremented using ao2_ref().

Parameters
publicationThe publication from which to retrieve the datastore
nameThe name of the datastore to retrieve
Return values
NULLFailed to find the specified datastore
non-NULLThe specified datastore

Definition at line 2718 of file res_pjsip_pubsub.c.

2719{
2720 return ast_datastores_find(publication->datastores, name);
2721}
struct ast_datastore * ast_datastores_find(struct ao2_container *datastores, const char *name)
Find a data store in a container.
Definition: datastore.c:123

References ast_datastores_find(), ast_sip_publication::datastores, and name.

◆ ast_sip_publication_get_datastores()

struct ao2_container * ast_sip_publication_get_datastores ( const struct ast_sip_publication publication)

Get the datastores container for a publication.

Parameters
publicationThe publication to get the datastores container from
Return values
NULLdatastores container not present
non-NULLdatastores container
Note
The container is NOT returned with reference count bumped
Since
14.0.0

Definition at line 2728 of file res_pjsip_pubsub.c.

2729{
2730 return publication->datastores;
2731}

References ast_sip_publication::datastores.

◆ ast_sip_publication_get_endpoint()

struct ast_sip_endpoint * ast_sip_publication_get_endpoint ( struct ast_sip_publication pub)

Given a publication, get the associated endpoint.

Parameters
pubThe publication
Return values
NULLFailure
non-NULLThe associated endpoint

Definition at line 3487 of file res_pjsip_pubsub.c.

3488{
3489 return pub->endpoint;
3490}
struct ast_sip_endpoint * endpoint
The endpoint with which the subscription is communicating.

References ast_sip_publication::endpoint.

◆ ast_sip_publication_get_event_configuration()

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.

Parameters
pubThe publication
Returns
The configuration name

Definition at line 3497 of file res_pjsip_pubsub.c.

3498{
3499 return pub->event_configuration_name;
3500}
char * event_configuration_name
The name of the event type configuration.

References ast_sip_publication::event_configuration_name.

Referenced by asterisk_publication_devicestate_state_change(), and asterisk_publication_mwi_state_change().

◆ ast_sip_publication_get_resource()

const char * ast_sip_publication_get_resource ( const struct ast_sip_publication pub)

Given a publication, get the resource the publication is to.

Parameters
pubThe publication
Returns
The resource

Definition at line 3492 of file res_pjsip_pubsub.c.

3493{
3494 return pub->resource;
3495}
char * resource
The resource the publication is to.

References ast_sip_publication::resource.

◆ ast_sip_publication_remove_datastore()

void ast_sip_publication_remove_datastore ( struct ast_sip_publication publication,
const char *  name 
)

Remove a publication datastore from the publication.

This operation may cause the datastore's free() callback to be called if the reference count reaches zero.

Parameters
publicationThe publication to remove the datastore from
nameThe name of the datastore to remove

Definition at line 2723 of file res_pjsip_pubsub.c.

2724{
2725 ast_datastores_remove(publication->datastores, name);
2726}
void ast_datastores_remove(struct ao2_container *datastores, const char *name)
Remove a data store from a container.
Definition: datastore.c:118

References ast_datastores_remove(), ast_sip_publication::datastores, and name.

◆ ast_sip_pubsub_generate_body_content()

int ast_sip_pubsub_generate_body_content ( const char *  content_type,
const char *  content_subtype,
struct ast_sip_body_data data,
struct ast_str **  str 
)

Generate body content for a PUBLISH or NOTIFY.

Since
13.0.0

This function takes a pre-allocated body and calls into registered body generators in order to fill in the body with appropriate details. The primary body generator will be called first, followed by the supplementary body generators

Parameters
content_typeThe content type of the body
content_subtypeThe content subtype of the body
dataThe data associated with body generation.
[out]strThe string representation of the generated body
Return values
0Success
non-zeroFailure

Definition at line 3586 of file res_pjsip_pubsub.c.

3588{
3589 struct ast_sip_pubsub_body_supplement *supplement;
3590 struct ast_sip_pubsub_body_generator *generator;
3591 int res = 0;
3592 void *body;
3593
3595 if (!generator) {
3596 ast_log(LOG_WARNING, "Unable to find a body generator for %s/%s\n",
3597 type, subtype);
3598 return -1;
3599 }
3600
3601 if (strcmp(data->body_type, generator->body_type)) {
3602 ast_log(LOG_WARNING, "%s/%s body generator does not accept the type of data provided\n",
3603 type, subtype);
3604 return -1;
3605 }
3606
3607 body = generator->allocate_body(data->body_data);
3608 if (!body) {
3609 ast_log(LOG_WARNING, "%s/%s body generator could not to allocate a body\n",
3610 type, subtype);
3611 return -1;
3612 }
3613
3614 if (generator->generate_body_content(body, data->body_data)) {
3615 res = -1;
3616 goto end;
3617 }
3618
3621 if (!strcmp(generator->type, supplement->type) &&
3622 !strcmp(generator->subtype, supplement->subtype)) {
3623 res = supplement->supplement_body(body, data->body_data);
3624 if (res) {
3625 break;
3626 }
3627 }
3628 }
3630
3631 if (!res) {
3632 generator->to_string(body, str);
3633 }
3634
3635end:
3636 if (generator->destroy_body) {
3637 generator->destroy_body(body);
3638 }
3639
3640 return res;
3641}
const char * str
Definition: app_jack.c:147
static const char type[]
Definition: chan_ooh323.c:109
char * end
Definition: eagi_proxy.c:73
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype(const char *type, const char *subtype)
const char * body_type
Pubsub body generator.
void(* to_string)(void *body, struct ast_str **str)
Convert the body to a string.
void(* destroy_body)(void *body)
Deallocate resources created for the body.
struct ast_sip_pubsub_body_generator::@261 list
const char * type
Content type In "plain/text", "plain" is the type.
const char * subtype
Content subtype In "plain/text", "text" is the subtype.
void *(* allocate_body)(void *data)
allocate body structure.
int(* generate_body_content)(void *body, void *data)
Add content to the body of a SIP request.
int(* supplement_body)(void *body, void *data)
Add additional content to a SIP request body.
const char * type
Content type In "plain/text", "plain" is the type.
const char * subtype
Content subtype In "plain/text", "text" is the subtype.

References ast_sip_pubsub_body_generator::allocate_body, ast_log, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_sip_body_data::body_data, ast_sip_body_data::body_type, ast_sip_pubsub_body_generator::body_type, ast_sip_pubsub_body_generator::destroy_body, end, find_body_generator_type_subtype(), ast_sip_pubsub_body_generator::generate_body_content, ast_sip_pubsub_body_generator::list, LOG_WARNING, str, ast_sip_pubsub_body_generator::subtype, ast_sip_pubsub_body_supplement::subtype, ast_sip_pubsub_body_supplement::supplement_body, ast_sip_pubsub_body_generator::to_string, type, ast_sip_pubsub_body_generator::type, and ast_sip_pubsub_body_supplement::type.

Referenced by ast_sip_subscription_notify(), exten_state_publisher_cb(), generate_initial_notify(), and send_unsolicited_mwi_notify_to_contact().

◆ ast_sip_pubsub_has_eventlist_support()

static int ast_sip_pubsub_has_eventlist_support ( pjsip_rx_data *  rdata)
static

Check if the rdata has a Supported header containing 'eventlist'.

Return values
1rdata has an eventlist containing supported header
0rdata doesn't have an eventlist containing supported header

Definition at line 882 of file res_pjsip_pubsub.c.

883{
884 pjsip_supported_hdr *supported_header = (pjsip_supported_hdr *) &rdata->msg_info.msg->hdr;
885
886 while ((supported_header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_SUPPORTED, supported_header->next))) {
887 int i;
888
889 for (i = 0; i < supported_header->count; i++) {
890 if (!pj_stricmp2(&supported_header->values[i], "eventlist")) {
891 return 1;
892 }
893 }
894 }
895
896 return 0;
897}
while(1)
Definition: ast_expr2f.c:880

References while().

Referenced by pubsub_on_rx_refresh(), pubsub_on_rx_subscribe_request(), and sub_persistence_recreate().

◆ ast_sip_pubsub_is_body_generator_registered()

int ast_sip_pubsub_is_body_generator_registered ( const char *  type,
const char *  subtype 
)

Is a body generator registered for the given type/subtype.

Since
14.0.0
Parameters
typeThe content type of the body
subtypeThe content subtype of the body
Note
In "plain/text", "plain" is the type and "text" is the subtype.
Return values
non-zeroif a generator is registered.

Definition at line 3502 of file res_pjsip_pubsub.c.

3503{
3504 return !!find_body_generator_type_subtype(type, subtype);
3505}

References find_body_generator_type_subtype(), and type.

Referenced by publisher_start().

◆ ast_sip_pubsub_register_body_generator()

int ast_sip_pubsub_register_body_generator ( struct ast_sip_pubsub_body_generator generator)

Register a body generator with the pubsub core.

Since
13.0.0

This may fail if an attempt is made to register a primary body supplement for a given content type if a primary body supplement for that content type has already been registered.

Parameters
generatorBody generator to register
Return values
0Success
-1Failure

Definition at line 3507 of file res_pjsip_pubsub.c.

3508{
3509 struct ast_sip_pubsub_body_generator *existing;
3510 pj_str_t accept;
3511 pj_size_t accept_len;
3512
3514 existing = find_body_generator_type_subtype_nolock(generator->type, generator->subtype);
3515 if (existing) {
3517 ast_log(LOG_WARNING, "A body generator for %s/%s is already registered.\n",
3518 generator->type, generator->subtype);
3519 return -1;
3520 }
3523
3524 /* Lengths of type and subtype plus a slash. */
3525 accept_len = strlen(generator->type) + strlen(generator->subtype) + 1;
3526
3527 /* Add room for null terminator that sprintf() will set. */
3528 pj_strset(&accept, ast_alloca(accept_len + 1), accept_len);
3529 sprintf((char *) pj_strbuf(&accept), "%s/%s", generator->type, generator->subtype);/* Safe */
3530
3531 pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), &pubsub_module,
3532 PJSIP_H_ACCEPT, NULL, 1, &accept);
3533
3534 return 0;
3535}
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:711
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:520
static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype_nolock(const char *type, const char *subtype)

References ast_alloca, AST_LIST_INSERT_HEAD, ast_log, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_sip_get_pjsip_endpoint(), find_body_generator_type_subtype_nolock(), ast_sip_pubsub_body_generator::list, LOG_WARNING, NULL, pubsub_module, ast_sip_pubsub_body_generator::subtype, and ast_sip_pubsub_body_generator::type.

Referenced by load_module().

◆ ast_sip_pubsub_register_body_supplement()

int ast_sip_pubsub_register_body_supplement ( struct ast_sip_pubsub_body_supplement supplement)

Register a body generator with the pubsub core.

Since
13.0.0

This may fail if an attempt is made to register a primary body supplement for a given content type if a primary body supplement for that content type has already been registered.

Parameters
supplementBody generator to register
Return values
0Success
-1Failure

Definition at line 3552 of file res_pjsip_pubsub.c.

3553{
3555 AST_RWLIST_INSERT_TAIL(&body_supplements, supplement, list);
3557
3558 return 0;
3559}

References AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_sip_pubsub_body_generator::list.

Referenced by load_module().

◆ ast_sip_pubsub_unregister_body_generator()

void ast_sip_pubsub_unregister_body_generator ( struct ast_sip_pubsub_body_generator generator)

Unregister a body generator with the pubsub core.

Since
13.0.0
Parameters
generatorBody generator to unregister

Definition at line 3537 of file res_pjsip_pubsub.c.

3538{
3539 struct ast_sip_pubsub_body_generator *iter;
3540
3543 if (iter == generator) {
3545 break;
3546 }
3547 }
3550}
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557

References AST_LIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_sip_pubsub_body_generator::list.

Referenced by unload_module(), and unregister_all().

◆ ast_sip_pubsub_unregister_body_supplement()

void ast_sip_pubsub_unregister_body_supplement ( struct ast_sip_pubsub_body_supplement supplement)

Unregister a body generator with the pubsub core.

Since
13.0.0
Parameters
supplementBody generator to unregister

Definition at line 3561 of file res_pjsip_pubsub.c.

3562{
3563 struct ast_sip_pubsub_body_supplement *iter;
3564
3567 if (iter == supplement) {
3569 break;
3570 }
3571 }
3574}
struct ast_sip_pubsub_body_supplement::@262 list

References AST_LIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_sip_pubsub_body_supplement::list.

Referenced by unload_module().

◆ ast_sip_register_publish_handler()

int ast_sip_register_publish_handler ( struct ast_sip_publish_handler handler)

Register a publish handler.

Return values
0Handler was registered successfully
non-zeroHandler was not registered successfully

Definition at line 2782 of file res_pjsip_pubsub.c.

2783{
2784 if (ast_strlen_zero(handler->event_name)) {
2785 ast_log(LOG_ERROR, "No event package specified for publish handler. Cannot register\n");
2786 return -1;
2787 }
2788
2791 if (!handler->publications) {
2792 ast_log(LOG_ERROR, "Could not allocate publications container for event '%s'\n",
2793 handler->event_name);
2794 return -1;
2795 }
2796
2798
2799 return 0;
2800}
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
static int publication_hash_fn(const void *obj, const int flags)
static int publication_cmp_fn(void *obj, void *arg, int flags)
#define PUBLICATIONS_BUCKETS
Number of buckets for publications (on a per handler)
static void publish_add_handler(struct ast_sip_publish_handler *handler)

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_log, ast_strlen_zero(), handler(), LOG_ERROR, NULL, publication_cmp_fn(), publication_hash_fn(), PUBLICATIONS_BUCKETS, and publish_add_handler().

Referenced by load_module().

◆ ast_sip_register_subscription_handler()

int ast_sip_register_subscription_handler ( struct ast_sip_subscription_handler handler)

Register a subscription handler.

Return values
0Handler was registered successfully
non-zeroHandler was not registered successfully

Definition at line 2841 of file res_pjsip_pubsub.c.

2842{
2843 pj_str_t event;
2844 pj_str_t accept[AST_SIP_MAX_ACCEPT] = { {0, }, };
2845 struct ast_sip_subscription_handler *existing;
2846 int i = 0;
2847
2848 if (ast_strlen_zero(handler->event_name)) {
2849 ast_log(LOG_ERROR, "No event package specified for subscription handler. Cannot register\n");
2850 return -1;
2851 }
2852
2853 existing = find_sub_handler_for_event_name(handler->event_name);
2854 if (existing) {
2856 "Unable to register subscription handler for event %s. A handler is already registered\n",
2857 handler->event_name);
2858 return -1;
2859 }
2860
2861 for (i = 0; i < AST_SIP_MAX_ACCEPT && !ast_strlen_zero(handler->accept[i]); ++i) {
2862 pj_cstr(&accept[i], handler->accept[i]);
2863 }
2864
2865 pj_cstr(&event, handler->event_name);
2866
2867 pjsip_evsub_register_pkg(&pubsub_module, &event, DEFAULT_EXPIRES, i, accept);
2868
2870
2871 return 0;
2872}
static struct ast_sip_subscription_handler * find_sub_handler_for_event_name(const char *event_name)
static void sub_add_handler(struct ast_sip_subscription_handler *handler)
#define DEFAULT_EXPIRES
Default expiration for subscriptions.
#define AST_SIP_MAX_ACCEPT
const char * accept[AST_SIP_MAX_ACCEPT]

References ast_sip_subscription_handler::accept, ast_log, AST_SIP_MAX_ACCEPT, ast_strlen_zero(), DEFAULT_EXPIRES, find_sub_handler_for_event_name(), handler(), LOG_ERROR, pubsub_module, and sub_add_handler().

Referenced by load_module().

◆ ast_sip_subscription_add_datastore()

int ast_sip_subscription_add_datastore ( struct ast_sip_subscription subscription,
struct ast_datastore datastore 
)

Add a datastore to a SIP subscription.

Note that SIP uses reference counted datastores. The datastore passed into this function must have been allocated using ao2_alloc() or there will be serious problems.

Parameters
subscriptionThe ssubscription to add the datastore to
datastoreThe datastore to be added to the subscription
Return values
0Success
-1Failure

Definition at line 2693 of file res_pjsip_pubsub.c.

2694{
2695 return ast_datastores_add(subscription->datastores, datastore);
2696}
struct ao2_container * datastores

References ast_datastores_add(), and ast_sip_subscription::datastores.

Referenced by add_datastore(), and add_mwi_datastore().

◆ ast_sip_subscription_alloc_datastore()

struct ast_datastore * ast_sip_subscription_alloc_datastore ( const struct ast_datastore_info info,
const char *  uid 
)

Alternative for ast_datastore_alloc()

There are two major differences between this and ast_datastore_alloc() 1) This allocates a refcounted object 2) This will fill in a uid if one is not provided

DO NOT call ast_datastore_free() on a datastore allocated in this way since that function will attempt to free the datastore rather than play nicely with its refcount.

Parameters
infoCallbacks for datastore
uidIdentifier for datastore
Return values
NULLFailed to allocate datastore
non-NULLNewly allocated datastore

Definition at line 2688 of file res_pjsip_pubsub.c.

2689{
2691}
struct ast_datastore * ast_datastores_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
Allocate a datastore for use with the datastores container.
Definition: datastore.c:142
def info(msg)

References ast_datastores_alloc_datastore(), sip_to_pjsip::info(), and ast_datastore::uid.

Referenced by add_datastore(), and add_mwi_datastore().

◆ ast_sip_subscription_destroy()

void ast_sip_subscription_destroy ( struct ast_sip_subscription sub)

Alert the pubsub core that the subscription is ready for destruction.

Since
13.6.0
Parameters
subThe subscription that is complete

Definition at line 1429 of file res_pjsip_pubsub.c.

1430{
1431 ast_debug(3, "Removing subscription %p '%s->%s' reference to subscription tree %p\n",
1432 sub, ast_sorcery_object_get_id(sub->tree->endpoint), sub->resource, sub->tree);
1433 ao2_cleanup(sub->tree);
1434}
#define ast_debug(level,...)
Log a DEBUG message.

References ao2_cleanup, ast_debug, ast_sorcery_object_get_id(), and sub.

Referenced by exten_state_subscription_destructor(), and mwi_subscription_destructor().

◆ ast_sip_subscription_get_body_subtype()

const char * ast_sip_subscription_get_body_subtype ( struct ast_sip_subscription sub)

Get the body subtype used for this subscription.

Since
13.0.0

Definition at line 3581 of file res_pjsip_pubsub.c.

3582{
3583 return sub->body_generator->subtype;
3584}

References sub.

Referenced by ast_sip_subscription_notify(), generate_initial_notify(), and generate_notify_body().

◆ ast_sip_subscription_get_body_type()

const char * ast_sip_subscription_get_body_type ( struct ast_sip_subscription sub)

Get the body type used for this subscription.

Since
13.0.0

Definition at line 3576 of file res_pjsip_pubsub.c.

3577{
3578 return sub->body_generator->type;
3579}

References sub.

Referenced by ast_sip_subscription_notify(), generate_initial_notify(), and generate_notify_body().

◆ ast_sip_subscription_get_datastore()

struct ast_datastore * ast_sip_subscription_get_datastore ( struct ast_sip_subscription subscription,
const char *  name 
)

Retrieve a subscription datastore.

The datastore retrieved will have its reference count incremented. When the caller is done with the datastore, the reference counted needs to be decremented using ao2_ref().

Parameters
subscriptionThe subscription from which to retrieve the datastore
nameThe name of the datastore to retrieve
Return values
NULLFailed to find the specified datastore
non-NULLThe specified datastore

Definition at line 2698 of file res_pjsip_pubsub.c.

2699{
2700 return ast_datastores_find(subscription->datastores, name);
2701}

References ast_datastores_find(), ast_sip_subscription::datastores, and name.

Referenced by get_exten_state_sub(), mwi_get_notify_data(), mwi_subscription_shutdown(), and mwi_to_ami().

◆ ast_sip_subscription_get_datastores()

struct ao2_container * ast_sip_subscription_get_datastores ( const struct ast_sip_subscription subscription)

Get the datastores container for a subscription.

Parameters
subscriptionThe subscription to get the datastores container from
Return values
NULLdatastores container not present
non-NULLdatastores container
Note
The container is NOT returned with reference count bumped
Since
14.0.0

Definition at line 2708 of file res_pjsip_pubsub.c.

2709{
2710 return subscription->datastores;
2711}

References ast_sip_subscription::datastores.

Referenced by alloc_notify_task_data(), exten_state_data_alloc(), and notify_task().

◆ ast_sip_subscription_get_dialog()

pjsip_dialog * ast_sip_subscription_get_dialog ( struct ast_sip_subscription sub)

Get the pjsip dialog that is associated with this subscription.

Since
13.9.0
Return values
NULLCould not get dialog
non-NULLThe dialog

Definition at line 1971 of file res_pjsip_pubsub.c.

1972{
1973 ast_assert(sub->tree->dlg != NULL);
1974 return sub->tree->dlg;
1975}
#define ast_assert(a)
Definition: utils.h:739

References ast_assert, NULL, and sub.

Referenced by dialog_info_generate_body_content(), mwi_get_notify_data(), and send_mwi_notify().

◆ ast_sip_subscription_get_endpoint()

struct ast_sip_endpoint * ast_sip_subscription_get_endpoint ( struct ast_sip_subscription sub)

Get the endpoint that is associated with this subscription.

This function will increase the reference count of the endpoint. Be sure to release the reference to it when you are finished with the endpoint.

Return values
NULLCould not get endpoint
non-NULLThe endpoint

Definition at line 1977 of file res_pjsip_pubsub.c.

1978{
1979 ast_assert(sub->tree->endpoint != NULL);
1980 return ao2_bump(sub->tree->endpoint);
1981}

References ao2_bump, ast_assert, NULL, and sub.

Referenced by dialog_info_generate_body_content(), mwi_get_notify_data(), mwi_subscription_established(), send_mwi_notify(), and subscription_established().

◆ ast_sip_subscription_get_header()

void * ast_sip_subscription_get_header ( const struct ast_sip_subscription sub,
const char *  header 
)

Get a header value for a subscription.

For notifiers, the headers of the inbound SUBSCRIBE that started the dialog are stored on the subscription. This method allows access to the header. The return is the same as pjsip_msg_find_hdr_by_name(), meaning that it is dependent on the header being searched for.

Parameters
subThe subscription to search in.
headerThe name of the header to search for.
Returns
The discovered header, or NULL if the header cannot be found.

Definition at line 1895 of file res_pjsip_pubsub.c.

1896{
1897 pjsip_dialog *dlg;
1898 pjsip_msg *msg;
1899 pj_str_t name;
1900
1901 dlg = sub->tree->dlg;
1902 msg = ast_sip_mod_data_get(dlg->mod_data, pubsub_module.id, MOD_DATA_MSG);
1903 pj_cstr(&name, header);
1904
1905 return pjsip_msg_find_hdr_by_name(msg, &name, NULL);
1906}

References ast_sip_mod_data_get, MOD_DATA_MSG, name, NULL, pubsub_module, and sub.

Referenced by get_user_agent().

◆ ast_sip_subscription_get_local_uri()

void ast_sip_subscription_get_local_uri ( struct ast_sip_subscription sub,
char *  buf,
size_t  size 
)

Retrieve the local URI for this subscription.

This is the local URI of the subscribed resource.

Parameters
subThe subscription
[out]bufThe buffer into which to store the URI.
sizeThe size of the buffer.

Definition at line 2642 of file res_pjsip_pubsub.c.

2643{
2644 pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, sub->uri, buf, size);
2645}

References buf, and sub.

Referenced by build_rlmi_body(), exten_state_data_alloc(), and notify_task().

◆ ast_sip_subscription_get_persistence_data()

const struct ast_json * ast_sip_subscription_get_persistence_data ( const struct ast_sip_subscription subscription)

Retrieve persistence data for a subscription.

Since
13.31.0
16.8.0
17.2.0
Parameters
subscriptionThe subscription to retrieve persistence data from

Definition at line 2750 of file res_pjsip_pubsub.c.

2751{
2752 return subscription->persistence_data;
2753}
struct ast_json * persistence_data

References ast_sip_subscription::persistence_data.

Referenced by dialog_info_generate_body_content().

◆ ast_sip_subscription_get_remote_uri()

void ast_sip_subscription_get_remote_uri ( struct ast_sip_subscription sub,
char *  buf,
size_t  size 
)

Retrive the remote URI for this subscription.

This is the remote URI as determined by the underlying SIP dialog.

Parameters
subThe subscription
[out]bufThe buffer into which to store the URI.
sizeThe size of the buffer.

Definition at line 2647 of file res_pjsip_pubsub.c.

2648{
2649 pjsip_dialog *dlg;
2650 pjsip_sip_uri *uri;
2651
2652 dlg = sub->tree->dlg;
2653 uri = pjsip_uri_get_uri(dlg->remote.info->uri);
2654
2655 if (pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, uri, buf, size) < 0) {
2656 *buf = '\0';
2657 }
2658}

References buf, sip_subscription_tree::dlg, and sub.

Referenced by exten_state_data_alloc(), and notify_task().

◆ ast_sip_subscription_get_resource_name()

const char * ast_sip_subscription_get_resource_name ( struct ast_sip_subscription sub)

Get the name of the subscribed resource.

Definition at line 2660 of file res_pjsip_pubsub.c.

2661{
2662 return sub->resource;
2663}

References sub.

Referenced by build_rlmi_body(), mwi_get_notify_data(), mwi_subscription_established(), remove_subscription(), send_mwi_notify(), and subscription_established().

◆ ast_sip_subscription_get_serializer()

struct ast_taskprocessor * ast_sip_subscription_get_serializer ( struct ast_sip_subscription sub)

Get the serializer for the subscription.

Tasks that originate outside of a SIP servant thread should get the serializer and push the task to the serializer.

Parameters
subThe subscription
Return values
NULLFailure
non-NULLThe subscription's serializer

Definition at line 1983 of file res_pjsip_pubsub.c.

1984{
1985 ast_assert(sub->tree->serializer != NULL);
1986 return sub->tree->serializer;
1987}

References ast_assert, NULL, and sub.

Referenced by exten_state_subscription_alloc(), and send_notify().

◆ ast_sip_subscription_get_sip_uri()

pjsip_sip_uri * ast_sip_subscription_get_sip_uri ( struct ast_sip_subscription sub)

Retrieve the local sip uri for this subscription.

Since
13.9.0

This is the local sip URI of the subscribed resource.

Parameters
subThe subscription
Return values
NULLCould not get uri
non-NULLThe local pjsip_sip_uri

Definition at line 2637 of file res_pjsip_pubsub.c.

2638{
2639 return sub->uri;
2640}

References sub.

Referenced by mwi_get_notify_data(), and send_mwi_notify().

◆ ast_sip_subscription_is_terminated()

int ast_sip_subscription_is_terminated ( const struct ast_sip_subscription sub)

Get whether the subscription has been terminated or not.

Parameters
subThe subscription.
Return values
0not terminated.
1terminated.
Since
13.4.0

Definition at line 2665 of file res_pjsip_pubsub.c.

2666{
2667 return sub->subscription_state == PJSIP_EVSUB_STATE_TERMINATED ? 1 : 0;
2668}

References sub.

Referenced by notify_task(), and state_changed().

◆ ast_sip_subscription_notify()

int ast_sip_subscription_notify ( struct ast_sip_subscription sub,
struct ast_sip_body_data notify_data,
int  terminate 
)

Notify a SIP subscription of a state change.

This tells the pubsub core that the state of a subscribed resource has changed. The pubsub core will generate an appropriate NOTIFY request to send to the subscriber.

Parameters
subThe subscription on which a state change is occurring.
notify_dataEvent package-specific data used to create the NOTIFY body.
terminateTrue if this NOTIFY is intended to terminate the subscription.
Return values
0Success
non-zeroFailure

Definition at line 2593 of file res_pjsip_pubsub.c.

2595{
2596 int res;
2597 pjsip_dialog *dlg = sub->tree->dlg;
2598
2599 pjsip_dlg_inc_lock(dlg);
2600
2601 if (sub->tree->state != SIP_SUB_TREE_NORMAL) {
2602 pjsip_dlg_dec_lock(dlg);
2603 return 0;
2604 }
2605
2608 pjsip_dlg_dec_lock(dlg);
2609 return -1;
2610 }
2611
2612 sub->body_changed = 1;
2613 if (terminate) {
2614 sub->subscription_state = PJSIP_EVSUB_STATE_TERMINATED;
2615 sub->tree->state = SIP_SUB_TREE_TERMINATE_PENDING;
2616 }
2617
2618 if (sub->tree->notification_batch_interval) {
2619 res = schedule_notification(sub->tree);
2620 } else {
2621 /* See the note in pubsub_on_rx_refresh() for why sub->tree is refbumped here */
2622 ao2_ref(sub->tree, +1);
2623 if (terminate) {
2625 }
2626 res = send_notify(sub->tree, 0);
2627 ast_test_suite_event_notify(terminate ? "SUBSCRIPTION_TERMINATED" : "SUBSCRIPTION_STATE_CHANGED",
2628 "Resource: %s",
2629 sub->tree->root->resource);
2630 ao2_ref(sub->tree, -1);
2631 }
2632
2633 pjsip_dlg_dec_lock(dlg);
2634 return res;
2635}
const char * ast_sip_subscription_get_body_type(struct ast_sip_subscription *sub)
Get the body type used for this subscription.
static int schedule_notification(struct sip_subscription_tree *sub_tree)
const char * ast_sip_subscription_get_body_subtype(struct ast_sip_subscription *sub)
Get the body subtype used for this subscription.
static int send_notify(struct sip_subscription_tree *sub_tree, unsigned int force_full_state)
Send a NOTIFY request to a subscriber.
int ast_sip_pubsub_generate_body_content(const char *type, const char *subtype, struct ast_sip_body_data *data, struct ast_str **str)
Generate body content for a PUBLISH or NOTIFY.
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:189

References ao2_ref, ast_sip_pubsub_generate_body_content(), ast_sip_subscription_get_body_subtype(), ast_sip_subscription_get_body_type(), ast_test_suite_event_notify, sip_subscription_tree::dlg, schedule_notification(), send_notify(), SIP_SUB_TREE_NORMAL, SIP_SUB_TREE_TERMINATE_IN_PROGRESS, SIP_SUB_TREE_TERMINATE_PENDING, and sub.

Referenced by notify_task(), and send_mwi_notify().

◆ ast_sip_subscription_remove_datastore()

void ast_sip_subscription_remove_datastore ( struct ast_sip_subscription subscription,
const char *  name 
)

Remove a subscription datastore from the subscription.

This operation may cause the datastore's free() callback to be called if the reference count reaches zero.

Parameters
subscriptionThe subscription to remove the datastore from
nameThe name of the datastore to remove

Definition at line 2703 of file res_pjsip_pubsub.c.

2704{
2705 ast_datastores_remove(subscription->datastores, name);
2706}

References ast_datastores_remove(), ast_sip_subscription::datastores, and name.

Referenced by mwi_subscription_established(), mwi_subscription_shutdown(), and subscription_shutdown().

◆ ast_sip_subscription_set_persistence_data()

void ast_sip_subscription_set_persistence_data ( struct ast_sip_subscription subscription,
struct ast_json persistence_data 
)

Set persistence data for a subscription.

Since
13.31.0
16.8.0
17.2.0
Parameters
subscriptionThe subscription to set persistence data on
persistence_dataThe persistence data to set
Note
This steals the reference to persistence_data

Definition at line 2733 of file res_pjsip_pubsub.c.

2734{
2735 ast_json_unref(subscription->persistence_data);
2736 subscription->persistence_data = persistence_data;
2737
2738 if (subscription->tree->persistence) {
2739 if (!subscription->tree->persistence->generator_data) {
2741 if (!subscription->tree->persistence->generator_data) {
2742 return;
2743 }
2744 }
2745 ast_json_object_set(subscription->tree->persistence->generator_data, subscription->resource,
2746 ast_json_ref(persistence_data));
2747 }
2748}
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:399
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414

References ast_json_object_create(), ast_json_object_set(), ast_json_ref(), ast_json_unref(), subscription_persistence::generator_data, sip_subscription_tree::persistence, ast_sip_subscription::persistence_data, ast_sip_subscription::resource, and ast_sip_subscription::tree.

Referenced by dialog_info_generate_body_content().

◆ ast_sip_unregister_publish_handler()

void ast_sip_unregister_publish_handler ( struct ast_sip_publish_handler handler)

Unregister a publish handler.

Definition at line 2802 of file res_pjsip_pubsub.c.

2803{
2804 struct ast_sip_publish_handler *iter;
2805
2808 if (handler == iter) {
2810 ao2_cleanup(handler->publications);
2811 break;
2812 }
2813 }
2816}
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
Callbacks that publication handlers will define.
struct ast_sip_publish_handler * next

References ao2_cleanup, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, handler(), and ast_sip_publish_handler::next.

Referenced by load_module(), and unload_module().

◆ ast_sip_unregister_subscription_handler()

void ast_sip_unregister_subscription_handler ( struct ast_sip_subscription_handler handler)

◆ build_body_part()

static void build_body_part ( pj_pool_t *  pool,
struct ast_sip_subscription sub,
struct body_part_list parts,
unsigned int  use_full_state 
)
static

Create a multipart body part for a subscribed resource.

Parameters
poolPJLIB allocation pool
subThe subscription representing a subscribed resource
partsA vector of parts to append the created part to.
use_full_stateUnused locally, but may be passed to other functions

Definition at line 2305 of file res_pjsip_pubsub.c.

2307{
2308 struct body_part *bp;
2309 pjsip_msg_body *body;
2310
2311 bp = allocate_body_part(pool, sub);
2312 if (!bp) {
2313 return;
2314 }
2315
2316 body = generate_notify_body(pool, sub, use_full_state);
2317 if (!body) {
2318 /* Partial state was requested and the resource has not changed state */
2319 ast_free(bp);
2320 return;
2321 }
2322
2323 bp->part = pjsip_multipart_create_part(pool);
2324 bp->part->body = body;
2325 pj_list_insert_before(&bp->part->hdr, bp->cid);
2326
2327 if (AST_VECTOR_APPEND(parts, bp)) {
2328 ast_free(bp);
2329 }
2330}
static pjsip_msg_body * generate_notify_body(pj_pool_t *pool, struct ast_sip_subscription *root, unsigned int force_full_state)
Create the body for a NOTIFY request.
static struct body_part * allocate_body_part(pj_pool_t *pool, const struct ast_sip_subscription *sub)
Allocate and initialize a body part structure.
pjsip_multipart_part * part
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256

References allocate_body_part(), ast_free, AST_VECTOR_APPEND, body_part::cid, generate_notify_body(), body_part::part, and sub.

Referenced by generate_list_body().

◆ build_node_children()

static void build_node_children ( struct ast_sip_endpoint endpoint,
const struct ast_sip_subscription_handler handler,
struct resource_list list,
struct tree_node parent,
struct resources visited,
pjsip_rx_data *  rdata 
)
static

Build child nodes for a given parent.

This iterates through the items on a resource list and creates tree nodes for each one. The tree nodes created are children of the supplied parent node. If an item in the resource list is itself a list, then this function is called recursively to provide children for the new node.

If an item in a resource list is not a list, then the supplied subscription handler is called into as if a new SUBSCRIBE for the list item were presented. The handler's response is used to determine if the node can be added to the tree or not.

If a parent node ends up having no child nodes added under it, then the parent node is pruned from the tree.

Parameters
endpointThe endpoint that sent the inbound SUBSCRIBE.
handlerThe subscription handler for leaf nodes in the tree.
listThe configured resource list from which the child node is being built.
parentThe parent node for these children.
visitedThe resources that have already been visited.

Definition at line 1044 of file res_pjsip_pubsub.c.

1046{
1047 int i;
1048
1049 for (i = 0; i < AST_VECTOR_SIZE(&list->items); ++i) {
1050 struct tree_node *current;
1051 struct resource_list *child_list;
1052 const char *resource = AST_VECTOR_GET(&list->items, i);
1053
1054 if (have_visited(resource, visited)) {
1055 ast_debug(1, "Already visited resource %s. Avoiding duplicate resource or potential loop.\n", resource);
1056 continue;
1057 }
1058
1059 child_list = retrieve_resource_list(resource, list->event);
1060 if (!child_list) {
1061 int resp = NEW_SUBSCRIBE(handler->notifier, endpoint, resource, rdata);
1062 if (PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {
1063 char display_name[AST_MAX_EXTENSION] = "";
1064 if (list->resource_display_name && handler->notifier->get_resource_display_name) {
1065 handler->notifier->get_resource_display_name(endpoint, resource, display_name, sizeof(display_name));
1066 }
1067 current = tree_node_alloc(resource, visited, 0, ast_strlen_zero(display_name) ? NULL : display_name);
1068 if (!current) {
1069 ast_debug(1,
1070 "Subscription to leaf resource %s was successful, but encountered allocation error afterwards\n",
1071 resource);
1072 continue;
1073 }
1074 ast_debug(2, "Subscription to leaf resource %s resulted in success. Adding to parent %s\n",
1075 resource, parent->resource);
1076 if (AST_VECTOR_APPEND(&parent->children, current)) {
1078 }
1079 } else {
1080 ast_debug(2, "Subscription to leaf resource %s resulted in error response %d\n",
1081 resource, resp);
1082 }
1083 } else {
1084 ast_debug(2, "Resource %s (child of %s) is a list\n", resource, parent->resource);
1085 current = tree_node_alloc(resource, visited, child_list->full_state, NULL);
1086 if (!current) {
1087 ast_debug(1, "Cannot build children of resource %s due to allocation failure\n", resource);
1088 continue;
1089 }
1090 build_node_children(endpoint, handler, child_list, current, visited, rdata);
1091 if (AST_VECTOR_SIZE(&current->children) > 0) {
1092 ast_debug(1, "List %s had no successful children.\n", resource);
1093 if (AST_VECTOR_APPEND(&parent->children, current)) {
1095 }
1096 } else {
1097 ast_debug(2, "List %s had successful children. Adding to parent %s\n",
1098 resource, parent->resource);
1100 }
1101 ao2_cleanup(child_list);
1102 }
1103 }
1104}
#define AST_MAX_EXTENSION
Definition: channel.h:134
size_t current
Definition: main/cli.c:113
#define NEW_SUBSCRIBE(notifier, endpoint, resource, rdata)
static int have_visited(const char *resource, struct resources *visited)
Determine if this resource has been visited already.
static void build_node_children(struct ast_sip_endpoint *endpoint, const struct ast_sip_subscription_handler *handler, struct resource_list *list, struct tree_node *parent, struct resources *visited, pjsip_rx_data *rdata)
Build child nodes for a given parent.
static void tree_node_destroy(struct tree_node *node)
Destructor for a tree node.
static struct tree_node * tree_node_alloc(const char *resource, struct resources *visited, unsigned int full_state, const char *display_name)
Allocate a tree node.
static struct resource_list * retrieve_resource_list(const char *resource, const char *event)
Helper function for retrieving a resource list for a given event.
unsigned int full_state
struct resources items
unsigned int resource_display_name
A node for a resource tree.
struct tree_node::@464 children
char resource[0]
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

References ao2_cleanup, ast_debug, AST_MAX_EXTENSION, ast_strlen_zero(), AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_SIZE, build_node_children(), tree_node::children, current, resource_list::event, resource_list::full_state, handler(), have_visited(), resource_list::items, NEW_SUBSCRIBE, NULL, tree_node::resource, resource_list::resource_display_name, retrieve_resource_list(), tree_node_alloc(), and tree_node_destroy().

Referenced by build_node_children(), and build_resource_tree().

◆ build_resource_tree()

static int build_resource_tree ( struct ast_sip_endpoint endpoint,
const struct ast_sip_subscription_handler handler,
const char *  resource,
struct resource_tree tree,
int  has_eventlist_support,
pjsip_rx_data *  rdata 
)
static

Build a resource tree.

This function builds a resource tree based on the requested resource in a SUBSCRIBE request.

This function also creates a container that has all resources that have been visited during creation of the tree, whether those resources resulted in a tree node being created or not. Keeping this container of visited resources allows for misconfigurations such as loops in the tree or duplicated resources to be detected.

Parameters
endpointThe endpoint that sent the SUBSCRIBE request.
handlerThe subscription handler for leaf nodes in the tree.
resourceThe resource requested in the SUBSCRIBE request.
treeThe tree that is to be built.
has_eventlist_support
Return values
200-299Successfully subscribed to at least one resource.
300-699Failure to subscribe to requested resource.

Definition at line 1162 of file res_pjsip_pubsub.c.

1164{
1165 RAII_VAR(struct resource_list *, list, NULL, ao2_cleanup);
1166 struct resources visited;
1167
1168 int not_eventlist_but_needs_children = !strcmp(handler->body_type, AST_SIP_DEVICE_FEATURE_SYNC_DATA);
1169
1170 if ((!has_eventlist_support && !not_eventlist_but_needs_children) || !(list = retrieve_resource_list(resource, handler->event_name))) {
1171 ast_debug(2, "Subscription '%s->%s' is not to a list\n",
1172 ast_sorcery_object_get_id(endpoint), resource);
1173 tree->root = tree_node_alloc(resource, NULL, 0, NULL);
1174 if (!tree->root) {
1175 return 500;
1176 }
1177 return NEW_SUBSCRIBE(handler->notifier, endpoint, resource, rdata);
1178 }
1179
1180 ast_debug(2, "Subscription '%s->%s' is a list\n",
1181 ast_sorcery_object_get_id(endpoint), resource);
1182 if (AST_VECTOR_INIT(&visited, AST_VECTOR_SIZE(&list->items))) {
1183 return 500;
1184 }
1185
1186 tree->root = tree_node_alloc(resource, &visited, list->full_state, NULL);
1187 if (!tree->root) {
1188 AST_VECTOR_FREE(&visited);
1189 return 500;
1190 }
1191
1192 tree->notification_batch_interval = list->notification_batch_interval;
1193
1194 build_node_children(endpoint, handler, list, tree->root, &visited, rdata);
1195 AST_VECTOR_FREE(&visited);
1196
1197 if (AST_VECTOR_SIZE(&tree->root->children) > 0) {
1198 return 200;
1199 } else {
1200 return 500;
1201 }
1202}
#define AST_SIP_DEVICE_FEATURE_SYNC_DATA
struct tree_node * root
unsigned int notification_batch_interval
A vector of strings commonly used throughout this module.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113

References ao2_cleanup, ast_debug, AST_SIP_DEVICE_FEATURE_SYNC_DATA, ast_sorcery_object_get_id(), AST_VECTOR_FREE, AST_VECTOR_INIT, AST_VECTOR_SIZE, build_node_children(), tree_node::children, handler(), NEW_SUBSCRIBE, resource_tree::notification_batch_interval, NULL, RAII_VAR, retrieve_resource_list(), resource_tree::root, and tree_node_alloc().

Referenced by pubsub_on_rx_refresh(), pubsub_on_rx_subscribe_request(), and sub_persistence_recreate().

◆ build_rlmi_body()

static pjsip_multipart_part * build_rlmi_body ( pj_pool_t *  pool,
struct ast_sip_subscription sub,
struct body_part_list body_parts,
unsigned int  full_state 
)
static

Create an RLMI body part for a multipart resource list body.

RLMI (Resource list meta information) is a special body type that lists the subscribed resources and tells subscribers the number of subscribed resources and what other body parts are in the multipart body. The RLMI body also has a version number that a subscriber can use to ensure that the locally-stored state corresponds to server state.

Parameters
poolThe allocation pool
subThe subscription representing the subscribed resource list
body_partsA container of body parts that RLMI will refer to
full_stateIndicates whether this is a full or partial state notification
Returns
The multipart part representing the RLMI body

Definition at line 2208 of file res_pjsip_pubsub.c.

2210{
2211 pj_xml_node *rlmi;
2212 pj_xml_node *name;
2213 pjsip_multipart_part *rlmi_part;
2214 char version_str[32];
2215 char uri[PJSIP_MAX_URL_SIZE];
2216 pjsip_generic_string_hdr *cid;
2217 int i;
2218
2219 rlmi = ast_sip_presence_xml_create_node(pool, NULL, "list");
2220 ast_sip_presence_xml_create_attr(pool, rlmi, "xmlns", "urn:ietf:params:xml:ns:rlmi");
2221
2222 ast_sip_subscription_get_local_uri(sub, uri, sizeof(uri));
2223 ast_sip_presence_xml_create_attr(pool, rlmi, "uri", uri);
2224
2225 snprintf(version_str, sizeof(version_str), "%u", sub->version++);
2226 ast_sip_presence_xml_create_attr(pool, rlmi, "version", version_str);
2227 ast_sip_presence_xml_create_attr(pool, rlmi, "fullState", full_state ? "true" : "false");
2228
2229 name = ast_sip_presence_xml_create_node(pool, rlmi, "name");
2230 pj_strdup2(pool, &name->content, ast_sip_subscription_get_resource_name(sub));
2231
2232 for (i = 0; i < AST_VECTOR_SIZE(body_parts); ++i) {
2233 const struct body_part *part = AST_VECTOR_GET(body_parts, i);
2234
2235 add_rlmi_resource(pool, rlmi, part->cid, S_OR(part->display_name, part->resource), part->uri, part->state);
2236 }
2237
2238 rlmi_part = pjsip_multipart_create_part(pool);
2239
2240 rlmi_part->body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body);
2241 pjsip_media_type_cp(pool, &rlmi_part->body->content_type, &rlmi_media_type);
2242
2243 rlmi_part->body->data = pj_xml_clone(pool, rlmi);
2244 rlmi_part->body->clone_data = rlmi_clone_data;
2245 rlmi_part->body->print_body = rlmi_print_body;
2246
2248 pj_list_insert_before(&rlmi_part->hdr, cid);
2249
2250 return rlmi_part;
2251}
static void * rlmi_clone_data(pj_pool_t *pool, const void *data, unsigned len)
const char * ast_sip_subscription_get_resource_name(struct ast_sip_subscription *sub)
Get the name of the subscribed resource.
static int rlmi_print_body(struct pjsip_msg_body *msg_body, char *buf, pj_size_t size)
static void add_rlmi_resource(pj_pool_t *pool, pj_xml_node *rlmi, const pjsip_generic_string_hdr *cid, const char *resource_name, const pjsip_sip_uri *resource_uri, pjsip_evsub_state state)
Add a resource XML element to an RLMI body.
static pjsip_media_type rlmi_media_type
void ast_sip_subscription_get_local_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
Retrieve the local URI for this subscription.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80

References add_rlmi_resource(), ast_sip_presence_xml_create_attr(), ast_sip_presence_xml_create_node(), ast_sip_subscription_get_local_uri(), ast_sip_subscription_get_resource_name(), AST_VECTOR_GET, AST_VECTOR_SIZE, body_part::cid, generate_content_id_hdr(), name, NULL, body_part::part, rlmi_clone_data(), rlmi_media_type, rlmi_print_body(), S_OR, and sub.

Referenced by generate_list_body().

◆ clean_sub_tree()

static void clean_sub_tree ( pjsip_evsub *  evsub)
static

Callback sequence for subscription terminate:

  • Please note that the descriptions below represent pjproject behavior on versions >= 2.13.
  • Client initiated: pjproject receives SUBSCRIBE on the subscription's serializer thread calls pubsub_evsub_set_state with state = TERMINATED pubsub_on_evsub_state checks the event and finds it is due to a received SUBSCRIBE with an expires of 0 and so does nothing. calls pubsub_on_rx_refresh with dialog locked pubsub_on_rx_refresh sets TERMINATE_PENDING calls pubsub_on_refresh_timeout to push final NOTIFY to pjproject checks state == TERMINATE_PENDING sets TERMINATE_IN_PROGRESS calls send_notify (2) send_notify ultimately calls pjsip_evsub_send_request pjsip_evsub_send_request calls evsub's set_state set_state calls pubsub_evsub_set_state pubsub_on_evsub_state checks state == TERMINATE_IN_PROGRESS removes the subscriptions cleans up references to evsub sets state = TERMINATED pubsub_on_refresh_timeout unlocks dialog returns to pjproject pjproject unlocks dialog
  • Subscription timer expires: pjproject timer expires locks dialog calls pubsub_on_server_timeout pubsub_on_server_timeout checks state == NORMAL sets TERMINATE_PENDING pushes serialized_pubsub_on_refresh_timeout returns to pjproject pjproject unlocks dialog serialized_pubsub_on_refresh_timeout starts (1) locks dialog checks state == TERMINATE_PENDING sets TERMINATE_IN_PROGRESS calls send_notify (2) send_notify ultimately calls pjsip_evsub_send_request pjsip_evsub_send_request calls evsub's set_state set_state calls pubsub_evsub_set_state pubsub_on_evsub_state checks state == TERMINATE_IN_PROGRESS checks that the event is not due to un-SUBSCRIBE removes the subscriptions cleans up references to evsub sets state = TERMINATED serialized_pubsub_on_refresh_timeout unlocks dialog
  • Transmission failure sending NOTIFY or error response from client pjproject transaction timer expires or non OK response pjproject locks dialog calls pubsub_on_evsub_state with event TSX_STATE pubsub_on_evsub_state checks event == TSX_STATE removes the subscriptions cleans up references to evsub sets state = TERMINATED pjproject unlocks dialog
  • ast_sip_subscription_notify is called checks state == NORMAL if not batched... sets TERMINATE_IN_PROGRESS (if terminate is requested) calls send_notify See (2) Above if batched... sets TERMINATE_PENDING schedules task scheduler runs sched_task sched_task pushes serialized_send_notify serialized_send_notify starts checks state <= TERMINATE_PENDING if state == TERMINATE_PENDING set state = TERMINATE_IN_PROGRESS call send_notify See (2) Above

Definition at line 3869 of file res_pjsip_pubsub.c.

3870{
3871
3872 struct sip_subscription_tree *sub_tree;
3873 sub_tree = pjsip_evsub_get_mod_data(evsub, pubsub_module.id);
3874
3875 ast_debug(3, "Cleaning subscription %p\n", evsub);
3876
3877 if (sub_tree->expiration_task) {
3878 char task_name[256];
3879
3880 ast_sip_sched_task_get_name(sub_tree->expiration_task, task_name, sizeof(task_name));
3881 ast_debug(3, "Cancelling timer: %s\n", task_name);
3883 ao2_cleanup(sub_tree->expiration_task);
3884 sub_tree->expiration_task = NULL;
3885 }
3886
3887 remove_subscription(sub_tree);
3888
3889 pjsip_evsub_set_mod_data(evsub, pubsub_module.id, NULL);
3890
3891#ifdef HAVE_PJSIP_EVSUB_GRP_LOCK
3892 pjsip_evsub_dec_ref(sub_tree->evsub);
3893#endif
3894
3895 sub_tree->evsub = NULL;
3896
3899
3901 shutdown_subscriptions(sub_tree->root);
3902
3903 sub_tree->state = SIP_SUB_TREE_TERMINATED;
3904 /* Remove evsub's reference to the sub_tree */
3905 ao2_ref(sub_tree, -1);
3906}
void ast_sip_dialog_set_endpoint(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint)
Set an endpoint on a SIP dialog so in-dialog requests do not undergo endpoint lookup.
int ast_sip_sched_task_cancel(struct ast_sip_sched_task *schtd)
Cancels the next invocation of a task.
int ast_sip_sched_task_get_name(struct ast_sip_sched_task *schtd, char *name, size_t maxlen)
Gets the task name.
void ast_sip_dialog_set_serializer(pjsip_dialog *dlg, struct ast_taskprocessor *serializer)
Set a serializer on a SIP dialog so requests and responses are automatically serialized.
static void shutdown_subscriptions(struct ast_sip_subscription *sub)
static void remove_subscription(struct sip_subscription_tree *obj)
static void subscription_persistence_remove(struct sip_subscription_tree *sub_tree)
Function which removes persistence of a subscription from sorcery.
enum sip_subscription_tree_state state
struct ast_sip_subscription * root
struct ast_sip_sched_task * expiration_task

References ao2_cleanup, ao2_ref, ast_debug, ast_sip_dialog_set_endpoint(), ast_sip_dialog_set_serializer(), ast_sip_sched_task_cancel(), ast_sip_sched_task_get_name(), sip_subscription_tree::dlg, sip_subscription_tree::evsub, sip_subscription_tree::expiration_task, NULL, pubsub_module, remove_subscription(), sip_subscription_tree::root, shutdown_subscriptions(), SIP_SUB_TREE_TERMINATED, sip_subscription_tree::state, and subscription_persistence_remove().

Referenced by pubsub_on_evsub_state().

◆ cli_complete_subscription_callid()

static char * cli_complete_subscription_callid ( struct ast_cli_args a)
static

Definition at line 4432 of file res_pjsip_pubsub.c.

4433{
4435 on_subscription_t on_subscription;
4436
4437 if (a->pos != 4) {
4438 return NULL;
4439 }
4440
4441 if (!strcasecmp(a->argv[3], "inbound")) {
4442 on_subscription = cli_complete_subscription_inbound;
4443 } else if (!strcasecmp(a->argv[3], "outbound")) {
4444 on_subscription = cli_complete_subscription_outbound;
4445 } else {
4446 /* Should never get here */
4447 ast_assert(0);
4448 return NULL;
4449 }
4450
4451 cli.a = a;
4452 cli.callid = NULL;
4453 cli.wordlen = strlen(a->word);
4454 cli.which = 0;
4455 for_each_subscription(on_subscription, &cli);
4456
4457 return cli.callid;
4458}
static struct ast_cli_entry cli[]
Definition: codec_dahdi.c:265
int(* on_subscription_t)(struct sip_subscription_tree *sub, void *arg)
static int cli_complete_subscription_outbound(struct sip_subscription_tree *sub_tree, void *arg)
static int cli_complete_subscription_inbound(struct sip_subscription_tree *sub_tree, void *arg)
static struct test_val a

References a, ast_assert, cli, cli_complete_subscription_inbound(), cli_complete_subscription_outbound(), for_each_subscription(), and NULL.

Referenced by cli_show_subscription_inout().

◆ cli_complete_subscription_common()

static int cli_complete_subscription_common ( struct sip_subscription_tree sub_tree,
struct cli_sub_complete_parms cli 
)
static

Definition at line 4399 of file res_pjsip_pubsub.c.

4400{
4401 pj_str_t *callid;
4402
4403 if (!sub_tree->dlg) {
4404 return 0;
4405 }
4406
4407 callid = &sub_tree->dlg->call_id->id;
4408 if (cli->wordlen <= pj_strlen(callid)
4409 && !strncasecmp(cli->a->word, pj_strbuf(callid), cli->wordlen)
4410 && (++cli->which > cli->a->n)) {
4411 cli->callid = ast_malloc(pj_strlen(callid) + 1);
4412 if (cli->callid) {
4413 ast_copy_pj_str(cli->callid, callid, pj_strlen(callid) + 1);
4414 }
4415 return -1;
4416 }
4417 return 0;
4418}
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
Definition: res_pjsip.c:2201

References ast_copy_pj_str(), ast_malloc, cli, and sip_subscription_tree::dlg.

Referenced by cli_complete_subscription_inbound(), and cli_complete_subscription_outbound().

◆ cli_complete_subscription_inbound()

static int cli_complete_subscription_inbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4420 of file res_pjsip_pubsub.c.

4421{
4422 return sub_tree->role == AST_SIP_NOTIFIER
4423 ? cli_complete_subscription_common(sub_tree, arg) : 0;
4424}
static int cli_complete_subscription_common(struct sip_subscription_tree *sub_tree, struct cli_sub_complete_parms *cli)

References AST_SIP_NOTIFIER, cli_complete_subscription_common(), and sip_subscription_tree::role.

Referenced by cli_complete_subscription_callid().

◆ cli_complete_subscription_outbound()

static int cli_complete_subscription_outbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4426 of file res_pjsip_pubsub.c.

4427{
4428 return sub_tree->role == AST_SIP_SUBSCRIBER
4429 ? cli_complete_subscription_common(sub_tree, arg) : 0;
4430}

References AST_SIP_SUBSCRIBER, cli_complete_subscription_common(), and sip_subscription_tree::role.

Referenced by cli_complete_subscription_callid().

◆ cli_list_subscriptions_detail()

static int cli_list_subscriptions_detail ( struct sip_subscription_tree sub_tree,
struct cli_sub_parms cli 
)
static

Definition at line 4763 of file res_pjsip_pubsub.c.

4764{
4765 char ep_cid_buf[50];
4766 char res_evt_buf[50];
4767 char callid[256];
4768
4769 /* Endpoint/CID column */
4770 snprintf(ep_cid_buf, sizeof(ep_cid_buf), "%s/%s",
4772 S_COR(sub_tree->endpoint->id.self.name.valid, sub_tree->endpoint->id.self.name.str,
4773 S_COR(sub_tree->endpoint->id.self.number.valid,
4774 sub_tree->endpoint->id.self.number.str, "<none>")));
4775
4776 /* Resource/Event column */
4777 snprintf(res_evt_buf, sizeof(res_evt_buf), "%s/%s",
4778 sub_tree->root->resource,
4779 sub_tree->root->handler->event_name);
4780
4781 /* Call-id column */
4782 if (sub_tree->dlg) {
4783 ast_copy_pj_str(callid, &sub_tree->dlg->call_id->id, sizeof(callid));
4784 } else {
4785 ast_copy_string(callid, "<unknown>", sizeof(callid));
4786 }
4787
4789 ep_cid_buf,
4790 res_evt_buf,
4791 cli_subscription_expiry(sub_tree),
4792 callid);
4793
4794 if (cli->like) {
4795 if (regexec(cli->like, ast_str_buffer(cli->buf), 0, NULL, 0)) {
4796 /* Output line did not match the regex */
4797 return 0;
4798 }
4799 }
4800
4801 ast_cli(cli->a->fd, "%s", ast_str_buffer(cli->buf));
4802 ++cli->count;
4803
4804 return 0;
4805}
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static unsigned int cli_subscription_expiry(struct sip_subscription_tree *sub_tree)
#define CLI_LIST_SUB_FORMAT_ENTRY
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
struct ast_party_name name
Subscriber name.
Definition: channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:344
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:281
char * str
Subscriber name (Malloced)
Definition: channel.h:266
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:299
char * str
Subscriber phone number (Malloced)
Definition: channel.h:293
struct ast_party_id self
Definition: res_pjsip.h:770
struct ast_sip_endpoint_id_configuration id
Definition: res_pjsip.h:1002
const struct ast_sip_subscription_handler * handler

References ast_cli(), ast_copy_pj_str(), ast_copy_string(), ast_sorcery_object_get_id(), ast_str_buffer(), ast_str_set(), cli, CLI_LIST_SUB_FORMAT_ENTRY, cli_subscription_expiry(), sip_subscription_tree::dlg, sip_subscription_tree::endpoint, ast_sip_subscription_handler::event_name, ast_sip_subscription::handler, ast_sip_endpoint::id, ast_party_id::name, NULL, ast_party_id::number, ast_sip_subscription::resource, sip_subscription_tree::root, S_COR, ast_sip_endpoint_id_configuration::self, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

Referenced by cli_list_subscriptions_inbound(), and cli_list_subscriptions_outbound().

◆ cli_list_subscriptions_inbound()

static int cli_list_subscriptions_inbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4807 of file res_pjsip_pubsub.c.

4808{
4809 return sub_tree->role == AST_SIP_NOTIFIER
4810 ? cli_list_subscriptions_detail(sub_tree, arg) : 0;
4811}
static int cli_list_subscriptions_detail(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)

References AST_SIP_NOTIFIER, cli_list_subscriptions_detail(), and sip_subscription_tree::role.

Referenced by cli_list_subscriptions_inout().

◆ cli_list_subscriptions_inout()

static char * cli_list_subscriptions_inout ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 4819 of file res_pjsip_pubsub.c.

4820{
4821 on_subscription_t on_subscription;
4822 struct cli_sub_parms cli;
4823 regex_t like;
4824 const char *regex;
4825
4826 switch (cmd) {
4827 case CLI_INIT:
4828 e->command = "pjsip list subscriptions {inbound|outbound} [like]";
4829 e->usage = "Usage:\n"
4830 " pjsip list subscriptions inbound [like <regex>]\n"
4831 " List active inbound subscriptions\n"
4832 " pjsip list subscriptions outbound [like <regex>]\n"
4833 " List active outbound subscriptions\n"
4834 "\n"
4835 " The regex selects output lines that match.\n";
4836 return NULL;
4837 case CLI_GENERATE:
4838 return NULL;
4839 }
4840
4841 if (a->argc != 4 && a->argc != 6) {
4842 return CLI_SHOWUSAGE;
4843 }
4844 if (!strcasecmp(a->argv[3], "inbound")) {
4845 on_subscription = cli_list_subscriptions_inbound;
4846 } else if (!strcasecmp(a->argv[3], "outbound")) {
4847 on_subscription = cli_list_subscriptions_outbound;
4848 } else {
4849 /* Should never get here */
4850 ast_assert(0);
4851 return CLI_SHOWUSAGE;
4852 }
4853 if (a->argc == 6) {
4854 int rc;
4855
4856 if (strcasecmp(a->argv[4], "like")) {
4857 return CLI_SHOWUSAGE;
4858 }
4859
4860 /* Setup regular expression */
4861 memset(&like, 0, sizeof(like));
4862 cli.like = &like;
4863 regex = a->argv[5];
4864 rc = regcomp(cli.like, regex, REG_EXTENDED | REG_NOSUB);
4865 if (rc) {
4866 char *regerr = ast_alloca(MAX_REGEX_ERROR_LEN);
4867
4868 regerror(rc, cli.like, regerr, MAX_REGEX_ERROR_LEN);
4869 ast_cli(a->fd, "Regular expression '%s' failed to compile: %s\n",
4870 regex, regerr);
4871 return CLI_FAILURE;
4872 }
4873 } else {
4874 cli.like = NULL;
4875 regex = NULL;
4876 }
4877
4878 cli.a = a;
4879 cli.e = e;
4880 cli.count = 0;
4881 cli.buf = ast_str_create(256);
4882 if (!cli.buf) {
4883 if (cli.like) {
4884 regfree(cli.like);
4885 }
4886 return CLI_FAILURE;
4887 }
4888
4890 "Endpoint/CLI", "Resource/Event", "Expiry", "Call-id");
4891 for_each_subscription(on_subscription, &cli);
4892 ast_cli(a->fd, "\n%d active subscriptions%s%s%s\n",
4893 cli.count,
4894 regex ? " matched \"" : "",
4895 regex ?: "",
4896 regex ? "\"" : "");
4897
4898 ast_free(cli.buf);
4899 if (cli.like) {
4900 regfree(cli.like);
4901 }
4902
4903 return CLI_SUCCESS;
4904}
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_SUCCESS
Definition: cli.h:44
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#define CLI_FAILURE
Definition: cli.h:46
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
#define MAX_REGEX_ERROR_LEN
static int cli_list_subscriptions_outbound(struct sip_subscription_tree *sub_tree, void *arg)
#define CLI_LIST_SUB_FORMAT_HEADER
static int cli_list_subscriptions_inbound(struct sip_subscription_tree *sub_tree, void *arg)
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
struct ast_cli_entry * e

References a, ast_alloca, ast_assert, ast_cli(), ast_free, ast_str_create, cli, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_LIST_SUB_FORMAT_HEADER, cli_list_subscriptions_inbound(), cli_list_subscriptions_outbound(), CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, cli_sub_parms::e, for_each_subscription(), cli_sub_parms::like, MAX_REGEX_ERROR_LEN, NULL, regex(), and ast_cli_entry::usage.

◆ cli_list_subscriptions_outbound()

static int cli_list_subscriptions_outbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4813 of file res_pjsip_pubsub.c.

4814{
4815 return sub_tree->role == AST_SIP_SUBSCRIBER
4816 ? cli_list_subscriptions_detail(sub_tree, arg) : 0;
4817}

References AST_SIP_SUBSCRIBER, cli_list_subscriptions_detail(), and sip_subscription_tree::role.

Referenced by cli_list_subscriptions_inout().

◆ cli_show_subscription_common()

static int cli_show_subscription_common ( struct sip_subscription_tree sub_tree,
struct cli_sub_parms cli 
)
static

Definition at line 4474 of file res_pjsip_pubsub.c.

4475{
4476 const char *callid = (const char *) cli->buf;/* Member repurposed to pass in callid */
4477 pj_str_t *sub_callid;
4478 struct ast_str *buf;
4479 char *src;
4480 char *dest;
4481 char *key;
4482 char *value;
4483 char *value_end;
4484 int key_len;
4485 int key_filler_width;
4486 int value_len;
4487
4488 if (!sub_tree->dlg) {
4489 return 0;
4490 }
4491 sub_callid = &sub_tree->dlg->call_id->id;
4492 if (pj_strcmp2(sub_callid, callid)) {
4493 return 0;
4494 }
4495
4496 buf = ast_str_create(512);
4497 if (!buf) {
4498 return -1;
4499 }
4500
4501 ast_cli(cli->a->fd,
4502 "%-20s: %s\n"
4503 "===========================================================================\n",
4504 "ParameterName", "ParameterValue");
4505
4506 ast_str_append(&buf, 0, "Resource: %s\n", sub_tree->root->resource);
4507 ast_str_append(&buf, 0, "Event: %s\n", sub_tree->root->handler->event_name);
4508 ast_str_append(&buf, 0, "Expiry: %u\n", cli_subscription_expiry(sub_tree));
4509
4510 sip_subscription_to_ami(sub_tree, &buf);
4511
4512 /* Convert AMI \r\n to \n line terminators. */
4513 src = strchr(ast_str_buffer(buf), '\r');
4514 if (src) {
4515 dest = src;
4516 ++src;
4517 while (*src) {
4518 if (*src == '\r') {
4519 ++src;
4520 continue;
4521 }
4522 *dest++ = *src++;
4523 }
4524 *dest = '\0';
4526 }
4527
4528 /* Reformat AMI key value pairs to pretty columns */
4529 key = ast_str_buffer(buf);
4530 do {
4531 value = strchr(key, ':');
4532 if (!value) {
4533 break;
4534 }
4535 value_end = strchr(value, '\n');
4536 if (!value_end) {
4537 break;
4538 }
4539
4540 /* Calculate field lengths */
4541 key_len = value - key;
4542 key_filler_width = 20 - key_len;
4543 if (key_filler_width < 0) {
4544 key_filler_width = 0;
4545 }
4546 value_len = value_end - value;
4547
4548 ast_cli(cli->a->fd, "%.*s%*s%.*s\n",
4549 key_len, key, key_filler_width, "",
4550 value_len, value);
4551
4552 key = value_end + 1;
4553 } while (*key);
4554 ast_cli(cli->a->fd, "\n");
4555
4556 ast_free(buf);
4557
4558 return -1;
4559}
if(!yyg->yy_init)
Definition: ast_expr2f.c:854
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition: strings.h:703
int value
Definition: syslog.c:37

References ast_cli(), ast_free, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_update(), buf, cli_sub_complete_parms::callid, cli, cli_subscription_expiry(), sip_subscription_tree::dlg, ast_sip_subscription_handler::event_name, ast_sip_subscription::handler, if(), ast_sip_subscription::resource, sip_subscription_tree::root, sip_subscription_to_ami(), and value.

Referenced by cli_show_subscription_inbound(), and cli_show_subscription_outbound().

◆ cli_show_subscription_inbound()

static int cli_show_subscription_inbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4561 of file res_pjsip_pubsub.c.

4562{
4563 return sub_tree->role == AST_SIP_NOTIFIER
4564 ? cli_show_subscription_common(sub_tree, arg) : 0;
4565}
static int cli_show_subscription_common(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)

References AST_SIP_NOTIFIER, cli_show_subscription_common(), and sip_subscription_tree::role.

Referenced by cli_show_subscription_inout().

◆ cli_show_subscription_inout()

static char * cli_show_subscription_inout ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 4573 of file res_pjsip_pubsub.c.

4574{
4575 on_subscription_t on_subscription;
4576 struct cli_sub_parms cli;
4577
4578 switch (cmd) {
4579 case CLI_INIT:
4580 e->command = "pjsip show subscription {inbound|outbound}";
4581 e->usage = "Usage:\n"
4582 " pjsip show subscription inbound <call-id>\n"
4583 " pjsip show subscription outbound <call-id>\n"
4584 " Show active subscription with the dialog call-id\n";
4585 return NULL;
4586 case CLI_GENERATE:
4588 }
4589
4590 if (a->argc != 5) {
4591 return CLI_SHOWUSAGE;
4592 }
4593
4594 if (!strcasecmp(a->argv[3], "inbound")) {
4595 on_subscription = cli_show_subscription_inbound;
4596 } else if (!strcasecmp(a->argv[3], "outbound")) {
4597 on_subscription = cli_show_subscription_outbound;
4598 } else {
4599 /* Should never get here */
4600 ast_assert(0);
4601 return NULL;
4602 }
4603
4604 /* Find the subscription with the specified call-id */
4605 cli.a = a;
4606 cli.e = e;
4607 cli.buf = (void *) a->argv[4];/* Repurpose the buf member to pass in callid */
4608 for_each_subscription(on_subscription, &cli);
4609
4610 return CLI_SUCCESS;
4611}
static char * cli_complete_subscription_callid(struct ast_cli_args *a)
static int cli_show_subscription_outbound(struct sip_subscription_tree *sub_tree, void *arg)
static int cli_show_subscription_inbound(struct sip_subscription_tree *sub_tree, void *arg)

References a, ast_assert, cli, cli_complete_subscription_callid(), CLI_GENERATE, CLI_INIT, cli_show_subscription_inbound(), cli_show_subscription_outbound(), CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, cli_sub_parms::e, for_each_subscription(), NULL, and ast_cli_entry::usage.

◆ cli_show_subscription_outbound()

static int cli_show_subscription_outbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4567 of file res_pjsip_pubsub.c.

4568{
4569 return sub_tree->role == AST_SIP_SUBSCRIBER
4570 ? cli_show_subscription_common(sub_tree, arg) : 0;
4571}

References AST_SIP_SUBSCRIBER, cli_show_subscription_common(), and sip_subscription_tree::role.

Referenced by cli_show_subscription_inout().

◆ cli_show_subscriptions_detail()

static int cli_show_subscriptions_detail ( struct sip_subscription_tree sub_tree,
struct cli_sub_parms cli 
)
static

Definition at line 4623 of file res_pjsip_pubsub.c.

4624{
4625 char caller_id[256];
4626 char callid[256];
4627
4628 ast_callerid_merge(caller_id, sizeof(caller_id),
4629 S_COR(sub_tree->endpoint->id.self.name.valid,
4630 sub_tree->endpoint->id.self.name.str, NULL),
4631 S_COR(sub_tree->endpoint->id.self.number.valid,
4632 sub_tree->endpoint->id.self.number.str, NULL),
4633 "<none>");
4634
4635 /* Call-id */
4636 if (sub_tree->dlg) {
4637 ast_copy_pj_str(callid, &sub_tree->dlg->call_id->id, sizeof(callid));
4638 } else {
4639 ast_copy_string(callid, "<unknown>", sizeof(callid));
4640 }
4641
4643 ast_sorcery_object_get_id(sub_tree->endpoint), caller_id,
4644 sub_tree->root->resource, sub_tree->root->handler->event_name,
4645 cli_subscription_expiry(sub_tree), callid);
4646
4647 if (cli->like) {
4648 if (regexec(cli->like, ast_str_buffer(cli->buf), 0, NULL, 0)) {
4649 /* Output line did not match the regex */
4650 return 0;
4651 }
4652 }
4653
4654 ast_cli(cli->a->fd, "%s", ast_str_buffer(cli->buf));
4655 ++cli->count;
4656
4657 return 0;
4658}
char * ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown)
Definition: callerid.c:1273
#define CLI_SHOW_SUB_FORMAT_ENTRY

References ast_callerid_merge(), ast_cli(), ast_copy_pj_str(), ast_copy_string(), ast_sorcery_object_get_id(), ast_str_buffer(), ast_str_set(), cli, CLI_SHOW_SUB_FORMAT_ENTRY, cli_subscription_expiry(), sip_subscription_tree::dlg, sip_subscription_tree::endpoint, ast_sip_subscription_handler::event_name, ast_sip_subscription::handler, ast_sip_endpoint::id, ast_party_id::name, NULL, ast_party_id::number, ast_sip_subscription::resource, sip_subscription_tree::root, S_COR, ast_sip_endpoint_id_configuration::self, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.

Referenced by cli_show_subscriptions_inbound(), and cli_show_subscriptions_outbound().

◆ cli_show_subscriptions_inbound()

static int cli_show_subscriptions_inbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4660 of file res_pjsip_pubsub.c.

4661{
4662 return sub_tree->role == AST_SIP_NOTIFIER
4663 ? cli_show_subscriptions_detail(sub_tree, arg) : 0;
4664}
static int cli_show_subscriptions_detail(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)

References AST_SIP_NOTIFIER, cli_show_subscriptions_detail(), and sip_subscription_tree::role.

Referenced by cli_show_subscriptions_inout().

◆ cli_show_subscriptions_inout()

static char * cli_show_subscriptions_inout ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 4672 of file res_pjsip_pubsub.c.

4673{
4674 on_subscription_t on_subscription;
4675 struct cli_sub_parms cli;
4676 regex_t like;
4677 const char *regex;
4678
4679 switch (cmd) {
4680 case CLI_INIT:
4681 e->command = "pjsip show subscriptions {inbound|outbound} [like]";
4682 e->usage = "Usage:\n"
4683 " pjsip show subscriptions inbound [like <regex>]\n"
4684 " Show active inbound subscriptions\n"
4685 " pjsip show subscriptions outbound [like <regex>]\n"
4686 " Show active outbound subscriptions\n"
4687 "\n"
4688 " The regex selects a subscriptions output that matches.\n"
4689 " i.e., All output lines for a subscription are checked\n"
4690 " as a block by the regex.\n";
4691 return NULL;
4692 case CLI_GENERATE:
4693 return NULL;
4694 }
4695
4696 if (a->argc != 4 && a->argc != 6) {
4697 return CLI_SHOWUSAGE;
4698 }
4699 if (!strcasecmp(a->argv[3], "inbound")) {
4700 on_subscription = cli_show_subscriptions_inbound;
4701 } else if (!strcasecmp(a->argv[3], "outbound")) {
4702 on_subscription = cli_show_subscriptions_outbound;
4703 } else {
4704 /* Should never get here */
4705 ast_assert(0);
4706 return CLI_SHOWUSAGE;
4707 }
4708 if (a->argc == 6) {
4709 int rc;
4710
4711 if (strcasecmp(a->argv[4], "like")) {
4712 return CLI_SHOWUSAGE;
4713 }
4714
4715 /* Setup regular expression */
4716 memset(&like, 0, sizeof(like));
4717 cli.like = &like;
4718 regex = a->argv[5];
4719 rc = regcomp(cli.like, regex, REG_EXTENDED | REG_NOSUB);
4720 if (rc) {
4721 char *regerr = ast_alloca(MAX_REGEX_ERROR_LEN);
4722
4723 regerror(rc, cli.like, regerr, MAX_REGEX_ERROR_LEN);
4724 ast_cli(a->fd, "Regular expression '%s' failed to compile: %s\n",
4725 regex, regerr);
4726 return CLI_FAILURE;
4727 }
4728 } else {
4729 cli.like = NULL;
4730 regex = NULL;
4731 }
4732
4733 cli.a = a;
4734 cli.e = e;
4735 cli.count = 0;
4736 cli.buf = ast_str_create(256);
4737 if (!cli.buf) {
4738 if (cli.like) {
4739 regfree(cli.like);
4740 }
4741 return CLI_FAILURE;
4742 }
4743
4745 for_each_subscription(on_subscription, &cli);
4746 ast_cli(a->fd, "%d active subscriptions%s%s%s\n",
4747 cli.count,
4748 regex ? " matched \"" : "",
4749 regex ?: "",
4750 regex ? "\"" : "");
4751
4752 ast_free(cli.buf);
4753 if (cli.like) {
4754 regfree(cli.like);
4755 }
4756
4757 return CLI_SUCCESS;
4758}
static int cli_show_subscriptions_outbound(struct sip_subscription_tree *sub_tree, void *arg)
#define CLI_SHOW_SUB_FORMAT_HEADER
static int cli_show_subscriptions_inbound(struct sip_subscription_tree *sub_tree, void *arg)

References a, ast_alloca, ast_assert, ast_cli(), ast_free, ast_str_create, cli, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOW_SUB_FORMAT_HEADER, cli_show_subscriptions_inbound(), cli_show_subscriptions_outbound(), CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, cli_sub_parms::e, for_each_subscription(), cli_sub_parms::like, MAX_REGEX_ERROR_LEN, NULL, regex(), and ast_cli_entry::usage.

◆ cli_show_subscriptions_outbound()

static int cli_show_subscriptions_outbound ( struct sip_subscription_tree sub_tree,
void *  arg 
)
static

Definition at line 4666 of file res_pjsip_pubsub.c.

4667{
4668 return sub_tree->role == AST_SIP_SUBSCRIBER
4669 ? cli_show_subscriptions_detail(sub_tree, arg) : 0;
4670}

References AST_SIP_SUBSCRIBER, cli_show_subscriptions_detail(), and sip_subscription_tree::role.

Referenced by cli_show_subscriptions_inout().

◆ cli_subscription_expiry()

static unsigned int cli_subscription_expiry ( struct sip_subscription_tree sub_tree)
static

Definition at line 4460 of file res_pjsip_pubsub.c.

4461{
4462 int expiry;
4463
4464 expiry = sub_tree->persistence
4465 ? ast_tvdiff_ms(sub_tree->persistence->expires, ast_tvnow()) / 1000
4466 : 0;
4467 if (expiry < 0) {
4468 /* Subscription expired */
4469 expiry = 0;
4470 }
4471 return expiry;
4472}
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

References ast_tvdiff_ms(), ast_tvnow(), subscription_persistence::expires, and sip_subscription_tree::persistence.

Referenced by cli_list_subscriptions_detail(), cli_show_subscription_common(), and cli_show_subscriptions_detail().

◆ cmp_strings()

static int cmp_strings ( char *  s1,
char *  s2 
)
static

Compare strings for equality checking for NULL.

This function considers NULL values as empty strings. This means NULL or empty strings are equal.

Return values
0The strings are equal
1The strings are not equal

Definition at line 4021 of file res_pjsip_pubsub.c.

4022{
4023 if (!ast_strlen_zero(s1) && !ast_strlen_zero(s2)) {
4024 return strcmp(s1, s2);
4025 }
4026
4027 return ast_strlen_zero(s1) == ast_strlen_zero(s2) ? 0 : 1;
4028}

References ast_strlen_zero().

Referenced by cmp_subscription_childrens().

◆ cmp_subscription_childrens()

static int cmp_subscription_childrens ( struct ast_sip_subscription s1,
struct ast_sip_subscription s2 
)
static

compares the childrens of two ast_sip_subscription s1 and s2

Return values
0The s1 childrens match the s2 childrens
1The s1 childrens do not match the s2 childrens

Definition at line 4036 of file res_pjsip_pubsub.c.

4037{
4038 int i;
4039
4040 if (AST_VECTOR_SIZE(&s1->children) != AST_VECTOR_SIZE(&s2->children)) {
4041 return 1;
4042 }
4043
4044 for (i = 0; i < AST_VECTOR_SIZE(&s1->children); ++i) {
4045 struct ast_sip_subscription *c1 = AST_VECTOR_GET(&s1->children, i);
4046 struct ast_sip_subscription *c2 = AST_VECTOR_GET(&s2->children, i);
4047
4048 if (cmp_strings(c1->resource, c2->resource)
4049 || cmp_strings(c1->display_name, c2->display_name)) {
4050
4051 return 1;
4052 }
4053 }
4054
4055 return 0;
4056}
static int cmp_strings(char *s1, char *s2)
Compare strings for equality checking for NULL.
struct ast_sip_subscription::@463 children

References AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sip_subscription::children, cmp_strings(), ast_sip_subscription::display_name, and ast_sip_subscription::resource.

Referenced by pubsub_on_rx_refresh().

◆ create_multipart_body()

static pjsip_msg_body * create_multipart_body ( pj_pool_t *  pool)
static

Create and initialize the PJSIP multipart body structure for a resource list subscription.

Parameters
pool
Returns
The multipart message body

Definition at line 2338 of file res_pjsip_pubsub.c.

2339{
2340 pjsip_media_type media_type;
2341 pjsip_param *media_type_param;
2342 char boundary[6];
2343 pj_str_t pj_boundary;
2344
2345 pjsip_media_type_init2(&media_type, "multipart", "related");
2346
2347 media_type_param = pj_pool_alloc(pool, sizeof(*media_type_param));
2348 pj_list_init(media_type_param);
2349
2350 pj_strdup2(pool, &media_type_param->name, "type");
2351 pj_strdup2(pool, &media_type_param->value, "\"application/rlmi+xml\"");
2352
2353 pj_list_insert_before(&media_type.param, media_type_param);
2354
2355 pj_cstr(&pj_boundary, ast_generate_random_string(boundary, sizeof(boundary)));
2356 return pjsip_multipart_create(pool, &media_type, &pj_boundary);
2357}

References ast_generate_random_string().

Referenced by generate_list_body().

◆ create_require_eventlist()

static pjsip_require_hdr * create_require_eventlist ( pj_pool_t *  pool)
static

Shortcut method to create a Require: eventlist header.

Definition at line 2451 of file res_pjsip_pubsub.c.

2452{
2453 pjsip_require_hdr *require;
2454
2455 require = pjsip_require_hdr_create(pool);
2456 pj_strdup2(pool, &require->values[0], "eventlist");
2457 require->count = 1;
2458
2459 return require;
2460}

Referenced by pubsub_on_rx_refresh(), send_notify(), and sip_subscription_accept().

◆ create_subscription_tree()

static struct sip_subscription_tree * create_subscription_tree ( const struct ast_sip_subscription_handler handler,
struct ast_sip_endpoint endpoint,
pjsip_rx_data *  rdata,
const char *  resource,
struct ast_sip_pubsub_body_generator generator,
struct resource_tree tree,
pj_status_t *  dlg_status,
struct subscription_persistence persistence 
)
static

Create a subscription tree based on a resource tree.

Using the previously-determined valid resources in the provided resource tree, a corresponding tree of ast_sip_subscriptions are created. The root of the subscription tree is a real subscription, and the rest in the tree are virtual subscriptions.

Parameters
handlerThe handler to use for leaf subscriptions
endpointThe endpoint that sent the SUBSCRIBE request
rdataThe SUBSCRIBE content
resourceThe requested resource in the SUBSCRIBE request
generatorThe body generator to use in leaf subscriptions
treeThe resource tree on which the subscription tree is based
[out]dlg_statusThe result of attempting to create a dialog
persistence
Return values
NULLCould not create the subscription tree
non-NULLThe root of the created subscription tree

Definition at line 1506 of file res_pjsip_pubsub.c.

1510{
1511 struct sip_subscription_tree *sub_tree;
1512 pjsip_dialog *dlg;
1513
1514 sub_tree = allocate_subscription_tree(endpoint, rdata);
1515 if (!sub_tree) {
1516 *dlg_status = PJ_ENOMEM;
1517 return NULL;
1518 }
1519 sub_tree->role = AST_SIP_NOTIFIER;
1520
1521 dlg = ast_sip_create_dialog_uas_locked(endpoint, rdata, dlg_status);
1522 if (!dlg) {
1523 if (*dlg_status != PJ_EEXISTS) {
1524 ast_log(LOG_WARNING, "Unable to create dialog for SIP subscription\n");
1525 }
1526 ao2_ref(sub_tree, -1);
1527 return NULL;
1528 }
1529
1530 persistence = ast_sip_mod_data_get(rdata->endpt_info.mod_data,
1532 if (persistence) {
1533 /* Update the created dialog with the persisted information */
1534 pjsip_ua_unregister_dlg(pjsip_ua_instance(), dlg);
1535 pj_strdup2(dlg->pool, &dlg->local.info->tag, persistence->tag);
1536 dlg->local.tag_hval = pj_hash_calc_tolower(0, NULL, &dlg->local.info->tag);
1537 pjsip_ua_register_dlg(pjsip_ua_instance(), dlg);
1538 dlg->local.cseq = persistence->cseq;
1539 }
1540
1541 pjsip_evsub_create_uas(dlg, &pubsub_cb, rdata, 0, &sub_tree->evsub);
1542
1543 subscription_setup_dialog(sub_tree, dlg);
1544
1545 /*
1546 * The evsub and subscription setup both add dialog refs, so the dialog ref that
1547 * was added when the dialog was created (see ast_sip_create_dialog_uas_lock) can
1548 * now be removed. The lock should no longer be needed so can be removed too.
1549 */
1550 pjsip_dlg_dec_lock(dlg);
1551
1552#ifdef HAVE_PJSIP_EVSUB_GRP_LOCK
1553 pjsip_evsub_add_ref(sub_tree->evsub);
1554#endif
1555
1557 pjsip_msg_clone(dlg->pool, rdata->msg_info.msg));
1558
1560
1561 /* Persistence information needs to be available for all the subscriptions */
1562 sub_tree->persistence = ao2_bump(persistence);
1563
1564 sub_tree->root = create_virtual_subscriptions(handler, resource, generator, sub_tree, tree->root);
1565 if (AST_VECTOR_SIZE(&sub_tree->root->children) > 0) {
1566 sub_tree->is_list = 1;
1567 }
1568
1569 add_subscription(sub_tree);
1570
1571 return sub_tree;
1572}
pjsip_dialog * ast_sip_create_dialog_uas_locked(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pj_status_t *status)
General purpose method for creating a UAS dialog with an endpoint.
Definition: res_pjsip.c:1192
#define ast_sip_mod_data_set(pool, mod_data, id, key, val)
Utilizing a mod_data array for a given id, set the value associated with the given key.
Definition: res_pjsip.h:2980
static struct ast_sip_subscription * create_virtual_subscriptions(const struct ast_sip_subscription_handler *handler, const char *resource, struct ast_sip_pubsub_body_generator *generator, struct sip_subscription_tree *tree, struct tree_node *current)
Create a tree of virtual subscriptions based on a resource tree node.
#define MOD_DATA_PERSISTENCE
unsigned int notification_batch_interval

References add_subscription(), allocate_subscription_tree(), ao2_bump, ao2_ref, ast_log, ast_sip_create_dialog_uas_locked(), ast_sip_mod_data_get, ast_sip_mod_data_set, AST_SIP_NOTIFIER, AST_VECTOR_SIZE, ast_sip_subscription::children, create_virtual_subscriptions(), subscription_persistence::cseq, sip_subscription_tree::dlg, sip_subscription_tree::endpoint, sip_subscription_tree::evsub, handler(), sip_subscription_tree::is_list, LOG_WARNING, MOD_DATA_MSG, MOD_DATA_PERSISTENCE, sip_subscription_tree::notification_batch_interval, resource_tree::notification_batch_interval, NULL, sip_subscription_tree::persistence, pubsub_cb, pubsub_module, sip_subscription_tree::role, sip_subscription_tree::root, resource_tree::root, subscription_setup_dialog(), and subscription_persistence::tag.

Referenced by pubsub_on_rx_subscribe_request(), and sub_persistence_recreate().

◆ create_virtual_subscriptions()

static struct ast_sip_subscription * create_virtual_subscriptions ( const struct ast_sip_subscription_handler handler,
const char *  resource,
struct ast_sip_pubsub_body_generator generator,
struct sip_subscription_tree tree,
struct tree_node current 
)
static

Create a tree of virtual subscriptions based on a resource tree node.

Parameters
handlerThe handler to supply to leaf subscriptions.
resourceThe requested resource for this subscription.
generatorBody generator to use for leaf subscriptions.
treeThe root of the subscription tree.
currentThe tree node that corresponds to the subscription being created.

Definition at line 1325 of file res_pjsip_pubsub.c.

1328{
1329 int i;
1330 struct ast_sip_subscription *sub;
1331
1333 if (!sub) {
1334 return NULL;
1335 }
1336
1337 sub->full_state = current->full_state;
1338 sub->body_generator = generator;
1339 AST_VECTOR_INIT(&sub->children, AST_VECTOR_SIZE(&current->children));
1340
1341 for (i = 0; i < AST_VECTOR_SIZE(&current->children); ++i) {
1342 struct ast_sip_subscription *child;
1343 struct tree_node *child_node = AST_VECTOR_GET(&current->children, i);
1344
1345 child = create_virtual_subscriptions(handler, child_node->resource, generator,
1346 tree, child_node);
1347
1348 if (!child) {
1349 ast_debug(1, "Child subscription to resource %s could not be created\n",
1350 child_node->resource);
1351 continue;
1352 }
1353
1354 if (AST_VECTOR_APPEND(&sub->children, child)) {
1355 ast_debug(1, "Child subscription to resource %s could not be appended\n",
1356 child_node->resource);
1357 destroy_subscription(child);
1358 /* Have to release tree here too because a ref was added
1359 * to child that destroy_subscription() doesn't release. */
1360 ao2_cleanup(tree);
1361 }
1362 }
1363
1364 return sub;
1365}

References allocate_subscription(), ao2_cleanup, ast_debug, AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_SIZE, create_virtual_subscriptions(), current, destroy_subscription(), handler(), NULL, ast_sip_subscription::resource, tree_node::resource, sub, and ast_sip_subscription::tree.

Referenced by create_subscription_tree(), create_virtual_subscriptions(), and pubsub_on_rx_refresh().

◆ destroy_subscription()

static void destroy_subscription ( struct ast_sip_subscription sub)
static

Definition at line 1230 of file res_pjsip_pubsub.c.

1231{
1232 ast_debug(3, "Destroying SIP subscription from '%s->%s'\n",
1233 sub->tree && sub->tree->endpoint ? ast_sorcery_object_get_id(sub->tree->endpoint) : "Unknown",
1234 sub->resource);
1235
1236 ast_free(sub->body_text);
1237
1238 AST_VECTOR_FREE(&sub->children);
1239 ao2_cleanup(sub->datastores);
1240 ast_json_unref(sub->persistence_data);
1241 ast_free(sub->display_name);
1242 ast_free(sub);
1243}

References ao2_cleanup, ast_debug, ast_free, ast_json_unref(), ast_sorcery_object_get_id(), AST_VECTOR_FREE, and sub.

Referenced by allocate_subscription(), create_virtual_subscriptions(), and destroy_subscriptions().

◆ destroy_subscriptions()

static void destroy_subscriptions ( struct ast_sip_subscription root)
static

Definition at line 1245 of file res_pjsip_pubsub.c.

1246{
1247 int i;
1248
1249 if (!root) {
1250 return;
1251 }
1252
1253 for (i = 0; i < AST_VECTOR_SIZE(&root->children); ++i) {
1254 struct ast_sip_subscription *child;
1255
1256 child = AST_VECTOR_GET(&root->children, i);
1257 destroy_subscriptions(child);
1258 }
1259
1261}
static void destroy_subscriptions(struct ast_sip_subscription *root)

References AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sip_subscription::children, destroy_subscription(), destroy_subscriptions(), and sip_subscription_tree::root.

Referenced by destroy_subscriptions(), destroy_subscriptions_task(), pubsub_on_rx_refresh(), and subscription_tree_destructor().

◆ destroy_subscriptions_task()

static int destroy_subscriptions_task ( void *  obj)
static

Definition at line 4058 of file res_pjsip_pubsub.c.

4059{
4060 struct ast_sip_subscription *sub = (struct ast_sip_subscription *) obj;
4061
4063
4064 return 0;
4065}

References destroy_subscriptions(), and sub.

Referenced by pubsub_on_rx_refresh().

◆ determine_sip_publish_type()

static enum sip_publish_type determine_sip_publish_type ( pjsip_rx_data *  rdata,
pjsip_generic_string_hdr *  etag_hdr,
unsigned int *  expires,
int *  entity_id 
)
static

Definition at line 3168 of file res_pjsip_pubsub.c.

3170{
3171 pjsip_expires_hdr *expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL);
3172
3173 if (etag_hdr) {
3174 char etag[pj_strlen(&etag_hdr->hvalue) + 1];
3175
3176 ast_copy_pj_str(etag, &etag_hdr->hvalue, sizeof(etag));
3177
3178 if (sscanf(etag, "%30d", entity_id) != 1) {
3179 return SIP_PUBLISH_UNKNOWN;
3180 }
3181 }
3182
3183 *expires = expires_hdr ? expires_hdr->ivalue : DEFAULT_PUBLISH_EXPIRES;
3184
3185 if (!(*expires)) {
3186 return SIP_PUBLISH_REMOVE;
3187 } else if (!etag_hdr && rdata->msg_info.msg->body) {
3188 return SIP_PUBLISH_INITIAL;
3189 } else if (etag_hdr && !rdata->msg_info.msg->body) {
3190 return SIP_PUBLISH_REFRESH;
3191 } else if (etag_hdr && rdata->msg_info.msg->body) {
3192 return SIP_PUBLISH_MODIFY;
3193 }
3194
3195 return SIP_PUBLISH_UNKNOWN;
3196}
#define DEFAULT_PUBLISH_EXPIRES
Default expiration time for PUBLISH if one is not specified.

References ast_copy_pj_str(), DEFAULT_PUBLISH_EXPIRES, NULL, SIP_PUBLISH_INITIAL, SIP_PUBLISH_MODIFY, SIP_PUBLISH_REFRESH, SIP_PUBLISH_REMOVE, and SIP_PUBLISH_UNKNOWN.

Referenced by pubsub_on_rx_publish_request().

◆ exceptional_accept()

static int exceptional_accept ( const pj_str_t *  accept)
static

Is the Accept header from the SUBSCRIBE in the list of exceptions?

Return values
1This Accept header value is an exception to the rule.
0This Accept header is not an exception to the rule.

Definition at line 833 of file res_pjsip_pubsub.c.

834{
835 int i;
836
837 for (i = 0; i < ARRAY_LEN(accept_exceptions); ++i) {
838 if (!pj_strcmp2(accept, accept_exceptions[i])) {
839 return 1;
840 }
841 }
842
843 return 0;
844}
const char * accept_exceptions[]
Accept headers that are exceptions to the rule.
#define ARRAY_LEN(a)
Definition: utils.h:666

References ast_sip_subscription_handler::accept, accept_exceptions, and ARRAY_LEN.

Referenced by subscription_get_generator_from_rdata().

◆ find_body_generator()

static struct ast_sip_pubsub_body_generator * find_body_generator ( char  accept[AST_SIP_MAX_ACCEPT][64],
size_t  num_accept,
const char *  body_type 
)
static

Definition at line 2926 of file res_pjsip_pubsub.c.

2928{
2929 int i;
2930 struct ast_sip_pubsub_body_generator *generator = NULL;
2931
2932 for (i = 0; i < num_accept; ++i) {
2933 generator = find_body_generator_accept(accept[i]);
2934 if (generator) {
2935 ast_debug(3, "Body generator %p found for accept type %s\n", generator, accept[i]);
2936 if (strcmp(generator->body_type, body_type)) {
2937 ast_log(LOG_WARNING, "Body generator '%s/%s'(%p) does not accept the type of data this event generates\n",
2938 generator->type, generator->subtype, generator);
2939 generator = NULL;
2940 continue;
2941 }
2942 break;
2943 } else {
2944 ast_debug(3, "No body generator found for accept type %s\n", accept[i]);
2945 }
2946 }
2947
2948 return generator;
2949}
static struct ast_sip_pubsub_body_generator * find_body_generator_accept(const char *accept)

References ast_debug, ast_log, ast_sip_pubsub_body_generator::body_type, find_body_generator_accept(), LOG_WARNING, NULL, ast_sip_pubsub_body_generator::subtype, and ast_sip_pubsub_body_generator::type.

Referenced by subscription_get_generator_from_rdata().

◆ find_body_generator_accept()

static struct ast_sip_pubsub_body_generator * find_body_generator_accept ( const char *  accept)
static

Definition at line 2913 of file res_pjsip_pubsub.c.

2914{
2915 char *accept_copy = ast_strdupa(accept);
2916 char *subtype = accept_copy;
2917 char *type = strsep(&subtype, "/");
2918
2919 if (ast_strlen_zero(type) || ast_strlen_zero(subtype)) {
2920 return NULL;
2921 }
2922
2923 return find_body_generator_type_subtype(type, subtype);
2924}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
char * strsep(char **str, const char *delims)

References ast_strdupa, ast_strlen_zero(), find_body_generator_type_subtype(), NULL, strsep(), ast_sip_pubsub_body_generator::subtype, and type.

Referenced by find_body_generator().

◆ find_body_generator_type_subtype()

static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype ( const char *  type,
const char *  subtype 
)
static

◆ find_body_generator_type_subtype_nolock()

static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype_nolock ( const char *  type,
const char *  subtype 
)
static

Definition at line 2889 of file res_pjsip_pubsub.c.

2890{
2892
2894 if (!strcmp(gen->type, type)
2895 && !strcmp(gen->subtype, subtype)) {
2896 break;
2897 }
2898 }
2899
2900 return gen;
2901}
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491

References AST_LIST_TRAVERSE, gen, ast_sip_pubsub_body_generator::list, ast_sip_pubsub_body_generator::subtype, and type.

Referenced by ast_sip_pubsub_register_body_generator(), and find_body_generator_type_subtype().

◆ find_pub_handler()

static struct ast_sip_publish_handler * find_pub_handler ( const char *  event)
static

Definition at line 3150 of file res_pjsip_pubsub.c.

3151{
3152 struct ast_sip_publish_handler *iter = NULL;
3153
3156 if (strcmp(event, iter->event_name)) {
3157 ast_debug(3, "Event %s does not match %s\n", event, iter->event_name);
3158 continue;
3159 }
3160 ast_debug(3, "Event name match: %s = %s\n", event, iter->event_name);
3161 break;
3162 }
3164
3165 return iter;
3166}
const char * event_name
The name of the event this handler deals with.

References ast_debug, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_sip_publish_handler::event_name, ast_sip_publish_handler::next, and NULL.

Referenced by pubsub_on_rx_publish_request().

◆ find_sub_handler_for_event_name()

static struct ast_sip_subscription_handler * find_sub_handler_for_event_name ( const char *  event_name)
static

◆ for_each_subscription()

static int for_each_subscription ( on_subscription_t  on_subscription,
void *  arg 
)
static

Definition at line 1841 of file res_pjsip_pubsub.c.

1842{
1843 int num = 0;
1844 struct sip_subscription_tree *i;
1845
1846 if (!on_subscription) {
1847 return num;
1848 }
1849
1852 if (on_subscription(i, arg)) {
1853 break;
1854 }
1855 ++num;
1856 }
1858 return num;
1859}
struct sip_subscription_tree * next

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and sip_subscription_tree::next.

Referenced by ami_show_subscriptions_inbound(), ami_show_subscriptions_outbound(), cli_complete_subscription_callid(), cli_list_subscriptions_inout(), cli_show_subscription_inout(), and cli_show_subscriptions_inout().

◆ format_ami_resource_lists()

static int format_ami_resource_lists ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 4329 of file res_pjsip_pubsub.c.

4330{
4331 struct resource_list *list = obj;
4332 struct ast_sip_ami *ami = arg;
4333 struct ast_str *buf;
4334
4335 buf = ast_sip_create_ami_event("ResourceListDetail", ami);
4336 if (!buf) {
4337 return CMP_STOP;
4338 }
4339
4340 if (ast_sip_sorcery_object_to_ami(list, &buf)) {
4341 ast_free(buf);
4342 return CMP_STOP;
4343 }
4344 astman_append(ami->s, "%s\r\n", ast_str_buffer(buf));
4345 ast_free(buf);
4346
4347 ++ami->count;
4348 return 0;
4349}
@ CMP_STOP
Definition: astobj2.h:1028
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
void * arg
Definition: res_pjsip.h:3055

References ast_sip_ami::arg, ast_free, ast_sip_create_ami_event(), ast_sip_sorcery_object_to_ami(), ast_str_buffer(), astman_append(), buf, CMP_STOP, ast_sip_ami::count, and ast_sip_ami::s.

Referenced by ami_show_resource_lists().

◆ free_body_parts()

static void free_body_parts ( struct body_part_list parts)
static

Destroy a list of body parts.

Parameters
partsThe container of parts to destroy

Definition at line 2261 of file res_pjsip_pubsub.c.

2262{
2263 int i;
2264
2265 for (i = 0; i < AST_VECTOR_SIZE(parts); ++i) {
2266 struct body_part *part = AST_VECTOR_GET(parts, i);
2267 ast_free(part);
2268 }
2269
2270 AST_VECTOR_FREE(parts);
2271}

References ast_free, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, and body_part::part.

Referenced by generate_list_body().

◆ generate_content_id_hdr()

static pjsip_generic_string_hdr * generate_content_id_hdr ( pj_pool_t *  pool,
const struct ast_sip_subscription sub 
)
static

Create a Content-ID header.

Content-ID headers are required by RFC2387 for multipart/related bodies. They serve as identifiers for each part of the multipart body.

Parameters
poolPJLIB allocation pool
subSubscription to a resource

Definition at line 2153 of file res_pjsip_pubsub.c.

2155{
2156 static const pj_str_t cid_name = { "Content-ID", 10 };
2157 pjsip_generic_string_hdr *cid;
2158 char id[6];
2159 size_t alloc_size;
2160 pj_str_t cid_value;
2161
2162 /* '<' + '@' + '>' = 3. pj_str_t does not require a null-terminator */
2163 alloc_size = sizeof(id) + pj_strlen(&sub->uri->host) + 3;
2164 cid_value.ptr = pj_pool_alloc(pool, alloc_size);
2165 cid_value.slen = sprintf(cid_value.ptr, "<%s@%.*s>",
2166 ast_generate_random_string(id, sizeof(id)),
2167 (int) pj_strlen(&sub->uri->host), pj_strbuf(&sub->uri->host));
2168 cid = pjsip_generic_string_hdr_create(pool, &cid_name, &cid_value);
2169
2170 return cid;
2171}
enum queue_result id
Definition: app_queue.c:1638

References ast_generate_random_string(), id, and sub.

Referenced by allocate_body_part(), and build_rlmi_body().

◆ generate_initial_notify()

static int generate_initial_notify ( struct ast_sip_subscription sub)
static

Definition at line 2951 of file res_pjsip_pubsub.c.

2952{
2953 void *notify_data;
2954 int res;
2955 struct ast_sip_body_data data = {
2956 .body_type = sub->handler->body_type,
2957 };
2958
2959 if (AST_VECTOR_SIZE(&sub->children) > 0) {
2960 int i;
2961
2962 for (i = 0; i < AST_VECTOR_SIZE(&sub->children); ++i) {
2963 if (generate_initial_notify(AST_VECTOR_GET(&sub->children, i))) {
2964 return -1;
2965 }
2966 }
2967
2968 return 0;
2969 }
2970
2971 /* We notify subscription establishment only on the tree leaves. */
2972 if (sub->handler->notifier->subscription_established(sub)) {
2973 return -1;
2974 }
2975
2976 notify_data = sub->handler->notifier->get_notify_data(sub);
2977 if (!notify_data) {
2978 ast_debug(3, "No notify data, not generating any body content\n");
2979 return -1;
2980 }
2981
2982 data.body_data = notify_data;
2983
2985 ast_sip_subscription_get_body_subtype(sub), &data, &sub->body_text);
2986
2988
2989 return res;
2990}
static int generate_initial_notify(struct ast_sip_subscription *sub)
Data used to create bodies for NOTIFY/PUBLISH requests.

References ao2_cleanup, ast_debug, ast_sip_pubsub_generate_body_content(), ast_sip_subscription_get_body_subtype(), ast_sip_subscription_get_body_type(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_sip_body_data::body_data, ast_sip_body_data::body_type, generate_initial_notify(), and sub.

Referenced by generate_initial_notify(), initial_notify_task(), and pubsub_on_refresh_timeout().

◆ generate_list_body()

static pjsip_msg_body * generate_list_body ( pj_pool_t *  pool,
struct ast_sip_subscription sub,
unsigned int  force_full_state 
)
static

Create a resource list body for NOTIFY requests.

Resource list bodies are multipart/related bodies. The first part of the multipart body is an RLMI body that describes the rest of the parts to come. The other parts of the body convey state of individual subscribed resources.

Parameters
poolPJLIB allocation pool
subSubscription details from which to generate body
force_full_stateIf true, ignore resource list settings and send a full state notification
Returns
The generated multipart/related body

Definition at line 2371 of file res_pjsip_pubsub.c.

2373{
2374 int i;
2375 pjsip_multipart_part *rlmi_part;
2376 pjsip_msg_body *multipart;
2377 struct body_part_list body_parts;
2378 unsigned int use_full_state = force_full_state ? 1 : sub->full_state;
2379
2380 if (AST_VECTOR_INIT(&body_parts, AST_VECTOR_SIZE(&sub->children))) {
2381 return NULL;
2382 }
2383
2384 for (i = 0; i < AST_VECTOR_SIZE(&sub->children); ++i) {
2385 build_body_part(pool, AST_VECTOR_GET(&sub->children, i), &body_parts, use_full_state);
2386 }
2387
2388 /* This can happen if issuing partial state and no children of the list have changed state */
2389 if (AST_VECTOR_SIZE(&body_parts) == 0) {
2390 free_body_parts(&body_parts);
2391 return NULL;
2392 }
2393
2394 multipart = create_multipart_body(pool);
2395
2396 rlmi_part = build_rlmi_body(pool, sub, &body_parts, use_full_state);
2397 if (!rlmi_part) {
2398 free_body_parts(&body_parts);
2399 return NULL;
2400 }
2401 pjsip_multipart_add_part(pool, multipart, rlmi_part);
2402
2403 for (i = 0; i < AST_VECTOR_SIZE(&body_parts); ++i) {
2404 pjsip_multipart_add_part(pool, multipart, AST_VECTOR_GET(&body_parts, i)->part);
2405 }
2406
2407 free_body_parts(&body_parts);
2408 return multipart;
2409}
static void build_body_part(pj_pool_t *pool, struct ast_sip_subscription *sub, struct body_part_list *parts, unsigned int use_full_state)
Create a multipart body part for a subscribed resource.
static void free_body_parts(struct body_part_list *parts)
Destroy a list of body parts.
static pjsip_msg_body * create_multipart_body(pj_pool_t *pool)
Create and initialize the PJSIP multipart body structure for a resource list subscription.
static pjsip_multipart_part * build_rlmi_body(pj_pool_t *pool, struct ast_sip_subscription *sub, struct body_part_list *body_parts, unsigned int full_state)
Create an RLMI body part for a multipart resource list body.
Type declaration for container of body part structures.

References AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_SIZE, build_body_part(), build_rlmi_body(), create_multipart_body(), free_body_parts(), NULL, and sub.

Referenced by generate_notify_body().

◆ generate_notify_body()

static pjsip_msg_body * generate_notify_body ( pj_pool_t *  pool,
struct ast_sip_subscription root,
unsigned int  force_full_state 
)
static

Create the body for a NOTIFY request.

Parameters
poolThe pool used for allocations
rootThe root of the subscription tree
force_full_stateIf true, ignore resource list settings and send a full state notification

Definition at line 2418 of file res_pjsip_pubsub.c.

2420{
2421 pjsip_msg_body *body;
2422
2423 if (AST_VECTOR_SIZE(&root->children) == 0) {
2424 if (force_full_state || root->body_changed) {
2425 /* Not a list. We've already generated the body and saved it on the subscription.
2426 * Use that directly.
2427 */
2428 pj_str_t type;
2429 pj_str_t subtype;
2430 pj_str_t text;
2431
2433 pj_cstr(&subtype, ast_sip_subscription_get_body_subtype(root));
2434 pj_cstr(&text, ast_str_buffer(root->body_text));
2435
2436 body = pjsip_msg_body_create(pool, &type, &subtype, &text);
2437 root->body_changed = 0;
2438 } else {
2439 body = NULL;
2440 }
2441 } else {
2442 body = generate_list_body(pool, root, force_full_state);
2443 }
2444
2445 return body;
2446}
char * text
Definition: app_queue.c:1639
static pjsip_msg_body * generate_list_body(pj_pool_t *pool, struct ast_sip_subscription *sub, unsigned int force_full_state)
Create a resource list body for NOTIFY requests.
struct ast_str * body_text

References ast_sip_subscription_get_body_subtype(), ast_sip_subscription_get_body_type(), ast_str_buffer(), AST_VECTOR_SIZE, ast_sip_subscription::body_changed, ast_sip_subscription::body_text, ast_sip_subscription::children, generate_list_body(), NULL, text, and type.

Referenced by build_body_part(), and send_notify().

◆ have_visited()

static int have_visited ( const char *  resource,
struct resources visited 
)
static

Determine if this resource has been visited already.

See build_resource_tree for more information

Parameters
resourceThe resource currently being visited
visitedThe resources that have previously been visited

Definition at line 1008 of file res_pjsip_pubsub.c.

1009{
1010 int i;
1011
1012 for (i = 0; i < AST_VECTOR_SIZE(visited); ++i) {
1013 if (!strcmp(resource, AST_VECTOR_GET(visited, i))) {
1014 return 1;
1015 }
1016 }
1017
1018 return 0;
1019}

References AST_VECTOR_GET, AST_VECTOR_SIZE, and tree_node::resource.

Referenced by build_node_children().

◆ initial_notify_task()

static int initial_notify_task ( void *  obj)
static

Definition at line 2994 of file res_pjsip_pubsub.c.

2995{
2996 struct initial_notify_data *ind = obj;
2997
2999 pjsip_evsub_terminate(ind->sub_tree->evsub, PJ_TRUE);
3000 } else {
3001 send_notify(ind->sub_tree, 1);
3002 ast_test_suite_event_notify("SUBSCRIPTION_ESTABLISHED",
3003 "Resource: %s",
3004 ind->sub_tree->root->resource);
3005 }
3006
3008 char *name = ast_alloca(strlen("->/ ") +
3009 strlen(ind->sub_tree->persistence->endpoint) +
3010 strlen(ind->sub_tree->root->resource) +
3011 strlen(ind->sub_tree->root->handler->event_name) +
3012 ind->sub_tree->dlg->call_id->id.slen + 1);
3013
3014 sprintf(name, "%s->%s/%s %.*s", ind->sub_tree->persistence->endpoint,
3016 (int)ind->sub_tree->dlg->call_id->id.slen, ind->sub_tree->dlg->call_id->id.ptr);
3017
3018 ast_debug(3, "Scheduling timer: %s\n", name);
3022 if (!ind->sub_tree->expiration_task) {
3023 ast_log(LOG_ERROR, "Unable to create expiration timer of %d seconds for %s\n",
3024 ind->expires, name);
3025 }
3026 }
3027
3028 ao2_ref(ind->sub_tree, -1);
3029 ast_free(ind);
3030
3031 return 0;
3032}
struct ast_sip_sched_task * ast_sip_schedule_task(struct ast_taskprocessor *serializer, int interval, ast_sip_task sip_task, const char *name, void *task_data, enum ast_sip_scheduler_task_flags flags)
Schedule a task to run in the res_pjsip thread pool.
@ AST_SIP_SCHED_TASK_FIXED
Definition: res_pjsip.h:2075
@ AST_SIP_SCHED_TASK_DATA_AO2
Definition: res_pjsip.h:2098
#define PJSIP_EXPIRES_NOT_SPECIFIED
Definition: res_pjsip.h:68
static int pubsub_on_refresh_timeout(void *userdata)
struct sip_subscription_tree * sub_tree

References ao2_ref, ast_alloca, ast_debug, ast_free, ast_log, AST_SIP_SCHED_TASK_DATA_AO2, AST_SIP_SCHED_TASK_FIXED, ast_sip_schedule_task(), ast_test_suite_event_notify, sip_subscription_tree::dlg, subscription_persistence::endpoint, ast_sip_subscription_handler::event_name, sip_subscription_tree::evsub, sip_subscription_tree::expiration_task, initial_notify_data::expires, generate_initial_notify(), ast_sip_subscription::handler, LOG_ERROR, name, sip_subscription_tree::persistence, PJSIP_EXPIRES_NOT_SPECIFIED, pubsub_on_refresh_timeout(), ast_sip_subscription::resource, sip_subscription_tree::root, send_notify(), sip_subscription_tree::serializer, and initial_notify_data::sub_tree.

Referenced by pubsub_on_rx_subscribe_request(), and sub_persistence_recreate().

◆ item_in_vector()

static int item_in_vector ( const struct resource_list list,
const char *  item 
)
static

Definition at line 5024 of file res_pjsip_pubsub.c.

5025{
5026 int i;
5027
5028 for (i = 0; i < AST_VECTOR_SIZE(&list->items); ++i) {
5029 if (!strcmp(item, AST_VECTOR_GET(&list->items, i))) {
5030 return 1;
5031 }
5032 }
5033
5034 return 0;
5035}
static struct aco_type item
Definition: test_config.c:1463

References AST_VECTOR_GET, AST_VECTOR_SIZE, item, and resource_list::items.

Referenced by list_item_handler().

◆ list_item_handler()

static int list_item_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 5037 of file res_pjsip_pubsub.c.

5039{
5040 struct resource_list *list = obj;
5041 char *items = ast_strdupa(var->value);
5042 char *item;
5043
5044 while ((item = ast_strip(strsep(&items, ",")))) {
5045 if (ast_strlen_zero(item)) {
5046 continue;
5047 }
5048
5049 if (item_in_vector(list, item)) {
5050 ast_log(LOG_WARNING, "Ignoring duplicated list item '%s'\n", item);
5051 continue;
5052 }
5053
5054 item = ast_strdup(item);
5055 if (!item || AST_VECTOR_APPEND(&list->items, item)) {
5056 ast_free(item);
5057 return -1;
5058 }
5059 }
5060
5061 return 0;
5062}
#define var
Definition: ast_expr2f.c:605
static int item_in_vector(const struct resource_list *list, const char *item)
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223

References ast_free, ast_log, ast_strdup, ast_strdupa, ast_strip(), ast_strlen_zero(), AST_VECTOR_APPEND, item, item_in_vector(), resource_list::items, LOG_WARNING, strsep(), and var.

Referenced by apply_list_configuration().

◆ list_item_to_str()

static int list_item_to_str ( const void *  obj,
const intptr_t *  args,
char **  buf 
)
static

Definition at line 5064 of file res_pjsip_pubsub.c.

5065{
5066 const struct resource_list *list = obj;
5067 int i;
5068 struct ast_str *str = ast_str_create(32);
5069
5070 for (i = 0; i < AST_VECTOR_SIZE(&list->items); ++i) {
5071 ast_str_append(&str, 0, "%s,", AST_VECTOR_GET(&list->items, i));
5072 }
5073
5074 /* Chop off trailing comma */
5075 ast_str_truncate(str, -1);
5077 ast_free(str);
5078 return 0;
5079}
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
Definition: strings.h:786

References ast_free, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_truncate(), ast_strdup, AST_VECTOR_GET, AST_VECTOR_SIZE, buf, resource_list::items, and str.

Referenced by apply_list_configuration().

◆ load_module()

static int load_module ( void  )
static

Definition at line 5806 of file res_pjsip_pubsub.c.

5807{
5808 static const pj_str_t str_PUBLISH = { "PUBLISH", 7 };
5809 struct ast_sorcery *sorcery;
5810
5812
5813 if (!(sched = ast_sched_context_create())) {
5814 ast_log(LOG_ERROR, "Could not create scheduler for publication expiration\n");
5816 }
5817
5819 ast_log(LOG_ERROR, "Could not start scheduler thread for publication expiration\n");
5822 }
5823
5824 ast_sorcery_apply_config(sorcery, "res_pjsip_pubsub");
5825 ast_sorcery_apply_default(sorcery, "subscription_persistence", "astdb", "subscription_persistence");
5827 NULL, NULL)) {
5828 ast_log(LOG_ERROR, "Could not register subscription persistence object support\n");
5831 }
5832 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "packet", "", OPT_CHAR_ARRAY_T, 0,
5833 CHARFLDSET(struct subscription_persistence, packet));
5834 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "src_name", "", OPT_CHAR_ARRAY_T, 0,
5835 CHARFLDSET(struct subscription_persistence, src_name));
5836 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "src_port", "0", OPT_UINT_T, 0,
5837 FLDSET(struct subscription_persistence, src_port));
5838 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "transport_key", "0", OPT_CHAR_ARRAY_T, 0,
5839 CHARFLDSET(struct subscription_persistence, transport_type));
5840 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "local_name", "", OPT_CHAR_ARRAY_T, 0,
5841 CHARFLDSET(struct subscription_persistence, local_name));
5842 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "local_port", "0", OPT_UINT_T, 0,
5843 FLDSET(struct subscription_persistence, local_port));
5844 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "cseq", "0", OPT_UINT_T, 0,
5845 FLDSET(struct subscription_persistence, cseq));
5846 ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "endpoint", "",
5848 ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "tag", "",
5850 ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "expires", "",
5852 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "contact_uri", "", OPT_CHAR_ARRAY_T, 0,
5853 CHARFLDSET(struct subscription_persistence, contact_uri));
5854 ast_sorcery_object_field_register(sorcery, "subscription_persistence", "prune_on_boot", "no", OPT_YESNO_T, 1,
5855 FLDSET(struct subscription_persistence, prune_on_boot));
5856 ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "generator_data", "",
5858
5862 }
5863
5864 ast_sorcery_apply_default(sorcery, "inbound-publication", "config", "pjsip.conf,criteria=type=inbound-publication");
5866 NULL, NULL)) {
5867 ast_log(LOG_ERROR, "Could not register subscription persistence object support\n");
5870 }
5871 ast_sorcery_object_field_register(sorcery, "inbound-publication", "type", "",