Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Enumerations | Functions
res_pjsip_pubsub.h File Reference
#include "asterisk/linkedlists.h"
Include dependency graph for res_pjsip_pubsub.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_sip_body_data
 Data used to create bodies for NOTIFY/PUBLISH requests. More...
 
struct  ast_sip_notifier
 
struct  ast_sip_publish_handler
 Callbacks that publication handlers will define. More...
 
struct  ast_sip_pubsub_body_generator
 Pubsub body generator. More...
 
struct  ast_sip_pubsub_body_supplement
 Body supplement. More...
 
struct  ast_sip_subscriber
 
struct  ast_sip_subscription_handler
 
struct  ast_sip_subscription_response_data
 Data for responses to SUBSCRIBEs and NOTIFIEs. More...
 

Macros

#define AST_SIP_EXTEN_STATE_DATA   "ast_sip_exten_state_data"
 
#define AST_SIP_MAX_ACCEPT   32
 
#define AST_SIP_MESSAGE_ACCUMULATOR   "ast_sip_message_accumulator"
 

Enumerations

enum  ast_sip_publish_state { AST_SIP_PUBLISH_STATE_INITIALIZED, AST_SIP_PUBLISH_STATE_ACTIVE, AST_SIP_PUBLISH_STATE_TERMINATED }
 
enum  ast_sip_subscription_notify_reason { AST_SIP_SUBSCRIPTION_NOTIFY_REASON_STARTED, AST_SIP_SUBSCRIPTION_NOTIFY_REASON_RENEWED, AST_SIP_SUBSCRIPTION_NOTIFY_REASON_TERMINATED, AST_SIP_SUBSCRIPTION_NOTIFY_REASON_OTHER }
 
enum  ast_sip_subscription_role { AST_SIP_SUBSCRIBER, AST_SIP_NOTIFIER }
 Role for the subscription that is being created. More...
 

Functions

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 *content_type, const char *content_subtype, struct ast_sip_body_data *data, struct ast_str **str)
 Generate body content for a PUBLISH or NOTIFY. 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...
 
int ast_sip_subscription_send_request (struct ast_sip_subscription *sub, pjsip_tx_data *tdata)
 Send a request created via a PJSIP evsub method. 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...
 

Macro Definition Documentation

◆ AST_SIP_EXTEN_STATE_DATA

#define AST_SIP_EXTEN_STATE_DATA   "ast_sip_exten_state_data"

Type used for extension state/presence

Definition at line 232 of file res_pjsip_pubsub.h.

Referenced by exten_state_publisher_cb(), and notify_task().

◆ AST_SIP_MAX_ACCEPT

#define AST_SIP_MAX_ACCEPT   32

◆ AST_SIP_MESSAGE_ACCUMULATOR

#define AST_SIP_MESSAGE_ACCUMULATOR   "ast_sip_message_accumulator"

Type used for conveying mailbox state

Definition at line 234 of file res_pjsip_pubsub.h.

Referenced by send_mwi_notify(), and send_unsolicited_mwi_notify_to_contact().

Enumeration Type Documentation

◆ ast_sip_publish_state

Enumerator
AST_SIP_PUBLISH_STATE_INITIALIZED 

Publication has just been initialized

AST_SIP_PUBLISH_STATE_ACTIVE 

Publication is currently active

AST_SIP_PUBLISH_STATE_TERMINATED 

Publication has been terminated

Definition at line 37 of file res_pjsip_pubsub.h.

37  {
38  /*! Publication has just been initialized */
40  /*! Publication is currently active */
42  /*! Publication has been terminated */
44 };

◆ ast_sip_subscription_notify_reason

Enumerator
AST_SIP_SUBSCRIPTION_NOTIFY_REASON_STARTED 

Initial NOTIFY for subscription

AST_SIP_SUBSCRIPTION_NOTIFY_REASON_RENEWED 

Subscription has been renewed

AST_SIP_SUBSCRIPTION_NOTIFY_REASON_TERMINATED 

Subscription is being terminated

AST_SIP_SUBSCRIPTION_NOTIFY_REASON_OTHER 

Other unspecified reason

Definition at line 220 of file res_pjsip_pubsub.h.

◆ ast_sip_subscription_role

Role for the subscription that is being created.

Enumerator
AST_SIP_SUBSCRIBER 
AST_SIP_NOTIFIER 

