mirror of
https://git.proxmox.com/git/fwupd
synced 2025-07-27 11:09:28 +00:00
trivial: libfwupd: move some duplicated code to fwupd-common
Several of the string/integer/time functions are duplicated in multiple source files for no discernable reason. Move them into fwupd-common as private symbols instead.
This commit is contained in:
parent
8ba0f7d895
commit
17c636686d
@ -51,4 +51,11 @@ GUnixInputStream *
|
||||
fwupd_unix_input_stream_from_fn(const gchar *fn, GError **error) G_GNUC_WARN_UNUSED_RESULT;
|
||||
#endif
|
||||
|
||||
void
|
||||
fwupd_pad_kv_unx(GString *str, const gchar *key, guint64 value);
|
||||
void
|
||||
fwupd_pad_kv_str(GString *str, const gchar *key, const gchar *value);
|
||||
void
|
||||
fwupd_pad_kv_int(GString *str, const gchar *key, guint32 value);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -1220,3 +1220,51 @@ fwupd_common_json_add_stringv(JsonBuilder *builder, const gchar *key, gchar **va
|
||||
json_builder_add_string_value(builder, value[i]);
|
||||
json_builder_end_array(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* fwupd_pad_kv_str: (skip):
|
||||
**/
|
||||
void
|
||||
fwupd_pad_kv_str(GString *str, const gchar *key, const gchar *value)
|
||||
{
|
||||
/* ignore */
|
||||
if (key == NULL || value == NULL)
|
||||
return;
|
||||
g_string_append_printf(str, " %s: ", key);
|
||||
for (gsize i = strlen(key); i < 20; i++)
|
||||
g_string_append(str, " ");
|
||||
g_string_append_printf(str, "%s\n", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* fwupd_pad_kv_unx: (skip):
|
||||
**/
|
||||
void
|
||||
fwupd_pad_kv_unx(GString *str, const gchar *key, guint64 value)
|
||||
{
|
||||
g_autoptr(GDateTime) date = NULL;
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
|
||||
date = g_date_time_new_from_unix_utc((gint64)value);
|
||||
tmp = g_date_time_format(date, "%F");
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* fwupd_pad_kv_int: (skip):
|
||||
**/
|
||||
void
|
||||
fwupd_pad_kv_int(GString *str, const gchar *key, guint32 value)
|
||||
{
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
tmp = g_strdup_printf("%" G_GUINT32_FORMAT, value);
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
@ -2446,33 +2446,6 @@ fwupd_device_from_key_value(FwupdDevice *self, const gchar *key, GVariant *value
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_str(GString *str, const gchar *key, const gchar *value)
|
||||
{
|
||||
/* ignore */
|
||||
if (key == NULL || value == NULL)
|
||||
return;
|
||||
g_string_append_printf(str, " %s: ", key);
|
||||
for (gsize i = strlen(key); i < 20; i++)
|
||||
g_string_append(str, " ");
|
||||
g_string_append_printf(str, "%s\n", value);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_unx(GString *str, const gchar *key, guint64 value)
|
||||
{
|
||||
g_autoptr(GDateTime) date = NULL;
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
|
||||
date = g_date_time_new_from_unix_utc((gint64)value);
|
||||
tmp = g_date_time_format(date, "%F");
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_dfl(GString *str, const gchar *key, guint64 device_flags)
|
||||
{
|
||||
@ -2507,18 +2480,6 @@ fwupd_device_pad_kv_problems(GString *str, const gchar *key, guint64 device_prob
|
||||
fwupd_pad_kv_str(str, key, tmp->str);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_int(GString *str, const gchar *key, guint32 value)
|
||||
{
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
tmp = g_strdup_printf("%" G_GUINT32_FORMAT, value);
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* fwupd_device_get_update_state:
|
||||
* @self: a #FwupdDevice
|
||||
|
@ -225,18 +225,6 @@ fwupd_plugin_from_key_value(FwupdPlugin *self, const gchar *key, GVariant *value
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_str(GString *str, const gchar *key, const gchar *value)
|
||||
{
|
||||
/* ignore */
|
||||
if (key == NULL || value == NULL)
|
||||
return;
|
||||
g_string_append_printf(str, " %s: ", key);
|
||||
for (gsize i = strlen(key); i < 20; i++)
|
||||
g_string_append(str, " ");
|
||||
g_string_append_printf(str, "%s\n", value);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_dfl(GString *str, const gchar *key, guint64 plugin_flags)
|
||||
{
|
||||
|
@ -1942,33 +1942,6 @@ fwupd_release_from_key_value(FwupdRelease *self, const gchar *key, GVariant *val
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_str(GString *str, const gchar *key, const gchar *value)
|
||||
{
|
||||
/* ignore */
|
||||
if (key == NULL || value == NULL)
|
||||
return;
|
||||
g_string_append_printf(str, " %s: ", key);
|
||||
for (gsize i = strlen(key); i < 20; i++)
|
||||
g_string_append(str, " ");
|
||||
g_string_append_printf(str, "%s\n", value);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_unx(GString *str, const gchar *key, guint64 value)
|
||||
{
|
||||
g_autoptr(GDateTime) date = NULL;
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
|
||||
date = g_date_time_new_from_unix_utc((gint64)value);
|
||||
tmp = g_date_time_format(date, "%F");
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_siz(GString *str, const gchar *key, guint64 value)
|
||||
{
|
||||
@ -1998,18 +1971,6 @@ fwupd_pad_kv_tfl(GString *str, const gchar *key, FwupdReleaseFlags release_flags
|
||||
fwupd_pad_kv_str(str, key, tmp->str);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_int(GString *str, const gchar *key, guint32 value)
|
||||
{
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
tmp = g_strdup_printf("%" G_GUINT32_FORMAT, value);
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* fwupd_release_to_json:
|
||||
* @self: a #FwupdRelease
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "fwupd-common-private.h"
|
||||
#include "fwupd-enums-private.h"
|
||||
#include "fwupd-request-private.h"
|
||||
|
||||
@ -280,33 +281,6 @@ fwupd_request_from_key_value(FwupdRequest *self, const gchar *key, GVariant *val
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_str(GString *str, const gchar *key, const gchar *value)
|
||||
{
|
||||
/* ignore */
|
||||
if (key == NULL || value == NULL)
|
||||
return;
|
||||
g_string_append_printf(str, " %s: ", key);
|
||||
for (gsize i = strlen(key); i < 20; i++)
|
||||
g_string_append(str, " ");
|
||||
g_string_append_printf(str, "%s\n", value);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_unx(GString *str, const gchar *key, guint64 value)
|
||||
{
|
||||
g_autoptr(GDateTime) date = NULL;
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
|
||||
date = g_date_time_new_from_unix_utc((gint64)value);
|
||||
tmp = g_date_time_format(date, "%F");
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* fwupd_request_get_message:
|
||||
* @self: a #FwupdRequest
|
||||
|
@ -1086,18 +1086,6 @@ fwupd_security_attr_from_key_value(FwupdSecurityAttr *self, const gchar *key, GV
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_str(GString *str, const gchar *key, const gchar *value)
|
||||
{
|
||||
/* ignore */
|
||||
if (key == NULL || value == NULL)
|
||||
return;
|
||||
g_string_append_printf(str, " %s: ", key);
|
||||
for (gsize i = strlen(key); i < 20; i++)
|
||||
g_string_append(str, " ");
|
||||
g_string_append_printf(str, "%s\n", value);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_tfl(GString *str, const gchar *key, FwupdSecurityAttrFlags security_attr_flags)
|
||||
{
|
||||
@ -1117,18 +1105,6 @@ fwupd_pad_kv_tfl(GString *str, const gchar *key, FwupdSecurityAttrFlags security
|
||||
fwupd_pad_kv_str(str, key, tmp->str);
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_int(GString *str, const gchar *key, guint32 value)
|
||||
{
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
tmp = g_strdup_printf("%" G_GUINT32_FORMAT, value);
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* fwupd_security_attr_from_json:
|
||||
* @self: a #FwupdSecurityAttr
|
||||
@ -1298,21 +1274,6 @@ fwupd_security_attr_to_json(FwupdSecurityAttr *self, JsonBuilder *builder)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fwupd_pad_kv_unx(GString *str, const gchar *key, guint64 value)
|
||||
{
|
||||
g_autoptr(GDateTime) date = NULL;
|
||||
g_autofree gchar *tmp = NULL;
|
||||
|
||||
/* ignore */
|
||||
if (value == 0)
|
||||
return;
|
||||
|
||||
date = g_date_time_new_from_unix_utc((gint64)value);
|
||||
tmp = g_date_time_format(date, "%F");
|
||||
fwupd_pad_kv_str(str, key, tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* fwupd_security_attr_to_string:
|
||||
* @self: a #FwupdSecurityAttr
|
||||
|
Loading…
Reference in New Issue
Block a user