[sr-dev] git:master:8cbef62a: presence: add delete_same_subs modparam

Stefan Mititelu stefan.mititelu at enea.com
Tue Mar 17 14:45:14 CET 2020


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

Author: Stefan Mititelu <stefan.mititelu92 at gmail.com>
Committer: Stefan Mititelu <stefan.mititelu at enea.com>
Date: 2020-03-17T15:45:05+02:00

presence: add delete_same_subs modparam

---

Modified: src/modules/presence/doc/presence_admin.xml
Modified: src/modules/presence/hash.c
Modified: src/modules/presence/hash.h
Modified: src/modules/presence/presence.c

---

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

---

diff --git a/src/modules/presence/doc/presence_admin.xml b/src/modules/presence/doc/presence_admin.xml
index 3eb1c1e942..32ffd3a2e6 100644
--- a/src/modules/presence/doc/presence_admin.xml
+++ b/src/modules/presence/doc/presence_admin.xml
@@ -951,6 +951,26 @@ modparam("presence", "pres_subs_mode", 0)
 	</example>
 </section>
 
+<section id="presence.p.delete_same_subs">
+	<title><varname>delete_same_subs</varname> (integer)</title>
+	<para>
+		Enable deleting of subscriptions with the same presence uri and callid.
+	</para>
+	<para>
+		<emphasis>
+			Default value is 0 (disabled behavior).
+		</emphasis>
+	</para>
+	<example>
+		<title>Set <varname>delete_same_subs</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("presence", "delete_same_subs", 1)
+...
+</programlisting>
+	</example>
+</section>
+
 </section>
 
 <section>
diff --git a/src/modules/presence/hash.c b/src/modules/presence/hash.c
index bf6bc839fb..50d4d9948c 100644
--- a/src/modules/presence/hash.c
+++ b/src/modules/presence/hash.c
@@ -258,6 +258,40 @@ int insert_shtable(shtable_t htable, unsigned int hash_code, subs_t *subs)
 {
 	subs_t *new_rec = NULL;
 
+	if (pres_delete_same_subs) {
+		subs_t* rec = NULL, *prev_rec = NULL;
+
+		lock_get(&htable[hash_code].lock);
+		/* search if there is another record with the same pres_uri & callid */
+		rec = htable[hash_code].entries->next;
+		while (rec) {
+			if (subs->pres_uri.len == rec->pres_uri.len && subs->callid.len == rec->callid.len &&
+					memcmp(subs->pres_uri.s, rec->pres_uri.s, subs->pres_uri.len) == 0 &&
+					memcmp(subs->callid.s, rec->callid.s, subs->callid.len) == 0) {
+				LM_NOTICE("Found another record with the same pres_uri[%.*s] and callid[%.*s]\n",
+					subs->pres_uri.len, subs->pres_uri.s, subs->callid.len, subs->callid.s);
+				/* delete this record */
+
+				if (prev_rec)
+					prev_rec->next = rec->next;
+				else
+					htable[hash_code].entries->next = rec->next;
+
+				if (subs_dbmode != NO_DB)
+					delete_db_subs(&rec->to_tag, &rec->from_tag, &rec->callid);
+
+				if (rec->contact.s!=NULL)
+					shm_free(rec->contact.s);
+
+				shm_free(rec);
+				break;
+			}
+			prev_rec = rec;
+			rec = rec->next;
+		}
+		lock_release(&htable[hash_code].lock);
+	}
+
 	new_rec = mem_copy_subs_noc(subs);
 	if(new_rec == NULL) {
 		LM_ERR("copying in share memory a subs_t structure\n");
diff --git a/src/modules/presence/hash.h b/src/modules/presence/hash.h
index 7f1276d9ad..676e6b4cff 100644
--- a/src/modules/presence/hash.h
+++ b/src/modules/presence/hash.h
@@ -56,6 +56,8 @@ struct presentity;
 #define PKG_MEM_TYPE 1 << 1
 #define SHM_MEM_TYPE 1 << 2
 
+extern int pres_delete_same_subs;
+
 /* subscribe hash entry */
 struct subscription;
 
@@ -136,4 +138,6 @@ int delete_phtable(str *pres_uri, int event);
 
 void destroy_phtable(void);
 
+int delete_db_subs(str* to_tag, str* from_tag, str* callid);
+
 #endif
diff --git a/src/modules/presence/presence.c b/src/modules/presence/presence.c
index a8f781c4be..0155cf286f 100644
--- a/src/modules/presence/presence.c
+++ b/src/modules/presence/presence.c
@@ -169,6 +169,7 @@ str pres_xavp_cfg = {0};
 int pres_retrieve_order = 0;
 str pres_retrieve_order_by = str_init("priority");
 int pres_enable_dmq = 0;
+int pres_delete_same_subs = 0;
 
 int db_table_lock_type = 1;
 db_locking_t db_table_lock = DB_LOCKING_WRITE;
@@ -245,6 +246,7 @@ static param_export_t params[]={
 	{ "cseq_offset",            PARAM_INT, &pres_cseq_offset},
 	{ "enable_dmq",             PARAM_INT, &pres_enable_dmq},
 	{ "pres_subs_mode",         PARAM_INT, &_pres_subs_mode},
+	{ "delete_same_subs",       PARAM_INT, &pres_delete_same_subs},
 	{0,0,0}
 };
 /* clang-format on */




More information about the sr-dev mailing list