Definition at line 190 of file res_pjsip_pubsub.h.

190  {
191  /* Sending SUBSCRIBEs, receiving NOTIFYs */
193  /* Sending NOTIFYs, receiving SUBSCRIBEs */
195 };

Function Documentation

◆ 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
subscriberThe 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 1868 of file res_pjsip_pubsub.c.

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, resource_list::event, ast_sip_subscription_handler::event_name, sip_subscription_tree::evsub, LOG_WARNING, NULL, pubsub_cb, sub, subscription_setup_dialog(), and ast_sip_contact::uri.

1870 {
1871  struct ast_sip_subscription *sub;
1872  pjsip_dialog *dlg;
1873  struct ast_sip_contact *contact;
1874  pj_str_t event;
1875  pjsip_tx_data *tdata;
1876  pjsip_evsub *evsub;
1877  struct sip_subscription_tree *sub_tree = NULL;
1878 
1879  sub_tree = allocate_subscription_tree(endpoint, NULL);
1880  if (!sub_tree) {
1881  return NULL;
1882  }
1883 
1884  sub = allocate_subscription(handler, resource, sub_tree);
1885  if (!sub) {
1886  ao2_cleanup(sub_tree);
1887  return NULL;
1888  }
1889 
1891  if (!contact || ast_strlen_zero(contact->uri)) {
1892  ast_log(LOG_WARNING, "No contacts configured for endpoint %s. Unable to create SIP subsription\n",
1893  ast_sorcery_object_get_id(endpoint));
1894  ao2_ref(sub_tree, -1);
1895  ao2_cleanup(contact);
1896  return NULL;
1897  }
1898 
1899  dlg = ast_sip_create_dialog_uac(endpoint, contact->uri, NULL);
1900  ao2_cleanup(contact);
1901  if (!dlg) {
1902  ast_log(LOG_WARNING, "Unable to create dialog for SIP subscription\n");
1903  ao2_ref(sub_tree, -1);
1904  return NULL;
1905  }
1906 
1907  pj_cstr(&event, handler->event_name);
1908  pjsip_evsub_create_uac(dlg, &pubsub_cb, &event, 0, &sub_tree->evsub);
1909  subscription_setup_dialog(sub_tree, dlg);
1910 
1911  evsub = sub_tree->evsub;
1912 
1913  if (pjsip_evsub_initiate(evsub, NULL, -1, &tdata) == PJ_SUCCESS) {
1914  pjsip_evsub_send_request(sub_tree->evsub, tdata);
1915  } else {
1916  /* pjsip_evsub_terminate will result in pubsub_on_evsub_state,
1917  * being called and terminating the subscription. Therefore, we don't
1918  * need to decrease the reference count of sub here.
1919  */
1920  pjsip_evsub_terminate(evsub, PJ_TRUE);
1921  ao2_ref(sub_tree, -1);
1922  return NULL;
1923  }
1924 
1925  add_subscription(sub_tree);
1926 
1927  return sub;
1928 }
static void add_subscription(struct sip_subscription_tree *obj)
#define LOG_WARNING
Definition: logger.h:274
Definition: astman.c:222
static pjsip_evsub_user pubsub_cb
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ao2_ref(o, delta)
Definition: astobj2.h:464
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
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
Structure representing a "virtual" SIP subscription.
static void subscription_setup_dialog(struct sip_subscription_tree *sub_tree, pjsip_dialog *dlg)
Contact associated with an address of record.
Definition: res_pjsip.h:281
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct ast_sip_subscription * allocate_subscription(const struct ast_sip_subscription_handler *handler, const char *resource, struct sip_subscription_tree *tree)
struct stasis_forward * sub
Definition: res_corosync.c:240
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:4028
const ast_string_field aors
Definition: res_pjsip.h:821
const ast_string_field uri
Definition: res_pjsip.h:303
A tree of SIP subscriptions.
static struct sip_subscription_tree * allocate_subscription_tree(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)

◆ 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 2649 of file res_pjsip_pubsub.c.

References ast_datastores_add(), and ast_sip_publication::datastores.

2650 {
2651  return ast_datastores_add(publication->datastores, datastore);
2652 }
int ast_datastores_add(struct ao2_container *datastores, struct ast_datastore *datastore)
Add a data store to a container.
Definition: datastore.c:101
struct ao2_container * 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 2654 of file res_pjsip_pubsub.c.

