[asterisk-commits] mmichelson: branch mmichelson/pubsub_bodies r405922 - in /team/mmichelson/pub...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 20 14:18:48 CST 2014
Author: mmichelson
Date: Mon Jan 20 14:18:44 2014
New Revision: 405922
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=405922
Log:
Store primary body generator in the subscription.
This majorly messes up extens state providers, but it's
also a good check-in point before expanding on primary
body generator callbacks. Once the primary generator
callbacks are put in place, I can fix up exten state
completely.
Modified:
team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h
team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c
team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c
team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c
Modified: team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h?view=diff&rev=405922&r1=405921&r2=405922
==============================================================================
--- team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h (original)
+++ team/mmichelson/pubsub_bodies/include/asterisk/res_pjsip_pubsub.h Mon Jan 20 14:18:44 2014
@@ -615,7 +615,7 @@
* \param body The pre-allocated body.
* \param data The data associated with body generation.
*/
-int ast_sip_pubsub_generate_body_content(char *content_type, char *content_subtype,
+int ast_sip_pubsub_generate_body_content(struct ast_sip_subscription *sub,
void *body, void *data);
/*!
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c?view=diff&rev=405922&r1=405921&r2=405922
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c Mon Jan 20 14:18:44 2014
@@ -410,7 +410,7 @@
reason_str_ptr = &reason_str;
}
- if (ast_sip_pubsub_generate_body_content(MWI_TYPE, MWI_SUBTYPE, &body, &counter)) {
+ if (ast_sip_pubsub_generate_body_content(sub->sip_sub, &body, &counter)) {
ast_log(LOG_WARNING, "Unable to generate SIP MWI NOTIFY body.\n");
return;
}
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c?view=diff&rev=405922&r1=405921&r2=405922
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c Mon Jan 20 14:18:44 2014
@@ -293,7 +293,8 @@
goto end;
}
- if (ast_sip_pubsub_generate_body_content("application", "pidf+xml", pres, &gen_data)) {
+ /* XXX Get this NULL fixed ASAP */
+ if (ast_sip_pubsub_generate_body_content(NULL, pres, &gen_data)) {
ast_log(LOG_WARNING, "Failed to generate PIDF NOTIFY body\n");
res = -1;
goto end;
@@ -388,7 +389,8 @@
goto end;
}
- if (ast_sip_pubsub_generate_body_content("application", "xpidf+xml", pres, &gen_data)) {
+ /* XXX Get this NULL fixed ASAP */
+ if (ast_sip_pubsub_generate_body_content(NULL, pres, &gen_data)) {
ast_log(LOG_WARNING, "Unable to generate XPIDF NOTIFY body\n");
res = -1;
goto end;
Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c?view=diff&rev=405922&r1=405921&r2=405922
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c Mon Jan 20 14:18:44 2014
@@ -81,6 +81,8 @@
.on_rx_request = pubsub_on_rx_request,
};
+#define MOD_DATA_BODY_GENERATOR "sub_body_generator"
+
static const pj_str_t str_event_name = { "Event", 5 };
/*! \brief Scheduler used for automatically expiring publications */
@@ -195,6 +197,8 @@
pjsip_evsub *evsub;
/*! The underlying PJSIP dialog */
pjsip_dialog *dlg;
+ /*! Primary body generaator for NOTIFYs */
+ struct ast_sip_pubsub_body_generator *body_generator;
/*! Next item in the list */
AST_LIST_ENTRY(ast_sip_subscription) next;
};
@@ -404,6 +408,8 @@
ao2_ref(sub, -1);
return NULL;
}
+ sub->body_generator = ast_sip_mod_data_get(rdata->endpt_info.mod_data,
+ pubsub_module.id, MOD_DATA_BODY_GENERATOR);
sub->role = role;
if (role == AST_SIP_NOTIFIER) {
dlg = ast_sip_create_dialog_uas(endpoint, rdata);
@@ -733,47 +739,23 @@
return find_body_generator_type_subtype(type, subtype);
}
-static struct ast_sip_subscription_handler *find_sub_handler(const char *event, char accept[AST_SIP_MAX_ACCEPT][64], size_t num_accept)
-{
- struct ast_sip_subscription_handler *handler;
+static struct ast_sip_pubsub_body_generator *find_body_generator(char accept[AST_SIP_MAX_ACCEPT][64],
+ size_t num_accept)
+{
int i;
-
- handler = find_sub_handler_for_event_name(event);
- if (!handler) {
- ast_log(LOG_WARNING, "No subscription handler found for event %s\n", event);
- return NULL;
- }
-
- /* If a SUBSCRIBE contains no Accept headers, then we must assume that
- * the default accept type for the event package is to be used.
- */
- if (num_accept == 0) {
- struct ast_sip_pubsub_body_generator *generator;
-
- generator = find_body_generator_accept(handler->default_accept);
- if (generator) {
- ast_debug(3, "Body generator %p found for accept type %s\n", generator, handler->default_accept);
- return handler;
- } else {
- ast_log(LOG_WARNING, "No body generator found for default accept type %s\n", handler->default_accept);
- return NULL;
- }
- }
+ struct ast_sip_pubsub_body_generator *generator = NULL;
for (i = 0; i < num_accept; ++i) {
- struct ast_sip_pubsub_body_generator *generator;
-
generator = find_body_generator_accept(accept[i]);
if (generator) {
ast_debug(3, "Body generator %p found for accept type %s\n", generator, accept[i]);
- return handler;
+ break;
} else {
ast_debug(3, "No body generator found for accept type %s\n", accept[i]);
}
}
- ast_log(LOG_WARNING, "No body generator found for any Accept headers\n");
- return NULL;
+ return generator;
}
static pj_bool_t pubsub_on_rx_subscribe_request(pjsip_rx_data *rdata)
@@ -787,6 +769,7 @@
RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
struct ast_sip_subscription *sub;
size_t num_accept_headers;
+ struct ast_sip_pubsub_body_generator *generator;
endpoint = ast_pjsip_rdata_get_endpoint(rdata);
ast_assert(endpoint != NULL);
@@ -814,25 +797,38 @@
}
ast_copy_pj_str(event, &event_header->event_type, sizeof(event));
- accept_header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_ACCEPT, rdata->msg_info.msg->hdr.next);
- if (accept_header) {
- int i;
-
- for (i = 0; i < accept_header->count; ++i) {
- ast_copy_pj_str(accept[i], &accept_header->values[i], sizeof(accept[i]));
- }
- num_accept_headers = accept_header->count;
- } else {
- num_accept_headers = 0;
- }
-
- handler = find_sub_handler(event, accept, num_accept_headers);
+ handler = find_sub_handler_for_event_name(event);
if (!handler) {
ast_log(LOG_WARNING, "No registered subscribe handler for event %s\n", event);
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 489, NULL, NULL, NULL);
return PJ_TRUE;
}
- /* XXX Add code here to check for presence of body generators */
+
+ accept_header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_ACCEPT, rdata->msg_info.msg->hdr.next);
+ if (accept_header) {
+ int i;
+
+ for (i = 0; i < accept_header->count; ++i) {
+ ast_copy_pj_str(accept[i], &accept_header->values[i], sizeof(accept[i]));
+ }
+ num_accept_headers = accept_header->count;
+ } else {
+ /* If a SUBSCRIBE contains no Accept headers, then we must assume that
+ * the default accept type for the event package is to be used.
+ */
+ ast_copy_string(accept[0], handler->default_accept, sizeof(accept[0]));
+ num_accept_headers = 1;
+ }
+
+ generator = find_body_generator(accept, num_accept_headers);
+ if (!generator) {
+ pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 489, NULL, NULL, NULL);
+ return PJ_TRUE;
+ }
+
+ ast_sip_mod_data_set(rdata->tp_info.pool, rdata->endpt_info.mod_data,
+ pubsub_module.id, MOD_DATA_BODY_GENERATOR, generator);
+
sub = handler->new_subscribe(endpoint, rdata);
if (!sub) {
pjsip_transaction *trans = pjsip_rdata_get_tsx(rdata);
@@ -1148,31 +1144,40 @@
struct ast_sip_pubsub_body_generator *iter;
SCOPED_LOCK(lock, &body_generators, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&body_generators, iter, list) {
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&body_generators, iter, list) {
if (iter == generator) {
AST_LIST_REMOVE_CURRENT(list);
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END;
-}
-
-int ast_sip_pubsub_generate_body_content(char *content_type, char *content_subtype,
+ AST_RWLIST_TRAVERSE_SAFE_END;
+}
+
+int ast_sip_pubsub_generate_body_content(struct ast_sip_subscription *sub,
void *body, void *data)
{
struct ast_sip_pubsub_body_generator *iter;
- int res = -1;
-
- SCOPED_LOCK(lock, &body_generators, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
- AST_LIST_TRAVERSE(&body_generators, iter, list) {
- if (!strcmp(content_type, iter->type) &&
- !strcmp(content_subtype, iter->subtype)) {
+ int res;
+
+ res = sub->body_generator->generate_body_content(body, data);
+ if (res) {
+ return res;
+ }
+
+ AST_RWLIST_RDLOCK(&body_generators);
+ AST_RWLIST_TRAVERSE(&body_generators, iter, list) {
+ if (iter->generator_type != AST_SIP_PUBSUB_BODY_GENERATOR_SUPPLEMENTARY) {
+ continue;
+ }
+ if (!strcmp(sub->body_generator->type, iter->type) &&
+ !strcmp(sub->body_generator->subtype, iter->subtype)) {
res = iter->generate_body_content(body, data);
if (res) {
break;
}
}
}
+ AST_RWLIST_UNLOCK(&body_generators);
return res;
}
More information about the asterisk-commits
mailing list