Welcome to mirror list, hosted at ThFree Co, Russian Federation.

remmina.c « src « remmina - gitlab.com/Remmina/Remmina.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aac5b018cbf7696cb03ced2e384b8f60c98b9994 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
 * Remmina - The GTK+ Remote Desktop Client
 * Copyright (C) 2009-2010 Vic Lee
 * Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 *  In addition, as a special exception, the copyright holders give
 *  permission to link the code of portions of this program with the
 *  OpenSSL library under certain conditions as described in each
 *  individual source file, and distribute linked combinations
 *  including the two.
 *  You must obey the GNU General Public License in all respects
 *  for all of the code used other than OpenSSL. *  If you modify
 *  file(s) with this exception, you may extend this exception to your
 *  version of the file(s), but you are not obligated to do so. *  If you
 *  do not wish to do so, delete this exception statement from your
 *  version. *  If you delete this exception statement from all source
 *  files in the program, then also delete it here.
 *
 */

#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <stdlib.h>
#include "config.h"
#include "remmina_public.h"
#include "remmina_main.h"
#include "remmina_file_manager.h"
#include "remmina_pref.h"
#include "remmina_widget_pool.h"
#include "remmina_plugin_manager.h"
#include "remmina_sftp_plugin.h"
#include "remmina_ssh_plugin.h"
#include "remmina_exec.h"
#include "remmina_icon.h"
#include "remmina_masterthread_exec.h"
#include "remmina/remmina_trace_calls.h"

#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <pthread.h>
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
GCRY_THREAD_OPTION_PTHREAD_IMPL;
#endif

static gboolean remmina_option_about;
static gchar *remmina_option_connect;
static gchar *remmina_option_edit;
static gboolean remmina_option_help;
static gboolean remmina_option_new;
static gchar *remmina_option_pref;
static gchar *remmina_option_plugin;
static gboolean remmina_option_quit;
static gchar *remmina_option_server;
static gchar *remmina_option_protocol;
static gchar *remmina_option_icon;


static GOptionEntry remmina_options[] =
{
	{ "about", 'a', 0, G_OPTION_ARG_NONE, &remmina_option_about, "Show about dialog", NULL },
	{ "connect", 'c', 0, G_OPTION_ARG_FILENAME, &remmina_option_connect, "Connect to a .remmina file", "FILE" },
	{ "edit", 'e', 0, G_OPTION_ARG_FILENAME, &remmina_option_edit, "Edit a .remmina file", "FILE" },
	{ "help", '?', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &remmina_option_help, NULL, NULL },
	{ "new", 'n', 0, G_OPTION_ARG_NONE, &remmina_option_new, "Create a new connection profile", NULL },
	{ "pref", 'p', 0, G_OPTION_ARG_STRING, &remmina_option_pref, "Show preferences dialog page", "PAGENR" },
	{ "plugin", 'x', 0, G_OPTION_ARG_STRING, &remmina_option_plugin, "Execute the plugin", "PLUGIN" },
	{ "quit", 'q', 0, G_OPTION_ARG_NONE, &remmina_option_quit, "Quit the application", NULL },
	{ "server", 's', 0, G_OPTION_ARG_STRING, &remmina_option_server, "Use default server name", "SERVER" },
	{ "protocol", 't', 0, G_OPTION_ARG_STRING, &remmina_option_protocol, "Use default protocol", "PROTOCOL" },
	{ "icon", 'i', 0, G_OPTION_ARG_NONE, &remmina_option_icon, "Start as tray icon", NULL },
	{ NULL }
};

