diff mbox series

[6/8] channel_curl: remove hard dependency on JSON

Message ID 20180305154006.18122-6-christian.storm@siemens.com
State Accepted
Headers show
Series [1/8] channel_curl: add support for Basic Auth credentials | expand

Commit Message

Storm, Christian March 5, 2018, 3:40 p.m. UTC
Currently, channel_curl relies on CONFIG_JSON. However, this
is mostly only required for preparing channel_get()'s return
value as proper json_object to be consumed further.
If used for, e.g., the dowloader, such preparation is not
necessary. Hence, enclose JSON-specifics in #ifdef's.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 Kconfig                | 2 --
 corelib/channel_curl.c | 7 ++++++-
 handlers/Config.in     | 1 +
 include/channel_curl.h | 4 ++++
 suricatta/Config.in    | 1 +
 5 files changed, 12 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/Kconfig b/Kconfig
index ed5559c..1ac2b81 100644
--- a/Kconfig
+++ b/Kconfig
@@ -297,9 +297,7 @@  comment "Image downloading support needs libcurl"
 config CHANNEL_CURL
 	bool
 	depends on HAVE_LIBCURL
-	depends on HAVE_JSON_C
 	select CURL
-	select JSON
 
 config HASH_VERIFY
 	bool "Allow to add sha256 hash to each image"
diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
index 1bac778..a6e0284 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -6,6 +6,7 @@ 
  */
 
 #include <stdbool.h>
+#include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
@@ -13,7 +14,6 @@ 
 #include <unistd.h>
 #include <math.h>
 #include <curl/curl.h>
-#include <json-c/json.h>
 #include <generated/autoconf.h>
 #include <unistd.h>
 #include <network_ipc.h>
@@ -21,6 +21,9 @@ 
 #include "sslapi.h"
 #include "channel.h"
 #include "channel_curl.h"
+#ifdef CONFIG_JSON
+#include <json-c/json.h>
+#endif
 
 #define SPEED_LOW_BYTES_SEC 8
 #define SPEED_LOW_TIME_SEC 300
@@ -979,6 +982,7 @@  channel_op_res_t channel_get(channel_t *this, void *data)
 			http_response_code);
 	}
 
+#ifdef CONFIG_JSON
 	assert(channel_data->json_reply == NULL);
 	enum json_tokener_error json_res;
 	struct json_tokener *json_tokenizer = json_tokener_new();
@@ -999,6 +1003,7 @@  channel_op_res_t channel_get(channel_t *this, void *data)
 
 cleanup_json_tokenizer:
 	json_tokener_free(json_tokenizer);
+#endif
 cleanup_chunk:
 	chunk.memory != NULL ? free(chunk.memory) : (void)0;
 cleanup_header:
diff --git a/handlers/Config.in b/handlers/Config.in
index 6226b59..da1110f 100644
--- a/handlers/Config.in
+++ b/handlers/Config.in
@@ -165,6 +165,7 @@  config SWUFORWARDER_HANDLER
 	depends on HAVE_LIBCURL
 	depends on HAVE_JSON_C
 	select CHANNEL_CURL
+	select JSON
 	default n
 	help
 	  This allows to build a chain of updater. A
diff --git a/include/channel_curl.h b/include/channel_curl.h
index eec071e..13988fa 100644
--- a/include/channel_curl.h
+++ b/include/channel_curl.h
@@ -6,7 +6,9 @@ 
  */
 
 #pragma once
+#ifdef CONFIG_JSON
 #include <json-c/json.h>
+#endif
 #include <stdio.h>
 #include <stdbool.h>
 #include "sslapi.h"
@@ -33,7 +35,9 @@  typedef struct {
 	char *url;
 	char *auth;
 	char *json_string;
+#ifdef CONFIG_JSON
 	json_object *json_reply;
+#endif
 	char *cafile;
 	char *sslkey;
 	char *sslcert;
diff --git a/suricatta/Config.in b/suricatta/Config.in
index 2586169..55943c8 100644
--- a/suricatta/Config.in
+++ b/suricatta/Config.in
@@ -72,6 +72,7 @@  config SURICATTA_HAWKBIT
 	depends on HAVE_LIBCURL
 	depends on HAVE_JSON_C
 	select CHANNEL_CURL
+	select JSON
 	help
 	  Support for hawkBit server.
 	  https://projects.eclipse.org/projects/iot.hawkbit