References ast_datastores_find(), and ast_sip_publication::datastores.

2655 {
2656  return ast_datastores_find(publication->datastores, name);
2657 }
struct ast_datastore * ast_datastores_find(struct ao2_container *datastores, const char *name)
Find a data store in a container.
Definition: datastore.c:119
struct ao2_container * datastores
static const char name[]
Definition: cdr_mysql.c:74

◆ 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 2664 of file res_pjsip_pubsub.c.

References ast_sip_publication::datastores.

2665 {
2666  return publication->datastores;
2667 }
struct ao2_container * 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 3420 of file res_pjsip_pubsub.c.

References ast_sip_publication::endpoint.

3421 {
3422  return pub->endpoint;
3423 }
struct ast_sip_endpoint * endpoint
The endpoint with which the subscription is communicating.

◆ 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 3430 of file res_pjsip_pubsub.c.

References ast_sip_publication::event_configuration_name.

Referenced by asterisk_publication_devicestate_state_change(), and asterisk_publication_mwi_state_change().

3431 {
3432  return pub->event_configuration_name;
3433 }
char * event_configuration_name
The name of the event type configuration.

◆ 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 3425 of file res_pjsip_pubsub.c.

References ast_sip_publication::resource.

3426 {
3427  return pub->resource;
3428 }
char * resource
The resource the publication is to.

◆ 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 2659 of file res_pjsip_pubsub.c.

References ast_datastores_remove(), and ast_sip_publication::datastores.

2660 {
2661  ast_datastores_remove(publication->datastores, name);
2662 }
struct ao2_container * datastores
static const char name[]
Definition: cdr_mysql.c:74
void ast_datastores_remove(struct ao2_container *datastores, const char *name)
Remove a data store from a container.
Definition: datastore.c:114

◆ 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 3519 of file res_pjsip_pubsub.c.

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, generator, ast_sip_pubsub_body_generator::list, LOG_WARNING, 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, 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().

3521 {
3522  struct ast_sip_pubsub_body_supplement *supplement;
3524  int res = 0;
3525  void *body;
3526 
3528  if (!generator) {
3529  ast_log(LOG_WARNING, "Unable to find a body generator for %s/%s\n",
3530  type, subtype);
3531  return -1;
3532  }
3533 
3534  if (strcmp(data->body_type, generator->body_type)) {
3535  ast_log(LOG_WARNING, "%s/%s body generator does not accept the type of data provided\n",
3536  type, subtype);
3537  return -1;
3538  }
3539 
3540  body = generator->allocate_body(data->body_data);
3541  if (!body) {
3542  ast_log(LOG_WARNING, "%s/%s body generator could not to allocate a body\n",
3543  type, subtype);
3544  return -1;
3545  }
3546 
3547  if (generator->generate_body_content(body, data->body_data)) {
3548  res = -1;
3549  goto end;
3550  }
3551 
3553  AST_RWLIST_TRAVERSE(&body_supplements, supplement, list) {
3554  if (!strcmp(generator->type, supplement->type) &&
3555  !strcmp(generator->subtype, supplement->subtype)) {
3556  res = supplement->supplement_body(body, data->body_data);
3557  if (res) {
3558  break;
3559  }
3560  }
3561  }
3563 
3564  if (!res) {
3565  generator->to_string(body, str);
3566  }
3567 
3568 end:
3569  if (generator->destroy_body) {
3570  generator->destroy_body(body);
3571  }
3572 
3573  return res;
3574 }
void(* to_string)(void *body, struct ast_str **str)
Convert the body to a string.
static const char type[]
Definition: chan_ooh323.c:109
Pubsub body generator.
const char * type
Content type In "plain/text", "plain" is the type.
const char * body_type
#define LOG_WARNING
Definition: logger.h:274
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * type
Content type In "plain/text", "plain" is the type.
char * end
Definition: eagi_proxy.c:73
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const char * subtype
Content subtype In "plain/text", "text" is the subtype.
#define ast_log
Definition: astobj2.c:42
void *(* allocate_body)(void *data)
allocate body structure.
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype(const char *type, const char *subtype)
const char * subtype
Content subtype In "plain/text", "text" is the subtype.
struct ast_sip_pubsub_body_generator::@306 list
static struct ast_generator generator
Definition: app_fax.c:359
void(* destroy_body)(void *body)
Deallocate resources created for the body.
int(* supplement_body)(void *body, void *data)
Add additional content to a SIP request body.
int(* generate_body_content)(void *body, void *data)
Add content to the body of a SIP request.

◆ 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 3435 of file res_pjsip_pubsub.c.

References find_body_generator_type_subtype().

Referenced by publisher_start().

3436 {
3438 }
static const char type[]
Definition: chan_ooh323.c:109
static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype(const char *type, const char *subtype)
const char * subtype
Content subtype In "plain/text", "text" is the subtype.

◆ 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 3440 of file res_pjsip_pubsub.c.

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().

3441 {
3442  struct ast_sip_pubsub_body_generator *existing;
3443  pj_str_t accept;
3444  pj_size_t accept_len;
3445 
3447  existing = find_body_generator_type_subtype_nolock(generator->type, generator->subtype);
3448  if (existing) {
3450  ast_log(LOG_WARNING, "A body generator for %s/%s is already registered.\n",
3451  generator->type, generator->subtype);
3452  return -1;
3453  }
3456 
3457  /* Lengths of type and subtype plus a slash. */
3458  accept_len = strlen(generator->type) + strlen(generator->subtype) + 1;
3459 
3460  /* Add room for null terminator that sprintf() will set. */
3461  pj_strset(&accept, ast_alloca(accept_len + 1), accept_len);
3462  sprintf((char *) pj_strbuf(&accept), "%s/%s", generator->type, generator->subtype);/* Safe */
3463 
3464  pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), &pubsub_module,
3465  PJSIP_H_ACCEPT, NULL, 1, &accept);
3466 
3467  return 0;
3468 }
static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype_nolock(const char *type, const char *subtype)
static struct pjsip_module pubsub_module
Pubsub body generator.
const char * type
Content type In "plain/text", "plain" is the type.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
const char * subtype
Content subtype In "plain/text", "text" is the subtype.
struct ast_sip_pubsub_body_generator::@306 list
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:3718

◆ 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
generatorBody generator to register
Return values
0Success
-1Failure

Definition at line 3485 of file res_pjsip_pubsub.c.

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

Referenced by load_module().

3486 {
3490 
3491  return 0;
3492 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
struct ast_sip_pubsub_body_generator::@306 list
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740

◆ 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 3470 of file res_pjsip_pubsub.c.

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().

3471 {
3472  struct ast_sip_pubsub_body_generator *iter;
3473 
3476  if (iter == generator) {
3478  break;
3479  }
3480  }
3483 }
Pubsub body generator.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
struct ast_sip_pubsub_body_generator::@306 list
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ 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
generatorBody generator to unregister

Definition at line 3494 of file res_pjsip_pubsub.c.

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().

3495 {
3496  struct ast_sip_pubsub_body_supplement *iter;
3497 
3500  if (iter == supplement) {
3502  break;
3503  }
3504  }
3507 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
struct ast_sip_pubsub_body_supplement::@307 list
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ 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 2718 of file res_pjsip_pubsub.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_log, ast_strlen_zero, ast_sip_publish_handler::event_name, LOG_ERROR, NULL, publication_cmp_fn(), publication_hash_fn(), ast_sip_publish_handler::publications, PUBLICATIONS_BUCKETS, and publish_add_handler().

Referenced by load_module().

2719 {
2720  if (ast_strlen_zero(handler->event_name)) {
2721  ast_log(LOG_ERROR, "No event package specified for publish handler. Cannot register\n");
2722  return -1;
2723  }
2724 
2727  if (!handler->publications) {
2728  ast_log(LOG_ERROR, "Could not allocate publications container for event '%s'\n",
2729  handler->event_name);
2730  return -1;
2731  }
2732 
2733  publish_add_handler(handler);
2734 
2735  return 0;
2736 }
const char * event_name
The name of the event this handler deals with.
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define PUBLICATIONS_BUCKETS
Number of buckets for publications (on a per handler)
static void publish_add_handler(struct ast_sip_publish_handler *handler)
static int publication_hash_fn(const void *obj, const int flags)
#define LOG_ERROR
Definition: logger.h:285
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
static int publication_cmp_fn(void *obj, void *arg, int flags)
struct ao2_container * publications
Publications.

◆ 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 2777 of file res_pjsip_pubsub.c.

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

Referenced by load_module().

