From 6169f6e5644dc33d315c20d933976712749d28b1 Mon Sep 17 00:00:00 2001 From: tinusm369 <48559209+tinusm369@users.noreply.github.com> Date: Tue, 3 May 2022 19:44:42 +0530 Subject: [PATCH 1/2] Process client responses with multipart content Current situation - the stack is not processing responses(1xx, 2xx) with multipart content and sends BYE request to UAS. The UAC is still connected and waiting for a response from UAS. Changes - Parse the multipart payload, extract the application/sdp part and replace the payload in response. --- libsofia-sip-ua/nua/nua_session.c | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/libsofia-sip-ua/nua/nua_session.c b/libsofia-sip-ua/nua/nua_session.c index 4333701c..e10396e8 100644 --- a/libsofia-sip-ua/nua/nua_session.c +++ b/libsofia-sip-ua/nua/nua_session.c @@ -943,6 +943,60 @@ static int nua_session_client_response(nua_client_request_t *cr, retry: + sip_t *req = (sip_t *) sip; + msg_t *msg = msg = nta_outgoing_getrequest(cr->cr_orq); + su_home_t * home_temp = NULL; + home_temp = su_home_create(); + su_home_init(home_temp); + + //For multipart content type, parse it, find application/sdp part and replace payload in response. + if (req->sip_content_type && su_casenmatch(req->sip_content_type->c_type, "multipart/", 10)) { + msg_multipart_t *mp, *mpp; + + if (req->sip_multipart) { + mp = req->sip_multipart; + } else { + mp = msg_multipart_parse(home_temp, req->sip_content_type, (sip_payload_t *)req->sip_payload); + req->sip_multipart = mp; + } + + if (mp) { + int sdp = 0; + /* extract the SDP and set the primary content-type and payload to that SDP as if it was the only content so SOA will work */ + for (mpp = mp; mpp; mpp = mpp->mp_next) { + if (mpp->mp_content_type && mpp->mp_content_type->c_type && + mpp->mp_payload && mpp->mp_payload->pl_data && + su_casenmatch(mpp->mp_content_type->c_type, "application/sdp", 15)) { + req->sip_content_type = msg_content_type_dup (msg_home(msg), mpp->mp_content_type); + + if (req->sip_content_length) { + req->sip_content_length->l_length = mpp->mp_payload->pl_len; + } + + req->sip_payload->pl_data = su_strdup (msg_home(msg), mpp->mp_payload->pl_data); + req->sip_payload->pl_len = mpp->mp_payload->pl_len; + + sdp++; + break; + } + } + + /* insist on the existance of a SDP in the content */ + if (!sdp) { + if (home_temp) { + su_home_destroy (home_temp); + su_home_unref (home_temp); + home_temp = NULL; + } + } + } + } + if (home_temp) { + su_home_destroy (home_temp); + su_home_unref (home_temp); + home_temp = NULL; + } + if (!ss || !sip || 300 <= status) /* Xyzzy */; else if (!session_get_description(sip, &sdp, &len)) From e1678b00849c1cc81be110a17dd68af2b66dba2e Mon Sep 17 00:00:00 2001 From: tinusm369 <48559209+tinusm369@users.noreply.github.com> Date: Wed, 4 May 2022 11:54:08 +0530 Subject: [PATCH 2/2] Fixed build errors - declaration of msg_t - label error --- libsofia-sip-ua/nua/nua_session.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libsofia-sip-ua/nua/nua_session.c b/libsofia-sip-ua/nua/nua_session.c index e10396e8..cd274d46 100644 --- a/libsofia-sip-ua/nua/nua_session.c +++ b/libsofia-sip-ua/nua/nua_session.c @@ -941,10 +941,8 @@ static int nua_session_client_response(nua_client_request_t *cr, SU_DEBUG_5(("nua(%p): %s: %s %s in %u %s (%u)\n", \ (void *)nh, cr->cr_method_name, (m), received, status, phrase, cr->cr_answer_recv)) - retry: - sip_t *req = (sip_t *) sip; - msg_t *msg = msg = nta_outgoing_getrequest(cr->cr_orq); + msg_t *msg = nta_outgoing_getrequest(cr->cr_orq); su_home_t * home_temp = NULL; home_temp = su_home_create(); su_home_init(home_temp); @@ -996,6 +994,8 @@ static int nua_session_client_response(nua_client_request_t *cr, su_home_unref (home_temp); home_temp = NULL; } + +retry: if (!ss || !sip || 300 <= status) /* Xyzzy */;