mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 19:52:48 +00:00
res_pjsip_messaging: Allow Content-Type to be overridden
ASTERISK-26082 #close Reported by: Alex Change-Id: I6549e90932016349bc72b0f053432dc25286f4fb
This commit is contained in:
@@ -316,10 +316,7 @@ static int is_msg_var_blocked(const char *name)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/* Don't block the Max-Forwards header because the user can override it */
|
||||||
* Don't block Content-Type or Max-Forwards headers because the
|
|
||||||
* user can override them.
|
|
||||||
*/
|
|
||||||
static const char *hdr[] = {
|
static const char *hdr[] = {
|
||||||
"To",
|
"To",
|
||||||
"From",
|
"From",
|
||||||
@@ -330,6 +327,7 @@ static int is_msg_var_blocked(const char *name)
|
|||||||
"CSeq",
|
"CSeq",
|
||||||
"Allow",
|
"Allow",
|
||||||
"Content-Length",
|
"Content-Length",
|
||||||
|
"Content-Type",
|
||||||
"Request-URI",
|
"Request-URI",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -635,11 +633,40 @@ static struct msg_data *msg_data_create(const struct ast_msg *msg, const char *t
|
|||||||
return mdata;
|
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)
|
static int msg_send(void *data)
|
||||||
{
|
{
|
||||||
RAII_VAR(struct msg_data *, mdata, data, ao2_cleanup);
|
RAII_VAR(struct msg_data *, mdata, data, ao2_cleanup);
|
||||||
|
|
||||||
const struct ast_sip_body body = {
|
struct ast_sip_body body = {
|
||||||
.type = "text",
|
.type = "text",
|
||||||
.subtype = "plain",
|
.subtype = "plain",
|
||||||
.body_text = ast_msg_get_body(mdata->msg)
|
.body_text = ast_msg_get_body(mdata->msg)
|
||||||
@@ -664,6 +691,7 @@ static int msg_send(void *data)
|
|||||||
|
|
||||||
update_to(tdata, mdata->to);
|
update_to(tdata, mdata->to);
|
||||||
update_from(tdata, mdata->from);
|
update_from(tdata, mdata->from);
|
||||||
|
update_content_type(tdata, mdata->msg, &body);
|
||||||
|
|
||||||
if (ast_sip_add_body(tdata, &body)) {
|
if (ast_sip_add_body(tdata, &body)) {
|
||||||
pjsip_tx_data_dec_ref(tdata);
|
pjsip_tx_data_dec_ref(tdata);
|
||||||
|
Reference in New Issue
Block a user