2778 {
2779  pj_str_t event;
2780  pj_str_t accept[AST_SIP_MAX_ACCEPT] = { {0, }, };
2781  struct ast_sip_subscription_handler *existing;
2782  int i = 0;
2783 
2784  if (ast_strlen_zero(handler->event_name)) {
2785  ast_log(LOG_ERROR, "No event package specified for subscription handler. Cannot register\n");
2786  return -1;
2787  }
2788 
2789  existing = find_sub_handler_for_event_name(handler->event_name);
2790  if (existing) {
2792  "Unable to register subscription handler for event %s. A handler is already registered\n",
2793  handler->event_name);
2794  return -1;
2795  }
2796 
2797  for (i = 0; i < AST_SIP_MAX_ACCEPT && !ast_strlen_zero(handler->accept[i]); ++i) {
2798  pj_cstr(&accept[i], handler->accept[i]);
2799  }
2800 
2801  pj_cstr(&event, handler->event_name);
2802 
2803  pjsip_evsub_register_pkg(&pubsub_module, &event, DEFAULT_EXPIRES, i, accept);
2804 
2805  sub_add_handler(handler);
2806 
2807  return 0;
2808 }
static struct pjsip_module pubsub_module
const char * accept[AST_SIP_MAX_ACCEPT]
#define DEFAULT_EXPIRES
Default expiration for subscriptions.
Definition: astman.c:222
static void sub_add_handler(struct ast_sip_subscription_handler *handler)
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define AST_SIP_MAX_ACCEPT
#define LOG_ERROR
Definition: logger.h:285
static struct ast_sip_subscription_handler * find_sub_handler_for_event_name(const char *event_name)

◆ 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 2629 of file res_pjsip_pubsub.c.

References ast_datastores_add(), and ast_sip_subscription::datastores.

Referenced by add_datastore(), and add_mwi_datastore().

2630 {
2631  return ast_datastores_add(subscription->datastores, datastore);
2632 }
int ast_datastores_add(struct ao2_container *datastores, struct ast_datastore *datastore)
Add a data store to a container.
Definition: datastore.c:101
struct ao2_container * datastores

◆ 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 2624 of file res_pjsip_pubsub.c.

References ast_datastores_alloc_datastore().

Referenced by add_datastore(), and add_mwi_datastore().

2625 {
2626  return ast_datastores_alloc_datastore(info, uid);
2627 }
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:138

◆ 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
Returns
Nothing

Definition at line 1389 of file res_pjsip_pubsub.c.

References ao2_cleanup, ast_debug, ast_sorcery_object_get_id(), sip_subscription_tree::endpoint, and ast_sip_subscription::tree.

Referenced by exten_state_subscription_destructor(), and mwi_subscription_destructor().

1390 {
1391  ast_debug(3, "Removing subscription %p '%s->%s' reference to subscription tree %p\n",
1392  sub, ast_sorcery_object_get_id(sub->tree->endpoint), sub->resource, sub->tree);
1393  ao2_cleanup(sub->tree);
1394 }
struct sip_subscription_tree * tree
struct ast_sip_endpoint * endpoint
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ 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 3514 of file res_pjsip_pubsub.c.

References ast_sip_subscription::body_generator, and ast_sip_pubsub_body_generator::subtype.

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

3515 {
3516  return sub->body_generator->subtype;
3517 }
struct ast_sip_pubsub_body_generator * body_generator
const char * subtype
Content subtype In "plain/text", "text" is the subtype.

◆ 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 3509 of file res_pjsip_pubsub.c.

References ast_sip_subscription::body_generator, and ast_sip_pubsub_body_generator::type.

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

3510 {
3511  return sub->body_generator->type;
3512 }
const char * type
Content type In "plain/text", "plain" is the type.
struct ast_sip_pubsub_body_generator * body_generator

◆ 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 2634 of file res_pjsip_pubsub.c.

References ast_datastores_find(), and ast_sip_subscription::datastores.

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

2635 {
2636  return ast_datastores_find(subscription->datastores, name);
2637 }
struct ast_datastore * ast_datastores_find(struct ao2_container *datastores, const char *name)
Find a data store in a container.
Definition: datastore.c:119
struct ao2_container * datastores
static const char name[]
Definition: cdr_mysql.c:74

◆ 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 2644 of file res_pjsip_pubsub.c.

References ast_sip_subscription::datastores.

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

2645 {
2646  return subscription->datastores;
2647 }
struct ao2_container * datastores

