Browse Source

domain: coheren indentation and whitespacing

- formatted to clang-format specs
Daniel-Constantin Mierla 8 năm trước cách đây
mục cha
commit
a4e753d041

+ 9 - 9
src/modules/domain/api.c

@@ -23,14 +23,14 @@
 #include "api.h"
 #include "api.h"
 #include "domain.h"
 #include "domain.h"
 
 
-int bind_domain(domain_api_t* api)
+int bind_domain(domain_api_t *api)
 {
 {
-    if (!api) {
-	LM_ERR("invalid parameter value\n");
-	return -1;
-    }
+	if(!api) {
+		LM_ERR("invalid parameter value\n");
+		return -1;
+	}
 
 
-    api->is_domain_local = is_domain_local;
-    
-    return 0;
-}
+	api->is_domain_local = is_domain_local;
+
+	return 0;
+}

+ 4 - 5
src/modules/domain/api.h

@@ -25,14 +25,13 @@
 #include "../../core/str.h"
 #include "../../core/str.h"
 #include "domain.h"
 #include "domain.h"
 
 
-typedef int (*is_domain_local_t)(str* _domain);
+typedef int (*is_domain_local_t)(str *_domain);
 
 
 typedef struct domain_api {
 typedef struct domain_api {
 	is_domain_local_t is_domain_local;
 	is_domain_local_t is_domain_local;
 } domain_api_t;
 } domain_api_t;
 
 
-typedef int (*bind_domain_t)(domain_api_t* api);
-extern int bind_domain(domain_api_t* api);
+typedef int (*bind_domain_t)(domain_api_t *api);
+extern int bind_domain(domain_api_t *api);
 
 
-
-#endif
+#endif

+ 259 - 256
src/modules/domain/domain.c

@@ -32,33 +32,32 @@
 #include "../../core/mod_fix.h"
 #include "../../core/mod_fix.h"
 #include "../../core/str.h"
 #include "../../core/str.h"
 
 
-static db1_con_t* db_handle=0;
+static db1_con_t *db_handle = 0;
 static db_func_t domain_dbf;
 static db_func_t domain_dbf;
 
 
 /* helper db functions*/
 /* helper db functions*/
 
 
-int domain_db_bind(const str* db_url)
+int domain_db_bind(const str *db_url)
 {
 {
-	if (db_bind_mod(db_url, &domain_dbf )) {
-	        LM_ERR("Cannot bind to database module!\n");
+	if(db_bind_mod(db_url, &domain_dbf)) {
+		LM_ERR("Cannot bind to database module!\n");
 		return -1;
 		return -1;
 	}
 	}
 	return 0;
 	return 0;
 }
 }
 
 
 
 
