MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / update_cloned_msg_from_msg

Function update_cloned_msg_from_msg

modules/tm/sip_msg.c:1210–1340  ·  view source on GitHub ↗

* Parameters: * c_msg - Currently saved SIP request in its initial form (Shared memory) * msg - Duplicate of "c_msg" (private memory + heap space) that has * been altered by the script (it is newer than c_msg) * * Handles all realloc() operations needed to update "c_msg" from "msg" * */

Source from the content-addressed store, hash-verified

1208 *
1209 */
1210int update_cloned_msg_from_msg(struct sip_msg *c_msg, struct sip_msg *msg)
1211{
1212 unsigned char copy_mask = 0;
1213 int l1_len, l2_len, l3_len;
1214 char *p;
1215 struct lump *add_rm_aux=NULL,*body_lumps_aux=NULL;
1216 struct lump_rpl *reply_lump_aux=NULL;
1217 struct sip_msg_body *body_bk=NULL;
1218
1219 if ( (c_msg->msg_flags & (FL_SHM_UPDATABLE|FL_SHM_CLONE))==0 ) {
1220 LM_CRIT("BUG trying to update a msg not in SHM or not "
1221 "UPDATABLE (%d)\n", c_msg->msg_flags);
1222 return -1;
1223 }
1224
1225 /* length of the new data lump structures */
1226 l1_len = l2_len = l3_len = 0;
1227 LUMP_LIST_LEN(l1_len, msg->add_rm);
1228 LUMP_LIST_LEN(l2_len, msg->body_lumps);
1229 RPL_LUMP_LIST_LEN(l3_len, msg->reply_lump);
1230
1231 shm_lock();
1232 /* SIP related strings */
1233 REALLOC_CLONED_FIELD_unsafe( new_uri, c_msg, msg, 0);
1234 REALLOC_CLONED_FIELD_unsafe( dst_uri, c_msg, msg, 1);
1235 REALLOC_CLONED_FIELD_unsafe( path_vec, c_msg, msg, 2);
1236 REALLOC_CLONED_FIELD_unsafe( set_global_address, c_msg, msg, 3);
1237 REALLOC_CLONED_FIELD_unsafe( set_global_port, c_msg, msg, 4);
1238
1239 /*
1240 * lump reallocation (guaranteed to be equal or greater size).
1241 *
1242 * c_msg lumps:
1243 * - initial set of SHM lumps
1244 *
1245 * msg lumps:
1246 * - initial set of SHM lumps (same memory as in c_msg above!)
1247 * - additional set of PKG lumps (from running various script changes)
1248 *
1249 * That is why mem is not leaked after the following allocations:
1250 */
1251
1252 if (l1_len) {
1253 add_rm_aux = c_msg->add_rm;
1254 c_msg->add_rm = shm_malloc_bulk(l1_len);
1255 }
1256 if (l2_len) {
1257 body_lumps_aux = c_msg->body_lumps;
1258 c_msg->body_lumps = shm_malloc_bulk(l2_len);
1259 }
1260
1261 if (l3_len) {
1262 reply_lump_aux = c_msg->reply_lump;
1263 c_msg->reply_lump = shm_malloc_bulk(l3_len);
1264 }
1265
1266 /* done with mem ops */
1267 shm_unlock();

Callers 4

w_t_reply_bodyFunction · 0.85
do_t_cleanupFunction · 0.85
w_t_relayFunction · 0.85
t_handle_asyncFunction · 0.85

Calls 4

shm_malloc_bulkFunction · 0.85
clone_sip_msg_bodyFunction · 0.85
free_sip_bodyFunction · 0.85
shm_free_bulkFunction · 0.85

Tested by

no test coverage detected