/** * as_app_parse_desktop_file: **/ gboolean as_app_parse_desktop_file (AsApp *app, const gchar *desktop_file, AsAppParseFlags flags, GError **error) { GKeyFileFlags kf_flags = G_KEY_FILE_KEEP_TRANSLATIONS; gchar *tmp; guint i; g_autoptr(GError) error_local = NULL; g_autofree gchar *app_id = NULL; g_autoptr(GKeyFile) kf = NULL; g_auto(GStrv) keys = NULL; /* load file */ kf = g_key_file_new (); if (flags & AS_APP_PARSE_FLAG_KEEP_COMMENTS) kf_flags |= G_KEY_FILE_KEEP_COMMENTS; if (!g_key_file_load_from_file (kf, desktop_file, kf_flags, &error_local)) { g_set_error (error, AS_APP_ERROR, AS_APP_ERROR_INVALID_TYPE, "Failed to parse %s: %s", desktop_file, error_local->message); return FALSE; } /* create app */ app_id = g_path_get_basename (desktop_file); as_app_set_id_kind (app, AS_ID_KIND_DESKTOP); /* is blacklisted */ if (as_utils_is_blacklisted_id (app_id)) as_app_add_veto (app, "%s is not an application", app_id); /* Ubuntu helpfully put the package name in the desktop file name */ tmp = g_strstr_len (app_id, -1, ":"); if (tmp != NULL) as_app_set_id (app, tmp + 1); else as_app_set_id (app, app_id); /* look at all the keys */ keys = g_key_file_get_keys (kf, G_KEY_FILE_DESKTOP_GROUP, NULL, error); if (keys == NULL) return FALSE; for (i = 0; keys[i] != NULL; i++) { if (!as_app_parse_file_key (app, kf, keys[i], flags, error)) return FALSE; if ((flags & AS_APP_PARSE_FLAG_USE_HEURISTICS) > 0) { if (!as_app_infer_file_key (app, kf, keys[i], error)) return FALSE; } } /* perform any fallbacks */ if ((flags & AS_APP_PARSE_FLAG_USE_FALLBACKS) > 0 && as_app_get_comment_size (app) == 0) { for (i = 0; keys[i] != NULL; i++) { if (!as_app_parse_file_key_fallback_comment (app, kf, keys[i], error)) return FALSE; } } /* all applications require icons */ if (as_app_get_icons(app)->len == 0) as_app_add_veto (app, "%s has no icon", app_id); return TRUE; }
/** * asb_plugin_process: */ GList * asb_plugin_process (AsbPlugin *plugin, AsbPackage *pkg, const gchar *tmpdir, GError **error) { const gchar *tmp; gchar **split; GList *apps = NULL; GPtrArray *keywords; guint i; guint j; _cleanup_free_ gchar *app_id = NULL; _cleanup_object_unref_ AsbApp *app = NULL; _cleanup_object_unref_ AsIcon *icon = NULL; _cleanup_string_free_ GString *str = NULL; /* use the pkgname suffix as the app-id */ tmp = asb_package_get_name (pkg); if (g_str_has_prefix (tmp, "gstreamer1-")) tmp += 11; if (g_str_has_prefix (tmp, "gstreamer-")) tmp += 10; if (g_str_has_prefix (tmp, "plugins-")) tmp += 8; app_id = g_strdup_printf ("gstreamer-%s", tmp); /* create app */ app = asb_app_new (pkg, app_id); as_app_set_id_kind (AS_APP (app), AS_ID_KIND_CODEC); as_app_set_name (AS_APP (app), "C", "GStreamer Multimedia Codecs", -1); asb_app_set_requires_appdata (app, TRUE); asb_app_set_hidpi_enabled (app, asb_context_get_hidpi_enabled (plugin->ctx)); as_app_add_category (AS_APP (app), "Addons", -1); as_app_add_category (AS_APP (app), "Codecs", -1); /* add icon */ icon = as_icon_new (); as_icon_set_kind (icon, AS_ICON_KIND_STOCK); as_icon_set_name (icon, "application-x-executable", -1); as_app_add_icon (AS_APP (app), icon); for (i = 0; data[i].path != NULL; i++) { if (!asb_utils_is_file_in_tmpdir (tmpdir, data[i].path)) continue; split = g_strsplit (data[i].text, "|", -1); for (j = 0; split[j] != NULL; j++) as_app_add_keyword (AS_APP (app), NULL, split[j], -1); g_strfreev (split); } /* no codecs we care about */ keywords = as_app_get_keywords (AS_APP (app), NULL); if (keywords == NULL) { g_set_error (error, ASB_PLUGIN_ERROR, ASB_PLUGIN_ERROR_FAILED, "nothing interesting in %s", asb_package_get_basename (pkg)); return NULL; } /* sort categories by name */ g_ptr_array_sort (keywords, asb_utils_string_sort_cb); /* create a description */ str = g_string_new ("Multimedia playback for "); if (keywords->len > 1) { for (i = 0; i < keywords->len - 1; i++) { tmp = g_ptr_array_index (keywords, i); g_string_append_printf (str, "%s, ", tmp); } g_string_truncate (str, str->len - 2); tmp = g_ptr_array_index (keywords, keywords->len - 1); g_string_append_printf (str, " and %s", tmp); } else { g_string_append (str, g_ptr_array_index (keywords, 0)); } as_app_set_comment (AS_APP (app), "C", str->str, -1); /* add */ asb_plugin_add_app (&apps, AS_APP (app)); return apps; }
/** * cra_plugin_process_filename: */ static gboolean cra_plugin_process_filename (CraPlugin *plugin, CraPackage *pkg, const gchar *filename, GList **apps, const gchar *tmpdir, GError **error) { GNode *root = NULL; GString *valid_xml; const gchar *tmp; const GNode *n; gboolean found_header = FALSE; gboolean ret; guint i; _cleanup_free_ gchar *basename = NULL; _cleanup_free_ gchar *data = NULL; _cleanup_free_ gchar *filename_tmp; _cleanup_object_unref_ CraApp *app = NULL; _cleanup_strv_free_ gchar **languages = NULL; _cleanup_strv_free_ gchar **lines = NULL; /* open file */ filename_tmp = g_build_filename (tmpdir, filename, NULL); ret = g_file_get_contents (filename_tmp, &data, NULL, error); if (!ret) goto out; /* some components start with a comment (invalid XML) and some * don't even have '<?xml' -- try to fix up best we can */ valid_xml = g_string_new (""); lines = g_strsplit (data, "\n", -1); for (i = 0; lines[i] != NULL; i++) { if (g_str_has_prefix (lines[i], "<?xml") || g_str_has_prefix (lines[i], "<component>")) found_header = TRUE; if (found_header) g_string_append_printf (valid_xml, "%s\n", lines[i]); } /* parse contents */ root = as_node_from_xml (valid_xml->str, -1, AS_NODE_FROM_XML_FLAG_NONE, error); if (!ret) goto out; /* create new app */ basename = g_path_get_basename (filename); app = cra_app_new (pkg, basename); as_app_set_id_kind (AS_APP (app), AS_ID_KIND_INPUT_METHOD); as_app_add_category (AS_APP (app), "Addons", -1); as_app_add_category (AS_APP (app), "InputSources", -1); as_app_set_icon (AS_APP (app), "system-run-symbolic", -1); as_app_set_icon_kind (AS_APP (app), AS_ICON_KIND_STOCK); cra_app_set_requires_appdata (app, TRUE); /* read the component header which all input methods have */ n = as_node_find (root, "component/description"); if (n != NULL) { as_app_set_name (AS_APP (app), "C", as_node_get_data (n), -1); as_app_set_comment (AS_APP (app), "C", as_node_get_data (n), -1); } n = as_node_find (root, "component/homepage"); if (n != NULL) { as_app_add_url (AS_APP (app), AS_URL_KIND_HOMEPAGE, as_node_get_data (n), -1); } /* do we have a engine section we can use? */ n = as_node_find (root, "component/engines/engine/longname"); if (n != NULL) as_app_set_name (AS_APP (app), "C", as_node_get_data (n), -1); n = as_node_find (root, "component/engines/engine/description"); if (n != NULL) as_app_set_comment (AS_APP (app), "C", as_node_get_data (n), -1); n = as_node_find (root, "component/engines/engine/symbol"); if (n != NULL) { tmp = as_node_get_data (n); if (tmp != NULL && tmp[0] != '\0') { as_app_add_metadata (AS_APP (app), "X-IBus-Symbol", tmp, -1); } } n = as_node_find (root, "component/engines/engine/language"); if (n != NULL) { tmp = as_node_get_data (n); if (tmp != NULL) { languages = g_strsplit (tmp, ",", -1); for (i = 0; languages[i] != NULL; i++) { if (g_strcmp0 (languages[i], "other") == 0) continue; as_app_add_language (AS_APP (app), 100, languages[i], -1); } } } /* add */ cra_plugin_add_app (apps, app); out: if (root != NULL) as_node_unref (root); return ret; }
/** * asb_plugin_process_filename: */ static gboolean asb_plugin_process_filename (AsbPlugin *plugin, AsbPackage *pkg, const gchar *filename, GList **apps, const gchar *tmpdir, GError **error) { gboolean ret = TRUE; gchar *error_msg = 0; gchar *filename_tmp; gint rc; guint i; sqlite3 *db = NULL; _cleanup_free_ gchar *basename = NULL; _cleanup_free_ gchar *description = NULL; _cleanup_free_ gchar *language_string = NULL; _cleanup_free_ gchar *name = NULL; _cleanup_free_ gchar *symbol = NULL; _cleanup_object_unref_ AsbApp *app = NULL; _cleanup_object_unref_ AsIcon *icon = NULL; _cleanup_strv_free_ gchar **languages = NULL; /* open IME database */ filename_tmp = g_build_filename (tmpdir, filename, NULL); rc = sqlite3_open (filename_tmp, &db); if (rc) { ret = FALSE; g_set_error (error, ASB_PLUGIN_ERROR, ASB_PLUGIN_ERROR_FAILED, "Can't open database: %s", sqlite3_errmsg (db)); goto out; } /* get name */ rc = sqlite3_exec(db, "SELECT * FROM ime WHERE attr = 'name' LIMIT 1;", asb_plugin_sqlite_callback_cb, &name, &error_msg); if (rc != SQLITE_OK) { ret = FALSE; g_set_error (error, ASB_PLUGIN_ERROR, ASB_PLUGIN_ERROR_FAILED, "Can't get IME name from %s: %s", filename, error_msg); sqlite3_free(error_msg); goto out; } /* get symbol */ rc = sqlite3_exec(db, "SELECT * FROM ime WHERE attr = 'symbol' LIMIT 1;", asb_plugin_sqlite_callback_cb, &symbol, &error_msg); if (rc != SQLITE_OK) { ret = FALSE; g_set_error (error, ASB_PLUGIN_ERROR, ASB_PLUGIN_ERROR_FAILED, "Can't get IME symbol from %s: %s", filename, error_msg); sqlite3_free(error_msg); goto out; } /* get languages */ rc = sqlite3_exec(db, "SELECT * FROM ime WHERE attr = 'languages' LIMIT 1;", asb_plugin_sqlite_callback_cb, &language_string, &error_msg); if (rc != SQLITE_OK) { ret = FALSE; g_set_error (error, ASB_PLUGIN_ERROR, ASB_PLUGIN_ERROR_FAILED, "Can't get IME languages from %s: %s", filename, error_msg); sqlite3_free(error_msg); goto out; } /* get description */ rc = sqlite3_exec(db, "SELECT * FROM ime WHERE attr = 'description' LIMIT 1;", asb_plugin_sqlite_callback_cb, &description, &error_msg); if (rc != SQLITE_OK) { ret = FALSE; g_set_error (error, ASB_PLUGIN_ERROR, ASB_PLUGIN_ERROR_FAILED, "Can't get IME name from %s: %s", filename, error_msg); sqlite3_free(error_msg); goto out; } /* this is _required_ */ if (name == NULL || description == NULL) { ret = FALSE; g_set_error (error, ASB_PLUGIN_ERROR, ASB_PLUGIN_ERROR_FAILED, "No 'name' and 'description' in %s", filename); goto out; } /* create new app */ basename = g_path_get_basename (filename); app = asb_app_new (pkg, basename); as_app_set_id_kind (AS_APP (app), AS_ID_KIND_INPUT_METHOD); as_app_add_category (AS_APP (app), "Addons"); as_app_add_category (AS_APP (app), "InputSources"); as_app_set_name (AS_APP (app), "C", name); as_app_set_comment (AS_APP (app), "C", description); if (symbol != NULL && symbol[0] != '\0') as_app_add_metadata (AS_APP (app), "X-IBus-Symbol", symbol); if (language_string != NULL) { languages = g_strsplit (language_string, ",", -1); for (i = 0; languages[i] != NULL; i++) { if (g_strcmp0 (languages[i], "other") == 0) continue; as_app_add_language (AS_APP (app), 100, languages[i]); } } asb_app_set_requires_appdata (app, TRUE); asb_app_set_hidpi_enabled (app, asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_HIDPI_ICONS)); /* add icon */ icon = as_icon_new (); as_icon_set_kind (icon, AS_ICON_KIND_STOCK); as_icon_set_name (icon, "system-run-symbolic"); as_app_add_icon (AS_APP (app), icon); asb_plugin_add_app (apps, AS_APP (app)); out: if (db != NULL) sqlite3_close (db); return ret; }
/** * fu_util_verify_update: **/ static gboolean fu_util_verify_update (FuUtilPrivate *priv, gchar **values, GError **error) { guint i; _cleanup_object_unref_ AsStore *store = NULL; _cleanup_object_unref_ GFile *xml_file = NULL; if (g_strv_length (values) < 2) { g_set_error_literal (error, FWUPD_ERROR, FWUPD_ERROR_INTERNAL, "Invalid arguments: expected 'filename.xml' 'filename.rom'"); return FALSE; } store = as_store_new (); /* open existing file */ xml_file = g_file_new_for_path (values[0]); if (g_file_query_exists (xml_file, NULL)) { if (!as_store_from_file (store, xml_file, NULL, NULL, error)) return FALSE; } /* add new values */ as_store_set_api_version (store, 0.9); for (i = 1; values[i] != NULL; i++) { _cleanup_free_ gchar *guid = NULL; _cleanup_free_ gchar *id = NULL; _cleanup_object_unref_ AsApp *app = NULL; _cleanup_object_unref_ AsRelease *rel = NULL; _cleanup_object_unref_ FuRom *rom = NULL; _cleanup_object_unref_ GFile *file = NULL; _cleanup_error_free_ GError *error_local = NULL; file = g_file_new_for_path (values[i]); rom = fu_rom_new (); g_print ("Processing %s...\n", values[i]); if (!fu_rom_load_file (rom, file, FU_ROM_LOAD_FLAG_BLANK_PPID, NULL, &error_local)) { g_print ("%s\n", error_local->message); continue; } /* add app to store */ app = as_app_new (); id = g_strdup_printf ("0x%04x:0x%04x", fu_rom_get_vendor (rom), fu_rom_get_model (rom)); guid = fu_guid_generate_from_string (id); as_app_set_id (app, guid, -1); as_app_set_id_kind (app, AS_ID_KIND_FIRMWARE); as_app_set_source_kind (app, AS_APP_SOURCE_KIND_INF); rel = as_release_new (); as_release_set_version (rel, fu_rom_get_version (rom), -1); as_release_set_checksum (rel, G_CHECKSUM_SHA1, fu_rom_get_checksum (rom), -1); as_app_add_release (app, rel); as_store_add_app (store, app); } if (!as_store_to_file (store, xml_file, AS_NODE_TO_XML_FLAG_ADD_HEADER | AS_NODE_TO_XML_FLAG_FORMAT_INDENT | AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE, NULL, error)) return FALSE; return TRUE; }