[asterisk-commits] mmichelson: branch mmichelson/pubsub_bodies r405879 - /team/mmichelson/pubsub...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 17 16:12:39 CST 2014


Author: mmichelson
Date: Fri Jan 17 16:12:38 2014
New Revision: 405879

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=405879
Log:
Make it so inbound SUBSCRIBEs need to have an appropriate body generator present.

The next step is to remove some of the redundant logic from the pubsub framework.
Body generators are the only thing that really need to worry about Accept headers
in SUBSCRIBEs. Subscription handlers and potentially exten state providers do not
need to concern themselves with this.


Modified:
    team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c

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=405879&r1=405878&r2=405879
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pubsub.c Fri Jan 17 16:12:38 2014
@@ -206,6 +206,8 @@
 
 AST_RWLIST_HEAD_STATIC(subscriptions, ast_sip_subscription);
 
+AST_RWLIST_HEAD_STATIC(body_generators, ast_sip_pubsub_body_generator);
+
 static void add_subscription(struct ast_sip_subscription *obj)
 {
 	SCOPED_LOCK(lock, &subscriptions, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
@@ -696,6 +698,35 @@
 	AST_RWLIST_TRAVERSE_SAFE_END;
 }
 
+static struct ast_sip_pubsub_body_generator *find_body_generator_type_subtype(char *content_type,
+		char *content_subtype)
+{
+	struct ast_sip_pubsub_body_generator *iter;
+	SCOPED_LOCK(lock, &body_generators, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
+
+	AST_LIST_TRAVERSE(&body_generators, iter, list) {
+		if (!strcmp(iter->type, content_type) &&
+				!strcmp(iter->subtype, content_subtype)) {
+			break;
+		}
+	};
+
+	return iter;
+}
+
+static struct ast_sip_pubsub_body_generator *find_body_generator_accept(const char *accept)
+{
+	char *accept_copy = ast_strdupa(accept);
+	char *subtype = accept_copy;
+	char *type = strsep(&subtype, "/");
+
+	if (ast_strlen_zero(type) || ast_strlen_zero(subtype)) {
+		return NULL;
+	}
+
+	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 *iter;
@@ -722,8 +753,14 @@
 					break;
 				}
 				if (!strcmp(accept[j], iter->accept[i])) {
+					struct ast_sip_pubsub_body_generator *generator;
+
 					ast_debug(3, "Accept headers match: %s = %s\n", accept[j], iter->accept[i]);
-					match = 1;
+					generator = find_body_generator_accept(accept[j]);
+					if (generator) {
+						ast_debug(3, "Body generator %p matches this content type\n", generator);
+						match = 1;
+					}
 					break;
 				}
 				ast_debug(3, "Accept %s does not match %s\n", accept[j], iter->accept[i]);
@@ -1064,8 +1101,6 @@
 	return pjsip_tsx_send_msg(tsx, tdata);
 }
 
-AST_RWLIST_HEAD_STATIC(body_generators, ast_sip_pubsub_body_generator);
-
 int ast_sip_pubsub_register_body_generator(struct ast_sip_pubsub_body_generator *generator)
 {
 	struct ast_sip_pubsub_body_generator *iter;
@@ -1114,8 +1149,8 @@
 {
 	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)) {




More information about the asterisk-commits mailing list