Browse Source

uid_uri_db: clang-format for coherent indentation and coding style

Victor Seva 2 năm trước cách đây
mục cha
commit
57e2255427

+ 0 - 1
src/modules/uid_uri_db/checks.c

@@ -25,4 +25,3 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
-

+ 6 - 6
src/modules/uid_uri_db/checks.h

@@ -37,25 +37,25 @@
  * Check if To header field contains the same username
  * as digest credentials
  */
-int check_to(struct sip_msg* _msg, char* _str1, char* _str2);
+int check_to(struct sip_msg *_msg, char *_str1, char *_str2);
 
 
 /*
  * Check if From header field contains the same username
  * as digest credentials
  */
-int check_from(struct sip_msg* _msg, char* _str1, char* _str2);
+int check_from(struct sip_msg *_msg, char *_str1, char *_str2);
 
 
 /*
  * Check if uri belongs to a local user, contributed by Juha Heinanen
  */
-int does_uri_exist(struct sip_msg* _msg, char* _table, char* _s2);
+int does_uri_exist(struct sip_msg *_msg, char *_table, char *_s2);
 
 
-int uridb_db_init(char* db_url);
-int uridb_db_bind(char* db_url);
+int uridb_db_init(char *db_url);
+int uridb_db_bind(char *db_url);
 void uridb_db_close();
-int uridb_db_ver(char* db_url, str* name);
+int uridb_db_ver(char *db_url, str *name);
 
 #endif /* CHECKS_H */

+ 138 - 137
src/modules/uid_uri_db/uid_uri_db_mod.c

@@ -57,20 +57,20 @@ MODULE_VERSION
  */
 #define URI_TABLE_VERSION 2
 
-static void destroy(void);       /* Module destroy function */
+static void destroy(void);		 /* Module destroy function */
 static int child_init(int rank); /* Per-child initialization function */
-static int lookup_user(struct sip_msg* msg, char* s1, char* s2);
-static int lookup_user_2(struct sip_msg* msg, char* s1, char* s2);
-static int check_uri(struct sip_msg* msg, char* s1, char* s2);
-static int header_fixup(void** param, int param_no);
-static int lookup_user_fixup(void** param, int param_no);
-
-#define URI_TABLE    "uid_uri"
-#define UID_COL      "uid"
-#define DID_COL      "did"
+static int lookup_user(struct sip_msg *msg, char *s1, char *s2);
+static int lookup_user_2(struct sip_msg *msg, char *s1, char *s2);
+static int check_uri(struct sip_msg *msg, char *s1, char *s2);
+static int header_fixup(void **param, int param_no);
+static int lookup_user_fixup(void **param, int param_no);
+
+#define URI_TABLE "uid_uri"
+#define UID_COL "uid"
+#define DID_COL "did"
 #define USERNAME_COL "username"
-#define FLAGS_COL    "flags"
-#define SCHEME_COL   "scheme"
+#define FLAGS_COL "flags"
+#define SCHEME_COL "scheme"
 
 #define CANONICAL_AVP "ruri_canonical"
 #define CANONICAL_AVP_VAL "1"
@@ -78,67 +78,62 @@ static int lookup_user_fixup(void** param, int param_no);
 /*
  * Module parameter variables
  */
-str db_url       = STR_STATIC_INIT(DEFAULT_RODB_URL);
-str uri_table    = STR_STATIC_INIT(URI_TABLE);
-str uid_col      = STR_STATIC_INIT(UID_COL);
-str did_col      = STR_STATIC_INIT(DID_COL);
+str db_url = STR_STATIC_INIT(DEFAULT_RODB_URL);
+str uri_table = STR_STATIC_INIT(URI_TABLE);
+str uid_col = STR_STATIC_INIT(UID_COL);
+str did_col = STR_STATIC_INIT(DID_COL);
 str username_col = STR_STATIC_INIT(USERNAME_COL);
-str flags_col    = STR_STATIC_INIT(FLAGS_COL);
-str scheme_col   = STR_STATIC_INIT(SCHEME_COL);
+str flags_col = STR_STATIC_INIT(FLAGS_COL);
+str scheme_col = STR_STATIC_INIT(SCHEME_COL);
 str canonical_avp = STR_STATIC_INIT(CANONICAL_AVP);
 str canonical_avp_val = STR_STATIC_INIT(CANONICAL_AVP_VAL);
 
-static db_ctx_t* db = NULL;
-static db_cmd_t* lookup_uid_cmd = NULL;
+static db_ctx_t *db = NULL;
+static db_cmd_t *lookup_uid_cmd = NULL;
 
 static domain_get_did_t dm_get_did = NULL;
 
 /* default did value */
