Browse code

ims_usrloc_pcscf: added a reverse searchin get_pcontact

- added a new parameter for reverse search in get_pcontact.

Aleksandar Yosifov authored on 03/08/2020 11:45:01 • Henning Westerholt committed on 12/08/2020 18:44:08
Showing 3 changed files
... ...
@@ -444,9 +444,10 @@ error:
444 444
  * @udomain_t* _d - domain to search in
445 445
  * @str* _contact - contact to search for - should be a SIP URI
446 446
  * @struct pontact** _c - contact to return to if found (null if not found)
447
+ * @int reverse_search - reverse search for a contact in the memory
447 448
  * @return 0 if found <>0 if not
448 449
  */
449
-int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact** _c) {
450
+int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact** _c, int reverse_search) {
450 451
 	unsigned int sl, i, j, aorhash, params_len, has_rinstance=0;
451 452
 	struct pcontact* c;
452 453
 	struct sip_uri needle_uri;
... ...
@@ -454,9 +455,10 @@ int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact**
454 455
 	char *params, *sep;
455 456
 	str rinstance = {0, 0};
456 457
         
457
-	LM_DBG("Searching for contact with AOR [%.*s] in P-CSCF usrloc based on VIA [%d://%.*s:%d] Received [%d://%.*s:%d], Search flag is %d\n",
458
+	LM_DBG("Searching for contact with AOR [%.*s] in P-CSCF usrloc based on VIA [%d://%.*s:%d] Received [%d://%.*s:%d], Search flag is %d, reverse_search %d\n",
458 459
 		contact_info->aor.len, contact_info->aor.s, contact_info->via_prot, contact_info->via_host.len, contact_info->via_host.s, contact_info->via_port,
459
-		contact_info->received_proto, contact_info->received_host.len, contact_info->received_host.s, contact_info->received_port, contact_info->searchflag);
460
+		contact_info->received_proto, contact_info->received_host.len, contact_info->received_host.s, contact_info->received_port, contact_info->searchflag,
461
+		reverse_search);
460 462
 
461 463
 	/* parse the uri in the NOTIFY */
462 464
 	if (contact_info->aor.len>0 && contact_info->aor.s){
... ...
@@ -501,7 +503,7 @@ int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact**
501 503
 	sl = aorhash & (_d->size - 1);
502 504
         
503 505
 	LM_DBG("get_pcontact slot is [%d]\n", sl);
504
-	c = _d->table[sl].first;
506
+	c = reverse_search ? _d->table[sl].last : _d->table[sl].first;
505 507
 
506 508
 	for (i = 0; i < _d->table[sl].n; i++) {
507 509
 		LM_DBG("comparing contact with aorhash [%u], aor [%.*s]\n", c->aorhash, c->aor.len, c->aor.s);
... ...
@@ -563,7 +565,7 @@ int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact**
563 565
 							c->rinstance.len, c->rinstance.s);
564 566
 					if ((rinstance.len == c->rinstance.len) && memcmp(rinstance.s, c->rinstance.s, rinstance.len) != 0) {
565 567
 						LM_DBG("rinstance does not match - no match here...\n");
566
-						c = c->next;
568
+						c = reverse_search ? c->prev : c->next;
567 569
 						continue;
568 570
 					}
569 571
 				}
... ...
@@ -571,7 +573,7 @@ int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact**
571 573
 				if ((contact_info->extra_search_criteria & SEARCH_SERVICE_ROUTES) && contact_info->num_service_routes > 0) {
572 574
 					LM_DBG("have %d service routes to search for\n", contact_info->num_service_routes);
573 575
 					if (contact_info->num_service_routes != c->num_service_routes) {
574
-						c = c->next;
576
+						c = reverse_search ? c->prev : c->next;
575 577
 						LM_DBG("number of service routes do not match - failing\n");
576 578
 						continue;
577 579
 					} 
... ...
@@ -588,7 +590,7 @@ int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact**
588 590
 						}
589 591
 					}
590 592
 					if (serviceroutematch == 0) {
591
-						c = c->next;
593
+						c = reverse_search ? c->prev : c->next;
592 594
 						continue;
593 595
 					}
594 596
 				}
... ...
@@ -596,14 +598,14 @@ int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact**
596 598
 				//finally check state being searched for
597 599
 				if ( (contact_info->reg_state != PCONTACT_ANY) && ((contact_info->reg_state & c->reg_state) == 0)) {
598 600
 					LM_DBG("can't find contact for requested reg state [%d] - (have [%d])\n", contact_info->reg_state, c->reg_state);
599
-					c = c->next;
601
+					c = reverse_search ? c->prev : c->next;
600 602
 					continue;
601 603
 				}
602 604
 				*_c = c;
603 605
 				return 0;
604 606
 			}
605 607
 		}
606
-		c = c->next;
608
+		c = reverse_search ? c->prev : c->next;
607 609
 	}
608 610
         
609 611
 	LM_DBG("contact not found in memory\n");
... ...
@@ -74,7 +74,7 @@ void unlock_ulslot(udomain_t* _d, int i);
74 74
 int update_rx_regsession(struct udomain* _d, str* session_id, struct pcontact* _c);
75 75
 int update_pcontact(struct udomain* _d, struct pcontact_info* _ci, struct pcontact* _c);
76 76
 int insert_pcontact(struct udomain* _d, str* _contact, struct pcontact_info* _ci, struct pcontact** _r);
77
-int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact** _r);
77
+int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact** _c, int reverse_search);
78 78
 int assert_identity(udomain_t* _d, str * _host, unsigned short _port, unsigned short _proto, str * _identity);
79 79
 int delete_pcontact(udomain_t* _d, struct pcontact* _r);
80 80
 int unreg_pending_contacts_cb(udomain_t* _d, pcontact_t* _c, int type);
... ...
@@ -237,7 +237,7 @@ typedef struct pcontact {
237 237
     struct pcontact* next; /*!< Previous item in the hash entry */
238 238
 } pcontact_t;
239 239
 
240
-typedef int (*get_pcontact_t)(struct udomain* _d, pcontact_info_t* contact_info, struct pcontact** _c);
240
+typedef int (*get_pcontact_t)(struct udomain* _d, pcontact_info_t* contact_info, struct pcontact** _c, int reverse_search);
241 241
 
242 242
 typedef int (*assert_identity_t)(struct udomain* _d, str * _host, unsigned short _port, unsigned short _proto, str * _identity);
243 243