Module: kamailio Branch: master Commit: a61f325589a3bef6164b1eca8bd93ca3dace4549 URL: https://github.com/kamailio/kamailio/commit/a61f325589a3bef6164b1eca8bd93ca3...
Author: Victor Seva linuxmaniac@torreviejawireless.org Committer: Victor Seva linuxmaniac@torreviejawireless.org Date: 2015-05-21T14:08:07+02:00
usrloc: run callbacks after updating the info on DB_ONLY mode
---
Modified: modules/usrloc/ucontact.c Modified: modules/usrloc/urecord.c
---
Diff: https://github.com/kamailio/kamailio/commit/a61f325589a3bef6164b1eca8bd93ca3... Patch: https://github.com/kamailio/kamailio/commit/a61f325589a3bef6164b1eca8bd93ca3...
---
diff --git a/modules/usrloc/ucontact.c b/modules/usrloc/ucontact.c index 8bd8c39..a645e42 100644 --- a/modules/usrloc/ucontact.c +++ b/modules/usrloc/ucontact.c @@ -1639,6 +1639,28 @@ static inline void update_contact_pos(struct urecord* _r, ucontact_t* _c) } }
+/*! + * \brief helper function for update_ucontact + * \param _c contact + * \return 0 on success, -1 on failure + */ +static inline int update_contact_db(ucontact_t* _c) +{ + int res; + + if (ul_db_update_as_insert) + res = db_insert_ucontact(_c); + else + res = db_update_ucontact(_c); + + if (res < 0) { + LM_ERR("failed to update database\n"); + return -1; + } else { + _c->state = CS_SYNC; + } + return 0; +}
/*! * \brief Update ucontact with new values @@ -1649,8 +1671,6 @@ static inline void update_contact_pos(struct urecord* _r, ucontact_t* _c) */ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci) { - int res; - /* we have to update memory in any case, but database directly * only in db_mode 1 */ if (mem_update_ucontact( _c, _ci) < 0) { @@ -1658,6 +1678,10 @@ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci) return -1; }
+ if (db_mode==DB_ONLY) { + if (update_contact_db(_c) < 0) return -1; + } + /* run callbacks for UPDATE event */ if (exists_ulcb_type(UL_CONTACT_UPDATE)) { @@ -1670,18 +1694,8 @@ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci)
st_update_ucontact(_c);
- if (db_mode == WRITE_THROUGH || db_mode==DB_ONLY) { - if (ul_db_update_as_insert) - res = db_insert_ucontact(_c); - else - res = db_update_ucontact(_c); - - if (res < 0) { - LM_ERR("failed to update database\n"); - return -1; - } else { - _c->state = CS_SYNC; - } + if (db_mode == WRITE_THROUGH) { + if (update_contact_db(_c) < 0) return -1; } return 0; } diff --git a/modules/usrloc/urecord.c b/modules/usrloc/urecord.c index 9e0bff3..36f747b 100644 --- a/modules/usrloc/urecord.c +++ b/modules/usrloc/urecord.c @@ -571,11 +571,20 @@ int insert_ucontact(urecord_t* _r, str* _contact, ucontact_info_t* _ci, return -1; }
+ if (db_mode==DB_ONLY) { + if (db_insert_ucontact(*_c) < 0) { + LM_ERR("failed to insert in database\n"); + return -1; + } else { + (*_c)->state = CS_SYNC; + } + } + if (exists_ulcb_type(UL_CONTACT_INSERT)) { run_ul_callbacks( UL_CONTACT_INSERT, *_c); }
- if (db_mode == WRITE_THROUGH || db_mode==DB_ONLY) { + if (db_mode == WRITE_THROUGH) { if (db_insert_ucontact(*_c) < 0) { LM_ERR("failed to insert in database\n"); return -1;