31 #include <pjsip_simple.h> 230 .name = {
"PubSub Module", 13 },
231 .priority = PJSIP_MOD_PRIORITY_APPLICATION,
235 #define MOD_DATA_PERSISTENCE "sub_persistence" 236 #define MOD_DATA_MSG "sub_msg" 244 #define PUBLICATIONS_BUCKETS 37 247 #define DEFAULT_PUBLISH_EXPIRES 3600 250 #define DATASTORE_BUCKETS 53 253 #define DEFAULT_EXPIRES 3600 376 char packet[PJSIP_MAX_PKT_LEN];
378 char src_name[PJ_INET6_ADDRSTRLEN];
382 char transport_key[32];
384 char local_name[PJ_INET6_ADDRSTRLEN];
392 struct timeval expires;
394 char contact_uri[PJSIP_MAX_URL_SIZE];
418 "TerminateInProgress",
493 pjsip_evsub_state subscription_state;
543 int *p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body);
545 pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body);
576 if (!sub_tree->
evsub) {
582 ast_debug(3,
"Transport destroyed. Removing subscription '%s->%s' prune on boot: %d\n",
587 pjsip_evsub_terminate(sub_tree->
evsub, PJ_TRUE);
639 char tag[PJ_GUID_STRING_LENGTH + 1];
645 "subscription_persistence",
NULL);
647 pjsip_dialog *dlg = sub_tree->
dlg;
671 ast_debug(3,
"Updating persistence for '%s->%s' prune on boot: %s\n",
680 pjsip_expires_hdr *expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES,
NULL);
681 pjsip_contact_hdr *contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,
NULL);
691 (pjsip_sip_uri *)pjsip_uri_get_uri(contact_hdr->uri),
695 ast_debug(3,
"adding transport monitor on %s for '%s->%s' prune on boot: %d\n",
696 rdata->tp_info.transport->obj_name,
699 sub_tree->
transport = rdata->tp_info.transport;
709 pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri,
723 if (rdata->msg_info.msg_buf) {
752 ast_debug(3,
"Unregistering transport monitor on %s '%s->%s'\n",
755 sub_tree->
root ? sub_tree->
root->resource :
"Unknown");
768 size_t num_accept,
const char *
body_type);
773 pjsip_event_hdr *event_header;
777 event_header = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &
str_event_name, rdata->msg_info.msg->hdr.next);
780 endpoint ? endpoint :
"Unknown");
788 endpoint ? endpoint :
"Unknown");
808 "application/rlmi+xml",
834 pjsip_accept_hdr *accept_header = (pjsip_accept_hdr *) &rdata->msg_info.msg->hdr;
836 size_t num_accept_headers = 0;
838 while ((accept_header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_ACCEPT, accept_header->next)) &&
842 for (i = 0; i < accept_header->count && num_accept_headers <
AST_SIP_MAX_ACCEPT; ++i) {
844 ast_copy_pj_str(accept[num_accept_headers], &accept_header->values[i],
sizeof(accept[num_accept_headers]));
845 ++num_accept_headers;
850 if (num_accept_headers == 0) {
855 num_accept_headers = 1;
868 pjsip_supported_hdr *supported_header = (pjsip_supported_hdr *) &rdata->msg_info.msg->hdr;
870 while ((supported_header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_SUPPORTED, supported_header->next))) {
873 for (i = 0; i < supported_header->count; i++) {
874 if (!pj_stricmp2(&supported_header->values[i],
"eventlist")) {
911 if (strcmp(list->
event, event)) {
912 ast_log(
LOG_WARNING,
"Found resource list %s, but its event type (%s) does not match SUBSCRIBE's (%s)\n",
913 resource, list->
event, event);
938 node =
ast_calloc(1,
sizeof(*node) + strlen(resource) + 1);
943 strcpy(node->resource, resource);
987 static int have_visited(
const char *resource,
struct resources *visited)
1032 ast_debug(1,
"Already visited resource %s. Avoiding duplicate resource or potential loop.\n", resource);
1039 if (PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {
1043 "Subscription to leaf resource %s was successful, but encountered allocation error afterwards\n",
1047 ast_debug(2,
"Subscription to leaf resource %s resulted in success. Adding to parent %s\n",
1048 resource, parent->resource);
1053 ast_debug(2,
"Subscription to leaf resource %s resulted in error response %d\n",
1057 ast_debug(2,
"Resource %s (child of %s) is a list\n", resource, parent->resource);
1060 ast_debug(1,
"Cannot build children of resource %s due to allocation failure\n", resource);
1065 ast_debug(1,
"List %s had no successful children.\n", resource);
1070 ast_debug(2,
"List %s had successful children. Adding to parent %s\n",
1071 resource, parent->resource);
1136 const char *resource,
struct resource_tree *tree,
int has_eventlist_support)
1139 struct resources visited;
1142 ast_debug(2,
"Subscription '%s->%s' is not to a list\n",
1151 ast_debug(2,
"Subscription '%s->%s' is a list\n",
1191 ast_debug(2,
"Removing subscription '%s->%s' from list of subscriptions\n",
1203 ast_debug(3,
"Destroying SIP subscription from '%s->%s'\n",
1237 pjsip_sip_uri *contact_uri;
1239 sub =
ast_calloc(1,
sizeof(*sub) + strlen(resource) + 1);
1243 strcpy(sub->resource, resource);
1252 if (!sub->body_text) {
1257 sub->uri = pjsip_sip_uri_create(tree->
dlg->pool, PJ_FALSE);
1258 contact_uri = pjsip_uri_get_uri(tree->
dlg->local.contact->uri);
1259 pjsip_sip_uri_assign(tree->
dlg->pool, sub->uri, contact_uri);
1260 pj_strdup2(tree->
dlg->pool, &sub->uri->user, resource);
1271 sub->subscription_state = PJSIP_EVSUB_STATE_ACTIVE;
1298 sub->full_state = current->full_state;
1310 ast_debug(1,
"Child subscription to resource %s could not be created\n",
1311 child_node->resource);
1316 ast_debug(1,
"Child subscription to resource %s could not be appended\n",
1317 child_node->resource);
1371 ast_debug(3,
"Destroying subscription tree %p '%s->%s'\n",
1374 sub_tree->
root ? sub_tree->
root->resource :
"Unknown");
1378 if (sub_tree->
dlg) {
1391 ast_debug(3,
"Removing subscription %p '%s->%s' reference to subscription tree %p\n",
1475 *dlg_status = PJ_ENOMEM;
1482 if (*dlg_status != PJ_EEXISTS) {
1493 pjsip_ua_unregister_dlg(pjsip_ua_instance(), dlg);
1494 pj_strdup2(dlg->pool, &dlg->local.info->tag, persistence->
tag);
1495 dlg->local.tag_hval = pj_hash_calc_tolower(0,
NULL, &dlg->local.info->tag);
1496 pjsip_ua_register_dlg(pjsip_ua_instance(), dlg);
1497 dlg->local.cseq = persistence->
cseq;
1500 pjsip_evsub_create_uas(dlg, &
pubsub_cb, rdata, 0, &sub_tree->
evsub);
1509 pjsip_dlg_dec_lock(dlg);
1511 #ifdef HAVE_PJSIP_EVSUB_GRP_LOCK 1512 pjsip_evsub_add_ref(sub_tree->
evsub);
1516 pjsip_msg_clone(dlg->pool, rdata->msg_info.msg));
1560 pjsip_rx_data *rdata = recreate_data->
rdata;
1566 pjsip_sip_uri *request_uri;
1567 size_t resource_size;
1570 pjsip_expires_hdr *expires_header;
1573 request_uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
1574 resource_size = pj_strlen(&request_uri->user) + 1;
1585 if (!handler || !handler->
notifier) {
1586 ast_log(
LOG_WARNING,
"Failed recreating '%s' subscription: Could not get subscription handler.\n",
1594 ast_log(
LOG_WARNING,
"Failed recreating '%s' subscription: Body generator not available.\n",
1607 ast_log(
LOG_WARNING,
"Failed recreating '%s' subscription: The endpoint was not found\n",
1614 expires_header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES,
1615 rdata->msg_info.msg->hdr.next);
1616 if (!expires_header) {
1617 expires_header = pjsip_expires_hdr_create(rdata->tp_info.pool, 0);
1618 if (!expires_header) {
1619 ast_log(
LOG_WARNING,
"Failed recreating '%s' subscription: Could not update expires header.\n",
1625 pjsip_msg_add_hdr(rdata->msg_info.msg, (pjsip_hdr *) expires_header);
1631 ast_debug(3,
"Expired subscription retrived from persistent store '%s' %s\n",
1637 expires_header->ivalue = expires;
1639 memset(&tree, 0,
sizeof(tree));
1642 if (PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {
1643 pj_status_t dlg_status;
1646 &tree, &dlg_status, persistence);
1648 if (dlg_status != PJ_EEXISTS) {
1649 ast_log(
LOG_WARNING,
"Failed recreating '%s' subscription: Could not create subscription tree.\n",
1657 pjsip_evsub_terminate(sub_tree->
evsub, PJ_TRUE);
1662 ind->
expires = expires_header->ivalue;
1667 pjsip_evsub_terminate(sub_tree->
evsub, PJ_TRUE);
1687 pj_pool_t *
pool = arg;
1689 pjsip_rx_data rdata;
1694 ast_debug(3,
"Deleting subscription marked as 'prune' from persistent store '%s' %s\n",
1702 ast_debug(3,
"Expired subscription retrived from persistent store '%s' %s\n",
1708 memset(&rdata, 0,
sizeof(rdata));
1709 pj_pool_reset(pool);
1710 rdata.tp_info.pool =
pool;
1715 ast_log(
LOG_WARNING,
"Failed recreating '%s' subscription: The message could not be parsed\n",
1721 if (rdata.msg_info.msg->type != PJSIP_REQUEST_MSG) {
1722 ast_log(
LOG_NOTICE,
"Failed recreating '%s' subscription: Stored a SIP response instead of a request.\n",
1731 ast_log(
LOG_WARNING,
"Failed recreating '%s' subscription: Could not get distributor serializer.\n",
1740 ast_log(
LOG_WARNING,
"Failed recreating '%s' subscription: Could not continue under distributor serializer.\n",
1757 PJSIP_POOL_RDATA_INC);
1759 ast_log(
LOG_WARNING,
"Could not create a memory pool for recreating SIP subscriptions\n");
1767 ao2_ref(persisted_subscriptions, -1);
1787 if (strcmp(type,
"FullyBooted")) {
1805 if (!on_subscription) {
1811 if (on_subscription(i, arg)) {
1831 if (sub_tree->
dlg) {
1862 pj_cstr(&name, header);
1864 return pjsip_msg_find_hdr_by_name(msg, &name,
NULL);
1875 pjsip_tx_data *tdata;
1892 ast_log(
LOG_WARNING,
"No contacts configured for endpoint %s. Unable to create SIP subsription\n",
1908 pjsip_evsub_create_uac(dlg, &
pubsub_cb, &event, 0, &sub_tree->
evsub);
1911 evsub = sub_tree->
evsub;
1913 if (pjsip_evsub_initiate(evsub,
NULL, -1, &tdata) == PJ_SUCCESS) {
1914 pjsip_evsub_send_request(sub_tree->
evsub, tdata);
1920 pjsip_evsub_terminate(evsub, PJ_TRUE);
1973 for (buf_size = PJSIP_MAX_PKT_LEN; size == -1 && buf_size < (PJSIP_MAX_PKT_LEN * 2); buf_size *= 2) {
1974 buf = pj_pool_alloc(tdata->pool, buf_size);
1975 size = pjsip_msg_print(tdata->msg, buf, buf_size);
1982 tdata->buf.start =
buf;
1983 tdata->buf.cur = tdata->buf.start;
1984 tdata->buf.end = tdata->buf.start + buf_size;
1991 #ifdef TEST_FRAMEWORK 1993 pjsip_evsub *evsub = sub_tree->
evsub;
1999 pjsip_tx_data_dec_ref(tdata);
2003 res = pjsip_evsub_send_request(sub_tree->
evsub, tdata);
2010 pjsip_evsub_get_state_name(evsub),
2013 return (res == PJ_SUCCESS ? 0 : -1);
2030 const char *resource_name,
const pjsip_sip_uri *resource_uri, pjsip_evsub_state
state)
2032 static pj_str_t
cid_name = {
"cid", 3 };
2033 pj_xml_node *resource;
2035 pj_xml_node *instance;
2036 pj_xml_attr *cid_attr;
2038 char uri[PJSIP_MAX_URL_SIZE];
2041 const pj_str_t cid_stripped = {
2042 .ptr = cid->hvalue.ptr + 1,
2043 .slen = cid->hvalue.slen - 2,
2050 pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, resource_uri, uri,
sizeof(uri));
2053 pj_strdup2(pool, &name->content, resource_name);
2059 state == PJSIP_EVSUB_STATE_TERMINATED ?
"terminated" :
"active");
2065 cid_attr = pj_xml_attr_new(pool, &cid_name, &cid_stripped);
2066 pj_xml_add_attr(instance, cid_attr);
2082 pjsip_generic_string_hdr *
cid;
2110 static const pj_str_t
cid_name = {
"Content-ID", 10 };
2111 pjsip_generic_string_hdr *cid;
2117 alloc_size =
sizeof(
id) + pj_strlen(&sub->uri->host) + 3;
2118 cid_value.ptr = pj_pool_alloc(pool, alloc_size);
2119 cid_value.slen = sprintf(cid_value.ptr,
"<%s@%.*s>",
2121 (
int) pj_strlen(&sub->uri->host), pj_strbuf(&sub->uri->host));
2122 cid = pjsip_generic_string_hdr_create(pool, &cid_name, &cid_value);
2130 pj_xml_node *rlmi = msg_body->data;
2132 num_printed = pj_xml_print(rlmi, buf, size, PJ_TRUE);
2142 const pj_xml_node *rlmi = data;
2144 return pj_xml_clone(pool, rlmi);
2163 struct body_part_list *body_parts,
unsigned int full_state)
2167 pjsip_multipart_part *rlmi_part;
2168 char version_str[32];
2169 char uri[PJSIP_MAX_URL_SIZE];
2170 pjsip_generic_string_hdr *cid;
2179 snprintf(version_str,
sizeof(version_str),
"%u", sub->version++);
2192 rlmi_part = pjsip_multipart_create_part(pool);
2194 rlmi_part->body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body);
2195 pjsip_media_type_cp(pool, &rlmi_part->body->content_type, &
rlmi_media_type);
2197 rlmi_part->body->data = pj_xml_clone(pool, rlmi);
2202 pj_list_insert_before(&rlmi_part->hdr, cid);
2208 unsigned int force_full_state);
2244 bp->
state = sub->subscription_state;
2259 struct body_part_list *parts,
unsigned int use_full_state)
2262 pjsip_msg_body *body;
2276 bp->
part = pjsip_multipart_create_part(pool);
2277 bp->
part->body = body;
2278 pj_list_insert_before(&bp->
part->hdr, bp->
cid);
2294 pjsip_param *media_type_param;
2296 pj_str_t pj_boundary;
2298 pjsip_media_type_init2(&media_type,
"multipart",
"related");
2300 media_type_param = pj_pool_alloc(pool,
sizeof(*media_type_param));
2301 pj_list_init(media_type_param);
2303 pj_strdup2(pool, &media_type_param->name,
"type");
2304 pj_strdup2(pool, &media_type_param->value,
"\"application/rlmi+xml\"");
2306 pj_list_insert_before(&media_type.param, media_type_param);
2309 return pjsip_multipart_create(pool, &media_type, &pj_boundary);
2325 unsigned int force_full_state)
2328 pjsip_multipart_part *rlmi_part;
2329 pjsip_msg_body *multipart;
2330 struct body_part_list body_parts;
2331 unsigned int use_full_state = force_full_state ? 1 : sub->full_state;
2354 pjsip_multipart_add_part(pool, multipart, rlmi_part);
2357 pjsip_multipart_add_part(pool, multipart,
AST_VECTOR_GET(&body_parts, i)->part);
2372 unsigned int force_full_state)
2374 pjsip_msg_body *body;
2377 if (force_full_state || root->body_changed) {
2389 body = pjsip_msg_body_create(pool, &type, &subtype, &text);
2390 root->body_changed = 0;
2406 pjsip_require_hdr *require;
2408 require = pjsip_require_hdr_create(pool);
2409 pj_strdup2(pool, &require->values[0],
"eventlist");
2427 pjsip_evsub *evsub = sub_tree->
evsub;
2428 pjsip_tx_data *tdata;
2431 && sub_tree->
root->subscription_state == PJSIP_EVSUB_STATE_TERMINATED
2436 if (pjsip_evsub_notify(evsub, sub_tree->
root->subscription_state,
2437 NULL,
NULL, &tdata) != PJ_SUCCESS) {
2442 if (!tdata->msg->body) {
2443 pjsip_tx_data_dec_ref(tdata);
2449 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) require);
2465 pjsip_dialog *
dlg = sub_tree->
dlg;
2467 pjsip_dlg_inc_lock(dlg);
2478 pjsip_dlg_dec_lock(dlg);
2483 if (sub_tree->
root->subscription_state == PJSIP_EVSUB_STATE_TERMINATED) {
2491 ?
"SUBSCRIPTION_TERMINATED" :
"SUBSCRIPTION_STATE_CHANGED",
2492 "Resource: %s", sub_tree->
root->resource);
2495 pjsip_dlg_dec_lock(dlg);
2535 pjsip_dlg_inc_lock(dlg);
2538 pjsip_dlg_dec_lock(dlg);
2544 pjsip_dlg_dec_lock(dlg);
2548 sub->body_changed = 1;
2550 sub->subscription_state = PJSIP_EVSUB_STATE_TERMINATED;
2569 pjsip_dlg_dec_lock(dlg);
2580 pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, sub->uri, buf, size);
2589 uri = pjsip_uri_get_uri(dlg->remote.info->uri);
2591 if (pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, uri, buf, size) < 0) {
2598 return sub->resource;
2603 return sub->subscription_state == PJSIP_EVSUB_STATE_TERMINATED ? 1 : 0;
2615 pj_list_init(&res_hdr);
2621 return pjsip_evsub_accept(sub_tree->
evsub, rdata, response, &res_hdr) == PJ_SUCCESS ? 0 : -1;
2672 subscription->persistence_data = persistence_data;
2688 return subscription->persistence_data;
2721 ast_log(
LOG_ERROR,
"No event package specified for publish handler. Cannot register\n");
2728 ast_log(
LOG_ERROR,
"Could not allocate publications container for event '%s'\n",
2744 if (handler == iter) {
2785 ast_log(
LOG_ERROR,
"No event package specified for subscription handler. Cannot register\n");
2792 "Unable to register subscription handler for event %s. A handler is already registered\n",
2798 pj_cstr(&accept[i], handler->
accept[i]);
2816 if (handler == iter) {
2830 if (!strcmp(gen->
type, type)
2831 && !strcmp(gen->
subtype, subtype)) {
2863 size_t num_accept,
const char *
body_type)
2868 for (i = 0; i < num_accept; ++i) {
2871 ast_debug(3,
"Body generator %p found for accept type %s\n", generator, accept[i]);
2872 if (strcmp(generator->
body_type, body_type)) {
2873 ast_log(
LOG_WARNING,
"Body generator '%s/%s'(%p) does not accept the type of data this event generates\n",
2880 ast_debug(3,
"No body generator found for accept type %s\n", accept[i]);
2953 ast_debug(3,
"Scheduling timer: %s\n", name);
2958 ast_log(
LOG_ERROR,
"Unable to create expiration timer of %d seconds for %s\n",
2971 pjsip_expires_hdr *expires_header;
2977 pjsip_uri *request_uri;
2978 pjsip_sip_uri *request_uri_sip;
2979 size_t resource_size;
2982 pj_status_t dlg_status;
2987 if (!endpoint->subscription.allow) {
2993 request_uri = rdata->msg_info.msg->line.req.uri;
2995 if (!PJSIP_URI_SCHEME_IS_SIP(request_uri) && !PJSIP_URI_SCHEME_IS_SIPS(request_uri)) {
2996 char uri_str[PJSIP_MAX_URL_SIZE];
2998 pjsip_uri_print(PJSIP_URI_IN_REQ_URI, request_uri, uri_str,
sizeof(uri_str));
3004 request_uri_sip = pjsip_uri_get_uri(request_uri);
3005 resource_size = pj_strlen(&request_uri_sip->user) + 1;
3015 expires_header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, rdata->msg_info.msg->hdr.next);
3016 if (expires_header) {
3017 if (expires_header->ivalue == 0) {
3018 ast_debug(1,
"Subscription request from endpoint %s rejected. Expiration of 0 is invalid\n",
3023 if (expires_header->ivalue < endpoint->subscription.minexpiry) {
3024 ast_log(
LOG_WARNING,
"Subscription expiration %d is too brief for endpoint %s. Minimum is %u\n",
3043 memset(&tree, 0,
sizeof(tree));
3046 if (!PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {
3054 if (dlg_status != PJ_EEXISTS) {
3061 pjsip_evsub_terminate(sub_tree->
evsub, PJ_TRUE);
3074 pjsip_evsub_terminate(sub_tree->
evsub, PJ_TRUE);
3103 pjsip_generic_string_hdr *etag_hdr,
unsigned int *expires,
int *entity_id)
3105 pjsip_expires_hdr *expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES,
NULL);
3108 char etag[pj_strlen(&etag_hdr->hvalue) + 1];
3112 if (sscanf(etag,
"%30d", entity_id) != 1) {
3121 }
else if (!etag_hdr && rdata->msg_info.msg->body) {
3123 }
else if (etag_hdr && !rdata->msg_info.msg->body) {
3125 }
else if (etag_hdr && rdata->msg_info.msg->body) {
3137 ast_debug(3,
"Destroying SIP publication\n");
3149 pjsip_expires_hdr *expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES,
NULL);
3150 size_t resource_len = strlen(resource) + 1, event_configuration_name_len = strlen(event_configuration_name) + 1;
3171 dst = publication->
data;
3172 publication->
resource = strcpy(dst, resource);
3173 dst += resource_len;
3180 pjsip_rx_data *rdata)
3182 pjsip_tx_data *tdata;
3183 pjsip_transaction *tsx;
3189 if (PJSIP_IS_STATUS_IN_CLASS(status_code, 200)) {
3192 snprintf(buf,
sizeof(buf),
"%d", pub->
entity_tag);
3195 snprintf(buf,
sizeof(buf),
"%d", pub->
expires);
3199 if (pjsip_tsx_create_uas(&
pubsub_module, rdata, &tsx) != PJ_SUCCESS) {
3200 pjsip_tx_data_dec_ref(tdata);
3204 pjsip_tsx_recv_msg(tsx, rdata);
3206 if (pjsip_tsx_send_msg(tsx, tdata) != PJ_SUCCESS) {
3207 pjsip_tx_data_dec_ref(tdata);
3218 char *resource_name;
3219 size_t resource_size;
3222 pjsip_uri *request_uri;
3223 pjsip_sip_uri *request_uri_sip;
3226 request_uri = rdata->msg_info.msg->line.req.uri;
3228 if (!PJSIP_URI_SCHEME_IS_SIP(request_uri) && !PJSIP_URI_SCHEME_IS_SIPS(request_uri)) {
3229 char uri_str[PJSIP_MAX_URL_SIZE];
3231 pjsip_uri_print(PJSIP_URI_IN_REQ_URI, request_uri, uri_str,
sizeof(uri_str));
3237 request_uri_sip = pjsip_uri_get_uri(request_uri);
3238 resource_size = pj_strlen(&request_uri_sip->user) + 1;
3240 ast_copy_pj_str(resource_name, &request_uri_sip->user, resource_size);
3250 ast_debug(1,
"No 'inbound-publication' defined for resource '%s'\n", resource_name);
3256 ast_debug(1,
"Resource %s has a defined endpoint '%s', but does not match endpoint '%s' that received the request\n",
3262 for (event_configuration_name = resource->events; event_configuration_name; event_configuration_name = event_configuration_name->
next) {
3263 if (!strcmp(event_configuration_name->
name, handler->
event_name)) {
3268 if (!event_configuration_name) {
3269 ast_debug(1,
"Event '%s' is not configured for '%s'\n", handler->
event_name, resource_name);
3276 if (!PJSIP_IS_STATUS_IN_CLASS(resp, 200)) {
3305 if (publication->handler->publish_expire) {
3306 publication->handler->publish_expire(publication);
3328 pjsip_event_hdr *event_header;
3332 static const pj_str_t str_sip_if_match = {
"SIP-If-Match", 12 };
3333 pjsip_generic_string_hdr *etag_hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_sip_if_match,
NULL);
3336 unsigned int expires = 0;
3337 int entity_id, response = 0;
3342 event_header = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &
str_event_name, rdata->msg_info.msg->hdr.next);
3343 if (!event_header) {
3364 static const pj_str_t str_conditional_request_failed = {
"Conditional Request Failed", 26 };
3375 publication->expires = expires;
3378 switch (publish_type) {
3444 pj_size_t accept_len;
3458 accept_len = strlen(generator->
type) + strlen(generator->
subtype) + 1;
3461 pj_strset(&accept,
ast_alloca(accept_len + 1), accept_len);
3462 sprintf((
char *) pj_strbuf(&accept),
"%s/%s", generator->
type, generator->
subtype);
3465 PJSIP_H_ACCEPT,
NULL, 1, &accept);
3476 if (iter == generator) {
3500 if (iter == supplement) {
3535 ast_log(
LOG_WARNING,
"%s/%s body generator does not accept the type of data provided\n",
3554 if (!strcmp(generator->
type, supplement->
type) &&
3582 char message_account[PJSIP_MAX_URL_SIZE];
3590 int found_counts = 0;
3597 memset(summary, 0,
sizeof(*summary));
3602 if (sscanf(line,
"voice-message: %d/%d (%d/%d)",
3611 return !found_counts;
3618 const char *endpoint_name;
3627 ast_debug(1,
"Incoming MWI: Endpoint not found in rdata (%p)\n", rdata);
3633 ast_debug(1,
"Incoming MWI: Found endpoint: %s\n", endpoint_name);
3635 ast_debug(1,
"Incoming MWI: No incoming mailbox specified for endpoint '%s'\n", endpoint_name);
3637 "Endpoint: %s", endpoint_name);
3642 mailbox =
ast_strdupa(endpoint->incoming_mwi_mailbox);
3643 atsign = strchr(mailbox,
'@');
3645 ast_debug(1,
"Incoming MWI: No '@' found in endpoint %s's incoming mailbox '%s'. Can't parse context\n",
3646 endpoint_name, endpoint->incoming_mwi_mailbox);
3652 context = atsign + 1;
3654 body =
ast_alloca(rdata->msg_info.msg->body->len + 1);
3655 rdata->msg_info.msg->body->print_body(rdata->msg_info.msg->body, body,
3656 rdata->msg_info.msg->body->len + 1);
3659 ast_debug(1,
"Incoming MWI: Endpoint: '%s' There was an issue getting message info from body '%s'\n",
3667 ast_log(
LOG_ERROR,
"Incoming MWI: Endpoint: '%s' Could not publish MWI to stasis. " 3668 "Mailbox: %s Message-Account: %s Voice-Messages: %d/%d (%d/%d)\n",
3669 endpoint_name, endpoint->incoming_mwi_mailbox, summary.
message_account,
3674 ast_debug(1,
"Incoming MWI: Endpoint: '%s' Mailbox: %s Message-Account: %s Voice-Messages: %d/%d (%d/%d)\n",
3675 endpoint_name, endpoint->incoming_mwi_mailbox, summary.
message_account,
3681 "MessageAccount: %s\r\n" 3682 "VoiceMessagesNew: %d\r\n" 3683 "VoiceMessagesOld: %d\r\n" 3684 "VoiceMessagesUrgentNew: %d\r\n" 3685 "VoiceMessagesUrgentOld: %d",
3686 endpoint_name, endpoint->incoming_mwi_mailbox, summary.
message_account,
3699 if (rdata->msg_info.msg->body &&
3701 "application",
"simple-message-summary")) {
3709 if (!pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, pjsip_get_subscribe_method())) {
3713 }
else if (!pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_notify_method)) {
3724 sub->subscription_state = PJSIP_EVSUB_STATE_TERMINATED;
3812 ast_debug(3,
"evsub %p state %s event %s sub_tree %p sub_tree state %s\n", evsub,
3813 pjsip_evsub_get_state_name(evsub), pjsip_event_str(event->type), sub_tree,
3816 if (!sub_tree || pjsip_evsub_get_state(evsub) != PJSIP_EVSUB_STATE_TERMINATED) {
3829 char task_name[256];
3832 ast_debug(3,
"Cancelling timer: %s\n", task_name);
3842 #ifdef HAVE_PJSIP_EVSUB_GRP_LOCK 3843 pjsip_evsub_dec_ref(sub_tree->
evsub);
3862 pjsip_dialog *
dlg = sub_tree->
dlg;
3864 ast_debug(3,
"sub_tree %p sub_tree state %s\n", sub_tree,
3867 pjsip_dlg_inc_lock(dlg);
3869 pjsip_dlg_dec_lock(dlg);
3881 "SUBSCRIPTION_TERMINATED" :
"SUBSCRIPTION_REFRESHED",
3882 "Resource: %s", sub_tree->
root->resource);
3884 pjsip_dlg_dec_lock(dlg);
3893 ast_debug(3,
"sub_tree %p sub_tree state %s\n", sub_tree,
3912 int *p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body)
3916 sub_tree = pjsip_evsub_get_mod_data(evsub,
pubsub_module.id);
3917 ast_debug(3,
"evsub %p sub_tree %p sub_tree state %s\n", evsub, sub_tree,
3925 char task_name[256];
3928 ast_debug(3,
"Cancelling timer: %s\n", task_name);
3938 if (pjsip_evsub_get_state(sub_tree->
evsub) == PJSIP_EVSUB_STATE_TERMINATED) {
3957 pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body)
3961 if (!(sub = pjsip_evsub_get_mod_data(evsub,
pubsub_module.id))) {
3966 pjsip_evsub_get_state(evsub));
3972 pjsip_tx_data *tdata;
3974 if (!sub_tree->
evsub) {
3979 if (pjsip_evsub_initiate(sub_tree->
evsub,
NULL, -1, &tdata) == PJ_SUCCESS) {
3980 pjsip_evsub_send_request(sub_tree->
evsub, tdata);
3982 pjsip_evsub_terminate(sub_tree->
evsub, PJ_TRUE);
3993 if (!(sub_tree = pjsip_evsub_get_mod_data(evsub,
pubsub_module.id))) {
4019 sub_tree = pjsip_evsub_get_mod_data(evsub,
pubsub_module.id);
4053 sub_tree, arg,
"InboundSubscriptionDetail") : 0;
4059 sub_tree, arg,
"OutboundSubscriptionDetail") : 0;
4125 astman_send_listack(s, m,
"A listing of resource lists follows, presented as ResourceListDetail events",
4135 #define AMI_SHOW_SUBSCRIPTIONS_INBOUND "PJSIPShowSubscriptionsInbound" 4136 #define AMI_SHOW_SUBSCRIPTIONS_OUTBOUND "PJSIPShowSubscriptionsOutbound" 4138 #define MAX_REGEX_ERROR_LEN 128 4164 if (!sub_tree->
dlg) {
4168 callid = &sub_tree->
dlg->call_id->id;
4169 if (cli->
wordlen <= pj_strlen(callid)
4170 && !strncasecmp(cli->
a->
word, pj_strbuf(callid), cli->
wordlen)
4171 && (++cli->
which > cli->
a->
n)) {
4202 if (!strcasecmp(a->
argv[3],
"inbound")) {
4204 }
else if (!strcasecmp(a->
argv[3],
"outbound")) {
4237 const char *
callid = (
const char *) cli->
buf;
4238 pj_str_t *sub_callid;
4246 int key_filler_width;
4249 if (!sub_tree->
dlg) {
4252 sub_callid = &sub_tree->
dlg->call_id->id;
4253 if (pj_strcmp2(sub_callid, callid)) {
4264 "===========================================================================\n",
4265 "ParameterName",
"ParameterValue");
4292 value = strchr(key,
':');
4296 value_end = strchr(
value,
'\n');
4302 key_len =
value - key;
4303 key_filler_width = 20 - key_len;
4304 if (key_filler_width < 0) {
4305 key_filler_width = 0;
4307 value_len = value_end -
value;
4310 key_len, key, key_filler_width,
"",
4313 key = value_end + 1;
4341 e->
command =
"pjsip show subscription {inbound|outbound}";
4342 e->
usage =
"Usage:\n" 4343 " pjsip show subscription inbound <call-id>\n" 4344 " pjsip show subscription outbound <call-id>\n" 4345 " Show active subscription with the dialog call-id\n";
4355 if (!strcasecmp(a->
argv[3],
"inbound")) {
4357 }
else if (!strcasecmp(a->
argv[3],
"outbound")) {
4368 cli.
buf = (
void *) a->
argv[4];
4374 #define CLI_SHOW_SUB_FORMAT_HEADER \ 4375 "Endpoint: <Endpoint/Caller-ID.............................................>\n" \ 4376 "Resource: <Resource/Event.................................................>\n" \ 4377 " Expiry: <Expiry> <Call-id..............................................>\n" \ 4378 "===========================================================================\n\n" 4379 #define CLI_SHOW_SUB_FORMAT_ENTRY \ 4380 "Endpoint: %s/%s\n" \ 4381 "Resource: %s/%s\n" \ 4382 " Expiry: %8d %s\n\n" 4386 char caller_id[256];
4397 if (sub_tree->
dlg) {
4442 e->
command =
"pjsip show subscriptions {inbound|outbound} [like]";
4443 e->
usage =
"Usage:\n" 4444 " pjsip show subscriptions inbound [like <regex>]\n" 4445 " Show active inbound subscriptions\n" 4446 " pjsip show subscriptions outbound [like <regex>]\n" 4447 " Show active outbound subscriptions\n" 4449 " The regex selects a subscriptions output that matches.\n" 4450 " i.e., All output lines for a subscription are checked\n" 4451 " as a block by the regex.\n";
4457 if (a->
argc != 4 && a->
argc != 6) {
4460 if (!strcasecmp(a->
argv[3],
"inbound")) {
4462 }
else if (!strcasecmp(a->
argv[3],
"outbound")) {
4472 if (strcasecmp(a->
argv[4],
"like")) {
4477 memset(&like, 0,
sizeof(like));
4480 rc = regcomp(cli.
like, regex, REG_EXTENDED | REG_NOSUB);
4485 ast_cli(a->
fd,
"Regular expression '%s' failed to compile: %s\n",
4507 ast_cli(a->
fd,
"%d active subscriptions%s%s%s\n",
4509 regex ?
" matched \"" :
"",
4521 #define CLI_LIST_SUB_FORMAT_HEADER "%-30.30s %-30.30s %6.6s %s\n" 4522 #define CLI_LIST_SUB_FORMAT_ENTRY "%-30.30s %-30.30s %6d %s\n" 4526 char ep_cid_buf[50];
4527 char res_evt_buf[50];
4531 snprintf(ep_cid_buf,
sizeof(ep_cid_buf),
"%s/%s",
4538 snprintf(res_evt_buf,
sizeof(res_evt_buf),
"%s/%s",
4539 sub_tree->
root->resource,
4543 if (sub_tree->
dlg) {
4589 e->
command =
"pjsip list subscriptions {inbound|outbound} [like]";
4590 e->
usage =
"Usage:\n" 4591 " pjsip list subscriptions inbound [like <regex>]\n" 4592 " List active inbound subscriptions\n" 4593 " pjsip list subscriptions outbound [like <regex>]\n" 4594 " List active outbound subscriptions\n" 4596 " The regex selects output lines that match.\n";
4602 if (a->
argc != 4 && a->
argc != 6) {
4605 if (!strcasecmp(a->
argv[3],
"inbound")) {
4607 }
else if (!strcasecmp(a->
argv[3],
"outbound")) {
4617 if (strcasecmp(a->
argv[4],
"like")) {
4622 memset(&like, 0,
sizeof(like));
4625 rc = regcomp(cli.
like, regex, REG_EXTENDED | REG_NOSUB);
4630 ast_cli(a->
fd,
"Regular expression '%s' failed to compile: %s\n",
4651 "Endpoint/CLI",
"Resource/Event",
"Expiry",
"Call-id");
4653 ast_cli(a->
fd,
"\n%d active subscriptions%s%s%s\n",
4655 regex ?
" matched \"" :
"",
4750 #define RESOURCE_LIST_INIT_SIZE 4 4860 "pjsip.conf,criteria=type=resource_list");
4882 #ifdef TEST_FRAMEWORK 4948 for (i = 0; i < num_resources; ++i) {
4984 const char *list_name,
const char *
event,
const char **resources,
size_t num_resources)
5023 const char **resources,
size_t num_resources)
5033 for (i = 0; i < num_resources; ++i) {
5034 if (strcmp(resources[i],
AST_VECTOR_GET(&node->children, i)->resource)) {
5070 if (strcasecmp(value,
"memory") && strcasecmp(value,
"astdb")) {
5082 const char *resources[] = {
5091 info->name =
"resource_tree";
5092 info->category =
"/res/res_pjsip_pubsub/";
5093 info->summary =
"Basic resource tree integrity check";
5095 "Create a resource list and ensure that our attempt to build a tree works as expected.";
5103 "'res_pjsip_pubsub' section to sorcery.conf, and set 'resource_list=memory'\n");
5136 const char *resources_1[] = {
5142 const char *resources_2[] = {
5156 info->name =
"complex_resource_tree";
5157 info->category =
"/res/res_pjsip_pubsub/";
5158 info->summary =
"Complex resource tree integrity check";
5160 "Create a complex resource list and ensure that our attempt to build a tree works as expected.";
5168 "'res_pjsip_pubsub' section to sorcery.conf, and set 'resource_list=memory'\n");
5212 const char *resources[] = {
5222 info->name =
"bad_resource";
5223 info->category =
"/res/res_pjsip_pubsub/";
5224 info->summary =
"Ensure bad resources do not end up in the tree";
5226 "Create a resource list with a single bad resource. Ensure the bad resource does not end up in the tree.";
5234 "'res_pjsip_pubsub' section to sorcery.conf, and set 'resource_list=memory'\n");
5269 const char *resources_1[] = {
5276 const char *resources_2[] = {
5286 info->name =
"bad_branch";
5287 info->category =
"/res/res_pjsip_pubsub/";
5288 info->summary =
"Ensure bad branches are pruned from the tree";
5290 "Create a resource list that makes a tree with an entire branch of bad resources.\n" 5291 "Ensure the bad branch is pruned from the tree.";
5299 "'res_pjsip_pubsub' section to sorcery.conf, and set 'resource_list=memory'\n");
5340 const char *resources_1[] = {
5346 const char *resources_2[] = {
5359 info->name =
"duplicate_resource";
5360 info->category =
"/res/res_pjsip_pubsub/";
5361 info->summary =
"Ensure duplicated resources do not end up in the tree";
5363 "Create a resource list with a single duplicated resource. Ensure the duplicated resource does not end up in the tree.";
5371 "'res_pjsip_pubsub' section to sorcery.conf, and set 'resource_list=memory'\n");
5421 const char *resources_1[] = {
5424 const char *resources_2[] = {
5431 info->name =
"loop";
5432 info->category =
"/res/res_pjsip_pubsub/";
5433 info->summary =
"Test that loops are properly detected.";
5435 "Create two resource lists that refer to each other. Ensure that attempting to build a tree\n" 5436 "results in an empty tree.";
5444 "'res_pjsip_pubsub' section to sorcery.conf, and set 'resource_list=memory'\n");
5471 const char *resources[] = {
5480 info->name =
"bad_event";
5481 info->category =
"/res/res_pjsip_pubsub/";
5482 info->summary =
"Ensure that list with wrong event specified is not retrieved";
5484 "Create a simple resource list for event 'tsetse'. Ensure that trying to retrieve the list for event 'test' fails.";
5492 "'res_pjsip_pubsub' section to sorcery.conf, and set 'resource_list=memory'\n");
5516 if (strcmp(tree->root->resource,
"foo")) {
5540 const char *
event = var->
name + 6;
5562 static const pj_str_t str_PUBLISH = {
"PUBLISH", 7 };
5568 ast_log(
LOG_ERROR,
"Could not create scheduler for publication expiration\n");
5573 ast_log(
LOG_ERROR,
"Could not start scheduler thread for publication expiration\n");
5582 ast_log(
LOG_ERROR,
"Could not register subscription persistence object support\n");
5621 ast_log(
LOG_ERROR,
"Could not register subscription persistence object support\n");
5713 .requires =
"res_pjsip",
void(* to_string)(void *body, struct ast_str **str)
Convert the body to a string.
int ast_sched_start_thread(struct ast_sched_context *con)
Start a thread for processing scheduler entries.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
struct ast_variable * next
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.
const char * event_name
The name of the event this handler deals with.
enum sip_cc_notify_state state
static struct ast_sip_publish_handler * find_pub_handler(const char *event)
void *(* get_notify_data)(struct ast_sip_subscription *sub)
Supply data needed to create a NOTIFY body.
static struct tree_node * tree_node_alloc(const char *resource, struct resources *visited, unsigned int full_state)
Allocate a tree node.
static void subscription_tree_destructor(void *obj)
static int generate_initial_notify(struct ast_sip_subscription *sub)
#define AST_SIP_USER_OPTIONS_TRUNCATE_CHECK(str)
Truncate the URI user field options string if enabled.
#define AST_CLI_DEFINE(fn, txt,...)
char data[0]
Data containing the above.
char * str
Subscriber phone number (Malloced)
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
struct ast_sip_subscription * root
void ast_taskprocessor_build_name(char *buf, unsigned int size, const char *format,...)
Build a taskprocessor name with a sequence number on the end.
static void pubsub_on_rx_refresh(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)
Called whenever an in-dialog SUBSCRIBE is received.
static struct resource_list * create_resource_list(struct ast_test *test, const char *list_name, const char *event, const char **resources, size_t num_resources)
allocate a resource list, store it in sorcery, and set its details
void astman_append(struct mansession *s, const char *fmt,...)
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
static pj_bool_t pubsub_on_rx_publish_request(pjsip_rx_data *rdata)
sip_subscription_tree_state
The state of the subscription tree.
static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype_nolock(const char *type, const char *subtype)
static int ami_subscription_detail_inbound(struct sip_subscription_tree *sub_tree, void *arg)
int ast_sip_publication_add_datastore(struct ast_sip_publication *publication, struct ast_datastore *datastore)
Add a datastore to a SIP publication.
static int serialized_send_notify(void *userdata)
#define CLI_SHOW_SUB_FORMAT_ENTRY
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
static int sched_cb(const void *data)
#define AMI_SHOW_SUBSCRIPTIONS_OUTBOUND
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
static pjsip_media_type rlmi_media_type
static void remove_subscription(struct sip_subscription_tree *obj)
static pj_bool_t pubsub_on_rx_request(pjsip_rx_data *rdata)
Opaque structure representing an RFC 3265 SIP subscription.
struct ast_sip_subscriber * subscriber
static void publication_destroy_fn(void *obj)
Internal destructor for publications.
media_type
Media types generate different "dummy answers" for not accepting the offer of a media stream...
static int rlmi_print_body(struct pjsip_msg_body *msg_body, char *buf, pj_size_t size)
void ast_sip_unregister_subscription_handler(struct ast_sip_subscription_handler *handler)
Unregister a subscription handler.
struct sip_subscription_tree * tree
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
static struct pjsip_module pubsub_module
struct ast_taskprocessor * ast_sip_subscription_get_serializer(struct ast_sip_subscription *sub)
Get the serializer for the subscription.
A multipart body part and meta-information.
#define ast_test_flag(p, flag)
static void subscription_persistence_destroy(void *obj)
Destructor for subscription persistence.
const char * type
Content type In "plain/text", "plain" is the type.
struct ast_sip_endpoint * endpoint
struct ao2_container * ast_sip_publication_get_datastores(const struct ast_sip_publication *publication)
Get the datastores container for a publication.
static struct subscription_persistence * subscription_persistence_create(struct sip_subscription_tree *sub_tree)
Function which creates initial persistence information of a subscription in sorcery.
const char * accept_exceptions[]
Accept headers that are exceptions to the rule.
static int cli_show_subscriptions_outbound(struct sip_subscription_tree *sub_tree, void *arg)
Data used to create bodies for NOTIFY/PUBLISH requests.
const pjsip_method pjsip_publish_method
Defined method for PUBLISH.
static void add_subscription(struct sip_subscription_tree *obj)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_party_name name
Subscriber name.
static pj_bool_t pubsub_on_rx_subscribe_request(pjsip_rx_data *rdata)
int ast_sip_sched_task_cancel(struct ast_sip_sched_task *schtd)
Cancels the next invocation of a task.
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.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
static int persistence_generator_data_str2struct(const struct aco_option *opt, struct ast_variable *var, void *obj)
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
static int parse_simple_message_summary(char *body, struct simple_message_summary *summary)
descriptor for a cli entry.
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)
Build child nodes for a given parent.
enum ast_transport_monitor_reg ast_sip_transport_monitor_register(pjsip_transport *transport, ast_transport_monitor_shutdown_cb cb, void *ao2_data)
Register a reliable transport shutdown monitor callback.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static int initial_notify_task(void *obj)
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.
#define ao2_callback(c, flags, cb_fn, arg)
struct ast_sip_notifier * notifier
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
char local_name[PJ_INET6_ADDRSTRLEN]
const char * accept[AST_SIP_MAX_ACCEPT]
#define DEFAULT_EXPIRES
Default expiration for subscriptions.
static int publish_expire(const void *data)
Party identification options for endpoints.
Structure for variables, used for configurations and for channel variables.
static pj_pool_t * pool
Global memory pool for configuration and timers.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
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.
static int sub_tree_subscription_terminate_cb(void *data)
static int ami_show_resource_lists(struct mansession *s, const struct message *m)
#define RESOURCE_LIST_INIT_SIZE
static int persistence_endpoint_struct2str(const void *obj, const intptr_t *args, char **buf)
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.
static const char * sip_subscription_roles_map[]
static int format_ami_resource_lists(void *obj, void *arg, int flags)
static struct ast_sip_pubsub_body_generator * find_body_generator_accept(const char *accept)
void ast_sip_pubsub_unregister_body_generator(struct ast_sip_pubsub_body_generator *generator)
Unregister a body generator with the pubsub core.
Universally unique identifier support.
int ast_sip_register_publish_handler(struct ast_sip_publish_handler *handler)
Register a publish handler.
#define ast_json_dump_string(root)
Encode a JSON value to a compact string.
static void * publication_resource_alloc(const char *name)
Allocator for publication resource.
Perform no matching, return all objects.
int ast_datastores_add(struct ao2_container *datastores, struct ast_datastore *datastore)
Add a data store to a container.
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...
int(* new_publication)(struct ast_sip_endpoint *endpoint, const char *resource, const char *event_configuration)
Called when a PUBLISH to establish a new publication arrives.
static int publish_expire_callback(void *data)
#define CLI_LIST_SUB_FORMAT_ENTRY
#define AST_TEST_REGISTER(cb)
int ast_sorcery_object_fields_register(struct ast_sorcery *sorcery, const char *type, const char *regex, aco_option_handler config_handler, sorcery_fields_handler sorcery_handler)
Register a regex for multiple fields within an object.
#define CHARFLDSET(type, field)
A helper macro to pass the appropriate arguments to aco_option_register for OPT_CHAR_ARRAY_T.
Full structure for sorcery.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
Type for a default handler that should do nothing.
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
static void * subscription_persistence_alloc(const char *name)
Allocator for subscription persistence.
Structure for a data store type.
char * str
Subscriber name (Malloced)
int ast_sip_pubsub_register_body_generator(struct ast_sip_pubsub_body_generator *generator)
Register a body generator with the pubsub core.
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
Structure used for persisting an inbound subscription.
#define CLI_LIST_SUB_FORMAT_HEADER
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
const char * ast_sip_publication_get_event_configuration(const struct ast_sip_publication *pub)
Given a publication, get the configuration name for the event type in use.
static struct resource_list * retrieve_resource_list(const char *resource, const char *event)
Helper function for retrieving a resource list for a given event.
pjsip_transport * transport
#define ast_cli_register_multiple(e, len)
Register multiple commands.
static pjsip_evsub_user pubsub_cb
static struct aco_type item
const char * type
Content type In "plain/text", "plain" is the type.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
static int persistence_tag_struct2str(const void *obj, const intptr_t *args, char **buf)
#define ast_sorcery_apply_config(sorcery, name)
Return all matching objects.
static int persistence_endpoint_str2struct(const struct aco_option *opt, struct ast_variable *var, void *obj)
struct ast_json * ast_json_load_string(const char *input, struct ast_json_error *error)
Parse null terminated string into a JSON object or array.
#define DEFAULT_PUBLISH_EXPIRES
Default expiration time for PUBLISH if one is not specified.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
#define ast_strdup(str)
A wrapper for strdup()
Structure for a data store object.
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.
static int cli_list_subscriptions_outbound(struct sip_subscription_tree *sub_tree, void *arg)
void(* to_ami)(struct ast_sip_subscription *sub, struct ast_str **buf)
Converts the subscriber to AMI.
static int apply_list_configuration(struct ast_sorcery *sorcery)
AST_VECTOR(resources, const char *)
A vector of strings commonly used throughout this module.
char packet[PJSIP_MAX_PKT_LEN]
static void sub_add_handler(struct ast_sip_subscription_handler *handler)
void ast_cli(int fd, const char *fmt,...)
struct subscription_persistence * persistence
int ast_sip_subscription_is_terminated(const struct ast_sip_subscription *sub)
Get whether the subscription has been terminated or not.
#define AST_TASKPROCESSOR_MAX_NAME
Suggested maximum taskprocessor name length (less null terminator).
int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to SIP servants and wait for it to complete.
int ast_get_timeval(const char *src, struct timeval *tv, struct timeval _default, int *consumed)
get values from config variables.
A node for a resource tree.
static int persistence_expires_struct2str(const void *obj, const intptr_t *args, char **buf)
JSON parsing error information.
static pjsip_require_hdr * create_require_eventlist(pj_pool_t *pool)
Shortcut method to create a Require: eventlist header.
static int ami_show_subscriptions_inbound(struct mansession *s, const struct message *m)
#define MAX_REGEX_ERROR_LEN
static struct ast_cli_entry cli_commands[]
struct ast_sip_subscription_handler test_handler
Subscription handler for unit tests.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
enum ast_sip_subscription_role role
char message_account[PJSIP_MAX_URL_SIZE]
#define ast_publish_mwi_state(mailbox, context, new_msgs, old_msgs)
Publish a MWI state update via stasis.
int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
Add a header to an outbound SIP message.
Resource list configuration item.
struct ast_datastore * ast_sip_publication_get_datastore(struct ast_sip_publication *publication, const char *name)
Retrieve a publication datastore.
static int subscription_persistence_recreate(void *obj, void *arg, int flags)
Callback function to perform the actual recreation of a subscription.
pjsip_dialog * ast_sip_subscription_get_dialog(struct ast_sip_subscription *sub)
Get the pjsip dialog that is associated with this subscription.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
struct ast_sip_pubsub_body_generator * body_generator
#define ast_module_unref(mod)
Release a reference to the module.
struct ast_datastore * ast_datastores_find(struct ao2_container *datastores, const char *name)
Find a data store in a container.
#define ast_strlen_zero(foo)
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
static char * sub_tree_state_description[]
static void * resource_list_alloc(const char *name)
static int ami_subscription_detail_outbound(struct sip_subscription_tree *sub_tree, void *arg)
struct ast_sip_endpoint * ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata)
Get the looked-up endpoint on an out-of dialog request or response.
struct ao2_container * ast_datastores_alloc(void)
Allocate a specialized data stores container.
int ast_sip_subscription_add_datastore(struct ast_sip_subscription *subscription, struct ast_datastore *datastore)
Add a datastore to a SIP subscription.
struct ao2_container * datastores
unsigned int notification_batch_interval
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 int sip_subscription_accept(struct sip_subscription_tree *sub_tree, pjsip_rx_data *rdata, int response)
Asterisk datastore objects.
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.
static int serialized_pubsub_on_refresh_timeout(void *userdata)
Type for default option handler for character array strings.
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.
static void sip_subscription_to_ami(struct sip_subscription_tree *sub_tree, struct ast_str **buf)
static void resource_list_destructor(void *obj)
static struct body_part * allocate_body_part(pj_pool_t *pool, const struct ast_sip_subscription *sub)
Allocate and initialize a body part structure.
int voice_messages_urgent_new
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
void ast_sip_subscription_get_remote_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
Retrive the remote URI for this subscription.
Type for default option handler for bools (ast_true/ast_false)
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
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.
const char * subtype
Content subtype In "plain/text", "text" is the subtype.
static void pubsub_on_server_timeout(pjsip_evsub *sub)
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
#define EVENT_FLAG_SYSTEM
#define ast_debug(level,...)
Log a DEBUG message.
struct stasis_message_type * ast_manager_get_generic_type(void)
Get the stasis_message_type for generic messages.
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
void ast_sip_pubsub_unregister_body_supplement(struct ast_sip_pubsub_body_supplement *supplement)
Unregister a body generator with the pubsub core.
#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.
static int exceptional_accept(const pj_str_t *accept)
Is the Accept header from the SUBSCRIBE in the list of exceptions?
#define ast_config_load(filename, flags)
Load a config file.
static int for_each_subscription(on_subscription_t on_subscription, void *arg)
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
static pjsip_msg_body * create_multipart_body(pj_pool_t *pool)
Create and initialize the PJSIP multipart body structure for a resource list subscription.
#define CLI_SHOW_SUB_FORMAT_HEADER
static int pubsub_on_refresh_timeout(void *userdata)
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
char * ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown)
struct ao2_container * datastores
#define PUBLICATIONS_BUCKETS
Number of buckets for publications (on a per handler)
#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...
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
pjsip_sip_uri * ast_sip_subscription_get_sip_uri(struct ast_sip_subscription *sub)
Retrieve the local sip uri for this subscription.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Type for default option handler for unsigned integers.
#define ast_test_status_update(a, b, c...)
static void cleanup_resource_list(struct resource_list *list)
RAII callback to destroy a resource list.
int(* on_subscription_t)(struct sip_subscription_tree *sub, void *arg)
static void publication_resource_destroy(void *obj)
Destructor for publication resource.
void *(* allocate_body)(void *data)
allocate body structure.
static struct ast_generator gen
void ast_sip_subscription_get_local_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
Retrieve the local URI for this subscription.
static int list_item_to_str(const void *obj, const intptr_t *args, char **buf)
static int schedule_notification(struct sip_subscription_tree *sub_tree)
static void sub_tree_transport_cb(void *data)
static int cli_list_subscriptions_detail(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)
const char * ast_sip_subscription_get_body_subtype(struct ast_sip_subscription *sub)
Get the body subtype used for this subscription.
void ast_sip_publication_remove_datastore(struct ast_sip_publication *publication, const char *name)
Remove a publication datastore from the publication.
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
const struct ast_sip_subscription_handler * handler
static int subscription_unreference_dialog(void *obj)
static struct ast_sip_pubsub_body_generator * subscription_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.
#define AST_RWLIST_TRAVERSE
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Scheduler Routines (derived from cheops)
#define AST_SIP_MAX_ACCEPT
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define ao2_ref(o, delta)
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
struct ast_sip_publish_handler * next
void ast_config_destroy(struct ast_config *config)
Destroys a config.
In case you didn't read that giant block of text above the mansession_session struct, the struct mansession is named this solely to keep the API the same in Asterisk. This structure really represents data that is different from Manager action to Manager action. The mansession_session pointer contained within points to session-specific data.
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
#define AST_RWLIST_REMOVE_CURRENT
#define ast_strdupa(s)
duplicate a string in memory from the stack
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
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.
const char * ast_sip_subscription_get_resource_name(struct ast_sip_subscription *sub)
Get the name of the subscribed resource.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
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.
int(* subscription_established)(struct ast_sip_subscription *sub)
Called when an inbound subscription has been accepted.
A set of macros to manage forward-linked lists.
#define ast_malloc(len)
A wrapper for malloc()
#define ast_variable_new(name, value, filename)
static void resource_tree_destroy(struct resource_tree *tree)
Destroy a resource tree.
static void publish_add_handler(struct ast_sip_publish_handler *handler)
static struct ast_sip_pubsub_body_generator * find_body_generator_type_subtype(const char *type, const char *subtype)
An entity with which Asterisk communicates.
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
int ast_sip_register_service(pjsip_module *module)
Register a SIP service in Asterisk.
const char * subtype
Content subtype In "plain/text", "text" is the subtype.
static void destroy_subscriptions(struct ast_sip_subscription *root)
struct ast_sip_pubsub_body_generator::@306 list
static force_inline char * ast_str_to_lower(char *str)
Convert a string to all lower-case.
enum sip_subscription_tree_state state
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.
static char * cli_list_subscriptions_inout(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
const char * bad_resources[]
"bad" resources
struct ast_sip_endpoint * ast_sip_publication_get_endpoint(struct ast_sip_publication *pub)
Given a publication, get the associated endpoint.
#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...
#define AST_PJSIP_XML_PROLOG_LEN
Length of the XML prolog when printing presence or other XML in PJSIP.
static pj_bool_t pubsub_on_rx_mwi_notify_request(pjsip_rx_data *rdata)
struct ast_sched_context * ast_sched_context_create(void)
Create a scheduler context.
static void pubsub_on_evsub_state(pjsip_evsub *sub, pjsip_event *event)
Callback sequence for subscription terminate:
void ast_sip_transport_monitor_unregister(pjsip_transport *transport, ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches)
Unregister a reliable transport shutdown monitor.
Structure representing a "virtual" SIP subscription.
int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype)
Checks if the given content type matches type/subtype.
#define ast_test_suite_event_notify(s, f,...)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
static struct ast_cli_entry cli[]
struct ast_sip_endpoint_id_configuration id
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
static char * cli_complete_subscription_callid(struct ast_cli_args *a)
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
int(* publication_state_change)(struct ast_sip_publication *pub, pjsip_msg_body *body, enum ast_sip_publish_state state)
Published resource has changed states.
static int persistence_tag_str2struct(const struct aco_option *opt, struct ast_variable *var, void *obj)
int ast_sip_pubsub_is_body_generator_registered(const char *type, const char *subtype)
Is a body generator registered for the given type/subtype.
int(* new_subscribe)(struct ast_sip_endpoint *endpoint, const char *resource)
Called when a SUBSCRIBE arrives attempting to establish a new subscription.
static int sip_subscription_send_request(struct sip_subscription_tree *sub_tree, pjsip_tx_data *tdata)
int ast_shutdown_final(void)
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.
static int publication_hash_fn(const void *obj, const int flags)
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
static pj_bool_t pubsub_on_rx_notify_request(pjsip_rx_data *rdata)
unsigned int expires
Expiration time of the publication.
static int resource_event_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
static int cli_show_subscription_outbound(struct sip_subscription_tree *sub_tree, void *arg)
struct ao2_container * ast_sip_subscription_get_datastores(const struct ast_sip_subscription *subscription)
Get the datastores container for a subscription.
struct ast_sip_publish_handler * handler
Handler for this publication.
struct ast_sip_pubsub_body_supplement::@307 list
static struct ast_sip_publication * publish_request_initial(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, struct ast_sip_publish_handler *handler)
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
static struct ast_generator generator
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 struct ast_sip_subscription_handler * subscription_get_handler_from_rdata(pjsip_rx_data *rdata, const char *endpoint)
Retrieve a handler using the Event header of an rdata message.
const char * ast_sip_subscription_get_body_type(struct ast_sip_subscription *sub)
Get the body type used for this subscription.
static int allocate_tdata_buffer(pjsip_tx_data *tdata)
Pre-allocate a buffer for the transmission.
static int cli_complete_subscription_outbound(struct sip_subscription_tree *sub_tree, void *arg)
#define ao2_unlink(container, obj)
int ast_sip_push_task(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Pushes a task to SIP servants.
static int test_new_subscribe(struct ast_sip_endpoint *endpoint, const char *resource)
new_subscribe callback for unit tests
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
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)
Build a resource tree.
static int send_notify(struct sip_subscription_tree *sub_tree, unsigned int force_full_state)
Send a NOTIFY request to a subscriber.
#define AST_TEST_UNREGISTER(cb)
static void subscription_setup_dialog(struct sip_subscription_tree *sub_tree, pjsip_dialog *dlg)
struct subscription_persistence * persistence
static int check_node(struct ast_test *test, struct tree_node *node, const char **resources, size_t num_resources)
Check the integrity of a tree node against a set of resources.
char * event_configuration_name
The name of the event type configuration.
Type for default option handler for bools (ast_true/ast_false)
char * ast_generate_random_string(char *buf, size_t size)
Create a pseudo-random string of a fixed length.
static int cli_complete_subscription_inbound(struct sip_subscription_tree *sub_tree, void *arg)
#define ast_module_shutdown_ref(mod)
Prevent unload of the module before shutdown.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const struct ast_json * ast_sip_subscription_get_persistence_data(const struct ast_sip_subscription *subscription)
Retrieve persistence data for a subscription.
#define ast_sorcery_apply_default(sorcery, type, name, data)
static int sub_persistence_recreate(void *obj)
#define stasis_subscribe_pool(topic, callback, data)
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
static int subscription_persistence_load(void *data)
Function which loads and recreates persisted subscriptions upon startup when the system is fully boot...
int ast_sip_register_subscription_handler(struct ast_sip_subscription_handler *handler)
Register a subscription handler.
struct ast_taskprocessor * ast_sip_create_serializer(const char *name)
Create a new serializer for SIP tasks.
void(* destroy_body)(void *body)
Deallocate resources created for the body.
static int ami_subscription_detail(struct sip_subscription_tree *sub_tree, struct ast_sip_ami *ami, const char *event)
struct stasis_subscription * stasis_unsubscribe(struct stasis_subscription *subscription)
Cancel a subscription.
Callbacks that publication handlers will define.
#define ao2_alloc(data_size, destructor_fn)
char * resource
The resource the publication is to.
struct ast_taskprocessor * ast_sip_get_distributor_serializer(pjsip_rx_data *rdata)
Determine the distributor serializer for the SIP message.
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
static int sip_publication_respond(struct ast_sip_publication *pub, int status_code, pjsip_rx_data *rdata)
void ast_sip_subscription_set_persistence_data(struct ast_sip_subscription *subscription, struct ast_json *persistence_data)
Set persistence data for a subscription.
struct sip_subscription_tree * next
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
static void subscription_persistence_remove(struct sip_subscription_tree *sub_tree)
Function which removes persistence of a subscription from sorcery.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
const char * ast_sip_publication_get_resource(const struct ast_sip_publication *pub)
Given a publication, get the resource the publication is to.
static int cli_show_subscription_inbound(struct sip_subscription_tree *sub_tree, void *arg)
struct ast_datastore * ast_sip_subscription_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
Alternative for ast_datastore_alloc()
static char version[AST_MAX_EXTENSION]
static int ineligible_configuration(void)
struct ast_sip_endpoint * endpoint
The endpoint with which the subscription is communicating.
int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, char *transport_type, const char *local_name, int local_port, const char *contact_uri)
General purpose method for creating an rdata structure using specific information.
#define ast_calloc(num, len)
A wrapper for calloc()
static int cli_show_subscriptions_detail(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)
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.
struct ast_sip_sched_task * expiration_task
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
void(* state_change)(struct ast_sip_subscription *sub, pjsip_msg_body *body, enum pjsip_evsub_state state)
A NOTIFY has been received.
static void shutdown_subscriptions(struct ast_sip_subscription *sub)
int ast_sip_will_uri_survive_restart(pjsip_sip_uri *uri, struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
void ast_datastores_remove(struct ao2_container *datastores, const char *name)
Remove a data store from a container.
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.
pjsip_generic_string_hdr * cid
static void * rlmi_clone_data(pj_pool_t *pool, const void *data, unsigned len)
pj_xml_node * ast_sip_presence_xml_create_node(pj_pool_t *pool, pj_xml_node *parent, const char *name)
Create XML node.
char * endpoint
Optional name of an endpoint that is only allowed to publish to this resource.
Module has failed to load, may be in an inconsistent state.
AST_TEST_DEFINE(resource_tree)
static void test_resource_tree_destroy(struct resource_tree *tree)
RAII_VAR callback to destroy an allocated resource tree.
static int list_item_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
#define ao2_find(container, arg, flags)
An API for managing task processing threads that can be shared across modules.
int ast_sip_pubsub_register_body_supplement(struct ast_sip_pubsub_body_supplement *supplement)
Register a body generator with the pubsub core.
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
struct ast_taskprocessor * serializer
Structure used to handle boolean flags.
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
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 char cid_name[AST_MAX_EXTENSION]
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
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.
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.
static int item_in_vector(const struct resource_list *list, const char *item)
void ast_sip_subscription_remove_datastore(struct ast_sip_subscription *subscription, const char *name)
Remove a subscription datastore from the subscription.
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
#define AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall)
#define AST_RWLIST_INSERT_TAIL
int voice_messages_urgent_old
static char * cli_show_subscriptions_inout(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
struct ast_flags ast_options
char * strsep(char **str, const char *delims)
A ast_taskprocessor structure is a singleton by name.
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)
Create a subscription tree based on a resource tree.
static struct ast_sip_publication * sip_create_publication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *resource, const char *event_configuration_name)
static struct ast_sorcery * sorcery
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
Standard Command Line Interface.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
char contact_uri[PJSIP_MAX_URL_SIZE]
ast_sip_subscription_role
Role for the subscription that is being created.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
struct sip_subscription_tree * sub_tree
#define AMI_SHOW_SUBSCRIPTIONS_INBOUND
static int publication_cmp_fn(void *obj, void *arg, int flags)
void * ast_sip_subscription_get_header(const struct ast_sip_subscription *sub, const char *header)
Get a header value for a subscription.
void ast_sip_unregister_service(pjsip_module *module)
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)
static int persistence_expires_str2struct(const struct aco_option *opt, struct ast_variable *var, void *obj)
static struct ast_sip_subscription_handler * find_sub_handler_for_event_name(const char *event_name)
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
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
sip_publish_type
The types of PUBLISH messages defined in RFC 3903.
static int populate_list(struct resource_list *list, const char *event, const char **resources, size_t num_resources)
Set properties on an allocated resource list.
static int load_module(void)
Abstract JSON element (object, array, string, int, ...).
static void pubsub_on_client_refresh(pjsip_evsub *sub)
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 char * cli_show_subscription_inout(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Structure representing a SIP publication.
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)
int entity_tag
Entity tag for the publication.
pjsip_multipart_part * part
int error(const char *format,...)
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.
static int resource_list_apply_handler(const struct ast_sorcery *sorcery, void *obj)
static void set_state_terminated(struct ast_sip_subscription *sub)
struct ast_sip_subscription_handler * next
static int ami_show_subscriptions_outbound(struct mansession *s, const struct message *m)
static pjsip_generic_string_hdr * generate_content_id_hdr(pj_pool_t *pool, const struct ast_sip_subscription *sub)
Create a Content-ID header.
void ast_sip_unregister_publish_handler(struct ast_sip_publish_handler *handler)
Unregister a publish handler.
static int have_visited(const char *resource, struct resources *visited)
Determine if this resource has been visited already.
unsigned char valid
TRUE if the name information is valid/present.
static char context[AST_MAX_CONTEXT]
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
int(* supplement_body)(void *body, void *data)
Add additional content to a SIP request body.
struct ast_sip_endpoint * ast_sip_subscription_get_endpoint(struct ast_sip_subscription *sub)
Get the endpoint that is associated with this subscription.
int ast_sip_sched_task_get_name(struct ast_sip_sched_task *schtd, char *name, size_t maxlen)
Gets the task name.
const ast_string_field aors
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
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.
static const pj_str_t str_event_name
#define ASTERISK_GPL_KEY
The text the key() function should return.
const char * default_accept
Default body type defined for the event package this notifier handles.
sip_persistence_update_type
Structure representing a publication resource.
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Asterisk module definitions.
static int persistence_generator_data_struct2str(const void *obj, const intptr_t *args, char **buf)
static int cli_show_subscriptions_inbound(struct sip_subscription_tree *sub_tree, void *arg)
struct ast_variable * events
Mapping for event types to configuration.
static unsigned int cli_subscription_expiry(struct sip_subscription_tree *sub_tree)
unsigned int send_scheduled_notify
struct ao2_container * publications
Publications.
static void destroy_subscription(struct ast_sip_subscription *sub)
char src_name[PJ_INET6_ADDRSTRLEN]
void ast_sip_transport_monitor_unregister_all(ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches)
Unregister a transport shutdown monitor from all reliable transports.
unsigned char valid
TRUE if the number information is valid/present.
#define PJSIP_EXPIRES_NOT_SPECIFIED
int(* generate_body_content)(void *body, void *data)
Add content to the body of a SIP request.
void(* subscription_shutdown)(struct ast_sip_subscription *subscription)
Called when a subscription is to be destroyed.
void ast_sched_context_destroy(struct ast_sched_context *c)
destroys a schedule context
#define AST_RWLIST_TRAVERSE_SAFE_END
struct ast_datastore * ast_sip_subscription_get_datastore(struct ast_sip_subscription *subscription, const char *name)
Retrieve a subscription datastore.
unsigned int notification_batch_interval
void ast_sip_subscription_destroy(struct ast_sip_subscription *sub)
Alert the pubsub core that the subscription is ready for destruction.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
static struct ast_sched_context * sched
Scheduler used for automatically expiring publications.
#define MOD_DATA_PERSISTENCE
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.
struct ast_sip_notifier test_notifier
Subscription notifier for unit tests.
A tree of SIP subscriptions.
static struct sip_subscription_tree * allocate_subscription_tree(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
static int cli_list_subscriptions_inbound(struct sip_subscription_tree *sub_tree, void *arg)
struct ast_json * generator_data
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
static int serialized_pubsub_on_client_refresh(void *userdata)
static int ast_sip_pubsub_has_eventlist_support(pjsip_rx_data *rdata)
Check if the rdata has a Supported header containing 'eventlist'.
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.
static int cli_complete_subscription_common(struct sip_subscription_tree *sub_tree, struct cli_sub_complete_parms *cli)
int sched_id
Scheduled item for expiration of publication.
static int cli_show_subscription_common(struct sip_subscription_tree *sub_tree, struct cli_sub_parms *cli)
static void tree_node_destroy(struct tree_node *node)
Destructor for a tree node.
char * ast_read_line_from_buffer(char **buffer)
Read lines from a string buffer.
static int unload_module(void)
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
unsigned int notification_batch_interval
struct ast_party_number number
Subscriber phone number.
#define ast_module_ref(mod)
Hold a reference to the module.
static int esc_etag_counter
#define ao2_link(container, obj)
static int resource_endpoint_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
static void free_body_parts(struct body_part_list *parts)
Destroy a list of body parts.