Module: sip-router
Branch: master
Commit: a74f12d633188a7e70b09238c0d48b207efc66c3
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a74f12d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)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
---
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 3609342..caa5465 100644
--- a/modules_k/registrar/save.c
+++ b/modules_k/registrar/save.c
@@ -369,12 +369,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
@@ -392,7 +392,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);
@@ -400,7 +400,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;
@@ -539,7 +540,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;
@@ -550,6 +551,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;
@@ -561,8 +563,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) &&
@@ -574,6 +579,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 */
@@ -701,8 +707,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;
@@ -719,7 +725,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);
@@ -728,7 +734,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;
}
@@ -781,7 +787,7 @@ int save(struct sip_msg* _m, udomain_t* _d, int _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;
}