<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13679">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_messaging: Allow Content-Type to be overridden<br><br>ASTERISK-26082 #close<br>Reported by: Alex<br><br>Change-Id: I6549e90932016349bc72b0f053432dc25286f4fb<br>---<br>M res/res_pjsip_messaging.c<br>1 file changed, 33 insertions(+), 5 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c</span><br><span>index 76d37f2..da08b44 100644</span><br><span>--- a/res/res_pjsip_messaging.c</span><br><span>+++ b/res/res_pjsip_messaging.c</span><br><span>@@ -317,10 +317,7 @@</span><br><span> {</span><br><span> int i;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /*</span><br><span style="color: hsl(0, 100%, 40%);">- * Don't block Content-Type or Max-Forwards headers because the</span><br><span style="color: hsl(0, 100%, 40%);">- * user can override them.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Don't block the Max-Forwards header because the user can override it */</span><br><span> static const char *hdr[] = {</span><br><span> "To",</span><br><span> "From",</span><br><span>@@ -331,6 +328,7 @@</span><br><span> "CSeq",</span><br><span> "Allow",</span><br><span> "Content-Length",</span><br><span style="color: hsl(120, 100%, 40%);">+ "Content-Type",</span><br><span> "Request-URI",</span><br><span> };</span><br><span> </span><br><span>@@ -636,11 +634,40 @@</span><br><span> return mdata;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void update_content_type(pjsip_tx_data *tdata, struct ast_msg *msg, struct ast_sip_body *body)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t CONTENT_TYPE = { "Content-Type", sizeof("Content-Type") - 1 };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *content_type = ast_msg_get_var(msg, pj_strbuf(&CONTENT_TYPE));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (content_type) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_str_t type, subtype;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_ctype_hdr *parsed;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Let pjsip do the parsing for us */</span><br><span style="color: hsl(120, 100%, 40%);">+ parsed = pjsip_parse_hdr(tdata->pool, &CONTENT_TYPE,</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_strdupa(content_type), strlen(content_type),</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!parsed) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Failed to parse '%s' as a content type. Using text/plain\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ content_type);</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</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%);">+ /* We need to turn type and subtype into zero-terminated strings */</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup_with_null(tdata->pool, &type, &parsed->media.type);</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup_with_null(tdata->pool, &subtype, &parsed->media.subtype);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ body->type = pj_strbuf(&type);</span><br><span style="color: hsl(120, 100%, 40%);">+ body->subtype = pj_strbuf(&subtype);</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%);">+</span><br><span> static int msg_send(void *data)</span><br><span> {</span><br><span> RAII_VAR(struct msg_data *, mdata, data, ao2_cleanup);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- const struct ast_sip_body body = {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_body body = {</span><br><span> .type = "text",</span><br><span> .subtype = "plain",</span><br><span> .body_text = ast_msg_get_body(mdata->msg)</span><br><span>@@ -665,6 +692,7 @@</span><br><span> </span><br><span> update_to(tdata, mdata->to);</span><br><span> update_from(tdata, mdata->from);</span><br><span style="color: hsl(120, 100%, 40%);">+ update_content_type(tdata, mdata->msg, &body);</span><br><span> </span><br><span> if (ast_sip_add_body(tdata, &body)) {</span><br><span> pjsip_tx_data_dec_ref(tdata);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13679">change 13679</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/+/13679"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I6549e90932016349bc72b0f053432dc25286f4fb </div>
<div style="display:none"> Gerrit-Change-Number: 13679 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>