michael@377: Index: modules/registrar/save.c michael@377: diff -Nau modules/registrar/save.c.orig modules/registrar/save.c michael@377: --- modules/registrar/save.c.orig 2008-08-03 15:53:57.000000000 +0200 michael@377: +++ modules/registrar/save.c 2009-03-24 21:44:46.182865192 +0100 michael@382: @@ -74,7 +74,7 @@ michael@377: struct save_ctx { michael@377: unsigned int flags; michael@377: str aor; michael@377: - unsigned int max_contacts; michael@377: + int max_contacts; michael@377: }; michael@377: michael@377: michael@382: @@ -386,7 +386,7 @@ michael@377: if (e == 0) michael@377: continue; michael@377: michael@377: - if (_sctx->max_contacts && (num >= _sctx->max_contacts)) { michael@377: + if (_sctx->max_contacts && (num >= abs(_sctx->max_contacts))) { michael@377: if (_sctx->flags®_SAVE_FORCE_REG_FLAG) { michael@377: /* we are overflowing the number of maximum contacts, michael@377: so remove the first (oldest) one to prevent this */ michael@382: @@ -492,6 +492,7 @@ michael@377: contact_t* _c, struct save_ctx *_sctx) michael@377: { michael@377: ucontact_info_t *ci; michael@377: + ucontact_t *ucon = 0; michael@377: ucontact_t* c; michael@377: int e; michael@377: unsigned int cflags; michael@382: @@ -552,7 +553,7 @@ michael@377: continue; michael@377: michael@377: /* we need to add a new contact -> too many ?? */ michael@377: - if (_sctx->max_contacts && num>=_sctx->max_contacts) { michael@377: + if (_sctx->max_contacts && num>=abs(_sctx->max_contacts)) { michael@377: if (_sctx->flags®_SAVE_FORCE_REG_FLAG) { michael@377: /* we are overflowing the number of maximum contacts, michael@377: so remove the first (oldest) one to prevent this */ michael@382: @@ -579,6 +580,23 @@ michael@377: goto error; michael@377: } michael@377: michael@377: + /* remove matching contacts or matching Call-ID headers before */ michael@377: + /* inserting a new one if indicated by a negative max_contacts */ michael@377: + if (_sctx->max_contacts < 0) { michael@377: + for (ucon = _r->contacts; ucon; ucon = ucon->next) { michael@377: + if (((ci->callid->len == ucon->callid.len) && \ michael@377: + !memcmp(ci->callid->s, ucon->callid.s, ci->callid->len)) \ michael@377: + || \ michael@377: + ((_c->uri.len==ucon->c.len) && \ michael@377: + !memcmp(_c->uri.s, ucon->c.s, _c->len))) { michael@377: + if (ul.delete_ucontact(_r, ucon) < 0) { michael@377: + rerrno = R_UL_DEL_C; michael@377: + LM_ERR("failed to delete contact\n"); michael@377: + goto error; michael@377: + } michael@377: + } michael@377: + } michael@377: + } michael@377: if (ul.insert_ucontact( _r, &_c->uri, ci, &c) < 0) { michael@377: rerrno = R_UL_INS_C; michael@377: LM_ERR("failed to insert contact\n"); michael@377: Index: modules/registrar/sip_msg.c michael@377: diff -Nau modules/registrar/sip_msg.c.orig modules/registrar/sip_msg.c michael@377: --- modules/registrar/sip_msg.c.orig 2008-08-03 15:53:57.000000000 +0200 michael@377: +++ modules/registrar/sip_msg.c 2009-03-24 21:44:46.182865192 +0100 michael@377: @@ -137,7 +137,7 @@ michael@377: /* Message without contacts is OK */ michael@377: if (_m->contact == 0) return 0; michael@377: michael@377: - if (((contact_body_t*)_m->contact->parsed)->star == 1) { michael@377: + if (((contact_body_t*)_m->contact->parsed)->star == -1) { michael@377: /* The first Contact HF is star */ michael@377: /* Expires must be zero */ michael@377: if (get_expires_hf(_m) > 0) { michael@377: @@ -167,7 +167,7 @@ michael@377: p = _m->contact->next; michael@377: while(p) { michael@377: if (p->type == HDR_CONTACT_T) { michael@377: - if (((contact_body_t*)p->parsed)->star == 1) { michael@377: + if (((contact_body_t*)p->parsed)->star == -1) { michael@377: rerrno = R_STAR_CONT; michael@377: return 1; michael@377: }