[Asterisk-code-review] bundled_pjproject: Add more support for multipart bodies (asterisk[16])

George Joseph asteriskteam at digium.com
Tue Dec 14 11:44:00 CST 2021


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17657 )


Change subject: bundled_pjproject:  Add more support for multipart bodies
......................................................................

bundled_pjproject:  Add more support for multipart bodies

Adding upstream patch for pull request...
https://github.com/pjsip/pjproject/pull/2920
---------------------------------------------------------------

sip_inv:  Additional multipart support (#2919)

sip_inv.c:inv_check_sdp_in_incoming_msg() deals with multipart
message bodies in rdata correctly. In the case where early media is
involved though, the existing sdp has to be retrieved from the last
tdata sent in this transaction. This, however, always assumes that
the sdp sent is in a non-multipart body. While there's a function
to retrieve the sdp from multipart and non-multpart rdata bodies,
no similar function for tdata exists.  So...

* The existing pjsip_rdata_get_sdp_info2 was refactored to
  find the sdp in any body, multipart or non-multipart, and
  from either an rdata or tdata.  The new function is
  pjsip_get_sdp_info.  This new function detects whether the
  pjsip_msg->body->data is the text representation of the sdp
  from an rdata or an existing pjmedia_sdp_session object
  from a tdata, or whether pjsip_msg->body is a multipart
  body containing either of the two sdp formats.

* The exsting pjsip_rdata_get_sdp_info and pjsip_rdata_get_sdp_info2
  functions are now wrappers that get the body and Content-Type
  header from the rdata and call pjsip_get_sdp_info.

* Two new wrappers named pjsip_tdata_get_sdp_info and
  pjsip_tdata_get_sdp_info2 have been created that get the body
  from the tdata and call pjsip_get_sdp_info.

* For testing purposes, a new field "create_multipart" was added
  to the pjsip_inv_session structure to allow forcing all bodies
  created to be multipart.

* The internal create_sdp_body function now takes an option to
  indicate that a multipart body should be created.

* inv_offer_answer_test.c was updated to use the create_multipart
  field and additional tests were added.

ASTERISK-29804

Change-Id: I483c7c3d413280c9e247a96ad581278347f9c71b
---
A third-party/pjproject/patches/0130-sip_inv-Additional-multipart-support-2919.patch
1 file changed, 692 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/17657/1

diff --git a/third-party/pjproject/patches/0130-sip_inv-Additional-multipart-support-2919.patch b/third-party/pjproject/patches/0130-sip_inv-Additional-multipart-support-2919.patch
new file mode 100644
index 0000000..615aba6
--- /dev/null
+++ b/third-party/pjproject/patches/0130-sip_inv-Additional-multipart-support-2919.patch
@@ -0,0 +1,692 @@
+From eb3cf4921caf095f82411be93223fe999ff70486 Mon Sep 17 00:00:00 2001
+From: George Joseph <gjoseph at sangoma.com>
+Date: Mon, 13 Dec 2021 08:24:35 -0700
+Subject: [PATCH] sip_inv:  Additional multipart support (#2919)
+
+sip_inv.c:inv_check_sdp_in_incoming_msg() deals with multipart
+message bodies in rdata correctly. In the case where early media is
+involved though, the existing sdp has to be retrieved from the last
+tdata sent in this transaction. This, however, always assumes that
+the sdp sent is in a non-multipart body. While there's a function
+to retrieve the sdp from multipart and non-multpart rdata bodies,
+no similar function for tdata exists.  So...
+
+* The existing pjsip_rdata_get_sdp_info2 was refactored to
+  find the sdp in any body, multipart or non-multipart, and
+  from either an rdata or tdata.  The new function is
+  pjsip_get_sdp_info.  This new function detects whether the
+  pjsip_msg->body->data is the text representation of the sdp
+  from an rdata or an existing pjmedia_sdp_session object
+  from a tdata, or whether pjsip_msg->body is a multipart
+  body containing either of the two sdp formats.
+
+* The exsting pjsip_rdata_get_sdp_info and pjsip_rdata_get_sdp_info2
+  functions are now wrappers that get the body and Content-Type
+  header from the rdata and call pjsip_get_sdp_info.
+
+* Two new wrappers named pjsip_tdata_get_sdp_info and
+  pjsip_tdata_get_sdp_info2 have been created that get the body
+  from the tdata and call pjsip_get_sdp_info.
+
+* For testing purposes, a new field "create_multipart" was added
+  to the pjsip_inv_session structure to allow forcing all bodies
+  created to be multipart.
+
+* The internal create_sdp_body function now takes an option to
+  indicate that a multipart body should be created.
+
+* inv_offer_answer_test.c was updated to use the create_multipart
+  field and additional tests were added.
+
+Fixes #2919
+---
+ pjsip/include/pjsip-ua/sip_inv.h       | 112 ++++++++++-
+ pjsip/src/pjsip-ua/sip_inv.c           | 268 ++++++++++++++++++++-----
+ pjsip/src/test/inv_offer_answer_test.c |  48 ++++-
+ 3 files changed, 365 insertions(+), 63 deletions(-)
+
+diff --git a/pjsip/include/pjsip-ua/sip_inv.h b/pjsip/include/pjsip-ua/sip_inv.h
+index 14f2d23fa..d64a13eb8 100644
+--- a/pjsip/include/pjsip-ua/sip_inv.h
++++ b/pjsip/include/pjsip-ua/sip_inv.h
+@@ -447,15 +447,19 @@ struct pjsip_inv_session
+     pj_atomic_t		*ref_cnt;		    /**< Reference counter. */
+     pj_bool_t            updated_sdp_answer;        /**< SDP answer just been
+ 							 updated?	    */
++    pj_bool_t            create_multipart;          /**< Create multipart
++                                                         bodies.  Should be
++                                                         used for testing
++                                                         only.              */
+ };
+ 
+ 
+ /**
+- * This structure represents SDP information in a pjsip_rx_data. Application
+- * retrieve this information by calling #pjsip_rdata_get_sdp_info(). This
++ * This structure represents SDP information in a pjsip_(rx|tx)_data. Application
++ * retrieve this information by calling #pjsip_get_sdp_info(). This
+  * mechanism supports multipart message body.
+  */
+-typedef struct pjsip_rdata_sdp_info
++typedef struct pjsip_sdp_info
+ {
+     /**
+      * Pointer and length of the text body in the incoming message. If
+@@ -475,7 +479,15 @@ typedef struct pjsip_rdata_sdp_info
+      */
+     pjmedia_sdp_session *sdp;
+ 
+-} pjsip_rdata_sdp_info;
++} pjsip_sdp_info;
++
++/**
++ * For backwards compatibility and completemess,
++ * pjsip_rdata_sdp_info and pjsip_tdata_sdp_info
++ * are typedef'd to pjsip_sdp_info.
++ */
++typedef pjsip_sdp_info pjsip_rdata_sdp_info;
++typedef pjsip_sdp_info pjsip_tdata_sdp_info;
+ 
+ 
+ /**
+@@ -1045,6 +1057,44 @@ PJ_DECL(pj_status_t) pjsip_create_sdp_body(pj_pool_t *pool,
+ 					   pjmedia_sdp_session *sdp,
+ 					   pjsip_msg_body **p_body);
+ 
++/**
++ * This is a utility function to create a multipart body with the
++ * SIP body as the first part.
++ *
++ * @param pool		Pool to allocate memory.
++ * @param sdp		SDP session to be put in the SIP message body.
++ * @param p_body	Pointer to receive SIP message body containing
++ *			the SDP session.
++ *
++ * @return		PJ_SUCCESS on success.
++ */
++PJ_DEF(pj_status_t) pjsip_create_multipart_sdp_body( pj_pool_t *pool,
++                                           pjmedia_sdp_session *sdp,
++                                           pjsip_msg_body **p_body);
++
++/**
++ * Retrieve SDP information from a message body. Application should
++ * prefer to use this function rather than parsing the SDP manually since
++ * this function supports multipart message body.
++ *
++ * This function will only parse the SDP once, the first time it is called
++ * on the same message. Subsequent call on the same message will just pick
++ * up the already parsed SDP from the message.
++ *
++ * @param pool               Pool to allocate memory.
++ * @param body               The message body.
++ * @param msg_media_type     From the rdata or tdata Content-Type header, if available.
++ *                           If NULL, the content_type from the body will be used.
++ * @param search_media_type  The media type to search for.
++ *                           If NULL, "application/sdp" will be used.
++ *
++ * @return                   The SDP info.
++ */
++PJ_DEF(pjsip_sdp_info*) pjsip_get_sdp_info(pj_pool_t *pool,
++					   pjsip_msg_body *body,
++					   pjsip_media_type *msg_media_type,
++					   const pjsip_media_type *search_media_type);
++
+ /**
+  * Retrieve SDP information from an incoming message. Application should
+  * prefer to use this function rather than parsing the SDP manually since
+@@ -1061,6 +1111,60 @@ PJ_DECL(pj_status_t) pjsip_create_sdp_body(pj_pool_t *pool,
+ PJ_DECL(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata);
+ 
+ 
++/**
++ * Retrieve SDP information from an incoming message. Application should
++ * prefer to use this function rather than parsing the SDP manually since
++ * this function supports multipart message body.
++ *
++ * This function will only parse the SDP once, the first time it is called
++ * on the same message. Subsequent call on the same message will just pick
++ * up the already parsed SDP from the message.
++ *
++ * @param rdata               The incoming message.
++ * @param search_media_type   The SDP media type to search for.
++ *                            If NULL, "application/sdp" will be used.
++ *
++ * @return                    The SDP info.
++ */
++PJ_DECL(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info2(
++					    pjsip_rx_data *rdata,
++					    const pjsip_media_type *search_media_type);
++
++/**
++ * Retrieve SDP information from an outgoing message. Application should
++ * prefer to use this function rather than parsing the SDP manually since
++ * this function supports multipart message body.
++ *
++ * This function will only parse the SDP once, the first time it is called
++ * on the same message. Subsequent call on the same message will just pick
++ * up the already parsed SDP from the message.
++ *
++ * @param tdata    The outgoing message.
++ *
++ * @return         The SDP info.
++ */
++PJ_DECL(pjsip_tdata_sdp_info*) pjsip_tdata_get_sdp_info(pjsip_tx_data *tdata);
++
++/**
++ * Retrieve SDP information from an outgoing message. Application should
++ * prefer to use this function rather than parsing the SDP manually since
++ * this function supports multipart message body.
++ *
++ * This function will only parse the SDP once, the first time it is called
++ * on the same message. Subsequent call on the same message will just pick
++ * up the already parsed SDP from the message.
++ *
++ * @param tdata               The outgoing message.
++ * @param search_media_type   The SDP media type to search for.
++ *                            If NULL, "application/sdp" will be used.
++ *
++ * @return                    The SDP info.
++ */
++PJ_DECL(pjsip_tdata_sdp_info*) pjsip_tdata_get_sdp_info2(
++					    pjsip_tx_data *tdata,
++					    const pjsip_media_type *search_media_type);
++
++
+ PJ_END_DECL
+ 
+ /**
+diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c
+index ca225015b..2e9556065 100644
+--- a/pjsip/src/pjsip-ua/sip_inv.c
++++ b/pjsip/src/pjsip-ua/sip_inv.c
+@@ -105,7 +105,8 @@ static pj_status_t inv_check_sdp_in_incoming_msg( pjsip_inv_session *inv,
+ 						  pjsip_rx_data *rdata);
+ static pj_status_t inv_negotiate_sdp( pjsip_inv_session *inv );
+ static pjsip_msg_body *create_sdp_body(pj_pool_t *pool,
+-				       const pjmedia_sdp_session *c_sdp);
++				       const pjmedia_sdp_session *c_sdp,
++				       pj_bool_t multipart);
+ static pj_status_t process_answer( pjsip_inv_session *inv,
+ 				   int st_code,
+ 				   pjsip_tx_data *tdata,
+@@ -118,6 +119,8 @@ static pj_status_t handle_timer_response(pjsip_inv_session *inv,
+ static pj_bool_t inv_check_secure_dlg(pjsip_inv_session *inv,
+ 				      pjsip_event *e);
+ 
++static int print_sdp(pjsip_msg_body *body, char *buf, pj_size_t len);
++
+ static void (*inv_state_handler[])( pjsip_inv_session *inv, pjsip_event *e) = 
+ {
+     &inv_on_state_null,
+@@ -946,66 +949,170 @@ PJ_DEF(pj_status_t) pjsip_inv_create_uac( pjsip_dialog *dlg,
+     return PJ_SUCCESS;
+ }
+ 
+-PJ_DEF(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata)
++PJ_DEF(pjsip_sdp_info*) pjsip_get_sdp_info(pj_pool_t *pool,
++                                           pjsip_msg_body *body,
++                                           pjsip_media_type *msg_media_type,
++                                           const pjsip_media_type *search_media_type)
+ {
+-    pjsip_rdata_sdp_info *sdp_info;
+-    pjsip_msg_body *body = rdata->msg_info.msg->body;
+-    pjsip_ctype_hdr *ctype_hdr = rdata->msg_info.ctype;
+-    pjsip_media_type app_sdp;
++    pjsip_sdp_info *sdp_info;
++    pjsip_media_type search_type;
++    pjsip_media_type multipart_mixed;
++    pjsip_media_type multipart_alternative;
++    pjsip_media_type *msg_type;
++    pj_status_t status;
+ 
+-    sdp_info = (pjsip_rdata_sdp_info*)
+-	       rdata->endpt_info.mod_data[mod_inv.mod.id];
+-    if (sdp_info)
+-	return sdp_info;
++    sdp_info = PJ_POOL_ZALLOC_T(pool,
++                                pjsip_sdp_info);
+ 
+-    sdp_info = PJ_POOL_ZALLOC_T(rdata->tp_info.pool,
+-				pjsip_rdata_sdp_info);
+     PJ_ASSERT_RETURN(mod_inv.mod.id >= 0, sdp_info);
+-    rdata->endpt_info.mod_data[mod_inv.mod.id] = sdp_info;
+ 
+-    pjsip_media_type_init2(&app_sdp, "application", "sdp");
++    if (!body) {
++        return sdp_info;
++    }
+ 
+-    if (body && ctype_hdr &&
+-	pj_stricmp(&ctype_hdr->media.type, &app_sdp.type)==0 &&
+-	pj_stricmp(&ctype_hdr->media.subtype, &app_sdp.subtype)==0)
++    if (msg_media_type) {
++	msg_type = msg_media_type;
++    } else {
++	if (body->content_type.type.slen == 0) {
++	    return sdp_info;
++	}
++	msg_type = &body->content_type;
++    }
++
++    if (!search_media_type) {
++        pjsip_media_type_init2(&search_type, "application", "sdp");
++    } else {
++        pj_memcpy(&search_type, search_media_type, sizeof(search_type));
++    }
++
++    pjsip_media_type_init2(&multipart_mixed, "multipart", "mixed");
++    pjsip_media_type_init2(&multipart_alternative, "multipart", "alternative");
++
++    if (pjsip_media_type_cmp(msg_type, &search_type, PJ_FALSE) == 0)
+     {
+-	sdp_info->body.ptr = (char*)body->data;
+-	sdp_info->body.slen = body->len;
+-    } else if  (body && ctype_hdr &&
+-	    	pj_stricmp2(&ctype_hdr->media.type, "multipart")==0 &&
+-	    	(pj_stricmp2(&ctype_hdr->media.subtype, "mixed")==0 ||
+-	    	 pj_stricmp2(&ctype_hdr->media.subtype, "alternative")==0))
++	/*
++	 * If the print_body function is print_sdp, we know that
++	 * body->data is a pjmedia_sdp_session object and came from
++	 * a tx_data.  If not, it's the text representation of the
++	 * sdp from an rx_data.
++	 */
++        if (body->print_body == print_sdp) {
++            sdp_info->sdp = body->data;
++        } else {
++            sdp_info->body.ptr = (char*)body->data;
++            sdp_info->body.slen = body->len;
++        }
++    } else if (pjsip_media_type_cmp(&multipart_mixed, msg_type, PJ_FALSE) == 0 ||
++	pjsip_media_type_cmp(&multipart_alternative, msg_type, PJ_FALSE) == 0)
+     {
+-	pjsip_multipart_part *part;
++        pjsip_multipart_part *part;
++        part = pjsip_multipart_find_part(body, &search_type, NULL);
++        if (part) {
++            if (part->body->print_body == print_sdp) {
++                sdp_info->sdp = part->body->data;
++            } else {
++                sdp_info->body.ptr = (char*)part->body->data;
++                sdp_info->body.slen = part->body->len;
++            }
++        }
++    }
+ 
+-	part = pjsip_multipart_find_part(body, &app_sdp, NULL);
+-	if (part) {
+-	    sdp_info->body.ptr = (char*)part->body->data;
+-	    sdp_info->body.slen = part->body->len;
+-	}
++    /*
++     * If the body was already a pjmedia_sdp_session, we can just
++     * return it.  If not and there wasn't a text representation
++     * of the sdp either, we can also just return.
++     */
++    if (sdp_info->sdp || !sdp_info->body.ptr) {
++	return sdp_info;
+     }
+ 
+-    if (sdp_info->body.ptr) {
+-	pj_status_t status;
+-	status = pjmedia_sdp_parse(rdata->tp_info.pool,
+-				   sdp_info->body.ptr,
+-				   sdp_info->body.slen,
+-				   &sdp_info->sdp);
+-	if (status == PJ_SUCCESS)
+-	    status = pjmedia_sdp_validate2(sdp_info->sdp, PJ_FALSE);
++    /*
++     * If the body was the text representation of teh SDP, we need
++     * to parse it to create a pjmedia_sdp_session object.
++     */
++    status = pjmedia_sdp_parse(pool,
++				sdp_info->body.ptr,
++				sdp_info->body.slen,
++				&sdp_info->sdp);
++    if (status == PJ_SUCCESS)
++	status = pjmedia_sdp_validate2(sdp_info->sdp, PJ_FALSE);
+ 
+-	if (status != PJ_SUCCESS) {
+-	    sdp_info->sdp = NULL;
+-	    PJ_PERROR(1,(THIS_FILE, status,
+-			 "Error parsing/validating SDP body"));
+-	}
++    if (status != PJ_SUCCESS) {
++	sdp_info->sdp = NULL;
++	PJ_PERROR(1, (THIS_FILE, status,
++	    "Error parsing/validating SDP body"));
++    }
+ 
+-	sdp_info->sdp_err = status;
++    sdp_info->sdp_err = status;
++
++    return sdp_info;
++}
++
++PJ_DEF(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info2(
++                                            pjsip_rx_data *rdata,
++                                            const pjsip_media_type *search_media_type)
++{
++    pjsip_media_type *msg_media_type = NULL;
++    pjsip_rdata_sdp_info *sdp_info;
++
++    if (rdata->endpt_info.mod_data[mod_inv.mod.id]) {
++	return (pjsip_rdata_sdp_info *)rdata->endpt_info.mod_data[mod_inv.mod.id];
++    }
++
++    /*
++     * rdata should have a Content-Type header at this point but we'll
++     * make sure.
++     */
++    if (rdata->msg_info.ctype) {
++	msg_media_type = &rdata->msg_info.ctype->media;
+     }
++    sdp_info = pjsip_get_sdp_info(rdata->tp_info.pool,
++				   rdata->msg_info.msg->body,
++				   msg_media_type,
++				   search_media_type);
++    rdata->endpt_info.mod_data[mod_inv.mod.id] = sdp_info;
+ 
+     return sdp_info;
+ }
+ 
++PJ_DEF(pjsip_rdata_sdp_info*) pjsip_rdata_get_sdp_info(pjsip_rx_data *rdata)
++{
++    return pjsip_rdata_get_sdp_info2(rdata, NULL);
++}
++
++PJ_DEF(pjsip_tdata_sdp_info*) pjsip_tdata_get_sdp_info2(
++                                            pjsip_tx_data *tdata,
++                                            const pjsip_media_type *search_media_type)
++{
++    pjsip_ctype_hdr *ctype_hdr = NULL;
++    pjsip_media_type *msg_media_type = NULL;
++    pjsip_tdata_sdp_info *sdp_info;
++
++    if (tdata->mod_data[mod_inv.mod.id]) {
++	return (pjsip_tdata_sdp_info *)tdata->mod_data[mod_inv.mod.id];
++    }
++    /*
++     * tdata won't usually have a Content-Type header at this point
++     * but we'll check just the same,
++     */
++    ctype_hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTENT_TYPE, NULL);
++    if (ctype_hdr) {
++	msg_media_type = &ctype_hdr->media;
++    }
++
++    sdp_info = pjsip_get_sdp_info(tdata->pool,
++				   tdata->msg->body,
++				   msg_media_type,
++				   search_media_type);
++    tdata->mod_data[mod_inv.mod.id] = sdp_info;
++
++    return sdp_info;
++}
++
++PJ_DEF(pjsip_tdata_sdp_info*) pjsip_tdata_get_sdp_info(pjsip_tx_data *tdata)
++{
++    return pjsip_tdata_get_sdp_info2(tdata, NULL);
++}
+ 
+ /*
+  * Verify incoming INVITE request.
+@@ -1730,15 +1837,64 @@ PJ_DEF(pj_status_t) pjsip_create_sdp_body( pj_pool_t *pool,
+     return PJ_SUCCESS;
+ }
+ 
++static pjsip_multipart_part* create_sdp_part(pj_pool_t *pool, pjmedia_sdp_session *sdp)
++{
++    pjsip_multipart_part *sdp_part;
++    pjsip_media_type media_type;
++
++    pjsip_media_type_init2(&media_type, "application", "sdp");
++
++    sdp_part = pjsip_multipart_create_part(pool);
++    PJ_ASSERT_RETURN(sdp_part != NULL, NULL);
++
++    sdp_part->body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body);
++    PJ_ASSERT_RETURN(sdp_part->body != NULL, NULL);
++
++    pjsip_media_type_cp(pool, &sdp_part->body->content_type, &media_type);
++
++    sdp_part->body->data = sdp;
++    sdp_part->body->clone_data = clone_sdp;
++    sdp_part->body->print_body = print_sdp;
++
++    return sdp_part;
++}
++
++PJ_DEF(pj_status_t) pjsip_create_multipart_sdp_body(pj_pool_t *pool,
++						     pjmedia_sdp_session *sdp,
++						     pjsip_msg_body **p_body)
++{
++    pjsip_media_type media_type;
++    pjsip_msg_body *multipart;
++    pjsip_multipart_part *sdp_part;
++
++    pjsip_media_type_init2(&media_type, "multipart", "mixed");
++    multipart = pjsip_multipart_create(pool, &media_type, NULL);
++    PJ_ASSERT_RETURN(multipart != NULL, PJ_ENOMEM);
++
++    sdp_part = create_sdp_part(pool, sdp);
++    PJ_ASSERT_RETURN(sdp_part != NULL, PJ_ENOMEM);
++    pjsip_multipart_add_part(pool, multipart, sdp_part);
++    *p_body = multipart;
++
++    return PJ_SUCCESS;
++}
++
+ static pjsip_msg_body *create_sdp_body(pj_pool_t *pool,
+-				       const pjmedia_sdp_session *c_sdp)
++				       const pjmedia_sdp_session *c_sdp,
++				       pj_bool_t multipart)
+ {
+     pjsip_msg_body *body;
+     pj_status_t status;
+ 
+-    status = pjsip_create_sdp_body(pool, 
+-				   pjmedia_sdp_session_clone(pool, c_sdp),
+-				   &body);
++    if (multipart) {
++	    status = pjsip_create_multipart_sdp_body(pool,
++					   pjmedia_sdp_session_clone(pool, c_sdp),
++					   &body);
++    } else {
++	    status = pjsip_create_sdp_body(pool,
++					   pjmedia_sdp_session_clone(pool, c_sdp),
++					   &body);
++    }
+ 
+     if (status != PJ_SUCCESS)
+ 	return NULL;
+@@ -1877,7 +2033,7 @@ PJ_DEF(pj_status_t) pjsip_inv_invite( pjsip_inv_session *inv,
+ 	    goto on_return;
+ 	}
+ 
+-	tdata->msg->body = create_sdp_body(tdata->pool, offer);
++	tdata->msg->body = create_sdp_body(tdata->pool, offer, inv->create_multipart);
+     }
+ 
+     /* Add Allow header. */
+@@ -2059,6 +2215,7 @@ static pj_status_t inv_check_sdp_in_incoming_msg( pjsip_inv_session *inv,
+ 	       )
+ 	   )
+ 	{
++	    pjsip_sdp_info *tdata_sdp_info;
+ 	    const pjmedia_sdp_session *reoffer_sdp = NULL;
+ 
+ 	    PJ_LOG(4,(inv->obj_name, "Received %s response "
+@@ -2067,14 +2224,15 @@ static pj_status_t inv_check_sdp_in_incoming_msg( pjsip_inv_session *inv,
+ 		      (st_code/10==18? "early" : "final" )));
+ 
+ 	    /* Retrieve original SDP offer from INVITE request */
+-	    reoffer_sdp = (const pjmedia_sdp_session*) 
+-			  tsx->last_tx->msg->body->data;
++	    tdata_sdp_info = pjsip_tdata_get_sdp_info(tsx->last_tx);
++	    reoffer_sdp = tdata_sdp_info->sdp;
+ 
+ 	    /* Feed the original offer to negotiator */
+ 	    status = pjmedia_sdp_neg_modify_local_offer2(inv->pool_prov, 
+ 							 inv->neg,
+                                                          inv->sdp_neg_flags,
+ 						         reoffer_sdp);
++
+ 	    if (status != PJ_SUCCESS) {
+ 		PJ_LOG(1,(inv->obj_name, "Error updating local offer for "
+ 			  "forked 2xx/18x response (err=%d)", status));
+@@ -2289,7 +2447,7 @@ static pj_status_t process_answer( pjsip_inv_session *inv,
+      *    session.
+      */
+     if (sdp) {
+-	tdata->msg->body = create_sdp_body(tdata->pool, sdp);
++	tdata->msg->body = create_sdp_body(tdata->pool, sdp, inv->create_multipart);
+     } else {
+ 	if (inv->options & PJSIP_INV_REQUIRE_100REL) {
+ 	    tdata->msg->body = NULL;
+@@ -3178,7 +3336,7 @@ PJ_DEF(pj_status_t) pjsip_inv_create_ack(pjsip_inv_session *inv,
+     /* See if we have pending SDP answer to send */
+     sdp = inv_has_pending_answer(inv, inv->invite_tsx);
+     if (sdp) {
+-	inv->last_ack->msg->body = create_sdp_body(inv->last_ack->pool, sdp);
++	inv->last_ack->msg->body = create_sdp_body(inv->last_ack->pool, sdp, inv->create_multipart);
+     }
+ 
+     /* Keep this for subsequent response retransmission */
+@@ -3547,7 +3705,7 @@ static void inv_respond_incoming_update(pjsip_inv_session *inv,
+ 		const pjmedia_sdp_session *sdp;
+ 		status = pjmedia_sdp_neg_get_active_local(inv->neg, &sdp);
+ 		if (status == PJ_SUCCESS)
+-		    tdata->msg->body = create_sdp_body(tdata->pool, sdp);
++		    tdata->msg->body = create_sdp_body(tdata->pool, sdp, inv->create_multipart);
+ 	    }
+ 	}
+     }
+@@ -3713,7 +3871,7 @@ static void inv_handle_incoming_reliable_response(pjsip_inv_session *inv,
+     /* See if we need to attach SDP answer on the PRACK request */
+     sdp = inv_has_pending_answer(inv, pjsip_rdata_get_tsx(rdata));
+     if (sdp) {
+-	tdata->msg->body = create_sdp_body(tdata->pool, sdp);
++	tdata->msg->body = create_sdp_body(tdata->pool, sdp, inv->create_multipart);
+     }
+ 
+     /* Send PRACK (must be using 100rel module!) */
+@@ -5057,7 +5215,7 @@ static void inv_on_state_confirmed( pjsip_inv_session *inv, pjsip_event *e)
+ 		}
+ 
+ 		if (sdp) {
+-		    tdata->msg->body = create_sdp_body(tdata->pool, sdp);
++		    tdata->msg->body = create_sdp_body(tdata->pool, sdp, inv->create_multipart);
+ 		}
+ 	    }
+ 
+diff --git a/pjsip/src/test/inv_offer_answer_test.c b/pjsip/src/test/inv_offer_answer_test.c
+index ad5fcd409..6b19f241e 100644
+--- a/pjsip/src/test/inv_offer_answer_test.c
++++ b/pjsip/src/test/inv_offer_answer_test.c
+@@ -137,6 +137,7 @@ typedef struct inv_test_param_t
+     pj_bool_t	need_established;
+     unsigned	count;
+     oa_t	oa[4];
++    pj_bool_t	multipart_body;
+ } inv_test_param_t;
+ 
+ typedef struct inv_test_t
+@@ -321,6 +322,7 @@ static pj_bool_t on_rx_request(pjsip_rx_data *rdata)
+ 	    pj_assert(!"Invalid offerer type");
+ 
+ 	status = pjsip_inv_create_uas(dlg, rdata, sdp, inv_test.param.inv_option, &inv_test.uas);
++	inv_test.uas->create_multipart = inv_test.param.multipart_body;
+ 	pj_assert(status == PJ_SUCCESS);
+ 	pjsip_dlg_dec_lock(dlg);
+ 
+@@ -426,6 +428,7 @@ static int perform_test(inv_test_param_t *param)
+ 	sdp = NULL;
+ 
+     status = pjsip_inv_create_uac(dlg, sdp, inv_test.param.inv_option, &inv_test.uac);
++    inv_test.uac->create_multipart = param->multipart_body;
+     PJ_ASSERT_RETURN(status==PJ_SUCCESS, -20);
+ 
+     TRACE_((THIS_FILE, "    Sending INVITE %s offer", (sdp ? "with" : "without")));
+@@ -555,7 +558,8 @@ static inv_test_param_t test_params[] =
+ 	0,
+ 	PJ_TRUE,
+ 	1,
+-	{ OFFERER_UAS }
++	{ OFFERER_UAS },
++	PJ_FALSE
+     },
+ 
+     {
+@@ -563,7 +567,25 @@ static inv_test_param_t test_params[] =
+ 	PJSIP_INV_REQUIRE_100REL,
+ 	PJ_TRUE,
+ 	1,
+-	{ OFFERER_UAS }
++	{ OFFERER_UAS },
++	PJ_FALSE
++    },
++    {
++	"INVITE with no offer Multipart",
++	0,
++	PJ_TRUE,
++	1,
++	{ OFFERER_UAS },
++	PJ_TRUE
++    },
++
++    {
++	"INVITE with no offer, with 100rel Multipart",
++	PJSIP_INV_REQUIRE_100REL,
++	PJ_TRUE,
++	1,
++	{ OFFERER_UAS },
++	PJ_TRUE
+     },
+ #endif
+ 
+@@ -584,14 +606,24 @@ static inv_test_param_t test_params[] =
+ 	0,
+ 	PJ_TRUE,
+ 	2,
+-	{ OFFERER_UAC, OFFERER_UAC }
++	{ OFFERER_UAC, OFFERER_UAC },
++	PJ_FALSE
++    },
++    {
++	"INVITE and UPDATE by UAC Multipart",
++	0,
++	PJ_TRUE,
++	2,
++	{ OFFERER_UAC, OFFERER_UAC },
++	PJ_TRUE
+     },
+     {
+ 	"INVITE and UPDATE by UAC, with 100rel",
+ 	PJSIP_INV_REQUIRE_100REL,
+ 	PJ_TRUE,
+ 	2,
+-	{ OFFERER_UAC, OFFERER_UAC }
++	{ OFFERER_UAC, OFFERER_UAC },
++	PJ_FALSE
+     },
+ #endif
+ 
+@@ -617,6 +649,14 @@ static inv_test_param_t test_params[] =
+ 	4,
+ 	{ OFFERER_UAC, OFFERER_UAS, OFFERER_UAC, OFFERER_UAS }
+     },
++    {
++	"INVITE and many UPDATE by UAC and UAS Multipart",
++	0,
++	PJ_TRUE,
++	4,
++	{ OFFERER_UAC, OFFERER_UAS, OFFERER_UAC, OFFERER_UAS },
++	PJ_TRUE
++    },
+ 
+ };
+ 
+-- 
+2.33.1
+

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17657
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I483c7c3d413280c9e247a96ad581278347f9c71b
Gerrit-Change-Number: 17657
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211214/7776dea5/attachment-0001.html>


More information about the asterisk-code-review mailing list