Release 1.25.0 -- Buddy Idle Time, RTF
[siplcs.git] / src / core / sipe-appshare-remmina.c
bloba78388174e8b995e480b33408c22d753c05cede3
1 /**
2 * @file sipe-appshare-remmina.c
4 * pidgin-sipe
6 * Copyright (C) 2014-2016 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 <glib.h>
24 #include <glib/gstdio.h>
26 #include <gio/gio.h>
28 #include <string.h>
30 #include "sipe-appshare-client.h"
31 #include "sipe-backend.h"
32 #include "sipe-buddy.h"
33 #include "sipe-common.h"
34 #include "sipe-media.h"
36 struct remmina_data {
37 gchar *config_file;
40 static GSocketAddress *
41 remmina_get_listen_address(SIPE_UNUSED_PARAMETER struct sipe_rdp_client *client)
43 GInetAddress *loopback;
44 GSocketAddress *address;
46 loopback = g_inet_address_new_loopback(G_SOCKET_FAMILY_IPV4);
47 address = g_inet_socket_address_new(loopback, 0);
48 g_object_unref(loopback);
50 return address;
53 static gboolean
54 remmina_launch(struct sipe_rdp_client *client, GSocketAddress *listen_address,
55 struct sipe_media_stream *stream)
57 struct remmina_data *client_data = client->client_data;
58 struct sipe_core_private *sipe_private;
59 GInetAddress *address;
60 gchar *address_string;
61 gchar *alias;
62 gchar *config_file;
63 gchar *cmdline;
64 guint16 port;
65 GError *error = NULL;
67 sipe_private = sipe_media_get_sipe_core_private(stream->call);
69 address = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(listen_address));
70 address_string = g_inet_address_to_string(address);
72 port = g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(listen_address));
74 alias = sipe_buddy_get_alias(sipe_private, stream->call->with);
76 config_file = g_strdup_printf("[remmina]\n"
77 "name=%s (Sipe desktop)\n"
78 "protocol=RDP\n"
79 "server=%s:%u\n"
80 "security=rdp\n"
81 "scale=1\n"
82 "aspectscale=1\n"
83 "viewmode=1\n"
84 "colordepth=0\n"
85 "disableautoreconnect=1\n",
86 alias ? alias : stream->call->with,
87 address_string,
88 port);
90 g_free(alias);
91 g_free(address_string);
93 client_data->config_file =
94 g_strdup_printf("%s/sipe-appshare-%u-%p.remmina",
95 g_get_user_runtime_dir(), getpid(),
96 client);
98 g_file_set_contents(client_data->config_file, config_file,
99 strlen(config_file), &error);
100 SIPE_DEBUG_INFO("Written .remmina file %s:\n%s",
101 client_data->config_file, config_file);
102 g_free(config_file);
103 if (error) {
104 SIPE_DEBUG_ERROR("Couldn't write remmina config file: %s",
105 error->message);
106 g_error_free(error);
107 return FALSE;
110 cmdline = g_strdup_printf("%s -c %s",
111 client->cmdline,
112 client_data->config_file);
114 SIPE_DEBUG_INFO("Launching remmina: %s", cmdline);
116 g_spawn_command_line_async(cmdline, &error);
117 g_free(cmdline);
118 if (error) {
119 SIPE_DEBUG_ERROR("Couldn't launch remmina: %s", error->message);
120 g_error_free(error);
121 return FALSE;
124 return TRUE;
127 static void
128 remmina_free(struct sipe_rdp_client *client)
130 struct remmina_data *client_data = client->client_data;
132 if (client_data->config_file) {
133 g_unlink(client_data->config_file);
134 g_free(client_data->config_file);
137 g_free(client_data);
140 void
141 sipe_appshare_remmina_init(struct sipe_rdp_client *client)
143 client->client_data = g_new0(struct remmina_data, 1);
145 client->get_listen_address_cb = remmina_get_listen_address;
146 client->launch_cb = remmina_launch;
147 client->free_cb = remmina_free;
151 Local Variables:
152 mode: c
153 c-file-style: "bsd"
154 indent-tabs-mode: t
155 tab-width: 8
156 End: