@@ -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
new file mode 100644
@@ -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);
+}
@@ -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;
}
new file mode 100644
@@ -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);
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