<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17857">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Add utils for checking media types<br><br>Added two new functions to assist checking media types...<br><br>* ast_sip_are_media_types_equal compares two pjsip_media_types.<br>* ast_sip_is_media_type_in tests if one media type is in a list<br>  of others.<br><br>Added static definitions for commonly used media types to<br>res_pjsip.h.<br><br>Changed several modules to use the new functions and static<br>definitions.<br><br>ASTERISK_29813<br>(not ready to close)<br><br>Change-Id: Ief77675235bd3bf00a6b095d4673fd878d0801b9<br>---<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip.c<br>M res/res_pjsip.exports.in<br>M res/res_pjsip_sdp_rtp.c<br>M res/res_pjsip_session.c<br>5 files changed, 97 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/17857/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index ac4725e..9f35393 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -953,6 +953,40 @@</span><br><span> #define AST_SIP_X_AST_TXP "x-ast-txp"</span><br><span> #define AST_SIP_X_AST_TXP_LEN 9</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Common media types used throughout res_pjsip and pjproject */</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_application_json;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_application_media_control_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_application_pidf_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_application_xpidf_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_application_cpim_xpidf_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_application_rlmi_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_application_simple_message_summary;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_application_sdp;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_multipart_alternative;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_multipart_mixed;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_multipart_related;</span><br><span style="color: hsl(120, 100%, 40%);">+extern pjsip_media_type pjsip_media_type_text_plain;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Compare pjsip media types</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param pjsip_media_type a</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param pjsip_media_type b</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 1 Media types are equal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 Media types are not equal</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_are_media_types_equal(pjsip_media_type *a, pjsip_media_type *b);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Check if a media type is in a list of others</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param a pjsip_media_type to search for</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param ... one or more pointers to pjsip_media_types the last of which must be "SENTINEL"</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 1 Media types are equal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 Media types are not equal</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_is_media_type_in(pjsip_media_type *a, ...) attribute_sentinel;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span>  * \brief Initialize an auth vector with the configured values.</span><br><span>  *</span><br><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index 697767d..2f9edfb 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -5292,6 +5292,34 @@</span><br><span>         return res;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_are_media_types_equal(pjsip_media_type *a, pjsip_media_type *b)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  int rc = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+   if (a != NULL && b != NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+     rc = pjsip_media_type_cmp(a, b, 0) ? 0 : 1;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+     return rc;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_is_media_type_in(pjsip_media_type *a, ...)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    int rc = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+   pjsip_media_type *b = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+   va_list ap;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert(a != NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+        va_start(ap, a);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    while ((b = va_arg(ap, pjsip_media_type *)) != (pjsip_media_type *)SENTINEL) {</span><br><span style="color: hsl(120, 100%, 40%);">+                if (pjsip_media_type_cmp(a, b, 0) == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     rc = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+                       break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     va_end(ap);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return rc;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> </span><br><span> int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype)</span><br><span> {</span><br><span>@@ -5844,6 +5872,20 @@</span><br><span>    pjmedia_strerror(0, NULL, 0);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Definitions of media types declared "extern" in res_pjsip.h */</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_application_json;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_application_media_control_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_application_pidf_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_application_xpidf_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_application_cpim_xpidf_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_application_rlmi_xml;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_application_simple_message_summary;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_application_sdp;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_multipart_alternative;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_multipart_mixed;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_multipart_related;</span><br><span style="color: hsl(120, 100%, 40%);">+pjsip_media_type pjsip_media_type_text_plain;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int load_module(void)</span><br><span> {</span><br><span>   struct ast_threadpool_options options;</span><br><span>@@ -5863,6 +5905,21 @@</span><br><span>              ast_log(LOG_WARNING, "Failed to register pjmedia error codes.  Codes will not be decoded.\n");</span><br><span>     }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Initialize common media types */</span><br><span style="color: hsl(120, 100%, 40%);">+   pjsip_media_type_init2(&pjsip_media_type_application_json, "application", "json");</span><br><span style="color: hsl(120, 100%, 40%);">+    pjsip_media_type_init2(&pjsip_media_type_application_media_control_xml, "application", "media_control+xml");</span><br><span style="color: hsl(120, 100%, 40%);">+  pjsip_media_type_init2(&pjsip_media_type_application_pidf_xml, "application", "pidf+xml");</span><br><span style="color: hsl(120, 100%, 40%);">+    pjsip_media_type_init2(&pjsip_media_type_application_xpidf_xml, "application", "xpidf+xml");</span><br><span style="color: hsl(120, 100%, 40%);">+  pjsip_media_type_init2(&pjsip_media_type_application_cpim_xpidf_xml, "application", "cpim-xpidf+xml");</span><br><span style="color: hsl(120, 100%, 40%);">+        pjsip_media_type_init2(&pjsip_media_type_application_rlmi_xml, "application", "rlmi+xml");</span><br><span style="color: hsl(120, 100%, 40%);">+    pjsip_media_type_init2(&pjsip_media_type_application_sdp, "application", "sdp");</span><br><span style="color: hsl(120, 100%, 40%);">+      pjsip_media_type_init2(&pjsip_media_type_application_simple_message_summary, "application",       "simple-message-summary");</span><br><span style="color: hsl(120, 100%, 40%);">+  pjsip_media_type_init2(&pjsip_media_type_multipart_alternative, "multipart", "alternative");</span><br><span style="color: hsl(120, 100%, 40%);">+  pjsip_media_type_init2(&pjsip_media_type_multipart_mixed, "multipart", "mixed");</span><br><span style="color: hsl(120, 100%, 40%);">+      pjsip_media_type_init2(&pjsip_media_type_multipart_related, "multipart", "related");</span><br><span style="color: hsl(120, 100%, 40%);">+  pjsip_media_type_init2(&pjsip_media_type_text_plain, "text", "plain");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>   if (ast_sip_initialize_system()) {</span><br><span>           ast_log(LOG_ERROR, "Failed to initialize SIP 'system' configuration section. Aborting load\n");</span><br><span>            goto error;</span><br><span>diff --git a/res/res_pjsip.exports.in b/res/res_pjsip.exports.in</span><br><span>index 7ac2b7e..58868e3 100644</span><br><span>--- a/res/res_pjsip.exports.in</span><br><span>+++ b/res/res_pjsip.exports.in</span><br><span>@@ -2,6 +2,7 @@</span><br><span>   global:</span><br><span>              LINKER_SYMBOL_PREFIXast_sip_*;</span><br><span>               LINKER_SYMBOL_PREFIX__ast_sip_*;</span><br><span style="color: hsl(120, 100%, 40%);">+              LINKER_SYMBOL_PREFIXpjsip_media_type_*;</span><br><span>              LINKER_SYMBOL_PREFIXast_copy_pj_str;</span><br><span>                 LINKER_SYMBOL_PREFIXast_copy_pj_str2;</span><br><span>                LINKER_SYMBOL_PREFIXast_pjsip_rdata_get_endpoint;</span><br><span>diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c</span><br><span>index 10db010..a5e0b78 100644</span><br><span>--- a/res/res_pjsip_sdp_rtp.c</span><br><span>+++ b/res/res_pjsip_sdp_rtp.c</span><br><span>@@ -2317,9 +2317,8 @@</span><br><span>   pjsip_tx_data *tdata;</span><br><span> </span><br><span>    if (!session->channel</span><br><span style="color: hsl(0, 100%, 40%);">-                || !ast_sip_is_content_type(&rdata->msg_info.msg->body->content_type,</span><br><span style="color: hsl(0, 100%, 40%);">-                      "application",</span><br><span style="color: hsl(0, 100%, 40%);">-                        "media_control+xml")) {</span><br><span style="color: hsl(120, 100%, 40%);">+             || !ast_sip_are_media_types_equal(&rdata->msg_info.msg->body->content_type,</span><br><span style="color: hsl(120, 100%, 40%);">+                      &pjsip_media_type_application_media_control_xml)) {</span><br><span>              return 0;</span><br><span>    }</span><br><span> </span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index e915429..cfd71fb 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -3893,9 +3893,8 @@</span><br><span>       pjsip_ctype_hdr *ctype_hdr = rdata->msg_info.ctype;</span><br><span> </span><br><span>   if (body && ctype_hdr &&</span><br><span style="color: hsl(0, 100%, 40%);">-                !pj_stricmp2(&ctype_hdr->media.type, "multipart") &&</span><br><span style="color: hsl(0, 100%, 40%);">-           (!pj_stricmp2(&ctype_hdr->media.subtype, "mixed") ||</span><br><span style="color: hsl(0, 100%, 40%);">-            !pj_stricmp2(&ctype_hdr->media.subtype, "alternative"))) {</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_sip_is_media_type_in(&ctype_hdr->media, &pjsip_media_type_multipart_mixed,</span><br><span style="color: hsl(120, 100%, 40%);">+                     &pjsip_media_type_multipart_alternative, SENTINEL)) {</span><br><span>            pjsip_multipart_part *part = pjsip_multipart_get_first_part(body);</span><br><span>           while (part != NULL) {</span><br><span>                       if (check_content_disposition_in_multipart(part)) {</span><br><span>@@ -5488,7 +5487,7 @@</span><br><span> </span><br><span>      /* SDP produced by us directly will never be multipart */</span><br><span>    if (!transport_state || hook || !tdata->msg->body ||</span><br><span style="color: hsl(0, 100%, 40%);">-              !ast_sip_is_content_type(&tdata->msg->body->content_type, "application", "sdp") ||</span><br><span style="color: hsl(120, 100%, 40%);">+           !ast_sip_are_media_types_equal(&tdata->msg->body->content_type, &pjsip_media_type_application_sdp) ||</span><br><span>               ast_strlen_zero(transport->external_media_address)) {</span><br><span>             return;</span><br><span>      }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17857">change 17857</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/17857"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 19 </div>
<div style="display:none"> Gerrit-Change-Id: Ief77675235bd3bf00a6b095d4673fd878d0801b9 </div>
<div style="display:none"> Gerrit-Change-Number: 17857 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>