Browse code

ims_registrar_pcscf: update_contacts get received from req

- update_contacts - if the reply doesn't include contact alias
get received info from the request.
- extend get_pcontact eith the new parameter.

Aleksandar Yosifov authored on 03/08/2020 11:46:22
Showing 3 changed files
... ...
@@ -182,7 +182,7 @@ int process_contact(udomain_t * _d, int expires, str contact_uri, int contact_st
182 182
         LM_DBG("Contact in NOTIFY does not have an alias....\n");
183 183
     }
184 184
 
185
-    if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //contact does not exist
185
+    if (ul.get_pcontact(_d, &ci, &pcontact, 0) != 0) { //contact does not exist
186 186
         if (contact_state == STATE_TERMINATED) {
187 187
             LM_DBG("This contact: <%.*s> is in state terminated and is not in usrloc, ignore\n", contact_uri.len, contact_uri.s);
188 188
             ret = RESULT_CONTACTS_FOUND;
... ...
@@ -196,10 +196,24 @@ static inline int update_contacts(struct sip_msg *req,struct sip_msg *rpl, udoma
196 196
 							ci.searchflag = SEARCH_RECEIVED;
197 197
 						}
198 198
 					}
199
-				} 
199
+				} else {
200
+					char* srcip = NULL;
201
+					if((srcip = pkg_malloc(50)) == NULL) {
202
+						LM_ERR("Error allocating memory for source IP address\n");
203
+						return -1;
204
+					}
205
+
206
+					ci.received_host.len = ip_addr2sbuf(&req->rcv.src_ip, srcip, 50);
207
+					ci.received_host.s = srcip;
208
+					ci.received_port = req->rcv.src_port;
209
+					ci.received_proto = req->rcv.proto;
210
+					ci.searchflag = SEARCH_RECEIVED;
211
+					LM_DBG("received from request: host [%.*s], port [%d] , proto [%d]\n", 
212
+							ci.received_host.len, ci.received_host.s, ci.received_port, ci.received_proto);
213
+				}
200 214
 				
201 215
 				ul.lock_udomain(_d, &puri.host, port, puri.proto);
202
-				if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //need to insert new contact
216
+				if (ul.get_pcontact(_d, &ci, &pcontact, 0) != 0) { //need to insert new contact
203 217
 					if ((expires-local_time_now)<=0) { //remove contact - de-register
204 218
 						LM_DBG("This is a de-registration for contact <%.*s> but contact is not in usrloc - ignore\n", c->uri.len, c->uri.s);
205 219
 						goto next_contact;
... ...
@@ -362,7 +376,7 @@ int save_pending(struct sip_msg* _m, udomain_t* _d) {
362 376
 	}
363 377
 
364 378
 	ul.lock_udomain(_d, &ci.via_host, ci.via_port, ci.via_prot);
365
-	if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //need to insert new contact
379
+	if (ul.get_pcontact(_d, &ci, &pcontact, 0) != 0) { //need to insert new contact
366 380
 		ipsec_pcscf.ipsec_reconfig(); // try to clean all ipsec SAs/Policies if there is no registered contacts
367 381
 
368 382
 		LM_DBG("Adding pending pcontact: <%.*s>\n", c->uri.len, c->uri.s);
... ...
@@ -261,7 +261,7 @@ tryagain:
261 261
 	if (b && b->contacts) {
262 262
 		for (ct = b->contacts; ct; ct = ct->next) {
263 263
 			search_ci.aor = ct->uri;
264
-			if (ul.get_pcontact(_d, &search_ci, &c) == 0) {
264
+			if (ul.get_pcontact(_d, &search_ci, &c, 0) == 0) {
265 265
 				if (checkcontact(_m, c) != 0) {
266 266
 					c = NULL;
267 267
 				} else {
... ...
@@ -278,7 +278,7 @@ tryagain:
278 278
 		//			received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
279 279
 		//			received_host.s = srcip;
280 280
 		search_ci.searchflag = SEARCH_RECEIVED;
281
-		if (ul.get_pcontact(_d, &search_ci, &c) == 1) {
281
+		if (ul.get_pcontact(_d, &search_ci, &c, 0) == 1) {
282 282
 			LM_DBG("No entry in usrloc for %.*s:%i (Proto %i) found!\n", received_host.len, received_host.s, _m->rcv.src_port, _m->rcv.proto);
283 283
 		} else {
284 284
 			if (checkcontact(_m, c) != 0) {
... ...
@@ -290,7 +290,7 @@ tryagain:
290 290
 	if ((c == NULL) && (is_registered_fallback2ip == 2)) {
291 291
 		LM_INFO("Contact not found based on IP/Port/Proto, trying Contact-header\n");
292 292
 		search_ci.searchflag = SEARCH_NORMAL;
293
-		if (ul.get_pcontact(_d, &search_ci, &c) == 1) {
293
+		if (ul.get_pcontact(_d, &search_ci, &c, 0) == 1) {
294 294
 		} else {
295 295
 			if (checkcontact(_m, c) != 0) {
296 296
 				c = NULL;
... ...
@@ -785,7 +785,7 @@ int pcscf_unregister(udomain_t* _d, str * uri, str * received_host, int received
785 785
         search_ci.aor.len = uri->len;
786 786
 		search_ci.reg_state = PCONTACT_ANY;
787 787
 
788
-	if (ul.get_pcontact(_d, &search_ci, &pcontact) == 0) {
788
+	if (ul.get_pcontact(_d, &search_ci, &pcontact, 0) == 0) {
789 789
 		/* Lock this record while working with the data: */
790 790
 		ul.lock_udomain(_d, &pcontact->via_host, pcontact->via_port, pcontact->via_proto);
791 791