Browse code

Merge remote branch 'origin/sr_3.0'

The dst_uri fix (see FlySpray#37) and kamctl.

* origin/sr_3.0:
core: avoid non-null 0-length dst_uri, ruris and path
tm: fake_req dst_uri and ruri copy fix
utils/kamctl: removed unsupported commands to manage lcr gateways and routes

Andrei Pelinescu-Onciul authored on 19/02/2010 11:05:41
Showing 5 changed files
... ...
@@ -784,6 +784,9 @@ int fake_req(struct sip_msg *faked_req,
784 784
 		memcpy( faked_req->dst_uri.s, shmem_msg->dst_uri.s,
785 785
 			faked_req->dst_uri.len);
786 786
 		faked_req->dst_uri.s[faked_req->dst_uri.len]=0;
787
+	}else{
788
+		/* in case len==0, but shmem_msg->dst_uri.s!=0 (extra safety) */
789
+		faked_req->dst_uri.s = 0;
787 790
 	}
788 791
 	/* new_uri can change -- make a private copy */
789 792
 	if (shmem_msg->new_uri.s!=0 && shmem_msg->new_uri.len!=0) {
... ...
@@ -796,6 +799,9 @@ int fake_req(struct sip_msg *faked_req,
796 799
 		memcpy( faked_req->new_uri.s, shmem_msg->new_uri.s,
797 800
 			faked_req->new_uri.len);
798 801
 		faked_req->new_uri.s[faked_req->new_uri.len]=0;
802
+	}else{
803
+		/* in case len==0, but shmem_msg->new_uri.s!=0  (extra safety)*/
804
+		faked_req->new_uri.s = 0;
799 805
 	}
800 806
 	if(uac) setbflagsval(0, uac->branch_flags);
801 807
 	else setbflagsval(0, 0);
... ...
@@ -751,12 +751,14 @@ int set_dst_uri(struct sip_msg* msg, str* uri)
751 751
 {
752 752
 	char* ptr;
753 753
 
754
-	if (!msg || !uri) {
754
+	if (unlikely(!msg || !uri)) {
755 755
 		LOG(L_ERR, "set_dst_uri: Invalid parameter value\n");
756 756
 		return -1;
757 757
 	}
758 758
 
759
-	if (msg->dst_uri.s && (msg->dst_uri.len >= uri->len)) {
759
+	if (unlikely(uri->len == 0)) {
760
+		reset_dst_uri(msg);
761
+	}else if (msg->dst_uri.s && (msg->dst_uri.len >= uri->len)) {
760 762
 		memcpy(msg->dst_uri.s, uri->s, uri->len);
761 763
 		msg->dst_uri.len = uri->len;
762 764
 	} else {
... ...
@@ -788,12 +790,14 @@ int set_path_vector(struct sip_msg* msg, str* path)
788 790
 {
789 791
 	char* ptr;
790 792
 
791
-	if (!msg || !path) {
793
+	if (unlikely(!msg || !path)) {
792 794
 		LM_ERR("invalid parameter value\n");
793 795
 		return -1;
794 796
 	}
795 797
 
796
-	if (msg->path_vec.s && (msg->path_vec.len >= path->len)) {
798
+	if (unlikely(path->len == 0)) {
799
+		reset_path_vector(msg);
800
+	} else if (msg->path_vec.s && (msg->path_vec.len >= path->len)) {
797 801
 		memcpy(msg->path_vec.s, path->s, path->len);
798 802
 		msg->path_vec.len = path->len;
799 803
 	} else {
... ...
@@ -520,6 +520,9 @@ struct sip_msg*  sip_msg_shm_clone( struct sip_msg *org_msg, int *sip_msg_len,
520 520
 	new_msg->add_rm = 0;
521 521
 	new_msg->body_lumps = 0;
522 522
 	new_msg->reply_lump = 0;
523
+	/* zero *uri.s, in case len is 0 but org_msg->*uris!=0 (just to be safe)*/
524
+	new_msg->new_uri.s = 0;
525
+	new_msg->dst_uri.s = 0;
523 526
 	/* new_uri */
524 527
 	if (org_msg->new_uri.s && org_msg->new_uri.len)
525 528
 	{
... ...
@@ -57,26 +57,11 @@ Grant user membership(s) (*)
57 57
 .TP 16
58 58
 .I  Least cost routes (lcr) managment command:
59 59
 .TP             
60
-.B lcr show 
61
-Show gateways and routes tables
62
-.TP
63 60
 .B lcr dump
64 61
 Show in memory gateways and routes tables
65 62
 .TP
66 63
 .B lcr reload 
67 64
 Reload lcr gateways and routes
68
-.TP
69
-.B lcr addgw <gw_name> <ip> <port> <scheme> <transport> <grp_id> <flags> <tag> <strip> <weight> <hostname> <ping>
70
-Add a gateway with flags, tag, strip, weight, hostname, and ping (flags, tag, strip, weight, hostname, and ping are optional)
71
-.TP
72
-.B lcr rmgw <gw_name> 
73
-Delete a gateway
74
-.TP
75
-.B lcr addroute <prefix> <from> <grp_id> <prio>
76
-Add a route ( use '' to match anything in <from> )
77
-.TP
78
-.B lcr rmroute <prefix> <from> <grp_id> <prio>
79
-Delete a route
80 65
 
81 66
 .TP 16
82 67
 .I Carrierroute tables('cr') managment commands:
... ...
@@ -362,23 +362,8 @@ usage_lcr() {
362 362
 	mecho " -- command 'lcr' - manage least cost routes (lcr)"
363 363
 	echo
364 364
 cat <<EOF
365
-   * IP addresses must be entered in dotted quad format e.g. 1.2.3.4   *
366
-   * <uri_scheme> and <transport> must be entered in integer or text,  *
367
-   * e.g. transport '2' is identical to transport 'tcp'.               *
368
-   *   scheme: 1=sip, 2=sips;   transport: 1=udp, 2=tcp, 3=tls, 4=sctp *
369
-   * Examples:  lcr addgw level3 1.2.3.4 5080 sip tcp 1                *
370
-   *            lcr addroute +1 '' 1 1                                 *
371
- lcr show .......... show gateways and routes tables
372 365
  lcr dump .......... show in memory gateways and routes tables
373 366
  lcr reload ........ reload lcr gateways and routes
374
- lcr addgw <gw_name> <ip> <port> <scheme> <transport> <grp_id> <flags> <tag> <strip> <weight> <hostname> <ping>
375
-           ......... add a gateway with flags, tag, strip, weight, hostname, and ping
376
-           ......... (flags, tag, strip, weight, hostname, and ping are optional)
377
- lcr rmgw <gw_name> delete a gateway
378
- lcr addroute <prefix> <from> <grp_id> <prio>
379
-           ......... add a route ( use '' to match anything in <from> )
380
- lcr rmroute <prefix> <from> <grp_id> <prio>
381
-           ......... delete a route
382 367
 EOF
383 368
 }
384 369
 USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_lcr"