Parcourir la source

uid_domain: clang-format for coherent indentation and coding style

Victor Seva il y a 2 ans
Parent
commit
488501c35e

+ 118 - 95
src/modules/uid_domain/domain.c

@@ -32,11 +32,11 @@
 /*
  * Search the list of domains for domain with given did
  */
-static domain_t* domain_search(domain_t* list, str* did)
+static domain_t *domain_search(domain_t *list, str *did)
 {
 	while(list) {
-		if (list->did.len == did->len &&
-			!memcmp(list->did.s, did->s, did->len)) {
+		if(list->did.len == did->len
+				&& !memcmp(list->did.s, did->s, did->len)) {
 			return list;
 		}
 		list = list->next;
@@ -48,28 +48,31 @@ static domain_t* domain_search(domain_t* list, str* did)
 /*
  * Add a new domain name to did
  */
-static int domain_add(domain_t* d, str* domain, unsigned int flags)
+static int domain_add(domain_t *d, str *domain, unsigned int flags)
 {
-	str* p1;
-	unsigned int* p2;
+	str *p1;
+	unsigned int *p2;
 	str dom;
 
-	if (!d || !domain) {
+	if(!d || !domain) {
 		ERR("Invalid parameter value\n");
 		return -1;
 	}
 
 	dom.s = shm_malloc(domain->len);
-	if (!dom.s) goto error;
+	if(!dom.s)
+		goto error;
 	memcpy(dom.s, domain->s, domain->len);
 	dom.len = domain->len;
 	strlower(&dom);
 
-	p1 = (str*)shm_realloc(d->domain, sizeof(str) * (d->n + 1));
-	if (!p1) goto error;
-	p2 = (unsigned int*)shm_realloc(d->flags,
-									sizeof(unsigned int) * (d->n + 1));
-	if (!p2) goto error;
+	p1 = (str *)shm_realloc(d->domain, sizeof(str) * (d->n + 1));
+	if(!p1)
+		goto error;
+	p2 = (unsigned int *)shm_realloc(
+			d->flags, sizeof(unsigned int) * (d->n + 1));
+	if(!p2)
+		goto error;
 
 	d->domain = p1;
 	d->domain[d->n] = dom;
@@ -81,7 +84,8 @@ static int domain_add(domain_t* d, str* domain, unsigned int flags)
 error:
 	SHM_MEM_ERROR;
 	ERR("Unable to add new domain name (out of memory)\n");
-	if (dom.s) shm_free(dom.s);
+	if(dom.s)
+		shm_free(dom.s);
 	return -1;
 }
 
@@ -89,60 +93,69 @@ error:
 /*
  * Release all memory allocated for given domain structure
  */
-static void free_domain(domain_t* d)
+static void free_domain(domain_t *d)
 {
 	int i;
-	if (!d) return;
-	if (d->did.s) shm_free(d->did.s);
+	if(!d)
+		return;
+	if(d->did.s)
+		shm_free(d->did.s);
 
 	for(i = 0; i < d->n; i++) {
-		if (d->domain[i].s) shm_free(d->domain[i].s);
+		if(d->domain[i].s)
+			shm_free(d->domain[i].s);
 	}
 	shm_free(d->domain);
 	shm_free(d->flags);
-	if (d->attrs) destroy_avp_list(&d->attrs);
+	if(d->attrs)
+		destroy_avp_list(&d->attrs);
 	shm_free(d);
 }
 
 
-
-
 /*
  * Create a new domain structure which will initialy have
  * one domain name
  */
-static domain_t* new_domain(str* did, str* domain, unsigned int flags)
+static domain_t *new_domain(str *did, str *domain, unsigned int flags)
 {
-	domain_t* d;
+	domain_t *d;
 	int_str name, val;
 	str name_s = STR_STATIC_INIT(AVP_DID);
 
-	d = (domain_t*)shm_malloc(sizeof(domain_t));
-	if (!d) goto error;
+	d = (domain_t *)shm_malloc(sizeof(domain_t));
+	if(!d)
+		goto error;
 	memset(d, 0, sizeof(domain_t));
 	d->did.s = shm_malloc(did->len);
-	if (!d->did.s) goto error;
+	if(!d->did.s)
+		goto error;
 	memcpy(d->did.s, did->s, did->len);
 	d->did.len = did->len;
 
-	d->domain = (str*)shm_malloc(sizeof(str));
-	if (!d->domain) goto error;
+	d->domain = (str *)shm_malloc(sizeof(str));
+	if(!d->domain)
+		goto error;
 	d->domain[0].s = shm_malloc(domain->len);
-	if (!d->domain[0].s) goto error;
+	if(!d->domain[0].s)
+		goto error;
 	memcpy(d->domain[0].s, domain->s, domain->len);
 	d->domain[0].len = domain->len;
 	strlower(d->domain);
 
-	d->flags = (unsigned int*)shm_malloc(sizeof(unsigned int));
-	if (!d->flags) goto error;
+	d->flags = (unsigned int *)shm_malloc(sizeof(unsigned int));
+	if(!d->flags)
+		goto error;
 	d->flags[0] = flags;
 	d->n = 1;
 
 	/* Create an attribute containing did of the domain */
 	name.s = name_s;
 	val.s = *did;
-	if (add_avp_list(&d->attrs, AVP_CLASS_DOMAIN | AVP_NAME_STR | AVP_VAL_STR,
-					 name, val) < 0) goto error;
+	if(add_avp_list(&d->attrs, AVP_CLASS_DOMAIN | AVP_NAME_STR | AVP_VAL_STR,
+			   name, val)
+			< 0)
+		goto error;
 
 	return d;
 
@@ -157,10 +170,11 @@ error:
 /*
  * Release all memory allocated for entire domain list
  */
-void free_domain_list(domain_t* list)
+void free_domain_list(domain_t *list)
 {
-	domain_t* ptr;
-	if (!list) return;
+	domain_t *ptr;
+	if(!list)
+		return;
 
 	while(list) {
 		ptr = list;
@@ -173,37 +187,37 @@ void free_domain_list(domain_t* list)
 /*
  * Load attributes from domain_attrs table
  */
-int db_load_domain_attrs(domain_t* d)
+int db_load_domain_attrs(domain_t *d)
 {
 	int_str name, v;
 	str avp_val;
-	db_res_t* res;
-	db_rec_t* rec;
+	db_res_t *res;
+	db_rec_t *rec;
 	unsigned short flags;
 
 	load_attrs_cmd->match[0].v.lstr = d->did;
 
-	if (db_exec(&res, load_attrs_cmd) < 0) {
+	if(db_exec(&res, load_attrs_cmd) < 0) {
 		ERR("Error while querying database\n");
 		return -1;
 	}
 
 	rec = db_first(res);
 	while(rec) {
-		if (rec->fld[0].flags & DB_NULL ||
-			rec->fld[1].flags & DB_NULL ||
-			rec->fld[3].flags & DB_NULL) {
+		if(rec->fld[0].flags & DB_NULL || rec->fld[1].flags & DB_NULL
+				|| rec->fld[3].flags & DB_NULL) {
 			ERR("Skipping row containing NULL entries\n");
 			goto skip;
 		}
 
-		if ((rec->fld[3].v.int4 & SRDB_LOAD_SER) == 0) goto skip;
+		if((rec->fld[3].v.int4 & SRDB_LOAD_SER) == 0)
+			goto skip;
 
 		/* Get AVP name */
 		name.s = rec->fld[0].v.lstr;
 
 		/* Test for NULL value */
-		if (rec->fld[2].flags & DB_NULL) {
+		if(rec->fld[2].flags & DB_NULL) {
 			avp_val.s = 0;
 			avp_val.len = 0;
 		} else {
@@ -211,19 +225,19 @@ int db_load_domain_attrs(domain_t* d)
 		}
 
 		flags = AVP_CLASS_DOMAIN | AVP_NAME_STR;
-		if (rec->fld[1].v.int4 == AVP_VAL_STR) {
+		if(rec->fld[1].v.int4 == AVP_VAL_STR) {
 			/* String AVP */
 			v.s = avp_val;
 			flags |= AVP_VAL_STR;
 		} else {
 			/* Integer AVP */
-			str2int(&avp_val, (unsigned*)&v.n);
+			str2int(&avp_val, (unsigned *)&v.n);
 		}
 
-		if (add_avp_list(&d->attrs, flags, name, v) < 0) {
+		if(add_avp_list(&d->attrs, flags, name, v) < 0) {
 			ERR("Error while adding domain attribute %.*s to domain %.*s, "
-				"skipping\n", name.s.len, ZSW(name.s.s),
-				d->did.len, ZSW(d->did.s));
+				"skipping\n",
+					name.s.len, ZSW(name.s.s), d->did.len, ZSW(d->did.s));
 		}
 
 	skip:
@@ -237,16 +251,16 @@ int db_load_domain_attrs(domain_t* d)
 /*
  * Create domain list from domain table
  */
-int load_domains(domain_t** dest)
+int load_domains(domain_t **dest)
 {
-	db_res_t* res = NULL;
-	db_rec_t* rec;
+	db_res_t *res = NULL;
+	db_rec_t *rec;
 	unsigned int flags;
-	domain_t* d, *list;
+	domain_t *d, *list;
 
 	list = 0;
 
-	if ((db_exec(&res, load_domains_cmd) < 0) || (res==NULL)) {
+	if((db_exec(&res, load_domains_cmd) < 0) || (res == NULL)) {
 		ERR("Error while querying database\n");
 		return -1;
 	}
@@ -258,9 +272,8 @@ int load_domains(domain_t** dest)
 		 * checking (dbtext does not) and perform sanity checks here to
 		 * make sure that we only load good entried
 		 */
-		if (rec->fld[0].flags & DB_NULL ||
-			rec->fld[1].flags & DB_NULL ||
-			rec->fld[2].flags & DB_NULL) {
+		if(rec->fld[0].flags & DB_NULL || rec->fld[1].flags & DB_NULL
+				|| rec->fld[2].flags & DB_NULL) {
 			ERR("Row with NULL column(s), skipping\n");
 			goto skip;
 		}
@@ -268,23 +281,26 @@ int load_domains(domain_t** dest)
 		flags = rec->fld[2].v.int4;
 
 		/* Skip entries that are disabled/scheduled for removal */
-		if (flags & SRDB_DISABLED) goto skip;
+		if(flags & SRDB_DISABLED)
+			goto skip;
 		/* Skip entries that are for serweb/ser-ctl only */
-		if (!(flags & SRDB_LOAD_SER)) goto skip;
+		if(!(flags & SRDB_LOAD_SER))
+			goto skip;
 
-		DBG("Processing entry (%.*s, %.*s, %u)\n",
-			rec->fld[0].v.lstr.len, ZSW(rec->fld[0].v.lstr.s),
-			rec->fld[1].v.lstr.len, ZSW(rec->fld[1].v.lstr.s),
-			flags);
+		DBG("Processing entry (%.*s, %.*s, %u)\n", rec->fld[0].v.lstr.len,
+				ZSW(rec->fld[0].v.lstr.s), rec->fld[1].v.lstr.len,
+				ZSW(rec->fld[1].v.lstr.s), flags);
 
 		d = domain_search(list, &rec->fld[0].v.lstr);
-		if (d) {
+		if(d) {
 			/* DID exists in the list, update it */
-			if (domain_add(d, &rec->fld[1].v.lstr, flags) < 0) goto error;
+			if(domain_add(d, &rec->fld[1].v.lstr, flags) < 0)
+				goto error;
 		} else {
 			/* DID does not exist yet, create a new entry */
 			d = new_domain(&rec->fld[0].v.lstr, &rec->fld[1].v.lstr, flags);
-			if (!d) goto error;
+			if(!d)
+				goto error;
 			d->next = list;
 			list = d;
 		}
@@ -296,10 +312,11 @@ int load_domains(domain_t** dest)
 	db_res_free(res);
 	res = NULL;
 
-	if (load_domain_attrs) {
+	if(load_domain_attrs) {
 		d = list;
 		while(d) {
-			if (db_load_domain_attrs(d) < 0) goto error;
+			if(db_load_domain_attrs(d) < 0)
+				goto error;
 			d = d->next;
 		}
 	}
@@ -307,8 +324,9 @@ int load_domains(domain_t** dest)
 	*dest = list;
 	return 0;
 
- error:
-	if (res) db_res_free(res);
+error:
+	if(res)
+		db_res_free(res);
 	free_domain_list(list);
 	return 1;
 }
@@ -320,43 +338,43 @@ int load_domains(domain_t** dest)
  * and -1 on error.  The result is allocated using pkg_malloc and must be
  * freed.
  */
-int db_get_did(str* did, str* domain)
+int db_get_did(str *did, str *domain)
 {
-	db_res_t* res = NULL;
-	db_rec_t* rec;
+	db_res_t *res = NULL;
+	db_rec_t *rec;
 
-	if (!domain) {
+	if(!domain) {
 		ERR("BUG:Invalid parameter value\n");
 		goto err;
 	}
 
 	get_did_cmd->match[0].v.lstr = *domain;
 
-	if (db_exec(&res, get_did_cmd) < 0) {
+	if(db_exec(&res, get_did_cmd) < 0) {
 		ERR("Error in database query\n");
 		goto err;
 	}
 
 	rec = db_first(res);
-	if (rec) {
+	if(rec) {
 		/* Test flags first, we are only interested in rows
 		 * that are not disabled
 		 */
-		if (rec->fld[1].flags & DB_NULL || (rec->fld[1].v.bitmap &
-											SRDB_DISABLED)) {
+		if(rec->fld[1].flags & DB_NULL
+				|| (rec->fld[1].v.bitmap & SRDB_DISABLED)) {
 			db_res_free(res);
 			return 0;
 		}
 
-		if (did) {
-			if (rec->fld[0].flags & DB_NULL) {
+		if(did) {
+			if(rec->fld[0].flags & DB_NULL) {
 				did->len = 0;
 				did->s = 0;
-				WARN("Domain '%.*s' has NULL did\n",
-					 domain->len, ZSW(domain->s));
+				WARN("Domain '%.*s' has NULL did\n", domain->len,
+						ZSW(domain->s));
 			} else {
 				did->s = pkg_malloc(rec->fld[0].v.lstr.len);
-				if (!did->s) {
+				if(!did->s) {
 					PKG_MEM_ERROR;
 					goto err;
 				}
@@ -372,8 +390,9 @@ int db_get_did(str* did, str* domain)
 		return 0;
 	}
 
- err:
-	if (res) db_res_free(res);
+err:
+	if(res)
+		db_res_free(res);
 	return -1;
 }
 
@@ -382,7 +401,7 @@ int db_get_did(str* did, str* domain)
  * of the locally configured domain names.
  * Returns 1 if yes and -1 otherwise
  */
-int is_domain_local(str* domain)
+int is_domain_local(str *domain)
 {
 	str tmp;
 
@@ -390,7 +409,7 @@ int is_domain_local(str* domain)
 	 * case insensitive
 	 */
 	tmp.s = pkg_malloc(domain->len);
-	if (!tmp.s) {
+	if(!tmp.s) {
 		PKG_MEM_ERROR;
 		return -1;
 	}
@@ -398,20 +417,24 @@ int is_domain_local(str* domain)
 	tmp.len = domain->len;
 	strlower(&tmp);
 
-	if (!db_mode) {
+	if(!db_mode) {
 		switch(db_get_did(0, &tmp)) {
-		case 1:  goto found;
-		default: goto not_found;
+			case 1:
+				goto found;
+			default:
+				goto not_found;
 		}
 	} else {
-		if (hash_lookup(0, *active_hash, &tmp) == 1) goto found;
-		else goto not_found;
+		if(hash_lookup(0, *active_hash, &tmp) == 1)
+			goto found;
+		else
+			goto not_found;
 	}
 
- found:
+found:
 	pkg_free(tmp.s);
 	return 1;
- not_found:
+not_found:
 	pkg_free(tmp.s);
 	return -1;
 }

+ 18 - 16
src/modules/uid_domain/domain.h

@@ -31,8 +31,9 @@
 /*
  * Flags stored in flags column and their meaning
  */
-enum domain_flags {
-	DOMAIN_DISABLED  = (1 << 0), /* Domain has been disabled and should not be
+enum domain_flags
+{
+	DOMAIN_DISABLED = (1 << 0), /* Domain has been disabled and should not be
 								  * loaded from the database */
 	DOMAIN_CANONICAL = (1 << 1) /* Canonical domain name (to be used in user
 								 * interfaces a.s.o.) */
@@ -44,33 +45,34 @@ enum domain_flags {
  * is identified by unique domain ID.  Each domain can have several domain
  * names (also called aliases
  */
-typedef struct domain {
-	str did;             /* Unique domain ID */
-	int n;               /* Number of domain names */
-	str* domain;         /* Array of all domains associated with did */
-	unsigned int* flags; /* Flags of each domain in the domain array */
-	avp_list_t attrs;    /* List of domain attributes */
-	struct domain* next; /* Next domain in the list */
+typedef struct domain
+{
+	str did;			 /* Unique domain ID */
+	int n;				 /* Number of domain names */
+	str *domain;		 /* Array of all domains associated with did */
+	unsigned int *flags; /* Flags of each domain in the domain array */
+	avp_list_t attrs;	 /* List of domain attributes */
+	struct domain *next; /* Next domain in the list */
 } domain_t;
 
 
 /*
  * Create domain list from domain table
  */
-int load_domains(domain_t** dest);
+int load_domains(domain_t **dest);
 
 /*
  * Load domain attributes from database
  */
-int db_load_domain_attrs(domain_t* dest);
+int db_load_domain_attrs(domain_t *dest);
 
 
 /*
  * Release all memory allocated for entire domain list
  */
-void free_domain_list(domain_t* list);
+void free_domain_list(domain_t *list);
 
-typedef int (*domain_get_did_t)(str* did, str* domain);
+typedef int (*domain_get_did_t)(str *did, str *domain);
 
 
 /* Retrieve did directly from database, without using memory cache. Use 0 as
@@ -79,14 +81,14 @@ typedef int (*domain_get_did_t)(str* did, str* domain);
  * and -1 on error.  The result is allocated using pkg_malloc and must be
  * freed.
  */
-int db_get_did(str* did, str* domain);
+int db_get_did(str *did, str *domain);
 
 /* Check if the domain name given in the parameter is one
  * of the locally configured domain names.
  * Returns 1 if yes and -1 otherwise
  */
-typedef int (*is_domain_local_f)(str* domain);
-int is_domain_local(str* domain);
+typedef int (*is_domain_local_f)(str *domain);
+int is_domain_local(str *domain);
 
 
 #endif /* _DOMAIN_H */

+ 2 - 2
src/modules/uid_domain/domain_api.c

@@ -25,9 +25,9 @@
 #include "domain.h"
 
 
-int bind_domain(domain_api_t* api)
+int bind_domain(domain_api_t *api)
 {
-	if (api == NULL) {
+	if(api == NULL) {
 		ERR("Invalid parameter value\n");
 		return -1;
 	}

+ 7 - 6
src/modules/uid_domain/domain_api.h

@@ -27,25 +27,26 @@
 #include "../../core/dprint.h"
 #include "domain.h"
 
-typedef struct domain_api {
+typedef struct domain_api
+{
 	is_domain_local_f is_domain_local;
 } domain_api_t;
 
-typedef int (*bind_domain_f)(domain_api_t* api);
-int bind_domain(domain_api_t* api);
+typedef int (*bind_domain_f)(domain_api_t *api);
+int bind_domain(domain_api_t *api);
 
-static inline int load_domain_api(domain_api_t* api)
+static inline int load_domain_api(domain_api_t *api)
 {
 	bind_domain_f bind_domain;
 
 	bind_domain = (bind_domain_f)find_export("bind_domain", 0, 0);
 
-	if (bind_domain == NULL) {
+	if(bind_domain == NULL) {
 		ERR("Cannot import bind_domain function from domain module\n");
 		return -1;
 	}
 
-	if (bind_domain(api) == -1) {
+	if(bind_domain(api) == -1) {
 		return -1;
 	}
 	return 0;

+ 37 - 35
src/modules/uid_domain/domain_rpc.c

@@ -29,39 +29,46 @@
 #include "domain_rpc.h"
 
 
-static void dump_domain(rpc_t* rpc, void* ctx, domain_t* d)
+static void dump_domain(rpc_t *rpc, void *ctx, domain_t *d)
 {
-	avp_t* a;
-	void* st;
+	avp_t *a;
+	void *st;
 	int i;
-	str* name;
+	str *name;
 	int_str val;
 
-	if (rpc->add(ctx, "{", &st) < 0) return;
-	if (rpc->struct_add(st, "S", "did", &d->did) < 0) return;
+	if(rpc->add(ctx, "{", &st) < 0)
+		return;
+	if(rpc->struct_add(st, "S", "did", &d->did) < 0)
+		return;
 
 	for(i = 0; i < d->n; i++) {
-		if (rpc->struct_add(st, "S", "domain", &d->domain[i]) < 0) return;
-		if (rpc->struct_add(st, "d", "flags", d->flags[i]) < 0) return;
+		if(rpc->struct_add(st, "S", "domain", &d->domain[i]) < 0)
+			return;
+		if(rpc->struct_add(st, "d", "flags", d->flags[i]) < 0)
+			return;
 	}
 
 	a = d->attrs;
 	while(a) {
 		name = get_avp_name(a);
 		get_avp_val(a, &val);
-		if (a->flags & AVP_VAL_STR) {
-			if (rpc->struct_printf(st, "attr", "%.*s=%.*s",
-								   STR_FMT(name), STR_FMT(&val.s)) < 0) return;
+		if(a->flags & AVP_VAL_STR) {
+			if(rpc->struct_printf(
+					   st, "attr", "%.*s=%.*s", STR_FMT(name), STR_FMT(&val.s))
+					< 0)
+				return;
 		} else {
-			if (rpc->struct_printf(st, "attr", "%.*s=%d",
-								   STR_FMT(name), val.n) < 0) return;
+			if(rpc->struct_printf(st, "attr", "%.*s=%d", STR_FMT(name), val.n)
+					< 0)
+				return;
 		}
 		a = a->next;
 	}
 }
 
 
-void dump_domain_list(rpc_t* rpc, void* ctx, domain_t* list)
+void dump_domain_list(rpc_t *rpc, void *ctx, domain_t *list)
 {
 	while(list) {
 		dump_domain(rpc, ctx, list);
@@ -70,55 +77,50 @@ void dump_domain_list(rpc_t* rpc, void* ctx, domain_t* list)
 }
 
 
-static const char* domain_reload_doc[2] = {
-	"Reload domain table from database",
-	0
-};
+static const char *domain_reload_doc[2] = {
+		"Reload domain table from database", 0};
 
 
 /*
  * Fifo function to reload domain table
  */
-static void domain_reload(rpc_t* rpc, void* ctx)
+static void domain_reload(rpc_t *rpc, void *ctx)
 {
-	if (!db_mode) {
+	if(!db_mode) {
 		rpc->fault(ctx, 200, "Server Domain Cache Disabled");
 		return;
 	}
 
-	if (reload_domain_list() < 0) {
+	if(reload_domain_list() < 0) {
 		rpc->fault(ctx, 400, "Domain Table Reload Failed");
 	}
 }
 
 
-
-static const char* domain_dump_doc[2] = {
-	"Return the contents of domain table",
-	0
-};
+static const char *domain_dump_doc[2] = {
+		"Return the contents of domain table", 0};
 
 
 /*
  * Fifo function to print domains from current hash table
  */
-static void domain_dump(rpc_t* rpc, void* ctx)
+static void domain_dump(rpc_t *rpc, void *ctx)
 {
-	domain_t* list;
+	domain_t *list;
 
-	if (!db_mode) {
+	if(!db_mode) {
 		rpc->fault(ctx, 400, "Server Domain Cache Disabled");
 		return;
 	}
 
-	if (*active_hash == hash_1) list = *domains_1;
-	else list = *domains_2;
+	if(*active_hash == hash_1)
+		list = *domains_1;
+	else
+		list = *domains_2;
 	dump_domain_list(rpc, ctx, list);
 }
 
 
 rpc_export_t domain_rpc[] = {
-	{"domain.reload", domain_reload, domain_reload_doc, 0},
-	{"domain.dump",   domain_dump,   domain_dump_doc,   0},
-	{0, 0, 0, 0}
-};
+		{"domain.reload", domain_reload, domain_reload_doc, 0},
+		{"domain.dump", domain_dump, domain_dump_doc, 0}, {0, 0, 0, 0}};

+ 35 - 29
src/modules/uid_domain/hash.c

@@ -42,8 +42,8 @@ static unsigned int calc_hash(str *key)
 	p = key->s;
 	len = key->len;
 
-	for (i = 0; i < len; i++) {
-		h = ( h << 5 ) - h + *(p + i);
+	for(i = 0; i < len; i++) {
+		h = (h << 5) - h + *(p + i);
 	}
 
 	return h % HASH_SIZE;
@@ -53,17 +53,17 @@ static unsigned int calc_hash(str *key)
 /*
  * Create new hash_entry structure from given key and domain
  */
-static struct hash_entry* new_hash_entry(str* key, domain_t* domain)
+static struct hash_entry *new_hash_entry(str *key, domain_t *domain)
 {
-	struct hash_entry* e;
+	struct hash_entry *e;
 
-	if (!key || !domain) {
+	if(!key || !domain) {
 		ERR("Invalid parameter value\n");
 		return 0;
 	}
 
-	e = (struct hash_entry*)shm_malloc(sizeof(struct hash_entry));
-	if (!e) {
+	e = (struct hash_entry *)shm_malloc(sizeof(struct hash_entry));
+	if(!e) {
 		SHM_MEM_ERROR;
 		return 0;
 	}
@@ -77,21 +77,23 @@ static struct hash_entry* new_hash_entry(str* key, domain_t* domain)
 /*
  * Release all memory allocated for given hash_entry structure
  */
-static void free_hash_entry(struct hash_entry* e)
+static void free_hash_entry(struct hash_entry *e)
 {
-	if (e) shm_free(e);
+	if(e)
+		shm_free(e);
 }
 
 
 /*
  * Free memory allocated for entire hash table
  */
-void free_table(struct hash_entry** table)
+void free_table(struct hash_entry **table)
 {
-	struct hash_entry* e;
+	struct hash_entry *e;
 	int i;
 
-	if (!table) return;
+	if(!table)
+		return;
 
 	for(i = 0; i < HASH_SIZE; i++) {
 		while(table[i]) {
@@ -106,13 +108,13 @@ void free_table(struct hash_entry** table)
 /*
  * Generate hash table, use domain names as hash keys
  */
-int gen_domain_table(struct hash_entry** table, domain_t* list)
+int gen_domain_table(struct hash_entry **table, domain_t *list)
 {
-	struct hash_entry* e;
+	struct hash_entry *e;
 	unsigned int slot;
 	int i;
 
-	if (!table) {
+	if(!table) {
 		ERR("Invalid parameter value\n");
 		return -1;
 	}
@@ -120,7 +122,8 @@ int gen_domain_table(struct hash_entry** table, domain_t* list)
 	while(list) {
 		for(i = 0; i < list->n; i++) {
 			e = new_hash_entry(&list->domain[i], list);
-			if (!e) goto error;
+			if(!e)
+				goto error;
 			slot = calc_hash(&list->domain[i]);
 			e->next = table[slot];
 			table[slot] = e;
@@ -130,7 +133,7 @@ int gen_domain_table(struct hash_entry** table, domain_t* list)
 	}
 	return 0;
 
- error:
+error:
 	free_table(table);
 	return -1;
 }
@@ -139,26 +142,27 @@ int gen_domain_table(struct hash_entry** table, domain_t* list)
 /*
  * Generate hash table, use did as hash key
  */
-int gen_did_table(struct hash_entry** table, domain_t* list)
+int gen_did_table(struct hash_entry **table, domain_t *list)
 {
 	unsigned int slot;
-	struct hash_entry* e;
+	struct hash_entry *e;
 
-	if (!table) {
+	if(!table) {
 		ERR("Invalid parameter value\n");
 		return -1;
 	}
 
 	while(list) {
 		e = new_hash_entry(&list->did, list);
-		if (!e) goto error;
+		if(!e)
+			goto error;
 		slot = calc_hash(&list->did);
 		e->next = table[slot];
 		table[slot] = e;
 		list = list->next;
 	}
 	return 0;
- error:
+error:
 	free_table(table);
 	return -1;
 }
@@ -167,17 +171,19 @@ int gen_did_table(struct hash_entry** table, domain_t* list)
 /*
  * Lookup key in the table
  */
-int hash_lookup(domain_t** d, struct hash_entry** table, str* key)
+int hash_lookup(domain_t **d, struct hash_entry **table, str *key)
 {
-	struct hash_entry* np;
+	struct hash_entry *np;
 
-	for (np = table[calc_hash(key)]; np != NULL; np = np->next) {
-		if ((np->key.len == key->len) &&
-			(strncmp(np->key.s, key->s, key->len) == 0)) {
-			if (d) *d = np->domain;
+	for(np = table[calc_hash(key)]; np != NULL; np = np->next) {
+		if((np->key.len == key->len)
+				&& (strncmp(np->key.s, key->s, key->len) == 0)) {
+			if(d)
+				*d = np->domain;
 			return 1;
 		}
 	}
-	if (d) *d = 0;
+	if(d)
+		*d = 0;
 	return -1;
 }

+ 9 - 8
src/modules/uid_domain/hash.h

@@ -32,34 +32,35 @@
 /*
  * Hash table entry
  */
-struct hash_entry {
-	str key;                  /* Hash key */
-	domain_t* domain;         /* Pointer to the domain structure */
-	struct hash_entry* next;  /* Next element in hash table colision slot */
+struct hash_entry
+{
+	str key;				 /* Hash key */
+	domain_t *domain;		 /* Pointer to the domain structure */
+	struct hash_entry *next; /* Next element in hash table colision slot */
 };
 
 
 /*
  * Generate hash table, use domain names as hash keys
  */
-int gen_domain_table(struct hash_entry** table, domain_t* list);
+int gen_domain_table(struct hash_entry **table, domain_t *list);
 
 
 /*
  * Lookup key in the table
  */
-int hash_lookup(domain_t** d, struct hash_entry** table, str* key);
+int hash_lookup(domain_t **d, struct hash_entry **table, str *key);
 
 
 /*
  * Generate hash table, use did as hash key
  */
-int gen_did_table(struct hash_entry** table, domain_t* list);
+int gen_did_table(struct hash_entry **table, domain_t *list);
 
 
 /*
  * Free memory allocated for entire hash table
  */
-void free_table(struct hash_entry** table);
+void free_table(struct hash_entry **table);
 
 #endif /* _HASH_H */

+ 191 - 190
src/modules/uid_domain/uid_domain_mod.c

@@ -51,11 +51,11 @@ static int mod_init(void);
 static void destroy(void);
 static int child_init(int rank);
 
-static int is_local(struct sip_msg* msg, char* s1, char* s2);
-static int lookup_domain(struct sip_msg* msg, char* s1, char* s2);
-static int get_did(str* did, str* domain);
+static int is_local(struct sip_msg *msg, char *s1, char *s2);
+static int lookup_domain(struct sip_msg *msg, char *s1, char *s2);
+static int get_did(str *did, str *domain);
 
-static int lookup_domain_fixup(void** param, int param_no);
+static int lookup_domain_fixup(void **param, int param_no);
 
 MODULE_VERSION
 
@@ -66,20 +66,20 @@ MODULE_VERSION
 #define DOMAIN_TABLE_VERSION 2
 #define DOMATTR_TABLE_VERSION 1
 
-#define DOMAIN_TABLE  "uid_domain"
-#define DOMAIN_COL    "domain"
-#define DID_COL       "did"
-#define FLAGS_COL     "flags"
+#define DOMAIN_TABLE "uid_domain"
+#define DOMAIN_COL "domain"
+#define DID_COL "did"
+#define FLAGS_COL "flags"
 
 #define DOMATTR_TABLE "uid_domain_attrs"
-#define DOMATTR_DID   "did"
-#define DOMATTR_NAME  "name"
-#define DOMATTR_TYPE  "type"
+#define DOMATTR_DID "did"
+#define DOMATTR_NAME "name"
+#define DOMATTR_TYPE "type"
 #define DOMATTR_VALUE "value"
 #define DOMATTR_FLAGS "flags"
-#define DOMAIN_COL    "domain"
+#define DOMAIN_COL "domain"
 
-int db_mode = 1;  /* Enable/disable domain cache */
+int db_mode = 1; /* Enable/disable domain cache */
 
 /*
  * Module parameter variables
@@ -87,28 +87,28 @@ int db_mode = 1;  /* Enable/disable domain cache */
 static str db_url = STR_STATIC_INIT(DEFAULT_RODB_URL);
 
 str domain_table = STR_STATIC_INIT(DOMAIN_TABLE); /* Name of domain table */
-str domain_col   = STR_STATIC_INIT(DOMAIN_COL);   /* Name of domain column */
-str did_col      = STR_STATIC_INIT(DID_COL);      /* Domain id */
-str flags_col    = STR_STATIC_INIT(FLAGS_COL);    /* Domain flags */
+str domain_col = STR_STATIC_INIT(DOMAIN_COL);	  /* Name of domain column */
+str did_col = STR_STATIC_INIT(DID_COL);			  /* Domain id */
+str flags_col = STR_STATIC_INIT(FLAGS_COL);		  /* Domain flags */
 
 str domattr_table = STR_STATIC_INIT(DOMATTR_TABLE);
-str domattr_did   = STR_STATIC_INIT(DOMATTR_DID);
-str domattr_name  = STR_STATIC_INIT(DOMATTR_NAME);
-str domattr_type  = STR_STATIC_INIT(DOMATTR_TYPE);
+str domattr_did = STR_STATIC_INIT(DOMATTR_DID);
+str domattr_name = STR_STATIC_INIT(DOMATTR_NAME);
+str domattr_type = STR_STATIC_INIT(DOMATTR_TYPE);
 str domattr_value = STR_STATIC_INIT(DOMATTR_VALUE);
 str domattr_flags = STR_STATIC_INIT(DOMATTR_FLAGS);
 
-int load_domain_attrs = 0;  /* Load attributes for each domain by default */
+int load_domain_attrs = 0; /* Load attributes for each domain by default */
 
-static db_ctx_t* db = NULL;
-db_cmd_t* load_domains_cmd = NULL, *get_did_cmd = NULL, *load_attrs_cmd = NULL;
+static db_ctx_t *db = NULL;
+db_cmd_t *load_domains_cmd = NULL, *get_did_cmd = NULL, *load_attrs_cmd = NULL;
 
-struct hash_entry*** active_hash = 0; /* Pointer to current hash table */
-struct hash_entry** hash_1 = 0;       /* Pointer to hash table 1 */
-struct hash_entry** hash_2 = 0;       /* Pointer to hash table 2 */
+struct hash_entry ***active_hash = 0; /* Pointer to current hash table */
+struct hash_entry **hash_1 = 0;		  /* Pointer to hash table 1 */
+struct hash_entry **hash_2 = 0;		  /* Pointer to hash table 2 */
 
-domain_t** domains_1 = 0;    /* List of domains 1 */
-domain_t** domains_2 = 0;    /* List of domains 2 */
+domain_t **domains_1 = 0; /* List of domains 1 */
+domain_t **domains_2 = 0; /* List of domains 2 */
 
 /* Global domain structure, this one is used to store data retrieved from
  * database when memory cache is disabled. There is one buffer for from and
@@ -120,111 +120,94 @@ static domain_t dom_buf[2];
  * Exported functions
  */
 static cmd_export_t cmds[] = {
-	{"is_local",      is_local,              1, fixup_var_str_1, 0,
-	 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE },
-	{"lookup_domain", lookup_domain,         2, lookup_domain_fixup, 0,
-	 REQUEST_ROUTE|FAILURE_ROUTE },
-	{"get_did",       (cmd_function)get_did, 0, 0, 0, 0},
-	{"bind_domain",   (cmd_function)bind_domain, 0, 0, 0, 0},
-	{0, 0, 0, 0, 0, 0}
-};
+		{"is_local", is_local, 1, fixup_var_str_1, 0,
+				REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE},
+		{"lookup_domain", lookup_domain, 2, lookup_domain_fixup, 0,
+				REQUEST_ROUTE | FAILURE_ROUTE},
+		{"get_did", (cmd_function)get_did, 0, 0, 0, 0},
+		{"bind_domain", (cmd_function)bind_domain, 0, 0, 0, 0},
+		{0, 0, 0, 0, 0, 0}};
 
 
 /*
  * Exported parameters
  */
-static param_export_t params[] = {
-	{"db_url",	          PARAM_STR, &db_url           },
-	{"db_mode",           PARAM_INT, &db_mode          },
-	{"domain_table",      PARAM_STR, &domain_table     },
-	{"domain_col",        PARAM_STR, &domain_col       },
-	{"did_col",           PARAM_STR, &did_col          },
-	{"flags_col",         PARAM_STR, &flags_col        },
-	{"domattr_table",     PARAM_STR, &domattr_table    },
-	{"domattr_did",       PARAM_STR, &domattr_did      },
-	{"domattr_name",      PARAM_STR, &domattr_name     },
-	{"domattr_type",      PARAM_STR, &domattr_type     },
-	{"domattr_value",     PARAM_STR, &domattr_value    },
-	{"domattr_flags",     PARAM_STR, &domattr_flags    },
-	{"load_domain_attrs", PARAM_INT, &load_domain_attrs},
-	{0, 0, 0}
-};
+static param_export_t params[] = {{"db_url", PARAM_STR, &db_url},
+		{"db_mode", PARAM_INT, &db_mode},
+		{"domain_table", PARAM_STR, &domain_table},
+		{"domain_col", PARAM_STR, &domain_col},
+		{"did_col", PARAM_STR, &did_col}, {"flags_col", PARAM_STR, &flags_col},
+		{"domattr_table", PARAM_STR, &domattr_table},
+		{"domattr_did", PARAM_STR, &domattr_did},
+		{"domattr_name", PARAM_STR, &domattr_name},
+		{"domattr_type", PARAM_STR, &domattr_type},
+		{"domattr_value", PARAM_STR, &domattr_value},
+		{"domattr_flags", PARAM_STR, &domattr_flags},
+		{"load_domain_attrs", PARAM_INT, &load_domain_attrs}, {0, 0, 0}};
 
 
 /*
  * Module interface
  */
 struct module_exports exports = {
-	"uid_domain", /* module name */
-	DEFAULT_DLFLAGS, /* dlopen flags */
-	cmds,         /* exported functions */
-	params,       /* exported parameters */
-	domain_rpc,   /* exported RPC methods */
-	0,            /* exported pseudo-variables */
-	0,            /* response handling function */
-	mod_init,     /* module init function */
-	child_init,   /* per-child init function */
-	destroy       /* module destroy function */
+		"uid_domain",	 /* module name */
+		DEFAULT_DLFLAGS, /* dlopen flags */
+		cmds,			 /* exported functions */
+		params,			 /* exported parameters */
+		domain_rpc,		 /* exported RPC methods */
+		0,				 /* exported pseudo-variables */
+		0,				 /* response handling function */
+		mod_init,		 /* module init function */
+		child_init,		 /* per-child init function */
+		destroy			 /* module destroy function */
 };
 
 
 static int init_db(void)
 {
-	db_fld_t load_domains_columns[] = {
-		{.name = did_col.s,    DB_STR},
-		{.name = domain_col.s, DB_STR},
-		{.name = flags_col.s,  DB_BITMAP},
-		{.name = NULL}
-	};
-	db_fld_t get_did_columns[] = {
-		{.name = did_col.s, DB_STR},
-		{.name = NULL}
-	};
-	db_fld_t load_attrs_columns[] = {
-		{.name = domattr_name.s, .type = DB_STR},
-		{.name = domattr_type.s, .type = DB_INT},
-		{.name = domattr_value.s, .type = DB_STR},
-		{.name = domattr_flags.s, .type = DB_BITMAP},
-		{.name = NULL}
-	};
-	db_fld_t get_did_match[] = {
-		{.name = domain_col.s, DB_STR},
-		{.name = NULL}
-	};
+	db_fld_t load_domains_columns[] = {{.name = did_col.s, DB_STR},
+			{.name = domain_col.s, DB_STR}, {.name = flags_col.s, DB_BITMAP},
+			{.name = NULL}};
+	db_fld_t get_did_columns[] = {{.name = did_col.s, DB_STR}, {.name = NULL}};
+	db_fld_t load_attrs_columns[] = {{.name = domattr_name.s, .type = DB_STR},
+			{.name = domattr_type.s, .type = DB_INT},
+			{.name = domattr_value.s, .type = DB_STR},
+			{.name = domattr_flags.s, .type = DB_BITMAP}, {.name = NULL}};
+	db_fld_t get_did_match[] = {{.name = domain_col.s, DB_STR}, {.name = NULL}};
 	db_fld_t load_attrs_match[] = {
-		{.name = domattr_did.s, .type = DB_STR},
-		{.name = NULL}
-	};
+			{.name = domattr_did.s, .type = DB_STR}, {.name = NULL}};
 
 	db = db_ctx("domain");
-	if (db == NULL) {
+	if(db == NULL) {
 		ERR("Error while initializing database layer\n");
 		return -1;
 	}
-	if (db_add_db(db, db_url.s) < 0) return -1;
-	if (db_connect(db) < 0) return -1;
+	if(db_add_db(db, db_url.s) < 0)
+		return -1;
+	if(db_connect(db) < 0)
+		return -1;
 
 	DBG("prepare load_domains_cmd\n");
-	load_domains_cmd = db_cmd(DB_GET, db, domain_table.s, load_domains_columns,
-							  NULL, NULL);
-	if (load_domains_cmd == NULL) {
+	load_domains_cmd = db_cmd(
+			DB_GET, db, domain_table.s, load_domains_columns, NULL, NULL);
+	if(load_domains_cmd == NULL) {
 		ERR("Error while preparing load_domains database command\n");
 		return -1;
 	}
 
 	DBG("prepare get_did_cmd\n");
-	get_did_cmd = db_cmd(DB_GET, db, domain_table.s, get_did_columns,
-						 get_did_match, NULL);
-	if (get_did_cmd == NULL) {
+	get_did_cmd = db_cmd(
+			DB_GET, db, domain_table.s, get_did_columns, get_did_match, NULL);
+	if(get_did_cmd == NULL) {
 		ERR("Error while preparing get_did database command\n");
 		return -1;
 	}
 
-	if (load_domain_attrs) {
+	if(load_domain_attrs) {
 		DBG("prepare load_attrs_cmd\n");
-		load_attrs_cmd = db_cmd(DB_GET, db, domattr_table.s,
-								load_attrs_columns, load_attrs_match, NULL);
-		if (load_attrs_cmd == NULL) {
+		load_attrs_cmd = db_cmd(DB_GET, db, domattr_table.s, load_attrs_columns,
+				load_attrs_match, NULL);
+		if(load_attrs_cmd == NULL) {
 			ERR("Error while preparing load_attrs database command\n");
 			return -1;
 		}
@@ -236,20 +219,21 @@ static int init_db(void)
 
 static int allocate_tables(void)
 {
-	active_hash = (struct hash_entry***)shm_malloc(sizeof(struct hash_entry**));
-	hash_1 = (struct hash_entry**)shm_malloc(sizeof(struct hash_entry*)
-											 * HASH_SIZE);
-	hash_2 = (struct hash_entry**)shm_malloc(sizeof(struct hash_entry*)
-											 * HASH_SIZE);
-	domains_1 = (domain_t**)shm_malloc(sizeof(domain_t*));
-	domains_2 = (domain_t**)shm_malloc(sizeof(domain_t*));
-
-	if (!hash_1 || !hash_2 || !active_hash || !domains_1 || !domains_2) {
+	active_hash =
+			(struct hash_entry ***)shm_malloc(sizeof(struct hash_entry **));
+	hash_1 = (struct hash_entry **)shm_malloc(
+			sizeof(struct hash_entry *) * HASH_SIZE);
+	hash_2 = (struct hash_entry **)shm_malloc(
+			sizeof(struct hash_entry *) * HASH_SIZE);
+	domains_1 = (domain_t **)shm_malloc(sizeof(domain_t *));
+	domains_2 = (domain_t **)shm_malloc(sizeof(domain_t *));
+
+	if(!hash_1 || !hash_2 || !active_hash || !domains_1 || !domains_2) {
 		SHM_MEM_ERROR;
 		return -1;
 	}
-	memset(hash_1, 0, sizeof(struct hash_entry*) * HASH_SIZE);
-	memset(hash_2, 0, sizeof(struct hash_entry*) * HASH_SIZE);
+	memset(hash_1, 0, sizeof(struct hash_entry *) * HASH_SIZE);
+	memset(hash_2, 0, sizeof(struct hash_entry *) * HASH_SIZE);
 	*active_hash = hash_1;
 	*domains_1 = 0;
 	*domains_2 = 0;
@@ -260,14 +244,15 @@ static void destroy_tables(void)
 {
 	free_table(hash_1);
 	free_table(hash_2);
-	if (active_hash) shm_free(active_hash);
+	if(active_hash)
+		shm_free(active_hash);
 
-	if (domains_1) {
+	if(domains_1) {
 		free_domain_list(*domains_1);
 		shm_free(domains_1);
 	}
 
-	if (domains_2) {
+	if(domains_2) {
 		free_domain_list(*domains_2);
 		shm_free(domains_2);
 	}
@@ -277,11 +262,14 @@ static void destroy_tables(void)
 static int mod_init(void)
 {
 	/* Check if cache needs to be loaded from domain table */
-	if (db_mode) {
-		if (init_db() < 0) goto error;
+	if(db_mode) {
+		if(init_db() < 0)
+			goto error;
 
-		if (allocate_tables() < 0) goto error;
-		if (reload_domain_list() < 0) goto error;
+		if(allocate_tables() < 0)
+			goto error;
+		if(reload_domain_list() < 0)
+			goto error;
 
 		db_cmd_free(load_domains_cmd);
 		load_domains_cmd = NULL;
@@ -292,27 +280,29 @@ static int mod_init(void)
 		db_cmd_free(get_did_cmd);
 		get_did_cmd = NULL;
 
-		if (db) db_disconnect(db);
+		if(db)
+			db_disconnect(db);
 		db_ctx_free(db);
 		db = NULL;
 	}
 
 	return 0;
 
- error:
-	if (get_did_cmd) {
+error:
+	if(get_did_cmd) {
 		db_cmd_free(get_did_cmd);
 		get_did_cmd = NULL;
 	}
-	if (load_domains_cmd) {
+	if(load_domains_cmd) {
 		db_cmd_free(load_domains_cmd);
 		load_domains_cmd = NULL;
 	}
-	if (load_attrs_cmd) {
+	if(load_attrs_cmd) {
 		db_cmd_free(load_attrs_cmd);
 		load_attrs_cmd = NULL;
 	}
-	if (db) db_disconnect(db);
+	if(db)
+		db_disconnect(db);
 	db_ctx_free(db);
 	db = NULL;
 	return -1;
@@ -322,38 +312,41 @@ static int mod_init(void)
 static int child_init(int rank)
 {
 	/* Check if database is needed by child */
-	if (rank > 0 || rank == PROC_RPC || rank == PROC_UNIXSOCK) {
-		if (init_db() < 0) return -1;
+	if(rank > 0 || rank == PROC_RPC || rank == PROC_UNIXSOCK) {
+		if(init_db() < 0)
+			return -1;
 	}
 
 	return 0;
 }
 
 
-static void free_old_domain(domain_t* d)
+static void free_old_domain(domain_t *d)
 {
 	int i;
 
-	if (!d) return;
-	if (d->did.s) {
+	if(!d)
+		return;
+	if(d->did.s) {
 		pkg_free(d->did.s);
 		d->did.s = NULL;
 	}
 
-	if (d->domain) {
+	if(d->domain) {
 		for(i = 0; i < d->n; i++) {
-			if (d->domain[i].s) pkg_free(d->domain[i].s);
+			if(d->domain[i].s)
+				pkg_free(d->domain[i].s);
 		}
 		pkg_free(d->domain);
 		d->domain = NULL;
 	}
 
-	if (d->flags) {
+	if(d->flags) {
 		pkg_free(d->flags);
 		d->flags = NULL;
 	}
 
-	if (d->attrs) {
+	if(d->attrs) {
 		destroy_avp_list(&d->attrs);
 	}
 }
@@ -364,16 +357,19 @@ static void destroy(void)
 	/* Destroy is called from the main process only, there is no need to close
 	 * database here because it is closed in mod_init already
 	 */
-	if (!db_mode) {
+	if(!db_mode) {
 		free_old_domain(&dom_buf[0]);
 		free_old_domain(&dom_buf[1]);
 	}
 
-	if (load_domains_cmd) db_cmd_free(load_domains_cmd);
-	if (get_did_cmd) db_cmd_free(get_did_cmd);
-	if (load_attrs_cmd) db_cmd_free(load_attrs_cmd);
+	if(load_domains_cmd)
+		db_cmd_free(load_domains_cmd);
+	if(get_did_cmd)
+		db_cmd_free(get_did_cmd);
+	if(load_attrs_cmd)
+		db_cmd_free(load_attrs_cmd);
 
-	if (db) {
+	if(db) {
 		db_disconnect(db);
 		db_ctx_free(db);
 	}
@@ -382,15 +378,14 @@ static void destroy(void)
 }
 
 
-
 /*
  * Check if domain is local
  */
-static int is_local(struct sip_msg* msg, char* fp, char* s2)
+static int is_local(struct sip_msg *msg, char *fp, char *s2)
 {
 	str domain;
 
-	if (get_str_fparam(&domain, msg, (fparam_t*)fp) != 0) {
+	if(get_str_fparam(&domain, msg, (fparam_t *)fp) != 0) {
 		ERR("Unable to get domain to check\n");
 		return -1;
 	}
@@ -399,14 +394,14 @@ static int is_local(struct sip_msg* msg, char* fp, char* s2)
 }
 
 
-static int db_load_domain(domain_t** d, unsigned long flags, str* domain)
+static int db_load_domain(domain_t **d, unsigned long flags, str *domain)
 {
 	int ret;
 	int_str name, val;
-	domain_t* p;
+	domain_t *p;
 	str name_s = STR_STATIC_INIT(AVP_DID);
 
-	if (flags & AVP_TRACK_FROM) {
+	if(flags & AVP_TRACK_FROM) {
 		p = &dom_buf[0];
 	} else {
 		p = &dom_buf[1];
@@ -415,35 +410,39 @@ static int db_load_domain(domain_t** d, unsigned long flags, str* domain)
 	free_old_domain(p);
 
 	ret = db_get_did(&p->did, domain);
-	if (ret != 1) return ret;
-	if (load_domain_attrs) {
-		if (db_load_domain_attrs(p) < 0) return -1;
+	if(ret != 1)
+		return ret;
+	if(load_domain_attrs) {
+		if(db_load_domain_attrs(p) < 0)
+			return -1;
 	}
 
 	/* Create an attribute containing did of the domain */
 	name.s = name_s;
 	val.s = p->did;
-	if (add_avp_list(&p->attrs, AVP_CLASS_DOMAIN | AVP_NAME_STR | AVP_VAL_STR,
-					 name, val) < 0) return -1;
+	if(add_avp_list(&p->attrs, AVP_CLASS_DOMAIN | AVP_NAME_STR | AVP_VAL_STR,
+			   name, val)
+			< 0)
+		return -1;
 
 	*d = p;
 	return 0;
 }
 
 
-static int lookup_domain(struct sip_msg* msg, char* flags, char* fp)
+static int lookup_domain(struct sip_msg *msg, char *flags, char *fp)
 {
 	str domain, tmp;
-	domain_t* d = NULL;
+	domain_t *d = NULL;
 	int ret = -1;
 
-	if (get_str_fparam(&domain, msg, (fparam_t*)fp) != 0) {
+	if(get_str_fparam(&domain, msg, (fparam_t *)fp) != 0) {
 		DBG("lookup_domain: Cannot get the domain name to lookup\n");
 		return -1;
 	}
 
 	tmp.s = pkg_malloc(domain.len);
-	if (!tmp.s) {
+	if(!tmp.s) {
 		PKG_MEM_ERROR;
 		return -1;
 	}
@@ -451,13 +450,13 @@ static int lookup_domain(struct sip_msg* msg, char* flags, char* fp)
 	tmp.len = domain.len;
 	strlower(&tmp);
 
-	if (db_mode) {
-		if (hash_lookup(&d, *active_hash, &tmp) == 1) {
+	if(db_mode) {
+		if(hash_lookup(&d, *active_hash, &tmp) == 1) {
 			set_avp_list((unsigned long)flags, &d->attrs);
 			ret = 1;
 		}
 	} else {
-		if (db_load_domain(&d, (unsigned long)flags, &tmp) == 0) {
+		if(db_load_domain(&d, (unsigned long)flags, &tmp) == 0) {
 			set_avp_list((unsigned long)flags, &d->attrs);
 			ret = 1;
 		}
@@ -468,18 +467,18 @@ static int lookup_domain(struct sip_msg* msg, char* flags, char* fp)
 }
 
 
-static int get_did(str* did, str* domain)
+static int get_did(str *did, str *domain)
 {
 	str tmp;
-	domain_t* d;
+	domain_t *d;
 
-	if (!db_mode) {
+	if(!db_mode) {
 		ERR("lookup_domain only works in cache mode\n");
 		return -1;
 	}
 
 	tmp.s = pkg_malloc(domain->len);
-	if (!tmp.s) {
+	if(!tmp.s) {
 		PKG_MEM_ERROR;
 		return -1;
 	}
@@ -487,7 +486,7 @@ static int get_did(str* did, str* domain)
 	tmp.len = domain->len;
 	strlower(&tmp);
 
-	if (hash_lookup(&d, *active_hash, &tmp) == 1) {
+	if(hash_lookup(&d, *active_hash, &tmp) == 1) {
 		*did = d->did;
 		pkg_free(tmp.s);
 		return 1;
@@ -500,11 +499,11 @@ static int get_did(str* did, str* domain)
 
 int reload_domain_list(void)
 {
-	struct hash_entry** new_table;
-	domain_t** new_list;
+	struct hash_entry **new_table;
+	domain_t **new_list;
 
 	/* Choose new hash table and free its old contents */
-	if (*active_hash == hash_1) {
+	if(*active_hash == hash_1) {
 		free_table(hash_2);
 		new_table = hash_2;
 		new_list = domains_2;
@@ -514,53 +513,55 @@ int reload_domain_list(void)
 		new_list = domains_1;
 	}
 
-	if (load_domains(new_list) < 0) goto error;
-	if (gen_domain_table(new_table, *new_list) < 0) goto error;
+	if(load_domains(new_list) < 0)
+		goto error;
+	if(gen_domain_table(new_table, *new_list) < 0)
+		goto error;
 	*active_hash = new_table;
 	return 0;
 
- error:
+error:
 	free_table(new_table);
 	free_domain_list(*new_list);
 	return -1;
 }
 
 
-static int lookup_domain_fixup(void** param, int param_no)
+static int lookup_domain_fixup(void **param, int param_no)
 {
-	unsigned long flags=0;
-	char* s;
+	unsigned long flags = 0;
+	char *s;
 
-	if (param_no == 1) {
+	if(param_no == 1) {
 		/* Determine the track and class of attributes to be loaded */
-		s = (char*)*param;
-		if (*s != '$' || (strlen(s) != 3)) {
+		s = (char *)*param;
+		if(*s != '$' || (strlen(s) != 3)) {
 			ERR("Invalid parameter value, $xy expected\n");
 			return -1;
 		}
 		switch((s[1] << 8) + s[2]) {
-		case 0x4644: /* $fd */
-		case 0x6664:
-		case 0x4664:
-		case 0x6644:
-			flags = AVP_TRACK_FROM | AVP_CLASS_DOMAIN;
-			break;
-
-		case 0x5444: /* $td */
-		case 0x7464:
-		case 0x5464:
-		case 0x7444:
-			flags = AVP_TRACK_TO | AVP_CLASS_DOMAIN;
-			break;
-
-		default:
-			ERR("Invalid parameter value: '%s'\n", s);
-			return -1;
+			case 0x4644: /* $fd */
+			case 0x6664:
+			case 0x4664:
+			case 0x6644:
+				flags = AVP_TRACK_FROM | AVP_CLASS_DOMAIN;
+				break;
+
+			case 0x5444: /* $td */
+			case 0x7464:
+			case 0x5464:
+			case 0x7444:
+				flags = AVP_TRACK_TO | AVP_CLASS_DOMAIN;
+				break;
+
+			default:
+				ERR("Invalid parameter value: '%s'\n", s);
+				return -1;
 		}
 
 		pkg_free(*param);
-		*param = (void*)flags;
-	} else if (param_no == 2) {
+		*param = (void *)flags;
+	} else if(param_no == 2) {
 		return fixup_var_str_12(param, 2);
 	}
 

+ 19 - 19
src/modules/uid_domain/uid_domain_mod.h

@@ -33,38 +33,38 @@
 /*
  * Module parameters variables
  */
-extern int db_mode;             /* Database usage mode: 0 = no cache,
+extern int db_mode;		 /* Database usage mode: 0 = no cache,
 								 * 1 = * cache */
-extern str domain_table;	/* Domain table name */
-extern str domain_col;   	/* Domain column name */
-extern str did_col;             /* Domain id col */
-extern str flags_col;           /* Flags column */
+extern str domain_table; /* Domain table name */
+extern str domain_col;	 /* Domain column name */
+extern str did_col;		 /* Domain id col */
+extern str flags_col;	 /* Flags column */
 
 /*
  * Table containing domain attributes (in form of AVPs)
  */
-extern str domattr_table;       /* Name of table containing domain attributes */
-extern str domattr_did;         /* Column containing domain id */
-extern str domattr_name;        /* Column containing name of attribute */
-extern str domattr_type;        /* Column containing type of attribute */
-extern str domattr_value;       /* Column containing value of attribute */
-extern str domattr_flags;       /* Column containing domain attribute flags */
+extern str domattr_table; /* Name of table containing domain attributes */
+extern str domattr_did;	  /* Column containing domain id */
+extern str domattr_name;  /* Column containing name of attribute */
+extern str domattr_type;  /* Column containing type of attribute */
+extern str domattr_value; /* Column containing value of attribute */
+extern str domattr_flags; /* Column containing domain attribute flags */
 
-extern int load_domain_attrs;   /* Turn on/off domain attributes */
+extern int load_domain_attrs; /* Turn on/off domain attributes */
 
 /*
  * Other module variables
  */
 
-extern struct hash_entry*** active_hash; /* Pointer to current hash table */
-extern domain_t** domains_1;      /* List of domains 1 */
-extern domain_t** domains_2;      /* List of domains 2 */
+extern struct hash_entry ***active_hash; /* Pointer to current hash table */
+extern domain_t **domains_1;			 /* List of domains 1 */
+extern domain_t **domains_2;			 /* List of domains 2 */
 
-extern struct hash_entry*** hash;  /* Pointer to the current hash table */
-extern struct hash_entry** hash_1; /* Hash table 1 */
-extern struct hash_entry** hash_2; /* Hash table 2 */
+extern struct hash_entry ***hash;  /* Pointer to the current hash table */
+extern struct hash_entry **hash_1; /* Hash table 1 */
+extern struct hash_entry **hash_2; /* Hash table 2 */
 
-extern db_cmd_t* load_domains_cmd, *get_did_cmd, *load_attrs_cmd;
+extern db_cmd_t *load_domains_cmd, *get_did_cmd, *load_attrs_cmd;
 
 int reload_domain_list(void);