◆ 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 1930 of file res_pjsip_pubsub.c.

References ast_assert, sip_subscription_tree::dlg, NULL, and ast_sip_subscription::tree.

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

1931 {
1932  ast_assert(sub->tree->dlg != NULL);
1933  return sub->tree->dlg;
1934 }
struct sip_subscription_tree * tree
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96

◆ 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 1936 of file res_pjsip_pubsub.c.

References ao2_bump, ast_assert, sip_subscription_tree::endpoint, NULL, and ast_sip_subscription::tree.

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

1937 {
1938  ast_assert(sub->tree->endpoint != NULL);
1939  return ao2_bump(sub->tree->endpoint);
1940 }
struct sip_subscription_tree * tree
struct ast_sip_endpoint * endpoint
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491

◆ 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 1854 of file res_pjsip_pubsub.c.

References ast_sip_mod_data_get, sip_subscription_tree::dlg, MOD_DATA_MSG, name, NULL, pubsub_module, and ast_sip_subscription::tree.

Referenced by get_user_agent().

1855 {
1856  pjsip_dialog *dlg;
1857  pjsip_msg *msg;
1858  pj_str_t name;
1859 
1860  dlg = sub->tree->dlg;
1861  msg = ast_sip_mod_data_get(dlg->mod_data, pubsub_module.id, MOD_DATA_MSG);
1862  pj_cstr(&name, header);
1863 
1864  return pjsip_msg_find_hdr_by_name(msg, &name, NULL);
1865 }
struct sip_subscription_tree * tree
static struct pjsip_module pubsub_module
#define NULL
Definition: resample.c:96
#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:2638
static const char name[]
Definition: cdr_mysql.c:74
#define MOD_DATA_MSG

◆ 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 2578 of file res_pjsip_pubsub.c.

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

2579 {
2580  pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, sub->uri, buf, size);
2581 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66

◆ 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 2686 of file res_pjsip_pubsub.c.

Referenced by dialog_info_generate_body_content().

2687 {
2688  return subscription->persistence_data;
2689 }

◆ 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 2583 of file res_pjsip_pubsub.c.

References sip_subscription_tree::dlg, and ast_sip_subscription::tree.

Referenced by exten_state_data_alloc(), and notify_task().

2584 {
2585  pjsip_dialog *dlg;
2586  pjsip_sip_uri *uri;
2587 
2588  dlg = sub->tree->dlg;
2589  uri = pjsip_uri_get_uri(dlg->remote.info->uri);
2590 
2591  if (pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, uri, buf, size) < 0) {
2592  *buf = '\0';
2593  }
2594 }
struct sip_subscription_tree * tree
char buf[BUFSIZE]
Definition: eagi_proxy.c:66

◆ 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 2596 of file res_pjsip_pubsub.c.

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

2597 {
2598  return sub->resource;
2599 }

◆ 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 1942 of file res_pjsip_pubsub.c.

References ast_assert, NULL, sip_subscription_tree::serializer, and ast_sip_subscription::tree.

Referenced by exten_state_subscription_alloc(), and send_notify().

1943 {
1944  ast_assert(sub->tree->serializer != NULL);
1945  return sub->tree->serializer;
1946 }
struct sip_subscription_tree * tree
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
struct ast_taskprocessor * serializer

◆ 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 2573 of file res_pjsip_pubsub.c.

Referenced by mwi_get_notify_data(), and send_mwi_notify().

2574 {
2575  return sub->uri;
2576 }

◆ 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 2601 of file res_pjsip_pubsub.c.

Referenced by notify_task().

2602 {
2603  return sub->subscription_state == PJSIP_EVSUB_STATE_TERMINATED ? 1 : 0;
2604 }

◆ 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 2529 of file res_pjsip_pubsub.c.

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, sip_subscription_tree::notification_batch_interval, sip_subscription_tree::root, schedule_notification(), send_notify(), SIP_SUB_TREE_NORMAL, SIP_SUB_TREE_TERMINATE_IN_PROGRESS, SIP_SUB_TREE_TERMINATE_PENDING, sip_subscription_tree::state, and ast_sip_subscription::tree.

Referenced by notify_task(), and send_mwi_notify().

