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.h"
31 #include "sipe-appshare-remmina.h"
32 #include "sipe-backend.h"
33 #include "sipe-buddy.h"
34 #include "sipe-common.h"
35 #include "sipe-media.h"
41 static GSocketAddress
*
42 remmina_get_listen_address(SIPE_UNUSED_PARAMETER
struct sipe_rdp_client
*client
)
44 GInetAddress
*loopback
;
45 GSocketAddress
*address
;
47 loopback
= g_inet_address_new_loopback(G_SOCKET_FAMILY_IPV4
);
48 address
= g_inet_socket_address_new(loopback
, 0);
49 g_object_unref(loopback
);
55 remmina_launch(struct sipe_rdp_client
*client
, GSocketAddress
*listen_address
,
56 struct sipe_media_stream
*stream
)
58 struct remmina_data
*client_data
= client
->client_data
;
59 struct sipe_core_private
*sipe_private
;
60 GInetAddress
*address
;
61 gchar
*address_string
;
68 sipe_private
= sipe_media_get_sipe_core_private(stream
->call
);
70 address
= g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(listen_address
));
71 address_string
= g_inet_address_to_string(address
);
73 port
= g_inet_socket_address_get_port(G_INET_SOCKET_ADDRESS(listen_address
));
75 alias
= sipe_buddy_get_alias(sipe_private
, stream
->call
->with
);
77 config_file
= g_strdup_printf("[remmina]\n"
78 "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
);
102 SIPE_DEBUG_ERROR("Couldn't write remmina config file: %s",
108 cmdline
= g_strdup_printf("remmina -c %s", client_data
->config_file
);
110 g_spawn_command_line_async(cmdline
, &error
);
113 SIPE_DEBUG_ERROR("Couldn't launch remmina: %s", error
->message
);
122 remmina_free(struct sipe_rdp_client
*client
)
124 struct remmina_data
*client_data
= client
->client_data
;
126 if (client_data
->config_file
) {
127 g_unlink(client_data
->config_file
);
128 g_free(client_data
->config_file
);
135 sipe_appshare_remmina_init(struct sipe_rdp_client
*client
)
137 client
->client_data
= g_new0(struct remmina_data
, 1);
139 client
->get_listen_address_cb
= remmina_get_listen_address
;
140 client
->launch_cb
= remmina_launch
;
141 client
->free_cb
= remmina_free
;