1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <fnmatch.h>
#include <asb-plugin.h>
/**
* asb_plugin_get_name:
*/
const gchar *
asb_plugin_get_name (void)
{
return "dbus";
}
/**
* asb_plugin_add_globs:
*/
void
asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs)
{
asb_plugin_add_glob (globs, "/usr/share/dbus-1/system-services/*.service");
asb_plugin_add_glob (globs, "/usr/share/dbus-1/services/*.service");
}
/**
* _asb_plugin_check_filename_system:
*/
static gboolean
_asb_plugin_check_filename_system (const gchar *filename)
{
if (asb_plugin_match_glob ("/usr/share/dbus-1/system-services/*.service", filename))
return TRUE;
return FALSE;
}
/**
* _asb_plugin_check_filename_session:
*/
static gboolean
_asb_plugin_check_filename_session (const gchar *filename)
{
if (asb_plugin_match_glob ("/usr/share/dbus-1/services/*.service", filename))
return TRUE;
return FALSE;
}
/**
* asb_plugin_process_dbus:
*/
static gboolean
asb_plugin_process_dbus (AsbApp *app,
const gchar *tmpdir,
const gchar *filename,
gboolean is_system,
GError **error)
{
g_autofree gchar *filename_full = NULL;
g_autofree gchar *name = NULL;
g_autoptr(GKeyFile) kf = NULL;
g_autoptr(AsProvide) provide = NULL;
/* load file */
filename_full = g_build_filename (tmpdir, filename, NULL);
kf = g_key_file_new ();
if (!g_key_file_load_from_file (kf, filename_full, G_KEY_FILE_NONE, error))
return FALSE;
name = g_key_file_get_string (kf, "D-BUS Service", "Name", error);
if (name == NULL)
return FALSE;
/* add provide */
provide = as_provide_new ();
as_provide_set_kind (provide, is_system ? AS_PROVIDE_KIND_DBUS_SYSTEM :
AS_PROVIDE_KIND_DBUS_SESSION);
as_provide_set_value (provide, name);
as_app_add_provide (AS_APP (app), provide);
return TRUE;
}
/**
* asb_plugin_process_app:
*/
gboolean
asb_plugin_process_app (AsbPlugin *plugin,
AsbPackage *pkg,
AsbApp *app,
const gchar *tmpdir,
GError **error)
{
gchar **filelist;
guint i;
/* look for any GIR files */
filelist = asb_package_get_filelist (pkg);
for (i = 0; filelist[i] != NULL; i++) {
if (_asb_plugin_check_filename_system (filelist[i])) {
if (!asb_plugin_process_dbus (app, tmpdir, filelist[i],
TRUE, error))
return FALSE;
} else if (_asb_plugin_check_filename_session (filelist[i])) {
if (!asb_plugin_process_dbus (app, tmpdir, filelist[i],
FALSE, error))
return FALSE;
}
}
return TRUE;
}
|