From: Joshua Colp Date: Mon, 3 Feb 2020 12:11:23 +0000 (-0600) Subject: Merge "res_pjsip_messaging: Allow Content-Type to be overridden" into 13 X-Git-Tag: 13.32.0-rc1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08ba741a8eb2c6ff23573cb4965bf9db0385425a;p=thirdparty%2Fasterisk.git Merge "res_pjsip_messaging: Allow Content-Type to be overridden" into 13 --- 08ba741a8eb2c6ff23573cb4965bf9db0385425a diff --cc res/res_pjsip_messaging.c index 81de9f8e6c,da08b44df9..ae28881645 --- a/res/res_pjsip_messaging.c +++ b/res/res_pjsip_messaging.c @@@ -636,11 -634,40 +634,40 @@@ static struct msg_data *msg_data_create return mdata; } + static void update_content_type(pjsip_tx_data *tdata, struct ast_msg *msg, struct ast_sip_body *body) + { + static const pj_str_t CONTENT_TYPE = { "Content-Type", sizeof("Content-Type") - 1 }; + + const char *content_type = ast_msg_get_var(msg, pj_strbuf(&CONTENT_TYPE)); + if (content_type) { + pj_str_t type, subtype; + pjsip_ctype_hdr *parsed; + + /* Let pjsip do the parsing for us */ + parsed = pjsip_parse_hdr(tdata->pool, &CONTENT_TYPE, + ast_strdupa(content_type), strlen(content_type), + NULL); + + if (!parsed) { + ast_log(LOG_WARNING, "Failed to parse '%s' as a content type. Using text/plain\n", + content_type); + return; + } + + /* We need to turn type and subtype into zero-terminated strings */ + pj_strdup_with_null(tdata->pool, &type, &parsed->media.type); + pj_strdup_with_null(tdata->pool, &subtype, &parsed->media.subtype); + + body->type = pj_strbuf(&type); + body->subtype = pj_strbuf(&subtype); + } + } + static int msg_send(void *data) { - RAII_VAR(struct msg_data *, mdata, data, ao2_cleanup); + struct msg_data *mdata = data; /* The caller holds a reference */ - const struct ast_sip_body body = { + struct ast_sip_body body = { .type = "text", .subtype = "plain", .body_text = ast_msg_get_body(mdata->msg)