@@ -25,6 +25,7 @@
#include "swupdate.h"
#include "parselib.h"
#include "swupdate_settings.h"
+#include "swupdate_dict.h"
#include "compat.h"
struct run_as {
@@ -125,3 +126,38 @@ int read_settings_user_id(const char *filename, const char *module, uid_t *useri
return 0;
}
+
+
+/*
+ * Callback to be used to put a section of configuration
+ * into a dictionary
+ */
+int settings_into_dict(void *settings, void *data)
+{
+ void *elem;
+ int count, i;
+ char name[80], value[80];
+ struct dict *dictionary = (struct dict *) data;
+
+ count = get_array_length(LIBCFG_PARSER, settings);
+
+ for(i = 0; i < count; ++i) {
+ elem = get_elem_from_idx(LIBCFG_PARSER, settings, i);
+
+ if (!elem)
+ continue;
+
+ if(!(exist_field_string(LIBCFG_PARSER, elem, "name")))
+ continue;
+ if(!(exist_field_string(LIBCFG_PARSER, elem, "value")))
+ continue;
+
+ GET_FIELD_STRING(LIBCFG_PARSER, elem, "name", name);
+ GET_FIELD_STRING(LIBCFG_PARSER, elem, "value", value);
+ dict_set_value(dictionary, name, value);
+ TRACE("Identify for configData: %s --> %s\n",
+ name, value);
+ }
+
+ return 0;
+}
@@ -11,6 +11,7 @@
#ifdef CONFIG_LIBCONFIG
int read_module_settings(const char *filename, const char *module, settings_callback fcn, void *data);
int read_settings_user_id(const char *filename, const char *module, uid_t *userid, gid_t *groupid);
+int settings_into_dict(void *settings, void *data);
#else
#include <unistd.h>
static inline int read_module_settings(const char __attribute__ ((__unused__))*filename,
@@ -33,6 +34,9 @@ static inline int read_settings_user_id(const char __attribute__ ((__unused__))*
return 0;
}
+
+static inline int settings_into_dict(void __attribute__ ((__unused__)) *settings,
+ void __attribute__ ((__unused__))*data);
#endif
#endif
@@ -1556,35 +1556,6 @@ static int suricatta_settings(void *elem, void __attribute__ ((__unused__)) *da
}
-static int suricatta_configdata_settings(void *settings, void __attribute__ ((__unused__)) *data)
-{
- void *elem;
- int count, i;
- char name[80], value[80];
-
- count = get_array_length(LIBCFG_PARSER, settings);
-
- for(i = 0; i < count; ++i) {
- elem = get_elem_from_idx(LIBCFG_PARSER, settings, i);
-
- if (!elem)
- continue;
-
- if(!(exist_field_string(LIBCFG_PARSER, elem, "name")))
- continue;
- if(!(exist_field_string(LIBCFG_PARSER, elem, "value")))
- continue;
-
- GET_FIELD_STRING(LIBCFG_PARSER, elem, "name", name);
- GET_FIELD_STRING(LIBCFG_PARSER, elem, "value", value);
- dict_set_value(&server_hawkbit.configdata, name, value);
- TRACE("Identify for configData: %s --> %s\n",
- name, value);
- }
-
- return 0;
-}
-
server_op_res_t server_start(char *fname, int argc, char *argv[])
{
update_state_t update_state = STATE_NOT_AVAILABLE;
@@ -1597,8 +1568,8 @@ server_op_res_t server_start(char *fname, int argc, char *argv[])
if (fname) {
read_module_settings(fname, "suricatta", suricatta_settings,
NULL);
- read_module_settings(fname, "identify", suricatta_configdata_settings,
- NULL);
+ read_module_settings(fname, "identify", settings_into_dict,
+ &server_hawkbit.configdata);
}
if (loglevel >= DEBUGLEVEL) {
identities are read up now by the Hawkbit connector. Factorize it and put in common code to make it available to other servers. Signed-off-by: Stefano Babic <sbabic@denx.de> --- corelib/swupdate_settings.c | 36 ++++++++++++++++++++++++++++++++++++ include/swupdate_settings.h | 4 ++++ suricatta/server_hawkbit.c | 33 ++------------------------------- 3 files changed, 42 insertions(+), 31 deletions(-)