Browse code

register(k): pack contact info based on header for searching existing ul records

- not using the contact header resulted in omitting instance and reg-id
parameters, not following gruu/ob extensions, ending in duplicate
records for same +sip.instance
- reported by José Luis Millán

Daniel-Constantin Mierla authored on 30/07/2012 10:57:09
Showing 1 changed files
... ...
@@ -302,6 +302,10 @@ static inline ucontact_info_t* pack_ci( struct sip_msg* _m, contact_t* _c,
302 302
 	}
303 303
 
304 304
 	if(_c!=0) {
305
+		/* hook uri address - should be more than 'sip:' chars */
306
+		if(_c->uri.s!=NULL && _c->uri.len>4)
307
+			ci.c = &_c->uri;
308
+
305 309
 		/* Calculate q value of the contact */
306 310
 		if (calc_contact_q(_c->q, &ci.q) < 0) {
307 311
 			rerrno = R_INV_Q;
... ...
@@ -651,6 +655,12 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
651 651
 		/* calculate expires */
652 652
 		calc_contact_expires(_m, _c->expires, &expires);
653 653
 
654
+		/* pack the contact info */
655
+		if ( (ci=pack_ci( 0, _c, expires, 0))==0 ) {
656
+			LM_ERR("failed to pack contact specific info\n");
657
+			goto error;
658
+		}
659
+
654 660
 		/* search for the contact*/
655 661
 		ret = ul.get_ucontact_by_instance( _r, &_c->uri, ci, &c);
656 662
 		if (ret==-1) {
... ...
@@ -668,12 +678,6 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
668 668
 			if (expires==0)
669 669
 				continue;
670 670
 
671
-			/* pack the contact_info */
672
-			if ( (ci=pack_ci( 0, _c, expires, 0))==0 ) {
673
-				LM_ERR("failed to extract contact info\n");
674
-				goto error;
675
-			}
676
-
677 671
 			if (ul.insert_ucontact( _r, &_c->uri, ci, &c) < 0) {
678 672
 				rerrno = R_UL_INS_C;
679 673
 				LM_ERR("failed to insert contact\n");
... ...
@@ -710,12 +714,6 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
710 710
 				rc = 3;
711 711
 			} else {
712 712
 				/* do update */
713
-				/* pack the contact specific info */
714
-				if ( (ci=pack_ci( 0, _c, expires, 0))==0 ) {
715
-					LM_ERR("failed to pack contact specific info\n");
716
-					goto error;
717
-				}
718
-
719 713
 				if(_mode)
720 714
 				{
721 715
 					ptr=_r->contacts;