Module: kamailio
Branch: master
Commit: 7ff33667d553bf510b0bcf4f16a93badb49cc8f4
URL: 
https://github.com/kamailio/kamailio/commit/7ff33667d553bf510b0bcf4f16a93badb49cc8f4

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-01-13T15:01:18+01:00

core: sip msg clone - split the function to get the length of the cloned data

---

Modified: src/core/sip_msg_clone.c
Modified: src/core/sip_msg_clone.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/7ff33667d553bf510b0bcf4f16a93badb49cc8f4.diff
Patch: 
https://github.com/kamailio/kamailio/commit/7ff33667d553bf510b0bcf4f16a93badb49cc8f4.patch

---

diff --git a/src/core/sip_msg_clone.c b/src/core/sip_msg_clone.c
index 5bd72c99190..4b8b0e7a052 100644
--- a/src/core/sip_msg_clone.c
+++ b/src/core/sip_msg_clone.c
@@ -358,23 +358,13 @@ static inline int clone_authorized_hooks(
 
 #define HOOK_SET(hook) (new_msg->hook != org_msg->hook)
 
-
-/** Creates a shm clone for a sip_msg.
- * org_msg is cloned along with most of its headers and lumps into one
- * shm memory block (so that a shm_free() on the result will free everything)
- * @return shm malloced sip_msg on success, 0 on error
- * Warning: Cloner does not clone all hdr_field headers (From, To, etc.).
- */
-struct sip_msg *sip_msg_shm_clone(
-               struct sip_msg *org_msg, int *sip_msg_len, int clone_lumps)
+unsigned int sip_msg_clone_len(sip_msg_t *org_msg, int clone_lumps)
 {
-       unsigned int len;
-       struct hdr_field *hdr, *new_hdr, *last_hdr;
+       struct hdr_field *hdr;
        struct via_body *via;
        struct via_param *prm;
-       struct to_param *to_prm, *new_to_prm;
-       struct sip_msg *new_msg;
-       char *p;
+       struct to_param *to_prm;
+       unsigned int len;
 
        /*computing the length of entire sip_msg structure*/
        len = ROUND4(sizeof(struct sip_msg));
@@ -494,6 +484,25 @@ struct sip_msg *sip_msg_shm_clone(
                RPL_LUMP_LIST_LEN(len, org_msg->reply_lump);
        }
 
+       return len;
+}
+
+/** Creates a shm clone for a sip_msg.
+ * org_msg is cloned along with most of its headers and lumps into one
+ * shm memory block (so that a shm_free() on the result will free everything)
+ * @return shm malloced sip_msg on success, 0 on error
+ * Warning: Cloner does not clone all hdr_field headers (From, To, etc.).
+ */
+struct sip_msg *sip_msg_shm_clone(
+               struct sip_msg *org_msg, int *sip_msg_len, int clone_lumps)
+{
+       unsigned int len;
+       struct hdr_field *hdr, *new_hdr, *last_hdr;
+       struct to_param *to_prm, *new_to_prm;
+       struct sip_msg *new_msg;
+       char *p;
+
+       len = sip_msg_clone_len(org_msg, clone_lumps);
        p = (char *)shm_malloc(len);
        if(!p) {
                SHM_MEM_ERROR;
diff --git a/src/core/sip_msg_clone.h b/src/core/sip_msg_clone.h
index e512697b915..4b768df7438 100644
--- a/src/core/sip_msg_clone.h
+++ b/src/core/sip_msg_clone.h
@@ -19,6 +19,8 @@
 
 #include "parser/msg_parser.h"
 
+unsigned int sip_msg_clone_len(sip_msg_t *org_msg, int clone_lumps);
+
 struct sip_msg *sip_msg_shm_clone(
                struct sip_msg *org_msg, int *sip_msg_len, int clone_lumps);
 

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to