1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.1+
6 */
7
8 /**
9 * SECTION:asb-plugin
10 * @short_description: Generic plugin helpers.
11 * @stability: Unstable
12 *
13 * Utilities for plugins.
14 */
15
16 #include "config.h"
17
18 #include <glib.h>
19 #include <fnmatch.h>
20
21 #include "asb-plugin.h"
22 #include "asb-utils.h"
23
24 /**
25 * asb_plugin_process:
26 * @plugin: A #AsbPlugin
27 * @pkg: A #AsbPackage
28 * @tmpdir: the temporary location
29 * @error: A #GError or %NULL
30 *
31 * Runs a function on a specific plugin.
32 *
33 * Returns: (transfer none) (element-type AsbApp): applications
34 *
35 * Since: 0.1.0
36 **/
37 GList *
asb_plugin_process(AsbPlugin * plugin,AsbPackage * pkg,const gchar * tmpdir,GError ** error)38 asb_plugin_process (AsbPlugin *plugin,
39 AsbPackage *pkg,
40 const gchar *tmpdir,
41 GError **error)
42 {
43 AsbPluginProcessFunc plugin_func = NULL;
44 gboolean ret;
45
46 /* run each plugin */
47 asb_package_log (pkg,
48 ASB_PACKAGE_LOG_LEVEL_DEBUG,
49 "Running asb_plugin_process() from %s",
50 plugin->name);
51 ret = g_module_symbol (plugin->module,
52 "asb_plugin_process",
53 (gpointer *) &plugin_func);
54 if (!ret) {
55 g_set_error_literal (error,
56 ASB_PLUGIN_ERROR,
57 ASB_PLUGIN_ERROR_FAILED,
58 "no asb_plugin_process");
59 return NULL;
60 }
61 return plugin_func (plugin, pkg, tmpdir, error);
62 }
63
64 /**
65 * asb_plugin_add_app:
66 * @list: (element-type AsApp): A list of #AsApp's
67 * @app: A #AsApp
68 *
69 * Adds an application to a list.
70 *
71 * Since: 0.1.0
72 **/
73 void
asb_plugin_add_app(GList ** list,AsApp * app)74 asb_plugin_add_app (GList **list, AsApp *app)
75 {
76 *list = g_list_prepend (*list, g_object_ref (app));
77 }
78
79 /**
80 * asb_plugin_add_glob:
81 * @array: (element-type utf8): A #GPtrArray
82 * @glob: a filename glob
83 *
84 * Adds a glob from the plugin.
85 *
86 * Since: 0.1.0
87 **/
88 void
asb_plugin_add_glob(GPtrArray * array,const gchar * glob)89 asb_plugin_add_glob (GPtrArray *array, const gchar *glob)
90 {
91 g_ptr_array_add (array, asb_glob_value_new (glob, ""));
92 }
93
94 /**
95 * asb_plugin_match_glob:
96 * @glob: a filename glob
97 * @value: a filename value
98 *
99 * Matches a value against a glob.
100 *
101 * Since: 0.3.5
102 **/
103 gboolean
asb_plugin_match_glob(const gchar * glob,const gchar * value)104 asb_plugin_match_glob (const gchar *glob, const gchar *value)
105 {
106 return (fnmatch (glob, value, 0) == 0);
107 }
108