Forráskód Böngészése

usrloc: clang-format for coherent indentation and coding style

Victor Seva 2 éve
szülő
commit
6e89f3e252

+ 187 - 196
src/modules/usrloc/dlist.c

@@ -28,16 +28,16 @@
 
 
 #include "dlist.h"
-#include <stdlib.h>	       /* abort */
-#include <string.h>            /* strlen, memcmp */
-#include <stdio.h>             /* printf */
+#include <stdlib.h> /* abort */
+#include <string.h> /* strlen, memcmp */
+#include <stdio.h>	/* printf */
 #include "../../core/ut.h"
 #include "../../lib/srdb1/db_ut.h"
 #include "../../core/mem/shm_mem.h"
 #include "../../core/dprint.h"
 #include "../../core/ip_addr.h"
 #include "../../core/socket_info.h"
-#include "udomain.h"           /* new_udomain, free_udomain */
+#include "udomain.h" /* new_udomain, free_udomain */
 #include "usrloc.h"
 #include "utime.h"
 #include "ul_keepalive.h"
@@ -64,14 +64,13 @@ void ul_set_max_partition(unsigned int m)
  * \param _d pointer to domain
  * \return 0 if the domain was found and 1 of not
  */
-static inline int find_dlist(str* _n, dlist_t** _d)
+static inline int find_dlist(str *_n, dlist_t **_d)
 {
-	dlist_t* ptr;
+	dlist_t *ptr;
 
 	ptr = _ksr_ul_root;
 	while(ptr) {
-		if ((_n->len == ptr->name.len) &&
-		    !memcmp(_n->s, ptr->name.s, _n->len)) {
+		if((_n->len == ptr->name.len) && !memcmp(_n->s, ptr->name.s, _n->len)) {
 			*_d = ptr;
 			return 0;
 		}
@@ -87,11 +86,11 @@ static inline int find_dlist(str* _n, dlist_t** _d)
  */
 int ul_ka_db_records(int partidx)
 {
-	db1_res_t* res = NULL;
+	db1_res_t *res = NULL;
 	db_row_t *row = NULL;
 	db_key_t keys1[4]; /* where */
 	db_val_t vals1[4];
-	db_op_t  ops1[4];
+	db_op_t ops1[4];
 	db_key_t keys2[9]; /* select */
 	int n[2] = {2, 9}; /* number of dynamic values used on key1/key2 */
 	dlist_t *dom = NULL;
@@ -126,12 +125,12 @@ int ul_ka_db_records(int partidx)
 	ops1[1] = OP_EQ;
 	vals1[1].type = DB1_INT;
 	vals1[1].nul = 0;
-	if(_ul_max_partition>0)
+	if(_ul_max_partition > 0)
 		vals1[1].val.int_val = partidx;
 	else
 		vals1[1].val.int_val = 0;
 
-	if (ul_ka_mode & ULKA_NAT) {
+	if(ul_ka_mode & ULKA_NAT) {
 		keys1[n[0]] = &ul_keepalive_col;
 		ops1[n[0]] = OP_EQ;
 		vals1[n[0]].type = DB1_INT;
@@ -139,7 +138,7 @@ int ul_ka_db_records(int partidx)
 		vals1[n[0]].val.int_val = 1;
 		n[0]++;
 	}
-	if(ul_ka_filter&GAU_OPT_SERVER_ID) {
+	if(ul_ka_filter & GAU_OPT_SERVER_ID) {
 		keys1[n[0]] = &ul_srv_id_col;
 		ops1[n[0]] = OP_EQ;
 		vals1[n[0]].type = DB1_INT;
@@ -148,17 +147,18 @@ int ul_ka_db_records(int partidx)
 		n[0]++;
 	}
 
-	for (dom = _ksr_ul_root; dom!=NULL ; dom=dom->next) {
-		if (ul_dbf.use_table(ul_dbh, dom->d->name) < 0) {
+	for(dom = _ksr_ul_root; dom != NULL; dom = dom->next) {
+		if(ul_dbf.use_table(ul_dbh, dom->d->name) < 0) {
 			LM_ERR("sql use_table failed\n");
 			return -1;
 		}
-		if (ul_dbf.query(ul_dbh, keys1, ops1, vals1, keys2,
-							n[0], n[1], NULL, &res) <0 ) {
+		if(ul_dbf.query(
+				   ul_dbh, keys1, ops1, vals1, keys2, n[0], n[1], NULL, &res)
+				< 0) {
 			LM_ERR("query error\n");
 			return -1;
 		}
-		if( RES_ROW_N(res)==0 ) {
+		if(RES_ROW_N(res) == 0) {
 			ul_dbf.free_result(ul_dbh, res);
 			continue;
 		}
@@ -169,8 +169,9 @@ int ul_ka_db_records(int partidx)
 			memset(&uc, 0, sizeof(ucontact_t));
 
 			/* received */
-			uc.received.s = (char*)VAL_STRING(ROW_VALUES(row));
-			if ( VAL_NULL(ROW_VALUES(row)) || uc.received.s==0 || uc.received.s[0]==0 ) {
+			uc.received.s = (char *)VAL_STRING(ROW_VALUES(row));
+			if(VAL_NULL(ROW_VALUES(row)) || uc.received.s == 0
+					|| uc.received.s[0] == 0) {
 				uc.received.s = NULL;
 				uc.received.len = 0;
 			} else {
@@ -178,8 +179,8 @@ int ul_ka_db_records(int partidx)
 			}
 
 			/* contact */
-			uc.c.s = (char*)VAL_STRING(ROW_VALUES(row)+1);
-			if (VAL_NULL(ROW_VALUES(row)+1) || uc.c.s==0 || uc.c.s[0]==0) {
+			uc.c.s = (char *)VAL_STRING(ROW_VALUES(row) + 1);
+			if(VAL_NULL(ROW_VALUES(row) + 1) || uc.c.s == 0 || uc.c.s[0] == 0) {
 				LM_ERR("empty contact -> skipping\n");
 				continue;
 			} else {
@@ -187,8 +188,9 @@ int ul_ka_db_records(int partidx)
 			}
 
 			/* path */
-			uc.path.s = (char*)VAL_STRING(ROW_VALUES(row)+4);
-			if (VAL_NULL(ROW_VALUES(row)+4) || uc.path.s==0 || uc.path.s[0]==0){
+			uc.path.s = (char *)VAL_STRING(ROW_VALUES(row) + 4);
+			if(VAL_NULL(ROW_VALUES(row) + 4) || uc.path.s == 0
+					|| uc.path.s[0] == 0) {
 				uc.path.s = NULL;
 				uc.path.len = 0;
 			} else {
@@ -196,25 +198,26 @@ int ul_ka_db_records(int partidx)
 			}
 
 			/* ruid */
-			uc.ruid.s = (char*)VAL_STRING(ROW_VALUES(row)+5);
-			if (VAL_NULL(ROW_VALUES(row)+5) || uc.ruid.s==0 || uc.ruid.s[0]==0){
+			uc.ruid.s = (char *)VAL_STRING(ROW_VALUES(row) + 5);
+			if(VAL_NULL(ROW_VALUES(row) + 5) || uc.ruid.s == 0
+					|| uc.ruid.s[0] == 0) {
 				uc.ruid.s = NULL;
 				uc.ruid.len = 0;
 			} else {
 				uc.ruid.len = strlen(uc.ruid.s);
 			}
 			/* sock */
-			p  = (char*)VAL_STRING(ROW_VALUES(row) + 2);
-			if (VAL_NULL(ROW_VALUES(row)+2) || p==0 || p[0]==0){
+			p = (char *)VAL_STRING(ROW_VALUES(row) + 2);
+			if(VAL_NULL(ROW_VALUES(row) + 2) || p == 0 || p[0] == 0) {
 				uc.sock = 0;
 			} else {
-				if (parse_phostport(p, &host.s, &host.len,
-							&port, &proto)!=0) {
+				if(parse_phostport(p, &host.s, &host.len, &port, &proto) != 0) {
 					LM_ERR("bad socket <%s>...set to 0\n", p);
 					uc.sock = 0;
 				} else {
-					uc.sock = grep_sock_info( &host, (unsigned short)port, proto);
-					if (uc.sock==0) {
+					uc.sock =
+							grep_sock_info(&host, (unsigned short)port, proto);
+					if(uc.sock == 0) {
 						LM_DBG("non-local socket <%s>...set to 0\n", p);
 					}
 				}
@@ -231,8 +234,8 @@ int ul_ka_db_records(int partidx)
 			ur.domain = &dom->name;
 
 			/* user */
-			p  = (char*)VAL_STRING(ROW_VALUES(row) + 6);
-			if (VAL_NULL(ROW_VALUES(row)+6) || p==0 || p[0]==0) {
+			p = (char *)VAL_STRING(ROW_VALUES(row) + 6);
+			if(VAL_NULL(ROW_VALUES(row) + 6) || p == 0 || p[0] == 0) {
 				LM_ERR("empty username -> skipping\n");
 				continue;
 			}
@@ -244,8 +247,8 @@ int ul_ka_db_records(int partidx)
 			strcpy(aorbuf, p);
 
 			/* domain */
-			p  = (char*)VAL_STRING(ROW_VALUES(row) + 7);
-			if (!(VAL_NULL(ROW_VALUES(row)+7) || p==0 || p[0]==0)) {
+			p = (char *)VAL_STRING(ROW_VALUES(row) + 7);
+			if(!(VAL_NULL(ROW_VALUES(row) + 7) || p == 0 || p[0] == 0)) {
 				if(ur.aor.len + strlen(p) >= ULKA_AORBUF_SIZE - 2) {
 					LM_DBG("long aor ->skipping\n");
 					continue;
@@ -258,7 +261,7 @@ int ul_ka_db_records(int partidx)
 			ur.contacts = &uc;
 
 			/* tcpconn_id */
-			uc.tcpconn_id = VAL_INT(ROW_VALUES(row)+8);
+			uc.tcpconn_id = VAL_INT(ROW_VALUES(row) + 8);
 
 			ul_ka_urecord(&ur);
 		} /* row cycle */
@@ -281,12 +284,11 @@ int ul_ka_db_records(int partidx)
  * \return 0 on success, positive if buffer size was not sufficient, negative on failure
  */
 static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
-								unsigned int part_idx, unsigned int part_max,
-								int options)
+		unsigned int part_idx, unsigned int part_max, int options)
 {
 	struct socket_info *sock;
 	unsigned int dbflags;
-	db1_res_t* res = NULL;
+	db1_res_t *res = NULL;
 	db_row_t *row;
 	dlist_t *dom;
 	int port, proto;
@@ -302,9 +304,9 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
 	int shortage, needed;
 	db_key_t keys1[4]; /* where */
 	db_val_t vals1[4];
-	db_op_t  ops1[4];
+	db_op_t ops1[4];
 	db_key_t keys2[6]; /* select */
-	int n[2] = {2,6}; /* number of dynamic values used on key1/key2 */
+	int n[2] = {2, 6}; /* number of dynamic values used on key1/key2 */
 
 	cp = buf;
 	shortage = 0;
@@ -331,12 +333,12 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
 	ops1[1] = OP_EQ;
 	vals1[1].type = DB1_INT;
 	vals1[1].nul = 0;
-	if(_ul_max_partition>0)
+	if(_ul_max_partition > 0)
 		vals1[1].val.int_val = part_idx;
 	else
 		vals1[1].val.int_val = 0;
 
-	if (flags & ul_nat_bflag) {
+	if(flags & ul_nat_bflag) {
 		keys1[n[0]] = &ul_keepalive_col;
 		ops1[n[0]] = OP_EQ;
 		vals1[n[0]].type = DB1_INT;
@@ -344,7 +346,7 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
 		vals1[n[0]].val.int_val = 1;
 		n[0]++;
 	}
-	if(options&GAU_OPT_SERVER_ID) {
+	if(options & GAU_OPT_SERVER_ID) {
 		keys1[n[0]] = &ul_srv_id_col;
 		ops1[n[0]] = OP_EQ;
 		vals1[n[0]].type = DB1_INT;
@@ -355,17 +357,18 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
 
 	/* TODO: use part_idx and part_max on keys1 */
 
-	for (dom = _ksr_ul_root; dom!=NULL ; dom=dom->next) {
-		if (ul_dbf.use_table(ul_dbh, dom->d->name) < 0) {
+	for(dom = _ksr_ul_root; dom != NULL; dom = dom->next) {
+		if(ul_dbf.use_table(ul_dbh, dom->d->name) < 0) {
 			LM_ERR("sql use_table failed\n");
 			return -1;
 		}
-		if (ul_dbf.query(ul_dbh, keys1, ops1, vals1, keys2,
-							n[0], n[1], NULL, &res) <0 ) {
+		if(ul_dbf.query(
+				   ul_dbh, keys1, ops1, vals1, keys2, n[0], n[1], NULL, &res)
+				< 0) {
 			LM_ERR("query error\n");
 			return -1;
 		}
-		if( RES_ROW_N(res)==0 ) {
+		if(RES_ROW_N(res) == 0) {
 			ul_dbf.free_result(ul_dbh, res);
 			continue;
 		}
@@ -375,28 +378,26 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
 
 
 			/* received */
-			recv.s = (char*)VAL_STRING(ROW_VALUES(row));
-			if ( VAL_NULL(ROW_VALUES(row)) || recv.s==0 || recv.s[0]==0 ) {
+			recv.s = (char *)VAL_STRING(ROW_VALUES(row));
+			if(VAL_NULL(ROW_VALUES(row)) || recv.s == 0 || recv.s[0] == 0) {
 				recv.s = NULL;
 				recv.len = 0;
-			}
-			else {
+			} else {
 				recv.len = strlen(recv.s);
 			}
 
 			/* contact */
-			addr.s = (char*)VAL_STRING(ROW_VALUES(row)+1);
-			if (VAL_NULL(ROW_VALUES(row)+1) || addr.s==0 || addr.s[0]==0) {
+			addr.s = (char *)VAL_STRING(ROW_VALUES(row) + 1);
+			if(VAL_NULL(ROW_VALUES(row) + 1) || addr.s == 0 || addr.s[0] == 0) {
 				LM_ERR("empty contact -> skipping\n");
 				continue;
-			}
-			else {
+			} else {
 				addr.len = strlen(addr.s);
 			}
 
 			/* path */
-			path.s = (char*)VAL_STRING(ROW_VALUES(row)+4);
-			if (VAL_NULL(ROW_VALUES(row)+4) || path.s==0 || path.s[0]==0){
+			path.s = (char *)VAL_STRING(ROW_VALUES(row) + 4);
+			if(VAL_NULL(ROW_VALUES(row) + 4) || path.s == 0 || path.s[0] == 0) {
 				path.s = NULL;
 				path.len = 0;
 			} else {
@@ -404,52 +405,49 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
 			}
 
 			/* ruid */
-			ruid.s = (char*)VAL_STRING(ROW_VALUES(row)+5);
-			if (VAL_NULL(ROW_VALUES(row)+5) || ruid.s==0 || ruid.s[0]==0){
+			ruid.s = (char *)VAL_STRING(ROW_VALUES(row) + 5);
+			if(VAL_NULL(ROW_VALUES(row) + 5) || ruid.s == 0 || ruid.s[0] == 0) {
 				ruid.s = NULL;
 				ruid.len = 0;
 			} else {
 				ruid.len = strlen(ruid.s);
 			}
 
-			needed = (int)(sizeof(addr.len) + addr.len
-					+ sizeof(recv.len) + recv.len
-					+ sizeof(sock) + sizeof(dbflags)
-					+ sizeof(path.len) + path.len
-					+ sizeof(ruid.len) + ruid.len
-					+ sizeof(aorhash));
-			if (len < needed) {
-				shortage += needed ;
+			needed = (int)(sizeof(addr.len) + addr.len + sizeof(recv.len)
+						   + recv.len + sizeof(sock) + sizeof(dbflags)
+						   + sizeof(path.len) + path.len + sizeof(ruid.len)
+						   + ruid.len + sizeof(aorhash));
+			if(len < needed) {
+				shortage += needed;
 				continue;
 			}
 
 			/* write contact */
 			memcpy(cp, &addr.len, sizeof(addr.len));
-			cp = (char*)cp + sizeof(addr.len);
+			cp = (char *)cp + sizeof(addr.len);
 			memcpy(cp, addr.s, addr.len);
-			cp = (char*)cp + addr.len;
+			cp = (char *)cp + addr.len;
 
 			/* write received */
 			memcpy(cp, &recv.len, sizeof(recv.len));
-			cp = (char*)cp + sizeof(recv.len);
+			cp = (char *)cp + sizeof(recv.len);
 			/* copy received only if exist */
-			if(recv.len){
+			if(recv.len) {
 				memcpy(cp, recv.s, recv.len);
-				cp = (char*)cp + recv.len;
+				cp = (char *)cp + recv.len;
 			}
 
 			/* sock */
-			p  = (char*)VAL_STRING(ROW_VALUES(row) + 2);
-			if (VAL_NULL(ROW_VALUES(row)+2) || p==0 || p[0]==0){
+			p = (char *)VAL_STRING(ROW_VALUES(row) + 2);
+			if(VAL_NULL(ROW_VALUES(row) + 2) || p == 0 || p[0] == 0) {
 				sock = 0;
 			} else {
-				if (parse_phostport( p, &host.s, &host.len,
-				&port, &proto)!=0) {
+				if(parse_phostport(p, &host.s, &host.len, &port, &proto) != 0) {
 					LM_ERR("bad socket <%s>...set to 0\n", p);
 					sock = 0;
 				} else {
-					sock = grep_sock_info( &host, (unsigned short)port, proto);
-					if (sock==0) {
+					sock = grep_sock_info(&host, (unsigned short)port, proto);
+					if(sock == 0) {
 						LM_DBG("non-local socket <%s>...set to 0\n", p);
 					}
 				}
@@ -460,31 +458,31 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
 
 			/* write sock and flags */
 			memcpy(cp, &sock, sizeof(sock));
-			cp = (char*)cp + sizeof(sock);
+			cp = (char *)cp + sizeof(sock);
 			memcpy(cp, &dbflags, sizeof(dbflags));
-			cp = (char*)cp + sizeof(dbflags);
+			cp = (char *)cp + sizeof(dbflags);
 
 			/* write path */
 			memcpy(cp, &path.len, sizeof(path.len));
-			cp = (char*)cp + sizeof(path.len);
+			cp = (char *)cp + sizeof(path.len);
 			/* copy path only if exist */
-			if(path.len){
+			if(path.len) {
 				memcpy(cp, path.s, path.len);
-				cp = (char*)cp + path.len;
+				cp = (char *)cp + path.len;
 			}
 
 			/* write ruid */
 			memcpy(cp, &ruid.len, sizeof(ruid.len));
-			cp = (char*)cp + sizeof(ruid.len);
+			cp = (char *)cp + sizeof(ruid.len);
 			/* copy ruid only if exist */
-			if(ruid.len){
+			if(ruid.len) {
 				memcpy(cp, ruid.s, ruid.len);
-				cp = (char*)cp + ruid.len;
+				cp = (char *)cp + ruid.len;
 			}
 			/* aorhash not used for db-only records, but it is added
 			 * (as 0) to match the struct used for mem records */
 			memcpy(cp, &aorhash, sizeof(aorhash));
-			cp = (char*)cp + sizeof(aorhash);
+			cp = (char *)cp + sizeof(aorhash);
 
 			len -= needed;
 		} /* row cycle */
@@ -493,11 +491,11 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
 	} /* domain cycle */
 
 	/* len < 0 is possible, if size of the buffer < sizeof(c->c.len) */
-	if (len >= 0)
+	if(len >= 0)
 		memset(cp, 0, sizeof(addr.len));
 
 	/* Shouldn't happen */
-	if (shortage > 0 && len > shortage) {
+	if(shortage > 0 && len > shortage) {
 		abort();
 	}
 
@@ -519,8 +517,7 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags,
  * \return 0 on success, positive if buffer size was not sufficient, negative on failure
  */
 static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
-								unsigned int part_idx, unsigned int part_max,
-								int options)
+		unsigned int part_idx, unsigned int part_max, int options)
 {
 	dlist_t *p;
 	urecord_t *r;
@@ -534,45 +531,42 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
 	time_t tnow = 0;
 
 
-	if(ul_keepalive_timeout>0)
+	if(ul_keepalive_timeout > 0)
 		tnow = time(NULL);
 
 	/* Reserve space for terminating 0000 */
 	len -= sizeof(c->c.len);
 
-	for (p = _ksr_ul_root; p != NULL; p = p->next) {
+	for(p = _ksr_ul_root; p != NULL; p = p->next) {
 
-		for(i=0; i<p->d->size; i++) {
+		for(i = 0; i < p->d->size; i++) {
 
-			if ( (i % part_max) != part_idx )
+			if((i % part_max) != part_idx)
 				continue;
 
 			lock_ulslot(p->d, i);
-			if(p->d->table[i].n<=0)
-			{
+			if(p->d->table[i].n <= 0) {
 				unlock_ulslot(p->d, i);
 				continue;
 			}
-			for (r = p->d->table[i].first; r != NULL; r = r->next) {
-				for (c = r->contacts; c != NULL; c = c->next) {
-					if (c->c.len <= 0)
+			for(r = p->d->table[i].first; r != NULL; r = r->next) {
+				for(c = r->contacts; c != NULL; c = c->next) {
+					if(c->c.len <= 0)
 						continue;
 					/*
 					 * List only contacts that have all requested
 					 * flags set
 					 */
-					if ((c->cflags & flags) != flags)
+					if((c->cflags & flags) != flags)
 						continue;
 
-					if(options&GAU_OPT_SERVER_ID && server_id!=c->server_id)
+					if(options & GAU_OPT_SERVER_ID && server_id != c->server_id)
 						continue;
 
-					if(ul_keepalive_timeout>0 && c->last_keepalive>0)
-					{
-						if(c->sock!=NULL && c->sock->proto==PROTO_UDP)
-						{
-							if(c->last_keepalive+ul_keepalive_timeout < tnow)
-							{
+					if(ul_keepalive_timeout > 0 && c->last_keepalive > 0) {
+						if(c->sock != NULL && c->sock->proto == PROTO_UDP) {
+							if(c->last_keepalive + ul_keepalive_timeout
+									< tnow) {
 								/* set contact as expired in 10s */
 								if(c->expires > tnow + 10)
 									c->expires = tnow + 10;
@@ -582,34 +576,34 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
 					}
 
 					needed = (int)(sizeof(c->c.len) + c->c.len
-							+ sizeof(c->received.len) + c->received.len
-							+ sizeof(c->sock) + sizeof(c->cflags)
-							+ sizeof(c->path.len) + c->path.len
-							+ sizeof(c->ruid.len) + c->ruid.len
-							+ sizeof(r->aorhash));
-					if (len >= needed) {
+								   + sizeof(c->received.len) + c->received.len
+								   + sizeof(c->sock) + sizeof(c->cflags)
+								   + sizeof(c->path.len) + c->path.len
+								   + sizeof(c->ruid.len) + c->ruid.len
+								   + sizeof(r->aorhash));
+					if(len >= needed) {
 						memcpy(cp, &c->c.len, sizeof(c->c.len));
-						cp = (char*)cp + sizeof(c->c.len);
+						cp = (char *)cp + sizeof(c->c.len);
 						memcpy(cp, c->c.s, c->c.len);
-						cp = (char*)cp + c->c.len;
-						memcpy(cp,&c->received.len,sizeof(c->received.len));
-						cp = (char*)cp + sizeof(c->received.len);
+						cp = (char *)cp + c->c.len;
+						memcpy(cp, &c->received.len, sizeof(c->received.len));
+						cp = (char *)cp + sizeof(c->received.len);
 						memcpy(cp, c->received.s, c->received.len);
-						cp = (char*)cp + c->received.len;
+						cp = (char *)cp + c->received.len;
 						memcpy(cp, &c->sock, sizeof(c->sock));
-						cp = (char*)cp + sizeof(c->sock);
+						cp = (char *)cp + sizeof(c->sock);
 						memcpy(cp, &c->cflags, sizeof(c->cflags));
-						cp = (char*)cp + sizeof(c->cflags);
+						cp = (char *)cp + sizeof(c->cflags);
 						memcpy(cp, &c->path.len, sizeof(c->path.len));
-						cp = (char*)cp + sizeof(c->path.len);
+						cp = (char *)cp + sizeof(c->path.len);
 						memcpy(cp, c->path.s, c->path.len);
-						cp = (char*)cp + c->path.len;
+						cp = (char *)cp + c->path.len;
 						memcpy(cp, &c->ruid.len, sizeof(c->ruid.len));
-						cp = (char*)cp + sizeof(c->ruid.len);
+						cp = (char *)cp + sizeof(c->ruid.len);
 						memcpy(cp, c->ruid.s, c->ruid.len);
-						cp = (char*)cp + c->ruid.len;
+						cp = (char *)cp + c->ruid.len;
 						memcpy(cp, &r->aorhash, sizeof(r->aorhash));
-						cp = (char*)cp + sizeof(r->aorhash);
+						cp = (char *)cp + sizeof(r->aorhash);
 						len -= needed;
 					} else {
 						shortage += needed;
@@ -620,11 +614,11 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
 		}
 	}
 	/* len < 0 is possible, if size of the buffer < sizeof(c->c.len) */
-	if (len >= 0)
+	if(len >= 0)
 		memset(cp, 0, sizeof(c->c.len));
 
 	/* Shouldn't happen */
-	if (shortage > 0 && len > shortage) {
+	if(shortage > 0 && len > shortage) {
 		abort();
 	}
 
@@ -634,7 +628,6 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
 }
 
 
-
 /*!
  * \brief Get all contacts from the usrloc, in partitions if wanted
  *
@@ -669,21 +662,22 @@ static inline int get_all_mem_ucontacts(void *buf, int len, unsigned int flags,
  * \return 0 on success, positive if buffer size was not sufficient, negative on failure
  */
 int get_all_ucontacts(void *buf, int len, unsigned int flags,
-								unsigned int part_idx, unsigned int part_max,
-								int options)
+		unsigned int part_idx, unsigned int part_max, int options)
 {
-	if (ul_db_mode==DB_ONLY)
-		return get_all_db_ucontacts( buf, len, flags, part_idx, part_max, options);
+	if(ul_db_mode == DB_ONLY)
+		return get_all_db_ucontacts(
+				buf, len, flags, part_idx, part_max, options);
 	else
-		return get_all_mem_ucontacts( buf, len, flags, part_idx, part_max, options);
+		return get_all_mem_ucontacts(
+				buf, len, flags, part_idx, part_max, options);
 }
 
 
 /**
  *
  */
-int ul_update_keepalive(unsigned int _aorhash, str *_ruid, time_t tval,
-		unsigned int rtrip)
+int ul_update_keepalive(
+		unsigned int _aorhash, str *_ruid, time_t tval, unsigned int rtrip)
 {
 	dlist_t *p;
 	urecord_t *r;
@@ -692,32 +686,28 @@ int ul_update_keepalive(unsigned int _aorhash, str *_ruid, time_t tval,
 
 	/* todo: get location domain via param */
 
-	for (p = _ksr_ul_root; p != NULL; p = p->next)
-	{
-		i = _aorhash&(p->d->size-1);
+	for(p = _ksr_ul_root; p != NULL; p = p->next) {
+		i = _aorhash & (p->d->size - 1);
 		lock_ulslot(p->d, i);
-		if(p->d->table[i].n<=0)
-		{
+		if(p->d->table[i].n <= 0) {
 			unlock_ulslot(p->d, i);
 			continue;
 		}
-		for (r = p->d->table[i].first; r != NULL; r = r->next)
-		{
-			if(r->aorhash==_aorhash)
-			{
-				for (c = r->contacts; c != NULL; c = c->next)
-				{
-					if (c->c.len <= 0 || c->ruid.len<=0)
+		for(r = p->d->table[i].first; r != NULL; r = r->next) {
+			if(r->aorhash == _aorhash) {
+				for(c = r->contacts; c != NULL; c = c->next) {
+					if(c->c.len <= 0 || c->ruid.len <= 0)
 						continue;
-					if(c->ruid.len==_ruid->len
-							&& !memcmp(c->ruid.s, _ruid->s, _ruid->len))
-					{
+					if(c->ruid.len == _ruid->len
+							&& !memcmp(c->ruid.s, _ruid->s, _ruid->len)) {
 						/* found */
 						c->last_keepalive = tval;
 						c->ka_roundtrip = rtrip;
-						LM_DBG("updated keepalive for [%.*s:%u] to %u (rtrip: %u)\n",
+						LM_DBG("updated keepalive for [%.*s:%u] to %u (rtrip: "
+							   "%u)\n",
 								_ruid->len, _ruid->s, _aorhash,
-								(unsigned int)c->last_keepalive, c->ka_roundtrip);
+								(unsigned int)c->last_keepalive,
+								c->ka_roundtrip);
 						unlock_ulslot(p->d, i);
 						return 0;
 					}
@@ -746,23 +736,23 @@ int ul_refresh_keepalive(unsigned int _aorhash, str *_ruid)
  * function must be called before the server forks if it should
  * be available to all processes
  */
-static inline int new_dlist(str* _n, dlist_t** _d)
+static inline int new_dlist(str *_n, dlist_t **_d)
 {
-	dlist_t* ptr;
+	dlist_t *ptr;
 
 	/* Domains are created before ser forks,
 	 * so we can create them using pkg_malloc
 	 */
-	ptr = (dlist_t*)shm_malloc(sizeof(dlist_t));
-	if (ptr == 0) {
+	ptr = (dlist_t *)shm_malloc(sizeof(dlist_t));
+	if(ptr == 0) {
 		SHM_MEM_ERROR;
 		return -1;
 	}
 	memset(ptr, 0, sizeof(dlist_t));
 
 	/* copy domain name as null terminated string */
-	ptr->name.s = (char*)shm_malloc(_n->len+1);
-	if (ptr->name.s == 0) {
+	ptr->name.s = (char *)shm_malloc(_n->len + 1);
+	if(ptr->name.s == 0) {
 		SHM_MEM_ERROR;
 		shm_free(ptr);
 		return -2;
@@ -772,7 +762,7 @@ static inline int new_dlist(str* _n, dlist_t** _d)
 	ptr->name.len = _n->len;
 	ptr->name.s[ptr->name.len] = 0;
 
-	if (new_udomain(&(ptr->name), ul_hash_size, &(ptr->d)) < 0) {
+	if(new_udomain(&(ptr->name), ul_hash_size, &(ptr->d)) < 0) {
 		LM_ERR("creating domain structure failed\n");
 		shm_free(ptr->name.s);
 		shm_free(ptr);
@@ -791,9 +781,9 @@ static inline int new_dlist(str* _n, dlist_t** _d)
  * \param _d usrloc domain
  * \return 0 on success, -1 on failure
  */
-int get_udomain(const char* _n, udomain_t** _d)
+int get_udomain(const char *_n, udomain_t **_d)
 {
-	dlist_t* d;
+	dlist_t *d;
 	str s;
 
 	if(_n == NULL) {
@@ -801,14 +791,14 @@ int get_udomain(const char* _n, udomain_t** _d)
 		goto notfound;
 	}
 
-	s.s = (char*)_n;
+	s.s = (char *)_n;
 	s.len = strlen(_n);
 	if(s.len <= 0) {
 		LM_ERR("empty location table name\n");
 		goto notfound;
 	}
 
-	if (find_dlist(&s, &d) == 0) {
+	if(find_dlist(&s, &d) == 0) {
 		*_d = d->d;
 		return 0;
 	}
@@ -828,21 +818,21 @@ notfound:
  * \param _d new created domain
  * \return 0 on success, -1 on failure
  */
-int register_udomain(const char* _n, udomain_t** _d)
+int register_udomain(const char *_n, udomain_t **_d)
 {
-	dlist_t* d;
+	dlist_t *d;
 	str s;
-	db1_con_t* con;
+	db1_con_t *con;
 
-	s.s = (char*)_n;
+	s.s = (char *)_n;
 	s.len = strlen(_n);
 
-	if (find_dlist(&s, &d) == 0) {
+	if(find_dlist(&s, &d) == 0) {
 		*_d = d->d;
 		return 0;
 	}
 
-	if (new_dlist(&s, &d) < 0) {
+	if(new_dlist(&s, &d) < 0) {
 		LM_ERR("failed to create new domain\n");
 		return -1;
 	}
@@ -850,20 +840,21 @@ int register_udomain(const char* _n, udomain_t** _d)
 	/* Test tables from database if we are gonna
 	 * to use database
 	 */
-	if (ul_db_mode != NO_DB) {
+	if(ul_db_mode != NO_DB) {
 		con = ul_dbf.init(&ul_db_url);
-		if (!con) {
+		if(!con) {
 			LM_ERR("failed to open database connection\n");
 			goto dberror;
 		}
 
 		if(ul_version_table != 0
-				&& db_check_table_version(&ul_dbf, con, &s, UL_TABLE_VERSION) < 0) {
+				&& db_check_table_version(&ul_dbf, con, &s, UL_TABLE_VERSION)
+						   < 0) {
 			DB_TABLE_VERSION_ERROR(s);
 			goto dberror;
 		}
 		/* test if DB really exists */
-		if (testdb_udomain(con, d->d) < 0) {
+		if(testdb_udomain(con, d->d) < 0) {
 			LM_ERR("testing domain '%.*s' failed\n", s.len, ZSW(s.s));
 			goto dberror;
 		}
@@ -879,7 +870,8 @@ int register_udomain(const char* _n, udomain_t** _d)
 	return 0;
 
 dberror:
-	if (con) ul_dbf.close(con);
+	if(con)
+		ul_dbf.close(con);
 	con = 0;
 	free_udomain(d->d);
 	shm_free(d->name.s);
@@ -893,7 +885,7 @@ dberror:
  */
 void free_all_udomains(void)
 {
-	dlist_t* ptr;
+	dlist_t *ptr;
 
 	while(_ksr_ul_root) {
 		ptr = _ksr_ul_root;
@@ -910,9 +902,9 @@ void free_all_udomains(void)
  * \brief Print all domains, just for debugging
  * \param _f output file
  */
-void print_all_udomains(FILE* _f)
+void print_all_udomains(FILE *_f)
 {
-	dlist_t* ptr;
+	dlist_t *ptr;
 
 	ptr = _ksr_ul_root;
 
@@ -933,14 +925,13 @@ unsigned long get_number_of_users(void)
 {
 	long numberOfUsers = 0;
 
-	dlist_t* current_dlist;
+	dlist_t *current_dlist;
 
 	current_dlist = _ksr_ul_root;
 
-	while (current_dlist)
-	{
+	while(current_dlist) {
 		numberOfUsers += get_stat_val(current_dlist->d->users);
-		current_dlist  = current_dlist->next;
+		current_dlist = current_dlist->next;
 	}
 
 	return numberOfUsers;
@@ -954,21 +945,21 @@ unsigned long get_number_of_users(void)
 int synchronize_all_udomains(int istart, int istep)
 {
 	int res = 0;
-	dlist_t* ptr;
+	dlist_t *ptr;
 
 	ul_get_act_time(); /* Get and save actual time */
 
-	if (ul_db_mode==DB_ONLY) {
+	if(ul_db_mode == DB_ONLY) {
 		if(istart == 0) {
-			for( ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) {
+			for(ptr = _ksr_ul_root; ptr; ptr = ptr->next) {
 				res |= db_timer_udomain(ptr->d);
 			}
 		}
-		if (ul_ka_mode != ULKA_NONE) {
+		if(ul_ka_mode != ULKA_NONE) {
 			ul_ka_db_records((unsigned int)istart);
 		}
 	} else {
-		for( ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) {
+		for(ptr = _ksr_ul_root; ptr; ptr = ptr->next) {
 			mem_timer_udomain(ptr->d, istart, istep);
 		}
 	}
@@ -983,11 +974,11 @@ int synchronize_all_udomains(int istart, int istep)
 int ul_db_clean_udomains(void)
 {
 	int res = 0;
-	dlist_t* ptr;
+	dlist_t *ptr;
 
 	ul_get_act_time(); /* Get and save actual time */
 
-	for( ptr=_ksr_ul_root ; ptr ; ptr=ptr->next)
+	for(ptr = _ksr_ul_root; ptr; ptr = ptr->next)
 		res |= db_timer_udomain(ptr->d);
 
 	return res;
@@ -999,12 +990,12 @@ int ul_db_clean_udomains(void)
  * \param _p pointer to domain if found
  * \return 1 if domain was found, 0 otherwise
  */
-int find_domain(str* _d, udomain_t** _p)
+int find_domain(str *_d, udomain_t **_p)
 {
-	dlist_t* d;
+	dlist_t *d;
 
-	if (find_dlist(_d, &d) == 0) {
-	        *_p = d->d;
+	if(find_dlist(_d, &d) == 0) {
+		*_p = d->d;
 		return 0;
 	}
 

+ 9 - 8
src/modules/usrloc/dlist.h

@@ -36,10 +36,11 @@
 /*!
  * List of all domains registered with usrloc
  */
-typedef struct dlist {
-	str name;            /*!< Name of the domain (null terminated) */
-	udomain_t* d;        /*!< Payload */
-	struct dlist* next;  /*!< Next element in the list */
+typedef struct dlist
+{
+	str name;			/*!< Name of the domain (null terminated) */
+	udomain_t *d;		/*!< Payload */
+	struct dlist *next; /*!< Next element in the list */
 } dlist_t;
 
 /*! \brief Global list of all registered domains */
@@ -56,7 +57,7 @@ extern dlist_t *_ksr_ul_root;
  * \param _d new created domain
  * \return 0 on success, -1 on failure
  */
-int register_udomain(const char* _n, udomain_t** _d);
+int register_udomain(const char *_n, udomain_t **_d);
 
 
 /*!
@@ -69,7 +70,7 @@ void free_all_udomains(void);
  * \brief Print all domains, just for debugging
  * \param _f output file
  */
-void print_all_udomains(FILE* _f);
+void print_all_udomains(FILE *_f);
 
 
 /*!
@@ -123,7 +124,7 @@ int get_all_ucontacts(void *buf, int len, unsigned int flags,
  * \param _d usrloc domain (location table)
  * \return 0 on success, -1 on failure
  */
- int get_udomain(const char* _n, udomain_t** _d);
+int get_udomain(const char *_n, udomain_t **_d);
 
 /*!
  * \brief Loops through all domains summing up the number of users
@@ -138,7 +139,7 @@ unsigned long get_number_of_users(void);
  * \param _p pointer to domain if found
  * \return 1 if domain was found, 0 otherwise
  */
-int find_domain(str* _d, udomain_t** _p);
+int find_domain(str *_d, udomain_t **_p);
 
 
 /*!

+ 10 - 11
src/modules/usrloc/hslot.c

@@ -26,7 +26,6 @@
  */
 
 
-
 #include "hslot.h"
 
 /*!
@@ -35,13 +34,13 @@
  * \param _s hash slot
  * \param n used to get the slot number (modulo number or locks)
  */
-int init_slot(struct udomain* _d, hslot_t* _s, int n)
+int init_slot(struct udomain *_d, hslot_t *_s, int n)
 {
 	_s->n = 0;
 	_s->first = 0;
 	_s->last = 0;
 	_s->d = _d;
-	if(rec_lock_init(&_s->rlock)==NULL) {
+	if(rec_lock_init(&_s->rlock) == NULL) {
 		LM_ERR("failed to initialize the slock (%d)\n", n);
 		return -1;
 	}
@@ -53,9 +52,9 @@ int init_slot(struct udomain* _d, hslot_t* _s, int n)
  * \brief Deinitialize given slot structure
  * \param _s hash slot
  */
-void deinit_slot(hslot_t* _s)
+void deinit_slot(hslot_t *_s)
 {
-	struct urecord* ptr;
+	struct urecord *ptr;
 
 	/* Remove all elements */
 	while(_s->first) {
@@ -67,7 +66,7 @@ void deinit_slot(hslot_t* _s)
 
 	_s->n = 0;
 	_s->last = 0;
-    _s->d = 0;
+	_s->d = 0;
 }
 
 
@@ -76,9 +75,9 @@ void deinit_slot(hslot_t* _s)
  * \param _s hash slot
  * \param _r added record
  */
-void slot_add(hslot_t* _s, struct urecord* _r)
+void slot_add(hslot_t *_s, struct urecord *_r)
 {
-	if (_s->n == 0) {
+	if(_s->n == 0) {
 		_s->first = _s->last = _r;
 	} else {
 		_r->prev = _s->last;
@@ -95,15 +94,15 @@ void slot_add(hslot_t* _s, struct urecord* _r)
  * \param _s hash slot
  * \param _r removed record
  */
-void slot_rem(hslot_t* _s, struct urecord* _r)
+void slot_rem(hslot_t *_s, struct urecord *_r)
 {
-	if (_r->prev) {
+	if(_r->prev) {
 		_r->prev->next = _r->next;
 	} else {
 		_s->first = _r->next;
 	}
 
-	if (_r->next) {
+	if(_r->next) {
 		_r->next->prev = _r->prev;
 	} else {
 		_s->last = _r->prev;

+ 11 - 11
src/modules/usrloc/hslot.h

@@ -24,7 +24,6 @@
  */
 
 
-
 #ifndef HSLOT_H
 #define HSLOT_H
 
@@ -38,35 +37,36 @@ struct udomain;
 struct urecord;
 
 
-typedef struct hslot {
-	int n;                  /*!< Number of elements in the collision slot */
-	struct urecord* first;  /*!< First element in the list */
-	struct urecord* last;   /*!< Last element in the list */
-	struct udomain* d;      /*!< Domain we belong to */
-	rec_lock_t rlock;       /*!< Recursive lock for hash entry */
+typedef struct hslot
+{
+	int n;				   /*!< Number of elements in the collision slot */
+	struct urecord *first; /*!< First element in the list */
+	struct urecord *last;  /*!< Last element in the list */
+	struct udomain *d;	   /*!< Domain we belong to */
+	rec_lock_t rlock;	   /*!< Recursive lock for hash entry */
 } hslot_t;
 
 /*! \brief
  * Initialize slot structure
  */
-int init_slot(struct udomain* _d, hslot_t* _s, int n);
+int init_slot(struct udomain *_d, hslot_t *_s, int n);
 
 
 /*! \brief
  * Deinitialize given slot structure
  */
-void deinit_slot(hslot_t* _s);
+void deinit_slot(hslot_t *_s);
 
 
 /*! \brief
  * Add an element to slot linked list
  */
-void slot_add(hslot_t* _s, struct urecord* _r);
+void slot_add(hslot_t *_s, struct urecord *_r);
 
 
 /*! \brief
  * Remove an element from slot linked list
  */
-void slot_rem(hslot_t* _s, struct urecord* _r);
+void slot_rem(hslot_t *_s, struct urecord *_r);
 
 #endif /* HSLOT_H */

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 260 - 236
src/modules/usrloc/ucontact.c


+ 17 - 17
src/modules/usrloc/ucontact.h

@@ -46,15 +46,15 @@
  * \param _ci contact informations
  * \return new created contact on success, 0 on failure
  */
-ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact,
-		ucontact_info_t* _ci);
+ucontact_t *new_ucontact(
+		str *_dom, str *_aor, str *_contact, ucontact_info_t *_ci);
 
 
 /*!
  * \brief Free all memory associated with given contact structure
  * \param _c freed contact
  */
-void free_ucontact(ucontact_t* _c);
+void free_ucontact(ucontact_t *_c);
 
 
 /*!
@@ -62,7 +62,7 @@ void free_ucontact(ucontact_t* _c);
  * \param _f output file
  * \param _c printed contact
  */
-void print_ucontact(FILE* _f, ucontact_t* _c);
+void print_ucontact(FILE *_f, ucontact_t *_c);
 
 
 /*!
@@ -71,7 +71,7 @@ void print_ucontact(FILE* _f, ucontact_t* _c);
  * \param _ci contact informations
  * \return 0
  */
-int mem_update_ucontact(ucontact_t* _c, ucontact_info_t *_ci);
+int mem_update_ucontact(ucontact_t *_c, ucontact_info_t *_ci);
 
 
 /* ===== State transition functions - for write back cache scheme ======== */
@@ -80,7 +80,7 @@ int mem_update_ucontact(ucontact_t* _c, ucontact_info_t *_ci);
  * \brief Update state of the contact if we are using write-back scheme
  * \param _c updated contact
  */
-void st_update_ucontact(ucontact_t* _c);
+void st_update_ucontact(ucontact_t *_c);
 
 
 /*!
@@ -88,7 +88,7 @@ void st_update_ucontact(ucontact_t* _c);
  * \param _c updated contact
  * \return 1 if the contact should be deleted from memory immediately, 0 otherwise
  */
-int st_delete_ucontact(ucontact_t* _c);
+int st_delete_ucontact(ucontact_t *_c);
 
 
 /*!
@@ -96,7 +96,7 @@ int st_delete_ucontact(ucontact_t* _c);
  * \param _c expired contact
  * \return 1 if the contact should be removed from the database and 0 otherwise
  */
-int st_expired_ucontact(ucontact_t* _c);
+int st_expired_ucontact(ucontact_t *_c);
 
 
 /*!
@@ -104,7 +104,7 @@ int st_expired_ucontact(ucontact_t* _c);
  * \param _c flushed contact
  * \return 1 if the contact should be inserted, 2 if update and 0 otherwise
  */
-int st_flush_ucontact(ucontact_t* _c);
+int st_flush_ucontact(ucontact_t *_c);
 
 
 /* ==== Database related functions ====== */
@@ -114,7 +114,7 @@ int st_flush_ucontact(ucontact_t* _c);
  * \param _c inserted contact
  * \return 0 on success, -1 on failure
  */
-int db_insert_ucontact(ucontact_t* _c);
+int db_insert_ucontact(ucontact_t *_c);
 
 
 /*!
@@ -122,7 +122,7 @@ int db_insert_ucontact(ucontact_t* _c);
  * \param _c updated contact
  * \return 0 on success, -1 on failure
  */
-int db_update_ucontact(ucontact_t* _c);
+int db_update_ucontact(ucontact_t *_c);
 
 
 /*!
@@ -130,7 +130,7 @@ int db_update_ucontact(ucontact_t* _c);
  * \param _c deleted contact
  * \return 0 on success, -1 on failure
  */
-int db_delete_ucontact(ucontact_t* _c);
+int db_delete_ucontact(ucontact_t *_c);
 
 /* ====== Module interface ====== */
 
@@ -141,7 +141,7 @@ int db_delete_ucontact(ucontact_t* _c);
  * \param _ci new contact informations
  * \return 0 on success, -1 on failure
  */
-int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci);
+int update_ucontact(struct urecord *_r, ucontact_t *_c, ucontact_info_t *_ci);
 
 /* ====== per contact attributes ====== */
 
@@ -156,7 +156,7 @@ int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci);
  * \param _ruid usrloc record unique id
  * \return 0 on success, -1 on failure
  */
-int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid);
+int uldb_delete_attrs(str *_dname, str *_user, str *_domain, str *_ruid);
 
 /*!
  * \brief Insert contact attributes into the database
@@ -167,8 +167,8 @@ int uldb_delete_attrs(str* _dname, str *_user, str *_domain, str *_ruid);
  * \param _xhead head of xavp list
  * \return 0 on success, -1 on failure
  */
-int uldb_insert_attrs(str *_dname, str *_user, str *_domain,
-        str *_ruid, sr_xavp_t *_xhead);
+int uldb_insert_attrs(
+		str *_dname, str *_user, str *_domain, str *_ruid, sr_xavp_t *_xhead);
 
 /*!
  * \brief Set the value for cloning the xavp list to contact structure
@@ -176,6 +176,6 @@ int uldb_insert_attrs(str *_dname, str *_user, str *_domain,
  */
 void ul_set_xavp_contact_clone(int v);
 
-int uldb_delete_attrs_ruid(str* _dname, str *_ruid);
+int uldb_delete_attrs_ruid(str *_dname, str *_ruid);
 
 #endif

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 223 - 212
src/modules/usrloc/udomain.c


+ 27 - 26
src/modules/usrloc/udomain.h

@@ -37,21 +37,22 @@
 #include "hslot.h"
 #include "usrloc.h"
 
-struct hslot;   /*!< Hash table slot */
+struct hslot;	/*!< Hash table slot */
 struct urecord; /*!< Usrloc record */
 
 
 /*! \brief
  * The structure represents a usrloc domain
  */
-struct udomain {
-	str* name;                 /*!< Domain name (NULL terminated) */
-	int size;                  /*!< Hash table size */
-	struct hslot* table;       /*!< Hash table - array of collision slots */
+struct udomain
+{
+	str *name;			 /*!< Domain name (NULL terminated) */
+	int size;			 /*!< Hash table size */
+	struct hslot *table; /*!< Hash table - array of collision slots */
 	/* statistics */
-	stat_var *users;           /*!< no of registered users */
-	stat_var *contacts;        /*!< no of registered contacts */
-	stat_var *expires;         /*!< no of expires */
+	stat_var *users;	/*!< no of registered users */
+	stat_var *contacts; /*!< no of registered contacts */
+	stat_var *expires;	/*!< no of expires */
 };
 
 
@@ -63,20 +64,20 @@ struct udomain {
  * \param _d new created domain
  * \return 0 on success, -1 on failure
  */
-int new_udomain(str* _n, int _s, udomain_t** _d);
+int new_udomain(str *_n, int _s, udomain_t **_d);
 
 
 /*!
  * \brief Free all memory allocated for the domain
  * \param _d freed domain
  */
-void free_udomain(udomain_t* _d);
+void free_udomain(udomain_t *_d);
 
 
 /*!
  * \brief Print udomain, debugging helper function
  */
-void print_udomain(FILE* _f, udomain_t* _d);
+void print_udomain(FILE *_f, udomain_t *_d);
 
 
 /*!
@@ -88,7 +89,7 @@ void print_udomain(FILE* _f, udomain_t* _d);
  * \param _d loaded domain
  * \return 0 on success, -1 on failure
  */
-int preload_udomain(db1_con_t* _c, udomain_t* _d);
+int preload_udomain(db1_con_t *_c, udomain_t *_d);
 
 
 /*!
@@ -96,7 +97,7 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d);
  * \param con database connection
  * \param d domain
  */
-int testdb_udomain(db1_con_t* con, udomain_t* d);
+int testdb_udomain(db1_con_t *con, udomain_t *d);
 
 
 /*!
@@ -104,7 +105,7 @@ int testdb_udomain(db1_con_t* con, udomain_t* d);
  * \param _d cleaned domain
  * \return 0 on success, -1 on failure
  */
-int db_timer_udomain(udomain_t* _d);
+int db_timer_udomain(udomain_t *_d);
 
 
 /*!
@@ -113,7 +114,7 @@ int db_timer_udomain(udomain_t* _d);
  * \param istart index of hash table slot to start processing
  * \param istep step through hash table slots to process
  */
-void mem_timer_udomain(udomain_t* _d, int istart, int istep);
+void mem_timer_udomain(udomain_t *_d, int istart, int istep);
 
 
 /*!
@@ -123,7 +124,7 @@ void mem_timer_udomain(udomain_t* _d, int istart, int istep);
  * \param _r new created record
  * \return 0 on success, -1 on failure
  */
-int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
+int mem_insert_urecord(udomain_t *_d, str *_aor, struct urecord **_r);
 
 
 /*!
@@ -131,13 +132,13 @@ int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  * \param _d domain the record belongs to
  * \param _r deleted record
  */
-void mem_delete_urecord(udomain_t* _d, struct urecord* _r);
+void mem_delete_urecord(udomain_t *_d, struct urecord *_r);
 
 
 /*! \brief
  * Timer handler for given domain
  */
-void lock_udomain(udomain_t* _d, str *_aor);
+void lock_udomain(udomain_t *_d, str *_aor);
 
 
 /*!
@@ -145,7 +146,7 @@ void lock_udomain(udomain_t* _d, str *_aor);
  * \param _d domain
  * \param _aor address of record, uses as hash source for the lock slot
  */
-void unlock_udomain(udomain_t* _d, str *_aor);
+void unlock_udomain(udomain_t *_d, str *_aor);
 
 
 /*!
@@ -153,14 +154,14 @@ void unlock_udomain(udomain_t* _d, str *_aor);
  * \param _d domain
  * \param i slot number
  */
-void lock_ulslot(udomain_t* _d, int i);
+void lock_ulslot(udomain_t *_d, int i);
 
 /*!
  * \brief Release lock for a slot
  * \param _d domain
  * \param i slot number
  */
-void unlock_ulslot(udomain_t* _d, int i);
+void unlock_ulslot(udomain_t *_d, int i);
 
 /* ===== module interface ======= */
 
@@ -172,7 +173,7 @@ void unlock_ulslot(udomain_t* _d, int i);
  * \param _r new created record
  * \return return 0 on success, -1 on failure
  */
-int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
+int insert_urecord(udomain_t *_d, str *_aor, struct urecord **_r);
 
 
 /*!
@@ -182,7 +183,7 @@ int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  * \param _r new created record
  * \return 0 if a record was found, 1 if nothing could be found
  */
-int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
+int get_urecord(udomain_t *_d, str *_aor, struct urecord **_r);
 
 /*!
  * \brief Obtain a urecord pointer if the urecord exists in domain (lock slot)
@@ -193,8 +194,8 @@ int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
  * \param _c store pointer to contact structure
  * \return 0 if a record was found, 1 if nothing could be found
  */
-int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash,
-		str *_ruid, struct urecord** _r, struct ucontact** _c);
+int get_urecord_by_ruid(udomain_t *_d, unsigned int _aorhash, str *_ruid,
+		struct urecord **_r, struct ucontact **_c);
 
 /*!
  * \brief Delete a urecord from domain
@@ -203,7 +204,7 @@ int get_urecord_by_ruid(udomain_t* _d, unsigned int _aorhash,
  * \param _r deleted record
  * \return 0 on success, -1 if the record could not be deleted
  */
-int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r);
+int delete_urecord(udomain_t *_d, str *_aor, struct urecord *_r);
 
 
 /* ===== per-contact attributes ======= */

+ 16 - 20
src/modules/usrloc/ul_callback.c

@@ -35,15 +35,14 @@
 #include "ul_callback.h"
 #include "ucontact.h"
 
-struct ulcb_head_list* ulcb_list = 0;
-
+struct ulcb_head_list *ulcb_list = 0;
 
 
 int init_ulcb_list(void)
 {
-	ulcb_list = (struct ulcb_head_list*)shm_malloc
-		( sizeof(struct ulcb_head_list) );
-	if (ulcb_list==0) {
+	ulcb_list =
+			(struct ulcb_head_list *)shm_malloc(sizeof(struct ulcb_head_list));
+	if(ulcb_list == 0) {
 		SHM_MEM_CRITICAL;
 		return -1;
 	}
@@ -57,41 +56,41 @@ void destroy_ulcb_list(void)
 {
 	struct ul_callback *cbp, *cbp_tmp;
 
-	if (!ulcb_list)
+	if(!ulcb_list)
 		return;
 
-	for( cbp=ulcb_list->first; cbp ; ) {
+	for(cbp = ulcb_list->first; cbp;) {
 		cbp_tmp = cbp;
 		cbp = cbp->next;
-		if (cbp_tmp->param) shm_free( cbp_tmp->param );
-		shm_free( cbp_tmp );
+		if(cbp_tmp->param)
+			shm_free(cbp_tmp->param);
+		shm_free(cbp_tmp);
 	}
 
 	shm_free(ulcb_list);
 }
 
 
-
 /*! \brief 
 	register a callback function 'f' for 'types' mask of events;
 */
-int register_ulcb( int types, ul_cb f, void *param )
+int register_ulcb(int types, ul_cb f, void *param)
 {
 	struct ul_callback *cbp;
 
 	/* are the callback types valid?... */
-	if ( types<0 || types>ULCB_MAX ) {
-		LM_CRIT("invalid callback types: mask=%d\n",types);
+	if(types < 0 || types > ULCB_MAX) {
+		LM_CRIT("invalid callback types: mask=%d\n", types);
 		return E_BUG;
 	}
 	/* we don't register null functions */
-	if (f==0) {
+	if(f == 0) {
 		LM_CRIT("null callback function\n");
 		return E_BUG;
 	}
 
 	/* build a new callback structure */
-	if (!(cbp=(struct ul_callback*)shm_malloc(sizeof( struct ul_callback)))) {
+	if(!(cbp = (struct ul_callback *)shm_malloc(sizeof(struct ul_callback)))) {
 		SHM_MEM_ERROR;
 		return E_OUT_OF_MEM;
 	}
@@ -104,13 +103,10 @@ int register_ulcb( int types, ul_cb f, void *param )
 	cbp->callback = f;
 	cbp->param = param;
 	cbp->types = types;
-	if (cbp->next)
-		cbp->id = cbp->next->id+1;
+	if(cbp->next)
+		cbp->id = cbp->next->id + 1;
 	else
 		cbp->id = 0;
 
 	return 1;
 }
-
-
-

+ 25 - 25
src/modules/usrloc/ul_callback.h

@@ -32,37 +32,38 @@
 /* forward declaration for ucontact_t */
 struct ucontact;
 
-#define UL_CONTACT_INSERT      (1<<0)
-#define UL_CONTACT_UPDATE      (1<<1)
-#define UL_CONTACT_DELETE      (1<<2)
-#define UL_CONTACT_EXPIRE      (1<<3)
-#define ULCB_MAX               ((1<<4)-1)
+#define UL_CONTACT_INSERT (1 << 0)
+#define UL_CONTACT_UPDATE (1 << 1)
+#define UL_CONTACT_DELETE (1 << 2)
+#define UL_CONTACT_EXPIRE (1 << 3)
+#define ULCB_MAX ((1 << 4) - 1)
 
 /*! \brief callback function prototype */
-typedef void (ul_cb) (struct ucontact *c, int type, void *param);
+typedef void(ul_cb)(struct ucontact *c, int type, void *param);
 /*! \brief register callback function prototype */
-typedef int (*register_ulcb_t)( int cb_types, ul_cb f, void *param);
+typedef int (*register_ulcb_t)(int cb_types, ul_cb f, void *param);
 
 
-struct ul_callback {
-	int id;                      /*!< id of this callback - useless */
-	int types;                   /*!< types of events that trigger the callback*/
-	ul_cb* callback;             /*!< callback function */
-	void *param;                 /*!< param to be passed to callback function */
-	struct ul_callback* next;
+struct ul_callback
+{
+	int id;			 /*!< id of this callback - useless */
+	int types;		 /*!< types of events that trigger the callback*/
+	ul_cb *callback; /*!< callback function */
+	void *param;	 /*!< param to be passed to callback function */
+	struct ul_callback *next;
 };
 
-struct ulcb_head_list {
+struct ulcb_head_list
+{
 	struct ul_callback *first;
 	int reg_types;
 };
 
 
-extern struct ulcb_head_list*  ulcb_list;
+extern struct ulcb_head_list *ulcb_list;
 
 
-#define exists_ulcb_type(_types_) \
-	( (ulcb_list->reg_types)&(_types_) )
+#define exists_ulcb_type(_types_) ((ulcb_list->reg_types) & (_types_))
 
 
 int init_ulcb_list(void);
@@ -71,22 +72,21 @@ void destroy_ulcb_list(void);
 
 
 /*! \brief register a callback for several types of events */
-int register_ulcb( int types, ul_cb f, void *param );
+int register_ulcb(int types, ul_cb f, void *param);
 
 /*! \brief run all transaction callbacks for an event type */
-static inline void run_ul_callbacks( int type , struct ucontact *c)
+static inline void run_ul_callbacks(int type, struct ucontact *c)
 {
 	struct ul_callback *cbp;
 
-	for (cbp=ulcb_list->first; cbp; cbp=cbp->next)  {
-		if(cbp->types&type) {
-			LM_DBG("contact=%p, callback type %d/%d, id %d entered\n",
-				c, type, cbp->types, cbp->id );
-			cbp->callback( c, type, cbp->param );
+	for(cbp = ulcb_list->first; cbp; cbp = cbp->next) {
+		if(cbp->types & type) {
+			LM_DBG("contact=%p, callback type %d/%d, id %d entered\n", c, type,
+					cbp->types, cbp->id);
+			cbp->callback(c, type, cbp->param);
 		}
 	}
 }
 
 
-
 #endif

+ 73 - 75
src/modules/usrloc/ul_keepalive.c

@@ -62,14 +62,15 @@ Content-Length: 0\r\n\r\n"
 #define ULKA_CALLID_PREFIX "ksrulka-"
 #define ULKA_CALLID_PREFIX_LEN (sizeof(ULKA_CALLID_PREFIX) - 1)
 
-#define ULKA_MSG "%.*s %.*s SIP/2.0\r\n" \
-  "Via: SIP/2.0/%.*s %s%.*s%s:%.*s;branch=z9hG4bKx.%u.%u.0\r\n" \
-  "%s%.*s%.*s" \
-  "From: <%.*s>;tag=%.*s-%x-%lx-%lx-%x.%x\r\n" \
-  "To: <sip:%.*s%s%.*s>\r\n" \
-  "Call-ID: " ULKA_CALLID_PREFIX "%x-%x-%x.%x\r\n" \
-  "CSeq: 80 %.*s\r\n" \
-  "Content-Length: 0\r\n\r\n"
+#define ULKA_MSG                                                  \
+	"%.*s %.*s SIP/2.0\r\n"                                       \
+	"Via: SIP/2.0/%.*s %s%.*s%s:%.*s;branch=z9hG4bKx.%u.%u.0\r\n" \
+	"%s%.*s%.*s"                                                  \
+	"From: <%.*s>;tag=%.*s-%x-%lx-%lx-%x.%x\r\n"                  \
+	"To: <sip:%.*s%s%.*s>\r\n"                                    \
+	"Call-ID: " ULKA_CALLID_PREFIX "%x-%x-%x.%x\r\n"              \
+	"CSeq: 80 %.*s\r\n"                                           \
+	"Content-Length: 0\r\n\r\n"
 
 extern str ul_ka_from;
 extern str ul_ka_domain;
@@ -109,46 +110,47 @@ int ul_ka_urecord(urecord_t *ur)
 	struct timeval tv;
 	time_t tnow = 0;
 
-	if (ul_ka_mode == ULKA_NONE) {
+	if(ul_ka_mode == ULKA_NONE) {
 		return 0;
 	}
 
-	if(likely(destroy_modules_phase()!=0)) {
+	if(likely(destroy_modules_phase() != 0)) {
 		return 0;
 	}
 
 	LM_DBG("keepalive for aor: %.*s\n", ur->aor.len, ur->aor.s);
 	tnow = time(NULL);
 
-	for(i=0; i<ur->aor.len; i++) {
+	for(i = 0; i < ur->aor.len; i++) {
 		if(ur->aor.s[i] == '@') {
 			aortype = 1;
 			break;
 		}
 	}
 	_ul_ka_counter++;
-	for (uc = ur->contacts; uc != NULL; uc = uc->next) {
-		if (uc->c.len <= 0) {
+	for(uc = ur->contacts; uc != NULL; uc = uc->next) {
+		if(uc->c.len <= 0) {
 			continue;
 		}
-		if((ul_ka_filter&GAU_OPT_SERVER_ID) && (uc->server_id != server_id)) {
+		if((ul_ka_filter & GAU_OPT_SERVER_ID) && (uc->server_id != server_id)) {
 			continue;
 		}
 		if(ul_ka_mode & ULKA_NAT) {
 			/* keepalive for natted contacts only */
-			if (ul_nat_bflag == 0) {
+			if(ul_nat_bflag == 0) {
 				continue;
 			}
-			if ((uc->cflags & ul_nat_bflag) != ul_nat_bflag) {
+			if((uc->cflags & ul_nat_bflag) != ul_nat_bflag) {
 				continue;
 			}
 		}
 
-		if(ul_keepalive_timeout>0 && uc->last_keepalive>0) {
-			if(uc->last_keepalive+ul_keepalive_timeout < tnow) {
+		if(ul_keepalive_timeout > 0 && uc->last_keepalive > 0) {
+			if(uc->last_keepalive + ul_keepalive_timeout < tnow) {
 				/* set contact as expired in 10s */
 				LM_DBG("set expired contact on keepalive (%u + %u < %u)"
-						" - aor: %.*s c: %.*s\n", (unsigned int)uc->last_keepalive,
+					   " - aor: %.*s c: %.*s\n",
+						(unsigned int)uc->last_keepalive,
 						(unsigned int)ul_keepalive_timeout, (unsigned int)tnow,
 						ur->aor.len, ur->aor.s, uc->c.len, uc->c.s);
 				if(uc->expires > tnow + 10) {
@@ -160,7 +162,7 @@ int ul_ka_urecord(urecord_t *ur)
 		if(uc->received.len > 0) {
 			sdst = uc->received;
 		} else {
-			if (uc->path.len > 0) {
+			if(uc->path.len > 0) {
 				if(get_path_dst_uri(&uc->path, &sdst) < 0) {
 					LM_ERR("failed to get first uri for path\n");
 					continue;
@@ -204,12 +206,12 @@ int ul_ka_urecord(urecord_t *ur)
 		idst.id = uc->tcpconn_id;
 
 		if(ssock->useinfo.name.len > 0) {
-			if (ssock->useinfo.address.af == AF_INET6) {
+			if(ssock->useinfo.address.af == AF_INET6) {
 				via_ipv6 = 1;
 			}
 			vaddr = ssock->useinfo.name;
 		} else {
-			if (ssock->address.af == AF_INET6) {
+			if(ssock->address.af == AF_INET6) {
 				via_ipv6 = 1;
 			}
 			vaddr = ssock->address_str;
@@ -224,39 +226,29 @@ int ul_ka_urecord(urecord_t *ur)
 		bcnt++;
 		gettimeofday(&tv, NULL);
 		kabuf_len = snprintf(kabuf, ULKA_BUF_SIZE - 1, ULKA_MSG,
-				ul_ka_method.len, ul_ka_method.s,
-				uc->c.len, uc->c.s,
-				sproto.len, sproto.s,
-				(via_ipv6==1)?"[":"",
-				vaddr.len, vaddr.s,
-				(via_ipv6==1)?"]":"",
-				vport.len, vport.s,
-				_ul_ka_counter, bcnt,
-				(uc->path.len>0)?"Route: ":"",
-				(uc->path.len>0)?uc->path.len:0,
-				(uc->path.len>0)?uc->path.s:"",
-				(uc->path.len>0)?2:0,
-				(uc->path.len>0)?"\r\n":"",
-				ul_ka_from.len, ul_ka_from.s,
-				uc->ruid.len, uc->ruid.s, ur->aorhash,
-				(unsigned long)tv.tv_sec, (unsigned long)tv.tv_usec,
-				_ul_ka_counter, bcnt,
-				ur->aor.len, ur->aor.s,
-				(aortype==1)?"":"@",
-				(aortype==1)?0:ul_ka_domain.len, (aortype==1)?"":ul_ka_domain.s,
-				fastrand(), my_pid(),
-				_ul_ka_counter, bcnt,
-				ul_ka_method.len, ul_ka_method.s);
-		if(kabuf_len<=0 || kabuf_len>=ULKA_BUF_SIZE) {
+				ul_ka_method.len, ul_ka_method.s, uc->c.len, uc->c.s,
+				sproto.len, sproto.s, (via_ipv6 == 1) ? "[" : "", vaddr.len,
+				vaddr.s, (via_ipv6 == 1) ? "]" : "", vport.len, vport.s,
+				_ul_ka_counter, bcnt, (uc->path.len > 0) ? "Route: " : "",
+				(uc->path.len > 0) ? uc->path.len : 0,
+				(uc->path.len > 0) ? uc->path.s : "",
+				(uc->path.len > 0) ? 2 : 0, (uc->path.len > 0) ? "\r\n" : "",
+				ul_ka_from.len, ul_ka_from.s, uc->ruid.len, uc->ruid.s,
+				ur->aorhash, (unsigned long)tv.tv_sec,
+				(unsigned long)tv.tv_usec, _ul_ka_counter, bcnt, ur->aor.len,
+				ur->aor.s, (aortype == 1) ? "" : "@",
+				(aortype == 1) ? 0 : ul_ka_domain.len,
+				(aortype == 1) ? "" : ul_ka_domain.s, fastrand(), my_pid(),
+				_ul_ka_counter, bcnt, ul_ka_method.len, ul_ka_method.s);
+		if(kabuf_len <= 0 || kabuf_len >= ULKA_BUF_SIZE) {
 			LM_ERR("failed to print the keepalive request\n");
 		} else {
-			LM_DBG("keepalive request (len: %d) [[\n%.*s]]\n",
-					kabuf_len, kabuf_len, kabuf);
+			LM_DBG("keepalive request (len: %d) [[\n%.*s]]\n", kabuf_len,
+					kabuf_len, kabuf);
 			kamsg.s = kabuf;
 			kamsg.len = kabuf_len;
 			ul_ka_send(&kamsg, &idst);
 		}
-
 	}
 	return 0;
 }
@@ -266,7 +258,7 @@ int ul_ka_urecord(urecord_t *ur)
  */
 static int ul_ka_send(str *kamsg, dest_info_t *kadst)
 {
-	if (kadst->proto == PROTO_UDP) {
+	if(kadst->proto == PROTO_UDP) {
 		return udp_send(kadst, kamsg->s, kamsg->len);
 	}
 
@@ -274,8 +266,7 @@ static int ul_ka_send(str *kamsg, dest_info_t *kadst)
 	else if(kadst->proto == PROTO_WS || kadst->proto == PROTO_WSS) {
 		/*ws-wss*/
 		return wss_send(kadst, kamsg->s, kamsg->len);
-	}
-	else if(kadst->proto == PROTO_TCP) {
+	} else if(kadst->proto == PROTO_TCP) {
 		/*tcp*/
 		return tcp_send(kadst, 0, kamsg->s, kamsg->len);
 	}
@@ -293,8 +284,7 @@ static int ul_ka_send(str *kamsg, dest_info_t *kadst)
 	}
 #endif
 	else {
-		LM_ERR("unknown proto [%d] for sending keepalive\n",
-				kadst->proto);
+		LM_ERR("unknown proto [%d] for sending keepalive\n", kadst->proto);
 		return -1;
 	}
 }
@@ -304,19 +294,25 @@ static int ul_ka_send(str *kamsg, dest_info_t *kadst)
  */
 unsigned long ul_ka_fromhex(str *shex, int *err)
 {
-    unsigned long v = 0;
+	unsigned long v = 0;
 	int i;
 
 	*err = 0;
-    for (i=0; i<shex->len; i++) {
-        char b = shex->s[i];
-        if (b >= '0' && b <= '9') b = b - '0';
-        else if (b >= 'a' && b <='f') b = b - 'a' + 10;
-        else if (b >= 'A' && b <='F') b = b - 'A' + 10;
-		else { *err = 1; return 0; };
-        v = (v << 4) | (b & 0xF);
-    }
-    return v;
+	for(i = 0; i < shex->len; i++) {
+		char b = shex->s[i];
+		if(b >= '0' && b <= '9')
+			b = b - '0';
+		else if(b >= 'a' && b <= 'f')
+			b = b - 'a' + 10;
+		else if(b >= 'A' && b <= 'F')
+			b = b - 'A' + 10;
+		else {
+			*err = 1;
+			return 0;
+		};
+		v = (v << 4) | (b & 0xF);
+	}
+	return v;
 }
 
 /**
@@ -344,7 +340,8 @@ int ul_ka_reply_received(sip_msg_t *msg)
 	if(get_cseq(msg)->method.len != ul_ka_method.len) {
 		return 1;
 	}
-	if(strncmp(get_cseq(msg)->method.s, ul_ka_method.s, ul_ka_method.len) != 0) {
+	if(strncmp(get_cseq(msg)->method.s, ul_ka_method.s, ul_ka_method.len)
+			!= 0) {
 		return 1;
 	}
 
@@ -399,7 +396,7 @@ int ul_ka_reply_received(sip_msg_t *msg)
 	}
 	LM_DBG("tv usec string is [%.*s] (%d)\n", tok.len, tok.s, tok.len);
 	tvm.tv_usec = ul_ka_fromhex(&tok, &err);
-	if(err==1) {
+	if(err == 1) {
 		LM_DBG("invalid tv usec value\n");
 		return 1;
 	}
@@ -421,7 +418,7 @@ int ul_ka_reply_received(sip_msg_t *msg)
 	}
 	LM_DBG("tv sec string is [%.*s] (%d)\n", tok.len, tok.s, tok.len);
 	tvm.tv_sec = ul_ka_fromhex(&tok, &err);
-	if(err==1) {
+	if(err == 1) {
 		LM_DBG("invalid tv sec value\n");
 		return 1;
 	}
@@ -443,7 +440,7 @@ int ul_ka_reply_received(sip_msg_t *msg)
 	}
 	LM_DBG("aor hash string is [%.*s] (%d)\n", tok.len, tok.s, tok.len);
 	aorhash = ul_ka_fromhex(&tok, &err);
-	if(err==1) {
+	if(err == 1) {
 		LM_DBG("invalid aor hash value\n");
 		return 1;
 	}
@@ -459,21 +456,22 @@ int ul_ka_reply_received(sip_msg_t *msg)
 	}
 
 	gettimeofday(&tvn, NULL);
-	tvdiff = (tvn.tv_sec - tvm.tv_sec) * 1000000
-					+ (tvn.tv_usec - tvm.tv_usec);
+	tvdiff = (tvn.tv_sec - tvm.tv_sec) * 1000000 + (tvn.tv_usec - tvm.tv_usec);
 	ul_update_keepalive(aorhash, &ruid, tvn.tv_sec, tvdiff);
 
 	if(ul_ka_loglevel != 255 && ul_ka_logfmt != NULL) {
-		if (pv_printf_s(msg, ul_ka_logfmt, &tok) == 0) {
-			LOG(ul_ka_loglevel, "keepalive roundtrip: %u.%06u sec - ruid [%.*s]%.*s\n",
-					tvdiff/1000000, tvdiff%1000000, ruid.len, ruid.s,
+		if(pv_printf_s(msg, ul_ka_logfmt, &tok) == 0) {
+			LOG(ul_ka_loglevel,
+					"keepalive roundtrip: %u.%06u sec - ruid [%.*s]%.*s\n",
+					tvdiff / 1000000, tvdiff % 1000000, ruid.len, ruid.s,
 					tok.len, tok.s);
 			return 0;
 		}
 	}
 
-	LM_DBG("response of keepalive for ruid [%.*s] aorhash [%u] roundtrip: %u.%06u secs\n",
-			ruid.len, ruid.s, aorhash, tvdiff/1000000, tvdiff%1000000);
+	LM_DBG("response of keepalive for ruid [%.*s] aorhash [%u] roundtrip: "
+		   "%u.%06u secs\n",
+			ruid.len, ruid.s, aorhash, tvdiff / 1000000, tvdiff % 1000000);
 
 	return 0;
 }

+ 3 - 3
src/modules/usrloc/ul_keepalive.h

@@ -29,9 +29,9 @@
 #include "urecord.h"
 
 #define ULKA_NONE 0
-#define ULKA_ALL  1
-#define ULKA_NAT  (1<<1)
-#define ULKA_UDP  (1<<2)
+#define ULKA_ALL 1
+#define ULKA_NAT (1 << 1)
+#define ULKA_UDP (1 << 2)
 
 int ul_ka_urecord(urecord_t *ur);
 int ul_ka_reply_received(sip_msg_t *msg);

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 229 - 282
src/modules/usrloc/ul_rpc.c


+ 180 - 171
src/modules/usrloc/urecord.c

@@ -52,17 +52,17 @@ int ul_cseq_delay = 20;
  * \param _r pointer to the new record
  * \return 0 on success, negative on failure
  */
-int new_urecord(str* _dom, str* _aor, urecord_t** _r)
+int new_urecord(str *_dom, str *_aor, urecord_t **_r)
 {
-	*_r = (urecord_t*)shm_malloc(sizeof(urecord_t));
-	if (*_r == 0) {
+	*_r = (urecord_t *)shm_malloc(sizeof(urecord_t));
+	if(*_r == 0) {
 		SHM_MEM_ERROR;
 		return -1;
 	}
 	memset(*_r, 0, sizeof(urecord_t));
 
-	(*_r)->aor.s = (char*)shm_malloc(_aor->len);
-	if ((*_r)->aor.s == 0) {
+	(*_r)->aor.s = (char *)shm_malloc(_aor->len);
+	if((*_r)->aor.s == 0) {
 		SHM_MEM_ERROR;
 		shm_free(*_r);
 		*_r = 0;
@@ -84,9 +84,9 @@ int new_urecord(str* _dom, str* _aor, urecord_t** _r)
  * lists first
  * \param _r freed record list
  */
-void free_urecord(urecord_t* _r)
+void free_urecord(urecord_t *_r)
 {
-	ucontact_t* ptr;
+	ucontact_t *ptr;
 
 	while(_r->contacts) {
 		ptr = _r->contacts;
@@ -95,8 +95,9 @@ void free_urecord(urecord_t* _r)
 	}
 
 	/* if mem cache is not used, the urecord struct is static*/
-	if (ul_db_mode!=DB_ONLY) {
-		if (_r->aor.s) shm_free(_r->aor.s);
+	if(ul_db_mode != DB_ONLY) {
+		if(_r->aor.s)
+			shm_free(_r->aor.s);
 		shm_free(_r);
 	}
 }
@@ -107,17 +108,17 @@ void free_urecord(urecord_t* _r)
  * \param _f print output
  * \param _r printed record
  */
-void print_urecord(FILE* _f, urecord_t* _r)
+void print_urecord(FILE *_f, urecord_t *_r)
 {
-	ucontact_t* ptr;
+	ucontact_t *ptr;
 
 	fprintf(_f, "...Record(%p)...\n", _r);
 	fprintf(_f, "domain : '%.*s'\n", _r->domain->len, ZSW(_r->domain->s));
 	fprintf(_f, "aor    : '%.*s'\n", _r->aor.len, ZSW(_r->aor.s));
 	fprintf(_f, "aorhash: '%u'\n", (unsigned)_r->aorhash);
-	fprintf(_f, "slot:    '%d'\n", _r->aorhash&(_r->slot->d->size-1));
+	fprintf(_f, "slot:    '%d'\n", _r->aorhash & (_r->slot->d->size - 1));
 
-	if (_r->contacts) {
+	if(_r->contacts) {
 		ptr = _r->contacts;
 		while(ptr) {
 			print_ucontact(_f, ptr);
@@ -139,29 +140,30 @@ void print_urecord(FILE* _f, urecord_t* _r)
  * \param _ci contact information
  * \return pointer to new created contact on success, 0 on failure
  */
-ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci)
+ucontact_t *mem_insert_ucontact(urecord_t *_r, str *_c, ucontact_info_t *_ci)
 {
-	ucontact_t* ptr, *prev = 0;
-	ucontact_t* c;
+	ucontact_t *ptr, *prev = 0;
+	ucontact_t *c;
 
-	if ( (c=new_ucontact(_r->domain, &_r->aor, _c, _ci)) == 0) {
+	if((c = new_ucontact(_r->domain, &_r->aor, _c, _ci)) == 0) {
 		LM_ERR("failed to create new contact\n");
 		return 0;
 	}
-	if_update_stat( _r->slot, _r->slot->d->contacts, 1);
+	if_update_stat(_r->slot, _r->slot->d->contacts, 1);
 
 	ptr = _r->contacts;
 
-	if (!ul_desc_time_order) {
+	if(!ul_desc_time_order) {
 		while(ptr) {
-			if (ptr->q < c->q) break;
+			if(ptr->q < c->q)
+				break;
 			prev = ptr;
 			ptr = ptr->next;
 		}
 	}
 
-	if (ptr) {
-		if (!ptr->prev) {
+	if(ptr) {
+		if(!ptr->prev) {
 			ptr->prev = c;
 			c->next = ptr;
 			_r->contacts = c;
@@ -171,7 +173,7 @@ ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci)
 			ptr->prev->next = c;
 			ptr->prev = c;
 		}
-	} else if (prev) {
+	} else if(prev) {
 		prev->next = c;
 		c->prev = prev;
 	} else {
@@ -187,16 +189,16 @@ ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci)
  * \param _r record this contact belongs to
  * \param _c removed contact
  */
-void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c)
+void mem_remove_ucontact(urecord_t *_r, ucontact_t *_c)
 {
-	if (_c->prev) {
+	if(_c->prev) {
 		_c->prev->next = _c->next;
-		if (_c->next) {
+		if(_c->next) {
 			_c->next->prev = _c->prev;
 		}
 	} else {
 		_r->contacts = _c->next;
-		if (_c->next) {
+		if(_c->next) {
 			_c->next->prev = 0;
 		}
 	}
@@ -208,16 +210,16 @@ void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c)
  * \param _r record this contact belongs to
  * \param _c deleted contact
  */
-void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c)
+void mem_delete_ucontact(urecord_t *_r, ucontact_t *_c)
 {
 	mem_remove_ucontact(_r, _c);
-	if_update_stat( _r->slot, _r->slot->d->contacts, -1);
+	if_update_stat(_r->slot, _r->slot->d->contacts, -1);
 	free_ucontact(_c);
 }
 
 int is_valid_tcpconn(ucontact_t *c)
 {
-	if (c->tcpconn_id == -1)
+	if(c->tcpconn_id == -1)
 		return 0; /* tcpconn_id is not present */
 	else
 		return 1; /* valid tcpconn_id */
@@ -228,7 +230,7 @@ int is_tcp_alive(ucontact_t *c)
 	struct tcp_connection *con = NULL;
 	int rc = 0;
 
-	if ((con = tcpconn_get(c->tcpconn_id, 0, 0, 0, 0))) {
+	if((con = tcpconn_get(c->tcpconn_id, 0, 0, 0, 0))) {
 		tcpconn_put(con); /* refcnt-- */
 		rc = 1;
 	}
@@ -242,11 +244,12 @@ int is_tcp_alive(ucontact_t *c)
  * Requests the TCP main process to close the specified TCP connection
  * \param conid the internal connection ID
  */
-static inline int close_connection(int conid) {
+static inline int close_connection(int conid)
+{
 	struct tcp_connection *con;
 	long msg[2];
 	int n;
-	if ((con = tcpconn_get(conid, 0, 0, 0, 0))) {
+	if((con = tcpconn_get(conid, 0, 0, 0, 0))) {
 		msg[0] = (long)con;
 		msg[1] = CONN_EOF;
 
@@ -254,8 +257,9 @@ static inline int close_connection(int conid) {
 		con->flags |= F_CONN_FORCE_EOF;
 
 		n = send_all(unix_tcp_sock, msg, sizeof(msg));
-		if (unlikely(n <= 0)){
-			LM_ERR("failed to send close request: %s (%d)\n", strerror(errno), errno);
+		if(unlikely(n <= 0)) {
+			LM_ERR("failed to send close request: %s (%d)\n", strerror(errno),
+					errno);
 			return 0;
 		}
 		return 1;
@@ -270,31 +274,32 @@ static inline int close_connection(int conid) {
  * the record, delete the expired ones from memory.
  * \param _r processed record
  */
-static inline void nodb_timer(urecord_t* _r)
+static inline void nodb_timer(urecord_t *_r)
 {
-	ucontact_t* ptr, *t;
+	ucontact_t *ptr, *t;
 
 
 	ptr = _r->contacts;
 
 	while(ptr) {
-		if (ul_handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) {
-			LM_DBG("tcp connection has been lost, expiring contact %.*s\n", ptr->c.len, ptr->c.s);
+		if(ul_handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) {
+			LM_DBG("tcp connection has been lost, expiring contact %.*s\n",
+					ptr->c.len, ptr->c.s);
 			ptr->expires = UL_EXPIRED_TIME;
 		}
 
-		if (!VALID_CONTACT(ptr, ul_act_time)) {
+		if(!VALID_CONTACT(ptr, ul_act_time)) {
 			/* run callbacks for EXPIRE event */
-			if (!(ptr->flags&FL_EXPCLB) && exists_ulcb_type(UL_CONTACT_EXPIRE)) {
-				run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
+			if(!(ptr->flags & FL_EXPCLB)
+					&& exists_ulcb_type(UL_CONTACT_EXPIRE)) {
+				run_ul_callbacks(UL_CONTACT_EXPIRE, ptr);
 				ptr->flags |= FL_EXPCLB;
 			}
 
-			LM_DBG("Binding '%.*s','%.*s' has expired\n",
-				ptr->aor->len, ZSW(ptr->aor->s),
-				ptr->c.len, ZSW(ptr->c.s));
+			LM_DBG("Binding '%.*s','%.*s' has expired\n", ptr->aor->len,
+					ZSW(ptr->aor->s), ptr->c.len, ZSW(ptr->c.s));
 
-			if (ul_close_expired_tcp && is_valid_tcpconn(ptr)) {
+			if(ul_close_expired_tcp && is_valid_tcpconn(ptr)) {
 				close_connection(ptr->tcpconn_id);
 			}
 
@@ -302,7 +307,7 @@ static inline void nodb_timer(urecord_t* _r)
 			ptr = ptr->next;
 
 			mem_delete_ucontact(_r, t);
-			update_stat( _r->slot->d->expires, 1);
+			update_stat(_r->slot->d->expires, 1);
 		} else {
 			ptr = ptr->next;
 		}
@@ -318,35 +323,34 @@ static inline void nodb_timer(urecord_t* _r)
  * \param _r processed record
  * \note currently unused, this mode is also handled by the wb_timer
  */
-static inline void wt_timer(urecord_t* _r)
+static inline void wt_timer(urecord_t *_r)
 {
-	ucontact_t* ptr, *t;
+	ucontact_t *ptr, *t;
 
 	ptr = _r->contacts;
 
 	while(ptr) {
-		if (!VALID_CONTACT(ptr, ul_act_time)) {
+		if(!VALID_CONTACT(ptr, ul_act_time)) {
 			/* run callbacks for EXPIRE event */
-			if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
-				run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
+			if(exists_ulcb_type(UL_CONTACT_EXPIRE)) {
+				run_ul_callbacks(UL_CONTACT_EXPIRE, ptr);
 			}
 
-			LM_DBG("Binding '%.*s','%.*s' has expired\n",
-				ptr->aor->len, ZSW(ptr->aor->s),
-				ptr->c.len, ZSW(ptr->c.s));
+			LM_DBG("Binding '%.*s','%.*s' has expired\n", ptr->aor->len,
+					ZSW(ptr->aor->s), ptr->c.len, ZSW(ptr->c.s));
 
-			if (ul_close_expired_tcp && is_valid_tcpconn(ptr)) {
+			if(ul_close_expired_tcp && is_valid_tcpconn(ptr)) {
 				close_connection(ptr->tcpconn_id);
 			}
 
 			t = ptr;
 			ptr = ptr->next;
 
-			if (db_delete_ucontact(t) < 0) {
+			if(db_delete_ucontact(t) < 0) {
 				LM_ERR("deleting contact from database failed\n");
 			}
 			mem_delete_ucontact(_r, t);
-			update_stat( _r->slot->d->expires, 1);
+			update_stat(_r->slot->d->expires, 1);
 		} else {
 			ptr = ptr->next;
 		}
@@ -362,9 +366,9 @@ static inline void wt_timer(urecord_t* _r)
  * ones in the DB.
  * \param _r processed record
  */
-static inline void wb_timer(urecord_t* _r)
+static inline void wb_timer(urecord_t *_r)
 {
-	ucontact_t* ptr, *t;
+	ucontact_t *ptr, *t;
 	cstate_t old_state;
 	int op;
 	int res;
@@ -372,23 +376,23 @@ static inline void wb_timer(urecord_t* _r)
 	ptr = _r->contacts;
 
 	while(ptr) {
-		if (ul_handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) {
-			LM_DBG("tcp connection has been lost, expiring contact %.*s\n", ptr->c.len, ptr->c.s);
+		if(ul_handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) {
+			LM_DBG("tcp connection has been lost, expiring contact %.*s\n",
+					ptr->c.len, ptr->c.s);
 			ptr->expires = UL_EXPIRED_TIME;
 		}
 
-		if (!VALID_CONTACT(ptr, ul_act_time)) {
+		if(!VALID_CONTACT(ptr, ul_act_time)) {
 			/* run callbacks for EXPIRE event */
-			if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
-				run_ul_callbacks( UL_CONTACT_EXPIRE, ptr);
+			if(exists_ulcb_type(UL_CONTACT_EXPIRE)) {
+				run_ul_callbacks(UL_CONTACT_EXPIRE, ptr);
 			}
 
-			LM_DBG("Binding '%.*s','%.*s' has expired\n",
-				ptr->aor->len, ZSW(ptr->aor->s),
-				ptr->c.len, ZSW(ptr->c.s));
-			update_stat( _r->slot->d->expires, 1);
+			LM_DBG("Binding '%.*s','%.*s' has expired\n", ptr->aor->len,
+					ZSW(ptr->aor->s), ptr->c.len, ZSW(ptr->c.s));
+			update_stat(_r->slot->d->expires, 1);
 
-			if (ul_close_expired_tcp && is_valid_tcpconn(ptr)) {
+			if(ul_close_expired_tcp && is_valid_tcpconn(ptr)) {
 				close_connection(ptr->tcpconn_id);
 			}
 
@@ -396,10 +400,10 @@ static inline void wb_timer(urecord_t* _r)
 			ptr = ptr->next;
 
 			/* Should we remove the contact from the database ? */
-			if (st_expired_ucontact(t) == 1) {
-				if (db_delete_ucontact(t) < 0) {
+			if(st_expired_ucontact(t) == 1) {
+				if(db_delete_ucontact(t) < 0) {
 					LM_ERR("failed to delete contact from the database"
-							" (aor: %.*s)\n",
+						   " (aor: %.*s)\n",
 							t->aor->len, ZSW(t->aor->s));
 				}
 			}
@@ -411,29 +415,29 @@ static inline void wb_timer(urecord_t* _r)
 			op = st_flush_ucontact(ptr);
 
 			switch(op) {
-			case 0: /* do nothing, contact is synchronized */
-				break;
-
-			case 1: /* insert */
-				if (db_insert_ucontact(ptr) < 0) {
-					LM_ERR("inserting contact into database failed"
-							" (aor: %.*s)\n",
-							ptr->aor->len, ZSW(ptr->aor->s));
-					ptr->state = old_state;
-				}
-				break;
-
-			case 2: /* update */
-				if (ul_db_update_as_insert)
-					res = db_insert_ucontact(ptr);
-				else
-					res = db_update_ucontact(ptr);
-				if (res < 0) {
-					LM_ERR("updating contact in db failed (aor: %.*s)\n",
-							ptr->aor->len, ZSW(ptr->aor->s));
-					ptr->state = old_state;
-				}
-				break;
+				case 0: /* do nothing, contact is synchronized */
+					break;
+
+				case 1: /* insert */
+					if(db_insert_ucontact(ptr) < 0) {
+						LM_ERR("inserting contact into database failed"
+							   " (aor: %.*s)\n",
+								ptr->aor->len, ZSW(ptr->aor->s));
+						ptr->state = old_state;
+					}
+					break;
+
+				case 2: /* update */
+					if(ul_db_update_as_insert)
+						res = db_insert_ucontact(ptr);
+					else
+						res = db_update_ucontact(ptr);
+					if(res < 0) {
+						LM_ERR("updating contact in db failed (aor: %.*s)\n",
+								ptr->aor->len, ZSW(ptr->aor->s));
+						ptr->state = old_state;
+					}
+					break;
 			}
 
 			ptr = ptr->next;
@@ -449,7 +453,7 @@ static inline void wb_timer(urecord_t* _r)
  * on the db_mode setting.
  * \param _r processed record
  */
-void timer_urecord(urecord_t* _r)
+void timer_urecord(urecord_t *_r)
 {
 	switch(ul_db_mode) {
 		case DB_READONLY:
@@ -473,11 +477,11 @@ void timer_urecord(urecord_t* _r)
  * \param _r deleted record
  * \return 0 on success, -1 on failure
  */
-int db_delete_urecord(urecord_t* _r)
+int db_delete_urecord(urecord_t *_r)
 {
 	db_key_t keys[2];
 	db_val_t vals[2];
-	char* dom;
+	char *dom;
 
 	keys[0] = &ul_user_col;
 	keys[1] = &ul_domain_col;
@@ -486,7 +490,7 @@ int db_delete_urecord(urecord_t* _r)
 	vals[0].val.str_val.s = _r->aor.s;
 	vals[0].val.str_val.len = _r->aor.len;
 
-	if (ul_use_domain) {
+	if(ul_use_domain) {
 		dom = memchr(_r->aor.s, '@', _r->aor.len);
 		vals[0].val.str_val.len = dom - _r->aor.s;
 
@@ -496,12 +500,12 @@ int db_delete_urecord(urecord_t* _r)
 		vals[1].val.str_val.len = _r->aor.s + _r->aor.len - dom - 1;
 	}
 
-	if (ul_dbf.use_table(ul_dbh, _r->domain) < 0) {
+	if(ul_dbf.use_table(ul_dbh, _r->domain) < 0) {
 		LM_ERR("use_table failed\n");
 		return -1;
 	}
 
-	if (ul_dbf.delete(ul_dbh, keys, 0, vals, (ul_use_domain) ? (2) : (1)) < 0) {
+	if(ul_dbf.delete(ul_dbh, keys, 0, vals, (ul_use_domain) ? (2) : (1)) < 0) {
 		LM_ERR("failed to delete from database\n");
 		return -1;
 	}
@@ -525,17 +529,17 @@ int db_delete_urecord_by_ruid(str *_table, str *_ruid)
 	vals[0].val.str_val.s = _ruid->s;
 	vals[0].val.str_val.len = _ruid->len;
 
-	if (ul_dbf.use_table(ul_dbh, _table) < 0) {
+	if(ul_dbf.use_table(ul_dbh, _table) < 0) {
 		LM_ERR("use_table failed\n");
 		return -1;
 	}
 
-	if (ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) {
+	if(ul_dbf.delete(ul_dbh, keys, 0, vals, 1) < 0) {
 		LM_ERR("failed to delete from database\n");
 		return -1;
 	}
 
-	if (ul_dbf.affected_rows(ul_dbh) == 0) {
+	if(ul_dbf.affected_rows(ul_dbh) == 0) {
 		return -2;
 	}
 
@@ -551,11 +555,11 @@ int db_delete_urecord_by_ruid(str *_table, str *_ruid)
  * it is not necessary, as this function already releases the record.
  * \param _r released record
  */
-void release_urecord(urecord_t* _r)
+void release_urecord(urecord_t *_r)
 {
-	if (ul_db_mode==DB_ONLY) {
+	if(ul_db_mode == DB_ONLY) {
 		free_urecord(_r);
-	} else if (_r->contacts == 0) {
+	} else if(_r->contacts == 0) {
 		mem_delete_urecord(_r->slot->d, _r);
 	}
 }
@@ -569,20 +573,20 @@ void release_urecord(urecord_t* _r)
  * \param _c new created contact
  * \return 0 on success, -1 on failure
  */
-int insert_ucontact(urecord_t* _r, str* _contact, ucontact_info_t* _ci,
-															ucontact_t** _c)
+int insert_ucontact(
+		urecord_t *_r, str *_contact, ucontact_info_t *_ci, ucontact_t **_c)
 {
 	struct urecord _ur;
-	if ( ((*_c)=mem_insert_ucontact(_r, _contact, _ci)) == 0) {
+	if(((*_c) = mem_insert_ucontact(_r, _contact, _ci)) == 0) {
 		LM_ERR("failed to insert contact\n");
 		return -1;
 	}
 
-	if (ul_db_mode==DB_ONLY) {
+	if(ul_db_mode == DB_ONLY) {
 		/* urecord is static generate a copy for later */
 		memcpy(&_ur, _r, sizeof(struct urecord));
 
-		if (db_insert_ucontact(*_c) < 0) {
+		if(db_insert_ucontact(*_c) < 0) {
 			LM_ERR("failed to insert in database\n");
 			return -1;
 		} else {
@@ -590,23 +594,23 @@ int insert_ucontact(urecord_t* _r, str* _contact, ucontact_info_t* _ci,
 		}
 	}
 
-	if (exists_ulcb_type(UL_CONTACT_INSERT)) {
-		run_ul_callbacks( UL_CONTACT_INSERT, *_c);
+	if(exists_ulcb_type(UL_CONTACT_INSERT)) {
+		run_ul_callbacks(UL_CONTACT_INSERT, *_c);
 	}
 
-	switch (ul_db_mode) {
+	switch(ul_db_mode) {
 		case WRITE_THROUGH:
-			if (db_insert_ucontact(*_c) < 0) {
+			if(db_insert_ucontact(*_c) < 0) {
 				LM_ERR("failed to insert in database\n");
 				return -1;
 			} else {
 				(*_c)->state = CS_SYNC;
 			}
-		break;
+			break;
 		case DB_ONLY:
 			/* urecord was static restore copy */
 			memcpy(_r, &_ur, sizeof(struct urecord));
-		break;
+			break;
 	}
 
 	return 0;
@@ -619,28 +623,28 @@ int insert_ucontact(urecord_t* _r, str* _contact, ucontact_info_t* _ci,
  * \param _c deleted contact
  * \return 0 on success, -1 on failure
  */
-int delete_ucontact(urecord_t* _r, struct ucontact* _c)
+int delete_ucontact(urecord_t *_r, struct ucontact *_c)
 {
 	int ret = 0;
 	struct urecord _ur;
 
-	if (ul_db_mode==DB_ONLY) {
+	if(ul_db_mode == DB_ONLY) {
 		/* urecord is static generate a copy for later */
 		memcpy(&_ur, _r, sizeof(struct urecord));
 	}
 
-	if (exists_ulcb_type(UL_CONTACT_DELETE)) {
-		run_ul_callbacks( UL_CONTACT_DELETE, _c);
+	if(exists_ulcb_type(UL_CONTACT_DELETE)) {
+		run_ul_callbacks(UL_CONTACT_DELETE, _c);
 	}
 
-	if (ul_db_mode==DB_ONLY) {
+	if(ul_db_mode == DB_ONLY) {
 		/* urecord was static restore copy */
 		memcpy(_r, &_ur, sizeof(struct urecord));
 	}
 
-	if (st_delete_ucontact(_c) > 0) {
-		if (ul_db_mode == WRITE_THROUGH || ul_db_mode==DB_ONLY) {
-			if (db_delete_ucontact(_c) < 0) {
+	if(st_delete_ucontact(_c) > 0) {
+		if(ul_db_mode == WRITE_THROUGH || ul_db_mode == DB_ONLY) {
+			if(db_delete_ucontact(_c) < 0) {
 				LM_ERR("failed to remove contact from database\n");
 				ret = -1;
 			}
@@ -653,10 +657,11 @@ int delete_ucontact(urecord_t* _r, struct ucontact* _c)
 }
 
 
-int delete_urecord_by_ruid(udomain_t* _d, str *_ruid)
+int delete_urecord_by_ruid(udomain_t *_d, str *_ruid)
 {
-	if (ul_db_mode != DB_ONLY) {
-		LM_ERR("delete_urecord_by_ruid currently available only in db_mode=3\n");
+	if(ul_db_mode != DB_ONLY) {
+		LM_ERR("delete_urecord_by_ruid currently available only in "
+			   "db_mode=3\n");
 		return -1;
 	}
 
@@ -670,10 +675,10 @@ int delete_urecord_by_ruid(udomain_t* _d, str *_ruid)
  * \param _c contact string
  * \return ptr on successfull match, 0 when they not match
  */
-static inline struct ucontact* contact_match( ucontact_t* ptr, str* _c)
+static inline struct ucontact *contact_match(ucontact_t *ptr, str *_c)
 {
 	while(ptr) {
-		if ((_c->len == ptr->c.len) && !memcmp(_c->s, ptr->c.s, _c->len)) {
+		if((_c->len == ptr->c.len) && !memcmp(_c->s, ptr->c.s, _c->len)) {
 			return ptr;
 		}
 
@@ -690,14 +695,13 @@ static inline struct ucontact* contact_match( ucontact_t* ptr, str* _c)
  * \param _callid callid
  * \return ptr on successfull match, 0 when they not match
  */
-static inline struct ucontact* contact_callid_match( ucontact_t* ptr,
-														str* _c, str *_callid)
+static inline struct ucontact *contact_callid_match(
+		ucontact_t *ptr, str *_c, str *_callid)
 {
 	while(ptr) {
-		if ( (_c->len==ptr->c.len) && (_callid->len==ptr->callid.len)
-		&& !memcmp(_c->s, ptr->c.s, _c->len)
-		&& !memcmp(_callid->s, ptr->callid.s, _callid->len)
-		) {
+		if((_c->len == ptr->c.len) && (_callid->len == ptr->callid.len)
+				&& !memcmp(_c->s, ptr->c.s, _c->len)
+				&& !memcmp(_callid->s, ptr->callid.s, _callid->len)) {
 			return ptr;
 		}
 
@@ -713,16 +717,18 @@ static inline struct ucontact* contact_callid_match( ucontact_t* ptr,
  * \param _path path
  * \return ptr on successfull match, 0 when they not match
  */
-static inline struct ucontact* contact_path_match( ucontact_t* ptr, str* _c, str *_path)
+static inline struct ucontact *contact_path_match(
+		ucontact_t *ptr, str *_c, str *_path)
 {
 	/* if no path is preset (in REGISTER request) or use_path is not configured
 	 * in registrar module, default to contact_match() */
-	if( _path == NULL) return contact_match(ptr, _c);
+	if(_path == NULL)
+		return contact_match(ptr, _c);
 
 	while(ptr) {
-		if ( (_c->len==ptr->c.len) && (_path->len==ptr->path.len)
-			&& !memcmp(_c->s, ptr->c.s, _c->len)
-			&& !memcmp(_path->s, ptr->path.s, _path->len) ) {
+		if((_c->len == ptr->c.len) && (_path->len == ptr->path.len)
+				&& !memcmp(_c->s, ptr->c.s, _c->len)
+				&& !memcmp(_path->s, ptr->path.s, _path->len)) {
 			return ptr;
 		}
 
@@ -732,17 +738,18 @@ static inline struct ucontact* contact_path_match( ucontact_t* ptr, str* _c, str
 }
 
 
-
 /*!
  * \brief Match a contact record to a Call-ID only
  * \param ptr contact record
  * \param _callid callid string
  * \return ptr on successfull match, 0 when they not match
  */
-static inline struct ucontact* contact_match_callidonly( ucontact_t* ptr, str* _callid)
+static inline struct ucontact *contact_match_callidonly(
+		ucontact_t *ptr, str *_callid)
 {
 	while(ptr) {
-		if ((_callid->len == ptr->callid.len) && !memcmp(_callid->s, ptr->callid.s, _callid->len)) {
+		if((_callid->len == ptr->callid.len)
+				&& !memcmp(_callid->s, ptr->callid.s, _callid->len)) {
 			return ptr;
 		}
 
@@ -763,44 +770,47 @@ static inline struct ucontact* contact_match_callidonly( ucontact_t* ptr, str* _
  * \return 0 - found, 1 - not found, -1 - invalid found,
  * -2 - found, but to be skipped (same cseq)
  */
-int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path, int _cseq,
-														struct ucontact** _co)
+int get_ucontact(urecord_t *_r, str *_c, str *_callid, str *_path, int _cseq,
+		struct ucontact **_co)
 {
-	ucontact_t* ptr;
+	ucontact_t *ptr;
 	int no_callid;
 
 	ptr = 0;
 	no_callid = 0;
 	*_co = 0;
 
-	switch (ul_matching_mode) {
+	switch(ul_matching_mode) {
 		case CONTACT_ONLY:
-			ptr = contact_match( _r->contacts, _c);
+			ptr = contact_match(_r->contacts, _c);
 			break;
 		case CONTACT_CALLID:
-			ptr = contact_callid_match( _r->contacts, _c, _callid);
+			ptr = contact_callid_match(_r->contacts, _c, _callid);
 			no_callid = 1;
 			break;
 		case CONTACT_PATH:
-			ptr = contact_path_match( _r->contacts, _c, _path);
+			ptr = contact_path_match(_r->contacts, _c, _path);
 			break;
 		case CONTACT_CALLID_ONLY:
-			ptr = contact_match_callidonly( _r->contacts, _callid);
+			ptr = contact_match_callidonly(_r->contacts, _callid);
 			break;
 		default:
 			LM_CRIT("unknown matching_mode %d\n", ul_matching_mode);
 			return -1;
 	}
 
-	if (ptr) {
+	if(ptr) {
 		/* found -> check callid and cseq */
-		if ( no_callid || (ptr->callid.len==_callid->len
-		&& memcmp(_callid->s, ptr->callid.s, _callid->len)==0 ) ) {
-			if (_cseq<ptr->cseq)
+		if(no_callid
+				|| (ptr->callid.len == _callid->len
+						&& memcmp(_callid->s, ptr->callid.s, _callid->len)
+								   == 0)) {
+			if(_cseq < ptr->cseq)
 				return -1;
-			if (_cseq==ptr->cseq) {
+			if(_cseq == ptr->cseq) {
 				ul_get_act_time();
-				return (ptr->last_modified+ul_cseq_delay>ul_act_time)?-2:-1;
+				return (ptr->last_modified + ul_cseq_delay > ul_act_time) ? -2
+																		  : -1;
 			}
 		}
 		*_co = ptr;
@@ -813,33 +823,32 @@ int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path, int _cseq,
 /*
  * Get pointer to ucontact with given info (by address or sip.instance)
  */
-int get_ucontact_by_instance(urecord_t* _r, str* _c, ucontact_info_t* _ci,
-		ucontact_t** _co)
+int get_ucontact_by_instance(
+		urecord_t *_r, str *_c, ucontact_info_t *_ci, ucontact_t **_co)
 {
-	ucontact_t* ptr;
+	ucontact_t *ptr;
 	str i1;
 	str i2;
 
-	if (_ci->instance.s == NULL || _ci->instance.len <= 0) {
+	if(_ci->instance.s == NULL || _ci->instance.len <= 0) {
 		return get_ucontact(_r, _c, _ci->callid, _ci->path, _ci->cseq, _co);
 	}
 
 	/* find by instance */
 	ptr = _r->contacts;
 	while(ptr) {
-		if (ptr->instance.len>0 && _ci->reg_id==ptr->reg_id)
-		{
+		if(ptr->instance.len > 0 && _ci->reg_id == ptr->reg_id) {
 			i1 = _ci->instance;
 			i2 = ptr->instance;
-			if(i1.s[0]=='<' && i1.s[i1.len-1]=='>') {
+			if(i1.s[0] == '<' && i1.s[i1.len - 1] == '>') {
 				i1.s++;
-				i1.len-=2;
+				i1.len -= 2;
 			}
-			if(i2.s[0]=='<' && i2.s[i2.len-1]=='>') {
+			if(i2.s[0] == '<' && i2.s[i2.len - 1] == '>') {
 				i2.s++;
-				i2.len-=2;
+				i2.len -= 2;
 			}
-			if(i1.len==i2.len && memcmp(i1.s, i2.s, i2.len)==0) {
+			if(i1.len == i2.len && memcmp(i1.s, i2.s, i2.len) == 0) {
 				*_co = ptr;
 				return 0;
 			}

+ 17 - 20
src/modules/usrloc/urecord.h

@@ -39,8 +39,6 @@
 struct hslot; /*!< Hash table slot */
 
 
-
-
 /*!
  * \brief Create and initialize new record structure
  * \param _dom domain name
@@ -48,7 +46,7 @@ struct hslot; /*!< Hash table slot */
  * \param _r pointer to the new record
  * \return 0 on success, negative on failure
  */
-int new_urecord(str* _dom, str* _aor, urecord_t** _r);
+int new_urecord(str *_dom, str *_aor, urecord_t **_r);
 
 
 /*!
@@ -59,7 +57,7 @@ int new_urecord(str* _dom, str* _aor, urecord_t** _r);
  * lists first
  * \param _r freed record list
  */
-void free_urecord(urecord_t* _r);
+void free_urecord(urecord_t *_r);
 
 
 /*!
@@ -67,7 +65,7 @@ void free_urecord(urecord_t* _r);
  * \param _f print output
  * \param _r printed record
  */
-void print_urecord(FILE* _f, urecord_t* _r);
+void print_urecord(FILE *_f, urecord_t *_r);
 
 
 /*!
@@ -80,7 +78,7 @@ void print_urecord(FILE* _f, urecord_t* _r);
  * \param _ci contact information
  * \return pointer to new created contact on success, 0 on failure
  */
-ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci);
+ucontact_t *mem_insert_ucontact(urecord_t *_r, str *_c, ucontact_info_t *_ci);
 
 
 /*!
@@ -88,7 +86,7 @@ ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci);
  * \param _r record this contact belongs to
  * \param _c removed contact
  */
-void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c);
+void mem_remove_ucontact(urecord_t *_r, ucontact_t *_c);
 
 
 /*!
@@ -96,7 +94,7 @@ void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c);
  * \param _r record this contact belongs to
  * \param _c deleted contact
  */
-void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c);
+void mem_delete_ucontact(urecord_t *_r, ucontact_t *_c);
 
 
 /*!
@@ -106,7 +104,7 @@ void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c);
  * on the db_mode setting.
  * \param _r processed record
  */
-void timer_urecord(urecord_t* _r);
+void timer_urecord(urecord_t *_r);
 
 
 /*!
@@ -114,7 +112,7 @@ void timer_urecord(urecord_t* _r);
  * \param _r deleted record
  * \return 0 on success, -1 on failure
  */
-int db_delete_urecord(urecord_t* _r);
+int db_delete_urecord(urecord_t *_r);
 
 
 /*!
@@ -124,7 +122,7 @@ int db_delete_urecord(urecord_t* _r);
  * \return 0 on success, -1 on failure, and -2 if record was
  * not found
  */
-int delete_urecord_by_ruid(udomain_t* _d, str *_ruid);
+int delete_urecord_by_ruid(udomain_t *_d, str *_ruid);
 
 
 /* ===== Module interface ======== */
@@ -138,7 +136,7 @@ int delete_urecord_by_ruid(udomain_t* _d, str *_ruid);
  * it is not necessary, as this function already releases the record.
  * \param _r released record
  */
-void release_urecord(urecord_t* _r);
+void release_urecord(urecord_t *_r);
 
 
 /*!
@@ -149,8 +147,8 @@ void release_urecord(urecord_t* _r);
  * \param _c new created contact
  * \return 0 on success, -1 on failure
  */
-int insert_ucontact(urecord_t* _r, str* _contact,
-		ucontact_info_t* _ci, ucontact_t** _c);
+int insert_ucontact(
+		urecord_t *_r, str *_contact, ucontact_info_t *_ci, ucontact_t **_c);
 
 
 /*!
@@ -159,7 +157,7 @@ int insert_ucontact(urecord_t* _r, str* _contact,
  * \param _c deleted contact
  * \return 0 on success, -1 on failure
  */
-int delete_ucontact(urecord_t* _r, struct ucontact* _c);
+int delete_ucontact(urecord_t *_r, struct ucontact *_c);
 
 
 /*!
@@ -173,9 +171,8 @@ int delete_ucontact(urecord_t* _r, struct ucontact* _c);
  * \return 0 - found, 1 - not found, -1 - invalid found, 
  * -2 - found, but to be skipped (same cseq)
  */
-int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path,
-		int _cseq,
-		struct ucontact** _co);
+int get_ucontact(urecord_t *_r, str *_c, str *_callid, str *_path, int _cseq,
+		struct ucontact **_co);
 
 /*!
  * \brief Get pointer to ucontact with given contact
@@ -186,8 +183,8 @@ int get_ucontact(urecord_t* _r, str* _c, str* _callid, str* _path,
  * \return 0 - found, 1 - not found, -1 - invalid found, 
  * -2 - found, but to be skipped (same cseq)
  */
-int get_ucontact_by_instance(urecord_t* _r, str* _c, ucontact_info_t* _ci,
-		ucontact_t** _co);
+int get_ucontact_by_instance(
+		urecord_t *_r, str *_c, ucontact_info_t *_ci, ucontact_t **_co);
 
 int is_valid_tcpconn(ucontact_t *c);
 

+ 26 - 26
src/modules/usrloc/usrloc.c

@@ -40,45 +40,45 @@
  * \param api usrloc API
  * \return 0 on success, -1 on failure
  */
-int bind_usrloc(usrloc_api_t* api)
+int bind_usrloc(usrloc_api_t *api)
 {
-	if (!api) {
+	if(!api) {
 		LM_ERR("invalid parameter value\n");
 		return -1;
 	}
-	if (ul_init_flag==0) {
+	if(ul_init_flag == 0) {
 		LM_ERR("configuration error - trying to bind to usrloc module"
-				" before being initialized\n");
+			   " before being initialized\n");
 		return -1;
 	}
 
-	api->register_udomain   = register_udomain;
-	api->get_udomain        = get_udomain;
-	api->get_all_ucontacts  = get_all_ucontacts;
-	api->insert_urecord     = insert_urecord;
-	api->delete_urecord     = delete_urecord;
-	api->delete_urecord_by_ruid     = delete_urecord_by_ruid;
-	api->get_urecord        = get_urecord;
-	api->lock_udomain       = lock_udomain;
-	api->unlock_udomain     = unlock_udomain;
-	api->release_urecord    = release_urecord;
-	api->insert_ucontact    = insert_ucontact;
-	api->delete_ucontact    = delete_ucontact;
-	api->get_ucontact       = get_ucontact;
-	api->update_ucontact    = update_ucontact;
-	api->register_ulcb      = register_ulcb;
-	api->get_aorhash        = ul_get_aorhash;
+	api->register_udomain = register_udomain;
+	api->get_udomain = get_udomain;
+	api->get_all_ucontacts = get_all_ucontacts;
+	api->insert_urecord = insert_urecord;
+	api->delete_urecord = delete_urecord;
+	api->delete_urecord_by_ruid = delete_urecord_by_ruid;
+	api->get_urecord = get_urecord;
+	api->lock_udomain = lock_udomain;
+	api->unlock_udomain = unlock_udomain;
+	api->release_urecord = release_urecord;
+	api->insert_ucontact = insert_ucontact;
+	api->delete_ucontact = delete_ucontact;
+	api->get_ucontact = get_ucontact;
+	api->update_ucontact = update_ucontact;
+	api->register_ulcb = register_ulcb;
+	api->get_aorhash = ul_get_aorhash;
 
-	api->get_urecord_by_ruid      = get_urecord_by_ruid;
+	api->get_urecord_by_ruid = get_urecord_by_ruid;
 	api->get_ucontact_by_instance = get_ucontact_by_instance;
 
-	api->set_keepalive_timeout    = ul_set_keepalive_timeout;
-	api->refresh_keepalive        = ul_refresh_keepalive;
-	api->set_max_partition        = ul_set_max_partition;
+	api->set_keepalive_timeout = ul_set_keepalive_timeout;
+	api->refresh_keepalive = ul_refresh_keepalive;
+	api->set_max_partition = ul_set_max_partition;
 
 	api->use_domain = ul_use_domain;
-	api->db_mode    = ul_db_mode;
-	api->nat_flag   = ul_nat_bflag;
+	api->db_mode = ul_db_mode;
+	api->nat_flag = ul_nat_bflag;
 
 	return 0;
 }

+ 132 - 123
src/modules/usrloc/usrloc.h

@@ -32,13 +32,13 @@
 #include "../../core/str.h"
 #include "../../core/xavp.h"
 
-#define NO_DB         0
+#define NO_DB 0
 #define WRITE_THROUGH 1
-#define WRITE_BACK    2
-#define DB_ONLY       3
-#define DB_READONLY   4
+#define WRITE_BACK 2
+#define DB_ONLY 3
+#define DB_READONLY 4
 
-#define GAU_OPT_SERVER_ID  (1<<0)  /* filter query by server_id */
+#define GAU_OPT_SERVER_ID (1 << 0) /* filter query by server_id */
 
 /*forward declaration necessary for udomain*/
 
@@ -48,141 +48,149 @@ typedef struct udomain udomain_t;
 /*!
  * \brief States for in-memory contacts in regards to contact storage handler (db, in-memory, ldap etc)
  */
-typedef enum cstate {
-	CS_NEW,        /*!< New contact - not flushed yet */
-	CS_SYNC,       /*!< Synchronized contact with the database */
-	CS_DIRTY       /*!< Update contact - not flushed yet */
+typedef enum cstate
+{
+	CS_NEW,	 /*!< New contact - not flushed yet */
+	CS_SYNC, /*!< Synchronized contact with the database */
+	CS_DIRTY /*!< Update contact - not flushed yet */
 } cstate_t;
 
 
 /*! \brief Flags that can be associated with a Contact */
-typedef enum flags {
-	FL_NONE        = 0,          /*!< No flags set */
-	FL_MEM         = 1 << 0,     /*!< Update memory only */
-	FL_DMQRPL      = 1 << 1,     /*!< DMQ replication */
-	FL_EXPCLB      = 1 << 2,     /*!< Expired callback executed */
-	FL_ALL         = (int)0xFFFFFFFF  /*!< All flags set */
+typedef enum flags
+{
+	FL_NONE = 0,			 /*!< No flags set */
+	FL_MEM = 1 << 0,		 /*!< Update memory only */
+	FL_DMQRPL = 1 << 1,		 /*!< DMQ replication */
+	FL_EXPCLB = 1 << 2,		 /*!< Expired callback executed */
+	FL_ALL = (int)0xFFFFFFFF /*!< All flags set */
 } flags_t;
 
 /*! \brief Valid contact is a contact that either didn't expire yet or is permanent */
-#define VALID_CONTACT(c, t)   ((c->expires>t) || (c->expires==0))
+#define VALID_CONTACT(c, t) ((c->expires > t) || (c->expires == 0))
 
 struct hslot; /*!< Hash table slot */
 struct socket_info;
 /*! \brief Main structure for handling of registered Contact data */
-typedef struct ucontact {
-	str* domain;            /*!< Pointer to domain name (NULL terminated) */
-	str ruid;               /*!< Pointer to record internal unique id */
-	str* aor;               /*!< Pointer to the AOR string in record structure*/
-	str c;                  /*!< Contact address */
-	str received;           /*!< IP+port+protocol we received the REGISTER from */
-	str path;               /*!< Path header */
-	time_t expires;         /*!< Expires parameter */
-	qvalue_t q;             /*!< q parameter */
-	str callid;             /*!< Call-ID header field of registration */
-	int cseq;               /*!< CSeq value */
-	cstate_t state;         /*!< State of the contact (\ref cstate) */
-	unsigned int flags;     /*!< Various internal flags (sync, etc) */
-	unsigned int cflags;    /*!< Custom contact flags (from script - bflags) */
-	str user_agent;         /*!< User-Agent header field */
-	str uniq;               /*!< Uniq header field */
-	struct socket_info *sock; /*!< received socket */
-	time_t last_modified;   /*!< When the record was last modified */
-	time_t last_keepalive;  /*!< Last keepalive timestamp */
+typedef struct ucontact
+{
+	str *domain;		 /*!< Pointer to domain name (NULL terminated) */
+	str ruid;			 /*!< Pointer to record internal unique id */
+	str *aor;			 /*!< Pointer to the AOR string in record structure*/
+	str c;				 /*!< Contact address */
+	str received;		 /*!< IP+port+protocol we received the REGISTER from */
+	str path;			 /*!< Path header */
+	time_t expires;		 /*!< Expires parameter */
+	qvalue_t q;			 /*!< q parameter */
+	str callid;			 /*!< Call-ID header field of registration */
+	int cseq;			 /*!< CSeq value */
+	cstate_t state;		 /*!< State of the contact (\ref cstate) */
+	unsigned int flags;	 /*!< Various internal flags (sync, etc) */
+	unsigned int cflags; /*!< Custom contact flags (from script - bflags) */
+	str user_agent;		 /*!< User-Agent header field */
+	str uniq;			 /*!< Uniq header field */
+	struct socket_info *sock;  /*!< received socket */
+	time_t last_modified;	   /*!< When the record was last modified */
+	time_t last_keepalive;	   /*!< Last keepalive timestamp */
 	unsigned int ka_roundtrip; /*!< Keepalive roundtrip in microseconds */
-	unsigned int methods;   /*!< Supported methods */
-	str instance;           /*!< SIP instance value - gruu */
-	unsigned int reg_id;    /*!< reg-id parameters */
-	int server_id;          /*!< server id */
-	int tcpconn_id;         /*!< unique tcp connection id */
-	int keepalive;          /*!< keepalive */
-	sr_xavp_t * xavp;       /*!< per contact xavps */
-	struct ucontact* next;  /*!< Next contact in the linked list */
-	struct ucontact* prev;  /*!< Previous contact in the linked list */
+	unsigned int methods;	   /*!< Supported methods */
+	str instance;			   /*!< SIP instance value - gruu */
+	unsigned int reg_id;	   /*!< reg-id parameters */
+	int server_id;			   /*!< server id */
+	int tcpconn_id;			   /*!< unique tcp connection id */
+	int keepalive;			   /*!< keepalive */
+	sr_xavp_t *xavp;		   /*!< per contact xavps */
+	struct ucontact *next;	   /*!< Next contact in the linked list */
+	struct ucontact *prev;	   /*!< Previous contact in the linked list */
 } ucontact_t;
 
 
 /*! \brief Informations related to a contact */
-typedef struct ucontact_info {
-	str ruid;                 /*!< Pointer to record internal unique id */
-	str *c;                   /*!< Contact address */
-	str received;             /*!< Received interface */
-	str* path;                /*!< Path informations */
-	time_t expires;           /*!< Contact expires */
-	qvalue_t q;               /*!< Q-value */
-	str* callid;              /*!< call-ID */
-	int cseq;                 /*!< CSEQ number */
-	unsigned int flags;       /*!< message flags */
-	unsigned int cflags;      /*!< contact flags */
-	str *user_agent;          /*!< user agent header */
+typedef struct ucontact_info
+{
+	str ruid;				  /*!< Pointer to record internal unique id */
+	str *c;					  /*!< Contact address */
+	str received;			  /*!< Received interface */
+	str *path;				  /*!< Path informations */
+	time_t expires;			  /*!< Contact expires */
+	qvalue_t q;				  /*!< Q-value */
+	str *callid;			  /*!< call-ID */
+	int cseq;				  /*!< CSEQ number */
+	unsigned int flags;		  /*!< message flags */
+	unsigned int cflags;	  /*!< contact flags */
+	str *user_agent;		  /*!< user agent header */
 	struct socket_info *sock; /*!< socket informations */
-	unsigned int methods;     /*!< supported methods */
-	str instance;             /*!< SIP instance value - gruu */
-	unsigned int reg_id;      /*!< reg-id parameters */
-	int server_id;            /*!< server id */
-	int tcpconn_id;           /*!< connection id */
-	int keepalive;            /*!< keepalive */
-	sr_xavp_t * xavp;         /*!< per contact xavps */
-	time_t last_modified;     /*!< last modified */
+	unsigned int methods;	  /*!< supported methods */
+	str instance;			  /*!< SIP instance value - gruu */
+	unsigned int reg_id;	  /*!< reg-id parameters */
+	int server_id;			  /*!< server id */
+	int tcpconn_id;			  /*!< connection id */
+	int keepalive;			  /*!< keepalive */
+	sr_xavp_t *xavp;		  /*!< per contact xavps */
+	time_t last_modified;	  /*!< last modified */
 } ucontact_info_t;
 
-typedef struct udomain_head{
-    str* name;
+typedef struct udomain_head
+{
+	str *name;
 } udomain_head_t;
 
 /*! \brief
  * Basic hash table element
  */
-typedef struct urecord {
-	str* domain;                   /*!< Pointer to domain we belong to
+typedef struct urecord
+{
+	str *domain;		  /*!< Pointer to domain we belong to
                                     * ( null terminated string) */
-	str aor;                       /*!< Address of record */
-	unsigned int aorhash;          /*!< Hash over address of record */
-	ucontact_t* contacts;          /*!< One or more contact fields */
+	str aor;			  /*!< Address of record */
+	unsigned int aorhash; /*!< Hash over address of record */
+	ucontact_t *contacts; /*!< One or more contact fields */
 
-	struct hslot* slot;            /*!< Collision slot in the hash table
+	struct hslot *slot;	  /*!< Collision slot in the hash table
                                     * array we belong to */
-	struct urecord* prev;          /*!< Next item in the hash entry */
-	struct urecord* next;          /*!< Previous item in the hash entry */
+	struct urecord *prev; /*!< Next item in the hash entry */
+	struct urecord *next; /*!< Previous item in the hash entry */
 } urecord_t;
 
-typedef int (*insert_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r);
+typedef int (*insert_urecord_t)(
+		struct udomain *_d, str *_aor, struct urecord **_r);
 
-typedef int (*get_urecord_t)(struct udomain* _d, str* _aor, struct urecord** _r);
+typedef int (*get_urecord_t)(
+		struct udomain *_d, str *_aor, struct urecord **_r);
 
-typedef int (*get_urecord_by_ruid_t)(udomain_t* _d, unsigned int _aorhash,
-		str *_ruid, struct urecord** _r, struct ucontact** _c);
+typedef int (*get_urecord_by_ruid_t)(udomain_t *_d, unsigned int _aorhash,
+		str *_ruid, struct urecord **_r, struct ucontact **_c);
 
-typedef int  (*delete_urecord_t)(struct udomain* _d, str* _aor, struct urecord* _r);
+typedef int (*delete_urecord_t)(
+		struct udomain *_d, str *_aor, struct urecord *_r);
 
-typedef int  (*delete_urecord_by_ruid_t)(struct udomain* _d, str* _ruid);
+typedef int (*delete_urecord_by_ruid_t)(struct udomain *_d, str *_ruid);
 
-typedef int (*update_ucontact_t)(struct urecord* _r, struct ucontact* _c,
-		struct ucontact_info* _ci);
-typedef void (*release_urecord_t)(struct urecord* _r);
+typedef int (*update_ucontact_t)(
+		struct urecord *_r, struct ucontact *_c, struct ucontact_info *_ci);
+typedef void (*release_urecord_t)(struct urecord *_r);
 
-typedef int (*insert_ucontact_t)(struct urecord* _r, str* _contact,
-		struct ucontact_info* _ci, struct ucontact** _c);
+typedef int (*insert_ucontact_t)(struct urecord *_r, str *_contact,
+		struct ucontact_info *_ci, struct ucontact **_c);
 
-typedef int (*delete_ucontact_t)(struct urecord* _r, struct ucontact* _c);
+typedef int (*delete_ucontact_t)(struct urecord *_r, struct ucontact *_c);
 
-typedef int (*get_ucontact_t)(struct urecord* _r, str* _c, str* _callid,
-		str* _path, int _cseq,
-		struct ucontact** _co);
+typedef int (*get_ucontact_t)(struct urecord *_r, str *_c, str *_callid,
+		str *_path, int _cseq, struct ucontact **_co);
 
-typedef int (*get_ucontact_by_instance_t)(struct urecord* _r, str* _c,
-		ucontact_info_t* _ci, ucontact_t** _co);
+typedef int (*get_ucontact_by_instance_t)(
+		struct urecord *_r, str *_c, ucontact_info_t *_ci, ucontact_t **_co);
 
-typedef void (*lock_udomain_t)(struct udomain* _d, str *_aor);
+typedef void (*lock_udomain_t)(struct udomain *_d, str *_aor);
 
-typedef void (*unlock_udomain_t)(struct udomain* _d, str *_aor);
+typedef void (*unlock_udomain_t)(struct udomain *_d, str *_aor);
 
-typedef int (*register_udomain_t)(const char* _n, struct udomain** _d);
+typedef int (*register_udomain_t)(const char *_n, struct udomain **_d);
 
-typedef int  (*get_all_ucontacts_t) (void* buf, int len, unsigned int flags,
+typedef int (*get_all_ucontacts_t)(void *buf, int len, unsigned int flags,
 		unsigned int part_idx, unsigned int part_max, int options);
 
-typedef int (*get_udomain_t)(const char* _n, udomain_t** _d);
+typedef int (*get_udomain_t)(const char *_n, udomain_t **_d);
 
 typedef unsigned int (*ul_get_aorhash_t)(str *_aor);
 unsigned int ul_get_aorhash(str *_aor);
@@ -193,48 +201,49 @@ int ul_set_keepalive_timeout(int _to);
 typedef int (*ul_refresh_keepalive_t)(unsigned int _aorhash, str *_ruid);
 int ul_refresh_keepalive(unsigned int _aorhash, str *_ruid);
 
-int ul_update_keepalive(unsigned int _aorhash, str *_ruid, time_t tval,
-		unsigned int rtrip);
+int ul_update_keepalive(
+		unsigned int _aorhash, str *_ruid, time_t tval, unsigned int rtrip);
 
 typedef void (*ul_set_max_partition_t)(unsigned int m);
 
 /*! usrloc API export structure */
-typedef struct usrloc_api {
-	int           use_domain; /*! use_domain module parameter */
-	int           db_mode;    /*! db_mode module parameter */
-	unsigned int  nat_flag;   /*! nat_flag module parameter */
+typedef struct usrloc_api
+{
+	int use_domain;		   /*! use_domain module parameter */
+	int db_mode;		   /*! db_mode module parameter */
+	unsigned int nat_flag; /*! nat_flag module parameter */
 
-	register_udomain_t   register_udomain;
-	get_udomain_t        get_udomain;
-	get_all_ucontacts_t  get_all_ucontacts;
+	register_udomain_t register_udomain;
+	get_udomain_t get_udomain;
+	get_all_ucontacts_t get_all_ucontacts;
 
-	insert_urecord_t     insert_urecord;
-	delete_urecord_t     delete_urecord;
-	delete_urecord_by_ruid_t     delete_urecord_by_ruid;
-	get_urecord_t        get_urecord;
-	lock_udomain_t       lock_udomain;
-	unlock_udomain_t     unlock_udomain;
+	insert_urecord_t insert_urecord;
+	delete_urecord_t delete_urecord;
+	delete_urecord_by_ruid_t delete_urecord_by_ruid;
+	get_urecord_t get_urecord;
+	lock_udomain_t lock_udomain;
+	unlock_udomain_t unlock_udomain;
 
-	release_urecord_t    release_urecord;
-	insert_ucontact_t    insert_ucontact;
-	delete_ucontact_t    delete_ucontact;
-	get_ucontact_t       get_ucontact;
+	release_urecord_t release_urecord;
+	insert_ucontact_t insert_ucontact;
+	delete_ucontact_t delete_ucontact;
+	get_ucontact_t get_ucontact;
 
-	get_urecord_by_ruid_t       get_urecord_by_ruid;
-	get_ucontact_by_instance_t  get_ucontact_by_instance;
+	get_urecord_by_ruid_t get_urecord_by_ruid;
+	get_ucontact_by_instance_t get_ucontact_by_instance;
 
-	update_ucontact_t    update_ucontact;
+	update_ucontact_t update_ucontact;
 
-	register_ulcb_t      register_ulcb;
-	ul_get_aorhash_t     get_aorhash;
+	register_ulcb_t register_ulcb;
+	ul_get_aorhash_t get_aorhash;
 
 	ul_set_keepalive_timeout_t set_keepalive_timeout;
-	ul_refresh_keepalive_t     refresh_keepalive;
-	ul_set_max_partition_t     set_max_partition;
+	ul_refresh_keepalive_t refresh_keepalive;
+	ul_set_max_partition_t set_max_partition;
 } usrloc_api_t;
 
 
 /*! usrloc API export bind function */
-typedef int (*bind_usrloc_t)(usrloc_api_t* api);
+typedef int (*bind_usrloc_t)(usrloc_api_t *api);
 
 #endif

+ 262 - 231
src/modules/usrloc/usrloc_mod.c

@@ -44,15 +44,15 @@
 #include "../../core/sr_module.h"
 #include "../../core/dprint.h"
 #include "../../core/rpc_lookup.h"
-#include "../../core/timer.h"     /* register_timer */
+#include "../../core/timer.h"	   /* register_timer */
 #include "../../core/timer_proc.h" /* register_sync_timer */
 #include "../../core/globals.h"
-#include "../../core/ut.h"        /* str_init */
+#include "../../core/ut.h" /* str_init */
 #include "../../core/utils/sruid.h"
-#include "dlist.h"           /* register_udomain */
-#include "udomain.h"         /* {insert,delete,get,release}_urecord */
-#include "urecord.h"         /* {insert,delete,get}_ucontact */
-#include "ucontact.h"        /* update_ucontact */
+#include "dlist.h"	  /* register_udomain */
+#include "udomain.h"  /* {insert,delete,get,release}_urecord */
+#include "urecord.h"  /* {insert,delete,get}_ucontact */
+#include "ucontact.h" /* update_ucontact */
 #include "ul_rpc.h"
 #include "ul_callback.h"
 #include "ul_keepalive.h"
@@ -60,51 +60,54 @@
 
 MODULE_VERSION
 
-#define RUID_COL       "ruid"
-#define USER_COL       "username"
-#define DOMAIN_COL     "domain"
-#define CONTACT_COL    "contact"
-#define EXPIRES_COL    "expires"
-#define Q_COL          "q"
-#define CALLID_COL     "callid"
-#define CSEQ_COL       "cseq"
-#define FLAGS_COL      "flags"
-#define CFLAGS_COL     "cflags"
+#define RUID_COL "ruid"
+#define USER_COL "username"
+#define DOMAIN_COL "domain"
+#define CONTACT_COL "contact"
+#define EXPIRES_COL "expires"
+#define Q_COL "q"
+#define CALLID_COL "callid"
+#define CSEQ_COL "cseq"
+#define FLAGS_COL "flags"
+#define CFLAGS_COL "cflags"
 #define USER_AGENT_COL "user_agent"
-#define RECEIVED_COL   "received"
-#define PATH_COL       "path"
-#define SOCK_COL       "socket"
-#define METHODS_COL    "methods"
-#define INSTANCE_COL   "instance"
-#define REG_ID_COL     "reg_id"
-#define LAST_MOD_COL   "last_modified"
-#define SRV_ID_COL     "server_id"
-#define CON_ID_COL     "connection_id"
-#define KEEPALIVE_COL  "keepalive"
-#define PARTITION_COL  "partition"
-
-#define ULATTRS_USER_COL       "username"
-#define ULATTRS_DOMAIN_COL     "domain"
-#define ULATTRS_RUID_COL       "ruid"
-#define ULATTRS_ANAME_COL      "aname"
-#define ULATTRS_ATYPE_COL      "atype"
-#define ULATTRS_AVALUE_COL     "avalue"
-#define ULATTRS_LAST_MOD_COL   "last_modified"
-
-static int mod_init(void);                          /*!< Module initialization function */
-static void destroy(void);                          /*!< Module destroy function */
-static void ul_core_timer(unsigned int ticks, void* param);  /*!< Core timer handler */
-static void ul_local_timer(unsigned int ticks, void* param); /*!< Local timer handler */
-static void ul_db_clean_timer(unsigned int ticks, void* param); /*!< DB clean timer handler */
-static int child_init(int rank);                    /*!< Per-child init function */
+#define RECEIVED_COL "received"
+#define PATH_COL "path"
+#define SOCK_COL "socket"
+#define METHODS_COL "methods"
+#define INSTANCE_COL "instance"
+#define REG_ID_COL "reg_id"
+#define LAST_MOD_COL "last_modified"
+#define SRV_ID_COL "server_id"
+#define CON_ID_COL "connection_id"
+#define KEEPALIVE_COL "keepalive"
+#define PARTITION_COL "partition"
+
+#define ULATTRS_USER_COL "username"
+#define ULATTRS_DOMAIN_COL "domain"
+#define ULATTRS_RUID_COL "ruid"
+#define ULATTRS_ANAME_COL "aname"
+#define ULATTRS_ATYPE_COL "atype"
+#define ULATTRS_AVALUE_COL "avalue"
+#define ULATTRS_LAST_MOD_COL "last_modified"
+
+static int mod_init(void); /*!< Module initialization function */
+static void destroy(void); /*!< Module destroy function */
+static void ul_core_timer(
+		unsigned int ticks, void *param); /*!< Core timer handler */
+static void ul_local_timer(
+		unsigned int ticks, void *param); /*!< Local timer handler */
+static void ul_db_clean_timer(
+		unsigned int ticks, void *param); /*!< DB clean timer handler */
+static int child_init(int rank);		  /*!< Per-child init function */
 static int ul_sip_reply_received(sip_msg_t *msg); /*!< SIP response handling */
 
-#define UL_PRELOAD_SIZE	8
-static char* ul_preload_list[UL_PRELOAD_SIZE];
+#define UL_PRELOAD_SIZE 8
+static char *ul_preload_list[UL_PRELOAD_SIZE];
 static int ul_preload_index = 0;
-static int ul_preload_param(modparam_t type, void* val);
+static int ul_preload_param(modparam_t type, void *val);
 
-extern int bind_usrloc(usrloc_api_t* api);
+extern int bind_usrloc(usrloc_api_t *api);
 int ul_db_update_as_insert = 0;
 int ul_timer_procs = 0;
 int ul_db_check_update = 0;
@@ -135,50 +138,84 @@ sruid_t _ul_sruid;
  * Module parameters and their default values
  */
 
-str ul_ruid_col        = str_init(RUID_COL); 		/*!< Name of column containing record unique id */
-str ul_user_col        = str_init(USER_COL); 		/*!< Name of column containing usernames */
-str ul_domain_col      = str_init(DOMAIN_COL); 	/*!< Name of column containing domains */
-str ul_contact_col     = str_init(CONTACT_COL);	/*!< Name of column containing contact addresses */
-str ul_expires_col     = str_init(EXPIRES_COL);	/*!< Name of column containing expires values */
-str ul_q_col           = str_init(Q_COL);			/*!< Name of column containing q values */
-str ul_callid_col      = str_init(CALLID_COL);		/*!< Name of column containing callid string */
-str ul_cseq_col        = str_init(CSEQ_COL);		/*!< Name of column containing cseq values */
-str ul_flags_col       = str_init(FLAGS_COL);		/*!< Name of column containing internal flags */
-str ul_cflags_col      = str_init(CFLAGS_COL);		/*!< Name of column containing contact flags */
-str ul_user_agent_col  = str_init(USER_AGENT_COL);	/*!< Name of column containing user agent string */
-str ul_received_col    = str_init(RECEIVED_COL);	/*!< Name of column containing transport info of REGISTER */
-str ul_path_col        = str_init(PATH_COL);		/*!< Name of column containing the Path header */
-str ul_sock_col        = str_init(SOCK_COL);		/*!< Name of column containing the received socket */
-str ul_methods_col     = str_init(METHODS_COL);	/*!< Name of column containing the supported methods */
-str ul_instance_col    = str_init(INSTANCE_COL);	/*!< Name of column containing the SIP instance value */
-str ul_reg_id_col      = str_init(REG_ID_COL);		/*!< Name of column containing the reg-id value */
-str ul_last_mod_col    = str_init(LAST_MOD_COL);	/*!< Name of column containing the last modified date */
-str ul_srv_id_col      = str_init(SRV_ID_COL);		/*!< Name of column containing the server id value */
-str ul_con_id_col      = str_init(CON_ID_COL);		/*!< Name of column containing the connection id value */
-str ul_keepalive_col   = str_init(KEEPALIVE_COL);	/*!< Name of column containing the keepalive value */
-str ul_partition_col   = str_init(PARTITION_COL);	/*!< Name of column containing the partition value */
-
-str ulattrs_user_col   = str_init(ULATTRS_USER_COL);   /*!< Name of column containing username */
-str ulattrs_domain_col = str_init(ULATTRS_DOMAIN_COL); /*!< Name of column containing domain */
-str ulattrs_ruid_col   = str_init(ULATTRS_RUID_COL);   /*!< Name of column containing record unique id */
-str ulattrs_aname_col  = str_init(ULATTRS_ANAME_COL);  /*!< Name of column containing attribute name */
-str ulattrs_atype_col  = str_init(ULATTRS_ATYPE_COL);  /*!< Name of column containing attribute type */
-str ulattrs_avalue_col = str_init(ULATTRS_AVALUE_COL); /*!< Name of column containing attribute value */
-str ulattrs_last_mod_col = str_init(ULATTRS_LAST_MOD_COL);	/*!< Name of column containing the last modified date */
-
-str ul_db_url          = str_init(DEFAULT_DB_URL);	/*!< Database URL */
-int ul_timer_interval  = 60;				/*!< Timer interval in seconds */
-int ul_db_mode         = 0;				/*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */
-int ul_db_load         = 1;				/*!< Database load after restart: 1- true, 0- false (only the db_mode allows it) */
-int ul_db_insert_update = 0;				/*!< Database : update on duplicate key instead of error */
-int ul_use_domain      = 0;				/*!< Whether usrloc should use domain part of aor */
-int ul_desc_time_order = 0;				/*!< By default do not enable timestamp ordering */
-int ul_handle_lost_tcp = 0;				/*!< By default do not remove contacts before expiration time */
-int ul_close_expired_tcp = 0;				/*!< By default do not close TCP connections for expired contacts */
-int ul_skip_remote_socket = 0;				/*!< By default do not skip remote socket */
-int ul_db_clean_tcp = 0;				/*!< Clean TCP/TLS/WSS contacts in DB before loading records */
-
-int ul_fetch_rows = 2000;				/*!< number of rows to fetch from result */
+str ul_ruid_col =
+		str_init(RUID_COL); /*!< Name of column containing record unique id */
+str ul_user_col =
+		str_init(USER_COL); /*!< Name of column containing usernames */
+str ul_domain_col =
+		str_init(DOMAIN_COL); /*!< Name of column containing domains */
+str ul_contact_col = str_init(
+		CONTACT_COL); /*!< Name of column containing contact addresses */
+str ul_expires_col =
+		str_init(EXPIRES_COL);	/*!< Name of column containing expires values */
+str ul_q_col = str_init(Q_COL); /*!< Name of column containing q values */
+str ul_callid_col =
+		str_init(CALLID_COL); /*!< Name of column containing callid string */
+str ul_cseq_col =
+		str_init(CSEQ_COL); /*!< Name of column containing cseq values */
+str ul_flags_col =
+		str_init(FLAGS_COL); /*!< Name of column containing internal flags */
+str ul_cflags_col =
+		str_init(CFLAGS_COL); /*!< Name of column containing contact flags */
+str ul_user_agent_col = str_init(
+		USER_AGENT_COL); /*!< Name of column containing user agent string */
+str ul_received_col = str_init(
+		RECEIVED_COL); /*!< Name of column containing transport info of REGISTER */
+str ul_path_col =
+		str_init(PATH_COL); /*!< Name of column containing the Path header */
+str ul_sock_col = str_init(
+		SOCK_COL); /*!< Name of column containing the received socket */
+str ul_methods_col = str_init(
+		METHODS_COL); /*!< Name of column containing the supported methods */
+str ul_instance_col = str_init(
+		INSTANCE_COL); /*!< Name of column containing the SIP instance value */
+str ul_reg_id_col =
+		str_init(REG_ID_COL); /*!< Name of column containing the reg-id value */
+str ul_last_mod_col = str_init(
+		LAST_MOD_COL); /*!< Name of column containing the last modified date */
+str ul_srv_id_col = str_init(
+		SRV_ID_COL); /*!< Name of column containing the server id value */
+str ul_con_id_col = str_init(
+		CON_ID_COL); /*!< Name of column containing the connection id value */
+str ul_keepalive_col = str_init(
+		KEEPALIVE_COL); /*!< Name of column containing the keepalive value */
+str ul_partition_col = str_init(
+		PARTITION_COL); /*!< Name of column containing the partition value */
+
+str ulattrs_user_col =
+		str_init(ULATTRS_USER_COL); /*!< Name of column containing username */
+str ulattrs_domain_col =
+		str_init(ULATTRS_DOMAIN_COL); /*!< Name of column containing domain */
+str ulattrs_ruid_col = str_init(
+		ULATTRS_RUID_COL); /*!< Name of column containing record unique id */
+str ulattrs_aname_col = str_init(
+		ULATTRS_ANAME_COL); /*!< Name of column containing attribute name */
+str ulattrs_atype_col = str_init(
+		ULATTRS_ATYPE_COL); /*!< Name of column containing attribute type */
+str ulattrs_avalue_col = str_init(
+		ULATTRS_AVALUE_COL); /*!< Name of column containing attribute value */
+str ulattrs_last_mod_col = str_init(
+		ULATTRS_LAST_MOD_COL); /*!< Name of column containing the last modified date */
+
+str ul_db_url = str_init(DEFAULT_DB_URL); /*!< Database URL */
+int ul_timer_interval = 60;				  /*!< Timer interval in seconds */
+int ul_db_mode =
+		0; /*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */
+int ul_db_load =
+		1; /*!< Database load after restart: 1- true, 0- false (only the db_mode allows it) */
+int ul_db_insert_update =
+		0; /*!< Database : update on duplicate key instead of error */
+int ul_use_domain = 0;		/*!< Whether usrloc should use domain part of aor */
+int ul_desc_time_order = 0; /*!< By default do not enable timestamp ordering */
+int ul_handle_lost_tcp =
+		0; /*!< By default do not remove contacts before expiration time */
+int ul_close_expired_tcp =
+		0; /*!< By default do not close TCP connections for expired contacts */
+int ul_skip_remote_socket = 0; /*!< By default do not skip remote socket */
+int ul_db_clean_tcp =
+		0; /*!< Clean TCP/TLS/WSS contacts in DB before loading records */
+
+int ul_fetch_rows = 2000; /*!< number of rows to fetch from result */
 int ul_hash_size = 10;
 int ul_db_insert_null = 0;
 int ul_db_timer_clean = 0;
@@ -187,7 +224,7 @@ int ul_db_timer_clean = 0;
 unsigned int ul_nat_bflag = (unsigned int)-1;
 unsigned int ul_init_flag = 0;
 
-db1_con_t* ul_dbh = 0; /* Database connection handle */
+db1_con_t *ul_dbh = 0; /* Database connection handle */
 db_func_t ul_dbf;
 
 /* filter on load and during cleanup by server id */
@@ -197,95 +234,90 @@ unsigned int ul_db_srvid = 0;
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-	{"ul_bind_usrloc",        (cmd_function)bind_usrloc,        1, 0, 0, 0},
-	{0, 0, 0, 0, 0, 0}
-};
+		{"ul_bind_usrloc", (cmd_function)bind_usrloc, 1, 0, 0, 0},
+		{0, 0, 0, 0, 0, 0}};
 
 
 /*! \brief
  * Exported parameters
  */
-static param_export_t params[] = {
-	{"ruid_column",         PARAM_STR, &ul_ruid_col      },
-	{"user_column",         PARAM_STR, &ul_user_col      },
-	{"domain_column",       PARAM_STR, &ul_domain_col    },
-	{"contact_column",      PARAM_STR, &ul_contact_col   },
-	{"expires_column",      PARAM_STR, &ul_expires_col   },
-	{"q_column",            PARAM_STR, &ul_q_col         },
-	{"callid_column",       PARAM_STR, &ul_callid_col    },
-	{"cseq_column",         PARAM_STR, &ul_cseq_col      },
-	{"flags_column",        PARAM_STR, &ul_flags_col     },
-	{"cflags_column",       PARAM_STR, &ul_cflags_col    },
-	{"db_url",              PARAM_STR, &ul_db_url        },
-	{"timer_interval",      INT_PARAM, &ul_timer_interval  },
-	{"db_mode",             INT_PARAM, &ul_db_mode         },
-	{"db_load",             INT_PARAM, &ul_db_load         },
-	{"db_insert_update",    INT_PARAM, &ul_db_insert_update },
-	{"use_domain",          INT_PARAM, &ul_use_domain      },
-	{"desc_time_order",     INT_PARAM, &ul_desc_time_order },
-	{"user_agent_column",   PARAM_STR, &ul_user_agent_col},
-	{"received_column",     PARAM_STR, &ul_received_col  },
-	{"path_column",         PARAM_STR, &ul_path_col      },
-	{"socket_column",       PARAM_STR, &ul_sock_col      },
-	{"methods_column",      PARAM_STR, &ul_methods_col   },
-	{"instance_column",     PARAM_STR, &ul_instance_col  },
-	{"reg_id_column",       PARAM_STR, &ul_reg_id_col    },
-	{"server_id_column",    PARAM_STR, &ul_srv_id_col    },
-	{"connection_id_column",PARAM_STR, &ul_con_id_col    },
-	{"keepalive_column",    PARAM_STR, &ul_keepalive_col },
-	{"partition_column",    PARAM_STR, &ul_partition_col },
-	{"matching_mode",       INT_PARAM, &ul_matching_mode },
-	{"cseq_delay",          INT_PARAM, &ul_cseq_delay      },
-	{"fetch_rows",          INT_PARAM, &ul_fetch_rows   },
-	{"hash_size",           INT_PARAM, &ul_hash_size    },
-	{"nat_bflag",           INT_PARAM, &ul_nat_bflag       },
-	{"handle_lost_tcp",     INT_PARAM, &ul_handle_lost_tcp },
-	{"close_expired_tcp",   INT_PARAM, &ul_close_expired_tcp },
-	{"skip_remote_socket",  INT_PARAM, &ul_skip_remote_socket },
-	{"preload",             PARAM_STRING|USE_FUNC_PARAM, (void*)ul_preload_param},
-	{"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert},
-	{"timer_procs",         INT_PARAM, &ul_timer_procs},
-	{"db_check_update",     INT_PARAM, &ul_db_check_update},
-	{"xavp_contact",        PARAM_STR, &ul_xavp_contact_name},
-	{"db_ops_ruid",         INT_PARAM, &ul_db_ops_ruid},
-	{"expires_type",        PARAM_INT, &ul_expires_type},
-	{"db_raw_fetch_type",   PARAM_INT, &ul_db_raw_fetch_type},
-	{"db_insert_null",      PARAM_INT, &ul_db_insert_null},
-	{"server_id_filter",    PARAM_INT, &ul_db_srvid},
-	{"db_timer_clean",      PARAM_INT, &ul_db_timer_clean},
-	{"rm_expired_delay",    PARAM_INT, &ul_rm_expired_delay},
-	{"version_table",       PARAM_INT, &ul_version_table},
-	{"ka_mode",             PARAM_INT, &ul_ka_mode},
-	{"ka_from",             PARAM_STR, &ul_ka_from},
-	{"ka_domain",           PARAM_STR, &ul_ka_domain},
-	{"ka_method",           PARAM_STR, &ul_ka_method},
-	{"ka_filter",           PARAM_INT, &ul_ka_filter},
-	{"ka_timeout",          PARAM_INT, &ul_keepalive_timeout},
-	{"ka_loglevel",         PARAM_INT, &ul_ka_loglevel},
-	{"ka_logmsg",           PARAM_STR, &ul_ka_logmsg},
-	{"load_rank",           PARAM_INT, &ul_load_rank},
-	{"db_clean_tcp",        PARAM_INT, &ul_db_clean_tcp},
-	{0, 0, 0}
-};
+static param_export_t params[] = {{"ruid_column", PARAM_STR, &ul_ruid_col},
+		{"user_column", PARAM_STR, &ul_user_col},
+		{"domain_column", PARAM_STR, &ul_domain_col},
+		{"contact_column", PARAM_STR, &ul_contact_col},
+		{"expires_column", PARAM_STR, &ul_expires_col},
+		{"q_column", PARAM_STR, &ul_q_col},
+		{"callid_column", PARAM_STR, &ul_callid_col},
+		{"cseq_column", PARAM_STR, &ul_cseq_col},
+		{"flags_column", PARAM_STR, &ul_flags_col},
+		{"cflags_column", PARAM_STR, &ul_cflags_col},
+		{"db_url", PARAM_STR, &ul_db_url},
+		{"timer_interval", INT_PARAM, &ul_timer_interval},
+		{"db_mode", INT_PARAM, &ul_db_mode},
+		{"db_load", INT_PARAM, &ul_db_load},
+		{"db_insert_update", INT_PARAM, &ul_db_insert_update},
+		{"use_domain", INT_PARAM, &ul_use_domain},
+		{"desc_time_order", INT_PARAM, &ul_desc_time_order},
+		{"user_agent_column", PARAM_STR, &ul_user_agent_col},
+		{"received_column", PARAM_STR, &ul_received_col},
+		{"path_column", PARAM_STR, &ul_path_col},
+		{"socket_column", PARAM_STR, &ul_sock_col},
+		{"methods_column", PARAM_STR, &ul_methods_col},
+		{"instance_column", PARAM_STR, &ul_instance_col},
+		{"reg_id_column", PARAM_STR, &ul_reg_id_col},
+		{"server_id_column", PARAM_STR, &ul_srv_id_col},
+		{"connection_id_column", PARAM_STR, &ul_con_id_col},
+		{"keepalive_column", PARAM_STR, &ul_keepalive_col},
+		{"partition_column", PARAM_STR, &ul_partition_col},
+		{"matching_mode", INT_PARAM, &ul_matching_mode},
+		{"cseq_delay", INT_PARAM, &ul_cseq_delay},
+		{"fetch_rows", INT_PARAM, &ul_fetch_rows},
+		{"hash_size", INT_PARAM, &ul_hash_size},
+		{"nat_bflag", INT_PARAM, &ul_nat_bflag},
+		{"handle_lost_tcp", INT_PARAM, &ul_handle_lost_tcp},
+		{"close_expired_tcp", INT_PARAM, &ul_close_expired_tcp},
+		{"skip_remote_socket", INT_PARAM, &ul_skip_remote_socket},
+		{"preload", PARAM_STRING | USE_FUNC_PARAM, (void *)ul_preload_param},
+		{"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert},
+		{"timer_procs", INT_PARAM, &ul_timer_procs},
+		{"db_check_update", INT_PARAM, &ul_db_check_update},
+		{"xavp_contact", PARAM_STR, &ul_xavp_contact_name},
+		{"db_ops_ruid", INT_PARAM, &ul_db_ops_ruid},
+		{"expires_type", PARAM_INT, &ul_expires_type},
+		{"db_raw_fetch_type", PARAM_INT, &ul_db_raw_fetch_type},
+		{"db_insert_null", PARAM_INT, &ul_db_insert_null},
+		{"server_id_filter", PARAM_INT, &ul_db_srvid},
+		{"db_timer_clean", PARAM_INT, &ul_db_timer_clean},
+		{"rm_expired_delay", PARAM_INT, &ul_rm_expired_delay},
+		{"version_table", PARAM_INT, &ul_version_table},
+		{"ka_mode", PARAM_INT, &ul_ka_mode},
+		{"ka_from", PARAM_STR, &ul_ka_from},
+		{"ka_domain", PARAM_STR, &ul_ka_domain},
+		{"ka_method", PARAM_STR, &ul_ka_method},
+		{"ka_filter", PARAM_INT, &ul_ka_filter},
+		{"ka_timeout", PARAM_INT, &ul_keepalive_timeout},
+		{"ka_loglevel", PARAM_INT, &ul_ka_loglevel},
+		{"ka_logmsg", PARAM_STR, &ul_ka_logmsg},
+		{"load_rank", PARAM_INT, &ul_load_rank},
+		{"db_clean_tcp", PARAM_INT, &ul_db_clean_tcp}, {0, 0, 0}};
 
 
 stat_export_t mod_stats[] = {
-	{"registered_users" ,  STAT_IS_FUNC, (stat_var**)get_number_of_users  },
-	{0,0,0}
-};
+		{"registered_users", STAT_IS_FUNC, (stat_var **)get_number_of_users},
+		{0, 0, 0}};
 
 
 struct module_exports exports = {
-	"usrloc",        /*!< module name */
-	DEFAULT_DLFLAGS, /*!< dlopen flags */
-	cmds,            /*!< exported functions */
-	params,          /*!< exported parameters */
-	0,               /*!< exported rpc functions */
-	0,               /*!< exported pseudo-variables */
-	ul_sip_reply_received, /*!< response handling function */
-	mod_init,        /*!< module init function */
-	child_init,      /*!< child init function */
-	destroy          /*!< destroy function */
+		"usrloc",			   /*!< module name */
+		DEFAULT_DLFLAGS,	   /*!< dlopen flags */
+		cmds,				   /*!< exported functions */
+		params,				   /*!< exported parameters */
+		0,					   /*!< exported rpc functions */
+		0,					   /*!< exported pseudo-variables */
+		ul_sip_reply_received, /*!< response handling function */
+		mod_init,			   /*!< module init function */
+		child_init,			   /*!< child init function */
+		destroy				   /*!< destroy function */
 };
 
 
@@ -295,44 +327,44 @@ struct module_exports exports = {
 static int mod_init(void)
 {
 	int i;
-	udomain_t* d;
+	udomain_t *d;
 
-	if(ul_rm_expired_delay!=0) {
+	if(ul_rm_expired_delay != 0) {
 		if(ul_db_mode != DB_ONLY) {
 			LM_ERR("rm expired delay feature is available for db only mode\n");
 			return -1;
 		}
 	}
-	if(ul_rm_expired_delay<0) {
+	if(ul_rm_expired_delay < 0) {
 		LM_WARN("rm expired delay value is negative (%d) - setting it to 0\n",
 				ul_rm_expired_delay);
 		ul_rm_expired_delay = 0;
 	}
-	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0) {
+	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC) < 0) {
 		return -1;
 	}
 
 #ifdef STATISTICS
 	/* register statistics */
-	if (register_module_stats(exports.name, mod_stats)!=0 ) {
+	if(register_module_stats(exports.name, mod_stats) != 0) {
 		LM_ERR("failed to register core statistics\n");
 		return -1;
 	}
 #endif
 
-	if (rpc_register_array(ul_rpc)!=0) {
+	if(rpc_register_array(ul_rpc) != 0) {
 		LM_ERR("failed to register RPC commands\n");
 		return -1;
 	}
 
-	if(ul_hash_size<=1) {
+	if(ul_hash_size <= 1) {
 		ul_hash_size = 512;
 	} else {
-		ul_hash_size = 1<<ul_hash_size;
+		ul_hash_size = 1 << ul_hash_size;
 	}
 
 	/* check matching mode */
-	switch (ul_matching_mode) {
+	switch(ul_matching_mode) {
 		case CONTACT_ONLY:
 		case CONTACT_CALLID:
 		case CONTACT_PATH:
@@ -343,8 +375,8 @@ static int mod_init(void)
 	}
 
 	/* Register cache timer */
-	if(ul_timer_procs<=0) {
-		if (ul_timer_interval > 0) {
+	if(ul_timer_procs <= 0) {
+		if(ul_timer_interval > 0) {
 			register_timer(ul_core_timer, 0, ul_timer_interval);
 		}
 	} else {
@@ -352,63 +384,63 @@ static int mod_init(void)
 	}
 
 	/* init the callbacks list */
-	if (init_ulcb_list() < 0) {
+	if(init_ulcb_list() < 0) {
 		LM_ERR("usrloc/callbacks initialization failed\n");
 		return -1;
 	}
 
 	/* Shall we use database ? */
-	switch (ul_db_mode) {
+	switch(ul_db_mode) {
 		case DB_ONLY:
 		case WRITE_THROUGH:
 		case WRITE_BACK:
-		/*
+			/*
 		 * register the need to be called post-fork of all children
 		 * with the special rank PROC_POSTCHILDINIT
 		 */
-		ksr_module_set_flag(KSRMOD_FLAG_POSTCHILDINIT);
+			ksr_module_set_flag(KSRMOD_FLAG_POSTCHILDINIT);
 	}
-	if (ul_db_mode != NO_DB) { /* Yes */
-		if (db_bind_mod(&ul_db_url, &ul_dbf) < 0) { /* Find database module */
+	if(ul_db_mode != NO_DB) {					   /* Yes */
+		if(db_bind_mod(&ul_db_url, &ul_dbf) < 0) { /* Find database module */
 			LM_ERR("failed to bind database module\n");
 			return -1;
 		}
-		if (!DB_CAPABILITY(ul_dbf, DB_CAP_ALL)) {
+		if(!DB_CAPABILITY(ul_dbf, DB_CAP_ALL)) {
 			LM_ERR("database module does not implement all functions"
-					" needed by the module\n");
+				   " needed by the module\n");
 			return -1;
 		}
-		if(ul_fetch_rows<=0) {
+		if(ul_fetch_rows <= 0) {
 			LM_ERR("invalid fetch_rows number '%d'\n", ul_fetch_rows);
 			return -1;
 		}
 	}
-	if(ul_db_mode==WRITE_THROUGH || ul_db_mode==WRITE_BACK) {
-		if(ul_db_timer_clean!=0) {
-			if(sr_wtimer_add(ul_db_clean_timer, 0, ul_timer_interval)<0) {
+	if(ul_db_mode == WRITE_THROUGH || ul_db_mode == WRITE_BACK) {
+		if(ul_db_timer_clean != 0) {
+			if(sr_wtimer_add(ul_db_clean_timer, 0, ul_timer_interval) < 0) {
 				LM_ERR("failed to add db clean timer routine\n");
 				return -1;
 			}
 		}
 	}
 
-	if (ul_nat_bflag==(unsigned int)-1) {
+	if(ul_nat_bflag == (unsigned int)-1) {
 		ul_nat_bflag = 0;
-	} else if (ul_nat_bflag>=8*sizeof(ul_nat_bflag) ) {
+	} else if(ul_nat_bflag >= 8 * sizeof(ul_nat_bflag)) {
 		LM_ERR("bflag index (%d) too big!\n", ul_nat_bflag);
 		return -1;
 	} else {
-		ul_nat_bflag = 1<<ul_nat_bflag;
+		ul_nat_bflag = 1 << ul_nat_bflag;
 	}
 
-	for(i=0; i<ul_preload_index; i++) {
-		if(register_udomain((const char*)ul_preload_list[i], &d)<0) {
+	for(i = 0; i < ul_preload_index; i++) {
+		if(register_udomain((const char *)ul_preload_list[i], &d) < 0) {
 			LM_ERR("cannot register preloaded table %s\n", ul_preload_list[i]);
 			return -1;
 		}
 	}
 
-	if (ul_handle_lost_tcp && ul_db_mode == DB_ONLY) {
+	if(ul_handle_lost_tcp && ul_db_mode == DB_ONLY) {
 		LM_WARN("handle_lost_tcp option makes nothing in DB_ONLY mode\n");
 	}
 
@@ -418,7 +450,7 @@ static int mod_init(void)
 
 	if(ul_ka_mode != ULKA_NONE) {
 		/* set max partition number for timers processing of db records */
-		if (ul_timer_procs > 1) {
+		if(ul_timer_procs > 1) {
 			ul_set_max_partition((unsigned int)ul_timer_procs);
 		}
 		if(ul_ka_logmsg.len > 0) {
@@ -436,18 +468,18 @@ static int mod_init(void)
 
 static int child_init(int _rank)
 {
-	dlist_t* ptr;
+	dlist_t *ptr;
 	int i;
 
-	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0)
+	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC) < 0)
 		return -1;
 
-	if(_rank==PROC_MAIN && ul_timer_procs>0)
-	{
-		for(i=0; i<ul_timer_procs; i++)
-		{
+	if(_rank == PROC_MAIN && ul_timer_procs > 0) {
+		for(i = 0; i < ul_timer_procs; i++) {
 			if(fork_sync_timer(PROC_TIMER, "USRLOC Timer", 1 /*socks flag*/,
-					ul_local_timer, (void*)(long)i, ul_timer_interval /*sec*/)<0) {
+					   ul_local_timer, (void *)(long)i,
+					   ul_timer_interval /*sec*/)
+					< 0) {
 				LM_ERR("failed to start timer routine as process\n");
 				return -1; /* error */
 			}
@@ -455,43 +487,44 @@ static int child_init(int _rank)
 	}
 
 	/* connecting to DB ? */
-	switch (ul_db_mode) {
+	switch(ul_db_mode) {
 		case NO_DB:
 			return 0;
 		case DB_ONLY:
 		case WRITE_THROUGH:
 			/* connect to db only from SIP workers, TIMER and MAIN processes,
 			 *  and RPC processes */
-			if (_rank<=0 && _rank!=PROC_TIMER && _rank!=PROC_POSTCHILDINIT
-					 && _rank!=PROC_RPC)
+			if(_rank <= 0 && _rank != PROC_TIMER && _rank != PROC_POSTCHILDINIT
+					&& _rank != PROC_RPC)
 				return 0;
 			break;
 		case WRITE_BACK:
 			/* connect to db only from TIMER (for flush), from MAIN (for
 			 * final flush() and from child 1 for preload */
-			if (_rank!=PROC_TIMER && _rank!=PROC_POSTCHILDINIT && _rank!=PROC_SIPINIT)
+			if(_rank != PROC_TIMER && _rank != PROC_POSTCHILDINIT
+					&& _rank != PROC_SIPINIT)
 				return 0;
 			break;
 		case DB_READONLY:
 			/* connect to db only from child 1 for preload */
-			ul_db_load=1; /* we always load from the db in this mode */
-			if(_rank!=PROC_SIPINIT)
+			ul_db_load = 1; /* we always load from the db in this mode */
+			if(_rank != PROC_SIPINIT)
 				return 0;
 			break;
 	}
 
 	ul_dbh = ul_dbf.init(&ul_db_url); /* Get a database connection per child */
-	if (!ul_dbh) {
+	if(!ul_dbh) {
 		LM_ERR("child(%d): failed to connect to database\n", _rank);
 		return -1;
 	}
 	/* _rank==PROC_SIPINIT is used even when fork is disabled */
-	if (_rank==ul_load_rank && ul_db_mode!=DB_ONLY && ul_db_load) {
+	if(_rank == ul_load_rank && ul_db_mode != DB_ONLY && ul_db_load) {
 		/* if cache is used, populate domains from DB */
-		for(ptr=_ksr_ul_root ; ptr ; ptr=ptr->next) {
-			if (preload_udomain(ul_dbh, ptr->d) < 0) {
-				LM_ERR("child(%d): failed to preload domain '%.*s'\n",
-						_rank, ptr->name.len, ZSW(ptr->name.s));
+		for(ptr = _ksr_ul_root; ptr; ptr = ptr->next) {
+			if(preload_udomain(ul_dbh, ptr->d) < 0) {
+				LM_ERR("child(%d): failed to preload domain '%.*s'\n", _rank,
+						ptr->name.len, ZSW(ptr->name.s));
 				return -1;
 			}
 			uldb_preload_attrs(ptr->d);
@@ -508,8 +541,8 @@ static int child_init(int _rank)
 static void destroy(void)
 {
 	/* we need to sync DB in order to flush the cache */
-	if (ul_dbh) {
-		if (synchronize_all_udomains(0, 1) != 0) {
+	if(ul_dbh) {
+		if(synchronize_all_udomains(0, 1) != 0) {
 			LM_ERR("flushing cache failed\n");
 		}
 		ul_dbf.close(ul_dbh);
@@ -536,9 +569,9 @@ static int ul_sip_reply_received(sip_msg_t *msg)
 /*! \brief
  * Core timer handler
  */
-static void ul_core_timer(unsigned int ticks, void* param)
+static void ul_core_timer(unsigned int ticks, void *param)
 {
-	if (synchronize_all_udomains(0, 1) != 0) {
+	if(synchronize_all_udomains(0, 1) != 0) {
 		LM_ERR("synchronizing cache failed\n");
 	}
 }
@@ -546,9 +579,9 @@ static void ul_core_timer(unsigned int ticks, void* param)
 /*! \brief
  * Local timer handler
  */
-static void ul_local_timer(unsigned int ticks, void* param)
+static void ul_local_timer(unsigned int ticks, void *param)
 {
-	if (synchronize_all_udomains((int)(long)param, ul_timer_procs) != 0) {
+	if(synchronize_all_udomains((int)(long)param, ul_timer_procs) != 0) {
 		LM_ERR("synchronizing cache failed\n");
 	}
 }
@@ -556,7 +589,7 @@ static void ul_local_timer(unsigned int ticks, void* param)
 /*! \brief
  * DB dlean timer handler
  */
-static void ul_db_clean_timer(unsigned int ticks, void* param)
+static void ul_db_clean_timer(unsigned int ticks, void *param)
 {
 	ul_db_clean_udomains();
 }
@@ -564,19 +597,17 @@ static void ul_db_clean_timer(unsigned int ticks, void* param)
 /*! \brief
  * preload module parameter handler
  */
-static int ul_preload_param(modparam_t type, void* val)
+static int ul_preload_param(modparam_t type, void *val)
 {
-	if(val==NULL)
-	{
+	if(val == NULL) {
 		LM_ERR("invalid parameter\n");
 		goto error;
 	}
-	if(ul_preload_index>=UL_PRELOAD_SIZE)
-	{
+	if(ul_preload_index >= UL_PRELOAD_SIZE) {
 		LM_ERR("too many preloaded tables\n");
 		goto error;
 	}
-	ul_preload_list[ul_preload_index] = (char*)val;
+	ul_preload_list[ul_preload_index] = (char *)val;
 	ul_preload_index++;
 	return 0;
 error:

+ 18 - 16
src/modules/usrloc/usrloc_mod.h

@@ -97,7 +97,7 @@ extern unsigned int ul_init_flag;
 
 extern str ul_xavp_contact_name;
 
-extern db1_con_t* ul_dbh;   /* Database connection handle */
+extern db1_con_t *ul_dbh; /* Database connection handle */
 extern db_func_t ul_dbf;
 
 /* filter on load and during cleanup by server id */
@@ -106,10 +106,10 @@ extern unsigned int ul_db_srvid;
 /*
  * Matching algorithms
  */
-#define CONTACT_ONLY         (0)
-#define CONTACT_CALLID       (1)
-#define CONTACT_PATH         (2)
-#define CONTACT_CALLID_ONLY  (3)
+#define CONTACT_ONLY (0)
+#define CONTACT_CALLID (1)
+#define CONTACT_PATH (2)
+#define CONTACT_CALLID_ONLY (3)
 
 extern int ul_matching_mode;
 
@@ -117,16 +117,18 @@ extern int ul_db_ops_ruid;
 
 extern int ul_expires_type;
 
-#define UL_DB_EXPIRES_SET(r, v)   do { \
-			if(ul_expires_type==1) { \
-				(r)->type = DB1_BIGINT; \
-				(r)->val.ll_val = (long long)(v); \
-			} else { \
-				(r)->type = DB1_DATETIME; \
-				(r)->val.time_val = (time_t)(v); \
-			} \
-		} while(0)
-
-#define UL_DB_EXPIRES_GET(r)  ((ul_expires_type==1)?(time_t)VAL_BIGINT(r):VAL_TIME(r))
+#define UL_DB_EXPIRES_SET(r, v)               \
+	do {                                      \
+		if(ul_expires_type == 1) {            \
+			(r)->type = DB1_BIGINT;           \
+			(r)->val.ll_val = (long long)(v); \
+		} else {                              \
+			(r)->type = DB1_DATETIME;         \
+			(r)->val.time_val = (time_t)(v);  \
+		}                                     \
+	} while(0)
+
+#define UL_DB_EXPIRES_GET(r) \
+	((ul_expires_type == 1) ? (time_t)VAL_BIGINT(r) : VAL_TIME(r))
 
 #endif /* _USRLOC_MOD_H_ */

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott