*
* BlueZ - Bluetooth protocol stack for Linux
*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
+ * Copyright (C) 2019-2020 Intel Corporation. All rights reserved.
*
*
*/
#include <libgen.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
-#include <sys/time.h>
-
#include <ell/ell.h>
#include <json-c/json.h>
json_object *jcfg;
char *cfg_fname;
uint8_t token[8];
- struct timeval write_time;
};
static struct mesh_db *cfg;
static const char *bak_ext = ".bak";
static const char *tmp_ext = ".tmp";
+static bool add_string(json_object *jobj, const char *desc, const char *str)
+{
+ json_object *jstring = json_object_new_string(str);
+
+ if (!jstring)
+ return false;
+
+ json_object_object_add(jobj, desc, jstring);
+ return true;
+}
+
+static bool set_timestamp(json_object *jobj)
+{
+ time_t time_raw;
+ struct tm *tp;
+ char buf[80];
+
+ time(&time_raw);
+ tp = gmtime(&time_raw);
+
+ strftime(buf, 80, "%FT%TZ", tp);
+
+ json_object_object_del(jobj, "timestamp");
+
+ return add_string(jobj, "timestamp", buf);
+}
+
static bool save_config_file(const char *fname)
{
FILE *outfile;
return false;
}
+ set_timestamp(cfg->jcfg);
+
str = json_object_to_json_string_ext(cfg->jcfg,
JSON_C_TO_STRING_PRETTY);
l_free(fname_tmp);
l_free(fname_bak);
- gettimeofday(&cfg->write_time, NULL);
-
return result;
}
return true;
}
-static bool add_string(json_object *jobj, const char *desc, const char *str)
-{
- json_object *jstring = json_object_new_string(str);
-
- if (!jstring)
- return false;
-
- json_object_object_add(jobj, desc, jstring);
- return true;
-}
-
static bool get_token(json_object *jobj, uint8_t token[8])
{
json_object *jval;
if (!write_int(jkey, "phase", KEY_REFRESH_PHASE_NONE))
goto fail;
+ if (!set_timestamp(jkey))
+ goto fail;
+
json_object_array_add(jarray, jkey);
return save_config();
json_object_array_add(jnodes, jnode);
- if (!save_config())
- goto fail;
-
- return true;
+ return save_config();
fail:
json_object_put(jnode);