diff mbox series

[04/14] channel_curl: Factor out channel reply log handling

Message ID 20200914145712.4989-4-christian.storm@siemens.com
State Accepted
Headers show
Series [01/14] channel_curl: Make setting request_body symmetric | expand

Commit Message

Storm, Christian Sept. 14, 2020, 2:57 p.m. UTC
Factor out channel reply log handling so that other channel
methods like, e.g. channel_post_method() can use it.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 corelib/channel_curl.c | 46 +++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 19 deletions(-)

Comments

Stefano Babic Sept. 17, 2020, 1:40 p.m. UTC | #1
On 14.09.20 16:57, Christian Storm wrote:
> Factor out channel reply log handling so that other channel
> methods like, e.g. channel_post_method() can use it.
> 
> Signed-off-by: Christian Storm <christian.storm@siemens.com>
> ---
>  corelib/channel_curl.c | 46 +++++++++++++++++++++++++-----------------
>  1 file changed, 27 insertions(+), 19 deletions(-)
> 
> diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
> index 4747107..4737037 100644
> --- a/corelib/channel_curl.c
> +++ b/corelib/channel_curl.c
> @@ -712,6 +712,29 @@ static size_t put_read_callback(void *ptr, size_t size, size_t nmemb, void *data
>  	return n;
>  }
>  
> +static void channel_log_reply(channel_op_res_t result, channel_data_t *channel_data,
> +			      output_data_t *chunk)
> +{
> +	if (result != CHANNEL_OK) {
> +		ERROR("Channel operation returned HTTP error code %ld.",
> +			channel_data->http_response_code);
> +		switch (channel_data->http_response_code) {
> +			case 403:
> +			case 404:
> +			case 500:
> +				DEBUG("The error message is: '%s'", chunk->memory);
> +				break;
> +			default:
> +				break;
> +		}
> +		return;
> +	}
> +	if (channel_data->debug) {
> +		TRACE("Channel operation returned HTTP status code %ld.",
> +		      channel_data->http_response_code);
> +	}
> +}
> +
>  static channel_op_res_t setup_reply_buffer(CURL *handle, write_callback_t *wrdata)
>  {
>  	wrdata->outdata->memory = NULL;
> @@ -1141,26 +1164,11 @@ channel_op_res_t channel_get(channel_t *this, void *data)
>  	if (channel_data->nocheckanswer)
>  		goto cleanup_header;
>  
> -	if (result != CHANNEL_OK) {
> -		ERROR("Channel operation returned HTTP error code %ld.",
> -		      channel_data->http_response_code);
> -		switch (channel_data->http_response_code) {
> -			case 403:
> -			case 404:
> -			case 500:
> -				DEBUG("The error's message is: '%s'\n", outdata.memory);
> -				break;
> -			default:
> -				break;
> -		}
> -		goto cleanup_header;
> -	}
> -	if (channel_data->debug) {
> -		TRACE("Channel operation returned HTTP status code %ld.",
> -			channel_data->http_response_code);
> -	}
> +	channel_log_reply(result, channel_data, &outdata);
>  
> -	result = parse_reply(channel_data, &outdata);
> +	if (result == CHANNEL_OK) {
> +	    result = parse_reply(channel_data, &outdata);
> +	}
>  
>  cleanup_header:
>  	outdata.memory != NULL ? free(outdata.memory) : (void)0;
> 

Reviewed-by: Stefano Babic <ababic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
index 4747107..4737037 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -712,6 +712,29 @@  static size_t put_read_callback(void *ptr, size_t size, size_t nmemb, void *data
 	return n;
 }
 
+static void channel_log_reply(channel_op_res_t result, channel_data_t *channel_data,
+			      output_data_t *chunk)
+{
+	if (result != CHANNEL_OK) {
+		ERROR("Channel operation returned HTTP error code %ld.",
+			channel_data->http_response_code);
+		switch (channel_data->http_response_code) {
+			case 403:
+			case 404:
+			case 500:
+				DEBUG("The error message is: '%s'", chunk->memory);
+				break;
+			default:
+				break;
+		}
+		return;
+	}
+	if (channel_data->debug) {
+		TRACE("Channel operation returned HTTP status code %ld.",
+		      channel_data->http_response_code);
+	}
+}
+
 static channel_op_res_t setup_reply_buffer(CURL *handle, write_callback_t *wrdata)
 {
 	wrdata->outdata->memory = NULL;
@@ -1141,26 +1164,11 @@  channel_op_res_t channel_get(channel_t *this, void *data)
 	if (channel_data->nocheckanswer)
 		goto cleanup_header;
 
-	if (result != CHANNEL_OK) {
-		ERROR("Channel operation returned HTTP error code %ld.",
-		      channel_data->http_response_code);
-		switch (channel_data->http_response_code) {
-			case 403:
-			case 404:
-			case 500:
-				DEBUG("The error's message is: '%s'\n", outdata.memory);
-				break;
-			default:
-				break;
-		}
-		goto cleanup_header;
-	}
-	if (channel_data->debug) {
-		TRACE("Channel operation returned HTTP status code %ld.",
-			channel_data->http_response_code);
-	}
+	channel_log_reply(result, channel_data, &outdata);
 
-	result = parse_reply(channel_data, &outdata);
+	if (result == CHANNEL_OK) {
+	    result = parse_reply(channel_data, &outdata);
+	}
 
 cleanup_header:
 	outdata.memory != NULL ? free(outdata.memory) : (void)0;