blob: 040650e3465fdb3cf2ad5734c522db4133f04d2a [file] [log] [blame]
Richard Hughes02c90d82018-08-09 12:13:03 +01001/*
Richard Hughes943d2c92017-06-21 09:04:39 +01002 * Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
3 *
Mario Limonciello51308e62018-05-28 20:05:46 -05004 * SPDX-License-Identifier: LGPL-2.1+
Richard Hughes943d2c92017-06-21 09:04:39 +01005 */
6
Richard Hughesbfd946e2019-02-09 08:21:40 +00007#pragma once
Richard Hughes943d2c92017-06-21 09:04:39 +01008
Richard Hughesadc9dad2017-09-04 13:19:27 +01009#include <gio/gio.h>
Richard Hughes943d2c92017-06-21 09:04:39 +010010
Richard Hughes2d3287a2019-02-10 17:32:14 +000011G_BEGIN_DECLS
12
Mario Limonciello39602652019-04-29 21:08:58 -050013/**
14 * FuAppFlags:
15 * @FU_APP_FLAGS_NONE: No flags set
16 * @FU_APP_FLAGS_NO_IDLE_SOURCES: Disallow idle sources
Mario Limonciello39602652019-04-29 21:08:58 -050017 *
18 * The flags to use when loading an application.
19 **/
Richard Hughes5b5f6552018-05-18 10:22:39 +010020typedef enum {
21 FU_APP_FLAGS_NONE = 0,
22 FU_APP_FLAGS_NO_IDLE_SOURCES = 1 << 0,
Mario Limonciello39602652019-04-29 21:08:58 -050023 /*< private >*/
Richard Hughes5b5f6552018-05-18 10:22:39 +010024 FU_APP_FLAGS_LAST
25} FuAppFlags;
26
Mario Limonciello39602652019-04-29 21:08:58 -050027/**
28 * FuDumpFlags:
29 * @FU_DUMP_FLAGS_NONE: No flags set
30 * @FU_DUMP_FLAGS_SHOW_ASCII: Show ASCII in debugging dumps
31 * @FU_DUMP_FLAGS_SHOW_ADDRESSES: Show addresses in debugging dumps
32 *
33 * The flags to use when configuring debugging
34 **/
Richard Hughes4be17d12018-05-30 20:36:29 +010035typedef enum {
Richard Hughes35481862019-01-06 12:01:58 +000036 FU_DUMP_FLAGS_NONE = 0,
37 FU_DUMP_FLAGS_SHOW_ASCII = 1 << 0,
38 FU_DUMP_FLAGS_SHOW_ADDRESSES = 1 << 1,
Mario Limonciello39602652019-04-29 21:08:58 -050039 /*< private >*/
Richard Hughes35481862019-01-06 12:01:58 +000040 FU_DUMP_FLAGS_LAST
41} FuDumpFlags;
42
Mario Limonciello39602652019-04-29 21:08:58 -050043/**
44 * FuPathKind:
45 * @FU_PATH_KIND_CACHEDIR_PKG: The cache directory (IE /var/cache/fwupd)
46 * @FU_PATH_KIND_DATADIR_PKG: The non-volatile data store (IE /usr/share/fwupd)
47 * @FU_PATH_KIND_EFIAPPDIR: The location to store EFI apps before install (IE /usr/libexec/fwupd/efi)
48 * @FU_PATH_KIND_LOCALSTATEDIR: The local state directory (IE /var)
49 * @FU_PATH_KIND_LOCALSTATEDIR_PKG: The local state directory for the package (IE /var/lib/fwupd)
50 * @FU_PATH_KIND_PLUGINDIR_PKG: The location to look for plugins for package (IE /usr/lib/[triplet]/fwupd-plugins-3)
51 * @FU_PATH_KIND_SYSCONFDIR: The configuration location (IE /etc)
52 * @FU_PATH_KIND_SYSCONFDIR_PKG: The package configuration location (IE /etc/fwupd)
53 * @FU_PATH_KIND_SYSFSDIR_FW: The sysfs firmware location (IE /sys/firmware)
54 * @FU_PATH_KIND_SYSFSDIR_DRIVERS: The platform sysfs directory (IE /sys/bus/platform/drivers)
55 * @FU_PATH_KIND_SYSFSDIR_TPM: The TPM sysfs directory (IE /sys/class/tpm)
Mario Limonciello057c67a2019-05-23 10:44:19 -050056 * @FU_PATH_KIND_POLKIT_ACTIONS The directory for policy kit actions (IE /usr/share/polkit-1/actions/)
Mario Limonciello39602652019-04-29 21:08:58 -050057 *
58 * Path types to use when dynamically determining a path at runtime
59 **/
Richard Hughes35481862019-01-06 12:01:58 +000060typedef enum {
Richard Hughes4be17d12018-05-30 20:36:29 +010061 FU_PATH_KIND_CACHEDIR_PKG,
62 FU_PATH_KIND_DATADIR_PKG,
Mario Limoncielloe6e2bf92018-07-10 12:11:25 -050063 FU_PATH_KIND_EFIAPPDIR,
Richard Hughes4be17d12018-05-30 20:36:29 +010064 FU_PATH_KIND_LOCALSTATEDIR,
65 FU_PATH_KIND_LOCALSTATEDIR_PKG,
66 FU_PATH_KIND_PLUGINDIR_PKG,
67 FU_PATH_KIND_SYSCONFDIR,
68 FU_PATH_KIND_SYSCONFDIR_PKG,
Richard Hughes282b10d2018-06-22 14:48:00 +010069 FU_PATH_KIND_SYSFSDIR_FW,
Richard Hughes83390f62018-06-22 20:36:46 +010070 FU_PATH_KIND_SYSFSDIR_DRIVERS,
Richard Hughesb56015e2018-12-12 09:25:32 +000071 FU_PATH_KIND_SYSFSDIR_TPM,
Mario Limonciello057c67a2019-05-23 10:44:19 -050072 FU_PATH_KIND_POLKIT_ACTIONS,
Mario Limonciello39602652019-04-29 21:08:58 -050073 /*< private >*/
Richard Hughes4be17d12018-05-30 20:36:29 +010074 FU_PATH_KIND_LAST
75} FuPathKind;
76
Richard Hughes049ccc82017-08-09 15:26:56 +010077typedef void (*FuOutputHandler) (const gchar *line,
78 gpointer user_data);
79
80gboolean fu_common_spawn_sync (const gchar * const *argv,
Richard Hughes4eada342017-10-03 21:20:32 +010081 FuOutputHandler handler_cb,
Richard Hughes049ccc82017-08-09 15:26:56 +010082 gpointer handler_user_data,
Richard Hughesb768e4d2019-02-26 13:55:18 +000083 guint timeout_ms,
Richard Hughes049ccc82017-08-09 15:26:56 +010084 GCancellable *cancellable,
85 GError **error);
86
Richard Hughes4be17d12018-05-30 20:36:29 +010087gchar *fu_common_get_path (FuPathKind path_kind);
Richard Hughes484ee292019-03-22 16:10:50 +000088gchar *fu_common_realpath (const gchar *filename,
89 GError **error);
Richard Hughes954dd9f2017-08-08 13:36:25 +010090gboolean fu_common_rmtree (const gchar *directory,
91 GError **error);
Richard Hughes89e968b2018-03-07 10:01:08 +000092GPtrArray *fu_common_get_files_recursive (const gchar *path,
93 GError **error);
Richard Hughes7ee42fe2017-08-15 14:06:21 +010094gboolean fu_common_mkdir_parent (const gchar *filename,
95 GError **error);
Richard Hughes943d2c92017-06-21 09:04:39 +010096gboolean fu_common_set_contents_bytes (const gchar *filename,
Richard Hughes4eada342017-10-03 21:20:32 +010097 GBytes *bytes,
Richard Hughes943d2c92017-06-21 09:04:39 +010098 GError **error);
Richard Hughesd0d2ae62017-08-08 12:22:30 +010099GBytes *fu_common_get_contents_bytes (const gchar *filename,
100 GError **error);
Richard Hughes943d2c92017-06-21 09:04:39 +0100101GBytes *fu_common_get_contents_fd (gint fd,
102 gsize count,
103 GError **error);
Richard Hughes94f939a2017-08-08 12:21:39 +0100104gboolean fu_common_extract_archive (GBytes *blob,
105 const gchar *dir,
106 GError **error);
Richard Hughes41cbe2a2017-08-08 14:13:35 +0100107GBytes *fu_common_firmware_builder (GBytes *bytes,
108 const gchar *script_fn,
109 const gchar *output_fn,
110 GError **error);
Richard Hughese82eef32018-05-20 10:41:26 +0100111GError *fu_common_error_array_get_best (GPtrArray *errors);
Richard Hughes73bf2332018-08-28 09:38:09 +0100112guint64 fu_common_strtoull (const gchar *str);
Richard Hughes22367e72018-08-30 10:24:04 +0100113gchar *fu_common_find_program_in_path (const gchar *basename,
114 GError **error);
Richard Hughesa574a752018-08-31 13:31:03 +0100115gchar *fu_common_strstrip (const gchar *str);
Richard Hughese59cb9a2018-12-05 14:37:40 +0000116void fu_common_dump_raw (const gchar *log_domain,
117 const gchar *title,
118 const guint8 *data,
119 gsize len);
Richard Hughes35481862019-01-06 12:01:58 +0000120void fu_common_dump_full (const gchar *log_domain,
121 const gchar *title,
122 const guint8 *data,
123 gsize len,
124 guint columns,
125 FuDumpFlags flags);
Richard Hughese59cb9a2018-12-05 14:37:40 +0000126void fu_common_dump_bytes (const gchar *log_domain,
127 const gchar *title,
128 GBytes *bytes);
Richard Hughesfc90f392019-01-15 21:21:16 +0000129GBytes *fu_common_bytes_align (GBytes *bytes,
130 gsize blksz,
131 gchar padval);
Richard Hughes36999462019-03-19 20:23:29 +0000132gboolean fu_common_bytes_is_empty (GBytes *bytes);
Richard Hughes2aad1042019-03-21 09:03:32 +0000133gboolean fu_common_bytes_compare (GBytes *bytes1,
134 GBytes *bytes2,
135 GError **error);
Richard Hughes7afd7cb2019-08-07 11:42:42 +0100136GBytes *fu_common_bytes_pad (GBytes *bytes,
137 gsize sz);
Richard Hughes5308ea42019-08-09 12:25:13 +0100138gboolean fu_memcpy_safe (guint8 *dst,
139 gsize dst_sz,
140 gsize dst_offset,
141 const guint8 *src,
142 gsize src_sz,
143 gsize src_offset,
144 gsize n,
145 GError **error);
Richard Hughes943d2c92017-06-21 09:04:39 +0100146
Richard Hughesae252cd2017-12-08 10:48:15 +0000147typedef guint FuEndianType;
148
149void fu_common_write_uint16 (guint8 *buf,
150 guint16 val_native,
151 FuEndianType endian);
152void fu_common_write_uint32 (guint8 *buf,
153 guint32 val_native,
154 FuEndianType endian);
155guint16 fu_common_read_uint16 (const guint8 *buf,
156 FuEndianType endian);
157guint32 fu_common_read_uint32 (const guint8 *buf,
158 FuEndianType endian);
159
Richard Hughes83e56c12018-10-10 20:24:41 +0100160guint fu_common_string_replace (GString *string,
161 const gchar *search,
162 const gchar *replace);
Richard Hughescea28de2019-08-09 11:16:40 +0100163void fu_common_string_append_kv (GString *str,
Richard Hughes6e3e62b2019-08-14 10:43:08 +0100164 guint idt,
Richard Hughescea28de2019-08-09 11:16:40 +0100165 const gchar *key,
166 const gchar *value);
Richard Hughes6e3e62b2019-08-14 10:43:08 +0100167void fu_common_string_append_ku (GString *str,
168 guint idt,
169 const gchar *key,
170 guint64 value);
171void fu_common_string_append_kx (GString *str,
172 guint idt,
173 const gchar *key,
174 guint64 value);
175void fu_common_string_append_kb (GString *str,
176 guint idt,
177 const gchar *key,
178 gboolean value);
Richard Hughes7afd7cb2019-08-07 11:42:42 +0100179gchar **fu_common_strnsplit (const gchar *str,
180 gsize sz,
181 const gchar *delimiter,
182 gint max_tokens);
Richard Hughes2d3287a2019-02-10 17:32:14 +0000183
184G_END_DECLS