瀏覽代碼

maxfwd: applied clang format

Daniel-Constantin Mierla 8 年之前
父節點
當前提交
6c01e2692d
共有 4 個文件被更改,包括 68 次插入74 次删除
  1. 4 5
      src/modules/maxfwd/api.h
  2. 26 29
      src/modules/maxfwd/maxfwd.c
  3. 35 36
      src/modules/maxfwd/mf_funcs.c
  4. 3 4
      src/modules/maxfwd/mf_funcs.h

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

@@ -30,11 +30,12 @@ typedef int (*process_maxfwd_f)(struct sip_msg *msg, int limit);
 /**
 /**
  * @brief MAXFWD API structure
  * @brief MAXFWD API structure
  */
  */
-typedef struct maxfwd_api {
+typedef struct maxfwd_api
+{
 	process_maxfwd_f process_maxfwd;
 	process_maxfwd_f process_maxfwd;
 } maxfwd_api_t;
 } maxfwd_api_t;
 
 
-typedef int (*bind_maxfwd_f)(maxfwd_api_t* api);
+typedef int (*bind_maxfwd_f)(maxfwd_api_t *api);
 
 
 /**
 /**
  * @brief Load the MAXFWD API
  * @brief Load the MAXFWD API
@@ -48,8 +49,7 @@ static inline int maxfwd_load_api(maxfwd_api_t *api)
 		LM_ERR("cannot find bind_maxfwd\n");
 		LM_ERR("cannot find bind_maxfwd\n");
 		return -1;
 		return -1;
 	}
 	}
-	if (bindmaxfwd(api)==-1)
-	{
+	if(bindmaxfwd(api) == -1) {
 		LM_ERR("cannot bind maxfwd api\n");
 		LM_ERR("cannot bind maxfwd api\n");
 		return -1;
 		return -1;
 	}
 	}
@@ -57,4 +57,3 @@ static inline int maxfwd_load_api(maxfwd_api_t *api)
 }
 }
 
 
 #endif
 #endif
-

+ 26 - 29
src/modules/maxfwd/maxfwd.c

@@ -38,6 +38,7 @@
 
 
 MODULE_VERSION
 MODULE_VERSION
 
 
+/* clang-format off */
 struct cfg_group_maxfwd {
 struct cfg_group_maxfwd {
 	int max_limit;
 	int max_limit;
 };
 };
@@ -100,13 +101,13 @@ struct module_exports exports= {
 	0,
 	0,
 	0           /* per-child init function */
 	0           /* per-child init function */
 };
 };
-
+/* clang-format on */
 
 
 
 
 static int mod_init(void)
 static int mod_init(void)
 {
 {
-	if (cfg_declare("maxfwd", maxfwd_cfg_def, &default_maxfwd_cfg,
-				cfg_sizeof(maxfwd), &maxfwd_cfg)) {
+	if(cfg_declare("maxfwd", maxfwd_cfg_def, &default_maxfwd_cfg,
+			   cfg_sizeof(maxfwd), &maxfwd_cfg)) {
 		LM_ERR("failed to declare the configuration\n");
 		LM_ERR("failed to declare the configuration\n");
 		return E_CFG;
 		return E_CFG;
 	}
 	}
@@ -114,8 +115,6 @@ static int mod_init(void)
 }
 }
 
 
 
 
-
-
 /**
 /**
  * process max forward header
  * process max forward header
  */
  */
@@ -125,17 +124,17 @@ int process_maxfwd_header(struct sip_msg *msg, int limit)
 	str mf_value = {0};
 	str mf_value = {0};
 	int max_limit;
 	int max_limit;
 
 
-	if(limit<0 || limit>255) {
+	if(limit < 0 || limit > 255) {
 		LM_ERR("invalid param value: %d\n", limit);
 		LM_ERR("invalid param value: %d\n", limit);
 		return -1;
 		return -1;
 	}
 	}
 	max_limit = cfg_get(maxfwd, maxfwd_cfg, max_limit);
 	max_limit = cfg_get(maxfwd, maxfwd_cfg, max_limit);
 
 
