[svn-commits] file: branch file/pjsip-subscription-persistence r415334 - /team/file/pjsip-s...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Jun 6 09:32:33 CDT 2014
Author: file
Date: Fri Jun 6 09:32:27 2014
New Revision: 415334
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=415334
Log:
Persist the expiration time of the subscription so the recreated subscription
does not start fresh at the requested (or default) expiration.
Modified:
team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c
Modified: team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c?view=diff&rev=415334&r1=415333&r2=415334
==============================================================================
--- team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c (original)
+++ team/file/pjsip-subscription-persistence/res/res_pjsip_pubsub.c Fri Jun 6 09:32:27 2014
@@ -206,6 +206,8 @@
unsigned int cseq;
/*! Local tag of the dialog */
char *tag;
+ /*! When this subscription expires */
+ struct timeval expires;
};
/*!
@@ -293,6 +295,12 @@
sub->persistence->cseq = sub->dlg->local.cseq;
if (rdata) {
+ int expires;
+ pjsip_expires_hdr *expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL);
+
+ expires = expires_hdr ? expires_hdr->ivalue : DEFAULT_PUBLISH_EXPIRES;
+ sub->persistence->expires = ast_tvadd(ast_tvnow(), ast_samp2tv(expires, 1));
+
ast_copy_string(sub->persistence->packet, rdata->pkt_info.packet, sizeof(sub->persistence->packet));
ast_copy_string(sub->persistence->src_name, rdata->pkt_info.src_name, sizeof(sub->persistence->src_name));
sub->persistence->src_port = rdata->pkt_info.src_port;
@@ -332,6 +340,7 @@
char event[32];
char accept[AST_SIP_MAX_ACCEPT][64];
pjsip_accept_hdr *accept_header;
+ pjsip_expires_hdr *expires_header;
pjsip_event_hdr *event_header;
struct ast_sip_subscription_handler *handler;
RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
@@ -339,6 +348,12 @@
size_t num_accept_headers;
struct ast_sip_pubsub_body_generator *generator;
+ /* If this subscription has already expired remove it */
+ if (ast_tvdiff_ms(persistence->expires, ast_tvnow()) <= 0) {
+ ast_sorcery_delete(ast_sip_get_sorcery(), persistence);
+ return 0;
+ }
+
endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", persistence->endpoint);
if (!endpoint) {
ast_log(LOG_WARNING, "A subscription for '%s' could not be recreated as the endpoint was not found\n",
@@ -367,6 +382,17 @@
rdata.tp_info.transport->type_name = persistence->transport_key;
pj_strset2(&rdata.tp_info.transport->local_name.host, persistence->local_name);
rdata.tp_info.transport->local_name.port = persistence->local_port;
+
+ /* Update the expiration header with the new expiration */
+ expires_header = pjsip_msg_find_hdr(rdata.msg_info.msg, PJSIP_H_EXPIRES, rdata.msg_info.msg->hdr.next);
+ if (!expires_header) {
+ expires_header = pjsip_expires_hdr_create(pool, 0);
+ if (!expires_header) {
+ return 0;
+ }
+ pjsip_msg_add_hdr(rdata.msg_info.msg, (pjsip_hdr*)expires_header);
+ }
+ expires_header->ivalue = (ast_tvdiff_ms(persistence->expires, ast_tvnow()) / 1000);
event_header = pjsip_msg_find_hdr_by_name(rdata.msg_info.msg, &str_event_name, rdata.msg_info.msg->hdr.next);
ast_copy_pj_str(event, &event_header->event_type, sizeof(event));
@@ -1760,6 +1786,18 @@
return 0;
}
+static int persistence_expires_str2struct(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+ struct subscription_persistence *persistence = obj;
+ return ast_get_timeval(var->value, &persistence->expires, ast_tv(0, 0), NULL);
+}
+
+static int persistence_expires_struct2str(const void *obj, const intptr_t *args, char **buf)
+{
+ const struct subscription_persistence *persistence = obj;
+ return (ast_asprintf(buf, "%ld", persistence->expires.tv_sec) < 0) ? -1 : 0;
+}
+
static int load_module(void)
{
static const pj_str_t str_PUBLISH = { "PUBLISH", 7 };
@@ -1813,6 +1851,8 @@
persistence_endpoint_str2struct, persistence_endpoint_struct2str, NULL, 0, 0);
ast_sorcery_object_field_register_custom_nodoc(sorcery, "subscription_persistence", "tag", "",
persistence_tag_str2struct, persistence_tag_struct2str, NULL, 0, 0);
+ ast_sorcery_object_field_register_custom_nodoc(sorcery, "subscription_persistence", "expires", "",
+ persistence_expires_str2struct, persistence_expires_struct2str, NULL, 0, 0);
ast_manager_register_xml(AMI_SHOW_SUBSCRIPTIONS_INBOUND, EVENT_FLAG_SYSTEM,
ami_show_subscriptions_inbound);
More information about the svn-commits
mailing list