[Asterisk-code-review] res pjsip: Use ast sip is content type() where appropriate (asterisk[13])

Sean Bright asteriskteam at digium.com
Fri Sep 22 10:04:53 CDT 2017


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/6564


Change subject: res_pjsip: Use ast_sip_is_content_type() where appropriate
......................................................................

res_pjsip: Use ast_sip_is_content_type() where appropriate

Change-Id: If3ab0d73d79ac4623308bd48508af2bfd554937d
---
M res/res_pjsip_messaging.c
M res/res_pjsip_publish_asterisk.c
M res/res_pjsip_pubsub.c
M res/res_pjsip_session.c
4 files changed, 13 insertions(+), 17 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/64/6564/1

diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index 2f01a0f..3209141 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -69,8 +69,8 @@
 			&rdata->msg_info.msg->body->content_type, "text", "plain");
 	} else {
 		res = rdata->msg_info.ctype &&
-			!pj_strcmp2(&rdata->msg_info.ctype->media.type, "text") &&
-			!pj_strcmp2(&rdata->msg_info.ctype->media.subtype, "plain");
+			ast_sip_is_content_type(
+				&rdata->msg_info.ctype->media, "text", "plain");
 	}
 
 	return res ? PJSIP_SC_OK : PJSIP_SC_UNSUPPORTED_MEDIA_TYPE;
diff --git a/res/res_pjsip_publish_asterisk.c b/res/res_pjsip_publish_asterisk.c
index 7e87762..fa5e4ce 100644
--- a/res/res_pjsip_publish_asterisk.c
+++ b/res/res_pjsip_publish_asterisk.c
@@ -605,8 +605,7 @@
 	}
 
 	/* We only accept JSON for content */
-	if (pj_strcmp2(&body->content_type.type, "application") ||
-		pj_strcmp2(&body->content_type.subtype, "json")) {
+	if (!ast_sip_is_content_type(&body->content_type, "application", "json")) {
 		ast_debug(2, "Received unsupported content type for Asterisk event on resource '%s'\n",
 			ast_sorcery_object_get_id(config));
 		return -1;
@@ -697,8 +696,7 @@
 	}
 
 	/* We only accept JSON for content */
-	if (pj_strcmp2(&body->content_type.type, "application") ||
-		pj_strcmp2(&body->content_type.subtype, "json")) {
+	if (!ast_sip_is_content_type(&body->content_type, "application", "json")) {
 		ast_debug(2, "Received unsupported content type for Asterisk event on resource '%s'\n",
 			ast_sorcery_object_get_id(config));
 		return -1;
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 6c6e2b6..0071e01 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -516,6 +516,8 @@
 AST_RWLIST_HEAD_STATIC(body_generators, ast_sip_pubsub_body_generator);
 AST_RWLIST_HEAD_STATIC(body_supplements, ast_sip_pubsub_body_supplement);
 
+static pjsip_media_type rlmi_media_type;
+
 static void pubsub_on_evsub_state(pjsip_evsub *sub, pjsip_event *event);
 static void pubsub_on_rx_refresh(pjsip_evsub *sub, pjsip_rx_data *rdata,
 		int *p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body);
@@ -2044,8 +2046,6 @@
 static pjsip_multipart_part *build_rlmi_body(pj_pool_t *pool, struct ast_sip_subscription *sub,
 		struct body_part_list *body_parts, unsigned int full_state)
 {
-	static const pj_str_t rlmi_type = { "application", 11 };
-	static const pj_str_t rlmi_subtype = { "rlmi+xml", 8 };
 	pj_xml_node *rlmi;
 	pj_xml_node *name;
 	pjsip_multipart_part *rlmi_part;
@@ -2076,9 +2076,7 @@
 	rlmi_part = pjsip_multipart_create_part(pool);
 
 	rlmi_part->body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body);
-	pj_strdup(pool, &rlmi_part->body->content_type.type, &rlmi_type);
-	pj_strdup(pool, &rlmi_part->body->content_type.subtype, &rlmi_subtype);
-	pj_list_init(&rlmi_part->body->content_type.param);
+	pjsip_media_type_cp(pool, &rlmi_part->body->content_type, &rlmi_media_type);
 
 	rlmi_part->body->data = pj_xml_clone(pool, rlmi);
 	rlmi_part->body->clone_data = rlmi_clone_data;
@@ -3584,12 +3582,11 @@
 	return PJ_TRUE;
 }
 
-static pjsip_media_type simple_message_summary;
-
 static pj_bool_t pubsub_on_rx_notify_request(pjsip_rx_data *rdata)
 {
 	if (rdata->msg_info.msg->body &&
-		pjsip_media_type_cmp(&rdata->msg_info.msg->body->content_type, &simple_message_summary, 0) == 0) {
+		ast_sip_is_content_type(&rdata->msg_info.msg->body->content_type,
+								"application", "simple-message-summary")) {
 		return pubsub_on_rx_mwi_notify_request(rdata);
 	}
 	return PJ_FALSE;
@@ -5425,7 +5422,7 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	pjsip_media_type_init2(&simple_message_summary, "application", "simple-message-summary");
+	pjsip_media_type_init2(&rlmi_media_type, "application", "rlmi+xml");
 
 	if (ast_sched_start_thread(sched)) {
 		ast_log(LOG_ERROR, "Could not start scheduler thread for publication expiration\n");
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 3d73862..d1e23f5 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -3181,8 +3181,9 @@
 	int stream;
 
 	/* SDP produced by us directly will never be multipart */
-	if (!transport_state || hook || !tdata->msg->body || pj_stricmp2(&tdata->msg->body->content_type.type, "application") ||
-		pj_stricmp2(&tdata->msg->body->content_type.subtype, "sdp") || ast_strlen_zero(transport->external_media_address)) {
+	if (!transport_state || hook || !tdata->msg->body ||
+		!ast_sip_is_content_type(&tdata->msg->body->content_type, "application", "sdp") ||
+		ast_strlen_zero(transport->external_media_address)) {
 		return;
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/6564
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: If3ab0d73d79ac4623308bd48508af2bfd554937d
Gerrit-Change-Number: 6564
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170922/04c6fcbd/attachment.html>


More information about the asterisk-code-review mailing list