-	val=is_maxfwd_present(msg, &mf_value);
-	switch (val) {
+	val = is_maxfwd_present(msg, &mf_value);
+	switch(val) {
 		/* header not found */
 		/* header not found */
 		case -1:
 		case -1:
-			if (add_maxfwd_header(msg, (unsigned int)limit)!=0)
+			if(add_maxfwd_header(msg, (unsigned int)limit) != 0)
 				goto error;
 				goto error;
 			return 2;
 			return 2;
 		/* error */
 		/* error */
@@ -145,11 +144,11 @@ int process_maxfwd_header(struct sip_msg *msg, int limit)
 		case 0:
 		case 0:
 			return -1;
 			return -1;
 		default:
 		default:
-			if (val>max_limit){
+			if(val > max_limit) {
 				LM_DBG("value %d decreased to %d\n", val, max_limit);
 				LM_DBG("value %d decreased to %d\n", val, max_limit);
-				val = max_limit+1;
+				val = max_limit + 1;
 			}
 			}
-			if ( decrement_maxfwd(msg, val, &mf_value)!=0 ) {
+			if(decrement_maxfwd(msg, val, &mf_value) != 0) {
 				LM_ERR("decrement failed!\n");
 				LM_ERR("decrement failed!\n");
 				goto error;
 				goto error;
 			}
 			}
@@ -163,10 +162,10 @@ error:
 /**
 /**
  *
  *
  */
  */
-static int w_process_maxfwd_header(struct sip_msg* msg, char* str1, char* str2)
+static int w_process_maxfwd_header(struct sip_msg *msg, char *str1, char *str2)
 {
 {
 	int mfval;
 	int mfval;
-	if (get_int_fparam(&mfval, msg, (fparam_t*) str1) < 0) {
+	if(get_int_fparam(&mfval, msg, (fparam_t *)str1) < 0) {
 		LM_ERR("could not get param value\n");
 		LM_ERR("could not get param value\n");
 		return -1;
 		return -1;
 	}
 	}
@@ -184,21 +183,21 @@ static int is_maxfwd_lt(struct sip_msg *msg, char *slimit, char *foo)
 	int val;
 	int val;
 
 
 	limit = (int)(long)slimit;
 	limit = (int)(long)slimit;
-	if (get_int_fparam(&limit, msg, (fparam_t*) slimit) < 0) {
+	if(get_int_fparam(&limit, msg, (fparam_t *)slimit) < 0) {
 		LM_ERR("could not get param value\n");
 		LM_ERR("could not get param value\n");
 		return -1;
 		return -1;
 	}
 	}
-	if(limit<0 || limit>255) {
+	if(limit < 0 || limit > 255) {
 		LM_ERR("invalid param value: %d\n", limit);
 		LM_ERR("invalid param value: %d\n", limit);
 		return -1;
 		return -1;
 	}
 	}
-	val = is_maxfwd_present( msg, &mf_value);
-	LM_DBG("value = %d \n",val);
+	val = is_maxfwd_present(msg, &mf_value);
+	LM_DBG("value = %d \n", val);
 
 
-	if ( val<0 ) {
+	if(val < 0) {
 		/* error or not found */
 		/* error or not found */
-		return val-1;
-	} else if ( val>=limit ) {
+		return val - 1;
+	} else if(val >= limit) {
 		/* greater or equal than/to limit */
 		/* greater or equal than/to limit */
 		return -1;
 		return -1;
 	}
 	}
@@ -211,7 +210,7 @@ static int is_maxfwd_lt(struct sip_msg *msg, char *slimit, char *foo)
  */
  */
 int bind_maxfwd(maxfwd_api_t *api)
 int bind_maxfwd(maxfwd_api_t *api)
 {
 {
-	if (!api) {
+	if(!api) {
 		ERR("Invalid parameter value\n");
 		ERR("Invalid parameter value\n");
 		return -1;
 		return -1;
 	}
 	}
@@ -224,14 +223,12 @@ int bind_maxfwd(maxfwd_api_t *api)
  *
  *
  */
  */
 static sr_kemi_t sr_kemi_maxfwd_exports[] = {
 static sr_kemi_t sr_kemi_maxfwd_exports[] = {
-	{ str_init("maxfwd"), str_init("process_maxfwd"),
-		SR_KEMIP_INT, process_maxfwd_header,
-		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
-			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
-	},
+		{str_init("maxfwd"), str_init("process_maxfwd"), SR_KEMIP_INT,
+				process_maxfwd_header,
+				{SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+						SR_KEMIP_NONE, SR_KEMIP_NONE}},
 
 
-	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
-};
+		{{0, 0}, {0, 0}, 0, NULL, {0, 0, 0, 0, 0, 0}}};
 
 
 /**
 /**
  *
  *

+ 35 - 36
src/modules/maxfwd/mf_funcs.c

@@ -34,52 +34,49 @@
 /* do a tricky thing and keep the parsed value of MAXFWD hdr incremented
 /* do a tricky thing and keep the parsed value of MAXFWD hdr incremented
  * by one in order to make difference between 0 (not set)
  * by one in order to make difference between 0 (not set)
  * and 0 (zero value) - bogdan */
  * and 0 (zero value) - bogdan */
-#define IS_MAXWD_STORED(_msg_) \
-	((_msg_)->maxforwards->parsed)
-#define STORE_MAXWD_VAL(_msg_,_val_) \
-	(_msg_)->maxforwards->parsed = ((void*)(long)((_val_)+1))
-#define FETCH_MAXWD_VAL(_msg_) \
-	(((int)(long)(_msg_)->maxforwards->parsed)-1)
+#define IS_MAXWD_STORED(_msg_) ((_msg_)->maxforwards->parsed)
+#define STORE_MAXWD_VAL(_msg_, _val_) \
+	(_msg_)->maxforwards->parsed = ((void *)(long)((_val_) + 1))
+#define FETCH_MAXWD_VAL(_msg_) (((int)(long)(_msg_)->maxforwards->parsed) - 1)
 
 
 /* looks for the MAX FORWARDS header
 /* looks for the MAX FORWARDS header
 	* returns its value, -1 if is not present or -2 for error */
 	* returns its value, -1 if is not present or -2 for error */
-int is_maxfwd_present( struct sip_msg* msg , str *foo)
+int is_maxfwd_present(struct sip_msg *msg, str *foo)
 {
 {
 	int x, err;
 	int x, err;
 
 
 	/* lookup into the message for MAX FORWARDS header*/
 	/* lookup into the message for MAX FORWARDS header*/
-	if ( !msg->maxforwards ) {
-		if  ( parse_headers( msg , HDR_MAXFORWARDS_F, 0 )==-1 ){
+	if(!msg->maxforwards) {
+		if(parse_headers(msg, HDR_MAXFORWARDS_F, 0) == -1) {
 			LM_ERR("parsing MAX_FORWARD header failed!\n");
 			LM_ERR("parsing MAX_FORWARD header failed!\n");
 			return -2;
 			return -2;
 		}
 		}
-		if (!msg->maxforwards) {
+		if(!msg->maxforwards) {
 			LM_DBG("max_forwards header not found!\n");
 			LM_DBG("max_forwards header not found!\n");
 			return -1;
 			return -1;
 		}
 		}
-	} else if (IS_MAXWD_STORED(msg)) {
-		trim_len( foo->len , foo->s , msg->maxforwards->body );
+	} else if(IS_MAXWD_STORED(msg)) {
+		trim_len(foo->len, foo->s, msg->maxforwards->body);
 		return FETCH_MAXWD_VAL(msg);
 		return FETCH_MAXWD_VAL(msg);
 	}
 	}
 
 
 	/* if header is present, trim to get only the string containing numbers */
 	/* if header is present, trim to get only the string containing numbers */
-	trim_len( foo->len , foo->s , msg->maxforwards->body );
+	trim_len(foo->len, foo->s, msg->maxforwards->body);
 
 
 	/* convert from string to number */
 	/* convert from string to number */
-	x = str2s( foo->s,foo->len,&err);
-	if (err){
+	x = str2s(foo->s, foo->len, &err);
+	if(err) {
 		LM_ERR("unable to parse the max forwards number\n");
 		LM_ERR("unable to parse the max forwards number\n");
 		return -2;
 		return -2;
 	}
 	}
 	/* store the parsed values */
 	/* store the parsed values */
 	STORE_MAXWD_VAL(msg, x);
 	STORE_MAXWD_VAL(msg, x);
-	LM_DBG("value = %d \n",x);
+	LM_DBG("value = %d \n", x);
 	return x;
 	return x;
 }
 }
 
 
 
 
-
-int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
+int decrement_maxfwd(struct sip_msg *msg, int x, str *s)
 {
 {
 	int i;
 	int i;
 
 
@@ -93,51 +90,53 @@ int decrement_maxfwd( struct sip_msg* msg , int x, str *s)
 	for(i = s->len - 1; i >= 0; i--) {
 	for(i = s->len - 1; i >= 0; i--) {
 		s->s[i] = (x % 10) + '0';
 		s->s[i] = (x % 10) + '0';
 		x /= 10;
 		x /= 10;
-		if (x==0) {
+		if(x == 0) {
 			i = i - 1;
 			i = i - 1;
 			break;
 			break;
 		}
 		}
 	}
 	}
-	while(i >= 0) s->s[i--] = ' ';
+	while(i >= 0)
+		s->s[i--] = ' ';
 
 
 	return 0;
 	return 0;
 }
 }
 
 
-int add_maxfwd_header( struct sip_msg* msg , unsigned int val )
+int add_maxfwd_header(struct sip_msg *msg, unsigned int val)
 {
 {
-	unsigned int  len;
-	char          *buf;
-	struct lump*  anchor;
+	unsigned int len;
+	char *buf;
+	struct lump *anchor;
 
 
 	/* constructing the header */
 	/* constructing the header */
-	len = MF_HDR_LEN /*"MAX-FORWARDS: "*/+ CRLF_LEN + 3/*val max on 3 digits*/;
+	len = MF_HDR_LEN /*"MAX-FORWARDS: "*/ + CRLF_LEN
+		  + 3 /*val max on 3 digits*/;
 
 
-	buf = (char*)pkg_malloc( len );
-	if (!buf) {
+	buf = (char *)pkg_malloc(len);
+	if(!buf) {
 		LM_ERR("add_maxfwd_header: no more pkg memory\n");
 		LM_ERR("add_maxfwd_header: no more pkg memory\n");
 		goto error;
 		goto error;
 	}
 	}
-	memcpy( buf , MF_HDR, MF_HDR_LEN );
-	len = MF_HDR_LEN ;
-	len += btostr( buf+len , val );
-	memcpy( buf+len , CRLF , CRLF_LEN );
-	len +=CRLF_LEN;
+	memcpy(buf, MF_HDR, MF_HDR_LEN);
+	len = MF_HDR_LEN;
+	len += btostr(buf + len, val);
+	memcpy(buf + len, CRLF, CRLF_LEN);
+	len += CRLF_LEN;
 
 
 	/*inserts the header at the beginning of the message*/
 	/*inserts the header at the beginning of the message*/
-	anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0 , 0);
-	if (anchor == 0) {
+	anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0, 0);
+	if(anchor == 0) {
 		LM_ERR("add_maxfwd_header: failed to get anchor\n");
 		LM_ERR("add_maxfwd_header: failed to get anchor\n");
 		goto error1;
 		goto error1;
 	}
 	}
 
 
-	if (insert_new_lump_before(anchor, buf, len, 0) == 0) {
+	if(insert_new_lump_before(anchor, buf, len, 0) == 0) {
 		LM_ERR("add_maxfwd_header: failed to insert MAX-FORWARDS lump\n");
 		LM_ERR("add_maxfwd_header: failed to insert MAX-FORWARDS lump\n");
 		goto error1;
 		goto error1;
 	}
 	}
 
 
 	return 0;
 	return 0;
 error1:
 error1:
-	pkg_free( buf );
+	pkg_free(buf);
 error:
 error:
 	return -1;
 	return -1;
 }
 }

+ 3 - 4
src/modules/maxfwd/mf_funcs.h

@@ -29,9 +29,8 @@
 #include "../../core/str.h"
 #include "../../core/str.h"
 
 
 
 
-int decrement_maxfwd( struct sip_msg* msg, int nr_val, str *str_val );
-int add_maxfwd_header( struct sip_msg* msg , unsigned int val );
-int is_maxfwd_present( struct sip_msg* msg, str *mf_value );
+int decrement_maxfwd(struct sip_msg *msg, int nr_val, str *str_val);
+int add_maxfwd_header(struct sip_msg *msg, unsigned int val);
+int is_maxfwd_present(struct sip_msg *msg, str *mf_value);
 
 
 #endif
 #endif
-