Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Speech dispatcher socket #5272

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Next Next commit
Add support for the Speech dispatcher socket
This commit allows accessing a Flatpak app the socket used for communication with the Speech dispatcher daemon.
  • Loading branch information
tyrylu authored and Lukáš Tyrychtr committed Jan 17, 2024
commit 83a3030bd65bdcbc3473825ad9f3eb2b1ebd7a39
1 change: 1 addition & 0 deletions common/flatpak-context-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef enum {
FLATPAK_CONTEXT_SOCKET_PCSC = 1 << 7,
FLATPAK_CONTEXT_SOCKET_CUPS = 1 << 8,
FLATPAK_CONTEXT_SOCKET_GPG_AGENT = 1 << 9,
FLATPAK_CONTEXT_SOCKET_SPEECH_DISPATCHER = 1 << 10,
} FlatpakContextSockets;

typedef enum {
Expand Down
1 change: 1 addition & 0 deletions common/flatpak-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const char *flatpak_context_sockets[] = {
"pcsc",
"cups",
"gpg-agent",
"speech-dispatcher",
NULL
};

Expand Down
8 changes: 7 additions & 1 deletion common/flatpak-run-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

#include "flatpak-run-cups-private.h"
#include "flatpak-run-pulseaudio-private.h"
#include "flatpak-run-wayland-private.h"
#include "flatpak-run-speech-dispatcher-private.h"
#include "flatpak-run-x11-private.h"
#include "flatpak-run-wayland-private.h"
#include "flatpak-utils-private.h"

static void
Expand Down Expand Up @@ -218,6 +219,11 @@ flatpak_run_add_socket_args_environment (FlatpakBwrap *bwrap,
{
flatpak_run_add_gpg_agent_args (bwrap);
}

if (sockets & FLATPAK_CONTEXT_SOCKET_SPEECH_DISPATCHER)
{
flatpak_run_add_speech_dispatcher_args (bwrap);
}
}

/*
Expand Down
31 changes: 31 additions & 0 deletions common/flatpak-run-speech-dispatcher-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright © 2014 Red Hat, Inc
*
* This program 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, see <http:https://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <[email protected]>
*/

#pragma once

#include "libglnx.h"

#include "flatpak-bwrap-private.h"

G_BEGIN_DECLS

void flatpak_run_add_speech_dispatcher_args (FlatpakBwrap *bwrap);

G_END_DECLS
68 changes: 68 additions & 0 deletions common/flatpak-run-speech-dispatcher.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* vi:set et sw=2 sts=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e-s:
* Copyright © 2014-2019 Red Hat, Inc
*
* This program 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, see <http:https://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put yourself as an author. Same applies to other files. Also the year can be updated.

*/

#include "config.h"

#include "flatpak-run-speech-dispatcher-private.h"

static gchar *
flatpak_run_default_speechd_socket_path (void)
{
return g_strdup_printf ("%s/speech-dispatcher/speechd.sock", g_get_user_runtime_dir ());
}

static char *
flatpak_run_get_socket_path_from_speechd_address (const char * speechd_address)
{
char *method_separator = strstr (speechd_address, ":");
if (method_separator == NULL || strlen (method_separator + 1) == 0)
return flatpak_run_default_speechd_socket_path ();
else
return g_strdup (method_separator + 1);
}

static char *
flatpak_run_get_host_speechd_socket_path (void)
{
const char * speechd_address = g_getenv ("SPEECHD_ADDRESS");
if (speechd_address && g_str_has_prefix (speechd_address, "unix_socket"))
return flatpak_run_get_socket_path_from_speechd_address (speechd_address);
else
return flatpak_run_default_speechd_socket_path ();
}

void
flatpak_run_add_speech_dispatcher_args (FlatpakBwrap *bwrap)
{
/*
* TODO: We only support unix sockets for communication with
* speech dispatcher. Supporting inet sockets would require network
* access for the sandbox though, so they're left out for now.
*/
g_autofree char * host_speechd_socket = NULL;
g_autofree char * sandbox_speechd_socket = NULL;

host_speechd_socket = flatpak_run_get_host_speechd_socket_path ();
sandbox_speechd_socket = g_strdup_printf ("%s/speech-dispatcher/speechd.sock", g_get_user_runtime_dir ());

flatpak_bwrap_add_args (bwrap,
"--bind-try", host_speechd_socket, sandbox_speechd_socket,
NULL);
}
2 changes: 1 addition & 1 deletion common/flatpak-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ flatpak_run_add_environment_args (FlatpakBwrap *bwrap,
flatpak_context_append_bwrap_filesystem (context, bwrap, app_id, app_id_dir,
exports, xdg_dirs_conf, home_access);

flatpak_run_add_socket_args_environment (bwrap, context->shares, context->sockets, app_id, instance_id);
flatpak_run_add_socket_args_environment (bwrap, context->shares, context->sockets);
flatpak_run_add_session_dbus_args (bwrap, proxy_arg_bwrap, context, flags, app_id);
flatpak_run_add_system_dbus_args (bwrap, proxy_arg_bwrap, context, flags);
flatpak_run_add_a11y_dbus_args (bwrap, proxy_arg_bwrap, context, flags);
Expand Down
3 changes: 2 additions & 1 deletion common/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ sources = [
'flatpak-run-dbus.c',
'flatpak-run-pulseaudio.c',
'flatpak-run-sockets.c',
'flatpak-run-speech-dispatcher.c',
'flatpak-run-wayland.c',
'flatpak-run-x11.c',
'flatpak-run-x11.c',
'flatpak-transaction.c',
'flatpak-utils-http.c',
'flatpak-utils.c',
Expand Down
4 changes: 2 additions & 2 deletions doc/flatpak-build-finish.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
Expose a well-known socket to the application. This updates
the [Context] group in the metadata.
SOCKET must be one of: x11, wayland, fallback-x11, pulseaudio, system-bus, session-bus,
ssh-auth, pcsc, cups, gpg-agent.
ssh-auth, pcsc, cups, gpg-agent, speech-dispatcher.
This option can be used multiple times.
</para><para>
The fallback-x11 option makes the X11 socket available only if
Expand All @@ -151,7 +151,7 @@
Don't expose a well known socket to the application. This updates
the [Context] group in the metadata.
SOCKET must be one of: x11, wayland, fallback-x11, pulseaudio, system-bus, session-bus,
ssh-auth, pcsc, cups, gpg-agent.
ssh-auth, pcsc, cups, gpg-agent, speech-dispatcher.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand Down
4 changes: 2 additions & 2 deletions doc/flatpak-build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
Expose a well-known socket to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">SOCKET</arg> must be one of: x11, wayland, fallback-x11, pulseaudio, system-bus, session-bus,
ssh-auth, pcsc, cups, gpg-agent.
ssh-auth, pcsc, cups, gpg-agent, speech-dispatcher.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand All @@ -161,7 +161,7 @@
Don't expose a well-known socket to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">SOCKET</arg> must be one of: x11, wayland, fallback-x11, pulseaudio, system-bus, session-bus,
ssh-auth, pcsc, cups, gpg-agent.
ssh-auth, pcsc, cups, gpg-agent, speech-dispatcher.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand Down
2 changes: 1 addition & 1 deletion doc/flatpak-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<listitem><para>
List of well-known sockets to make available in the sandbox.
Possible sockets: x11, wayland, fallback-x11, pulseaudio, session-bus, system-bus,
ssh-auth, pcsc, cups.
ssh-auth, pcsc, cups, speech-dispatcher.
When making a socket available, flatpak also sets
well-known environment variables like DISPLAY or
DBUS_SYSTEM_BUS_ADDRESS to let the application
Expand Down
2 changes: 1 addition & 1 deletion doc/flatpak-override.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
Expose a well-known socket to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">SOCKET</arg> must be one of: x11, wayland, fallback-x11, pulseaudio, system-bus, session-bus,
ssh-auth, pcsc, cups, gpg-agent.
ssh-auth, pcsc, cups, gpg-agent, speech-dispatcher.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand Down
4 changes: 2 additions & 2 deletions doc/flatpak-run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
Expose a well known socket to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">SOCKET</arg> must be one of: x11, wayland, fallback-x11, pulseaudio, system-bus, session-bus,
ssh-auth, pcsc, cups, gpg-agent.
ssh-auth, pcsc, cups, gpg-agent, speech-dispatcher.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand All @@ -320,7 +320,7 @@
Don't expose a well known socket to the application. This overrides to
the Context section from the application metadata.
<arg choice="plain">SOCKET</arg> must be one of: x11, wayland, fallback-x11, pulseaudio, system-bus, session-bus,
ssh-auth, pcsc, cups, gpg-agent.
ssh-auth, pcsc, cups, gpg-agent, speech-dispatcher.
This option can be used multiple times.
</para></listitem>
</varlistentry>
Expand Down