[svn-commits] mmichelson: branch mmichelson/rls-rlmi r418224 - /team/mmichelson/rls-rlmi/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 9 11:02:46 CDT 2014


Author: mmichelson
Date: Wed Jul  9 11:02:43 2014
New Revision: 418224

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418224
Log:
Fix a few known issues with multipart body generation

* Place the RLMI body part before the other body parts
* Make body generation for lists of lists work properly


Modified:
    team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c

Modified: team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c?view=diff&rev=418224&r1=418223&r2=418224
==============================================================================
--- team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c Wed Jul  9 11:02:43 2014
@@ -1467,14 +1467,16 @@
 	ast_sip_presence_xml_create_attr(pool, instance, "cid", ast_strip_quoted(ast_strdupa(cid), "<", ">"));
 }
 
+AST_VECTOR(cid_list, const char *);
+
 static pj_xml_node *build_rlmi_body(pj_pool_t *pool, struct ast_sip_subscription *sub,
-		pjsip_msg_body *body)
+		struct cid_list *cids)
 {
 	pj_xml_node *rlmi;
 	pj_xml_node *name;
 	char version_str[32];
 	char uri[PJSIP_MAX_URL_SIZE];
-	pjsip_multipart_part *part_iter;
+	int i;
 
 	rlmi = ast_sip_presence_xml_create_node(pool, NULL, "list");
 	ast_sip_presence_xml_create_attr(pool, rlmi, "xmlns", "urn:ietf:params:xml:ns:rlmi");
@@ -1494,23 +1496,31 @@
 	name = ast_sip_presence_xml_create_node(pool, rlmi, "name");
 	pj_strdup2(pool, &name->content, ast_sip_subscription_get_resource_name(sub));
 
-	for (part_iter = pjsip_multipart_get_first_part(body);
-			part_iter;
-			part_iter = pjsip_multipart_get_next_part(body, part_iter)) {
-		/* XXX This is where we'd search for the Content-ID header on
-		 * the multipart part. However, we currently have a hard-coded
-		 * Content-ID anyway, so just use that for the moment.
-		 */
-		add_rlmi_resource(pool, rlmi, "<prawnstar at bass-turd.org>");
-	}
+	for (i = 0; i < AST_VECTOR_SIZE(cids); ++i) {
+		add_rlmi_resource(pool, rlmi, AST_VECTOR_GET(cids, i));
+	}
+
 	return rlmi;
+}
+
+static pjsip_msg_body *generate_notify_body(pj_pool_t *pool, struct ast_sip_subscription *root);
+
+static void free_cids(struct cid_list *cids)
+{
+	int i;
+
+	for (i = 0; i < AST_VECTOR_SIZE(cids); ++i) {
+		ast_free((char *) AST_VECTOR_GET(cids, i));
+	}
+
+	AST_VECTOR_FREE(cids);
 }
 
 static pjsip_msg_body *generate_list_body(pj_pool_t *pool, struct ast_sip_subscription *sub)
 {
 	int i;
 	pj_xml_node *rlmi;
-	char rlmi_str[2048];
+	char rlmi_str[2048] = { 0,};
 	pjsip_msg_body *multipart;
 	pjsip_media_type media_type = {
 		.type = { "multipart", 9 },
@@ -1520,48 +1530,46 @@
 	static const pj_str_t rlmi_type = { "application", 11};
 	static const pj_str_t rlmi_subtype = {"rlmi+xml", 8};
 	pj_str_t rlmi_text;
+	struct cid_list cids;
+
+	AST_VECTOR_INIT(&cids, AST_VECTOR_SIZE(&sub->children));
 	
 	multipart = pjsip_multipart_create(pool, &media_type, NULL);
+
+	/* Start by generating content IDs for children.
+	 * Do this by creating a parallel vector to the vector of child subscriptions.
+	 */
+	for (i = 0; i < AST_VECTOR_SIZE(&sub->children); ++i) {
+		/* XXX Using a hard-coded value for the moment */
+		AST_VECTOR_APPEND(&cids, ast_strdup("<prawnstar at bass-turd.org>"));
+	}
+	
+	rlmi = build_rlmi_body(pool, sub, &cids);
+	pj_xml_print(rlmi, rlmi_str, sizeof(rlmi_str) - 1, PJ_TRUE);
+	pj_cstr(&rlmi_text, rlmi_str);
+
+	rlmi_part = pjsip_multipart_create_part(pool);
+	rlmi_part->body = pjsip_msg_body_create(pool, &rlmi_type, &rlmi_subtype, &rlmi_text);
+	pjsip_multipart_add_part(pool, multipart, rlmi_part);
 
 	for (i = 0; i < AST_VECTOR_SIZE(&sub->children); ++i) {
 		/* XXX This should probably be factored into a function */
 		struct ast_sip_subscription *child = AST_VECTOR_GET(&sub->children, i);
 		pjsip_multipart_part *part = pjsip_multipart_create_part(pool);
 		pjsip_generic_string_hdr *cid;
-		pj_str_t type;
-		pj_str_t subtype;
-		pj_str_t text;
 		static const pj_str_t cid_name = { "Content-ID", 10 };
-		/* XXX Hard-coded for the moment */
-		pj_str_t cid_value = {"<prawnstar at bass-turd.org>", 25 };
-
-		pj_cstr(&type, ast_sip_subscription_get_body_type(child));
-		pj_cstr(&subtype, ast_sip_subscription_get_body_subtype(child));
-		pj_cstr(&text, ast_str_buffer(child->body_text));
-
-		/* XXX This assumes that child is not a list. If child were a list, then
-		 * we would make a recursive call to create the message body.
-		 */
-		part->body = pjsip_msg_body_create(pool, &type, &subtype, &text);
-
+		pj_str_t cid_value;
+
+		part->body = generate_notify_body(pool, child);
+
+		pj_cstr(&cid_value, AST_VECTOR_GET(&cids, i));
 		cid = pjsip_generic_string_hdr_create(pool, &cid_name, &cid_value);
 		pj_list_insert_before(&part->hdr, cid);
 
 		pjsip_multipart_add_part(pool, multipart, part);
 	}
 
-	/* Once we've built the other bodies, we can build our RLMI body! */
-	/* XXX It would be better to have the RLMI body as the first part in
-	 * the multipart body. This currently places it at the end.
-	 */
-	rlmi = build_rlmi_body(pool, sub, multipart);
-	pj_xml_print(rlmi, rlmi_str, sizeof(rlmi_str) - 1, PJ_TRUE);
-	pj_cstr(&rlmi_text, rlmi_str);
-
-	rlmi_part = pjsip_multipart_create_part(pool);
-	rlmi_part->body = pjsip_msg_body_create(pool, &rlmi_type, &rlmi_subtype, &rlmi_text);
-	pjsip_multipart_add_part(pool, multipart, rlmi_part);
-
+	free_cids(&cids);
 	return multipart;
 }
 




More information about the svn-commits mailing list