Browse code

uac_redirect: select the contacts with highest q when a limit is set

- reported by Stefan Prelle, FS#349

Daniel-Constantin Mierla authored on 03/03/2014 18:15:30
Showing 1 changed files
... ...
@@ -165,7 +165,7 @@ static int sort_contacts(hdr_field_t *chdr, contact_t **ct_array,
165 165
 					ct_list->uri.len,ct_list->uri.s,q);
166 166
 			/*insert the contact into the sorted array */
167 167
 			for(i=0;i<n;i++) {
168
-				/* keep in mind that the contact list is reversts */
168
+				/* keep in mind that the contact list is reversed */
169 169
 				if (q_array[i]<=q)
170 170
 					continue;
171 171
 				break;
... ...
@@ -285,14 +285,18 @@ static int shmcontact2dset(struct sip_msg *req, struct sip_msg *sh_rpl,
285 285
 		goto restore;
286 286
 	}
287 287
 
288
-	/* to many branches ? */
288
+	i=0;
289
+
290
+	/* more branches than requested in the parameter
291
+	 * - add only the last ones from sorted array,
292
+	 *   because the order is by increasing q */
289 293
 	if (max!=-1 && n>max)
290
-		n = max;
294
+		i = n - max;
291 295
 
292 296
 	added = 0;
293 297
 
294 298
 	/* add the sortet contacts as branches in dset and log this! */
295
-	for ( i=0 ; i<n ; i++ ) {
299
+	for (  ; i<n ; i++ ) {
296 300
 		LM_DBG("adding contact <%.*s>\n", scontacts[i]->uri.len,
297 301
 				scontacts[i]->uri.s);
298 302
 		if(sruid_next(&_redirect_sruid)==0) {