/*! * \brief Update ucontact with new values * \param _r record the contact belongs to * \param _c updated contact * \param _ci new contact informations * \return 0 on success, -1 on failure */ int update_ucontact(struct impurecord* _r, ucontact_t* _c, ucontact_info_t* _ci) { /* we have to update memory in any case, but database directly * only in db_mode 1 */ LM_DBG("Updating contact aor: [%.*s] and contact uri: [%.*s]\n", _c->aor.len, _c->aor.s, _c->c.len, _c->c.s); if (mem_update_ucontact(_c, _ci) < 0) { LM_ERR("failed to update memory\n"); return -1; } if (db_mode == WRITE_THROUGH && (db_insert_ucontact(_r, _c) != 0)) { /* this is an insert/update */ LM_ERR("failed to update contact in DB [%.*s]\n", _c->aor.len, _c->aor.s); return -1; } //make sure IMPU is linked to this contact link_contact_to_impu(_r, _c, 1); /* run callbacks for UPDATE event */ if (exists_ulcb_type(_c->cbs, UL_CONTACT_UPDATE)) { LM_DBG("exists callback for type= UL_CONTACT_UPDATE\n"); run_ul_callbacks(_c->cbs, UL_CONTACT_UPDATE, _r, _c); } if (exists_ulcb_type(_r->cbs, UL_IMPU_UPDATE_CONTACT)) { run_ul_callbacks(_r->cbs, UL_IMPU_UPDATE_CONTACT, _r, _c); } // update_contact_pos(_r, _c); return 0; }
/*! * \brief Create and insert new contact into impurecord * \param _r record into the new contact should be inserted * \param _contact contact string * \param _ci contact information * \param _c new created contact * \return 0 on success, -1 on failure */ int insert_scontact(impurecord_t* _r, str* _contact, ucontact_info_t* _ci, ucontact_t** _c) { //First check our constraints if (maxcontact > 0 && maxcontact_behaviour > 0) { int numcontacts = get_contacts_count(_r); if (numcontacts >= maxcontact) { switch (maxcontact_behaviour) { case 1://reject LM_ERR("too many contacts already registered for IMPU <%.*s>\n", _r->public_identity.len, _r->public_identity.s); return -1; case 2://overwrite oldest LM_DBG("Too many contacts already registered, overwriting oldest for IMPU <%.*s>\n", _r->public_identity.len, _r->public_identity.s); //we can just remove the first one seeing the contacts are ordered on insertion with newest last and oldest first mem_delete_ucontact(_r->newcontacts[0]); break; default://unknown LM_ERR("unknown maxcontact behaviour..... ignoring\n"); break; } } } //at this stage we are safe to insert the new contact LM_DBG("INSERTing ucontact in usrloc module\n"); if (((*_c) = mem_insert_scontact(_r, _contact, _ci)) == 0) { LM_ERR("failed to insert contact\n"); return -1; } // /*DB?*/ if (db_mode == WRITE_THROUGH && db_insert_ucontact(_r, *_c) != 0) { LM_ERR("error inserting contact into db"); return -1; } //make sure IMPU is linked to this contact link_contact_to_impu(_r, *_c, 1); release_scontact(*_c); if (exists_ulcb_type(NULL, UL_CONTACT_INSERT)) { run_ul_callbacks(NULL, UL_CONTACT_INSERT, _r, *_c); } if (exists_ulcb_type(_r->cbs, UL_IMPU_NEW_CONTACT)) { run_ul_callbacks(_r->cbs, UL_IMPU_NEW_CONTACT, _r, *_c); } return 0; }