Commit 2e8b92eb authored by Jeremy White's avatar Jeremy White

Pull a few options from ~/.config/x11spice

parent 0a3660f3
......@@ -43,6 +43,7 @@ int main(int argc, char *argv[])
rc = options_parse_arguments(argc, argv, &options);
if (rc)
goto exit;
options_from_config(&options);
/*------------------------------------------------------------------------
** Open the display
......
......@@ -19,6 +19,7 @@
*/
#include <glib.h>
#include <getopt.h>
#include <string.h>
#include <stdlib.h>
......@@ -39,8 +40,53 @@ void options_free(options_t *options)
free(options->display);
options->display = NULL;
}
g_free(options->spice_addr);
options->spice_addr = NULL;
g_free(options->spice_password);
options->spice_password = NULL;
}
static gchar * string_option(GKeyFile *u, GKeyFile *s, const gchar *section, const gchar *key)
{
gchar *ret = NULL;
GError *error = NULL;
if (u)
ret = g_key_file_get_string(u, section, key, &error);
if ((! u || error) && s)
ret = g_key_file_get_string(s, section, key, NULL);
return ret;
}
static gint int_option(GKeyFile *u, GKeyFile *s, const gchar *section, const gchar *key)
{
gint ret = 0;
GError *error = NULL;
if (u)
ret = g_key_file_get_integer(u, section, key, &error);
if ((! u || error) && s)
ret = g_key_file_get_integer(s, section, key, NULL);
return ret;
}
static gboolean bool_option(GKeyFile *u, GKeyFile *s, const gchar *section, const gchar *key)
{
gboolean ret = FALSE;
GError *error = NULL;
if (u)
ret = g_key_file_get_boolean(u, section, key, &error);
if ((! u || error) && s)
ret = g_key_file_get_boolean(s, section, key, NULL);
return ret;
}
static void usage(char *argv0)
{
fprintf(stderr, "%s: \n", argv0);
......@@ -95,3 +141,32 @@ int options_parse_arguments(int argc, char *argv[], options_t *options)
return rc;
}
void options_from_config(options_t *options)
{
GKeyFile * userkey = g_key_file_new();
GKeyFile * systemkey = g_key_file_new();
char * user_config_file = g_build_filename(g_get_user_config_dir(), "x11spice", NULL);
if(!g_key_file_load_from_file(userkey, user_config_file, G_KEY_FILE_NONE, NULL))
{
g_key_file_free(userkey);
userkey = NULL;
}
if (!g_key_file_load_from_dirs(systemkey, "x11spice", (const char**)g_get_system_config_dirs(),
NULL, G_KEY_FILE_NONE, NULL))
{
g_key_file_free(systemkey);
systemkey = NULL;
}
options->spice_addr = string_option(userkey, systemkey, "spice", "addr");
options->spice_password = string_option(userkey, systemkey, "spice", "password");
options->spice_port = int_option(userkey, systemkey, "spice", "port");
options->disable_ticketing = bool_option(userkey, systemkey, "spice", "disable_ticketing");
options->exit_on_disconnect = bool_option(userkey, systemkey, "spice", "exit_on_disconnect");
g_debug("options addr '%s', disable_ticketing %d, port %d", options->spice_addr, options->disable_ticketing, options->spice_port);
}
......@@ -28,6 +28,12 @@ typedef struct
{
long timeout;
char *display;
char *spice_addr;
int spice_port;
char *spice_password;
int disable_ticketing;
int exit_on_disconnect;
} options_t;
......@@ -37,5 +43,6 @@ typedef struct
void options_init(options_t *options);
int options_parse_arguments(int argc, char *argv[], options_t *options);
void options_free(options_t *options);
void options_from_config(options_t *options);
#endif
......@@ -318,6 +318,20 @@ void initialize_spice_instance(spice_t *s)
s->display_sin.st = (struct QXLState*) s;
}
static void set_options(spice_t *s, options_t *options)
{
if (options->disable_ticketing)
spice_server_set_noauth(s->server);
spice_server_set_addr(s->server, options->spice_addr ?
options->spice_addr : "", 0);
if (options->spice_port)
spice_server_set_port(s->server, options->spice_port);
if (options->spice_password)
spice_server_set_ticket(s->server, options->spice_password, 0, 0, 0);
}
int spice_start(spice_t *s, options_t *options)
{
s->server = spice_server_new();
......@@ -326,6 +340,8 @@ int spice_start(spice_t *s, options_t *options)
initialize_spice_instance(s);
set_options(s, options);
if (spice_server_init(s->server, s->core) < 0)
{
spice_server_destroy(s->server);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment