forked from Mirrors/flatpak-builder
Make xdg-dbus-proxy talk command line args and install it
parent
7183917583
commit
01bd1a3dfd
|
@ -31,5 +31,6 @@ doc/*.1
|
|||
*~
|
||||
xdg-app-dbus.[ch]
|
||||
xdg-app-systemd-dbus.[ch]
|
||||
xdg-app-resources.c
|
||||
xdg-app-resources.[ch]
|
||||
xdg-dbus-proxy
|
||||
*.service
|
||||
|
|
11
Makefile.am
11
Makefile.am
|
@ -20,12 +20,9 @@ dist_triggers_SCRIPTS = \
|
|||
triggers/desktop-database.trigger \
|
||||
$(NULL)
|
||||
|
||||
noinst_PROGRAMS = \
|
||||
dbus-proxy \
|
||||
$(NULL)
|
||||
|
||||
bin_PROGRAMS = \
|
||||
xdg-app-helper \
|
||||
xdg-dbus-proxy \
|
||||
xdg-app \
|
||||
$(NULL)
|
||||
|
||||
|
@ -126,14 +123,14 @@ xdg_app_SOURCES = \
|
|||
xdg_app_LDADD = $(BASE_LIBS) $(OSTREE_LIBS) $(SOUP_LIBS) libglnx.la
|
||||
xdg_app_CFLAGS = $(BASE_CFLAGS) $(OSTREE_CFLAGS) $(SOUP_CFLAGS) -I$(srcdir)/libglnx
|
||||
|
||||
dbus_proxy_SOURCES = \
|
||||
xdg_dbus_proxy_SOURCES = \
|
||||
xdg-app-proxy.c \
|
||||
xdg-app-proxy.h \
|
||||
dbus-proxy.c \
|
||||
$(NULL)
|
||||
|
||||
dbus_proxy_LDADD = $(BASE_LIBS)
|
||||
dbus_proxy_CFLAGS = $(BASE_CFLAGS)
|
||||
xdg_dbus_proxy_LDADD = $(BASE_LIBS) libglnx.la
|
||||
xdg_dbus_proxy_CFLAGS = $(BASE_CFLAGS) -I$(srcdir)/libglnx
|
||||
|
||||
|
||||
install-exec-hook:
|
||||
|
|
132
dbus-proxy.c
132
dbus-proxy.c
|
@ -18,26 +18,134 @@
|
|||
* Alexander Larsson <alexl@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libglnx/libglnx.h"
|
||||
|
||||
#include "xdg-app-proxy.h"
|
||||
|
||||
GList *proxies;
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
start_proxy (int n_args, const char *args[])
|
||||
{
|
||||
g_autoptr(XdgAppProxy) proxy = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
const char *bus_address, *socket_path;
|
||||
int n;
|
||||
|
||||
n = 0;
|
||||
if (n_args < n+1 || args[n][0] == '-')
|
||||
{
|
||||
g_printerr ("No bus address given\n");
|
||||
return -1;
|
||||
}
|
||||
bus_address = args[n++];
|
||||
|
||||
if (n_args < n+1 || args[n][0] == '-')
|
||||
{
|
||||
g_printerr ("No socket path given\n");
|
||||
return -1;
|
||||
}
|
||||
socket_path = args[n++];
|
||||
|
||||
proxy = xdg_app_proxy_new (bus_address, socket_path);
|
||||
|
||||
while (n < n_args)
|
||||
{
|
||||
if (args[n][0] != '-')
|
||||
break;
|
||||
|
||||
if (g_str_has_prefix (args[n], "--see=") ||
|
||||
g_str_has_prefix (args[n], "--talk=") ||
|
||||
g_str_has_prefix (args[n], "--own="))
|
||||
{
|
||||
XdgAppPolicy policy = XDG_APP_POLICY_SEE;
|
||||
g_autofree char *name = NULL;
|
||||
gboolean wildcard = FALSE;
|
||||
|
||||
if (args[n][2] == 't')
|
||||
policy = XDG_APP_POLICY_TALK;
|
||||
else if (args[n][2] == 'o')
|
||||
policy = XDG_APP_POLICY_OWN;
|
||||
|
||||
name = g_strdup (strchr (args[n], '=') + 1);
|
||||
if (g_str_has_suffix (name, ".*"))
|
||||
{
|
||||
name[strlen (name) - 2] = 0;
|
||||
wildcard = TRUE;
|
||||
}
|
||||
|
||||
if (name[0] == ':' || !g_dbus_is_name (name))
|
||||
{
|
||||
g_printerr ("'%s' is not a valid dbus name\n", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (wildcard)
|
||||
xdg_app_proxy_add_wildcarded_policy (proxy, name, policy);
|
||||
else
|
||||
xdg_app_proxy_add_policy (proxy, name, policy);
|
||||
}
|
||||
else if (g_str_equal (args[n], "--log"))
|
||||
{
|
||||
xdg_app_proxy_set_log_messages (proxy, TRUE);
|
||||
}
|
||||
else if (g_str_equal (args[n], "--filter"))
|
||||
{
|
||||
xdg_app_proxy_set_filter (proxy, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_printerr ("Unknown argument %s\n", args[n]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
if (!xdg_app_proxy_start (proxy, &error))
|
||||
{
|
||||
g_printerr ("Failed to start proxy for %s: %s\n", bus_address, error->message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
proxies = g_list_prepend (proxies, g_object_ref (proxy));
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
{
|
||||
GMainLoop *service_loop;
|
||||
XdgAppProxy *proxy;
|
||||
GError *error = NULL;
|
||||
int n_args, res;
|
||||
const char **args;
|
||||
|
||||
proxy = xdg_app_proxy_new (g_getenv ("DBUS_SESSION_BUS_ADDRESS"));
|
||||
n_args = argc - 1;
|
||||
args = &argv[1];
|
||||
|
||||
xdg_app_proxy_set_log_messages (proxy, TRUE);
|
||||
xdg_app_proxy_set_filter (proxy, TRUE);
|
||||
xdg_app_proxy_add_policy (proxy, "ca.desrt.dconf", XDG_APP_POLICY_TALK);
|
||||
xdg_app_proxy_add_policy (proxy, "org.gnome.gedit", XDG_APP_POLICY_TALK);
|
||||
xdg_app_proxy_add_policy (proxy, "org.gnome.d-feet", XDG_APP_POLICY_OWN);
|
||||
xdg_app_proxy_add_policy (proxy, "org.gtk.vfs.Daemon", XDG_APP_POLICY_TALK);
|
||||
while (n_args > 0)
|
||||
{
|
||||
res = start_proxy (n_args, args);
|
||||
if (res == -1)
|
||||
return 1;
|
||||
|
||||
xdg_app_proxy_start (proxy, &error);
|
||||
g_assert_no_error (error);
|
||||
n_args -= res;
|
||||
args += n_args;
|
||||
}
|
||||
|
||||
if (proxies == NULL)
|
||||
{
|
||||
g_printerr ("No proxies specied\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
service_loop = g_main_loop_new (NULL, FALSE);
|
||||
g_main_loop_run (service_loop);
|
||||
|
|
|
@ -155,7 +155,8 @@ typedef struct {
|
|||
enum {
|
||||
PROP_0,
|
||||
|
||||
PROP_DBUS_ADDRESS
|
||||
PROP_DBUS_ADDRESS,
|
||||
PROP_SOCKET_PATH
|
||||
};
|
||||
|
||||
#define XDG_APP_TYPE_PROXY xdg_app_proxy_get_type()
|
||||
|
@ -337,6 +338,9 @@ xdg_app_proxy_set_property (GObject *object,
|
|||
case PROP_DBUS_ADDRESS:
|
||||
proxy->dbus_address = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_SOCKET_PATH:
|
||||
proxy->socket_path = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -356,6 +360,9 @@ xdg_app_proxy_get_property (GObject *object,
|
|||
case PROP_DBUS_ADDRESS:
|
||||
g_value_set_string (value, proxy->dbus_address);
|
||||
break;
|
||||
case PROP_SOCKET_PATH:
|
||||
g_value_set_string (value, proxy->socket_path);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -1805,15 +1812,23 @@ xdg_app_proxy_class_init (XdgAppProxyClass *klass)
|
|||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_SOCKET_PATH,
|
||||
g_param_spec_string ("socket-path",
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
}
|
||||
|
||||
XdgAppProxy *
|
||||
xdg_app_proxy_new (const char *dbus_address)
|
||||
xdg_app_proxy_new (const char *dbus_address,
|
||||
const char *socket_path)
|
||||
{
|
||||
XdgAppProxy *proxy;
|
||||
|
||||
proxy = g_object_new (XDG_APP_TYPE_PROXY, "dbus-address", dbus_address, NULL);
|
||||
proxy = g_object_new (XDG_APP_TYPE_PROXY, "dbus-address", dbus_address, "socket-path", socket_path, NULL);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
@ -1823,7 +1838,6 @@ xdg_app_proxy_start (XdgAppProxy *proxy, GError **error)
|
|||
GSocketAddress *address;
|
||||
gboolean res;
|
||||
|
||||
proxy->socket_path = g_build_filename (g_get_user_runtime_dir (), "gdbus-proxy", NULL);
|
||||
unlink (proxy->socket_path);
|
||||
|
||||
g_print ("listening on DBUS_SESSION_BUS_ADDRESS=\"unix:path=%s\"\n", proxy->socket_path);
|
||||
|
|
|
@ -32,9 +32,12 @@ typedef enum {
|
|||
|
||||
typedef struct XdgAppProxy XdgAppProxy;
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(XdgAppProxy, g_object_unref)
|
||||
|
||||
GType xdg_app_proxy_get_type (void);
|
||||
|
||||
XdgAppProxy *xdg_app_proxy_new (const char *dbus_address);
|
||||
XdgAppProxy *xdg_app_proxy_new (const char *dbus_address,
|
||||
const char *socket_path);
|
||||
void xdg_app_proxy_set_log_messages (XdgAppProxy *proxy,
|
||||
gboolean log);
|
||||
void xdg_app_proxy_set_filter (XdgAppProxy *proxy,
|
||||
|
|
Loading…
Reference in New Issue