Browse code

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

Daniel-Constantin Mierla authored on 04/11/2014 15:32:13
Showing 3 changed files
... ...
@@ -28,6 +28,7 @@
28 28
 #include "../../modules/usrloc/usrloc.h"
29 29
 #include "../../lib/srutils/sruid.h"
30 30
 #include <libxml/parser.h>
31
+#include "usrloc_cb.h"
31 32
 #include "pua_reginfo.h"
32 33
 
33 34
 /*<?xml version="1.0"?>
... ...
@@ -71,7 +72,9 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
71 72
 	static str no_ua = str_init("n/a");
72 73
 	static ucontact_info_t ci;
73 74
 	ucontact_t * ul_contact;
75
+	int ret;
74 76
 
77
+	pua_reginfo_update_self_op(1);
75 78
 	if (*ul_record == NULL) {
76 79
 		switch(event) {
77 80
 			case EVENT_REGISTERED:
... ...
@@ -81,14 +84,15 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
81 84
 				   create a new entry for this user in the usrloc-DB */
82 85
 				if (ul.insert_urecord(domain, &aor, ul_record) < 0) {
83 86
 					LM_ERR("failed to insert new user-record\n");
84
-					return RESULT_ERROR;
87
+					ret = RESULT_ERROR;
88
+					goto done;
85 89
 				}
86 90
 				break;
87 91
 			default:
88 92
 				/* No entry in usrloc and the contact is expired, deleted, unregistered, whatever:
89 93
                                    We do not need to do anything. */
90
-				return RESULT_NO_CONTACTS;
91
-				break;
94
+				ret = RESULT_NO_CONTACTS;
95
+				goto done;
92 96
 		}
93 97
 	}
94 98
 	
... ...
@@ -118,12 +122,14 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
118 122
 		|| (ul.get_ucontact(*ul_record, &contact_uri, &callid, &no_str, cseq+1, &ul_contact) != 0)) {
119 123
 		if (ul.insert_ucontact(*ul_record, &contact_uri, &ci, &ul_contact) < 0) {
120 124
 			LM_ERR("failed to insert new contact\n");
121
-			return RESULT_ERROR;
125
+			ret = RESULT_ERROR;
126
+			goto done;
122 127
 		}
123 128
 	} else {
124 129
 		if (ul.update_ucontact(*ul_record, ul_contact, &ci) < 0) {
125 130
 			LM_ERR("failed to update contact\n");
126
-			return RESULT_ERROR;
131
+			ret = RESULT_ERROR;
132
+			goto done;
127 133
 		}
128 134
 	}
129 135
 	ul_contact = (*ul_record)->contacts;
... ...
@@ -132,7 +138,10 @@ int process_contact(udomain_t * domain, urecord_t ** ul_record, str aor, str cal
132 138
 		ul_contact = ul_contact->next;
133 139
 	}
134 140
 
135
-	return RESULT_NO_CONTACTS;
141
+	ret = RESULT_NO_CONTACTS;
142
+done:
143
+	pua_reginfo_update_self_op(0);
144
+	return ret;
136 145
 }
137 146
 
138 147
 xmlNodePtr xmlGetNodeByName(xmlNodePtr parent, const char *name) {
... ...
@@ -49,6 +49,12 @@ Call-ID: 9ad9f89f-164d-bb86-1072-52e7e9eb5025.
49 49
 .</registration>
50 50
 </reginfo> */
51 51
 
52
+static int _pua_reginfo_self_op = 0;
53
+
54
+void pua_reginfo_update_self_op(int v)
55
+{
56
+	_pua_reginfo_self_op = v;
57
+}
52 58
 
53 59
 str* build_reginfo_full(urecord_t * record, str uri, ucontact_t* c, int type) {
54 60
 	xmlDocPtr  doc = NULL; 
... ...
@@ -221,6 +227,12 @@ void reginfo_usrloc_cb(ucontact_t* c, int type, void* param) {
221 227
 	char id_buf[512];
222 228
 	int id_buf_len;
223 229
 
230
+	if(_pua_reginfo_self_op == 1) {
231
+		LM_DBG("operation triggered by own action for aor: %.*s (%d)\n",
232
+				c->aor->len, c->aor->s, type);
233
+		return;
234
+	}
235
+
224 236
 	content_type.s = "application/reginfo+xml";
225 237
 	content_type.len = 23;
226 238
 	
... ...
@@ -21,6 +21,12 @@
21 21
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 22
  */
23 23
 
24
+#ifndef __PUA_REGINFO_USRLOC_CB__
25
+#define __PUA_REGINFO_USRLOC_CB__
26
+
24 27
 #include "../usrloc/usrloc.h"
25 28
 
26 29
 void reginfo_usrloc_cb(ucontact_t* c, int type, void* param);
30
+void pua_reginfo_update_self_op(int v);
31
+
32
+#endif