2531 {
2532  int res;
2533  pjsip_dialog *dlg = sub->tree->dlg;
2534 
2535  pjsip_dlg_inc_lock(dlg);
2536 
2537  if (sub->tree->state != SIP_SUB_TREE_NORMAL) {
2538  pjsip_dlg_dec_lock(dlg);
2539  return 0;
2540  }
2541 
2543  ast_sip_subscription_get_body_subtype(sub), notify_data, &sub->body_text)) {
2544  pjsip_dlg_dec_lock(dlg);
2545  return -1;
2546  }
2547 
2548  sub->body_changed = 1;
2549  if (terminate) {
2550  sub->subscription_state = PJSIP_EVSUB_STATE_TERMINATED;
2552  }
2553 
2554  if (sub->tree->notification_batch_interval) {
2555  res = schedule_notification(sub->tree);
2556  } else {
2557  /* See the note in pubsub_on_rx_refresh() for why sub->tree is refbumped here */
2558  ao2_ref(sub->tree, +1);
2559  if (terminate) {
2561  }
2562  res = send_notify(sub->tree, 0);
2563  ast_test_suite_event_notify(terminate ? "SUBSCRIPTION_TERMINATED" : "SUBSCRIPTION_STATE_CHANGED",
2564  "Resource: %s",
2565  sub->tree->root->resource);
2566  ao2_ref(sub->tree, -1);
2567  }
2568 
2569  pjsip_dlg_dec_lock(dlg);
2570  return res;
2571 }
struct ast_sip_subscription * root
struct sip_subscription_tree * tree
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.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
enum sip_subscription_tree_state state
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:196
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.
const char * ast_sip_subscription_get_body_type(struct ast_sip_subscription *sub)
Get the body type 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.
unsigned int notification_batch_interval

◆ 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 2639 of file res_pjsip_pubsub.c.

References ast_datastores_remove(), and ast_sip_subscription::datastores.

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

2640 {
2641  ast_datastores_remove(subscription->datastores, name);
2642 }
struct ao2_container * datastores
static const char name[]
Definition: cdr_mysql.c:74
void ast_datastores_remove(struct ao2_container *datastores, const char *name)
Remove a data store from a container.
Definition: datastore.c:114

◆ ast_sip_subscription_send_request()

int ast_sip_subscription_send_request ( struct ast_sip_subscription sub,
pjsip_tx_data *  tdata 
)

Send a request created via a PJSIP evsub method.

Callers of this function should take care to do so within a SIP servant thread.

Parameters
subThe subscription on which to send the request
tdataThe request to send
Return values
0Success
non-zeroFailure

◆ 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 2669 of file res_pjsip_pubsub.c.

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

Referenced by dialog_info_generate_body_content().

2670 {
2671  ast_json_unref(subscription->persistence_data);
2672  subscription->persistence_data = persistence_data;
2673 
2674  if (subscription->tree->persistence) {
2675  if (!subscription->tree->persistence->generator_data) {
2677  if (!subscription->tree->persistence->generator_data) {
2678  return;
2679  }
2680  }
2681  ast_json_object_set(subscription->tree->persistence->generator_data, subscription->resource,
2682  ast_json_ref(persistence_data));
2683  }
2684 }
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct sip_subscription_tree * tree
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct subscription_persistence * persistence
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:404
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:389
struct ast_json * generator_data

◆ ast_sip_unregister_publish_handler()

void ast_sip_unregister_publish_handler ( struct ast_sip_publish_handler handler)

Unregister a publish handler.

Definition at line 2738 of file res_pjsip_pubsub.c.

References ao2_cleanup, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_sip_publish_handler::next, and ast_sip_publish_handler::publications.

Referenced by load_module(), and unload_module().

2739 {
2740  struct ast_sip_publish_handler *iter;
2741 
2744  if (handler == iter) {
2746  ao2_cleanup(handler->publications);
2747  break;
2748  }
2749  }
2752 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
struct ast_sip_publish_handler * next
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
Callbacks that publication handlers will define.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ao2_container * publications
Publications.
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ ast_sip_unregister_subscription_handler()

void ast_sip_unregister_subscription_handler ( struct ast_sip_subscription_handler handler)

Unregister a subscription handler.

Definition at line 2810 of file res_pjsip_pubsub.c.

References AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_sip_subscription_handler::next.

Referenced by unload_module().

2811 {
2812  struct ast_sip_subscription_handler *iter;
2813 
2816  if (handler == iter) {
2818  break;
2819  }
2820  }
2823 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
struct ast_sip_subscription_handler * next
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616