diff -Nur asterisk-16.6.2-old/res/res_pjsip_messaging.c asterisk-16.6.2/res/res_pjsip_messaging.c --- asterisk-16.6.2-old/res/res_pjsip_messaging.c 2020-01-18 17:02:19.931696415 +0100 +++ asterisk-16.6.2/res/res_pjsip_messaging.c 2020-01-25 21:39:58.683188302 +0100 @@ -584,6 +584,8 @@ struct ast_msg *msg; char *to; char *from; + char *type; + char *subtype; }; static void msg_data_destroy(void *obj) @@ -592,12 +594,18 @@ ast_free(mdata->from); ast_free(mdata->to); + ast_free(mdata->type); + ast_free(mdata->subtype); ast_msg_destroy(mdata->msg); } static struct msg_data *msg_data_create(const struct ast_msg *msg, const char *to, const char *from) { + const char *rawcontenttype; + char *contenttype; + char *type; + int typepart; char *uri_params; struct msg_data *mdata = ao2_alloc(sizeof(*mdata), msg_data_destroy); @@ -611,18 +619,48 @@ /* To starts with 'pjsip:' which needs to be removed. */ if (!(to = strchr(to, ':'))) { ao2_ref(mdata, -1); + ast_log(LOG_DEBUG, "Wrong to\n"); return NULL; } ++to;/* Now skip the ':' */ /* Make sure we start with sip: */ + ast_log(LOG_DEBUG, "Handling pjsip: to sip: in to\n"); mdata->to = ast_begins_with(to, "sip:") ? ast_strdup(to) : ast_strdup(to - 4); + ast_log(LOG_DEBUG, "Handling from\n"); mdata->from = ast_strdup(from); if (!mdata->to || !mdata->from) { ao2_ref(mdata, -1); return NULL; } + ast_log(LOG_DEBUG, "Reading Content-Type\n"); + rawcontenttype = ast_msg_get_var(mdata->msg, "Content-Type"); + ast_log(LOG_DEBUG, "RAW content type: %s\n", rawcontenttype); + + if (rawcontenttype != NULL) { + contenttype = ast_strdup(rawcontenttype); + ast_log(LOG_DEBUG, "Copied content type: %s\n", contenttype); + + ast_log(LOG_DEBUG, "Defining content-type to %s\n", contenttype); + typepart = 0; + while (type = strsep(&contenttype, "/") && typepart < 2) { + if (typepart == 0) { + mdata->type = ast_strdup(type); + } + else { + mdata->subtype = ast_strdup(type); + } + typepart++; + } + ast_log(LOG_DEBUG, "Content-Type in mdata set to %s/%s\n", mdata->type, mdata->subtype); + ast_free(contenttype); + } else { + ast_log(LOG_DEBUG, "Default content-type to text/plain because no content-type was defined\n"); + mdata->type = "text"; + mdata->subtype = "plain"; + } + /* * Sometimes from URI can contain URI parameters, so remove them. * @@ -640,8 +678,8 @@ RAII_VAR(struct msg_data *, mdata, data, ao2_cleanup); const struct ast_sip_body body = { - .type = "text", - .subtype = "plain", + .type = mdata->type, + .subtype = mdata->subtype, .body_text = ast_msg_get_body(mdata->msg) }; @@ -665,6 +703,8 @@ update_to(tdata, mdata->to); update_from(tdata, mdata->from); + ast_log(LOG_DEBUG, "Set Content-Type of body to %s/%s\n", body.type, body.subtype); + if (ast_sip_add_body(tdata, &body)) { pjsip_tx_data_dec_ref(tdata); ast_log(LOG_ERROR, "PJSIP MESSAGE - Could not add body to request\n");