Răsfoiți Sursa

usrloc: extend handle_lost_tcp use for get_urecord (#1366)

* usrloc: extend handle_lost_tcp use for get_urecord

* usrloc: extend handle_lost_tcp, do not use inline functions
Vasiliy Ganchev 7 ani în urmă
părinte
comite
a1cf1aa386

+ 14 - 1
src/modules/usrloc/udomain.c

@@ -40,6 +40,7 @@
 #include "usrloc.h"
 #include "utime.h"
 #include "usrloc.h"
+#include "urecord.h"
 
 #ifdef STATISTICS
 static char *build_stat_name( str* domain, char *var_name)
@@ -1116,6 +1117,7 @@ int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r)
 {
 	unsigned int sl, i, aorhash;
 	urecord_t* r;
+	ucontact_t* ptr = NULL;
 
 	if (db_mode!=DB_ONLY) {
 		/* search in cache */
@@ -1125,7 +1127,18 @@ int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r)
 
 		for(i = 0; r!=NULL && i < _d->table[sl].n; i++) {
 			if((r->aorhash==aorhash) && (r->aor.len==_aor->len)
-						&& !memcmp(r->aor.s,_aor->s,_aor->len)){
+						&& !memcmp(r->aor.s,_aor->s,_aor->len))
+			{
+				if (handle_lost_tcp)
+				{
+					for (ptr = r->contacts;ptr;ptr = ptr->next)
+					{
+						if (ptr->expires == UL_EXPIRED_TIME )
+							continue;
+						if (is_valid_tcpconn(ptr) && !is_tcp_alive(ptr))
+							ptr->expires = UL_EXPIRED_TIME;
+					}
+				}
 				*_r = r;
 				return 0;
 			}

+ 2 - 2
src/modules/usrloc/urecord.c

@@ -216,7 +216,7 @@ void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c)
 	free_ucontact(_c);
 }
 
-static inline int is_valid_tcpconn(ucontact_t *c)
+int is_valid_tcpconn(ucontact_t *c)
 {
 	if (c->tcpconn_id == -1)
 		return 0; /* tcpconn_id is not present */
@@ -224,7 +224,7 @@ static inline int is_valid_tcpconn(ucontact_t *c)
 		return 1; /* valid tcpconn_id */
 }
 
-static inline int is_tcp_alive(ucontact_t *c)
+int is_tcp_alive(ucontact_t *c)
 {
 	struct tcp_connection *con = NULL;
 	int rc = 0;

+ 4 - 0
src/modules/usrloc/urecord.h

@@ -189,4 +189,8 @@ int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path,
 int get_ucontact_by_instance(urecord_t* _r, str* _c, ucontact_info_t* _ci,
 		ucontact_t** _co);
 
+int is_valid_tcpconn(ucontact_t *c);
+
+int is_tcp_alive(ucontact_t *c);
+
 #endif