-
-int domain_db_init(const str* db_url)
-{	
-	if (domain_dbf.init==0){
+int domain_db_init(const str *db_url)
+{
+	if(domain_dbf.init == 0) {
 		LM_ERR("Unbound database module\n");
 		LM_ERR("Unbound database module\n");
 		goto error;
 		goto error;
 	}
 	}
-	if (db_handle!=0)
+	if(db_handle != 0)
 		return 0;
 		return 0;
 
 
-	db_handle=domain_dbf.init(db_url);
-	if (db_handle==0){
+	db_handle = domain_dbf.init(db_url);
+	if(db_handle == 0) {
 		LM_ERR("Cannot initialize database connection\n");
 		LM_ERR("Cannot initialize database connection\n");
 		goto error;
 		goto error;
 	}
 	}
@@ -70,17 +69,16 @@ error:
 
 
 void domain_db_close(void)
 void domain_db_close(void)
 {
 {
-	if (db_handle && domain_dbf.close){
+	if(db_handle && domain_dbf.close) {
 		domain_dbf.close(db_handle);
 		domain_dbf.close(db_handle);
-		db_handle=0;
+		db_handle = 0;
 	}
 	}
 }
 }
 
 
 
 
-
-int domain_db_ver(str* name, int version)
+int domain_db_ver(str *name, int version)
 {
 {
-	if (db_handle==0){
+	if(db_handle == 0) {
 		LM_ERR("null database handler\n");
 		LM_ERR("null database handler\n");
 		return -1;
 		return -1;
 	}
 	}
@@ -91,24 +89,24 @@ int domain_db_ver(str* name, int version)
 /*
 /*
  * Check if domain is local
  * Check if domain is local
  */
  */
-int is_domain_local(str* _host)
+int is_domain_local(str *_host)
 {
 {
-    str did;
-    struct attr_list *attrs;
+	str did;
+	struct attr_list *attrs;
 
 
-    return hash_table_lookup(_host, &did, &attrs);
+	return hash_table_lookup(_host, &did, &attrs);
 }
 }
 
 
 /*
 /*
  * Check if host in From uri is local
  * Check if host in From uri is local
  */
  */
-int is_from_local(struct sip_msg* _msg, char* _s1, char* _s2)
+int is_from_local(struct sip_msg *_msg, char *_s1, char *_s2)
 {
 {
 	struct sip_uri *puri;
 	struct sip_uri *puri;
 	str did;
 	str did;
 	struct attr_list *attrs;
 	struct attr_list *attrs;
 
 
-	if ((puri=parse_from_uri(_msg))==NULL) {
+	if((puri = parse_from_uri(_msg)) == NULL) {
 		LM_ERR("Error while parsing From header\n");
 		LM_ERR("Error while parsing From header\n");
 		return -2;
 		return -2;
 	}
 	}
@@ -119,94 +117,93 @@ int is_from_local(struct sip_msg* _msg, char* _s1, char* _s2)
 /*
 /*
  * Check if host in Request URI is local
  * Check if host in Request URI is local
  */
  */
-int is_uri_host_local(struct sip_msg* _msg, char* _s1, char* _s2)
+int is_uri_host_local(struct sip_msg *_msg, char *_s1, char *_s2)
 {
 {
-    str branch;
-    qvalue_t q;
-    struct sip_uri puri;
-    struct attr_list *attrs;
-    str did;
-
-    if ( is_route_type(REQUEST_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE) ) {
-	if (parse_sip_msg_uri(_msg) < 0) {
-	    LM_ERR("error while parsing R-URI\n");
-	    return -1;
-	}
-	return hash_table_lookup(&(_msg->parsed_uri.host), &did, &attrs);
-    } else if (is_route_type(FAILURE_ROUTE)) {
-	branch.s = get_branch(0, &branch.len, &q, 0, 0, 0, 0, 0, 0, 0);
-	if (branch.s) {
-	    if (parse_uri(branch.s, branch.len, &puri) < 0) {
-		LM_ERR("error while parsing branch URI\n");
-		return -1;
-	    }
-	    return hash_table_lookup(&(puri.host), &did, &attrs);
+	str branch;
+	qvalue_t q;
+	struct sip_uri puri;
+	struct attr_list *attrs;
+	str did;
+
+	if(is_route_type(REQUEST_ROUTE | BRANCH_ROUTE | LOCAL_ROUTE)) {
+		if(parse_sip_msg_uri(_msg) < 0) {
+			LM_ERR("error while parsing R-URI\n");
+			return -1;
+		}
+		return hash_table_lookup(&(_msg->parsed_uri.host), &did, &attrs);
+	} else if(is_route_type(FAILURE_ROUTE)) {
+		branch.s = get_branch(0, &branch.len, &q, 0, 0, 0, 0, 0, 0, 0);
+		if(branch.s) {
+			if(parse_uri(branch.s, branch.len, &puri) < 0) {
+				LM_ERR("error while parsing branch URI\n");
+				return -1;
+			}
+			return hash_table_lookup(&(puri.host), &did, &attrs);
+		} else {
+			LM_ERR("branch is missing, error in script\n");
+			return -1;
+		}
 	} else {
 	} else {
-	    LM_ERR("branch is missing, error in script\n");
-	    return -1;
+		LM_ERR("unsupported route type\n");
+		return -1;
 	}
 	}
-    } else {
-	LM_ERR("unsupported route type\n");
-	return -1;
-    }
 }
 }
 
 
 
 
 /*
 /*
  * Check if domain given as value of pseudo variable parameter is local.
  * Check if domain given as value of pseudo variable parameter is local.
  */
  */
-int w_is_domain_local(struct sip_msg* _msg, char* _sp, char* _s2)
+int w_is_domain_local(struct sip_msg *_msg, char *_sp, char *_s2)
 {
 {
-    struct attr_list *attrs;
-    str did;
+	struct attr_list *attrs;
+	str did;
 	str sdomain;
 	str sdomain;
 
 
-	if(fixup_get_svalue(_msg, (gparam_t*)_sp, &sdomain)<0) {
+	if(fixup_get_svalue(_msg, (gparam_t *)_sp, &sdomain) < 0) {
 		LM_ERR("cannot get domain paramter\n");
 		LM_ERR("cannot get domain paramter\n");
 		return -1;
 		return -1;
 	}
 	}
 
 
 	return hash_table_lookup(&sdomain, &did, &attrs);
 	return hash_table_lookup(&sdomain, &did, &attrs);
-
 }
 }
 
 
 /*
 /*
  * Check if domain is local and, if it is, add attributes as AVPs
  * Check if domain is local and, if it is, add attributes as AVPs
  */
  */
-int w_lookup_domain(struct sip_msg* _msg, char* _sp, char* _prefix)
+int w_lookup_domain(struct sip_msg *_msg, char *_sp, char *_prefix)
 {
 {
 
 
-    int_str name, val;
-    struct attr_list *attrs;
-    str *prefix, did;
-    unsigned short flags;
+	int_str name, val;
+	struct attr_list *attrs;
+	str *prefix, did;
+	unsigned short flags;
 	str sdomain;
 	str sdomain;
 	str sprefix;
 	str sprefix;
 
 
-	if(fixup_get_svalue(_msg, (gparam_t*)_sp, &sdomain)<0) {
+	if(fixup_get_svalue(_msg, (gparam_t *)_sp, &sdomain) < 0) {
 		LM_ERR("cannot get domain paramter\n");
 		LM_ERR("cannot get domain paramter\n");
 		return -1;
 		return -1;
 	}
 	}
 	if(_prefix) {
 	if(_prefix) {
-		if(fixup_get_svalue(_msg, (gparam_t*)_prefix, &sprefix)<0) {
+		if(fixup_get_svalue(_msg, (gparam_t *)_prefix, &sprefix) < 0) {
 			LM_ERR("cannot get prefix paramter\n");
 			LM_ERR("cannot get prefix paramter\n");
 			return -1;
 			return -1;
 		}
 		}
 	}
 	}
 
 
-	if (hash_table_lookup(&sdomain, &did, &attrs) != 1) {
+	if(hash_table_lookup(&sdomain, &did, &attrs) != 1) {
 		return -1;
 		return -1;
 	}
 	}
 
 
-	while (attrs) {
-		if (attrs->type == 2)
+	while(attrs) {
+		if(attrs->type == 2)
 			flags = AVP_NAME_STR | AVP_VAL_STR;
 			flags = AVP_NAME_STR | AVP_VAL_STR;
 		else
 		else
 			flags = AVP_NAME_STR;
 			flags = AVP_NAME_STR;
-		if (_prefix) {
+		if(_prefix) {
 			name.s.len = sprefix.len + attrs->name.len;
 			name.s.len = sprefix.len + attrs->name.len;
 			name.s.s = pkg_malloc(name.s.len);
 			name.s.s = pkg_malloc(name.s.len);
-			if (name.s.s == NULL) {
+			if(name.s.s == NULL) {
 				ERR("no pkg memory for avp name\n");
 				ERR("no pkg memory for avp name\n");
 				return -1;
 				return -1;
 			}
 			}
@@ -215,21 +212,22 @@ int w_lookup_domain(struct sip_msg* _msg, char* _sp, char* _prefix)
 		} else {
 		} else {
 			name.s = attrs->name;
 			name.s = attrs->name;
 		}
 		}
-		if (add_avp(flags, name, attrs->val) < 0) {
-			LM_ERR("unable to add a new AVP '%.*s'\n",
-					name.s.len, name.s.s);
-			if (_prefix) pkg_free(name.s.s);
+		if(add_avp(flags, name, attrs->val) < 0) {
+			LM_ERR("unable to add a new AVP '%.*s'\n", name.s.len, name.s.s);
+			if(_prefix)
+				pkg_free(name.s.s);
 			return -1;
 			return -1;
 		}
 		}
 		LM_DBG("added AVP '%.*s'\n", name.s.len, name.s.s);
 		LM_DBG("added AVP '%.*s'\n", name.s.len, name.s.s);
-		if (prefix) pkg_free(name.s.s);
+		if(prefix)
+			pkg_free(name.s.s);
 		attrs = attrs->next;
 		attrs = attrs->next;
 	}
 	}
 	flags = AVP_NAME_STR | AVP_VAL_STR;
 	flags = AVP_NAME_STR | AVP_VAL_STR;
-	if (_prefix) {
+	if(_prefix) {
 		name.s.len = sprefix.len + 3;
 		name.s.len = sprefix.len + 3;
 		name.s.s = pkg_malloc(name.s.len);
 		name.s.s = pkg_malloc(name.s.len);
-		if (name.s.s == NULL) {
+		if(name.s.s == NULL) {
 			ERR("no pkg memory for avp name\n");
 			ERR("no pkg memory for avp name\n");
 			return -1;
 			return -1;
 		}
 		}
@@ -240,229 +238,234 @@ int w_lookup_domain(struct sip_msg* _msg, char* _sp, char* _prefix)
 		name.s.len = 3;
 		name.s.len = 3;
 	}
 	}
 	val.s = did;
 	val.s = did;
-	if (add_avp(flags, name, val) < 0) {
-		LM_ERR("unable to add a new AVP '%.*s'\n",
-			name.s.len, name.s.s);
-		if (_prefix) pkg_free(name.s.s);
+	if(add_avp(flags, name, val) < 0) {
+		LM_ERR("unable to add a new AVP '%.*s'\n", name.s.len, name.s.s);
+		if(_prefix)
+			pkg_free(name.s.s);
 		return -1;
 		return -1;
 	}
 	}
 	LM_DBG("added AVP '%.*s'\n", name.s.len, name.s.s);
 	LM_DBG("added AVP '%.*s'\n", name.s.len, name.s.s);
-	if (_prefix) pkg_free(name.s.s);
+	if(_prefix)
+		pkg_free(name.s.s);
 	return 1;
 	return 1;
 }
 }
 
 
 /*
 /*
  * Check if domain is local and, if it is, add attributes as AVPs
  * Check if domain is local and, if it is, add attributes as AVPs
  */
  */
-int w_lookup_domain_no_prefix(struct sip_msg* _msg, char* _domain, char* _str)
+int w_lookup_domain_no_prefix(struct sip_msg *_msg, char *_domain, char *_str)
 {
 {
-    return w_lookup_domain(_msg, _domain, NULL);
+	return w_lookup_domain(_msg, _domain, NULL);
 }
 }
 
 
-int domain_check_self(str* host, unsigned short port, unsigned short proto)
+int domain_check_self(str *host, unsigned short port, unsigned short proto)
 {
 {
-    struct attr_list *attrs;
-    str did;
-    if (hash_table_lookup(host, &did, &attrs) > 0)
+	struct attr_list *attrs;
+	str did;
+	if(hash_table_lookup(host, &did, &attrs) > 0)
 		return 1;
 		return 1;
-    return 0;
+	return 0;
 }
 }
 
 
 /*
 /*
  * Reload domain table to new hash table and when done, make new hash table
  * Reload domain table to new hash table and when done, make new hash table
  * current one.
  * current one.
  */
  */
-int reload_tables ( void )
+int reload_tables(void)
 {
 {
-    db_key_t cols[4];
-    db1_res_t* res = NULL;
-    db_row_t* row;
-    struct domain_list **new_hash_table;
-    int i;
-    short type;
-    str did, domain, name, value;
-    int_str val;
-
-    /* Choose new hash table and free its old contents */
-    if (*hash_table == hash_table_1) {
-	hash_table_free(hash_table_2);
-	new_hash_table = hash_table_2;
-    } else {
-	hash_table_free(hash_table_1);
-	new_hash_table = hash_table_1;
-    }
-
-    cols[0] = &did_col;
-    cols[1] = &name_col;
-    cols[2] = &type_col;
-    cols[3] = &value_col;
-
-    if (domain_db_init(&d_db_url) < 0) {
-	LM_ERR("unable to open database connection\n");
-	return -1;
-    }
+	db_key_t cols[4];
+	db1_res_t *res = NULL;
+	db_row_t *row;
+	struct domain_list **new_hash_table;
+	int i;
+	short type;
+	str did, domain, name, value;
+	int_str val;
+
+	/* Choose new hash table and free its old contents */
+	if(*hash_table == hash_table_1) {
+		hash_table_free(hash_table_2);
+		new_hash_table = hash_table_2;
+	} else {
+		hash_table_free(hash_table_1);
+		new_hash_table = hash_table_1;
+	}
 
 
-    if (domain_dbf.use_table(db_handle, &domain_attrs_table) < 0) {
-	LM_ERR("error while trying to use domain_attrs table\n");
-	goto err;
-    }
+	cols[0] = &did_col;
+	cols[1] = &name_col;
+	cols[2] = &type_col;
+	cols[3] = &value_col;
 
 
-    if (domain_dbf.query(db_handle, NULL, 0, NULL, cols, 0, 4, 0, &res) < 0) {
-	LM_ERR("error while querying database\n");
-	goto err;
-    }
+	if(domain_db_init(&d_db_url) < 0) {
+		LM_ERR("unable to open database connection\n");
+		return -1;
+	}
 
 
-    row = RES_ROWS(res);
+	if(domain_dbf.use_table(db_handle, &domain_attrs_table) < 0) {
+		LM_ERR("error while trying to use domain_attrs table\n");
+		goto err;
+	}
 
 
-    LM_DBG("number of rows in domain_attrs table: %d\n", RES_ROW_N(res));
-    
-    for (i = 0; i < RES_ROW_N(res); i++) {
+	if(domain_dbf.query(db_handle, NULL, 0, NULL, cols, 0, 4, 0, &res) < 0) {
+		LM_ERR("error while querying database\n");
+		goto err;
+	}
 
 
-	row = RES_ROWS(res) + i;
+	row = RES_ROWS(res);
 
 
-	if ((VAL_NULL(ROW_VALUES(row)) == 1) ||
-	    (VAL_TYPE(ROW_VALUES(row)) != DB1_STRING)) {
-	    LM_ERR("did at row <%u> is null or not string\n", i);
-	    goto err;
-	}
-	did.s = (char *)VAL_STRING(ROW_VALUES(row));
-	did.len = strlen(did.s);
-	if (did.len == 0) {
-	    LM_ERR("did at row <%u> is empty string\n", i);
-	    goto err;
-	}
+	LM_DBG("number of rows in domain_attrs table: %d\n", RES_ROW_N(res));
 
 
-	if ((VAL_NULL(ROW_VALUES(row) + 1) == 1) ||
-	    (VAL_TYPE(ROW_VALUES(row) + 1) != DB1_STRING)) {
-	    LM_ERR("name at row <%u> is null or not string\n", i);
-	    goto err;
-	}
-	name.s = (char *)VAL_STRING(ROW_VALUES(row) + 1);
-	name.len = strlen(name.s);
-	if (name.len == 0) {
-	    LM_ERR("name at row <%u> is empty string\n", i);
-	    goto err;
-	}
+	for(i = 0; i < RES_ROW_N(res); i++) {
 
 
-	if ((VAL_NULL(ROW_VALUES(row) + 2) == 1) ||
-	    ((VAL_TYPE(ROW_VALUES(row) + 2) != DB1_INT) &&
-	     (VAL_TYPE(ROW_VALUES(row) + 2) != DB1_BIGINT))) {
-	    LM_ERR("type at row <%u> is null or not int\n", i);
-	    goto err;
-	}
-	if(VAL_TYPE(ROW_VALUES(row) + 2) == DB1_BIGINT) {
-		type = (int)VAL_BIGINT(ROW_VALUES(row) + 2);
-	} else {
-		type = (int)VAL_INT(ROW_VALUES(row) + 2);
-	}
-	if ((type != 0) && (type != 2)) {
-	    LM_ERR("unknown type <%d> at row <%u>\n", type, i);
-	    goto err;
-	}
+		row = RES_ROWS(res) + i;
 
 
-	if ((VAL_NULL(ROW_VALUES(row) + 3) == 1) ||
-	    (VAL_TYPE(ROW_VALUES(row) + 3) != DB1_STRING)) {
-	    LM_ERR("value at row <%u> is null or not string\n", i);
-	    goto err;
-	}
-	value.s = (char *)VAL_STRING(ROW_VALUES(row) + 3);
-	value.len = strlen(value.s);
+		if((VAL_NULL(ROW_VALUES(row)) == 1)
+				|| (VAL_TYPE(ROW_VALUES(row)) != DB1_STRING)) {
+			LM_ERR("did at row <%u> is null or not string\n", i);
+			goto err;
+		}
+		did.s = (char *)VAL_STRING(ROW_VALUES(row));
+		did.len = strlen(did.s);
+		if(did.len == 0) {
+			LM_ERR("did at row <%u> is empty string\n", i);
+			goto err;
+		}
 
 
-	if (type == 0) {
-	    if (str2sint(&value, &(val.n)) == -1) {
-		LM_ERR("value at row <%u> is invalid int\n", i);
-		goto err;
-	    }
-	} else {
-	    val.s = value;
-	}
+		if((VAL_NULL(ROW_VALUES(row) + 1) == 1)
+				|| (VAL_TYPE(ROW_VALUES(row) + 1) != DB1_STRING)) {
+			LM_ERR("name at row <%u> is null or not string\n", i);
+			goto err;
+		}
+		name.s = (char *)VAL_STRING(ROW_VALUES(row) + 1);
+		name.len = strlen(name.s);
+		if(name.len == 0) {
+			LM_ERR("name at row <%u> is empty string\n", i);
+			goto err;
+		}
 
 
-	if (type == 0) 
-	    LM_DBG("inserting <did/name/type/value> = <%s/%s/%d/%d> into attribute list\n", did.s, name.s, type, val.n);
-	else
-	    LM_DBG("inserting <did/name/type/value> = <%s/%s/%d/%s> into attribute list\n", did.s, name.s, type, val.s.s);
-		
-	if (hash_table_attr_install(new_hash_table, &did, &name, type,
-				    &val) == -1) {
-	    LM_ERR("could not install attribute into hash table\n");
-	    goto err;
-	}
-    }
-
-    domain_dbf.free_result(db_handle, res);
-    res = NULL;
-
-    cols[0] = &domain_col;
-    cols[1] = &did_col;
-    
-    if (domain_dbf.use_table(db_handle, &domain_table) < 0) {
-	LM_ERR("error while trying to use domain table\n");
-	goto err;
-    }
-
-    if (domain_dbf.query(db_handle, NULL, 0, NULL, cols, 0, 2, 0, &res) < 0) {
-	LM_ERR("error while querying database\n");
-	goto err;
-    }
-
-    row = RES_ROWS(res);
-
-    LM_DBG("number of rows in domain table: %d\n", RES_ROW_N(res));
-		
-    for (i = 0; i < RES_ROW_N(res); i++) {
-	
-	row = RES_ROWS(res) + i;
-
-	if ((VAL_NULL(ROW_VALUES(row)) == 1) ||
-	    (VAL_TYPE(ROW_VALUES(row)) != DB1_STRING)) {
-	    LM_ERR("domain at row <%u> is null or not string\n", i);
-	    goto err;
-	}
-	domain.s = (char *)VAL_STRING(ROW_VALUES(row));
-	domain.len = strlen(domain.s);
-	if (domain.len == 0) {
-	    LM_ERR("domain at row <%u> is empty string\n", i);
-	    goto err;
+		if((VAL_NULL(ROW_VALUES(row) + 2) == 1)
+				|| ((VAL_TYPE(ROW_VALUES(row) + 2) != DB1_INT)
+						   && (VAL_TYPE(ROW_VALUES(row) + 2) != DB1_BIGINT))) {
+			LM_ERR("type at row <%u> is null or not int\n", i);
+			goto err;
+		}
+		if(VAL_TYPE(ROW_VALUES(row) + 2) == DB1_BIGINT) {
+			type = (int)VAL_BIGINT(ROW_VALUES(row) + 2);
+		} else {
+			type = (int)VAL_INT(ROW_VALUES(row) + 2);
+		}
+		if((type != 0) && (type != 2)) {
+			LM_ERR("unknown type <%d> at row <%u>\n", type, i);
+			goto err;
+		}
+
+		if((VAL_NULL(ROW_VALUES(row) + 3) == 1)
+				|| (VAL_TYPE(ROW_VALUES(row) + 3) != DB1_STRING)) {
+			LM_ERR("value at row <%u> is null or not string\n", i);
+			goto err;
+		}
+		value.s = (char *)VAL_STRING(ROW_VALUES(row) + 3);
+		value.len = strlen(value.s);
+
+		if(type == 0) {
+			if(str2sint(&value, &(val.n)) == -1) {
+				LM_ERR("value at row <%u> is invalid int\n", i);
+				goto err;
+			}
+		} else {
+			val.s = value;
+		}
+
+		if(type == 0)
+			LM_DBG("inserting <did/name/type/value> = <%s/%s/%d/%d> into "
+				   "attribute list\n",
+					did.s, name.s, type, val.n);
+		else
+			LM_DBG("inserting <did/name/type/value> = <%s/%s/%d/%s> into "
+				   "attribute list\n",
+					did.s, name.s, type, val.s.s);
+
+		if(hash_table_attr_install(new_hash_table, &did, &name, type, &val)
+				== -1) {
+			LM_ERR("could not install attribute into hash table\n");
+			goto err;
+		}
 	}
 	}
 
 
-	if ((VAL_NULL(ROW_VALUES(row) + 1) != 1) &&
-	    (VAL_TYPE(ROW_VALUES(row) + 1) != DB1_STRING)) {
-	    LM_ERR("did at row <%u> is not null or string\n", i);
-	    goto err;
+	domain_dbf.free_result(db_handle, res);
+	res = NULL;
+
+	cols[0] = &domain_col;
+	cols[1] = &did_col;
+
+	if(domain_dbf.use_table(db_handle, &domain_table) < 0) {
+		LM_ERR("error while trying to use domain table\n");
+		goto err;
 	}
 	}
-	if (VAL_NULL(ROW_VALUES(row) + 1) == 1) {
-	    did.s = domain.s;
-	    did.len = domain.len;
-	} else {
-	    did.s = (char *)VAL_STRING(ROW_VALUES(row) + 1);
-	    did.len = strlen(did.s);
-	    if (did.len == 0) {
-		LM_ERR("did at row <%u> is empty string\n", i);
+
+	if(domain_dbf.query(db_handle, NULL, 0, NULL, cols, 0, 2, 0, &res) < 0) {
+		LM_ERR("error while querying database\n");
 		goto err;
 		goto err;
-	    }
 	}
 	}
 
 
-	LM_DBG("inserting <did/domain> = <%s/%s> into hash table\n",
-	       did.s, domain.s);
+	row = RES_ROWS(res);
+
+	LM_DBG("number of rows in domain table: %d\n", RES_ROW_N(res));
+
+	for(i = 0; i < RES_ROW_N(res); i++) {
+
+		row = RES_ROWS(res) + i;
+
+		if((VAL_NULL(ROW_VALUES(row)) == 1)
+				|| (VAL_TYPE(ROW_VALUES(row)) != DB1_STRING)) {
+			LM_ERR("domain at row <%u> is null or not string\n", i);
+			goto err;
+		}
+		domain.s = (char *)VAL_STRING(ROW_VALUES(row));
+		domain.len = strlen(domain.s);
+		if(domain.len == 0) {
+			LM_ERR("domain at row <%u> is empty string\n", i);
+			goto err;
+		}
+
+		if((VAL_NULL(ROW_VALUES(row) + 1) != 1)
+				&& (VAL_TYPE(ROW_VALUES(row) + 1) != DB1_STRING)) {
+			LM_ERR("did at row <%u> is not null or string\n", i);
+			goto err;
+		}
+		if(VAL_NULL(ROW_VALUES(row) + 1) == 1) {
+			did.s = domain.s;
+			did.len = domain.len;
+		} else {
+			did.s = (char *)VAL_STRING(ROW_VALUES(row) + 1);
+			did.len = strlen(did.s);
+			if(did.len == 0) {
+				LM_ERR("did at row <%u> is empty string\n", i);
+				goto err;
+			}
+		}
+
+		LM_DBG("inserting <did/domain> = <%s/%s> into hash table\n", did.s,
+				domain.s);
 
 
-	if (hash_table_install(new_hash_table, &did, &domain) == -1) {
-	    LM_ERR("could not install domain into hash table\n");
-	    domain_dbf.free_result(db_handle, res);
-	    goto err;
+		if(hash_table_install(new_hash_table, &did, &domain) == -1) {
+			LM_ERR("could not install domain into hash table\n");
+			domain_dbf.free_result(db_handle, res);
+			goto err;
+		}
 	}
 	}
-    }
 
 
-    domain_dbf.free_result(db_handle, res);
-    res = NULL;
-    
-    *hash_table = new_hash_table;
+	domain_dbf.free_result(db_handle, res);
+	res = NULL;
 
 
-    domain_db_close();
-    return 1;
+	*hash_table = new_hash_table;
 
 
- err:
-    domain_dbf.free_result(db_handle, res);
-    res = NULL;
-    domain_db_close();
-    return -1;
-}
+	domain_db_close();
+	return 1;
+
+err:
+	domain_dbf.free_result(db_handle, res);
+	res = NULL;
+	domain_db_close();
+	return -1;
+}

+ 11 - 11
src/modules/domain/domain.h

@@ -23,7 +23,7 @@
 
 
 #ifndef DOMAIN_H
 #ifndef DOMAIN_H
 #define DOMAIN_H
 #define DOMAIN_H
-		
+
 
 
 #include "../../core/parser/msg_parser.h"
 #include "../../core/parser/msg_parser.h"
 
 
@@ -31,13 +31,13 @@
 /*
 /*
  * Check if host in From uri is local
  * Check if host in From uri is local
  */
  */
-int is_from_local(struct sip_msg* _msg, char* _s1, char* _s2);
+int is_from_local(struct sip_msg *_msg, char *_s1, char *_s2);
 
 
 
 
 /*
 /*
  * Check if host in Request URI is local
  * Check if host in Request URI is local
  */
  */
-int is_uri_host_local(struct sip_msg* _msg, char* _s1, char* _s2);
+int is_uri_host_local(struct sip_msg *_msg, char *_s1, char *_s2);
 
 
 
 
 /*
 /*
@@ -49,19 +49,19 @@ int is_uri_host_local(struct sip_msg* _msg, char* _s1, char* _s2);
  * - avp name or alias - check the domain given by the value
  * - avp name or alias - check the domain given by the value
  *                       pointed by the avp name/alias
  *                       pointed by the avp name/alias
  */
  */
-int w_is_domain_local(struct sip_msg* _msg, char* _s1, char* _s2);
+int w_is_domain_local(struct sip_msg *_msg, char *_s1, char *_s2);
 
 
-int w_lookup_domain(struct sip_msg* _msg, char* _s1, char* _s2);
-int w_lookup_domain_no_prefix(struct sip_msg* _msg, char* _s1, char* _s2);
+int w_lookup_domain(struct sip_msg *_msg, char *_s1, char *_s2);
+int w_lookup_domain_no_prefix(struct sip_msg *_msg, char *_s1, char *_s2);
 
 
-int is_domain_local(str* domain);
+int is_domain_local(str *domain);
 
 
-int domain_check_self(str* host, unsigned short port, unsigned short proto);
+int domain_check_self(str *host, unsigned short port, unsigned short proto);
 
 
-int domain_db_bind(const str* db_url);
-int domain_db_init(const str* db_url);
+int domain_db_bind(const str *db_url);
+int domain_db_init(const str *db_url);
 void domain_db_close(void);
 void domain_db_close(void);
-int domain_db_ver(str* name, int version);
+int domain_db_ver(str *name, int version);
 
 
 int reload_tables(void);
 int reload_tables(void);
 
 

+ 62 - 68
src/modules/domain/domain_mod.c

@@ -70,24 +70,26 @@ static int domain_init_rpc(void);
 str d_db_url = str_init(DEFAULT_RODB_URL);
 str d_db_url = str_init(DEFAULT_RODB_URL);
 str domain_table = str_init(DOMAIN_TABLE); /* Name of domain table */
 str domain_table = str_init(DOMAIN_TABLE); /* Name of domain table */
 str domain_attrs_table = str_init(DOMAIN_ATTRS_TABLE);
 str domain_attrs_table = str_init(DOMAIN_ATTRS_TABLE);
-str did_col = str_init(DID_COL);       /* Name of domain id column */
-str domain_col = str_init(DOMAIN_COL);       /* Name of domain column */
-str name_col = str_init(NAME_COL);   /* Name of attribute name column */
-str type_col = str_init(TYPE_COL);   /* Name of attribute type column */
-str value_col = str_init(VALUE_COL); /* Name of attribute value column */
+str did_col = str_init(DID_COL);	   /* Name of domain id column */
+str domain_col = str_init(DOMAIN_COL); /* Name of domain column */
+str name_col = str_init(NAME_COL);	 /* Name of attribute name column */
+str type_col = str_init(TYPE_COL);	 /* Name of attribute type column */
+str value_col = str_init(VALUE_COL);   /* Name of attribute value column */
 int domain_reg_myself = 0;
 int domain_reg_myself = 0;
 
 
 /*
 /*
  * Other module variables
  * Other module variables
  */
  */
-struct domain_list ***hash_table = 0;	/* Pointer to current hash table pointer */
-struct domain_list **hash_table_1 = 0;	/* Pointer to hash table 1 */
-struct domain_list **hash_table_2 = 0;	/* Pointer to hash table 2 */
+struct domain_list ***hash_table =
+		0; /* Pointer to current hash table pointer */
+struct domain_list **hash_table_1 = 0; /* Pointer to hash table 1 */
+struct domain_list **hash_table_2 = 0; /* Pointer to hash table 2 */
 gen_lock_t *reload_lock;
 gen_lock_t *reload_lock;
 
 
 /*
 /*
  * Exported functions
  * Exported functions
  */
  */
+/* clang-format off */
 static cmd_export_t cmds[] = {
 static cmd_export_t cmds[] = {
 	{"is_from_local", (cmd_function)is_from_local, 0, 0, 0,
 	{"is_from_local", (cmd_function)is_from_local, 0, 0, 0,
 		REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
 		REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
@@ -105,11 +107,12 @@ static cmd_export_t cmds[] = {
 	{"bind_domain", (cmd_function)bind_domain, 1, 0, 0, 0},
 	{"bind_domain", (cmd_function)bind_domain, 1, 0, 0, 0},
 	{0, 0, 0, 0, 0, 0}
 	{0, 0, 0, 0, 0, 0}
 };
 };
-
+/* clang-format on */
 
 
 /*
 /*
  * Exported parameters
  * Exported parameters
  */
  */
+/* clang-format off */
 static param_export_t params[] = {
 static param_export_t params[] = {
 	{"db_url",         PARAM_STR, &d_db_url      },
 	{"db_url",         PARAM_STR, &d_db_url      },
 	{"domain_table",   PARAM_STR, &domain_table},
 	{"domain_table",   PARAM_STR, &domain_table},
@@ -122,11 +125,12 @@ static param_export_t params[] = {
 	{"register_myself",INT_PARAM, &domain_reg_myself},
 	{"register_myself",INT_PARAM, &domain_reg_myself},
 	{0, 0, 0}
 	{0, 0, 0}
 };
 };
-
+/* clang-format on */
 
 
 /*
 /*
  * Module interface
  * Module interface
  */
  */
+/* clang-format off */
 struct module_exports exports = {
 struct module_exports exports = {
 	"domain",
 	"domain",
 	DEFAULT_DLFLAGS, /* dlopen flags */
 	DEFAULT_DLFLAGS, /* dlopen flags */
@@ -141,43 +145,43 @@ struct module_exports exports = {
 	destroy,   /* destroy function */
 	destroy,   /* destroy function */
 	child_init /* per-child init function */
 	child_init /* per-child init function */
 };
 };
-
+/* clang-format on */
 
 
 static int mod_init(void)
 static int mod_init(void)
 {
 {
 	LM_DBG("initializing\n");
 	LM_DBG("initializing\n");
 
 
-	if (domain_init_rpc() != 0) {
+	if(domain_init_rpc() != 0) {
 		LM_ERR("failed to register RPC commands\n");
 		LM_ERR("failed to register RPC commands\n");
 		return -1;
 		return -1;
 	}
 	}
 
 
-	if (domain_reg_myself !=0 ) {
-		if (register_check_self_func(domain_check_self) <0 ) {
+	if(domain_reg_myself != 0) {
+		if(register_check_self_func(domain_check_self) < 0) {
 			LM_ERR("failed to register check self function\n");
 			LM_ERR("failed to register check self function\n");
 			return -1;
 			return -1;
 		}
 		}
 	}
 	}
 
 
 	/* Bind database */
 	/* Bind database */
-	if (domain_db_bind(&d_db_url)) {
+	if(domain_db_bind(&d_db_url)) {
 		LM_DBG("Usign db_url [%.*s]\n", d_db_url.len, d_db_url.s);
 		LM_DBG("Usign db_url [%.*s]\n", d_db_url.len, d_db_url.s);
 		LM_ERR("no database module found. Have you configure"
 		LM_ERR("no database module found. Have you configure"
-				" the \"db_url\" modparam properly?\n");
+			   " the \"db_url\" modparam properly?\n");
 		return -1;
 		return -1;
 	}
 	}
 
 
 	/* Check table versions */
 	/* Check table versions */
-	if (domain_db_init(&d_db_url) < 0) {
+	if(domain_db_init(&d_db_url) < 0) {
 		LM_ERR("unable to open database connection\n");
 		LM_ERR("unable to open database connection\n");
 		return -1;
 		return -1;
 	}
 	}
-	if (domain_db_ver(&domain_table, DOMAIN_TABLE_VERSION) < 0) {
+	if(domain_db_ver(&domain_table, DOMAIN_TABLE_VERSION) < 0) {
 		LM_ERR("error during check of domain table version\n");
 		LM_ERR("error during check of domain table version\n");
 		domain_db_close();
 		domain_db_close();
 		goto error;
 		goto error;
 	}
 	}
-	if (domain_db_ver(&domain_attrs_table, DOMAIN_ATTRS_TABLE_VERSION) < 0) {
+	if(domain_db_ver(&domain_attrs_table, DOMAIN_ATTRS_TABLE_VERSION) < 0) {
 		LM_ERR("error during check of domain_attrs table version\n");
 		LM_ERR("error during check of domain_attrs table version\n");
 		domain_db_close();
 		domain_db_close();
 		goto error;
 		goto error;
@@ -185,36 +189,34 @@ static int mod_init(void)
 	domain_db_close();
 	domain_db_close();
 
 
 	/* Initializing hash tables and hash table variable */
 	/* Initializing hash tables and hash table variable */
-	hash_table = (struct domain_list ***)shm_malloc
-		(sizeof(struct domain_list **));
-	hash_table_1 = (struct domain_list **)shm_malloc
-		(sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
-	hash_table_2 = (struct domain_list **)shm_malloc
-		(sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
-	if ((hash_table == 0) || (hash_table_1 == 0) || (hash_table_2 == 0)) {
+	hash_table =
+			(struct domain_list ***)shm_malloc(sizeof(struct domain_list **));
+	hash_table_1 = (struct domain_list **)shm_malloc(
+			sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
+	hash_table_2 = (struct domain_list **)shm_malloc(
+			sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
+	if((hash_table == 0) || (hash_table_1 == 0) || (hash_table_2 == 0)) {
 		LM_ERR("no memory for hash table\n");
 		LM_ERR("no memory for hash table\n");
 		goto error;
 		goto error;
 	}
 	}
-	memset(hash_table_1, 0, sizeof(struct domain_list *) *
-			(DOM_HASH_SIZE + 1));
-	memset(hash_table_2, 0, sizeof(struct domain_list *) *
-			(DOM_HASH_SIZE + 1));
+	memset(hash_table_1, 0, sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
+	memset(hash_table_2, 0, sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
 	*hash_table = hash_table_1;
 	*hash_table = hash_table_1;
 
 
 	/* Allocate and initialize locks */
 	/* Allocate and initialize locks */
 	reload_lock = lock_alloc();
 	reload_lock = lock_alloc();
-	if (reload_lock == NULL) {
+	if(reload_lock == NULL) {
 		LM_ERR("cannot allocate reload_lock\n");
 		LM_ERR("cannot allocate reload_lock\n");
 		goto error;
 		goto error;
 	}
 	}
-	if (lock_init(reload_lock) == NULL) {
+	if(lock_init(reload_lock) == NULL) {
 		LM_ERR("cannot init reload_lock\n");
 		LM_ERR("cannot init reload_lock\n");
 		goto error;
 		goto error;
 	}
 	}
 
 
 	/* First reload */
 	/* First reload */
 	lock_get(reload_lock);
 	lock_get(reload_lock);
-	if (reload_tables() == -1) {
+	if(reload_tables() == -1) {
 		lock_release(reload_lock);
 		lock_release(reload_lock);
 		LM_CRIT("domain reload failed\n");
 		LM_CRIT("domain reload failed\n");
 		goto error;
 		goto error;
@@ -241,16 +243,16 @@ static void destroy(void)
 	 * there is no need to close database here because
 	 * there is no need to close database here because
 	 * it is closed in mod_init already
 	 * it is closed in mod_init already
 	 */
 	 */
-	if (hash_table) {
+	if(hash_table) {
 		shm_free(hash_table);
 		shm_free(hash_table);
 		hash_table = 0;
 		hash_table = 0;
 	}
 	}
-	if (hash_table_1) {
+	if(hash_table_1) {
 		hash_table_free(hash_table_1);
 		hash_table_free(hash_table_1);
 		shm_free(hash_table_1);
 		shm_free(hash_table_1);
 		hash_table_1 = 0;
 		hash_table_1 = 0;
 	}
 	}
-	if (hash_table_2) {
+	if(hash_table_2) {
 		hash_table_free(hash_table_2);
 		hash_table_free(hash_table_2);
 		shm_free(hash_table_2);
 		shm_free(hash_table_2);
 		hash_table_2 = 0;
 		hash_table_2 = 0;
@@ -258,66 +260,60 @@ static void destroy(void)
 }
 }
 
 
 
 
-static const char* domain_rpc_reload_doc[2] = {
-	"Reload domain tables from database",
-	0
-};
+static const char *domain_rpc_reload_doc[2] = {
+		"Reload domain tables from database", 0};
 
 
 
 
 /*
 /*
  * RPC command to reload domain table
  * RPC command to reload domain table
  */
  */
-static void domain_rpc_reload(rpc_t* rpc, void* ctx)
+static void domain_rpc_reload(rpc_t *rpc, void *ctx)
 {
 {
 	lock_get(reload_lock);
 	lock_get(reload_lock);
-	if (reload_tables() < 0) {
+	if(reload_tables() < 0) {
 		rpc->fault(ctx, 400, "Reload of domain tables failed");
 		rpc->fault(ctx, 400, "Reload of domain tables failed");
 	}
 	}
 	lock_release(reload_lock);
 	lock_release(reload_lock);
 }
 }
 
 
 
 
-static const char* domain_rpc_dump_doc[2] = {
-	"Return the contents of domain and domain_attrs tables",
-	0
-};
+static const char *domain_rpc_dump_doc[2] = {
+		"Return the contents of domain and domain_attrs tables", 0};
 
 
 
 
 /*
 /*
  * Fifo function to print domains from current hash table
  * Fifo function to print domains from current hash table
  */
  */
-static void domain_rpc_dump(rpc_t* rpc, void* ctx)
+static void domain_rpc_dump(rpc_t *rpc, void *ctx)
 {
 {
 	int i;
 	int i;
 	struct domain_list *np;
 	struct domain_list *np;
 	struct attr_list *ap;
 	struct attr_list *ap;
 	struct domain_list **ht;
 	struct domain_list **ht;
-	void* st;
+	void *st;
 
 
-	if(hash_table==0 || *hash_table==0) {
+	if(hash_table == 0 || *hash_table == 0) {
 		rpc->fault(ctx, 404, "Server Domain Cache Empty");
 		rpc->fault(ctx, 404, "Server Domain Cache Empty");
 		return;
 		return;
 	}
 	}
 	ht = *hash_table;
 	ht = *hash_table;
-	for (i = 0; i < DOM_HASH_SIZE; i++) {
+	for(i = 0; i < DOM_HASH_SIZE; i++) {
 		np = ht[i];
 		np = ht[i];
-		while (np) {
-			if (rpc->add(ctx, "{", &st) < 0) return;
-			rpc->struct_add(st, "SS",
-					"domain", &np->domain,
-					"did", &np->did);
+		while(np) {
+			if(rpc->add(ctx, "{", &st) < 0)
+				return;
+			rpc->struct_add(st, "SS", "domain", &np->domain, "did", &np->did);
 			np = np->next;
 			np = np->next;
 		}
 		}
 	}
 	}
 	np = ht[DOM_HASH_SIZE];
 	np = ht[DOM_HASH_SIZE];
-	while (np) {
-		if (rpc->add(ctx, "{", &st) < 0) return;
-		rpc->struct_add(st, "S",
-				"did", &np->did);
+	while(np) {
+		if(rpc->add(ctx, "{", &st) < 0)
+			return;
+		rpc->struct_add(st, "S", "did", &np->did);
 		ap = np->attrs;
 		ap = np->attrs;
-		while (ap) {
-			rpc->struct_add(st, "S",
-					"attr", &ap->name);
+		while(ap) {
+			rpc->struct_add(st, "S", "attr", &ap->name);
 			ap = ap->next;
 			ap = ap->next;
 		}
 		}
 		np = np->next;
 		np = np->next;
@@ -328,16 +324,14 @@ static void domain_rpc_dump(rpc_t* rpc, void* ctx)
 
 
 
 
 rpc_export_t domain_rpc_list[] = {
 rpc_export_t domain_rpc_list[] = {
-	{"domain.reload", domain_rpc_reload, domain_rpc_reload_doc, 0},
-	{"domain.dump",   domain_rpc_dump,   domain_rpc_dump_doc,   0},
-	{0, 0, 0, 0}
-};
+		{"domain.reload", domain_rpc_reload, domain_rpc_reload_doc, 0},
+		{"domain.dump", domain_rpc_dump, domain_rpc_dump_doc, 0}, {0, 0, 0, 0}};
 
 
 static int domain_init_rpc(void)
 static int domain_init_rpc(void)
 {
 {
-	if (rpc_register_array(domain_rpc_list) != 0) {
+	if(rpc_register_array(domain_rpc_list) != 0) {
 		LM_ERR("failed to register RPC commands\n");
 		LM_ERR("failed to register RPC commands\n");
 		return -1;
 		return -1;
 	}
 	}
 	return 0;
 	return 0;
-}
+}

+ 14 - 12
src/modules/domain/domain_mod.h

@@ -36,15 +36,16 @@
 #define DOM_HASH_SIZE 128
 #define DOM_HASH_SIZE 128
 
 
 /* flags for param source for is_domain_local() */
 /* flags for param source for is_domain_local() */
-#define PARAM_SOURCE_NONE  (0)
-#define PARAM_SOURCE_AVP   (1<<0)
-#define PARAM_SOURCE_RURI  (1<<1)
-#define PARAM_SOURCE_FROM  (1<<2)
+#define PARAM_SOURCE_NONE (0)
+#define PARAM_SOURCE_AVP (1 << 0)
+#define PARAM_SOURCE_RURI (1 << 1)
+#define PARAM_SOURCE_FROM (1 << 2)
 
 
 
 
 /*
 /*
  * Type definitions
  * Type definitions
  */
  */
+/* clang-format off */
 struct domain_list {
 struct domain_list {
     str domain;
     str domain;
     str did;
     str did;
@@ -65,18 +66,19 @@ typedef struct param_source {
 	int avp_type;     /* If source is an avp, the avp type else 0 */
 	int avp_type;     /* If source is an avp, the avp type else 0 */
 	int_str avp_name; /* If source is an avp, the avp name else NULL */
 	int_str avp_name; /* If source is an avp, the avp name else NULL */
 } param_source;
 } param_source;
+/* clang-format on */
 
 
 /*
 /*
  * Module parameters variables
  * Module parameters variables
  */
  */
 extern str d_db_url;
 extern str d_db_url;
-extern str domain_table;	/* Domain table name */
-extern str domain_attrs_table;	/* Domain attributes table name */
-extern str did_col;   	        /* Domain id column name */
-extern str domain_col;   	/* Domain column name */
-extern str name_col;   	        /* Attribute name column name */
-extern str type_col;   	        /* Attribute type column name */
-extern str value_col;  	        /* Attribute value column name */
+extern str domain_table;	   /* Domain table name */
+extern str domain_attrs_table; /* Domain attributes table name */
+extern str did_col;			   /* Domain id column name */
+extern str domain_col;		   /* Domain column name */
+extern str name_col;		   /* Attribute name column name */
+extern str type_col;		   /* Attribute type column name */
+extern str value_col;		   /* Attribute value column name */
 
 
 /*
 /*
  * Other module variables
  * Other module variables
@@ -86,4 +88,4 @@ extern struct domain_list **hash_table_2; /* Hash table for domains */
 extern struct domain_list ***hash_table;  /* Current hash table */
 extern struct domain_list ***hash_table;  /* Current hash table */
 extern gen_lock_t *reload_lock;
 extern gen_lock_t *reload_lock;
 
 
-#endif /* DOMAIN_MOD_H */
+#endif /* DOMAIN_MOD_H */

+ 125 - 120
src/modules/domain/hash.c

@@ -31,19 +31,19 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <ctype.h>
 
 
-#define dom_hash(_s)  core_case_hash( _s, 0, DOM_HASH_SIZE)
+#define dom_hash(_s) core_case_hash(_s, 0, DOM_HASH_SIZE)
 
 
 /* Check if domain exists in hash table */
 /* Check if domain exists in hash table */
-int hash_table_lookup (str *domain, str *did, struct attr_list **attrs)
+int hash_table_lookup(str *domain, str *did, struct attr_list **attrs)
 {
 {
 	struct domain_list *np;
 	struct domain_list *np;
 
 
-	for (np = (*hash_table)[dom_hash(domain)]; np != NULL; np = np->next) {
-		if ((np->domain.len == domain->len) && 
-		    (strncasecmp(np->domain.s, domain->s, domain->len) == 0)) {
-		    *did = np->did;
-		    *attrs = np->attrs;
-		    return 1;
+	for(np = (*hash_table)[dom_hash(domain)]; np != NULL; np = np->next) {
+		if((np->domain.len == domain->len)
+				&& (strncasecmp(np->domain.s, domain->s, domain->len) == 0)) {
+			*did = np->did;
+			*attrs = np->attrs;
+			return 1;
 		}
 		}
 	}
 	}
 
 
@@ -51,113 +51,116 @@ int hash_table_lookup (str *domain, str *did, struct attr_list **attrs)
 }
 }
 
 
 /* Add did attribute to hash table */
 /* Add did attribute to hash table */
-int hash_table_attr_install (struct domain_list **hash_table, str* did,
-			     str *name, short type, int_str *val)
+int hash_table_attr_install(struct domain_list **hash_table, str *did,
+		str *name, short type, int_str *val)
 {
 {
-    struct attr_list *attr;
-    struct domain_list *np;
+	struct attr_list *attr;
+	struct domain_list *np;
 
 
-    attr = (struct attr_list *)shm_malloc(sizeof(struct attr_list));
-    if (attr == NULL) {
-	LM_ERR("no shm memory left for attribute\n");
-	return -1;
-    }
-    attr->name.s = (char *)shm_malloc(name->len);
-    if (attr->name.s == NULL) {
-	LM_ERR("no shm memory left for attribute name\n");
-	shm_free(attr);
-	return -1;
-    }
-    memcpy(attr->name.s, name->s, name->len);
-    attr->name.len = name->len;
-    attr->type = type;
-    attr->val.n = val->n;
-    attr->val.s = val->s;
-    if (type == 2) {
-	attr->val.s.s = (char *)shm_malloc(val->s.len);
-	if (attr->val.s.s == NULL) {
-	    LM_ERR("no shm memory left for attribute value\n");
-	    shm_free(attr->name.s);
-	    shm_free(attr);
+	attr = (struct attr_list *)shm_malloc(sizeof(struct attr_list));
+	if(attr == NULL) {
+		LM_ERR("no shm memory left for attribute\n");
+		return -1;
 	}
 	}
-	memcpy(attr->val.s.s, val->s.s, val->s.len);
-	attr->val.s.len = val->s.len;
-    }
-    attr->next = NULL;
-
-    np = hash_table[DOM_HASH_SIZE];
-    while (np) {
-	if ((np->did.len == did->len) && 
-	    (strncasecmp(np->did.s, did->s, did->len) == 0)) {
-	    if (np->attrs) attr->next = np->attrs;
-	    np->attrs = attr;
-	    return 1;
+	attr->name.s = (char *)shm_malloc(name->len);
+	if(attr->name.s == NULL) {
+		LM_ERR("no shm memory left for attribute name\n");
+		shm_free(attr);
+		return -1;
 	}
 	}
-	np = np->next;
-    }
-    np = (struct domain_list *)shm_malloc(sizeof(struct domain_list));
-    if (np == NULL) {
-	LM_ERR("no shm memory left for domain list\n");
-	if (type == 2) shm_free(attr->name.s);
-	shm_free(attr);
-	return -1;
-    }
-    np->did.s = (char *)shm_malloc(did->len);
-    if (np->did.s == NULL) {
-	LM_ERR("no shm memory left for did\n");
-	if (type == 2) shm_free(attr->name.s);
-	shm_free(attr);
-	shm_free(np);
-	return -1;
-    }
-    memcpy(np->did.s, did->s, did->len);
-    np->did.len = did->len;
-    np->attrs = attr;
-    np->next = hash_table[DOM_HASH_SIZE];
-    hash_table[DOM_HASH_SIZE] = np;
-	
-    return 1;
+	memcpy(attr->name.s, name->s, name->len);
+	attr->name.len = name->len;
+	attr->type = type;
+	attr->val.n = val->n;
+	attr->val.s = val->s;
+	if(type == 2) {
+		attr->val.s.s = (char *)shm_malloc(val->s.len);
+		if(attr->val.s.s == NULL) {
+			LM_ERR("no shm memory left for attribute value\n");
+			shm_free(attr->name.s);
+			shm_free(attr);
+		}
+		memcpy(attr->val.s.s, val->s.s, val->s.len);
+		attr->val.s.len = val->s.len;
+	}
+	attr->next = NULL;
+
+	np = hash_table[DOM_HASH_SIZE];
+	while(np) {
+		if((np->did.len == did->len)
+				&& (strncasecmp(np->did.s, did->s, did->len) == 0)) {
+			if(np->attrs)
+				attr->next = np->attrs;
+			np->attrs = attr;
+			return 1;
+		}
+		np = np->next;
+	}
+	np = (struct domain_list *)shm_malloc(sizeof(struct domain_list));
+	if(np == NULL) {
+		LM_ERR("no shm memory left for domain list\n");
+		if(type == 2)
+			shm_free(attr->name.s);
+		shm_free(attr);
+		return -1;
+	}
+	np->did.s = (char *)shm_malloc(did->len);
+	if(np->did.s == NULL) {
+		LM_ERR("no shm memory left for did\n");
+		if(type == 2)
+			shm_free(attr->name.s);
+		shm_free(attr);
+		shm_free(np);
+		return -1;
+	}
+	memcpy(np->did.s, did->s, did->len);
+	np->did.len = did->len;
+	np->attrs = attr;
+	np->next = hash_table[DOM_HASH_SIZE];
+	hash_table[DOM_HASH_SIZE] = np;
+
+	return 1;
 }
 }
 
 
 /* Add domain to hash table */
 /* Add domain to hash table */
-int hash_table_install (struct domain_list **hash_table, str* did, str *domain)
+int hash_table_install(struct domain_list **hash_table, str *did, str *domain)
 {
 {
-        struct domain_list *np, *dl;
+	struct domain_list *np, *dl;
 	unsigned int hash_val;
 	unsigned int hash_val;
-	    
-	np = (struct domain_list *) shm_malloc(sizeof(*np));
-	if (np == NULL) {
+
+	np = (struct domain_list *)shm_malloc(sizeof(*np));
+	if(np == NULL) {
 		LM_ERR("no shared memory for hash table entry\n");
 		LM_ERR("no shared memory for hash table entry\n");
 		return -1;
 		return -1;
 	}
 	}
 
 
 	np->did.len = did->len;
 	np->did.len = did->len;
 	np->did.s = (char *)shm_malloc(did->len);
 	np->did.s = (char *)shm_malloc(did->len);
-	if (np->did.s == NULL) {
+	if(np->did.s == NULL) {
 		LM_ERR("no shared memeory for did\n");
 		LM_ERR("no shared memeory for did\n");
-	        shm_free(np);
+		shm_free(np);
 		return -1;
 		return -1;
 	}
 	}
 	(void)memcpy(np->did.s, did->s, did->len);
 	(void)memcpy(np->did.s, did->s, did->len);
 
 
 	np->domain.len = domain->len;
 	np->domain.len = domain->len;
-	np->domain.s = (char *) shm_malloc(domain->len);
-	if (np->domain.s == NULL) {
+	np->domain.s = (char *)shm_malloc(domain->len);
+	if(np->domain.s == NULL) {
 		LM_ERR("no shared memory for domain\n");
 		LM_ERR("no shared memory for domain\n");
-	        shm_free(np);
+		shm_free(np);
 		return -1;
 		return -1;
 	}
 	}
 	(void)strncpy(np->domain.s, domain->s, domain->len);
 	(void)strncpy(np->domain.s, domain->s, domain->len);
 
 
 	np->attrs = NULL;
 	np->attrs = NULL;
 	dl = hash_table[DOM_HASH_SIZE];
 	dl = hash_table[DOM_HASH_SIZE];
-	while (dl) {
-	    if ((dl->did.len == did->len) && 
-		(strncasecmp(dl->did.s, did->s, did->len) == 0)) {
-		np->attrs = dl->attrs;
-		break;
-	    }
-	    dl = dl->next;
+	while(dl) {
+		if((dl->did.len == did->len)
+				&& (strncasecmp(dl->did.s, did->s, did->len) == 0)) {
+			np->attrs = dl->attrs;
+			break;
+		}
+		dl = dl->next;
 	}
 	}
 	hash_val = dom_hash(&np->domain);
 	hash_val = dom_hash(&np->domain);
 	np->next = hash_table[hash_val];
 	np->next = hash_table[hash_val];
@@ -168,40 +171,42 @@ int hash_table_install (struct domain_list **hash_table, str* did, str *domain)
 
 
 
 
 /* Free contents of hash table */
 /* Free contents of hash table */
-void hash_table_free (struct domain_list **hash_table)
+void hash_table_free(struct domain_list **hash_table)
 {
 {
-    int i;
-    struct domain_list *np, *next;
-    struct attr_list *ap, *next_ap;
-
-    if (hash_table == 0) return;
-
-    for (i = 0; i < DOM_HASH_SIZE; i++) {
-	np = hash_table[i];
-	while (np) {
-	    shm_free(np->did.s);
-	    shm_free(np->domain.s);
-	    next = np->next;
-	    shm_free(np);
-	    np = next;
+	int i;
+	struct domain_list *np, *next;
+	struct attr_list *ap, *next_ap;
+
+	if(hash_table == 0)
+		return;
+
+	for(i = 0; i < DOM_HASH_SIZE; i++) {
+		np = hash_table[i];
+		while(np) {
+			shm_free(np->did.s);
+			shm_free(np->domain.s);
+			next = np->next;
+			shm_free(np);
+			np = next;
+		}
+		hash_table[i] = NULL;
 	}
 	}
-	hash_table[i] = NULL;
-    }
-
-    np = hash_table[DOM_HASH_SIZE];
-    while (np) {
-	shm_free(np->did.s);
-	ap = np->attrs;
-	while (ap) {
-	    shm_free(ap->name.s);
-	    if (ap->type == 2) shm_free(ap->val.s.s);
-	    next_ap = ap->next;
-	    shm_free(ap);
-	    ap = next_ap;
+
+	np = hash_table[DOM_HASH_SIZE];
+	while(np) {
+		shm_free(np->did.s);
+		ap = np->attrs;
+		while(ap) {
+			shm_free(ap->name.s);
+			if(ap->type == 2)
+				shm_free(ap->val.s.s);
+			next_ap = ap->next;
+			shm_free(ap);
+			ap = next_ap;
+		}
+		np = np->next;
 	}
 	}
-	np = np->next;
-    }
 
 
-    hash_table[DOM_HASH_SIZE] = NULL;
-    return;
-}
+	hash_table[DOM_HASH_SIZE] = NULL;
+	return;
+}

+ 6 - 6
src/modules/domain/hash.h

@@ -27,10 +27,10 @@
 #include <stdio.h>
 #include <stdio.h>
 #include "domain_mod.h"
 #include "domain_mod.h"
 
 
-int hash_table_install (struct domain_list **hash_table, str *did, str *domain);
-int hash_table_attr_install (struct domain_list **hash_table, str* did,
-			     str *name, short type, int_str *val);
-int hash_table_lookup (str *domain, str *did, struct attr_list **attrs);
-void hash_table_free (struct domain_list **hash_table);
+int hash_table_install(struct domain_list **hash_table, str *did, str *domain);
+int hash_table_attr_install(struct domain_list **hash_table, str *did,
+		str *name, short type, int_str *val);
+int hash_table_lookup(str *domain, str *did, struct attr_list **attrs);
+void hash_table_free(struct domain_list **hash_table);
 
 
-#endif
+#endif