[sr-dev] git:master:f5a7b12c: usrloc - fix db_delete_ucontact_ruid

Luis Azedo luis at 2600hz.com
Fri Feb 27 12:20:44 CET 2015


Module: kamailio
Branch: master
Commit: f5a7b12ce5f73749e9ae3d7a31e2a3616539421c
URL: https://github.com/kamailio/kamailio/commit/f5a7b12ce5f73749e9ae3d7a31e2a3616539421c

Author: Luis Azedo <luis at 2600hz.com>
Committer: Luis Azedo <luis at 2600hz.com>
Date: 2015-02-27T11:20:20Z

usrloc - fix db_delete_ucontact_ruid

when the contact is deleted using db_delete_ucontact_ruid (default)
the uldb_attrs_delete is not called leaving the location_attrs with unwanted records

created uldb_attrs_delete_ruid to be called by db_delete_ucontact_ruid
redirected uldb_attrs_delete to uldb_attrs_delete_ruid when ul_db_ops_ruid == 1

(cherry picked from commit 09c51685af36071aad6054d84571c260be2ba9e2)

---

Modified: modules/usrloc/ucontact.c

---

Diff:  https://github.com/kamailio/kamailio/commit/f5a7b12ce5f73749e9ae3d7a31e2a3616539421c.diff
Patch: https://github.com/kamailio/kamailio/commit/f5a7b12ce5f73749e9ae3d7a31e2a3616539421c.patch

---

diff --git a/modules/usrloc/ucontact.c b/modules/usrloc/ucontact.c
index 737da03..89b94dc 100644
--- a/modules/usrloc/ucontact.c
+++ b/modules/usrloc/ucontact.c
@@ -76,6 +76,8 @@ void ucontact_xavp_store(ucontact_t *_c)
 }
 #endif
 
+int uldb_delete_attrs_ruid(str* _dname, str *_ruid);
+
 /*!
  * \brief Create a new contact structure
  * \param _dom domain
@@ -1451,6 +1453,8 @@ int db_delete_ucontact_ruid(ucontact_t* _c)
 	vals[n].val.str_val = _c->ruid;
 	n++;
 
+	uldb_delete_attrs_ruid(_c->domain, &_c->ruid);
+
 	if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) {
 		LM_ERR("sql use_table failed\n");
 		return -1;
@@ -1611,6 +1615,9 @@ int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid)
 	db_key_t keys[3];
 	db_val_t vals[3];
 
+	if(ul_db_ops_ruid==1)
+		return uldb_delete_attrs_ruid(_dname, _ruid);
+
 	LM_DBG("trying to delete location attributes\n");
 
 	if(ul_xavp_contact_name.s==NULL) {
@@ -1660,6 +1667,56 @@ int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid)
 }
 
 /*!
+ * \brief Delete all location attributes from a udomain by ruid
+ *
+ * \param _dname loaded domain name
+ * \param _ruid usrloc record unique id
+ * \return 0 on success, -1 on failure
+ */
+int uldb_delete_attrs_ruid(str* _dname, str *_ruid)
+{
+	char tname_buf[64];
+	str tname;
+	db_key_t keys[1];
+	db_val_t vals[1];
+
+	LM_DBG("trying to delete location attributes\n");
+
+	if(ul_xavp_contact_name.s==NULL) {
+		/* feature disabled by mod param */
+		return 0;
+	}
+
+	if(_dname->len+6>=64) {
+		LM_ERR("attributes table name is too big\n");
+		return -1;
+	}
+	strncpy(tname_buf, _dname->s, _dname->len);
+	tname_buf[_dname->len] = '\0';
+	strcat(tname_buf, "_attrs");
+	tname.s = tname_buf;
+	tname.len = _dname->len + 6;
+
+	keys[0] = &ulattrs_ruid_col;
+
+	vals[0].type = DB1_STR;
+	vals[0].nul = 0;
+	vals[0].val.str_val = *_ruid;
+
+	if (ul_dbf.use_table(ul_dbh, &tname) < 0) {
+		LM_ERR("sql use_table failed\n");
+		return -1;
+	}
+
+	if (ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) {
+		LM_ERR("deleting from database failed\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+/*!
  * \brief Insert contact attributes into the database
  * \param _dname loaded domain name
  * \param _user sip username




More information about the sr-dev mailing list