Browse code

A function to copy dst_uri

Jan Janak authored on 01/09/2004 17:06:26
Showing 2 changed files
... ...
@@ -596,6 +596,7 @@ void free_reply_lump( struct lump_rpl *lump)
596 596
 void free_sip_msg(struct sip_msg* msg)
597 597
 {
598 598
 	if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
599
+	if (msg->dst_uri.s) { pkg_free(msg->dst_uri.s); msg->dst_uri.len=0; }
599 600
 	if (msg->headers)     free_hdr_field_lst(msg->headers);
600 601
 	if (msg->add_rm)      free_lump_list(msg->add_rm);
601 602
 	if (msg->body_lumps)  free_lump_list(msg->body_lumps);
... ...
@@ -621,3 +622,34 @@ int check_transaction_quadruple( struct sip_msg* msg )
621 622
 		return 0;
622 623
 	}
623 624
 }
625
+
626
+
627
+/*
628
+ * Make a private copy of the string and assign it to dst_uri
629
+ */
630
+int set_dst_uri(struct sip_msg* msg, str* uri)
631
+{
632
+	char* ptr;
633
+
634
+	if (!msg || !uri) {
635
+		LOG(L_ERR, "set_dst_uri: Invalid parameter value\n");
636
+		return -1;
637
+	}
638
+
639
+	if (msg->dst_uri.s && (msg->dst_uri.len >= uri->len)) {
640
+		memcpy(msg->dst_uri.s, uri->s, uri->len);
641
+		msg->dst_uri.len = uri->len;
642
+	} else {
643
+		ptr = (char*)pkg_malloc(uri->len);
644
+		if (!ptr) {
645
+			LOG(L_ERR, "set_dst_uri: Not enough memory\n");
646
+			return -1;
647
+		}
648
+
649
+		memcpy(ptr, uri->s, uri->len);
650
+		if (msg->dst_uri.s) pkg_free(msg->dst_uri.s);
651
+		msg->dst_uri.s = ptr;
652
+		msg->dst_uri.len = uri->len;
653
+	}
654
+	return 0;
655
+}
... ...
@@ -317,4 +317,11 @@ inline static char* get_body(struct sip_msg *msg)
317 317
 	return msg->unparsed + offset;
318 318
 }
319 319
 
320
+
321
+/*
322
+ * Make a private copy of the string and assign it to dst_uri
323
+ */
324
+int set_dst_uri(struct sip_msg* msg, str* uri);
325
+
326
+
320 327
 #endif