Module: kamailio
Branch: master
Commit: 48317d3180e8ec67d24862ebcbbb80ab887ff5bd
URL: 
https://github.com/kamailio/kamailio/commit/48317d3180e8ec67d24862ebcbbb80ab887ff5bd

Author: Richard Fuchs <rfu...@sipwise.com>
Committer: Richard Fuchs <rfu...@sipwise.com>
Date: 2024-06-03T15:49:12-04:00

rtpengine: use extract_body with read_sdp_pv

If the module uses an SDP taken from a pvar, and the current message
uses a multipart content, don't replace the entire message body with the
rewritten SDP, but only the part of the body that is SDP.

closes #3854

---

Modified: src/modules/rtpengine/rtpengine.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/48317d3180e8ec67d24862ebcbbb80ab887ff5bd.diff
Patch: 
https://github.com/kamailio/kamailio/commit/48317d3180e8ec67d24862ebcbbb80ab887ff5bd.patch

---

diff --git a/src/modules/rtpengine/rtpengine.c 
b/src/modules/rtpengine/rtpengine.c
index c26f61e2483..775542c5994 100644
--- a/src/modules/rtpengine/rtpengine.c
+++ b/src/modules/rtpengine/rtpengine.c
@@ -4718,28 +4718,13 @@ static int rtpengine_offer_answer(
                        }
                }
                if(write_sdp_pvar == NULL || write_sdp_pvar_mode != 0) {
-                       if(cl_field.len) {
-                               anchor = del_lump(msg, cl_field.s - msg->buf, 
cl_field.len, 0);
-                               cl_repl.s = pkg_malloc(10);
-                               if(!cl_repl.s) {
-                                       LM_ERR("pkg_malloc for Content-Length 
failed\n");
-                                       goto error_free;
-                               }
-                               cl_repl.len = snprintf(cl_repl.s, 10, "%i", 
(int)newbody.len);
-                               if(!insert_new_lump_after(anchor, cl_repl.s, 
cl_repl.len, 0)) {
-                                       LM_ERR("insert_new_lump_after 
failed\n");
-                                       goto error_free;
-                               }
-                               cl_repl.s = NULL;
-                       }
-
                        if(read_sdp_pvar_str.len > 0) {
                                /* get the body from the message as body ptr 
may have changed
                                 * when using read_sdp_pv */
-                               cur_body.len = 0;
-                               cur_body.s = get_body(msg);
-                               cur_body.len = msg->buf + msg->len - cur_body.s;
-
+                               if(extract_body(msg, &cur_body, &cl_field) == 
-1) {
+                                       LM_ERR("failed to extract body from 
message");
+                                       goto error_free;
+                               }
                                anchor = del_lump(msg, cur_body.s - msg->buf, 
cur_body.len, 0);
                        } else {
                                anchor = del_lump(msg, body.s - msg->buf, 
body.len, 0);
@@ -4752,6 +4737,21 @@ static int rtpengine_offer_answer(
                                LM_ERR("insert_new_lump_after failed\n");
                                goto error_free;
                        }
+
+                       if(cl_field.len) {
+                               anchor = del_lump(msg, cl_field.s - msg->buf, 
cl_field.len, 0);
+                               cl_repl.s = pkg_malloc(10);
+                               if(!cl_repl.s) {
+                                       LM_ERR("pkg_malloc for Content-Length 
failed\n");
+                                       goto error_free;
+                               }
+                               cl_repl.len = snprintf(cl_repl.s, 10, "%i", 
(int)newbody.len);
+                               if(!insert_new_lump_after(anchor, cl_repl.s, 
cl_repl.len, 0)) {
+                                       LM_ERR("insert_new_lump_after 
failed\n");
+                                       goto error_free;
+                               }
+                               cl_repl.s = NULL;
+                       }
                }
        }
 

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org

Reply via email to