summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-08-22 14:12:14 +0100
committerRichard Hughes <richard@hughsie.com>2016-08-22 14:19:12 +0100
commite83da4ad01e6eaa50b45124706ef9f6b31bcd071 (patch)
tree27cc8aa655510e9a945b8df776f5827db7eedec8
parent47bdeafc778ed1d83bef46ce50963c5513a6cd2d (diff)
downloadappstream-glib-e83da4ad01e6eaa50b45124706ef9f6b31bcd071.tar.gz
Remove the inf parsing from appstream-glib
I don't want to maintain this large chunk of complex code in the main library, especially as it's basically unused except for the validation of .cab files. The latter has a python implmentation as used on the LVFS, so it's really just dead code now. Move the (unused) implementation to libginf for archival, but leave stubs in to avoid upsetting the API/ABI checkers. We can remove the symbols when we next break soname.
-rw-r--r--data/tests/Makefile.am1
-rw-r--r--data/tests/example.inf50
-rw-r--r--libappstream-glib/as-app-inf.c218
-rw-r--r--libappstream-glib/as-app-validate.c3
-rw-r--r--libappstream-glib/as-app.c4
-rw-r--r--libappstream-glib/as-app.h12
-rw-r--r--libappstream-glib/as-inf.c843
-rw-r--r--libappstream-glib/as-inf.h9
-rw-r--r--libappstream-glib/as-self-test.c356
-rw-r--r--libappstream-glib/as-store-cab.c62
10 files changed, 35 insertions, 1523 deletions
diff --git a/data/tests/Makefile.am b/data/tests/Makefile.am
index 6034e2b..abf1686 100644
--- a/data/tests/Makefile.am
+++ b/data/tests/Makefile.am
@@ -15,7 +15,6 @@ test_files = \
composite-1-1.fc21.x86_64.rpm \
example.appdata.xml \
example.desktop \
- example.inf \
example.metainfo.xml \
example-v04.xml.gz \
example-v06.yml.gz \
diff --git a/data/tests/example.inf b/data/tests/example.inf
deleted file mode 100644
index 98d1330..0000000
--- a/data/tests/example.inf
+++ /dev/null
@@ -1,50 +0,0 @@
-; Copyright (C) 2015 Hughski Limited
-
-[Version]
-Signature="$WINDOWS NT$"
-Class=Firmware
-ClassGuid={F2E7DD72-6468-4E36-B6f1-6488F42C1B52}
-Provider=%Provider%
-DriverVer=03/03/2015,2.0.2
-PnpLockdown=1
-CatalogFile=firmware.cat
-
-[Manufacturer]
-%MfgName% = Hughski,NTamd64
-
-[Hughski.NTamd64]
-%FirmwareDesc% = Firmware_Install,firmware\RES_{84f40464-9272-4ef7-9399-cd95f12da695}
-
-[Firmware_Install.NT]
-CopyFiles = Firmware_CopyFiles
-
-[Firmware_CopyFiles]
-firmware.bin
-
-[Firmware_Install.NT.Hw]
-AddReg = Firmware_AddReg
-
-[Firmware_AddReg]
-HKR,,FirmwareId,,{84f40464-9272-4ef7-9399-cd95f12da695}
-HKR,,FirmwareVersion,%REG_DWORD%, 0x00020002
-HKR , , FirmwareFilename , , "firmware.bin"
-
-[SourceDisksNames]
-1 = %DiskName%
-
-[SourceDisksFiles]
-firmware.bin = 1
-
-[DestinationDirs]
-DefaultDestDir = %DIRID_WINDOWS%,Firmware ; %SystemRoot%\Firmware
-
-[Strings]
-; localizable
-Provider = "Hughski"
-MfgName = "Hughski Limited"
-FirmwareDesc = "ColorHug Firmware"
-DiskName = "Firmware for the ColorHug Colorimeter"
-
-; non-localizable
-DIRID_WINDOWS = 10
-REG_DWORD = 0x00010001
diff --git a/libappstream-glib/as-app-inf.c b/libappstream-glib/as-app-inf.c
index 2169fb9..61441d8 100644
--- a/libappstream-glib/as-app-inf.c
+++ b/libappstream-glib/as-app-inf.c
@@ -24,24 +24,6 @@
#include "as-app-private.h"
#include "as-inf.h"
-#include "as-utils-private.h"
-
-#define AS_APP_INF_CLASS_GUID_FIRMWARE "f2e7dd72-6468-4e36-b6f1-6488f42c1b52"
-
-static gchar *
-as_app_parse_inf_sanitize_guid (const gchar *guid)
-{
- GString *id;
- guint i;
-
- id = g_string_sized_new (strlen (guid));
-
- for (i = 0; guid[i] != '\0'; i++) {
- if (g_ascii_isalnum (guid[i]) || guid[i] == '-')
- g_string_append_c (id, g_ascii_tolower (guid[i]));
- }
- return g_string_free (id, FALSE);
-}
gboolean
as_app_parse_inf_file (AsApp *app,
@@ -49,199 +31,9 @@ as_app_parse_inf_file (AsApp *app,
AsAppParseFlags flags,
GError **error)
{
- guint64 timestamp;
- g_autoptr(GError) error_local = NULL;
- g_autofree gchar *appstream_id = NULL;
- g_autofree gchar *catalog_basename = NULL;
- g_autofree gchar *class_guid = NULL;
- g_autofree gchar *class_guid_unsafe = NULL;
- g_autofree gchar *class = NULL;
- g_autofree gchar *comment = NULL;
- g_autofree gchar *display_version = NULL;
- g_autofree gchar *filename_full = NULL;
- g_autofree gchar *firmware_basename = NULL;
- g_autofree gchar *guid = NULL;
- g_autofree gchar *provide_guid = NULL;
- g_autofree gchar *location_checksum = NULL;
- g_autofree gchar *name = NULL;
- g_autofree gchar *srcpkg = NULL;
- g_autofree gchar *vendor = NULL;
- g_autofree gchar *version = NULL;
- g_autofree gchar *version_parsed = NULL;
- g_autoptr(GKeyFile) kf = NULL;
- g_autoptr(AsChecksum) csum = NULL;
- g_autoptr(AsIcon) icon = NULL;
- g_autoptr(AsProvide) provide = NULL;
- g_autoptr(AsRelease) release = NULL;
- g_auto(GStrv) source_keys = NULL;
-
- /* load file */
- kf = g_key_file_new ();
- if (!as_inf_load_file (kf, filename, AS_INF_LOAD_FLAG_NONE, &error_local)) {
- g_set_error (error,
- AS_APP_ERROR,
- AS_APP_ERROR_INVALID_TYPE,
- "Failed to parse %s: %s",
- filename, error_local->message);
- return FALSE;
- }
-
- /* get the type of .inf file */
- class = g_key_file_get_string (kf, "Version", "Class", NULL);
- if (class == NULL) {
- g_set_error_literal (error,
- AS_APP_ERROR,
- AS_APP_ERROR_INVALID_TYPE,
- "Driver class is missing");
- return FALSE;
- }
- if (g_strcmp0 (class, "Firmware") != 0) {
- g_set_error (error,
- AS_APP_ERROR,
- AS_APP_ERROR_INVALID_TYPE,
- "Driver class is '%s', not 'Firmware'", class);
- return FALSE;
- }
- as_app_set_kind (app, AS_APP_KIND_FIRMWARE);
-
- /* get the Class GUID */
- class_guid_unsafe = g_key_file_get_string (kf, "Version", "ClassGuid", NULL);
- if (class_guid_unsafe == NULL) {
- g_set_error_literal (error,
- AS_APP_ERROR,
- AS_APP_ERROR_INVALID_TYPE,
- "ClassGuid is missing");
- return FALSE;
- }
- class_guid = as_app_parse_inf_sanitize_guid (class_guid_unsafe);
- if (g_strcmp0 (class_guid, AS_APP_INF_CLASS_GUID_FIRMWARE) != 0) {
- g_set_error (error,
- AS_APP_ERROR,
- AS_APP_ERROR_INVALID_TYPE,
- "ClassGuid is invalid, expected %s, got %s",
- AS_APP_INF_CLASS_GUID_FIRMWARE,
- class_guid);
- return FALSE;
- }
-
- /* get the ESRT GUID */
- guid = g_key_file_get_string (kf,
- "Firmware_AddReg",
- "HKR_FirmwareId",
- NULL);
- if (guid == NULL) {
- g_set_error_literal (error,
- AS_APP_ERROR,
- AS_APP_ERROR_INVALID_TYPE,
- "HKR->FirmwareId missing from [Firmware_AddReg]");
- return FALSE;
- }
-
- /* get the version */
- version = g_key_file_get_string (kf,
- "Firmware_AddReg",
- "HKR_FirmwareVersion_0x00010001",
- NULL);
- if (version == NULL) {
- g_set_error_literal (error,
- AS_APP_ERROR,
- AS_APP_ERROR_INVALID_TYPE,
- "HKR->FirmwareVersion missing from [Firmware_AddReg]");
- return FALSE;
- }
-
- /* convert if required */
- version_parsed = as_utils_version_parse (version);
-
- /* add the GUID as a provide */
- provide_guid = as_app_parse_inf_sanitize_guid (guid);
- if (provide_guid != NULL) {
- provide = as_provide_new ();
- as_provide_set_kind (provide, AS_PROVIDE_KIND_FIRMWARE_FLASHED);
- as_provide_set_value (provide, provide_guid);
- as_app_add_provide (AS_APP (app), provide);
- }
-
- /* get the ID, which might be missing */
- appstream_id = g_key_file_get_string (kf, "Version", "AppstreamId", NULL);
- if (appstream_id != NULL) {
- g_debug ("Using AppstreamId as ID");
- as_app_set_id (app, appstream_id);
- } else {
- as_app_set_id (app, provide_guid);
- }
-
- /* get vendor */
- vendor = g_key_file_get_string (kf, "Version", "Provider", NULL);
- if (vendor == NULL)
- vendor = g_key_file_get_string (kf, "Version", "MfgName", NULL);
- if (vendor != NULL)
- as_app_set_developer_name (app, NULL, vendor);
-
- /* get name */
- name = g_key_file_get_string (kf, "Strings", "FirmwareDesc", NULL);
- if (name != NULL)
- as_app_set_name (app, NULL, name);
-
- /* get comment */
- comment = g_key_file_get_string (kf, "SourceDisksNames", "1", NULL);
- if (comment == NULL) /* FIXME: is a hack */
- comment = g_key_file_get_string (kf, "Strings", "DiskName", NULL);
- if (comment != NULL)
- as_app_set_comment (app, NULL, comment);
-
- /* parse the DriverVer */
- display_version = as_inf_get_driver_version (kf, &timestamp, &error_local);
- if (display_version == NULL) {
- if (g_error_matches (error_local,
- AS_INF_ERROR,
- AS_INF_ERROR_NOT_FOUND)) {
- g_clear_error (&error_local);
- } else {
- g_set_error_literal (error,
- AS_APP_ERROR,
- AS_APP_ERROR_FAILED,
- error_local->message);
- return FALSE;
- }
- }
-
- /* find the firmware file we're installing */
- source_keys = g_key_file_get_keys (kf, "SourceDisksFiles", NULL, NULL);
- if (source_keys != NULL && g_strv_length (source_keys) == 1) {
- firmware_basename = g_strdup (source_keys[0]);
- } else {
- firmware_basename = g_key_file_get_string (kf,
- "Firmware_CopyFiles",
- "value000", NULL);
- }
- if (firmware_basename == NULL) {
- g_set_error (error,
- AS_APP_ERROR,
- AS_APP_ERROR_INVALID_TYPE,
- "no SourceDisksFiles or Firmware_CopyFiles");
- return FALSE;
- }
-
- /* this is for display only */
- if (display_version != NULL)
- as_app_add_metadata (app, "DisplayVersion", display_version);
-
- /* add a release with no real description */
- release = as_release_new ();
- as_release_set_version (release, version_parsed);
- as_release_set_timestamp (release, timestamp);
- csum = as_checksum_new ();
- as_checksum_set_filename (csum, firmware_basename);
- as_checksum_set_target (csum, AS_CHECKSUM_TARGET_CONTENT);
- as_release_add_checksum (release, csum);
- as_app_add_release (app, release);
-
- /* add icon */
- icon = as_icon_new ();
- as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
- as_icon_set_name (icon, "application-x-executable");
- as_app_add_icon (app, icon);
-
- return TRUE;
+ g_set_error (error,
+ AS_INF_ERROR,
+ AS_INF_ERROR_FAILED,
+ "Loading .inf data is no longer suported, see libginf");
+ return FALSE;
}
diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c
index f5f509f..d44c7fe 100644
--- a/libappstream-glib/as-app-validate.c
+++ b/libappstream-glib/as-app-validate.c
@@ -764,8 +764,7 @@ as_app_validate_screenshots (AsApp *app, AsAppValidateHelper *helper)
number_screenshots_min = 0;
/* metainfo and inf do not require any screenshots */
- if (as_app_get_source_kind (app) == AS_APP_SOURCE_KIND_METAINFO ||
- as_app_get_source_kind (app) == AS_APP_SOURCE_KIND_INF)
+ if (as_app_get_source_kind (app) == AS_APP_SOURCE_KIND_METAINFO)
number_screenshots_min = 0;
/* only for AppData and AppStream */
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index f18e7ba..524db25 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -5533,10 +5533,6 @@ as_app_parse_file (AsApp *app,
if (!as_app_parse_appdata_file (app, filename, flags, error))
return FALSE;
break;
- case AS_APP_SOURCE_KIND_INF:
- if (!as_app_parse_inf_file (app, filename, flags, error))
- return FALSE;
- break;
default:
g_set_error (error,
AS_APP_ERROR,
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index 01fa789..bb21512 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -264,12 +264,12 @@ typedef enum {
* The source kind.
**/
typedef enum {
- AS_APP_SOURCE_KIND_UNKNOWN, /* Since: 0.1.4 */
- AS_APP_SOURCE_KIND_APPSTREAM, /* Since: 0.1.4 */
- AS_APP_SOURCE_KIND_DESKTOP, /* Since: 0.1.4 */
- AS_APP_SOURCE_KIND_APPDATA, /* Since: 0.1.4 */
- AS_APP_SOURCE_KIND_METAINFO, /* Since: 0.1.7 */
- AS_APP_SOURCE_KIND_INF, /* Since: 0.3.5 */
+ AS_APP_SOURCE_KIND_UNKNOWN, /* Since: 0.1.4 */
+ AS_APP_SOURCE_KIND_APPSTREAM, /* Since: 0.1.4 */
+ AS_APP_SOURCE_KIND_DESKTOP, /* Since: 0.1.4 */
+ AS_APP_SOURCE_KIND_APPDATA, /* Since: 0.1.4 */
+ AS_APP_SOURCE_KIND_METAINFO, /* Since: 0.1.7 */
+ AS_APP_SOURCE_KIND_INF, /* Since: 0.3.5 (deprecated 0.6.2) */
/*< private >*/
AS_APP_SOURCE_KIND_LAST
} AsAppSourceKind;
diff --git a/libappstream-glib/as-inf.c b/libappstream-glib/as-inf.c
index 067748d..c3450bc 100644
--- a/libappstream-glib/as-inf.c
+++ b/libappstream-glib/as-inf.c
@@ -32,8 +32,8 @@
#include "config.h"
#include <gio/gio.h>
-#include <string.h>
-#include <stdlib.h>
+//#include <string.h>
+//#include <stdlib.h>
#include "as-inf.h"
@@ -46,682 +46,6 @@
**/
G_DEFINE_QUARK (as-inf-error-quark, as_inf_error)
-typedef struct {
- GKeyFile *keyfile;
- GHashTable *dict;
- gboolean last_line_continuation;
- gboolean last_line_continuation_ignore;
- gboolean require_2nd_pass;
- gchar *group;
- gchar *last_key;
- gchar *comment;
- gchar *comment_group;
- guint nokey_idx;
- AsInfLoadFlags flags;
-} AsInfHelper;
-
-static gchar *
-as_inf_make_case_insensitive (AsInfHelper *helper, const gchar *text)
-{
- if (helper->flags & AS_INF_LOAD_FLAG_CASE_INSENSITIVE)
- return g_ascii_strdown (text, -1);
- return g_strdup (text);
-}
-
-static gboolean
-as_inf_string_isdigits (const gchar *str)
-{
- guint i;
- for (i = 0; str[i] != '\0'; i++) {
- if (!g_ascii_isdigit (str[i]))
- return FALSE;
- }
- return TRUE;
-}
-
-static gchar *
-as_inf_replace_variable (AsInfHelper *helper, const gchar *line, GError **error)
-{
- GString *new;
- const gchar *tmp;
- guint i;
- g_auto(GStrv) split = NULL;
-
- /* split up into sections of the delimiter */
- new = g_string_sized_new (strlen (line));
- split = g_strsplit (line, "%", -1);
- for (i = 0; split[i] != NULL; i++) {
- g_autofree gchar *lower = NULL;
-
- /* the text between the substitutions */
- if (i % 2 == 0) {
- g_strdelimit (split[i], "\\", '/');
- g_string_append (new, split[i]);
- continue;
- }
-
- /* a Dirid */
- if (as_inf_string_isdigits (split[i])) {
- g_string_append (new, "/tmp");
- continue;
- }
-
- /* replace or ignore things not (yet) in the dictionary */
- lower = as_inf_make_case_insensitive (helper, split[i]);
- tmp = g_hash_table_lookup (helper->dict, lower);
- if (tmp == NULL) {
- if (helper->flags & AS_INF_LOAD_FLAG_STRICT) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "No replacement for '%s' in [Strings]",
- lower);
- g_string_free (new, TRUE);
- return NULL;
- }
- g_string_append_printf (new, "%%%s%%", split[i]);
- continue;
- }
- g_string_append (new, tmp);
- }
- return g_string_free (new, FALSE);
-}
-
-static GHashTable *
-as_inf_get_dict (AsInfHelper *helper, GError **error)
-{
- GHashTable *dict = NULL;
- gchar *val;
- guint i;
- g_autofree gchar *lower = NULL;
- g_autoptr(GHashTable) dict_tmp = NULL;
- g_auto(GStrv) keys = NULL;
- struct {
- const gchar *search;
- const gchar *replace;
- } types[] = {
- { "REG_SZ", "0x00000000" },
- { "REG_BINARY", "0x00000001" },
- { "REG_MULTI_SZ", "0x00010000" },
- { "REG_EXPAND_SZ", "0x00020000" },
- { "REG_DWORD", "0x00010001" },
- { "REG_NONE", "0x00020001" },
- { NULL, NULL } };
-
- dict_tmp = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- lower = as_inf_make_case_insensitive (helper, "Strings");
- keys = g_key_file_get_keys (helper->keyfile, lower, NULL, NULL);
- for (i = 0; keys != NULL && keys[i] != NULL; i++) {
- val = g_key_file_get_string (helper->keyfile, lower, keys[i], error);
- if (val == NULL)
- goto out;
- g_hash_table_insert (dict_tmp, g_strdup (keys[i]), val);
- }
-
- /* verify that commonly missed types are present */
- for (i = 0; types[i].search != NULL; i++) {
- if (g_hash_table_lookup (dict_tmp, types[i].search) == NULL) {
- g_hash_table_insert (dict_tmp,
- g_strdup (types[i].search),
- g_strdup (types[i].replace));
- }
- }
-
- dict = g_hash_table_ref (dict_tmp);
-out:
- return dict;
-}
-
-static gboolean
-as_inf_replace_variables (AsInfHelper *helper, GError **error)
-{
- guint i;
- guint j;
- g_auto(GStrv) groups = NULL;
-
- groups = g_key_file_get_groups (helper->keyfile, NULL);
- for (i = 0; groups[i] != NULL; i++) {
- g_auto(GStrv) keys = NULL;
-
- /* ignore the source */
- if (g_strcmp0 (groups[i], "Strings") == 0)
- continue;
-
- /* fix up keys */
- keys = g_key_file_get_keys (helper->keyfile, groups[i], NULL, NULL);
- if (keys == NULL)
- continue;
- for (j = 0; keys[j] != NULL; j++) {
- g_autofree gchar *data_old = NULL;
- g_autofree gchar *data_new = NULL;
-
- /* get the old data for this [group] key */
- data_old = g_key_file_get_string (helper->keyfile,
- groups[i],
- keys[j],
- NULL);
- if (data_old == NULL || data_old[0] == '\0')
- continue;
-
- /* optimise a little */
- if (g_strstr_len (data_old, -1, "%") == NULL)
- continue;
-
- /* do string replacement */
- data_new = as_inf_replace_variable (helper,
- data_old,
- error);
- if (data_new == NULL)
- return FALSE;
- if (g_strcmp0 (data_old, data_new) == 0)
- continue;
- g_key_file_set_string (helper->keyfile,
- groups[i],
- keys[j],
- data_new);
- }
- }
- return TRUE;
-}
-
-static void
-as_inf_set_last_key (AsInfHelper *helper, const gchar *key)
-{
- /* same value */
- if (key == helper->last_key)
- return;
- g_free (helper->last_key);
- helper->last_key = g_strdup (key);
-}
-
-static void
-as_inf_set_comment (AsInfHelper *helper, const gchar *comment)
-{
- /* same value */
- if (comment == helper->comment)
- return;
-
- g_free (helper->comment);
- helper->comment = g_strdup (comment);
- if (helper->comment != NULL)
- g_strchug (helper->comment);
-}
-
-static gboolean
-as_inf_strcheckchars (const gchar *str, const gchar *chars)
-{
- guint i;
- guint j;
- for (i = 0; str[i] != '\0'; i++) {
- for (j = 0; chars[j] != '\0'; j++) {
- if (str[i] == chars[j])
- return TRUE;
- }
- }
- return FALSE;
-}
-
-static gboolean
-as_inf_strip_value (AsInfHelper *helper, gchar *value, GError **error)
-{
- gchar *comment;
- gchar *last_quote;
-
- /* trivial case; no quotes */
- if (value[0] != '"') {
- comment = g_strrstr (value + 1, ";");
- if (comment != NULL) {
- *comment = '\0';
- if (helper->comment == NULL)
- as_inf_set_comment (helper, comment + 1);
- g_strchomp (value + 1);
- }
- return TRUE;
- }
-
- /* is there only one quote? */
- last_quote = g_strrstr (value, "\"");
- if (last_quote == value) {
- if (helper->flags & AS_INF_LOAD_FLAG_STRICT) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "mismatched quotes %s", value);
- return FALSE;
- }
- last_quote = NULL;
- }
-
- /* shift the string down */
- memmove (value, value + 1, strlen (value));
-
- /* there's a comment past the last quote */
- comment = g_strrstr (value, ";");
- if (comment != NULL && comment > last_quote) {
- *comment = '\0';
- if (helper->comment == NULL)
- as_inf_set_comment (helper, comment + 1);
- g_strchomp (value);
- }
-
- /* remove the last quote */
- if (last_quote != NULL)
- *(last_quote-1) = '\0';
-
- return TRUE;
-}
-
-static gboolean
-as_inf_set_group (AsInfHelper *helper, const gchar *group, GError **error)
-{
- /* same value */
- if (group == helper->group)
- return TRUE;
-
- /* maximum permitted length is 255 chars */
- if (strlen (group) > 255) {
- if (helper->flags & AS_INF_LOAD_FLAG_STRICT) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "section name is too long: %s",
- group);
- return FALSE;
- }
- }
-
- /* save new value */
- g_free (helper->group);
- helper->group = as_inf_make_case_insensitive (helper, group);
-
- /* section names can contain double quotes */
- if (!as_inf_strip_value (helper, helper->group, error))
- return FALSE;
-
- /* does this section name have any banned chars */
- if (helper->flags & AS_INF_LOAD_FLAG_STRICT) {
- if (g_str_has_prefix (helper->group, " ")) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "section name '%s' has leading spaces",
- helper->group);
- return FALSE;
- }
- if (g_str_has_suffix (helper->group, " ")) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "section name '%s' has trailing spaces",
- helper->group);
- return FALSE;
- }
- if (as_inf_strcheckchars (helper->group, "\t\n\r;\"")) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "section name '%s' has invalid chars",
- helper->group);
- return FALSE;
- }
- } else {
- g_strstrip (helper->group);
- g_strdelimit (helper->group, "\t\n\r;\"", '_');
- }
-
- /* start with new values */
- helper->last_line_continuation_ignore = FALSE;
- helper->nokey_idx = 0;
-
- /* no longer valid */
- as_inf_set_last_key (helper, NULL);
-
- /* FIXME: refusing to add a comment to a group that does not exist
- * is a GLib bug! */
- if (helper->comment != NULL) {
- g_key_file_set_comment (helper->keyfile,
- helper->group,
- NULL,
- helper->comment,
- NULL);
- as_inf_set_comment (helper, NULL);
- }
- return TRUE;
-}
-
-static void
-as_inf_set_key (AsInfHelper *helper, const gchar *key, const gchar *value)
-{
- helper->last_line_continuation_ignore = FALSE;
- g_key_file_set_string (helper->keyfile, helper->group, key, value);
- if (helper->comment != NULL) {
- g_key_file_set_comment (helper->keyfile,
- helper->group,
- key,
- helper->comment,
- NULL);
- as_inf_set_comment (helper, NULL);
- }
- as_inf_set_last_key (helper, key);
-}
-
-static void
-as_inf_convert_key (gchar *key)
-{
- guint i;
- for (i = 0; key[i] != '\0'; i++) {
- if (g_ascii_isalnum (key[i]))
- continue;
- if (key[i] == '.' || key[i] == '%')
- continue;
- key[i] = '_';
- }
-}
-
-static gboolean
-as_inf_repair_utf8 (AsInfHelper *helper, gchar *line, GError **error)
-{
- guint i;
- guint8 val;
-
- /* Microsoft keeps using 0x99 as UTF-8 (R), and it's not valid */
- for (i = 0; line[i] != '\0'; i++) {
- val = (guint8) line[i];
- if (val == 0x99) {
- if (helper->flags & AS_INF_LOAD_FLAG_STRICT) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "Invalid UTF-8: 0x%02x", val);
- return FALSE;
-
- }
- line[i] = '?';
- continue;
- }
- }
- return TRUE;
-}
-
-static gboolean
-as_inf_parse_line (AsInfHelper *helper, gchar *line, GError **error)
-{
- gchar *kvsplit;
- gchar *comment;
- gchar *tmp;
- guint len;
- gboolean ret = TRUE;
- gboolean continuation = FALSE;
- g_autofree gchar *key = NULL;
-
- /* line too long */
- if ((helper->flags & AS_INF_LOAD_FLAG_STRICT) > 0 &&
- strlen (line) > 4096) {
- ret = FALSE;
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "line too long: %s", line);
- goto out;
- }
-
- /* fix up invalid UTF-8 */
- if (!as_inf_repair_utf8 (helper, line, error)) {
- ret = FALSE;
- goto out;
- }
-
- /* remove leading and trailing whitespace */
- g_strstrip (line);
- if (line[0] == '\0')
- goto out;
-
- /* remove comments */
- if (line[0] == ';') {
- as_inf_set_comment (helper, line + 1);
- goto out;
- }
-
- /* ignore pragmas */
- if (g_str_has_prefix (line, "#pragma"))
- goto out;
- if (g_str_has_prefix (line, "#define"))
- goto out;
-
- /* [group] */
- if (line[0] == '[') {
-
- /* remove comments */
- comment = g_strstr_len (line, -1, ";");
- if (comment != NULL) {
- *comment = '\0';
- as_inf_set_comment (helper, comment + 1);
- g_strchomp (line);
- }
-
- /* find group end */
- tmp = g_strrstr (line, "]");
- if (tmp == NULL) {
- ret = FALSE;
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "[ but no ] : '%s'", line);
- goto out;
- }
- *tmp = '\0';
- ret = as_inf_set_group (helper, line + 1, error);
- goto out;
- }
-
- /* last char continuation */
- len = (guint) strlen (line);
- if (line[len-1] == '\\') {
- line[len-1] = '\0';
- continuation = TRUE;
- }
-
- /* is a multiline key value */
- if (line[len-1] == '|') {
- line[len-1] = '\0';
- continuation = TRUE;
- }
-
- /* if the key-value split is before the first quote */
- kvsplit = g_strstr_len (line, -1, "=");
- tmp = g_strstr_len (line, -1, "\"");
- if ((tmp == NULL && kvsplit != NULL) ||
- (kvsplit != NULL && kvsplit < tmp)) {
- g_autofree gchar *key_new = NULL;
-
- /* key=value before [group] */
- if (helper->group == NULL) {
- ret = FALSE;
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "key not in group: '%s'", line);
- goto out;
- }
-
- *kvsplit = '\0';
- key = as_inf_make_case_insensitive (helper, line);
- g_strchomp (key);
-
- /* remove invalid chars as GKeyFile is more strict than .ini */
- as_inf_convert_key (key);
-
- /* convert key names with variables */
- if (key[0] == '%') {
- g_autofree gchar *key_tmp = NULL;
- if (helper->dict == NULL) {
- helper->require_2nd_pass = TRUE;
- helper->last_line_continuation_ignore = TRUE;
- goto out;
- }
- key_tmp = as_inf_replace_variable (helper, key, error);
- if (key_tmp == NULL)
- return FALSE;
- if (key_tmp[0] == '%') {
- key_new = g_strdup (key + 1);
- g_strdelimit (key_new, "%", '\0');
- g_debug ("No replacement for '%s' in [Strings] "
- "using '%s'", key, key_new);
- goto out;
- }
-
- /* this has to be lowercase */
- key_new = as_inf_make_case_insensitive (helper, key_tmp);
- as_inf_convert_key (key_new);
- } else {
- key_new = g_strdup (key);
- }
-
- /* remove leading and trailing quote */
- g_strchug (kvsplit + 1);
- if (!as_inf_strip_value (helper, kvsplit + 1, error)) {
- ret = FALSE;
- goto out;
- }
-
- /* add to keyfile */
- as_inf_set_key (helper, key_new, kvsplit + 1);
- goto out;
- }
-
- /* last_line_continuation from the last line */
- if (helper->last_line_continuation) {
- g_autofree gchar *old = NULL;
- g_autofree gchar *new = NULL;
-
- /* this is the 1st pass, and we have no key */
- if (helper->last_line_continuation_ignore)
- goto out;
-
- /* eek, no key at all */
- if (helper->last_key == NULL) {
- ret = FALSE;
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "continued last but no key for %s", line);
- goto out;
- }
-
- /* get the old value of this */
- old = g_key_file_get_string (helper->keyfile,
- helper->group,
- helper->last_key,
- NULL);
- if (old == NULL) {
- ret = FALSE;
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "can't continue [%s] '%s': %s",
- helper->group, helper->last_key, line);
- goto out;
- }
-
- /* remove leading and trailing quote */
- if (!as_inf_strip_value (helper, line, error)) {
- ret = FALSE;
- goto out;
- }
-
- /* re-set key with new value */
- new = g_strdup_printf ("%s%s", old, line);
- as_inf_set_key (helper, helper->last_key, new);
- goto out;
- }
-
- /* there was left-over data but with no group defined */
- if (helper->group == NULL) {
- ret = FALSE;
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_FAILED,
- "fake key %s without [group]", line);
- goto out;
- }
-
- /* remove leading and trailing quote */
- if (!as_inf_strip_value (helper, line, error)) {
- ret = FALSE;
- goto out;
- }
-
- /* convert registry entries. e.g.
- * "HKR,,FirmwareFilename,,firmware.bin"
- * -> "HKR_FirmwareFilename"="firmware.bin"
- * "HKR,,FirmwareVersion,%REG_DWORD%,0x0000000"
- * -> "HKR_FirmwareVersion_0x00010001"="0x0000000" */
- if (g_strcmp0 (helper->group, "Firmware_AddReg") == 0 &&
- g_str_has_prefix (line, "HK")) {
- guint i;
- g_auto(GStrv) reg_split = NULL;
- g_autoptr(GString) str = NULL;
- str = g_string_new ("");
- reg_split = g_strsplit (line, ",", -1);
- for (i = 0; reg_split[i+1] != NULL; i++) {
- g_strstrip (reg_split[i]);
- if (reg_split[i][0] == '\0')
- continue;
- g_string_append_printf (str, "%s_", reg_split[i]);
- }
- if (str->len > 0) {
- g_autofree gchar *key_tmp = NULL;
-
- /* remove trailing '_' */
- g_string_truncate (str, str->len - 1);
-
- /* remove leading and trailing quote */
- g_strchug (reg_split[i]);
- if (!as_inf_strip_value (helper, reg_split[i], error)) {
- ret = FALSE;
- goto out;
- }
- if (helper->dict == NULL) {
- helper->require_2nd_pass = TRUE;
- helper->last_line_continuation_ignore = TRUE;
- goto out;
- }
- key_tmp = as_inf_replace_variable (helper, str->str, error);
- if (key_tmp == NULL)
- return FALSE;
- as_inf_set_key (helper, key_tmp, reg_split[i]);
- goto out;
- }
- }
-
- /* add fake key */
- key = g_strdup_printf ("value%03u", helper->nokey_idx++);
- as_inf_set_key (helper, key, line);
-out:
- helper->last_line_continuation = continuation;
- return ret;
-}
-
-static AsInfHelper *
-as_inf_helper_new (void)
-{
- AsInfHelper *helper;
- helper = g_new0 (AsInfHelper, 1);
- return helper;
-}
-
-static void
-as_inf_helper_free (AsInfHelper *helper)
-{
- if (helper->dict != NULL)
- g_hash_table_unref (helper->dict);
- g_key_file_unref (helper->keyfile);
- g_free (helper->comment);
- g_free (helper->group);
- g_free (helper->last_key);
- g_free (helper);
-}
-
/**
* as_inf_load_data:
* @keyfile: a #GKeyFile
@@ -745,66 +69,13 @@ as_inf_load_data (GKeyFile *keyfile,
AsInfLoadFlags flags,
GError **error)
{
- AsInfHelper *helper;
- gboolean ret = TRUE;
- guint i;
- g_auto(GStrv) lines = NULL;
-
- /* initialize helper */
- helper = as_inf_helper_new ();
- helper->flags = flags;
- helper->keyfile = g_key_file_ref (keyfile);
-
- /* verify each line, and make sane */
- lines = g_strsplit (data, "\n", -1);
- for (i = 0; lines[i] != NULL; i++) {
- if (!as_inf_parse_line (helper, lines[i], error)) {
- g_prefix_error (error,
- "Failed to parse line %u: ",
- i + 1);
- ret = FALSE;
- goto out;
- }
- }
-
- /* process every key in each group for strings we can substitute */
- helper->dict = as_inf_get_dict (helper, error);
- if (helper->dict == NULL) {
- ret = FALSE;
- goto out;
- }
-
- /* lets do this all over again */
- if (helper->require_2nd_pass) {
- g_auto(GStrv) lines2 = NULL;
- lines2 = g_strsplit (data, "\n", -1);
- for (i = 0; lines2[i] != NULL; i++) {
- if (!as_inf_parse_line (helper, lines2[i], error)) {
- g_prefix_error (error,
- "Failed to parse line %u: ",
- i + 1);
- ret = FALSE;
- goto out;
- }
- }
- }
-
- /* replace key values */
- if (!as_inf_replace_variables (helper, error)) {
- ret = FALSE;
- goto out;
- }
-out:
- as_inf_helper_free (helper);
- return ret;
+ g_set_error (error,
+ AS_INF_ERROR,
+ AS_INF_ERROR_FAILED,
+ "Loading .inf data is no longer suported, see libginf");
+ return FALSE;
}
-typedef struct {
- const gchar *id;
- const gchar *name;
- guint id_length;
-} AsInfBOM;
-
/**
* as_inf_load_file:
* @keyfile: a #GKeyFile
@@ -824,45 +95,11 @@ as_inf_load_file (GKeyFile *keyfile,
AsInfLoadFlags flags,
GError **error)
{
- const gchar *data_no_bom;
- gsize len;
- guint i;
- g_autofree gchar *data = NULL;
- AsInfBOM boms[] = { { "\x00\x00\xfe\xff", "UTF-32BE", 4 },
- { "\xff\xfe\x00\x00", "UTF-32LE", 4 },
- { "\xfe\xff", "UTF-16BE", 2 },
- { "\xff\xfe", "UTF-16LE", 2 },
- { "\xef\xbb\xbf", "UTF-8", 3 },
- { NULL, NULL, 0 } };
-
- if (!g_file_get_contents (filename, &data, &len, error))
- return FALSE;
-
- /* detect BOM */
- data_no_bom = data;
- for (i = 0; boms[i].id != NULL; i++) {
-
- /* BOM matches */
- if (len < boms[i].id_length)
- continue;
- if (memcmp (data, boms[i].id, boms[i].id_length) != 0)
- continue;
-
- /* ignore UTF-8 BOM */
- if (g_strcmp0 (boms[i].name, "UTF-8") == 0) {
- data_no_bom += boms[i].id_length;
- break;
- }
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_INVALID_TYPE,
- "File is encoded with %s and not supported",
- boms[i].name);
- return FALSE;
- }
-
- /* load data stripped of BOM */
- return as_inf_load_data (keyfile, data_no_bom, flags, error);
+ g_set_error (error,
+ AS_INF_ERROR,
+ AS_INF_ERROR_FAILED,
+ "Loading .inf files is no longer suported, see libginf");
+ return FALSE;
}
/**
@@ -880,55 +117,9 @@ as_inf_load_file (GKeyFile *keyfile,
gchar *
as_inf_get_driver_version (GKeyFile *keyfile, guint64 *timestamp, GError **error)
{
- g_autoptr(GDateTime) dt = NULL;
- g_auto(GStrv) split = NULL;
- g_auto(GStrv) dv_split = NULL;
- g_autofree gchar *driver_ver = NULL;
-
- /* get the release date and the version in case there's no metainfo */
- driver_ver = g_key_file_get_string (keyfile, "Version", "DriverVer", NULL);
- if (driver_ver == NULL) {
- g_set_error_literal (error,
- AS_INF_ERROR,
- AS_INF_ERROR_NOT_FOUND,
- "DriverVer is missing");
- return NULL;
- }
-
- /* split into driver date and version */
- dv_split = g_strsplit (driver_ver, ",", -1);
- if (g_strv_length (dv_split) != 2) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_INVALID_TYPE,
- "DriverVer is invalid: %s", driver_ver);
- return NULL;
- }
-
- /* split up into MM/DD/YYYY, because America */
- if (timestamp != NULL) {
- split = g_strsplit (dv_split[0], "/", -1);
- if (g_strv_length (split) != 3) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_INVALID_TYPE,
- "DriverVer date invalid: %s",
- dv_split[0]);
- return NULL;
- }
- dt = g_date_time_new_utc (atoi (split[2]),
- atoi (split[0]),
- atoi (split[1]),
- 0, 0, 0);
- if (dt == NULL) {
- g_set_error (error,
- AS_INF_ERROR,
- AS_INF_ERROR_INVALID_TYPE,
- "DriverVer date invalid: %s",
- dv_split[0]);
- return NULL;
- }
- *timestamp = (guint64) g_date_time_to_unix (dt);
- }
- return g_strdup (dv_split[1]);
+ g_set_error (error,
+ AS_INF_ERROR,
+ AS_INF_ERROR_FAILED,
+ "Loading .inf files is no longer suported, see libginf");
+ return NULL;
}
diff --git a/libappstream-glib/as-inf.h b/libappstream-glib/as-inf.h
index 2ebfd98..ba99184 100644
--- a/libappstream-glib/as-inf.h
+++ b/libappstream-glib/as-inf.h
@@ -68,14 +68,17 @@ GQuark as_inf_error_quark (void);
gboolean as_inf_load_data (GKeyFile *keyfile,
const gchar *data,
AsInfLoadFlags flags,
- GError **error);
+ GError **error)
+G_DEPRECATED;
gboolean as_inf_load_file (GKeyFile *keyfile,
const gchar *filename,
AsInfLoadFlags flags,
- GError **error);
+ GError **error)
+G_DEPRECATED;
gchar *as_inf_get_driver_version (GKeyFile *keyfile,
guint64 *timestamp,
- GError **error);
+ GError **error)
+G_DEPRECATED;
G_END_DECLS
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 7e56e60..bb6b0dc 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -36,7 +36,6 @@
#include "as-icon-private.h"
#include "as-image-private.h"
#include "as-review-private.h"
-#include "as-inf.h"
#include "as-markup.h"
#include "as-monitor.h"
#include "as-node-private.h"
@@ -2173,52 +2172,6 @@ as_test_app_parse_file_desktop_func (void)
}
static void
-as_test_app_parse_file_inf_func (void)
-{
- AsIcon *ic;
- AsRelease *rel;
- GError *error = NULL;
- GPtrArray *releases;
- gboolean ret;
- g_autofree gchar *filename = NULL;
- g_autoptr(AsApp) app = NULL;
-
- /* create an AsApp from a desktop file */
- app = as_app_new ();
- filename = as_test_get_filename ("example.inf");
- ret = as_app_parse_file (app,
- filename,
- AS_APP_PARSE_FLAG_NONE,
- &error);
- g_assert_no_error (error);
- g_assert (ret);
-
- /* test things we found */
- g_assert_cmpstr (as_app_get_name (app, "C"), ==, "ColorHug Firmware");
- g_assert_cmpstr (as_app_get_comment (app, "C"), ==,
- "Firmware for the ColorHug Colorimeter");
- g_assert_cmpstr (as_app_get_source_file (app), ==, filename);
- g_assert_cmpstr (as_app_get_id (app), ==, "84f40464-9272-4ef7-9399-cd95f12da695");
-
- /* check icon */
- g_assert_cmpint (as_app_get_icons(app)->len, ==, 1);
- ic = as_app_get_icon_default (app);
- g_assert (ic != NULL);
- g_assert_cmpstr (as_icon_get_name (ic), ==, "application-x-executable");
- g_assert_cmpint (as_icon_get_kind (ic), ==, AS_ICON_KIND_STOCK);
- g_assert_cmpint (as_icon_get_width (ic), ==, 0);
- g_assert_cmpint (as_icon_get_height (ic), ==, 0);
-
- /* check releases */
- releases = as_app_get_releases (app);
- g_assert_cmpint (releases->len, ==, 1);
- rel = g_ptr_array_index (releases, 0);
- g_assert_cmpint ((gint32) as_release_get_timestamp (rel), ==, 1425340800);
- g_assert_cmpstr (as_release_get_version (rel), ==, "0.2.2");
- //g_assert_cmpstr (as_release_get_description (rel), ==, "XXX");
-}
-
-static void
as_test_app_no_markup_func (void)
{
GError *error = NULL;
@@ -4653,313 +4606,6 @@ as_test_utils_vercmp_func (void)
}
static void
-as_test_inf_func (void)
-{
- GError *error = NULL;
- GKeyFile *kf;
- const gchar *data;
- gboolean ret;
- gchar *tmp;
- guint64 ts;
- g_autoptr(GDir) dir = NULL;
- g_autofree gchar *filename = NULL;
- g_autofree gchar *infs = NULL;
-
- /* case insensitive */
- kf = g_key_file_new ();
- ret = as_inf_load_data (kf, "[Version]\nClass=Firmware",
- AS_INF_LOAD_FLAG_CASE_INSENSITIVE, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "version", "class", NULL);
- g_assert_cmpstr (tmp, ==, "Firmware");
- g_free (tmp);
-
- /* section merging */
- ret = as_inf_load_data (kf, "[Version]\nPnpLockdown=1", 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "version", "class", NULL);
- g_assert_cmpstr (tmp, ==, "Firmware");
- g_free (tmp);
- tmp = g_key_file_get_string (kf, "Version", "PnpLockdown", NULL);
- g_assert_cmpstr (tmp, ==, "1");
- g_free (tmp);
-
- /* dequoting */
- ret = as_inf_load_data (kf, "[Version]\n"
- "PnpLockdown = \" 2 \"\n"
- "Empty = \"\"", 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Version", "PnpLockdown", NULL);
- g_assert_cmpstr (tmp, ==, " 2 ");
- g_free (tmp);
- tmp = g_key_file_get_string (kf, "Version", "Empty", NULL);
- g_assert_cmpstr (tmp, ==, "");
- g_free (tmp);
-
- /* autovalues */
- ret = as_inf_load_data (kf, "[RandomList]\nfilename.cap", 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "RandomList", "value000", NULL);
- g_assert_cmpstr (tmp, ==, "filename.cap");
- g_free (tmp);
-
- /* autovalues with quotes */
- ret = as_inf_load_data (kf, "[RandomList2]\n\"SomeRandomValue=1\"", 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "RandomList2", "value000", NULL);
- g_assert_cmpstr (tmp, ==, "SomeRandomValue=1");
- g_free (tmp);
-
- /* Dirids */
- ret = as_inf_load_data (kf, "[DriverServiceInst]\nServiceBinary=%12%\\service.exe", 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "DriverServiceInst", "ServiceBinary", NULL);
- g_assert_cmpstr (tmp, ==, "/tmp/service.exe");
- g_free (tmp);
-
- /* comments */
- data = "; group priority\n"
- "[Metadata] ; similar to [Version]\n"
- "Vendor=Hughski ; vendor name\n"
- "Owner=\"Richard; Ania\"\n"
- "; device name priority\n"
- "Device=\"ColorHug\" ; device name";
- ret = as_inf_load_data (kf, data, 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Metadata", "Vendor", NULL);
- g_assert_cmpstr (tmp, ==, "Hughski");
- g_free (tmp);
- tmp = g_key_file_get_string (kf, "Metadata", "Device", NULL);
- g_assert_cmpstr (tmp, ==, "ColorHug");
- g_free (tmp);
- tmp = g_key_file_get_string (kf, "Metadata", "Owner", NULL);
- g_assert_cmpstr (tmp, ==, "Richard; Ania");
- g_free (tmp);
-
- /* comment values */
- tmp = g_key_file_get_comment (kf, "Metadata", "Vendor", NULL);
- g_assert_cmpstr (tmp, ==, "vendor name\n");
- g_free (tmp);
- tmp = g_key_file_get_comment (kf, "Metadata", "Device", NULL);
- g_assert_cmpstr (tmp, ==, "device name priority\n");
- g_free (tmp);
- tmp = g_key_file_get_comment (kf, "Metadata", "Owner", NULL);
- g_assert_cmpstr (tmp, ==, NULL);
- g_free (tmp);
-// tmp = g_key_file_get_comment (kf, "metadata", NULL, NULL);
-// g_assert_cmpstr (tmp, ==, "group priority");
-// g_free (tmp);
-
- /* strings substitution */
- data = "[Version]\n"
- "Provider=Vendor was %Provider% now %Unknown% Ltd\n"
- "[Strings]\n"
- "Provider=Hughski\n";
- ret = as_inf_load_data (kf, data, 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Version", "Provider", NULL);
- g_assert_cmpstr (tmp, ==, "Vendor was Hughski now %Unknown% Ltd");
- g_free (tmp);
-
- /* continued lines */
- data = "[Version]\n"
- "Provider=Richard & \\\n"
- "Ania & \\\n"
- "Friends";
- ret = as_inf_load_data (kf, data, 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Version", "Provider", NULL);
- g_assert_cmpstr (tmp, ==, "Richard & Ania & Friends");
- g_free (tmp);
-
- /* multiline value */
- data = "[Metadata]\n"
- "UpdateDescription = \"This is a very \"long\" update \" |\n"
- " \"description designed to be shown \" |\n"
- " \"to the end user.\"";
- ret = as_inf_load_data (kf, data, 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Metadata", "UpdateDescription", NULL);
- g_assert_cmpstr (tmp, ==, "This is a very \"long\" update description "
- "designed to be shown to the end user.");
- g_free (tmp);
-
- /* substitution as the key name */
- data = "[Version]\n"
- "%Manufacturer.Foo% = \"Devices\"\n"
- "[Strings]\n"
- "Manufacturer.Foo = \"Hughski\"\n";
- ret = as_inf_load_data (kf, data, 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Version", "Hughski", NULL);
- g_assert_cmpstr (tmp, ==, "Devices");
- g_free (tmp);
-
- /* key names with double quotes */
- ret = as_inf_load_data (kf, "[\"Firmware\"]\nFoo=Bar\n", 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Firmware", "Foo", NULL);
- g_assert_cmpstr (tmp, ==, "Bar");
- g_free (tmp);
-
- /* unbalanced quotes */
- ret = as_inf_load_data (kf, "[Version]\nProvider = \"Hughski\n",
- AS_INF_LOAD_FLAG_STRICT, &error);
- g_assert_error (error, AS_INF_ERROR, AS_INF_ERROR_FAILED);
- g_assert (!ret);
- g_clear_error (&error);
- ret = as_inf_load_data (kf, "[Version]\nProvider = \"Hughski\n",
- AS_INF_LOAD_FLAG_NONE, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Version", "Provider", NULL);
- g_assert_cmpstr (tmp, ==, "Hughski");
- g_free (tmp);
-
- /* missing string replacement */
- ret = as_inf_load_data (kf, "[Version]\nProvider = \"%MISSING%\"\n",
- AS_INF_LOAD_FLAG_STRICT, &error);
- g_assert_error (error, AS_INF_ERROR, AS_INF_ERROR_FAILED);
- g_assert (!ret);
- g_clear_error (&error);
- ret = as_inf_load_data (kf, "[Version]\nProvider = \"%MISSING%\"\n",
- AS_INF_LOAD_FLAG_NONE, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Version", "Provider", NULL);
- g_assert_cmpstr (tmp, ==, "%MISSING%");
- g_free (tmp);
-
- /* invalid UTF-8 */
- ret = as_inf_load_data (kf, "[Version]\nProvider = Hughski \x99\n",
- AS_INF_LOAD_FLAG_STRICT, &error);
- g_assert_error (error, AS_INF_ERROR, AS_INF_ERROR_FAILED);
- g_assert (!ret);
- g_clear_error (&error);
- ret = as_inf_load_data (kf, "[Version]\nProvider = Hughski \x99\n",
- AS_INF_LOAD_FLAG_NONE, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = g_key_file_get_string (kf, "Version", "Provider", NULL);
- g_assert_cmpstr (tmp, ==, "Hughski ?");
- g_free (tmp);
-
- g_key_file_unref (kf);
-
- /* parse file */
- kf = g_key_file_new ();
- filename = as_test_get_filename ("example.inf");
- ret = as_inf_load_file (kf, filename, 0, &error);
- g_assert_no_error (error);
- g_assert (ret);
-
- /* simple */
- tmp = g_key_file_get_string (kf, "Version", "Class", NULL);
- g_assert_cmpstr (tmp, ==, "Firmware");
- g_free (tmp);
-
- /* HK */
- tmp = g_key_file_get_string (kf, "Firmware_AddReg", "HKR_FirmwareId", NULL);
- g_assert_cmpstr (tmp, ==, "{84f40464-9272-4ef7-9399-cd95f12da695}");
- g_free (tmp);
- tmp = g_key_file_get_string (kf, "Firmware_AddReg", "HKR_FirmwareVersion_0x00010001", NULL);
- g_assert_cmpstr (tmp, ==, "0x00020002");
- g_free (tmp);
- tmp = g_key_file_get_string (kf, "Firmware_AddReg", "HKR_FirmwareFilename", NULL);
- g_assert_cmpstr (tmp, ==, "firmware.bin");
- g_free (tmp);
-
- /* key replacement */
- tmp = g_key_file_get_string (kf, "Firmware_CopyFiles", "value000", NULL);
- g_assert_cmpstr (tmp, ==, "firmware.bin");
- g_free (tmp);
-
- /* double quotes swallowing */
- tmp = g_key_file_get_string (kf, "Strings", "FirmwareDesc", NULL);
- g_assert_cmpstr (tmp, ==, "ColorHug Firmware");
- g_free (tmp);
-
- /* string replacement */
- tmp = g_key_file_get_string (kf, "Version", "Provider", NULL);
- g_assert_cmpstr (tmp, ==, "Hughski");
- g_free (tmp);
-
- /* valid DriverVer */
- ret = as_inf_load_data (kf, "[Version]\n"
- "DriverVer = \"03/01/2015,2.0.0\"\n",
- AS_INF_LOAD_FLAG_NONE, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = as_inf_get_driver_version (kf, &ts, &error);
- g_assert_no_error (error);
- g_assert_cmpstr (tmp, ==, "2.0.0");
- g_assert_cmpint ((gint32) ts, ==, 1425168000);
- g_free (tmp);
-
- /* invalid DriverVer date */
- ret = as_inf_load_data (kf, "[Version]\n"
- "DriverVer = \"13/01/2015,2.0.0\"\n",
- AS_INF_LOAD_FLAG_NONE, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = as_inf_get_driver_version (kf, &ts, &error);
- g_assert_error (error, AS_INF_ERROR, AS_INF_ERROR_INVALID_TYPE);
- g_assert_cmpstr (tmp, ==, NULL);
- g_clear_error (&error);
-
- /* no DriverVer date */
- ret = as_inf_load_data (kf, "[Version]\n"
- "DriverVer = \"2.0.0\"\n",
- AS_INF_LOAD_FLAG_NONE, &error);
- g_assert_no_error (error);
- g_assert (ret);
- tmp = as_inf_get_driver_version (kf, &ts, &error);
- g_assert_error (error, AS_INF_ERROR, AS_INF_ERROR_INVALID_TYPE);
- g_assert_cmpstr (tmp, ==, NULL);
- g_clear_error (&error);
-
- g_key_file_unref (kf);
-
- /* test every .inf file from my Windows XP installation disk */
- infs = as_test_get_filename ("infs");
- if (infs != NULL) {
- dir = g_dir_open (infs, 0, NULL);
- while ((data = g_dir_read_name (dir)) != NULL) {
- g_autofree gchar *path = NULL;
- path = g_build_filename (infs, data, NULL);
- kf = g_key_file_new ();
- ret = as_inf_load_file (kf, path,
- AS_INF_LOAD_FLAG_NONE,
- &error);
- if (g_error_matches (error,
- AS_INF_ERROR,
- AS_INF_ERROR_INVALID_TYPE)) {
- g_clear_error (&error);
- } else {
- if (error != NULL)
- g_print ("Failed to process: %s\n",
- path);
- g_assert_no_error (error);
- g_assert (ret);
- }
- g_key_file_unref (kf);
- }
- }
-}
-
-static void
as_test_utils_install_filename_func (void)
{
gboolean ret;
@@ -5260,11 +4906,9 @@ main (int argc, char **argv)
g_test_add_func ("/AppStream/app{validate-meta-bad}", as_test_app_validate_meta_bad_func);
g_test_add_func ("/AppStream/app{validate-intltool}", as_test_app_validate_intltool_func);
g_test_add_func ("/AppStream/app{parse-file:desktop}", as_test_app_parse_file_desktop_func);
- g_test_add_func ("/AppStream/app{parse-file:inf}", as_test_app_parse_file_inf_func);
g_test_add_func ("/AppStream/app{no-markup}", as_test_app_no_markup_func);
g_test_add_func ("/AppStream/app{subsume}", as_test_app_subsume_func);
g_test_add_func ("/AppStream/app{search}", as_test_app_search_func);
- g_test_add_func ("/AppStream/inf", as_test_inf_func);
g_test_add_func ("/AppStream/markup{import-html}", as_test_markup_import_html);
g_test_add_func ("/AppStream/node", as_test_node_func);
g_test_add_func ("/AppStream/node{reflow}", as_test_node_reflow_text_func);
diff --git a/libappstream-glib/as-store-cab.c b/libappstream-glib/as-store-cab.c
index a46460e..63c1e0c 100644
--- a/libappstream-glib/as-store-cab.c
+++ b/libappstream-glib/as-store-cab.c
@@ -330,68 +330,6 @@ as_store_cab_from_bytes_with_origin (AsStore *store,
as_store_add_app (store, app);
}
- /* if we provided an .inf file check the values matched */
- for (i = 0; i < filelist->len; i++) {
- AsApp *app_tmp;
- AsChecksum *csum_inf;
- AsChecksum *csum_metainfo;
- AsRelease *rel_inf;
- AsRelease *rel_metainfo;
- const gchar *fn;
- g_autoptr(AsApp) app_inf = NULL;
- g_autofree gchar *tmp_fn = NULL;
-
- fn = g_ptr_array_index (filelist, i);
- if (as_app_guess_source_kind (fn) != AS_APP_SOURCE_KIND_INF)
- continue;
-
- /* get the id from the store */
- app_inf = as_app_new ();
- tmp_fn = g_build_filename (tmp_path, fn, NULL);
- if (!as_app_parse_file (app_inf, tmp_fn, AS_APP_PARSE_FLAG_NONE, error))
- return FALSE;
- app_tmp = as_store_get_app_by_provide (store,
- AS_PROVIDE_KIND_FIRMWARE_FLASHED,
- as_app_get_id (app_inf));
- if (app_tmp == NULL) {
- g_set_error (error,
- AS_STORE_ERROR,
- AS_STORE_ERROR_FAILED,
- "no metainfo file with provide %s",
- as_app_get_id (app_inf));
- return FALSE;
- }
-
- /* check the version matches */
- rel_inf = as_app_get_release_default (app_inf);
- rel_metainfo = as_app_get_release_default (app_tmp);
- if (as_release_get_version (rel_inf) != NULL &&
- as_utils_vercmp (as_release_get_version (rel_inf),
- as_release_get_version (rel_metainfo)) != 0) {
- g_set_error (error,
- AS_STORE_ERROR,
- AS_STORE_ERROR_FAILED,
- "metainfo version is %s while inf has %s",
- as_release_get_version (rel_metainfo),
- as_release_get_version (rel_inf));
- return FALSE;
- }
-
- /* verify Firmware_CopyFiles matches */
- csum_inf = as_release_get_checksum_by_target (rel_inf, AS_CHECKSUM_TARGET_CONTENT);
- csum_metainfo = as_release_get_checksum_by_target (rel_metainfo, AS_CHECKSUM_TARGET_CONTENT);
- if (g_strcmp0 (as_checksum_get_filename (csum_inf),
- as_checksum_get_filename (csum_metainfo)) != 0) {
- g_set_error (error,
- AS_STORE_ERROR,
- AS_STORE_ERROR_FAILED,
- "metainfo filename is %s while inf has %s",
- as_checksum_get_filename (csum_metainfo),
- as_checksum_get_filename (csum_inf));
- return FALSE;
- }
- }
-
/* delete temp files */
for (i = 0; i < filelist->len; i++) {
const gchar *fn;