-str default_did	= STR_STATIC_INIT("_default");
+str default_did = STR_STATIC_INIT("_default");
 
 /*
  * Exported functions
  */
-static cmd_export_t cmds[] = {
-	{"lookup_user", lookup_user,   1, header_fixup, 0,
-		REQUEST_ROUTE | FAILURE_ROUTE},
-	{"lookup_user", lookup_user_2, 2, lookup_user_fixup, 0,
-		REQUEST_ROUTE | FAILURE_ROUTE},
-	{"check_uri",   check_uri,     1, header_fixup, 0,
-		REQUEST_ROUTE | FAILURE_ROUTE},
-	{0, 0, 0, 0, 0, 0}
-};
+static cmd_export_t cmds[] = {{"lookup_user", lookup_user, 1, header_fixup, 0,
+									  REQUEST_ROUTE | FAILURE_ROUTE},
+		{"lookup_user", lookup_user_2, 2, lookup_user_fixup, 0,
+				REQUEST_ROUTE | FAILURE_ROUTE},
+		{"check_uri", check_uri, 1, header_fixup, 0,
+				REQUEST_ROUTE | FAILURE_ROUTE},
+		{0, 0, 0, 0, 0, 0}};
 
 
 /*
  * Exported parameters
  */
-static param_export_t params[] = {
-	{"db_url",          PARAM_STR, &db_url       },
-	{"uri_table",       PARAM_STR, &uri_table    },
-	{"uid_column",      PARAM_STR, &uid_col      },
-	{"did_column",      PARAM_STR, &did_col      },
-	{"username_column", PARAM_STR, &username_col },
-	{"flags_column",    PARAM_STR, &flags_col    },
-	{"scheme_column",   PARAM_STR, &scheme_col   },
-	{0, 0, 0}
-};
+static param_export_t params[] = {{"db_url", PARAM_STR, &db_url},
+		{"uri_table", PARAM_STR, &uri_table},
+		{"uid_column", PARAM_STR, &uid_col},
+		{"did_column", PARAM_STR, &did_col},
+		{"username_column", PARAM_STR, &username_col},
+		{"flags_column", PARAM_STR, &flags_col},
+		{"scheme_column", PARAM_STR, &scheme_col}, {0, 0, 0}};
 
 
 /*
  * Module interface
  */
 struct module_exports exports = {
-	"uid_uri_db", /* module name */
-	DEFAULT_DLFLAGS, /* dlopen flags */
-	cmds,         /* exported functions */
-	params,       /* exported parameters */
-	0,            /* exported RPC methods */
-	0,            /* exported pseudo-variables */
-	0,            /* module init function */
-	0,            /* response handling function */
-	child_init,   /* child init function */
-	destroy       /* destroy function */
+		"uid_uri_db",	 /* module name */
+		DEFAULT_DLFLAGS, /* dlopen flags */
+		cmds,			 /* exported functions */
+		params,			 /* exported parameters */
+		0,				 /* exported RPC methods */
+		0,				 /* exported pseudo-variables */
+		0,				 /* module init function */
+		0,				 /* response handling function */
+		child_init,		 /* child init function */
+		destroy			 /* destroy function */
 };
 
 
