diff mbox series

[4/6] suricatta: factorize function for servers

Message ID 20180920114033.31082-4-sbabic@denx.de
State Accepted
Headers show
Series [1/6] suricatta: factorize channel default values | expand

Commit Message

Stefano Babic Sept. 20, 2018, 11:40 a.m. UTC
Some function can be shared between the server's
implementation. Move them outside the Hawkbit connector
to make them available to the rest of the suricatta
module.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 suricatta/Makefile            |  2 +-
 suricatta/common.c            | 43 +++++++++++++++++++++++++++++++++++
 suricatta/server_hawkbit.c    | 24 +++----------------
 suricatta/suricatta_private.h | 14 ++++++++++++
 4 files changed, 61 insertions(+), 22 deletions(-)
 create mode 100644 suricatta/common.c
 create mode 100644 suricatta/suricatta_private.h
diff mbox series

Patch

diff --git a/suricatta/Makefile b/suricatta/Makefile
index 3b8dfa7..10d913e 100644
--- a/suricatta/Makefile
+++ b/suricatta/Makefile
@@ -1,7 +1,7 @@ 
 # Copyright (C) 2014-2018 Stefano Babic <sbabic@denx.de>
 #
 # SPDX-License-Identifier:     GPL-2.0-or-later
-lib-$(CONFIG_SURICATTA) += suricatta.o
+lib-$(CONFIG_SURICATTA) += suricatta.o common.o
 ifneq ($(CONFIG_SURICATTA_HAWKBIT),)
 lib-$(CONFIG_SURICATTA) += server_hawkbit.o
 endif
diff --git a/suricatta/common.c b/suricatta/common.c
new file mode 100644
index 0000000..a5e5e10
--- /dev/null
+++ b/suricatta/common.c
@@ -0,0 +1,43 @@ 
+/*
+ * (C) Copyright 2018
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier:     GPL-2.0-or-later
+ */
+#include <stdbool.h>
+#include <swupdate_dict.h>
+#include <channel.h>
+#include <util.h>
+#include <parselib.h>
+#include <swupdate_settings.h>
+#include <channel_curl.h>
+#include "suricatta/suricatta.h"
+#include "suricatta_private.h"
+
+void suricatta_channel_settings(void *elem, channel_data_t *chan)
+{
+	char tmp[128];
+
+	get_field(LIBCFG_PARSER, elem, "retry",
+		&chan->retries);
+
+	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "retrywait", tmp);
+	if (strlen(tmp))
+		chan->retry_sleep =
+			(unsigned int)strtoul(tmp, NULL, 10);
+	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "cafile", tmp);
+	if (strlen(tmp))
+		SETSTRING(chan->cafile, tmp);
+	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "sslkey", tmp);
+	if (strlen(tmp))
+		SETSTRING(chan->sslkey, tmp);
+	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "ciphers", tmp);
+	if (strlen(tmp))
+		SETSTRING(chan->ciphers, tmp);
+	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "sslcert", tmp);
+	if (strlen(tmp))
+		SETSTRING(chan->sslcert, tmp);
+	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "proxy", tmp);
+	if (strlen(tmp))
+		SETSTRING(chan->proxy, tmp);
+}
diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 357cf0a..b6f0407 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -20,6 +20,7 @@ 
 #include <sys/time.h>
 #include <swupdate_status.h>
 #include "suricatta/suricatta.h"
+#include "suricatta_private.h"
 #include "parselib.h"
 #include "channel.h"
 #include "channel_curl.h"
@@ -1492,34 +1493,15 @@  static int server_hawkbit_settings(void *elem, void  __attribute__ ((__unused__)
 	get_field(LIBCFG_PARSER, elem, "polldelay",
 		&server_hawkbit.polling_interval);
 
-	get_field(LIBCFG_PARSER, elem, "retry",
-		&channel_data_defaults.retries);
+	suricatta_channel_settings(elem, &channel_data_defaults);
 
-	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "retrywait", tmp);
-	if (strlen(tmp))
-		channel_data_defaults.retry_sleep =
-			(unsigned int)strtoul(tmp, NULL, 10);
-	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "cafile", tmp);
-	if (strlen(tmp))
-		SETSTRING(channel_data_defaults.cafile, tmp);
-	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "sslkey", tmp);
-	if (strlen(tmp))
-		SETSTRING(channel_data_defaults.sslkey, tmp);
-	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "ciphers", tmp);
-	if (strlen(tmp))
-		SETSTRING(channel_data_defaults.ciphers, tmp);
-	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "sslcert", tmp);
-	if (strlen(tmp))
-		SETSTRING(channel_data_defaults.sslcert, tmp);
-	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "proxy", tmp);
-	if (strlen(tmp))
-		SETSTRING(channel_data_defaults.proxy, tmp);
 	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "targettoken", tmp);
 	if (strlen(tmp))
 		SETSTRING(server_hawkbit.targettoken, tmp);
 	GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "gatewaytoken", tmp);
 	if (strlen(tmp))
 		SETSTRING(server_hawkbit.gatewaytoken, tmp);
+
 	return 0;
 
 }
diff --git a/suricatta/suricatta_private.h b/suricatta/suricatta_private.h
new file mode 100644
index 0000000..32ec2c4
--- /dev/null
+++ b/suricatta/suricatta_private.h
@@ -0,0 +1,14 @@ 
+/*
+ * (C) Copyright 2018
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier:     GPL-2.0-or-later
+ */
+
+#pragma once
+#include <stdbool.h>
+#include <swupdate_dict.h>
+#include <channel_curl.h>
+#include <util.h>
+
+void suricatta_channel_settings(void *elem, channel_data_t *chan);