Browse Source

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 5 years ago
parent
commit
3ee011fa21

+ 1 - 1
src/modules/ims_registrar_pcscf/notify.c

@@ -182,7 +182,7 @@ int process_contact(udomain_t * _d, int expires, str contact_uri, int contact_st
         LM_DBG("Contact in NOTIFY does not have an alias....\n");
     }
 
-    if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //contact does not exist
+    if (ul.get_pcontact(_d, &ci, &pcontact, 0) != 0) { //contact does not exist
         if (contact_state == STATE_TERMINATED) {
             LM_DBG("This contact: <%.*s> is in state terminated and is not in usrloc, ignore\n", contact_uri.len, contact_uri.s);
             ret = RESULT_CONTACTS_FOUND;

+ 17 - 3
src/modules/ims_registrar_pcscf/save.c

@@ -196,10 +196,24 @@ static inline int update_contacts(struct sip_msg *req,struct sip_msg *rpl, udoma
 							ci.searchflag = SEARCH_RECEIVED;
 						}
 					}
-				} 
+				} else {
+					char* srcip = NULL;
+					if((srcip = pkg_malloc(50)) == NULL) {
+						LM_ERR("Error allocating memory for source IP address\n");
+						return -1;
+					}
+
+					ci.received_host.len = ip_addr2sbuf(&req->rcv.src_ip, srcip, 50);
+					ci.received_host.s = srcip;
+					ci.received_port = req->rcv.src_port;
+					ci.received_proto = req->rcv.proto;
+					ci.searchflag = SEARCH_RECEIVED;
+					LM_DBG("received from request: host [%.*s], port [%d] , proto [%d]\n", 
+							ci.received_host.len, ci.received_host.s, ci.received_port, ci.received_proto);
+				}
 				
 				ul.lock_udomain(_d, &puri.host, port, puri.proto);
-				if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //need to insert new contact
+				if (ul.get_pcontact(_d, &ci, &pcontact, 0) != 0) { //need to insert new contact
 					if ((expires-local_time_now)<=0) { //remove contact - de-register
 						LM_DBG("This is a de-registration for contact <%.*s> but contact is not in usrloc - ignore\n", c->uri.len, c->uri.s);
 						goto next_contact;
@@ -362,7 +376,7 @@ int save_pending(struct sip_msg* _m, udomain_t* _d) {
 	}
 
 	ul.lock_udomain(_d, &ci.via_host, ci.via_port, ci.via_prot);
-	if (ul.get_pcontact(_d, &ci, &pcontact) != 0) { //need to insert new contact
+	if (ul.get_pcontact(_d, &ci, &pcontact, 0) != 0) { //need to insert new contact
 		ipsec_pcscf.ipsec_reconfig(); // try to clean all ipsec SAs/Policies if there is no registered contacts
 
 		LM_DBG("Adding pending pcontact: <%.*s>\n", c->uri.len, c->uri.s);

+ 4 - 4
src/modules/ims_registrar_pcscf/service_routes.c

@@ -261,7 +261,7 @@ tryagain:
 	if (b && b->contacts) {
 		for (ct = b->contacts; ct; ct = ct->next) {
 			search_ci.aor = ct->uri;
-			if (ul.get_pcontact(_d, &search_ci, &c) == 0) {
+			if (ul.get_pcontact(_d, &search_ci, &c, 0) == 0) {
 				if (checkcontact(_m, c) != 0) {
 					c = NULL;
 				} else {
@@ -278,7 +278,7 @@ tryagain:
 		//			received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
 		//			received_host.s = srcip;
 		search_ci.searchflag = SEARCH_RECEIVED;
-		if (ul.get_pcontact(_d, &search_ci, &c) == 1) {
+		if (ul.get_pcontact(_d, &search_ci, &c, 0) == 1) {
 			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);
 		} else {
 			if (checkcontact(_m, c) != 0) {
@@ -290,7 +290,7 @@ tryagain:
 	if ((c == NULL) && (is_registered_fallback2ip == 2)) {
 		LM_INFO("Contact not found based on IP/Port/Proto, trying Contact-header\n");
 		search_ci.searchflag = SEARCH_NORMAL;
-		if (ul.get_pcontact(_d, &search_ci, &c) == 1) {
+		if (ul.get_pcontact(_d, &search_ci, &c, 0) == 1) {
 		} else {
 			if (checkcontact(_m, c) != 0) {
 				c = NULL;
@@ -785,7 +785,7 @@ int pcscf_unregister(udomain_t* _d, str * uri, str * received_host, int received
         search_ci.aor.len = uri->len;
 		search_ci.reg_state = PCONTACT_ANY;
 
-	if (ul.get_pcontact(_d, &search_ci, &pcontact) == 0) {
+	if (ul.get_pcontact(_d, &search_ci, &pcontact, 0) == 0) {
 		/* Lock this record while working with the data: */
 		ul.lock_udomain(_d, &pcontact->via_host, pcontact->via_port, pcontact->via_proto);