[sr-dev] git:master:036a77d4: ims_usrloc_scscf: Remove all unlinked contacts

Federico Favaro federico at aereo.lan.athonet.com
Tue Aug 2 14:45:12 CEST 2016


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

Author: Federico Favaro <federico at aereo.lan.athonet.com>
Committer: Federico Favaro <federico at aereo.lan.athonet.com>
Date: 2016-08-01T14:29:18+02:00

ims_usrloc_scscf: Remove all unlinked contacts

At startup, if IMPU table is empty, it means
that all the contacts stored on contact table
are "unlinked". Remove them as they are
unuseful

---

Modified: modules/ims_usrloc_scscf/usrloc_db.c

---

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

---

diff --git a/modules/ims_usrloc_scscf/usrloc_db.c b/modules/ims_usrloc_scscf/usrloc_db.c
index 5f428c2..94e870c 100644
--- a/modules/ims_usrloc_scscf/usrloc_db.c
+++ b/modules/ims_usrloc_scscf/usrloc_db.c
@@ -75,6 +75,9 @@ int impu_subscriber_insert_query_len;
 char* impu_subscriber_delete_query = "DELETE impu_subscriber FROM impu_subscriber INNER JOIN impu on impu_subscriber.impu_id=impu.id INNER JOIN subscriber on impu_subscriber.subscriber_id=subscriber.id WHERE impu.impu='%.*s' AND subscriber.event='%.*s' and subscriber.watcher_contact='%.*s' and subscriber.presentity_uri='%.*s'";
 int impu_subscriber_delete_query_len;
 
+char* delete_unlinked_contact_query = "DELETE from contact";
+int delete_unlinked_contact_query_len;	
+
 
 
 extern db1_con_t* ul_dbh;
@@ -651,6 +654,32 @@ static inline int dbrow2subscriber(db_val_t* val, subscriber_data_t* subscriber_
 	return 0;
 }
 
+int delete_all_unlinked_contacts() {
+	int len;
+	db1_res_t* rs;
+	
+	len = strlen(delete_unlinked_contact_query) +1;
+	if (!query_buffer_len || query_buffer_len < len) {
+		if (query_buffer.s) {
+			pkg_free(query_buffer.s);
+		}
+		query_buffer.s = (char*) pkg_malloc(len);
+		if (!query_buffer.s) {
+			LM_ERR("no more pkg mem\n");
+			return -1;
+		}
+		query_buffer_len = len;
+	}
+	snprintf(query_buffer.s,query_buffer_len,delete_unlinked_contact_query);
+	query_buffer.len = strlen(query_buffer.s);
+	
+	if (ul_dbf.raw_query(ul_dbh, &query_buffer, &rs) != 0) {
+		return -1;
+	}
+	ul_dbf.free_result(ul_dbh,rs);
+	return 0;
+}
+
 int preload_udomain(db1_con_t* _c, udomain_t* _d) {
     db_key_t col[9];
     db_row_t* row;
@@ -717,9 +746,12 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) {
     }
 
     if (RES_ROW_N(rs) == 0) {
-	LM_DBG("table is empty\n");
-	ul_dbf.free_result(_c, rs);
-	return 0;
+		LM_DBG("IMPU table is empty, removing all unlinked contacts \n");
+		ul_dbf.free_result(_c, rs);
+		if (delete_all_unlinked_contacts() != 0) {
+			LM_ERR("Not able to delete unlinked contacts\n");
+		}
+		return 0;
     }
 
     LM_DBG("preloading S-CSCF usrloc...\n");




More information about the sr-dev mailing list