static gint remmina_on_command_line(GApplication *app, GApplicationCommandLine *cmdline)
{
	TRACE_CALL("remmina_on_command_line");
	gint status = 0;
	gint argc;
	gchar **argv;
	GError *error = NULL;
	GOptionContext *context;
	gboolean parsed;
	gchar *s;
	gboolean executed = FALSE;

	remmina_option_about = FALSE;
	remmina_option_connect = NULL;
	remmina_option_edit = NULL;
	remmina_option_help = FALSE;
	remmina_option_new = FALSE;
	remmina_option_pref = NULL;
	remmina_option_plugin = NULL;
	remmina_option_server = NULL;
	remmina_option_protocol = NULL;
	remmina_option_icon = FALSE;

	argv = g_application_command_line_get_arguments(cmdline, &argc);

	context = g_option_context_new("- The GTK+ Remote Desktop Client");
	g_option_context_add_main_entries(context, remmina_options, GETTEXT_PACKAGE);
	g_option_context_set_help_enabled(context, FALSE);
	parsed = g_option_context_parse(context, &argc, &argv, &error);
	g_strfreev(argv);

	if (!parsed)
	{
		g_print("option parsing failed: %s\n", error->message);
		status = 1;
	}

	if (remmina_option_quit)
	{
		gtk_main_quit();
		status = 1;
	}

	if (remmina_option_about)
	{
		remmina_exec_command(REMMINA_COMMAND_ABOUT, NULL);
		executed = TRUE;
	}
	if (remmina_option_connect)
	{
		remmina_exec_command(REMMINA_COMMAND_CONNECT, remmina_option_connect);
		executed = TRUE;
	}
	if (remmina_option_edit)
	{
		remmina_exec_command(REMMINA_COMMAND_EDIT, remmina_option_edit);
		executed = TRUE;
	}
	if (remmina_option_help)
	{
		s = g_option_context_get_help(context, TRUE, NULL);
		g_print("%s", s);
		g_free(s);
		status = 1;
	}
	if (remmina_option_new)
	{
		if (remmina_option_server)
		{
			s = g_strdup_printf("%s,%s", remmina_option_protocol, remmina_option_server);
		}
		else
		{
			s = g_strdup(remmina_option_protocol);
		}
		remmina_exec_command(REMMINA_COMMAND_NEW, s);
		g_free(s);
		executed = TRUE;
	}
	if (remmina_option_pref)
	{
		remmina_exec_command(REMMINA_COMMAND_PREF, remmina_option_pref);
		executed = TRUE;
	}
	if (remmina_option_plugin)
	{
		remmina_exec_command(REMMINA_COMMAND_PLUGIN, remmina_option_plugin);
		executed = TRUE;
	}
	if (remmina_option_icon)
	{
		remmina_exec_command(REMMINA_COMMAND_NONE, remmina_option_icon);
		executed = TRUE;
	}
	if (!executed)
	{
		remmina_exec_command(REMMINA_COMMAND_MAIN, NULL);
	}

	g_option_context_free(context);

	return status;
}

static void remmina_on_startup(GApplication *app)
{
	TRACE_CALL("remmina_on_startup");
	remmina_file_manager_init();
	remmina_pref_init();
	remmina_plugin_manager_init();
	remmina_widget_pool_init();
	remmina_sftp_plugin_register();
	remmina_ssh_plugin_register();
	remmina_icon_init();

	g_set_application_name("Remmina");
	gtk_window_set_default_icon_name("remmina");

	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
		REMMINA_DATADIR G_DIR_SEPARATOR_S "icons");
}

static gboolean remmina_on_local_cmdline (GApplication *app, gchar ***arguments, gint *exit_status)
{
	TRACE_CALL("remmina_on_local_cmdline");
	/* Partially unimplemented local command line only used to append the
	 * command line arguments to the help text and to parse the --help/-h
	 * arguments locally instead of forwarding them to the remote instance */
	GOptionContext *context;
	gint i = 0;
	gchar **argv;

	context = g_option_context_new("- The GTK+ Remote Desktop Client");
	g_option_context_add_group(context, gtk_get_option_group(FALSE));
	g_option_context_set_help_enabled(context, TRUE);
	g_option_context_add_main_entries(context, remmina_options, GETTEXT_PACKAGE);
	g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
	*exit_status = 0;

	// Parse the command line arguments for --help/-h
	argv = *arguments;
	for (i = 0; argv[i] != NULL; i++)
	{
		if ((g_strcmp0(argv[i], "--help") == 0 || g_strcmp0(argv[i], "-h") == 0))
		{
			g_print("%s", g_option_context_get_help(context, TRUE, NULL));
			*exit_status = EXIT_FAILURE;
		}
	}
	g_option_context_free(context);
	// Exit from the local instance whenever the exit status is not zero
	if (*exit_status != 0)
		exit(*exit_status);
	return FALSE;
}

int main(int argc, char* argv[])
{
	TRACE_CALL("main");
	GApplication *app;
	GApplicationClass *app_class;
	int status;

	remmina_masterthread_exec_save_main_thread_id();

	bindtextdomain(GETTEXT_PACKAGE, REMMINA_LOCALEDIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);

#ifdef HAVE_LIBGCRYPT
	gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
	gcry_check_version (NULL);
	gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
	gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif

	gtk_init(&argc, &argv);

	app = g_application_new("org.Remmina", G_APPLICATION_HANDLES_COMMAND_LINE);
	app_class = G_APPLICATION_CLASS(G_OBJECT_GET_CLASS (app));
	app_class->local_command_line = remmina_on_local_cmdline;
	g_signal_connect(app, "startup", G_CALLBACK(remmina_on_startup), NULL);
	g_signal_connect(app, "command-line", G_CALLBACK(remmina_on_command_line), NULL);
	g_application_set_inactivity_timeout(app, 10000);

	status = g_application_run(app, argc, argv);

	if (status == 0 && !g_application_get_is_remote(app))
	{
		gtk_main();
	}

	g_object_unref(app);

	return status;
}