/** * as_provide_node_parse: * @provide: a #AsProvide instance. * @node: a #GNode. * @ctx: a #AsNodeContext. * @error: A #GError or %NULL. * * Populates the object from a DOM node. * * Returns: %TRUE for success * * Since: 0.1.6 **/ gboolean as_provide_node_parse (AsProvide *provide, GNode *node, AsNodeContext *ctx, GError **error) { AsProvidePrivate *priv = GET_PRIVATE (provide); const gchar *tmp; if (g_strcmp0 (as_node_get_name (node), "dbus") == 0) { tmp = as_node_get_attribute (node, "type"); if (g_strcmp0 (tmp, "system") == 0) priv->kind = AS_PROVIDE_KIND_DBUS_SYSTEM; else priv->kind = AS_PROVIDE_KIND_DBUS_SESSION; } else if (g_strcmp0 (as_node_get_name (node), "firmware") == 0) { tmp = as_node_get_attribute (node, "type"); if (g_strcmp0 (tmp, "flashed") == 0) priv->kind = AS_PROVIDE_KIND_FIRMWARE_FLASHED; else priv->kind = AS_PROVIDE_KIND_FIRMWARE_RUNTIME; } else { priv->kind = as_provide_kind_from_string (as_node_get_name (node)); } as_ref_string_assign (&priv->value, as_node_get_data_as_refstr (node)); return TRUE; }
/** * as_require_node_parse: * @require: a #AsRequire instance. * @node: a #GNode. * @ctx: a #AsNodeContext. * @error: A #GError or %NULL. * * Populates the object from a DOM node. * * Returns: %TRUE for success * * Since: 0.6.7 **/ gboolean as_require_node_parse (AsRequire *require, GNode *node, AsNodeContext *ctx, GError **error) { AsRequirePrivate *priv = GET_PRIVATE (require); const gchar *tmp; tmp = as_node_get_name (node); if (tmp != NULL) as_require_set_kind (require, as_require_kind_from_string (tmp)); tmp = as_node_get_attribute (node, "compare"); if (tmp != NULL) as_require_set_compare (require, as_require_compare_from_string (tmp)); as_ref_string_assign (&priv->version, as_node_get_attribute_as_refstr (node, "version")); as_ref_string_assign (&priv->value, as_node_get_data_as_refstr (node)); return TRUE; }
/** * asb_plugin_process_gir: */ static gboolean asb_plugin_process_gir (AsbApp *app, const gchar *tmpdir, const gchar *filename, GError **error) { GNode *l; GNode *node = NULL; const gchar *name; const gchar *version; gboolean ret = TRUE; g_autofree gchar *filename_full = NULL; g_autoptr(GFile) file = NULL; /* load file */ filename_full = g_build_filename (tmpdir, filename, NULL); file = g_file_new_for_path (filename_full); node = as_node_from_file (file, AS_NODE_FROM_XML_FLAG_NONE, NULL, error); if (node == NULL) { ret = FALSE; goto out; } /* look for includes */ l = as_node_find (node, "repository"); if (l == NULL) goto out; for (l = l->children; l != NULL; l = l->next) { if (g_strcmp0 (as_node_get_name (l), "include") != 0) continue; name = as_node_get_attribute (l, "name"); version = as_node_get_attribute (l, "version"); if (g_strcmp0 (name, "Gtk") == 0 && g_strcmp0 (version, "3.0") == 0) { asb_package_log (asb_app_get_package (app), ASB_PACKAGE_LOG_LEVEL_DEBUG, "Auto-adding kudo ModernToolkit for %s", as_app_get_id (AS_APP (app))); as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_MODERN_TOOLKIT); } } out: if (node != NULL) as_node_unref (node); return ret; }
static gboolean as_app_validate_description (const gchar *xml, AsAppValidateHelper *helper, guint number_para_min, guint number_para_max, gboolean allow_short_para, GError **error) { GNode *l; GNode *l2; g_autoptr(AsNode) node = NULL; /* parse xml */ node = as_node_from_xml (xml, AS_NODE_FROM_XML_FLAG_NONE, error); if (node == NULL) return FALSE; helper->number_paragraphs = 0; helper->previous_para_was_short = FALSE; for (l = node->children; l != NULL; l = l->next) { if (g_strcmp0 (as_node_get_name (l), "p") == 0) { if (as_node_get_attribute (l, "xml:lang") != NULL) continue; as_app_validate_description_para (as_node_get_data (l), helper); } else if (g_strcmp0 (as_node_get_name (l), "ul") == 0 || g_strcmp0 (as_node_get_name (l), "ol") == 0) { as_app_validate_description_list (as_node_get_data (l), allow_short_para, helper); for (l2 = l->children; l2 != NULL; l2 = l2->next) { if (g_strcmp0 (as_node_get_name (l2), "li") == 0) { if (as_node_get_attribute (l2, "xml:lang") != NULL) continue; as_app_validate_description_li (as_node_get_data (l2), helper); } else { /* only <li> supported */ g_set_error (error, AS_APP_ERROR, AS_APP_ERROR_FAILED, "invalid markup: <%s> follows <%s>", as_node_get_name (l2), as_node_get_name (l)); return FALSE; } } } else { /* only <p>, <ol> and <ul> supported */ g_set_error (error, AS_APP_ERROR, AS_APP_ERROR_FAILED, "invalid markup: tag <%s> invalid here", as_node_get_name (l)); return FALSE; } } /* previous paragraph wasn't long enough */ if (helper->previous_para_was_short) { ai_app_validate_add (helper, AS_PROBLEM_KIND_STYLE_INCORRECT, "<p> is too short [%s]", helper->previous_para_was_short_str); } if (helper->number_paragraphs < number_para_min) { ai_app_validate_add (helper, AS_PROBLEM_KIND_STYLE_INCORRECT, "Not enough <p> tags for a good description [%u/%u]", helper->number_paragraphs, number_para_min); } if (helper->number_paragraphs > number_para_max) { ai_app_validate_add (helper, AS_PROBLEM_KIND_STYLE_INCORRECT, "Too many <p> tags for a good description [%u/%u]", helper->number_paragraphs, number_para_max); } return TRUE; }
/** * as_markup_convert_full: * @markup: the text to copy. * @format: the #AsMarkupConvertFormat, e.g. %AS_MARKUP_CONVERT_FORMAT_MARKDOWN * @flags: the #AsMarkupConvertFlag, e.g. %AS_MARKUP_CONVERT_FLAG_IGNORE_ERRORS * @error: A #GError or %NULL * * Converts an XML description into a printable form. * * Returns: (transfer full): a newly allocated %NULL terminated string * * Since: 0.3.5 **/ gchar * as_markup_convert_full (const gchar *markup, AsMarkupConvertFormat format, AsMarkupConvertFlag flags, GError **error) { GNode *tmp; GNode *tmp_c; const gchar *tag; const gchar *tag_c; g_autoptr(AsNode) root = NULL; g_autoptr(GError) error_local = NULL; g_autoptr(GString) str = NULL; /* is this actually markup */ if (g_strstr_len (markup, -1, "<") == NULL) return g_strdup (markup); /* load */ root = as_node_from_xml (markup, AS_NODE_FROM_XML_FLAG_NONE, &error_local); if (root == NULL) { /* truncate to the last tag and try again */ if (flags & AS_MARKUP_CONVERT_FLAG_IGNORE_ERRORS) { gchar *found; g_autofree gchar *markup_new = NULL; markup_new = g_strdup (markup); found = g_strrstr (markup_new, "<"); g_assert (found != NULL); *found = '\0'; return as_markup_convert_full (markup_new, format, flags, error); } /* just return error */ g_propagate_error (error, error_local); error_local = NULL; return NULL; } /* format */ str = g_string_new (""); for (tmp = root->children; tmp != NULL; tmp = tmp->next) { tag = as_node_get_name (tmp); if (g_strcmp0 (tag, "unknown") == 0) continue; if (g_strcmp0 (tag, "p") == 0) { as_markup_render_para (str, format, as_node_get_data (tmp)); continue; } /* loop on the children */ if (g_strcmp0 (tag, "ul") == 0 || g_strcmp0 (tag, "ol") == 0) { as_markup_render_ul_start (str, format); for (tmp_c = tmp->children; tmp_c != NULL; tmp_c = tmp_c->next) { tag_c = as_node_get_name (tmp_c); if (g_strcmp0 (tag_c, "unknown") == 0) continue; if (g_strcmp0 (tag_c, "li") == 0) { as_markup_render_li (str, format, as_node_get_data (tmp_c)); continue; } /* just abort the list */ if (flags & AS_MARKUP_CONVERT_FLAG_IGNORE_ERRORS) break; /* only <li> is valid in lists */ g_set_error (error, AS_NODE_ERROR, AS_NODE_ERROR_FAILED, "Tag %s in %s invalid", tag_c, tag); return NULL; } as_markup_render_ul_end (str, format); continue; } /* just try again */ if (flags & AS_MARKUP_CONVERT_FLAG_IGNORE_ERRORS) continue; /* only <p>, <ul> and <ol> is valid here */ g_set_error (error, AS_NODE_ERROR, AS_NODE_ERROR_FAILED, "Unknown tag '%s'", tag); return NULL; } /* success */ switch (format) { case AS_MARKUP_CONVERT_FORMAT_SIMPLE: case AS_MARKUP_CONVERT_FORMAT_MARKDOWN: if (str->len > 0) g_string_truncate (str, str->len - 1); break; default: break; } return g_strdup (str->str); }