Skip to content

Instantly share code, notes, and snippets.

@saghul
Created September 1, 2025 15:27
Show Gist options
  • Save saghul/3043e6499a745c106cdc094b1ad76572 to your computer and use it in GitHub Desktop.
Save saghul/3043e6499a745c106cdc094b1ad76572 to your computer and use it in GitHub Desktop.

Revisions

  1. saghul created this gist Sep 1, 2025.
    35 changes: 35 additions & 0 deletions 0040-content-type-hack.diff
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    diff --git a/pjsip/src/pjsip/sip_parser.c b/pjsip/src/pjsip/sip_parser.c
    index 5dc10b47e..e1ba192c5 100644
    --- a/pjsip/src/pjsip/sip_parser.c
    +++ b/pjsip/src/pjsip/sip_parser.c
    @@ -1132,21 +1132,26 @@ parse_headers:
    /* If we have Content-Type header, treat the rest of the message
    * as body.
    */
    - if (ctype_hdr && scanner->curptr!=scanner->end) {
    + if (scanner->curptr!=scanner->end) {
    /* New: if Content-Type indicates that this is a multipart
    * message body, parse it.
    */
    const pj_str_t STR_MULTIPART = { "multipart", 9 };
    pjsip_msg_body *body;

    - if (pj_stricmp(&ctype_hdr->media.type, &STR_MULTIPART)==0) {
    + if (ctype_hdr && pj_stricmp(&ctype_hdr->media.type, &STR_MULTIPART)==0) {
    body = pjsip_multipart_parse(pool, scanner->curptr,
    scanner->end - scanner->curptr,
    &ctype_hdr->media, 0);
    } else {
    body = PJ_POOL_ALLOC_T(pool, pjsip_msg_body);
    - pjsip_media_type_cp(pool, &body->content_type,
    - &ctype_hdr->media);
    + if (ctype_hdr) {
    + pjsip_media_type_cp(pool, &body->content_type,
    + &ctype_hdr->media);
    + } else {
    + // HACK: Assume messages with a body but no Content-Type header contain an SDP
    + pjsip_media_type_init2(&body->content_type, "application", "sdp");
    + }

    body->data = scanner->curptr;
    body->len = (unsigned)(scanner->end - scanner->curptr);