@@ -147,49 +142,49 @@ struct module_exports exports = {
  */
 static int child_init(int rank)
 {
-	db_fld_t lookup_uid_columns[] = {
-		{.name = uid_col.s,   DB_STR},
-		{.name = flags_col.s, DB_BITMAP},
-		{.name = NULL}
-	};
-
-	db_fld_t lookup_uid_match[] = {
-		{.name = username_col.s, DB_STR},
-		{.name = did_col.s,      DB_STR},
-		{.name = scheme_col.s,   DB_STR},
-		{.name = NULL}
-	};
-
-	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
+	db_fld_t lookup_uid_columns[] = {{.name = uid_col.s, DB_STR},
+			{.name = flags_col.s, DB_BITMAP}, {.name = NULL}};
+
+	db_fld_t lookup_uid_match[] = {{.name = username_col.s, DB_STR},
+			{.name = did_col.s, DB_STR}, {.name = scheme_col.s, DB_STR},
+			{.name = NULL}};
+
+	if(rank == PROC_INIT || rank == PROC_MAIN || rank == PROC_TCP_MAIN)
 		return 0; /* do nothing for the main or tcp_main processes */
 
 	db = db_ctx("uri_db");
-	if (db == NULL) {
+	if(db == NULL) {
 		LM_ERR("failure initializing database layer\n");
 		return -1;
 	}
-	if (db_add_db(db, db_url.s) < 0) goto error;
-	if (db_connect(db) < 0) goto error;
+	if(db_add_db(db, db_url.s) < 0)
+		goto error;
+	if(db_connect(db) < 0)
+		goto error;
 
 	lookup_uid_cmd = db_cmd(DB_GET, db, uri_table.s, lookup_uid_columns,
 			lookup_uid_match, NULL);
-	if (lookup_uid_cmd == NULL) {
+	if(lookup_uid_cmd == NULL) {
 		LM_ERR("failure building db query to load global attributes\n");
 		goto error;
 	}
 	return 0;
 
 error:
-	if (lookup_uid_cmd) db_cmd_free(lookup_uid_cmd);
-	if (db) db_ctx_free(db);
+	if(lookup_uid_cmd)
+		db_cmd_free(lookup_uid_cmd);
+	if(db)
+		db_ctx_free(db);
 	return -1;
 }
 
 
 static void destroy(void)
 {
-	if (lookup_uid_cmd) db_cmd_free(lookup_uid_cmd);
-	if (db) db_ctx_free(db);
+	if(lookup_uid_cmd)
+		db_cmd_free(lookup_uid_cmd);
+	if(db)
+		db_ctx_free(db);
 }
 
 /*
@@ -197,53 +192,54 @@ static void destroy(void)
  * store the UID in an attribute.
  * The function returns 1 if UID was found, -1 if not or on an error
  */
-static int lookup_uid(struct sip_msg* msg, long id, int store)
+static int lookup_uid(struct sip_msg *msg, long id, int store)
 {
-	struct to_body* from, *to;
+	struct to_body *from, *to;
 	struct sip_uri puri;
 	str did, uid;
-	db_res_t* res;
-	db_rec_t* rec;
+	db_res_t *res;
+	db_rec_t *rec;
 	int flag, ret;
 
 	int_str avp_name, avp_val;
-	flag=0; /*warning fix*/
+	flag = 0; /*warning fix*/
 
-	did.s = 0; did.len = 0;
+	did.s = 0;
+	did.len = 0;
 
-	if (id == USE_FROM) {
+	if(id == USE_FROM) {
 		get_from_did(&did, msg);
 		flag = SRDB_IS_FROM;
 
-		if (parse_from_header(msg) < 0) {
+		if(parse_from_header(msg) < 0) {
 			LM_ERR("error while parsing From header\n");
 			return -1;
 		}
 		from = get_from(msg);
-		if (!from) {
+		if(!from) {
 			LM_ERR("unable to get From username\n");
 			return -1;
 		}
-		if (parse_uri(from->uri.s, from->uri.len, &puri) < 0) {
+		if(parse_uri(from->uri.s, from->uri.len, &puri) < 0) {
 			LM_ERR("error while parsing From URI\n");
 			return -1;
 		}
 		lookup_uid_cmd->match[0].v.lstr = puri.user;
 		uri_type_to_str(puri.type, &(lookup_uid_cmd->match[2].v.lstr));
-	} else if (id == USE_TO) {
+	} else if(id == USE_TO) {
 		get_to_did(&did, msg);
-		if (!msg->to) {
-			if (parse_headers(msg, HDR_TO_F, 0)==-1 || !msg->to) {
+		if(!msg->to) {
+			if(parse_headers(msg, HDR_TO_F, 0) == -1 || !msg->to) {
 				LM_ERR("unable to parse To header\n");
 				return -1;
 			}
 		}
 		to = get_to(msg);
-		if (!to) {
+		if(!to) {
 			LM_ERR("unable to get To body\n");
 			return -1;
 		}
-		if (parse_uri(to->uri.s, to->uri.len, &puri) < 0) {
+		if(parse_uri(to->uri.s, to->uri.len, &puri) < 0) {
 			LM_ERR("error while parsing To URI\n");
 			return -1;
 		}
@@ -254,59 +250,64 @@ static int lookup_uid(struct sip_msg* msg, long id, int store)
 		get_to_did(&did, msg);
 		flag = SRDB_IS_TO;
 
-		if (parse_sip_msg_uri(msg) < 0) return -1;
+		if(parse_sip_msg_uri(msg) < 0)
+			return -1;
 		lookup_uid_cmd->match[0].v.lstr = msg->parsed_uri.user;
-		uri_type_to_str(msg->parsed_uri.type, &(lookup_uid_cmd->match[2].v.lstr));
+		uri_type_to_str(
+				msg->parsed_uri.type, &(lookup_uid_cmd->match[2].v.lstr));
 	}
 
-	if (did.s && did.len) {
+	if(did.s && did.len) {
 		lookup_uid_cmd->match[1].v.lstr = did;
 	} else {
 		LM_DBG("DID not found, using default value\n");
 		lookup_uid_cmd->match[1].v.lstr = default_did;
 	}
 
-	if (db_exec(&res, lookup_uid_cmd) < 0) {
+	if(db_exec(&res, lookup_uid_cmd) < 0) {
 		LM_ERR("error while executing database query\n");
 		return -1;
 	}
 
 	rec = db_first(res);
 	while(rec) {
-		if (rec->fld[0].flags & DB_NULL ||
-				rec->fld[1].flags & DB_NULL) {
+		if(rec->fld[0].flags & DB_NULL || rec->fld[1].flags & DB_NULL) {
 			LM_ERR("bogus line in %s table\n", uri_table.s);
 			goto skip;
 		}
 
 		/* Skip disabled entries */
-		if ((rec->fld[1].v.int4 & SRDB_DISABLED)) goto skip;
+		if((rec->fld[1].v.int4 & SRDB_DISABLED))
+			goto skip;
 		/* Not for SER */
-		if ((rec->fld[1].v.int4 & SRDB_LOAD_SER) == 0) goto skip;
+		if((rec->fld[1].v.int4 & SRDB_LOAD_SER) == 0)
+			goto skip;
 		/* Not allowed in the header we are interested in */
-		if ((rec->fld[1].v.int4 & flag) == 0) goto skip;
+		if((rec->fld[1].v.int4 & flag) == 0)
+			goto skip;
 		goto found;
 
-skip:
+	skip:
 		rec = db_next(res);
 	}
 	ret = -1; /* Not found -> not allowed */
 	goto freeres;
 
 found:
-	if (store) {
+	if(store) {
 		uid = rec->fld[0].v.lstr;
-		if (id == USE_FROM) {
+		if(id == USE_FROM) {
 			set_from_uid(&uid);
 		} else {
 			set_to_uid(&uid);
-			if (id == USE_RURI) {
+			if(id == USE_RURI) {
 				/* store as str|int avp if alias is canonical or not (1,0) */
-				if ((rec->fld[1].v.int4 & SRDB_CANON) != 0) {
+				if((rec->fld[1].v.int4 & SRDB_CANON) != 0) {
 					avp_name.s = canonical_avp;
 					avp_val.s = canonical_avp_val;
 					add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR
-							| AVP_VAL_STR, avp_name, avp_val);
+									| AVP_VAL_STR,
+							avp_name, avp_val);
 				}
 			}
 		}
@@ -319,55 +320,54 @@ freeres:
 }
 
 
-static int check_uri(struct sip_msg* msg, char* s1, char* s2)
+static int check_uri(struct sip_msg *msg, char *s1, char *s2)
 {
 	return lookup_uid(msg, (long)s1, 0);
 }
 
 
-
-static int lookup_user(struct sip_msg* msg, char* s1, char* s2)
+static int lookup_user(struct sip_msg *msg, char *s1, char *s2)
 {
 	return lookup_uid(msg, (long)s1, 1);
 }
 
 
-static int lookup_user_2(struct sip_msg* msg, char* attr, char* select)
+static int lookup_user_2(struct sip_msg *msg, char *attr, char *select)
 {
-	db_res_t* res;
-	db_rec_t* rec;
+	db_res_t *res;
+	db_rec_t *rec;
 	str uri, did, uid;
 	struct sip_uri puri;
-	avp_ident_t* avp;
+	avp_ident_t *avp;
 	int_str avp_val;
 	int flag, ret;
 
-	avp = &((fparam_t*)attr)->v.avp;
+	avp = &((fparam_t *)attr)->v.avp;
 
-	if (!avp) {
+	if(!avp) {
 		LM_ERR("invalid parameter 1, attribute name expected\n");
 		return -1;
 	}
 
-	if (avp->flags & AVP_TRACK_TO) {
+	if(avp->flags & AVP_TRACK_TO) {
 		flag = SRDB_IS_TO;
 	} else {
 		flag = SRDB_IS_FROM;
 	}
 
-	if (get_str_fparam(&uri, msg, (fparam_t*)select) != 0) {
-		LM_ERR("unable to get SIP URI from %s\n", ((fparam_t*)select)->orig);
+	if(get_str_fparam(&uri, msg, (fparam_t *)select) != 0) {
+		LM_ERR("unable to get SIP URI from %s\n", ((fparam_t *)select)->orig);
 		return -1;
 	}
 
-	if (parse_uri(uri.s, uri.len, &puri) < 0) {
+	if(parse_uri(uri.s, uri.len, &puri) < 0) {
 		LM_ERR("error while parsing URI '%.*s'\n", uri.len, ZSW(uri.s));
 		return -1;
 	}
 
-	if (puri.host.len) {
+	if(puri.host.len) {
 		/* domain name is present */
-		if (dm_get_did(&did, &puri.host) < 0) {
+		if(dm_get_did(&did, &puri.host) < 0) {
 			LM_DBG("cannot lookup DID for domain '%.*s', using default value\n",
 					puri.host.len, ZSW(puri.host.s));
 			did = default_did;
@@ -379,7 +379,7 @@ static int lookup_user_2(struct sip_msg* msg, char* attr, char* select)
 	}
 
 	/* don't lookup users with empty username -- wasted DB time */
-	if (puri.user.len==0) {
+	if(puri.user.len == 0) {
 		return -1;
 	}
 
@@ -387,28 +387,30 @@ static int lookup_user_2(struct sip_msg* msg, char* attr, char* select)
 	lookup_uid_cmd->match[1].v.lstr = did;
 	uri_type_to_str(puri.type, &(lookup_uid_cmd->match[2].v.lstr));
 
-	if (db_exec(&res, lookup_uid_cmd) < 0) {
+	if(db_exec(&res, lookup_uid_cmd) < 0) {
 		LM_ERR("error in db_query\n");
 		return -1;
 	}
 
 	rec = db_first(res);
 	while(rec) {
-		if (rec->fld[0].flags & DB_NULL ||
-				rec->fld[1].flags & DB_NULL) {
+		if(rec->fld[0].flags & DB_NULL || rec->fld[1].flags & DB_NULL) {
 			LM_ERR("bogus line in %s table\n", uri_table.s);
 			goto skip;
 		}
 
 		/* Skip disabled entries */
-		if ((rec->fld[1].v.int4 & SRDB_DISABLED)) goto skip;
+		if((rec->fld[1].v.int4 & SRDB_DISABLED))
+			goto skip;
 		/* Not for SER */
-		if ((rec->fld[1].v.int4 & SRDB_LOAD_SER) == 0) goto skip;
+		if((rec->fld[1].v.int4 & SRDB_LOAD_SER) == 0)
+			goto skip;
 		/* Not allowed in the header we are interested in */
-		if ((rec->fld[1].v.int4 & flag) == 0) goto skip;
+		if((rec->fld[1].v.int4 & flag) == 0)
+			goto skip;
 		goto found;
 
-skip:
+	skip:
 		rec = db_next(res);
 	}
 
@@ -420,7 +422,7 @@ found:
 	uid = rec->fld[0].v.lstr;
 	avp_val.s = uid;
 
-	if (add_avp(avp->flags | AVP_VAL_STR, avp->name, avp_val) < 0) {
+	if(add_avp(avp->flags | AVP_VAL_STR, avp->name, avp_val) < 0) {
 		LM_ERR("error while creating attribute\n");
 		ret = -1;
 	} else {
@@ -433,17 +435,16 @@ freeres:
 }
 
 
-
-static int header_fixup(void** param, int param_no)
+static int header_fixup(void **param, int param_no)
 {
 	long id = 0;
 
-	if (param_no == 1) {
-		if (!strcasecmp(*param, "Request-URI")) {
+	if(param_no == 1) {
+		if(!strcasecmp(*param, "Request-URI")) {
 			id = USE_RURI;
-		} else if (!strcasecmp(*param, "From")) {
+		} else if(!strcasecmp(*param, "From")) {
 			id = USE_FROM;
-		} else if (!strcasecmp(*param, "To")) {
+		} else if(!strcasecmp(*param, "To")) {
 			id = USE_TO;
 		} else {
 			LM_ERR("unknown parameter: %d\n", param_no);
@@ -452,20 +453,20 @@ static int header_fixup(void** param, int param_no)
 	}
 
 	pkg_free(*param);
-	*param=(void*)id;
+	*param = (void *)id;
 	return 0;
 }
 
 
-static int lookup_user_fixup(void** param, int param_no)
+static int lookup_user_fixup(void **param, int param_no)
 {
-	if (param_no == 1) {
-		if (fix_param(FPARAM_AVP, param) != 0) {
+	if(param_no == 1) {
+		if(fix_param(FPARAM_AVP, param) != 0) {
 			LM_ERR("invalid parameter 1, attribute expected\n");
 			return -1;
 		}
 		dm_get_did = (domain_get_did_t)find_export("get_did", 0, 0);
-		if (!dm_get_did) {
+		if(!dm_get_did) {
 			LM_ERR("could not find domain module\n");
 			return -1;
 		}