diff options
-rw-r--r-- | src/remmina.c | 51 | ||||
-rw-r--r-- | src/remmina_exec.c | 57 | ||||
-rw-r--r-- | src/remmina_exec.h | 2 |
3 files changed, 95 insertions, 15 deletions
diff --git a/src/remmina.c b/src/remmina.c index abf80ddad..e736f1de8 100644 --- a/src/remmina.c +++ b/src/remmina.c @@ -95,6 +95,8 @@ static GOptionEntry remmina_options[] = { "icon", 'i', 0, G_OPTION_ARG_NONE, NULL, N_("Start as tray icon"), NULL }, { "version", 'v', 0, G_OPTION_ARG_NONE, NULL, N_("Show the application’s version"), NULL }, { "full-version", 'V', 0, G_OPTION_ARG_NONE, NULL, N_("Show the application’s version, including the plugin versions"), NULL }, + { "update-profile", 0, 0, G_OPTION_ARG_FILENAME, NULL, N_("Modify connection profile, require also --set-option"), NULL }, + { "set-option", 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, N_("Set a profile setting, to be used with --update-profile"), NULL }, { NULL } }; @@ -198,16 +200,6 @@ static gint remmina_on_command_line(GApplication *app, GApplicationCommandLine * executed = TRUE; } - if (g_variant_dict_lookup_value(opts, "version", NULL)) { - remmina_exec_command(REMMINA_COMMAND_VERSION, NULL); - executed = TRUE; - } - - if (g_variant_dict_lookup_value(opts, "full-version", NULL)) { - remmina_exec_command(REMMINA_COMMAND_FULL_VERSION, NULL); - executed = TRUE; - } - if (!executed) { remmina_exec_command(REMMINA_COMMAND_MAIN, NULL); } @@ -221,9 +213,6 @@ static void remmina_on_startup(GApplication *app) RemminaSecretPlugin *secret_plugin; - remmina_pref_init(); - remmina_file_manager_init(); - remmina_plugin_manager_init(); remmina_widget_pool_init(); remmina_sftp_plugin_register(); remmina_ssh_plugin_register(); @@ -256,15 +245,41 @@ static void remmina_on_startup(GApplication *app) } -static gint remmina_on_local_cmdline(GApplication *app, GVariantDict *options, gpointer user_data) +static gint remmina_on_local_cmdline(GApplication *app, GVariantDict *opts, gpointer user_data) { TRACE_CALL(__func__); int status = -1; + gchar *str; + gchar **settings; /* Here you handle any command line options that you want to be executed - * from command line, one time, and than exit */ + * in the local instance (the non-unique instance) */ + + if (g_variant_dict_lookup_value(opts, "version", NULL)) { + remmina_exec_command(REMMINA_COMMAND_VERSION, NULL); + status = 0; + } + + if (g_variant_dict_lookup_value(opts, "full-version", NULL)) { + remmina_exec_command(REMMINA_COMMAND_FULL_VERSION, NULL); + status = 0; + } + if (g_variant_dict_lookup(opts, "update-profile", "^&ay", &str)) { /* ^&ay no need to free */ + if (g_variant_dict_lookup(opts, "set-option", "^a&s", &settings)) { + if (settings != NULL) { + status = remmina_exec_set_setting(str, settings); + g_free(settings); + } else + status = 1; + } else { + status = 1; + g_print("Error: --update-profile requires --set-option\n"); + } + } + + /* Returning a non negative value here makes the application exit */ return status; } @@ -303,6 +318,12 @@ int main(int argc, char* argv[]) gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); #endif /* !HAVE_LIBGCRYPT */ + /* Initialize some remmina parts needed also on a local instance for correct handle-local-options */ + remmina_pref_init(); + remmina_file_manager_init(); + remmina_plugin_manager_init(); + + app_id = g_application_id_is_valid(REMMINA_APP_ID) ? REMMINA_APP_ID : NULL; app = gtk_application_new(app_id, G_APPLICATION_HANDLES_COMMAND_LINE); #if !GTK_CHECK_VERSION(4, 0, 0) /* This is not needed anymore starting from Gtk+ 4 */ diff --git a/src/remmina_exec.c b/src/remmina_exec.c index 13e2281ec..0d300db57 100644 --- a/src/remmina_exec.c +++ b/src/remmina_exec.c @@ -53,6 +53,7 @@ #include "remmina_exec.h" #include "remmina_icon.h" #include "remmina/remmina_trace_calls.h" +#include "remmina_file_manager.h" #ifdef SNAP_BUILD # define ISSNAP "- SNAP Build -" @@ -142,6 +143,62 @@ void remmina_application_condexit(RemminaCondExitType why) } } + +static void newline_remove(char *s) +{ + char c; + while((c = *s) != 0 && c != '\r' && c != '\n') + s++; + *s = 0; +} + +/* used for commandline parameter --update-profile X --set-option Y --set-option Z + * return a status code for exit() + */ +int remmina_exec_set_setting(gchar *profilefilename, gchar **settings) +{ + RemminaFile *remminafile; + int i; + gchar **tk, *value; + char *line = NULL; + size_t len = 0; + ssize_t read; + gboolean abort = FALSE; + + remminafile = remmina_file_manager_load_file(profilefilename); + + if (!remminafile) { + g_print(_("Unable to open profile file %s\n"), profilefilename); + return 2; + } + + for(i = 0; settings[i] != NULL && !abort; i++) { + if (strlen(settings[i]) > 0) { + tk = g_strsplit(settings[i], "=", 2); + if (tk[1] == NULL) { + read = getline(&line, &len, stdin); + if (read > 0) { + newline_remove(line); + value = line; + } else { + g_print(_("Error: an extra line of standard input is needed\n")); + abort = TRUE; + } + } else + value = tk[1]; + remmina_file_set_string(remminafile, tk[0], value); + g_strfreev(tk); + } + } + + if (line) free(line); + + if (!abort) remmina_file_save(remminafile); + + return 0; + +} + void remmina_exec_command(RemminaCommandType command, const gchar* data) { TRACE_CALL(__func__); diff --git a/src/remmina_exec.h b/src/remmina_exec.h index 433b00f54..52e5f2e9d 100644 --- a/src/remmina_exec.h +++ b/src/remmina_exec.h @@ -61,6 +61,8 @@ void remmina_exec_command(RemminaCommandType command, const gchar* data); void remmina_exec_exitremmina(void); void remmina_application_condexit(RemminaCondExitType why); +int remmina_exec_set_setting(gchar *profilefilename, gchar **settings); + G_END_DECLS |