2 * @file sipe-appshare-remmina.c
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
24 #include <glib/gstdio.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"
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
);
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
;
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"
85 "disableautoreconnect=1\n",
86 alias
? alias
: stream
->call
->with
,
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(),
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
);
104 SIPE_DEBUG_ERROR("Couldn't write remmina config file: %s",
110 cmdline
= g_strdup_printf("%s -c %s",
112 client_data
->config_file
);
114 SIPE_DEBUG_INFO("Launching remmina: %s", cmdline
);
116 g_spawn_command_line_async(cmdline
, &error
);
119 SIPE_DEBUG_ERROR("Couldn't launch remmina: %s", error
->message
);
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
);
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
;