Ver código fonte

pua_reginfo: avoid sending notify when processing location record action triggered by itself

Daniel-Constantin Mierla 11 anos atrás
pai
commit
e070257321

+ 15 - 6
modules/pua_reginfo/notify.c

@@ -28,6 +28,7 @@
 #include "../../modules/usrloc/usrloc.h"
 #include "../../lib/srutils/sruid.h"
 #include <libxml/parser.h>
+#include "usrloc_cb.h"
 #include "pua_reginfo.h"
 
 /*<?xml version="1.0"?>
@@ -71,7 +72,9 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
 	static str no_ua = str_init("n/a");
 	static ucontact_info_t ci;
 	ucontact_t * ul_contact;
+	int ret;
 
+	pua_reginfo_update_self_op(1);
 	if (*ul_record == NULL) {
 		switch(event) {
 			case EVENT_REGISTERED:
@@ -81,14 +84,15 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
 				   create a new entry for this user in the usrloc-DB */
 				if (ul.insert_urecord(domain, &aor, ul_record) < 0) {
 					LM_ERR("failed to insert new user-record\n");
-					return RESULT_ERROR;
+					ret = RESULT_ERROR;
+					goto done;
 				}
 				break;
 			default:
 				/* No entry in usrloc and the contact is expired, deleted, unregistered, whatever:
                                    We do not need to do anything. */
-				return RESULT_NO_CONTACTS;
-				break;
+				ret = RESULT_NO_CONTACTS;
+				goto done;
 		}
 	}
 	
@@ -118,12 +122,14 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
 		|| (ul.get_ucontact(*ul_record, &contact_uri, &callid, &no_str, cseq+1, &ul_contact) != 0)) {
 		if (ul.insert_ucontact(*ul_record, &contact_uri, &ci, &ul_contact) < 0) {
 			LM_ERR("failed to insert new contact\n");
-			return RESULT_ERROR;
+			ret = RESULT_ERROR;
+			goto done;
 		}
 	} else {
 		if (ul.update_ucontact(*ul_record, ul_contact, &ci) < 0) {
 			LM_ERR("failed to update contact\n");
-			return RESULT_ERROR;
+			ret = RESULT_ERROR;
+			goto done;
 		}
 	}
 	ul_contact = (*ul_record)->contacts;
@@ -132,7 +138,10 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
 		ul_contact = ul_contact->next;
 	}
 
-	return RESULT_NO_CONTACTS;
+	ret = RESULT_NO_CONTACTS;
+done:
+	pua_reginfo_update_self_op(0);
+	return ret;
 }
 
 xmlNodePtr xmlGetNodeByName(xmlNodePtr parent, const char *name) {

+ 12 - 0
modules/pua_reginfo/usrloc_cb.c

@@ -49,6 +49,12 @@ Call-ID: 9ad9f89f-164d-bb86-1072-52e7e9eb5025.
 .</registration>
 </reginfo> */
 
+static int _pua_reginfo_self_op = 0;
+
+void pua_reginfo_update_self_op(int v)
+{
+	_pua_reginfo_self_op = v;
+}
 
 str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
 	xmlDocPtr  doc = NULL; 
@@ -221,6 +227,12 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
 	char id_buf[512];
 	int id_buf_len;
 
+	if(_pua_reginfo_self_op == 1) {
+		LM_DBG("operation triggered by own action for aor: %.*s (%d)\n",
+				c->aor->len, c->aor->s, type);
+		return;
+	}
+
 	content_type.s = "application/reginfo+xml";
 	content_type.len = 23;
 	

+ 6 - 0
modules/pua_reginfo/usrloc_cb.h

@@ -21,6 +21,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#ifndef __PUA_REGINFO_USRLOC_CB__
+#define __PUA_REGINFO_USRLOC_CB__
+
 #include "../usrloc/usrloc.h"
 
 void reginfo_usrloc_cb(ucontact_t* c, int type, void* param);
+void pua_reginfo_update_self_op(int v);
+
+#endif