Pārlūkot izejas kodu

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)
Luis Azedo 10 gadi atpakaļ
vecāks
revīzija
f5a7b12ce5
1 mainītis faili ar 57 papildinājumiem un 0 dzēšanām
  1. 57 0
      modules/usrloc/ucontact.c

+ 57 - 0
modules/usrloc/ucontact.c

@@ -76,6 +76,8 @@ void ucontact_xavp_store(ucontact_t *_c)
 }
 }
 #endif
 #endif
 
 
+int uldb_delete_attrs_ruid(str* _dname, str *_ruid);
+
 /*!
 /*!
  * \brief Create a new contact structure
  * \brief Create a new contact structure
  * \param _dom domain
  * \param _dom domain
@@ -1451,6 +1453,8 @@ int db_delete_ucontact_ruid(ucontact_t* _c)
 	vals[n].val.str_val = _c->ruid;
 	vals[n].val.str_val = _c->ruid;
 	n++;
 	n++;
 
 
+	uldb_delete_attrs_ruid(_c->domain, &_c->ruid);
+
 	if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) {
 	if (ul_dbf.use_table(ul_dbh, _c->domain) < 0) {
 		LM_ERR("sql use_table failed\n");
 		LM_ERR("sql use_table failed\n");
 		return -1;
 		return -1;
@@ -1611,6 +1615,9 @@ int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid)
 	db_key_t keys[3];
 	db_key_t keys[3];
 	db_val_t vals[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");
 	LM_DBG("trying to delete location attributes\n");
 
 
 	if(ul_xavp_contact_name.s==NULL) {
 	if(ul_xavp_contact_name.s==NULL) {
@@ -1659,6 +1666,56 @@ int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid)
 	return 0;
 	return 0;
 }
 }
 
 
+/*!
+ * \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
  * \brief Insert contact attributes into the database
  * \param _dname loaded domain name
  * \param _dname loaded domain name