Browse code

sip: b/f: fix case-sensitivity issue for transport parameter

Raphael Coeffic authored on 17/12/2013 11:12:16
Showing 3 changed files
... ...
@@ -166,10 +166,16 @@ inline int lower_cmp(const char* l, const char* r, int len)
166 166
     const char* end = l+len;
167 167
 
168 168
     while(l!=end){
169
-	if( LOWER_B(*l) != LOWER_B(*r) ){
169
+	if( LOWER_B(*l) == LOWER_B(*r) ){
170
+	    l++; r++;
171
+	    continue;
172
+	}
173
+	else if(LOWER_B(*l) < LOWER_B(*r)) {
174
+	    return -1;
175
+	}
176
+	else {
170 177
 	    return 1;
171 178
 	}
172
-	l++; r++;
173 179
     }
174 180
 
175 181
     return 0;
... ...
@@ -177,10 +183,12 @@ inline int lower_cmp(const char* l, const char* r, int len)
177 183
 
178 184
 inline int lower_cmp_n(const char* l, int llen, const char* r, int rlen)
179 185
 {
180
-    if(llen != rlen)
181
-	return 1;
186
+    if(llen == rlen)
187
+	return lower_cmp(l,r,rlen);
188
+    else if(llen < rlen)
189
+	return -1;
182 190
 
183
-    return lower_cmp(l,r,rlen);
191
+    return 1;
184 192
 }
185 193
 
186 194
 inline int lower_cmp_n(const cstring& l, const cstring& r)
... ...
@@ -69,6 +69,12 @@
69 69
 bool _trans_layer::accept_fr_without_totag = false;
70 70
 unsigned int _trans_layer::default_bl_ttl = DEFAULT_BL_TTL;
71 71
 
72
+bool _trans_layer::less_case_i::operator () (const string& lhs, const string& rhs)
73
+{
74
+    return lower_cmp_n(lhs.c_str(),lhs.length(),
75
+		       rhs.c_str(),rhs.length()) < 0;
76
+}
77
+
72 78
 _trans_layer::_trans_layer()
73 79
     : ua(NULL),
74 80
       transports()
... ...
@@ -126,9 +132,19 @@ int _trans_layer::set_trsp_socket(sip_msg* msg, const cstring& next_trsp,
126 132
     prot_collection::iterator prot_sock_it =
127 133
 	transports[out_interface].find(c2stlstr(next_trsp));
128 134
 
129
-    // if we couldn't find anything, take whatever is there...
130 135
     if(prot_sock_it == transports[out_interface].end()) {
131
-	prot_sock_it = transports[out_interface].begin();
136
+
137
+	DBG("could not find transport '%.*s' in outbound interface %i",
138
+	    next_trsp.len,next_trsp.s,out_interface);
139
+
140
+	prot_sock_it = transports[out_interface].find("udp");
141
+	
142
+	// if we couldn't find anything, take whatever is there...
143
+	if(prot_sock_it == transports[out_interface].end()) {
144
+	    DBG("could not find transport 'udp' in outbound interface %i",
145
+		out_interface);
146
+	    prot_sock_it = transports[out_interface].begin();
147
+	}
132 148
     }
133 149
 
134 150
     if(msg->local_socket) dec_ref(msg->local_socket);
... ...
@@ -2506,19 +2522,6 @@ int _trans_layer::find_outbound_if(sockaddr_storage* remote_ip)
2506 2522
     }
2507 2523
     close(temp_sock);
2508 2524
     
2509
-    // disabled: does not work with TCP...
2510
-    //
2511
-    // try exact match
2512
-    // for(vector<trsp_socket*>::iterator it = transports.begin();
2513
-    //     it != transports.end(); ++it) {
2514
-    //     if((*it)->match_addr(&from)){
2515
-    // 	  tsock = *it;
2516
-    // 	  break;
2517
-    //     }
2518
-    // }
2519
-    // if(tsock != NULL)
2520
-    //     return tsock;
2521
-
2522 2525
     // try with alternative address
2523 2526
     char local_ip[NI_MAXHOST];
2524 2527
     if(am_inet_ntop(&from,local_ip,NI_MAXHOST) != NULL) {
... ...
@@ -2530,7 +2533,6 @@ int _trans_layer::find_outbound_if(sockaddr_storage* remote_ip)
2530 2533
 		  local_ip);
2531 2534
 	}
2532 2535
 	else {
2533
-	    //tsock = transports[if_it->second];
2534 2536
 	    return if_it->second;
2535 2537
 	}
2536 2538
     }
... ...
@@ -122,7 +122,9 @@ private:
122 122
     trans_stats stats;
123 123
     sip_ua*     ua;
124 124
 
125
-    typedef map<string,trsp_socket*> prot_collection;
125
+    struct less_case_i { bool operator ()(const string& lhs, const string& rhs); };
126
+    typedef map<string,trsp_socket*,less_case_i> prot_collection;
127
+
126 128
     vector<prot_collection> transports;
127 129
 
128 130
 public: