mirror of
https://github.com/owntracks/recorder.git
synced 2026-05-05 02:36:45 +00:00
waypoints and config dumps are prettyfied
This commit is contained in:
27
recorder.c
27
recorder.c
@@ -327,19 +327,28 @@ static void putrec(struct udata *ud, time_t now, UT_string *reltopic, UT_string
|
||||
* via cmd `dump' to the device. Store it "pretty".
|
||||
*/
|
||||
|
||||
void config_dump(struct udata *ud, UT_string *username, UT_string *device, char *payloadstring)
|
||||
static char *prettyfy(char *payloadstring)
|
||||
{
|
||||
JsonNode *json;
|
||||
static UT_string *ts = NULL;
|
||||
char *pretty_js;
|
||||
|
||||
if ((json = json_decode(payloadstring)) == NULL) {
|
||||
olog(LOG_ERR, "Cannot decode JSON from %s", payloadstring);
|
||||
return;
|
||||
return (NULL);
|
||||
}
|
||||
pretty_js = json_stringify(json, "\t");
|
||||
json_delete(json);
|
||||
|
||||
return (pretty_js);
|
||||
}
|
||||
|
||||
void config_dump(struct udata *ud, UT_string *username, UT_string *device, char *payloadstring)
|
||||
{
|
||||
static UT_string *ts = NULL;
|
||||
char *pretty_js;
|
||||
|
||||
pretty_js = prettyfy(payloadstring);
|
||||
|
||||
utstring_renew(ts);
|
||||
|
||||
utstring_printf(ts, "%s/%s/%s/%s",
|
||||
@@ -349,6 +358,7 @@ void config_dump(struct udata *ud, UT_string *username, UT_string *device, char
|
||||
UB(device));
|
||||
if (mkpath(UB(ts)) < 0) {
|
||||
olog(LOG_ERR, "Cannot mkdir %s: %m", UB(ts));
|
||||
if (pretty_js) free(pretty_js);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -356,8 +366,8 @@ void config_dump(struct udata *ud, UT_string *username, UT_string *device, char
|
||||
if (ud->verbose) {
|
||||
printf("Received configuration dump, storing at %s\n", UB(ts));
|
||||
}
|
||||
safewrite(UB(ts), pretty_js);
|
||||
free(pretty_js);
|
||||
safewrite(UB(ts), (pretty_js) ? pretty_js : payloadstring);
|
||||
if (pretty_js) free(pretty_js);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -368,6 +378,9 @@ void config_dump(struct udata *ud, UT_string *username, UT_string *device, char
|
||||
void waypoints_dump(struct udata *ud, UT_string *username, UT_string *device, char *payloadstring)
|
||||
{
|
||||
static UT_string *ts = NULL;
|
||||
char *pretty_js;
|
||||
|
||||
pretty_js = prettyfy(payloadstring);
|
||||
|
||||
utstring_renew(ts);
|
||||
|
||||
@@ -378,6 +391,7 @@ void waypoints_dump(struct udata *ud, UT_string *username, UT_string *device, ch
|
||||
UB(device));
|
||||
if (mkpath(UB(ts)) < 0) {
|
||||
olog(LOG_ERR, "Cannot mkdir %s: %m", UB(ts));
|
||||
if (pretty_js) free(pretty_js);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -385,7 +399,8 @@ void waypoints_dump(struct udata *ud, UT_string *username, UT_string *device, ch
|
||||
if (ud->verbose) {
|
||||
printf("Received waypoints dump, storing at %s\n", UB(ts));
|
||||
}
|
||||
safewrite(UB(ts), payloadstring);
|
||||
safewrite(UB(ts), (pretty_js) ? pretty_js : payloadstring);
|
||||
if (pretty_js) free(pretty_js);
|
||||
}
|
||||
|
||||
#ifdef WITH_RONLY
|
||||
|
||||
Reference in New Issue
Block a user