Coverage Report

Created: 2026-01-16 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fwupd/libfwupdplugin/fu-cab-image.c
Line
Count
Source
1
/*
2
 * Copyright 2023 Richard Hughes <richard@hughsie.com>
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
7
0
#define G_LOG_DOMAIN "FuCabFirmware"
8
9
#include "config.h"
10
11
#include "fu-cab-image.h"
12
#include "fu-common.h"
13
14
struct _FuCabImage {
15
  FuFirmware parent_instance;
16
  gchar *win32_filename;
17
  GDateTime *created;
18
};
19
20
41.7k
G_DEFINE_TYPE(FuCabImage, fu_cab_image, FU_TYPE_FIRMWARE)
21
41.7k
22
41.7k
/**
23
41.7k
 * fu_cab_image_get_win32_filename:
24
41.7k
 * @self: a #FuCabImage
25
41.7k
 *
26
41.7k
 * Gets the in-archive Windows filename, with a possible path component -- creating from the
27
41.7k
 * firmware ID if required.
28
41.7k
 *
29
41.7k
 * Returns: filename, or %NULL
30
41.7k
 *
31
41.7k
 * Since: 1.9.7
32
41.7k
 **/
33
41.7k
const gchar *
34
41.7k
fu_cab_image_get_win32_filename(FuCabImage *self)
35
41.7k
{
36
144
  g_return_val_if_fail(FU_IS_CAB_IMAGE(self), NULL);
37
38
  /* generate from the id */
39
144
  if (self->win32_filename == NULL) {
40
144
    g_autoptr(GString) str = g_string_new(fu_firmware_get_id(FU_FIRMWARE(self)));
41
144
    g_string_replace(str, "/", "\\", 0);
42
144
    if (str->len == 0)
43
12
      return NULL;
44
132
    fu_cab_image_set_win32_filename(self, str->str);
45
132
  }
46
47
132
  return self->win32_filename;
48
144
}
49
50
/**
51
 * fu_cab_image_set_win32_filename:
52
 * @self: a #FuCabImage
53
 * @win32_filename: filename, or %NULL
54
 *
55
 * Sets the in-archive Windows filename, with a possible path component.
56
 *
57
 * Since: 1.9.7
58
 **/
59
void
60
fu_cab_image_set_win32_filename(FuCabImage *self, const gchar *win32_filename)
61
132
{
62
132
  g_return_if_fail(FU_IS_CAB_IMAGE(self));
63
132
  g_free(self->win32_filename);
64
132
  self->win32_filename = g_strdup(win32_filename);
65
132
}
66
67
/**
68
 * fu_cab_image_get_created:
69
 * @self: a #FuCabImage
70
 *
71
 * Gets the created timestamp.
72
 *
73
 * Returns: (transfer none): a #GDateTime, or %NULL
74
 *
75
 * Since: 1.9.7
76
 **/
77
GDateTime *
78
fu_cab_image_get_created(FuCabImage *self)
79
0
{
80
0
  g_return_val_if_fail(FU_IS_CAB_IMAGE(self), NULL);
81
0
  return self->created;
82
0
}
83
84
/**
85
 * fu_cab_image_set_created:
86
 * @self: a #FuCabImage
87
 * @created: a #GDateTime, or %NULL
88
 *
89
 * Sets the created timestamp.
90
 *
91
 * Since: 1.9.7
92
 **/
93
void
94
fu_cab_image_set_created(FuCabImage *self, GDateTime *created)
95
12.4k
{
96
12.4k
  g_return_if_fail(FU_IS_CAB_IMAGE(self));
97
12.4k
  if (self->created != NULL) {
98
0
    g_date_time_unref(self->created);
99
0
    self->created = NULL;
100
0
  }
101
12.4k
  if (created != NULL)
102
6.77k
    self->created = g_date_time_ref(created);
103
12.4k
}
104
105
static gboolean
106
fu_cab_image_build(FuFirmware *firmware, XbNode *n, GError **error)
107
0
{
108
0
  FuCabImage *self = FU_CAB_IMAGE(firmware);
109
0
  const gchar *tmp;
110
111
  /* simple properties */
112
0
  tmp = xb_node_query_text(n, "win32_filename", NULL);
113
0
  if (tmp != NULL)
114
0
    fu_cab_image_set_win32_filename(self, tmp);
115
0
  tmp = xb_node_query_text(n, "created", NULL);
116
0
  if (tmp != NULL) {
117
0
    g_autoptr(GDateTime) created = g_date_time_new_from_iso8601(tmp, NULL);
118
0
    if (created == NULL) {
119
0
      g_set_error(error,
120
0
            FWUPD_ERROR,
121
0
            FWUPD_ERROR_INVALID_DATA,
122
0
            "not iso8601: %s",
123
0
            tmp);
124
0
      return FALSE;
125
0
    }
126
0
    fu_cab_image_set_created(self, created);
127
0
  }
128
129
  /* success */
130
0
  return TRUE;
131
0
}
132
133
static void
134
fu_cab_image_export(FuFirmware *firmware, FuFirmwareExportFlags flags, XbBuilderNode *bn)
135
0
{
136
0
  FuCabImage *self = FU_CAB_IMAGE(firmware);
137
0
  fu_xmlb_builder_insert_kv(bn, "win32_filename", self->win32_filename);
138
0
  if (self->created != NULL) {
139
0
    g_autofree gchar *str = g_date_time_format_iso8601(self->created);
140
0
    fu_xmlb_builder_insert_kv(bn, "created", str);
141
0
  }
142
0
}
143
144
static void
145
fu_cab_image_finalize(GObject *object)
146
13.0k
{
147
13.0k
  FuCabImage *self = FU_CAB_IMAGE(object);
148
13.0k
  g_free(self->win32_filename);
149
13.0k
  if (self->created != NULL)
150
6.77k
    g_date_time_unref(self->created);
151
13.0k
  G_OBJECT_CLASS(fu_cab_image_parent_class)->finalize(object);
152
13.0k
}
153
154
static void
155
fu_cab_image_class_init(FuCabImageClass *klass)
156
1
{
157
1
  FuFirmwareClass *firmware_class = FU_FIRMWARE_CLASS(klass);
158
1
  GObjectClass *object_class = G_OBJECT_CLASS(klass);
159
1
  object_class->finalize = fu_cab_image_finalize;
160
1
  firmware_class->build = fu_cab_image_build;
161
1
  firmware_class->export = fu_cab_image_export;
162
1
}
163
164
static void
165
fu_cab_image_init(FuCabImage *self)
166
13.0k
{
167
13.0k
}
168
169
/**
170
 * fu_cab_image_new:
171
 *
172
 * Returns: (transfer full): a #FuCabImage
173
 *
174
 * Since: 1.9.7
175
 **/
176
FuCabImage *
177
fu_cab_image_new(void)
178
13.0k
{
179
13.0k
  return g_object_new(FU_TYPE_CAB_IMAGE, NULL);
180
13.0k
}