浏览代码

http_client Fix formatting of source code

Olle E. Johansson 9 年之前
父节点
当前提交
38548b561f
共有 2 个文件被更改,包括 62 次插入64 次删除
  1. 16 18
      modules/http_client/functions.c
  2. 46 46
      modules/http_client/http_client.c

+ 16 - 18
modules/http_client/functions.c

@@ -82,17 +82,17 @@ size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr)
 
 
 	if (stream->max_size == 0 || stream->curr_size < stream->max_size) {
-	    char *tmp = (char *) pkg_realloc(stream->buf, stream->curr_size + (size * nmemb));
+		char *tmp = (char *) pkg_realloc(stream->buf, stream->curr_size + (size * nmemb));
 
-	    if (tmp == NULL) {
-	        LM_ERR("cannot allocate memory for stream\n");
-	        return CURLE_WRITE_ERROR;
+	    	if (tmp == NULL) {
+	        	LM_ERR("cannot allocate memory for stream\n");
+	        	return CURLE_WRITE_ERROR;
 		}
-	    stream->buf = tmp;
+	    	stream->buf = tmp;
 
 		memcpy(&stream->buf[stream->pos], (char *) ptr, (size * nmemb));
 
-	    stream->curr_size += ((size * nmemb));
+	    	stream->curr_size += ((size * nmemb));
 		stream->pos += (size * nmemb);
 
 	}  else {
@@ -321,9 +321,9 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst, const
 		if(url) {
 	    		LM_DBG("We visited URL: %s\n", url);
 			if (params->pconn) {
-			strncpy(params->pconn->redirecturl, url , sizeof(params->pconn->redirecturl));
-		}
-	    }
+				strncpy(params->pconn->redirecturl, url , sizeof(params->pconn->redirecturl));
+			}
+	    	}
 	}
 	if (params->pconn) {
 		params->pconn->last_result = stat;
@@ -379,7 +379,7 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst, const
 		curl_easy_cleanup(curl);
 	}
 	if (stream.buf != NULL) {
-	    pkg_free(stream.buf);
+		pkg_free(stream.buf);
 	}
 	return stat;
 }
