Release 1.25.0 -- Buddy Idle Time, RTF
[siplcs.git] / src / core / sipe-appshare-xfreerdp.c
blob306bd90df7d94b8ab4cf1f34e0e64b1dc88743ca
1 /**
2 * @file sipe-appshare-xfreerdp.c
4 * pidgin-sipe
6 * Copyright (C) 2014-2018 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <string.h>
25 #include <glib.h>
26 #include <glib/gstdio.h>
28 #include <gio/gio.h>
30 #include <sys/socket.h>
31 #include <sys/un.h>
33 #include "sipe-appshare-client.h"
34 #include "sipe-backend.h"
35 #include "sipe-common.h"
37 struct xfreerdp_data {
38 gchar *socket_path;
41 static GSocketAddress *
42 xfreerdp_get_listen_address(struct sipe_rdp_client *client)
44 struct xfreerdp_data *data = client->client_data;
45 struct sockaddr_un address;
47 data->socket_path = g_strdup_printf("%s/sipe-appshare-%u-%p",
48 g_get_user_runtime_dir(), getpid(),
49 client);
51 g_unlink(data->socket_path);
53 address.sun_family = AF_LOCAL;
54 strncpy(address.sun_path, data->socket_path, sizeof (address.sun_path) - 1);
55 address.sun_path[sizeof (address.sun_path) - 1] = '\0';
57 return g_socket_address_new_from_native(&address, sizeof (address));
60 static gboolean
61 xfreerdp_launch(struct sipe_rdp_client *client,
62 SIPE_UNUSED_PARAMETER GSocketAddress *listen_address,
63 SIPE_UNUSED_PARAMETER struct sipe_media_stream *stream)
65 struct xfreerdp_data *client_data = client->client_data;
66 gchar *cmdline;
67 GError *error = NULL;
69 /* This assumes FreeRDP 2.x.x */
70 cmdline = g_strdup_printf("%s /v:%s /sec:rdp",
71 client->cmdline,
72 client_data->socket_path);
74 g_spawn_command_line_async(cmdline, &error);
75 g_free(cmdline);
76 if (error) {
77 SIPE_DEBUG_ERROR("Can't launch xfreerdp: %s", error->message);
78 g_error_free(error);
79 return FALSE;
82 return TRUE;
85 static void
86 xfreerdp_free(struct sipe_rdp_client *client)
88 struct xfreerdp_data *client_data = client->client_data;
90 if (client_data->socket_path) {
91 g_unlink(client_data->socket_path);
92 g_free(client_data->socket_path);
95 g_free(client_data);
98 void
99 sipe_appshare_xfreerdp_init(struct sipe_rdp_client *client)
101 client->client_data = g_new0(struct xfreerdp_data, 1);
103 client->get_listen_address_cb = xfreerdp_get_listen_address;
104 client->launch_cb = xfreerdp_launch;
105 client->free_cb = xfreerdp_free;
109 Local Variables:
110 mode: c
111 c-file-style: "bsd"
112 indent-tabs-mode: t
113 tab-width: 8
114 End: