--- res/res_pjsip_messaging.c 2016-05-09 16:04:34.000000000 +0300 +++ res/res_pjsip_messaging.c 2016-06-01 17:01:58.000000000 +0300 @@ -285,8 +291,9 @@ * \param msg The msg structure to copy headers from * \param tdata The SIP transmission data */ -static enum pjsip_status_code vars_to_headers(const struct ast_msg *msg, pjsip_tx_data *tdata) +static enum pjsip_status_code vars_to_headers(const struct ast_msg *msg, pjsip_tx_data *tdata, struct ast_sip_body *body) { + char* p; const char *name; const char *value; int max_forwards; @@ -295,7 +302,13 @@ for (iter = ast_msg_var_iterator_init(msg); ast_msg_var_iterator_next(msg, iter, &name, &value); ast_msg_var_unref_current(iter)) { - if (!strcasecmp(name, "Max-Forwards")) { + if (!strcasecmp(name, "Content-Type")) { + body->type = value; + if ((p = strchr(body->type, '/'))) { + *p++ = '\0'; + body->subtype = p; + } + } else if (!strcasecmp(name, "Max-Forwards")) { /* Decrement Max-Forwards for SIP loop prevention. */ if (sscanf(value, "%30d", &max_forwards) != 1 || --max_forwards == 0) { ast_msg_var_iterator_destroy(iter); @@ -546,11 +560,9 @@ { RAII_VAR(struct msg_data *, mdata, data, ao2_cleanup); - const struct ast_sip_body body = { - .type = "text", - .subtype = "plain", - .body_text = ast_msg_get_body(mdata->msg) - }; + struct ast_sip_body body; + body.type = "text"; + body.subtype = "plain"; pjsip_tx_data *tdata; RAII_VAR(char *, uri, NULL, ast_free); @@ -571,14 +583,15 @@ update_to(tdata, mdata->to); update_from(tdata, mdata->from); + vars_to_headers(mdata->msg, tdata, &body); + + body.body_text = ast_msg_get_body(mdata->msg); 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"); return -1; } - vars_to_headers(mdata->msg, tdata); - ast_debug(1, "Sending message to '%s' (via endpoint %s) from '%s'\n", mdata->to, ast_sorcery_object_get_id(endpoint), mdata->from);