[asterisk-commits] mmichelson: branch mmichelson/rls-notify r418145 - /team/mmichelson/rls-notif...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jul 7 14:55:38 CDT 2014
Author: mmichelson
Date: Mon Jul 7 14:55:34 2014
New Revision: 418145
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418145
Log:
Change algorithm for NOTIFY body generation.
Prior to this change, a "bottom-up" algorithm
was used. When a leaf subscription's state changed,
the body was generated and stored on the leaf subscription.
Then, moving up the tree, each parent list subscription
had its body regenerated until the root was reached. When
it came time to send a NOTIFY, the pre-generated body on
the root subscription was used in the NOTIFY body.
This would be a fine method to use if we were always
sending full or always sending partial notification
state. However, the context of the NOTIFY we send
can change whether we send a full or partial state.
Therefore, we have to generate the list body at the
time that we send our NOTIFY so we can generate the
proper body type.
The next large effort is to properly track the subscription
state of individual leaves/lists since right now that
is totally messed up.
Modified:
team/mmichelson/rls-notify/res/res_pjsip_pubsub.c
Modified: team/mmichelson/rls-notify/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-notify/res/res_pjsip_pubsub.c?view=diff&rev=418145&r1=418144&r2=418145
==============================================================================
--- team/mmichelson/rls-notify/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-notify/res/res_pjsip_pubsub.c Mon Jul 7 14:55:34 2014
@@ -434,6 +434,8 @@
AST_LIST_HEAD_NOLOCK(,ast_sip_subscription) children;
/*! Saved NOTIFY body text for this subscription */
struct ast_str *body_text;
+ /*! Indicator that the body text has changed since the last notification */
+ int body_changed;
/*! Name of resource being subscribed to */
char resource[0];
};
@@ -1464,6 +1466,32 @@
return res;
}
+static int generate_list_body(struct ast_sip_subscription *sub, struct ast_str **str)
+{
+ /* XXX This is where a multipart/related body would be created with
+ * an RLMI part and the bodies of all child parts of the subscription.
+ * The generated multipart/related body is then saved on sub->body_text.
+ *
+ * This will be added when working on ASTERISK-23867. For now, this is
+ * just a STUB.
+ */
+ return 0;
+}
+
+static int generate_notify_body(struct ast_sip_subscription *root, struct ast_str **body_text)
+{
+ if (AST_LIST_EMPTY(&root->children)) {
+ /* Not a list. We've already generated the body and saved it on the subscription.
+ * Use that directly.
+ */
+ ast_str_copy_string(body_text, root->body_text);
+ root->body_changed = 0;
+ return 0;
+ }
+
+ return generate_list_body(root, body_text);
+}
+
static int send_notify(struct ast_sip_subscription *sub, int terminate)
{
pjsip_evsub *evsub = sip_subscription_get_evsub(sub);
@@ -1474,6 +1502,12 @@
.subtype = ast_sip_subscription_get_body_subtype(sub),
.body_text = ast_str_buffer(sub->body_text),
};
+ struct ast_str *body_text;
+
+ body_text = ast_str_create(64);
+ if (!body_text) {
+ return -1;
+ }
if (terminate) {
state = PJSIP_EVSUB_STATE_TERMINATED;
@@ -1483,33 +1517,33 @@
}
if (pjsip_evsub_notify(evsub, state, NULL, NULL, &tdata) != PJ_SUCCESS) {
+ ast_free(body_text);
return -1;
}
+
+ if (generate_notify_body(sub, &body_text)) {
+ pjsip_tx_data_dec_ref(tdata);
+ ast_free(body_text);
+ return -1;
+ }
+
+ body.body_text = ast_str_buffer(body_text);
if (ast_sip_add_body(tdata, &body)) {
pjsip_tx_data_dec_ref(tdata);
+ ast_free(body_text);
return -1;
}
if (sip_subscription_send_request(sub, tdata)) {
pjsip_tx_data_dec_ref(tdata);
+ ast_free(body_text);
return -1;
}
sub->reality.real.send_scheduled_notify = 0;
+ ast_free(body_text);
- return 0;
-}
-
-static int generate_list_body(struct ast_sip_subscription *sub)
-{
- /* XXX This is where a multipart/related body would be created with
- * an RLMI part and the bodies of all child parts of the subscription.
- * The generated multipart/related body is then saved on sub->body_text.
- *
- * This will be added when working on ASTERISK-23867. For now, this is
- * just a STUB.
- */
return 0;
}
@@ -1561,11 +1595,10 @@
return -1;
}
+ sub->body_changed = 1;
+
while (sub->type == SIP_SUBSCRIPTION_VIRTUAL) {
sub = sub->reality.virtual.parent;
- if (generate_list_body(sub)) {
- return -1;
- }
}
if (sub->reality.real.notification_batch_interval) {
@@ -1904,14 +1937,13 @@
return -1;
}
- AST_LIST_TRAVERSE(&sub->children, child, next) {
- if (generate_initial_notify(child)) {
- return -1;
+ if (!AST_LIST_EMPTY(&sub->children)) {
+ AST_LIST_TRAVERSE(&sub->children, child, next) {
+ if (generate_initial_notify(child)) {
+ return -1;
+ }
}
- }
-
- if (!AST_LIST_EMPTY(&sub->children)) {
- return generate_list_body(sub);
+ return 0;
}
notify_data = sub->handler->notifier->get_notify_data(sub);
More information about the asterisk-commits
mailing list