@@ -455,8 +455,7 @@ int curl_con_query_url(struct sip_msg* _m, const str *connection, const str* url
 	if (url && (url->len > 0) && (url->s != NULL)) {
 		int url_len = conn->schema.len + 3 + conn->url.len + 1 + url->len + 1;
 		urlbuf = pkg_malloc(url_len);
-		if (urlbuf == NULL)
-		{
+		if (urlbuf == NULL) {
 			res = -1;
 			goto error;
 		}
@@ -468,8 +467,7 @@ int curl_con_query_url(struct sip_msg* _m, const str *connection, const str* url
 	} else {
 		int url_len = conn->schema.len + 3 + conn->url.len + 1;
 		urlbuf = pkg_malloc(url_len);
-		if (urlbuf == NULL)
-		{
+		if (urlbuf == NULL) {
 			res = -1;
 			goto error;
 		}
@@ -484,10 +482,10 @@ int curl_con_query_url(struct sip_msg* _m, const str *connection, const str* url
 		/* Allocated using pkg_memory */
 		postdata = as_asciiz((str*)post);
 		if (postdata  == NULL) {
-	    	    ERR("Curl: No memory left\n");
-		    res = -1;
-		    goto error;
-	            }
+	    	    	ERR("Curl: No memory left\n");
+		    	res = -1;
+		    	goto error;
+	        }
 		LM_DBG("***** #### ***** CURL POST data: %s Content-type %s\n", postdata, contenttype);
 	}
 

+ 46 - 46
modules/http_client/http_client.c

@@ -164,7 +164,7 @@ static param_export_t params[] = {
 	{"httpcon",  PARAM_STRING|USE_FUNC_PARAM, (void*)curl_con_param},
 	{"authmetod", PARAM_INT, &default_authmethod },
 	{"keep_connections", PARAM_INT, &default_keep_connections },
-    	{0, 0, 0}
+	{0, 0, 0}
 };
 
 
@@ -172,26 +172,26 @@ static param_export_t params[] = {
  * \brief Exported Pseudo variables
  */
 static pv_export_t mod_pvs[] = {
-    {{"curlerror", (sizeof("curlerror")-1)}, /* Curl error codes */
-     PVT_OTHER, pv_get_curlerror, 0, pv_parse_curlerror, 0, 0, 0},
+	{{"curlerror", (sizeof("curlerror")-1)}, /* Curl error codes */
+	PVT_OTHER, pv_get_curlerror, 0, pv_parse_curlerror, 0, 0, 0},
 
-    {{0, 0}, 0, 0, 0, 0, 0, 0, 0}
+	{{0, 0}, 0, 0, 0, 0, 0, 0, 0}
 };
 
 /* Module interface */
 struct module_exports exports = {
-    "http_client",
-    DEFAULT_DLFLAGS, /* dlopen flags */
-    cmds,      /* Exported functions */
-    params,    /* Exported parameters */
-    0,         /* exported statistics */
-    0,   	/* exported MI functions */
-    mod_pvs,         /* exported pseudo-variables */
-    0,         /* extra processes */
-    mod_init,  /* module initialization function */
-    0,         /* response function*/
-    destroy,   /* destroy function */
-    child_init /* per-child init function */
+	"http_client",
+	DEFAULT_DLFLAGS, /* dlopen flags */
+	cmds,      /* Exported functions */
+	params,    /* Exported parameters */
+	0,         /* exported statistics */
+	0,   	/* exported MI functions */
+	mod_pvs,         /* exported pseudo-variables */
+	0,         /* extra processes */
+	mod_init,  /* module initialization function */
+	0,         /* response function*/
+	destroy,   /* destroy function */
+	child_init /* per-child init function */
 };
 
 counter_handle_t connections;	/* Number of connection definitions */
@@ -350,24 +350,24 @@ error:
  */
 static int fixup_http_query_get(void** param, int param_no)
 {
-    if (param_no == 1) {
-	return fixup_spve_null(param, 1);
-    }
-
-    if (param_no == 2) {
-	if (fixup_pvar_null(param, 1) != 0) {
-	    LM_ERR("failed to fixup result pvar\n");
-	    return -1;
+	if (param_no == 1) {
+		return fixup_spve_null(param, 1);
 	}
-	if (((pv_spec_t *)(*param))->setf == NULL) {
-	    LM_ERR("result pvar is not writeble\n");
-	    return -1;
+
+	if (param_no == 2) {
+		if (fixup_pvar_null(param, 1) != 0) {
+			LM_ERR("failed to fixup result pvar\n");
+			return -1;
+		}
+		if (((pv_spec_t *)(*param))->setf == NULL) {
+			LM_ERR("result pvar is not writeble\n");
+			return -1;
+		}
+		return 0;
 	}
-	return 0;
-    }
 
-    LM_ERR("invalid parameter number <%d>\n", param_no);
-    return -1;
+	LM_ERR("invalid parameter number <%d>\n", param_no);
+	return -1;
 }
 
 /*
@@ -376,7 +376,7 @@ static int fixup_http_query_get(void** param, int param_no)
 static int fixup_free_http_query_get(void** param, int param_no)
 {
     if (param_no == 1) {
-        return fixup_free_spve_null(param, 1);
+		return fixup_free_spve_null(param, 1);
     }
 
     if (param_no == 2) {
@@ -401,7 +401,7 @@ static int fixup_curl_connect(void** param, int param_no)
     }
     /* URL and data may contain pvar */
     if (param_no == 2) {
-        return fixup_spve_null(param, 1);
+		return fixup_spve_null(param, 1);
     }
     if (param_no == 3) {
 	if (fixup_pvar_null(param, 1) != 0) {
@@ -433,7 +433,7 @@ static int fixup_curl_connect_post(void** param, int param_no)
     }
     /* URL and data may contain pvar */
     if (param_no == 2 || param_no == 4) {
-        return fixup_spve_null(param, 1);
+		return fixup_spve_null(param, 1);
     }
     if (param_no == 5) {
 	if (fixup_pvar_null(param, 1) != 0) {
@@ -462,7 +462,7 @@ static int fixup_free_curl_connect_post(void** param, int param_no)
 	return 0;
     }
     if (param_no == 2 || param_no == 4) {
-        return fixup_free_spve_null(param, 1);
+		return fixup_free_spve_null(param, 1);
     }
 
     if (param_no == 5) {
@@ -483,7 +483,7 @@ static int fixup_free_curl_connect(void** param, int param_no)
 	return 0;
     }
     if (param_no == 2) {
-        return fixup_free_spve_null(param, 1);
+		return fixup_free_spve_null(param, 1);
     }
 
     if (param_no == 3) {
@@ -607,7 +607,7 @@ static int fixup_http_query_post(void** param, int param_no)
 static int fixup_free_http_query_post(void** param, int param_no)
 {
     if ((param_no == 1) || (param_no == 2)) {
-        return fixup_free_spve_null(param, 1);
+		return fixup_free_spve_null(param, 1);
     }
 
     if (param_no == 3) {
@@ -757,16 +757,16 @@ static int fixup_curl_get_redirect(void** param, int param_no)
  */
 static int fixup_free_curl_get_redirect(void** param, int param_no)
 {
-    if (param_no == 1) {
-	/* Char strings don't need freeing */
-	return 0;
-    }
-    if (param_no == 2) {
-        return fixup_free_spve_null(param, 1);
-    }
+	if (param_no == 1) {
+		/* Char strings don't need freeing */
+		return 0;
+	}
+	if (param_no == 2) {
+		return fixup_free_spve_null(param, 1);
+	}
 
-    LM_ERR("invalid parameter number <%d>\n", param_no);
-    return -1;
+	LM_ERR("invalid parameter number <%d>\n", param_no);
+	return -1;
 }
 
 /*