[sr-dev] git:3.1: registrar(k): reset local interator to contacts headers

Daniel-Constantin Mierla miconda at gmail.com
Mon Jun 6 12:44:30 CEST 2011


Module: sip-router
Branch: 3.1
Commit: 16183d4553aca270da1284255f3f6862132a3aeb
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=16183d4553aca270da1284255f3f6862132a3aeb

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sat Jun  4 10:22:09 2011 +0200

registrar(k): reset local interator to contacts headers

- when the REGISTER request had more than one Contact header and
  max_contacts parameter was set, there were two iterations through the
  list fo Contacts header without reseting the iterator, resulting in
  not processing all Contact headers in save() - reported by Andreas Granig
- instead of parsing the fist contact header as parameter to several
  functions, take it from sip msg structure hook
(cherry picked from commit a74f12d633188a7e70b09238c0d48b207efc66c3)

---

 modules_k/registrar/save.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/modules_k/registrar/save.c b/modules_k/registrar/save.c
index 9955034..bc89eb6 100644
--- a/modules_k/registrar/save.c
+++ b/modules_k/registrar/save.c
@@ -368,12 +368,12 @@ error:
  * and insert all contacts from the message that have expires
  * > 0
  */
-static inline int insert_contacts(struct sip_msg* _m, contact_t* _c,
-													udomain_t* _d, str* _a)
+static inline int insert_contacts(struct sip_msg* _m, udomain_t* _d, str* _a)
 {
 	ucontact_info_t* ci;
 	urecord_t* r;
 	ucontact_t* c;
+	contact_t* _c;
 	unsigned int flags;
 	int num, expires;
 #ifdef USE_TCP
@@ -391,7 +391,7 @@ static inline int insert_contacts(struct sip_msg* _m, contact_t* _c,
 		e_max = tcp_check = 0;
 	}
 #endif
-
+	_c = get_first_contact(_m);
 	for( num=0,r=0,ci=0 ; _c ; _c = get_next_contact(_c) ) {
 		/* calculate expires */
 		calc_contact_expires(_m, _c->expires, &expires);
@@ -399,7 +399,8 @@ static inline int insert_contacts(struct sip_msg* _m, contact_t* _c,
 		if (expires == 0)
 			continue;
 
-		if (cfg_get(registrar, registrar_cfg, max_contacts) && (num >= cfg_get(registrar, registrar_cfg, max_contacts))) {
+		if (cfg_get(registrar, registrar_cfg, max_contacts)
+				&& (num >= cfg_get(registrar, registrar_cfg, max_contacts))) {
 			LM_INFO("too many contacts (%d) for AOR <%.*s>\n", 
 					num, _a->len, _a->s);
 			rerrno = R_TOO_MANY;
@@ -538,7 +539,7 @@ static int test_max_contacts(struct sip_msg* _m, urecord_t* _r, contact_t* _c,
  *    == 0, delete contact
  */
 static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
-										contact_t* _c, int _mode)
+										int _mode)
 {
 	ucontact_info_t *ci;
 	ucontact_t *c, *ptr, *ptr0;
@@ -549,6 +550,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 	struct sip_uri uri;
 #endif
 	int rc;
+	contact_t* _c;
 
 	/* mem flag */
 	flags = mem_only;
@@ -560,8 +562,11 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 		goto error;
 	}
 
-	if (cfg_get(registrar, registrar_cfg, max_contacts) && test_max_contacts(_m, _r, _c, ci) != 0 )
-		goto error;
+	if (cfg_get(registrar, registrar_cfg, max_contacts)) {
+		_c = get_first_contact(_m);
+		if(test_max_contacts(_m, _r, _c, ci) != 0)
+			goto error;
+	}
 
 #ifdef USE_TCP
 	if ( (_m->flags&tcp_persistent_flag) &&
@@ -573,6 +578,7 @@ static inline int update_contacts(struct sip_msg* _m, urecord_t* _r,
 	}
 #endif
 
+	_c = get_first_contact(_m);
 	updated=0;
 	for( ; _c ; _c = get_next_contact(_c) ) {
 		/* calculate expires */
@@ -700,8 +706,8 @@ error:
  * This function will process request that
  * contained some contact header fields
  */
-static inline int add_contacts(struct sip_msg* _m, contact_t* _c,
-								udomain_t* _d, str* _a, int _mode)
+static inline int add_contacts(struct sip_msg* _m, udomain_t* _d,
+		str* _a, int _mode)
 {
 	int res;
 	int ret;
@@ -718,7 +724,7 @@ static inline int add_contacts(struct sip_msg* _m, contact_t* _c,
 	}
 
 	if (res == 0) { /* Contacts found */
-		if ((ret=update_contacts(_m, r, _c, _mode)) < 0) {
+		if ((ret=update_contacts(_m, r, _mode)) < 0) {
 			build_contact(r->contacts);
 			ul.release_urecord(r);
 			ul.unlock_udomain(_d, _a);
@@ -727,7 +733,7 @@ static inline int add_contacts(struct sip_msg* _m, contact_t* _c,
 		build_contact(r->contacts);
 		ul.release_urecord(r);
 	} else {
-		if (insert_contacts(_m, _c, _d, _a) < 0) {
+		if (insert_contacts(_m, _d, _a) < 0) {
 			ul.unlock_udomain(_d, _a);
 			return -4;
 		}
@@ -780,7 +786,7 @@ int save(struct sip_msg* _m, char* _d, char* _cflags)
 		}
 	} else {
 		mode = is_cflag_set(REG_SAVE_REPL_FL)?1:0;
-		if ((ret=add_contacts(_m, c, (udomain_t*)_d, &aor, mode)) < 0)
+		if ((ret=add_contacts(_m, (udomain_t*)_d, &aor, mode)) < 0)
 			goto error;
 		ret = (ret==0)?1:ret;
 	}




More information about the sr-dev mailing list