mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-10-03 23:38:25 +00:00
json: Making formatter_json API more independent
Only export functions that make sense to be used externally and move function to set/unset json out of the formatter. Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
@@ -63,6 +63,17 @@ static bool quiet = false;
|
||||
static bool debug = false;
|
||||
static bool verbose = false;
|
||||
|
||||
static void set_json_format(bool on)
|
||||
{
|
||||
if (on) {
|
||||
log_set_function(log_json);
|
||||
progress_set_format(json_progress, json_start, json_end);
|
||||
} else {
|
||||
log_set_function(NULL);
|
||||
progress_set_format(NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* Sets the content_url global variable */
|
||||
static void set_content_url(char *url)
|
||||
{
|
||||
|
||||
+18
-30
@@ -25,14 +25,8 @@
|
||||
#include "formatter_json.h"
|
||||
#include "log.h"
|
||||
#include "macros.h"
|
||||
#include "progress.h"
|
||||
#include "strings.h"
|
||||
|
||||
static void log_json(FILE *out UNUSED_PARAM, const char *file UNUSED_PARAM, int line UNUSED_PARAM, const char *label, const char *format, va_list args_list)
|
||||
{
|
||||
json_message(label, format, args_list);
|
||||
}
|
||||
|
||||
static void json_sanitize_string(char *full_msg)
|
||||
{
|
||||
int i;
|
||||
@@ -55,30 +49,7 @@ static void json_sanitize_string(char *full_msg)
|
||||
}
|
||||
}
|
||||
|
||||
void set_json_format(bool on)
|
||||
{
|
||||
if (on) {
|
||||
log_set_function(log_json);
|
||||
progress_set_format(json_progress, json_start, json_end);
|
||||
} else {
|
||||
log_set_function(NULL);
|
||||
progress_set_format(NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void json_start(const char *op)
|
||||
{
|
||||
fprintf(stdout, "[\n{ \"type\" : \"start\", \"section\" : \"%s\" },\n", op);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void json_end(const char *op, int status)
|
||||
{
|
||||
fprintf(stdout, "{ \"type\" : \"end\", \"section\" : \"%s\", \"status\" : %d }\n]\n", op, status);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void json_message(const char *msg_type, const char *msg, va_list args_list)
|
||||
static void json_message(const char *msg_type, const char *msg, va_list args_list)
|
||||
{
|
||||
char *full_msg;
|
||||
char *type = NULL;
|
||||
@@ -107,6 +78,23 @@ void json_message(const char *msg_type, const char *msg, va_list args_list)
|
||||
}
|
||||
}
|
||||
|
||||
void json_start(const char *op)
|
||||
{
|
||||
fprintf(stdout, "[\n{ \"type\" : \"start\", \"section\" : \"%s\" },\n", op);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void json_end(const char *op, int status)
|
||||
{
|
||||
fprintf(stdout, "{ \"type\" : \"end\", \"section\" : \"%s\", \"status\" : %d }\n]\n", op, status);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void log_json(FILE *out UNUSED_PARAM, const char *file UNUSED_PARAM, int line UNUSED_PARAM, const char *label, const char *format, va_list args_list)
|
||||
{
|
||||
json_message(label, format, args_list);
|
||||
}
|
||||
|
||||
void json_progress(const char *step_description, unsigned int current_step, unsigned int total_steps, int percentage)
|
||||
{
|
||||
fprintf(stdout, "{ \"type\" : \"progress\", "
|
||||
|
||||
@@ -13,11 +13,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables/Disables the JSON formatter
|
||||
*/
|
||||
void set_json_format(bool on);
|
||||
|
||||
/**
|
||||
* @brief Generates the initial message of a JSON stream
|
||||
*/
|
||||
@@ -29,9 +24,9 @@ void json_start(const char *);
|
||||
void json_end(const char *, int);
|
||||
|
||||
/**
|
||||
* @brief Converts the provided message to a JSON stream
|
||||
* @brief Log message using Json format
|
||||
*/
|
||||
void json_message(const char *, const char *, va_list);
|
||||
void log_json(FILE *out, const char *file, int line, const char *label, const char *format, va_list args_list);
|
||||
|
||||
/**
|
||||
* @brief Prints the progress of a given step into the JSON stream
|
||||
|
||||
Reference in New Issue
Block a user