Exemplo n.º 1
0
/**
 * Load the session from the specified filename.
 *
 * @param ctx The context in which to load the session.
 * @param filename The name of the session file to load.
 * @param session The session to load the file into.
 *
 * @retval SR_OK Success
 * @retval SR_ERR_MALLOC Memory allocation error
 * @retval SR_ERR_DATA Malformed session file
 * @retval SR_ERR This is not a session file
 */
SR_API int sr_session_load(struct sr_context *ctx, const char *filename,
		struct sr_session **session)
{
	GKeyFile *kf;
	GError *error;
	struct zip *archive;
	struct zip_stat zs;
	struct sr_dev_inst *sdi;
	struct sr_channel *ch;
	int ret, i, j;
	uint64_t tmp_u64;
	int total_channels, k;
	int unitsize;
	char **sections, **keys, *val;
	char channelname[SR_MAX_CHANNELNAME_LEN + 1];

	if ((ret = sr_sessionfile_check(filename)) != SR_OK)
		return ret;

	if (!(archive = zip_open(filename, 0, NULL)))
		return SR_ERR;

	if (zip_stat(archive, "metadata", 0, &zs) < 0) {
		zip_discard(archive);
		return SR_ERR;
	}
	kf = sr_sessionfile_read_metadata(archive, &zs);
	zip_discard(archive);
	if (!kf)
		return SR_ERR_DATA;

	if ((ret = sr_session_new(ctx, session)) != SR_OK) {
		g_key_file_free(kf);
		return ret;
	}

	error = NULL;
	ret = SR_OK;
	sections = g_key_file_get_groups(kf, NULL);
	for (i = 0; sections[i] && ret == SR_OK; i++) {
		if (!strcmp(sections[i], "global"))
			/* nothing really interesting in here yet */
			continue;
		if (!strncmp(sections[i], "device ", 7)) {
			/* device section */
			sdi = NULL;
			keys = g_key_file_get_keys(kf, sections[i], NULL, NULL);
			for (j = 0; keys[j]; j++) {
				if (!strcmp(keys[j], "capturefile")) {
					val = g_key_file_get_string(kf, sections[i],
							keys[j], &error);
					if (!val) {
						ret = SR_ERR_DATA;
						break;
					}
					sdi = g_malloc0(sizeof(struct sr_dev_inst));
					sdi->driver = &session_driver;
					sdi->status = SR_ST_ACTIVE;
					if (!session_driver_initialized) {
						/* first device, init the driver */
						session_driver_initialized = 1;
						sdi->driver->init(sdi->driver, NULL);
					}
					sr_dev_open(sdi);
					sr_session_dev_add(*session, sdi);
					(*session)->owned_devs = g_slist_append(
							(*session)->owned_devs, sdi);
					sr_config_set(sdi, NULL, SR_CONF_SESSIONFILE,
							g_variant_new_string(filename));
					sr_config_set(sdi, NULL, SR_CONF_CAPTUREFILE,
							g_variant_new_string(val));
					g_free(val);
				} else if (!strcmp(keys[j], "samplerate")) {
					val = g_key_file_get_string(kf, sections[i],
							keys[j], &error);
					if (!sdi || !val || sr_parse_sizestring(val,
								&tmp_u64) != SR_OK) {
						g_free(val);
						ret = SR_ERR_DATA;
						break;
					}
					g_free(val);
					sr_config_set(sdi, NULL, SR_CONF_SAMPLERATE,
							g_variant_new_uint64(tmp_u64));
				} else if (!strcmp(keys[j], "unitsize")) {
					unitsize = g_key_file_get_integer(kf, sections[i],
							keys[j], &error);
					if (!sdi || unitsize <= 0 || error) {
						ret = SR_ERR_DATA;
						break;
					}
					sr_config_set(sdi, NULL, SR_CONF_CAPTURE_UNITSIZE,
							g_variant_new_uint64(unitsize));
				} else if (!strcmp(keys[j], "total probes")) {
					total_channels = g_key_file_get_integer(kf,
							sections[i], keys[j], &error);
					if (!sdi || total_channels < 0 || error) {
						ret = SR_ERR_DATA;
						break;
					}
					sr_config_set(sdi, NULL, SR_CONF_NUM_LOGIC_CHANNELS,
							g_variant_new_int32(total_channels));
					for (k = 0; k < total_channels; k++) {
						g_snprintf(channelname, sizeof channelname,
								"%d", k);
						sr_channel_new(sdi, k, SR_CHANNEL_LOGIC,
								FALSE, channelname);
					}
				} else if (!strncmp(keys[j], "probe", 5)) {
					tmp_u64 = g_ascii_strtoull(keys[j]+5, NULL, 10);
					if (!sdi || tmp_u64 == 0 || tmp_u64 > G_MAXINT) {
						ret = SR_ERR_DATA;
						break;
					}
					ch = g_slist_nth_data(sdi->channels, tmp_u64 - 1);
					if (!ch) {
						ret = SR_ERR_DATA;
						break;
					}
					val = g_key_file_get_string(kf, sections[i],
							keys[j], &error);
					if (!val) {
						ret = SR_ERR_DATA;
						break;
					}
					/* sr_session_save() */
					sr_dev_channel_name_set(ch, val);
					g_free(val);
					sr_dev_channel_enable(ch, TRUE);
				}
			}
			g_strfreev(keys);
		}
	}
	g_strfreev(sections);
	g_key_file_free(kf);

	if (error) {
		sr_err("Failed to parse metadata: %s", error->message);
		g_error_free(error);
	}
	return ret;
}
Exemplo n.º 2
0
static void
load_config( GKeyFile *file )
{
    GKeyFile *config = pgm_main_window_get_config();

    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "AutoIndent", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( auto_indent ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "AutoIndent",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "IndentOnTab", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( indent_on_tab ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "IndentOnTab",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "ShowLineNumbers", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( show_line_numbers ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "ShowLineNumbers",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "SmartHomeEnd", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( smart_home_end ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "SmartHomeEnd",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "InsertSpacesInsteadOfTab", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( insert_spaces_instead_of_tabs ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "InsertSpacesInsteadOfTab",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "HighlightCurrentLine", NULL ) )
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( highlight_current_line ),
                                      g_key_file_get_boolean( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "HighlightCurrentLine",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "IndentWidth", NULL ) )
        gtk_spin_button_set_value( GTK_SPIN_BUTTON( indent_width_editor ),
                                   g_key_file_get_integer( config,
                                                           PGM_SQL_EDITOR_CONFIG_GROUP,
                                                           "IndentWidth",
                                                           NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "TabWidth", NULL ) )
        gtk_spin_button_set_value( GTK_SPIN_BUTTON( tab_width_editor ),
                                   g_key_file_get_integer( config,
                                                           PGM_SQL_EDITOR_CONFIG_GROUP,
                                                           "TabWidth",
                                                           NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "Font", NULL ) )
        gtk_font_button_set_font_name( GTK_FONT_BUTTON( font_editor ),
                                       g_key_file_get_string( config,
                                                              PGM_SQL_EDITOR_CONFIG_GROUP,
                                                              "Font",
                                                              NULL ) );
    if( g_key_file_has_key( config, PGM_SQL_EDITOR_CONFIG_GROUP, "DrawSpaces", NULL ) )
        gtk_combo_box_set_active( GTK_COMBO_BOX( draw_spaces_editor ),
                                  g_key_file_get_integer( config,
                                                          PGM_SQL_EDITOR_CONFIG_GROUP,
                                                          "DrawSpaces",
                                                          NULL ) );
}
static GtkListStore *
hd_select_plugins_dialog_get_store (GList *loaded_plugins,
                                    gchar **plugin_dirs)
{
  GKeyFile *keyfile;
  const char *filename;
  const char *plugin_dir;
  GError *error = NULL;
  GtkListStore *store;
  GtkTreeIter iter;

  store = gtk_list_store_new (HD_SPD_N_COLUMNS, 
                              G_TYPE_STRING, 
                              G_TYPE_BOOLEAN,
                              G_TYPE_STRING); 

  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
                                        HD_SPD_COLUMN_NAME,
                                        GTK_SORT_ASCENDING);

  while ((plugin_dir = *(plugin_dirs++)))
  {
    GDir *dir;

    dir = g_dir_open (plugin_dir, 0, &error);

    if (!dir)
      {
        g_clear_error (&error);

        continue;
      }

    keyfile = g_key_file_new ();

    while ((filename = g_dir_read_name (dir)))
      {
        gchar *desktop_path = NULL;
        gchar *name = NULL;
        gchar *text_domain = NULL;
        GList *active;
        error = NULL;

        /* Only consider .desktop files */
        if (!g_str_has_suffix (filename, ".desktop")) continue;

        desktop_path = g_build_filename (plugin_dir, filename, NULL);

        g_key_file_load_from_file (keyfile,
                                   desktop_path,
                                   G_KEY_FILE_NONE,
                                   &error);

        if (error)
          {
            g_warning ("Error loading plugin configuration file: %s", error->message);

            g_error_free (error);
            g_dir_close (dir);
            g_key_file_free (keyfile);
            g_free (desktop_path);


            return NULL;
          }

        name = g_key_file_get_string (keyfile,
                                      HD_PLUGIN_CONFIG_GROUP,
                                      HD_PLUGIN_CONFIG_KEY_NAME,
                                      &error);

        if (error)
          {
            g_warning ("Error reading plugin configuration file: %s", error->message);

            g_error_free (error);
            g_dir_close (dir);
            g_key_file_free (keyfile);
            g_free (desktop_path);

            return NULL;
          }

        active = g_list_find_custom (loaded_plugins, 
                                     desktop_path, 
                                     hd_select_plugins_dialog_find_func);

        gtk_list_store_append (GTK_LIST_STORE (store), &iter);

        text_domain = g_key_file_get_string (keyfile, 
                                             HD_PLUGIN_CONFIG_GROUP,
                                             HD_PLUGIN_CONFIG_KEY_TEXT_DOMAIN, 
                                             NULL);

        gtk_list_store_set (GTK_LIST_STORE (store), &iter, 
                            HD_SPD_COLUMN_NAME, (text_domain ? dgettext(text_domain, name) : _(name)),
                            HD_SPD_COLUMN_ACTIVE, active,
                            HD_SPD_COLUMN_DESKTOP_FILE, desktop_path,
                            -1);

        g_free (desktop_path);
        g_free (text_domain);
        g_free (name);
      }

    g_key_file_free (keyfile);
    g_dir_close (dir);
  }

  return store;
}
Exemplo n.º 4
0
void tool_init(gint* ac, gchar*** av, const gchar* tool_name, GOptionEntry* tool_entries)
{
  GError *local_err = NULL;

  init();

  opt_context = g_option_context_new(tool_name);
  if (tool_allow_unknown_options)
    g_option_context_set_ignore_unknown_options(opt_context, TRUE);
  if (tool_entries)
    g_option_context_add_main_entries(opt_context, tool_entries, NULL);
  g_option_context_add_main_entries(opt_context, auth_options, NULL);
  g_option_context_add_main_entries(opt_context, basic_options, NULL);

  if (!g_option_context_parse(opt_context, ac, av, &local_err))
  {
    g_printerr("ERROR: Option parsing failed: %s\n", local_err->message);
    g_clear_error(&local_err);
    exit(1);
  }

  print_version();

  // load username/password from ini file
  if (!opt_no_config || opt_config)
  {
    gboolean status;
    gc_key_file_unref GKeyFile* kf = g_key_file_new();

    if (opt_config)
      status = g_key_file_load_from_file(kf, opt_config, 0, NULL);
    else
    {
      status = g_key_file_load_from_file(kf, MEGA_RC_FILENAME, 0, NULL);
      if (!status)
      {
        gc_free gchar* tmp = g_build_filename(g_get_home_dir(), MEGA_RC_FILENAME, NULL);
        status = g_key_file_load_from_file(kf, tmp, 0, NULL);
      }
    }

    if (status)
    {
      if (!opt_username)
        opt_username = g_key_file_get_string(kf, "Login", "Username", NULL);
      if(!opt_password)
        opt_password = g_key_file_get_string(kf, "Login", "Password", NULL);

      gint to = g_key_file_get_integer(kf, "Cache", "Timeout", &local_err);
      if (local_err == NULL)
        opt_cache_timout = to;
      else
        g_clear_error(&local_err);
    }
  }

  if (!opt_username)
  {
    g_printerr("ERROR: You must specify your mega.co.nz username (email)\n");
    exit(1);
  }

  if (!opt_password && opt_no_ask_password)
  {
    g_printerr("ERROR: You must specify your mega.co.nz password\n");
    exit(1);
  }

  if (!opt_password)
    opt_password = input_password();
}
Exemplo n.º 5
0
bool
bt_load_config(const char *filename, bt_config_t *config)
{
  GKeyFile *keyfile;
  GKeyFileFlags flags;
  GError *error = NULL;

  /* Creates a new GKeyFile object and a bitwise list of flags. */
  keyfile = g_key_file_new ();
  flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;

  /* Loads the GKeyFile from filename or return. */
  if (!g_key_file_load_from_file (keyfile, filename, flags, &error)) {
    syslog(LOG_ERR, "Cannot load config file: %s", error->message);
    return false;
  }

  /* Fills the config data struct, one section at a time. */
  config->bttracker_addr          =
    g_key_file_get_string (keyfile, "BtTracker", "Address", NULL);
  config->bttracker_port          =
    g_key_file_get_integer(keyfile, "BtTracker", "Port", NULL);
  config->thread_max              =
    g_key_file_get_integer(keyfile, "Threading", "MaxThreads", NULL);
  config->thread_max_idle_time    =
    g_key_file_get_integer(keyfile, "Threading", "MaxIdleTime", NULL);
  config->announce_wait_time      =
    g_key_file_get_integer(keyfile, "Announce",  "WaitTime", NULL);
  config->announce_peer_ttl       =
    g_key_file_get_integer(keyfile, "Announce",  "PeerTTL", NULL);
  config->announce_max_numwant    =
    g_key_file_get_integer(keyfile, "Announce",  "MaxNumWant", NULL);

  char *info_hash_restriction_str =
    g_key_file_get_string(keyfile,  "Announce",  "InfoHashRestriction", NULL);

  if (strcmp(info_hash_restriction_str, "whitelist") == 0) {
    config->info_hash_restriction = BT_RESTRICTION_WHITELIST;
  } else if (strcmp(info_hash_restriction_str, "blacklist") == 0) {
    config->info_hash_restriction = BT_RESTRICTION_BLACKLIST;
  } else {
    config->info_hash_restriction = BT_RESTRICTION_NONE;
  }

  char *log_level_str =
    g_key_file_get_string (keyfile, "BtTracker", "LogLevel", NULL);

  if (strcmp(log_level_str, "DEBUG") == 0) {
    config->bttracker_log_level_mask = LOG_DEBUG;
  } else if (strcmp(log_level_str, "INFO") == 0) {
    config->bttracker_log_level_mask = LOG_INFO;
  } else if (strcmp(log_level_str, "NOTICE") == 0) {
    config->bttracker_log_level_mask = LOG_NOTICE;
  } else if (strcmp(log_level_str, "WARNING") == 0) {
    config->bttracker_log_level_mask = LOG_WARNING;
  } else if (strcmp(log_level_str, "ERR") == 0) {
    config->bttracker_log_level_mask = LOG_ERR;
  } else if (strcmp(log_level_str, "CRIT") == 0) {
    config->bttracker_log_level_mask = LOG_CRIT;
  } else if (strcmp(log_level_str, "ALERT") == 0) {
    config->bttracker_log_level_mask = LOG_ALERT;
  } else if (strcmp(log_level_str, "EMERG") == 0) {
    config->bttracker_log_level_mask = LOG_EMERG;
  } else {
    config->bttracker_log_level_mask = LOG_INFO;
  }

  free(info_hash_restriction_str);
  free(log_level_str);

  config->redis_socket_path =
    g_key_file_get_string(keyfile,  "Redis", "SocketPath", NULL);
  config->redis_host        =
    g_key_file_get_string(keyfile,  "Redis", "Host", NULL);
  config->redis_port        =
    g_key_file_get_integer(keyfile, "Redis", "Port", NULL);
  config->redis_timeout     =
    g_key_file_get_integer(keyfile, "Redis", "Timeout", NULL);
  config->redis_db          =
    g_key_file_get_integer(keyfile, "Redis", "DB", NULL);
  config->redis_key_prefix  =
    g_key_file_get_string(keyfile,  "Redis", "KeyPrefix", NULL);

  g_key_file_free(keyfile);

  return true;
}
Exemplo n.º 6
0
	/* Get the dependency list */
	info->dependencies = g_key_file_get_string_list (plugin_file,
							 "Pluma Plugin",
							 "Depends",
							 NULL,
							 NULL);
	if (info->dependencies == NULL)
	{
		pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Depends' in %s", file);
		info->dependencies = g_new0 (gchar *, 1);
	}

	/* Get the loader for this plugin */
	str = g_key_file_get_string (plugin_file,
				     "Pluma Plugin",
				     "Loader",
				     NULL);
	
	if ((str != NULL) && (*str != '\0'))
	{
		info->loader = str;
	}
	else
	{
		/* default to the C loader */
		info->loader = g_strdup("c");
		g_free (str);
	}

	/* Get Name */
	str = g_key_file_get_locale_string (plugin_file,
Exemplo n.º 7
0
int sr_session_load(const char *filename)
{
	GKeyFile *kf;
	GPtrArray *capturefiles;
	struct zip *archive;
	struct zip_file *zf;
	struct zip_stat zs;
	struct sr_session *session;
	struct sr_device *device;
	struct sr_probe *probe;
	int ret, err, probenum, devcnt, i, j;
	uint64_t tmp_u64, total_probes, enabled_probes, p;
	char **sections, **keys, *metafile, *val, c;

	if (!(archive = zip_open(filename, 0, &err))) {
		sr_dbg("Failed to open session file: zip error %d", err);
		return SR_ERR;
	}

	/* check "version" */
	if (!(zf = zip_fopen(archive, "version", 0))) {
		sr_dbg("Not a sigrok session file.");
		return SR_ERR;
	}
	ret = zip_fread(zf, &c, 1);
	if (ret != 1 || c != '1') {
		sr_dbg("Not a valid sigrok session file.");
		return SR_ERR;
	}
	zip_fclose(zf);

	/* read "metadata" */
	if (zip_stat(archive, "metadata", 0, &zs) == -1) {
		sr_dbg("Not a valid sigrok session file.");
		return SR_ERR;
	}

	if (!(metafile = g_try_malloc(zs.size))) {
		sr_err("session file: %s: metafile malloc failed", __func__);
		return SR_ERR_MALLOC;
	}

	zf = zip_fopen_index(archive, zs.index, 0);
	zip_fread(zf, metafile, zs.size);
	zip_fclose(zf);

	kf = g_key_file_new();
	if (!g_key_file_load_from_data(kf, metafile, zs.size, 0, NULL)) {
		sr_dbg("Failed to parse metadata.");
		return SR_ERR;
	}

	session = sr_session_new();

	devcnt = 0;
	capturefiles = g_ptr_array_new_with_free_func(g_free);
	sections = g_key_file_get_groups(kf, NULL);
	for (i = 0; sections[i]; i++) {
		if (!strcmp(sections[i], "global"))
			/* nothing really interesting in here yet */
			continue;
		if (!strncmp(sections[i], "device ", 7)) {
			/* device section */
			device = NULL;
			enabled_probes = 0;
			keys = g_key_file_get_keys(kf, sections[i], NULL, NULL);
			for (j = 0; keys[j]; j++) {
				val = g_key_file_get_string(kf, sections[i], keys[j], NULL);
				if (!strcmp(keys[j], "capturefile")) {
					device = sr_device_new(&session_driver, devcnt, 0);
					if (devcnt == 0)
						/* first device, init the plugin */
						device->plugin->init((char *)filename);
					sr_session_device_add(device);
					device->plugin->set_configuration(devcnt, SR_HWCAP_CAPTUREFILE, val);
					g_ptr_array_add(capturefiles, val);
				} else if (!strcmp(keys[j], "samplerate")) {
					tmp_u64 = sr_parse_sizestring(val);
					device->plugin->set_configuration(devcnt, SR_HWCAP_SAMPLERATE, &tmp_u64);
				} else if (!strcmp(keys[j], "unitsize")) {
					tmp_u64 = strtoull(val, NULL, 10);
					device->plugin->set_configuration(devcnt, SR_HWCAP_CAPTURE_UNITSIZE, &tmp_u64);
				} else if (!strcmp(keys[j], "total probes")) {
					total_probes = strtoull(val, NULL, 10);
					device->plugin->set_configuration(devcnt, SR_HWCAP_CAPTURE_NUM_PROBES, &total_probes);
					for (p = 1; p <= total_probes; p++)
						sr_device_probe_add(device, NULL);
				} else if (!strncmp(keys[j], "probe", 5)) {
					if (!device)
						continue;
					enabled_probes++;
					tmp_u64 = strtoul(keys[j]+5, NULL, 10);
					sr_device_probe_name(device, tmp_u64, val);
				} else if (!strncmp(keys[j], "trigger", 7)) {
					probenum = strtoul(keys[j]+7, NULL, 10);
					sr_device_trigger_set(device, probenum, val);
				}
			}
			g_strfreev(keys);
			for (p = enabled_probes; p < total_probes; p++) {
				probe = g_slist_nth_data(device->probes, p);
				probe->enabled = FALSE;
			}
		}
	}
	g_strfreev(sections);
	g_key_file_free(kf);

	return SR_OK;
}
Exemplo n.º 8
0
static void
load_httpserver_config (SeafileSession *session)
{
    GError *error = NULL;
    char *host = NULL;
    int port = 0;
    int max_upload_size_mb;
    int max_download_dir_size_mb;

    host = g_key_file_get_string (session->config, "httpserver", "host", &error);
    if (!error) {
        bind_addr = host;
    } else {
        if (error->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
            error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
            seaf_warning ("[conf] Error: failed to read the value of 'host'\n");
            exit (1);
        }

        bind_addr = DEFAULT_BIND_HOST;
        g_clear_error (&error);
    }

    port = g_key_file_get_integer (session->config, "httpserver", "port", &error);
    if (!error) {
        bind_port = port;
    } else {
        if (error->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
            error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
            seaf_warning ("[conf] Error: failed to read the value of 'port'\n");
            exit (1);
        }

        bind_port = DEFAULT_BIND_PORT;
        g_clear_error (&error);
    }

    use_https = g_key_file_get_boolean (session->config,
                                        "httpserver", "https",
                                        &error);
    if (error) {
        if (error->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
            error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) {
            seaf_warning ("[conf] Error: failed to read the value of 'https'\n");
            exit (1);
        }

        /* There is no <https> field in seafile.conf, so we use http. */
        g_clear_error (&error);

    } else if (use_https) {
        /* read https config */
        pemfile = g_key_file_get_string (session->config,
                                         "httpserver", "pemfile",
                                         &error);
        if (error) {
            seaf_warning ("[conf] Error: https is true, "
                          "but the value of pemfile is unknown\n");
            exit (1);
        }

        privkey = g_key_file_get_string (session->config,
                                         "httpserver", "privkey",
                                         &error);
        if (error) {
            seaf_warning ("[conf] Error: https is true, "
                          "but the value of privkey is unknown\n");
            exit (1);
        }
    }

    max_upload_size_mb = g_key_file_get_integer (session->config,
                                                 "httpserver",
                                                 "max_upload_size",
                                                 &error);
    if (error) {
        session->max_upload_size = -1; /* no limit */
        g_clear_error (&error);
    } else {
        if (max_upload_size_mb <= 0)
            session->max_upload_size = -1; /* no limit */
        else
            session->max_upload_size = max_upload_size_mb * ((gint64)1 << 20);
    }

    max_download_dir_size_mb = g_key_file_get_integer (session->config,
                                                 "httpserver",
                                                 "max_download_dir_size",
                                                 &error);
    if (error) {
        session->max_download_dir_size = DEFAULT_MAX_DOWNLOAD_DIR_SIZE;
        g_clear_error (&error);
    } else {
        if (max_download_dir_size_mb <= 0)
            session->max_download_dir_size = DEFAULT_MAX_DOWNLOAD_DIR_SIZE;
        else
            session->max_download_dir_size = max_download_dir_size_mb * ((gint64)1 << 20);
    }
}
Exemplo n.º 9
0
/**
 * Internal spider used to get list of executables.
 */
static void get_apps_dir ( DRunModePrivateData *pd, const char *bp )
{
    DIR *dir = opendir ( bp );

    if ( dir != NULL ) {
        struct dirent *dent;

        while ( ( dent = readdir ( dir ) ) != NULL ) {
            if ( dent->d_type != DT_REG && dent->d_type != DT_LNK && dent->d_type != DT_UNKNOWN ) {
                continue;
            }
            // Skip dot files.
            if ( dent->d_name[0] == '.' ) {
                continue;
            }
            gchar    *path  = g_build_filename ( bp, dent->d_name, NULL );
            GKeyFile *kf    = g_key_file_new ();
            GError   *error = NULL;
            // TODO: check what flags to set;
            g_key_file_load_from_file ( kf, path, 0, NULL );
            if ( error == NULL ) {
                if ( g_key_file_has_key ( kf, "Desktop Entry", "Exec", NULL ) ) {
                    pd->cmd_list   = g_realloc ( pd->cmd_list, ( ( pd->cmd_list_length ) + 2 ) * sizeof ( *( pd->cmd_list ) ) );
                    pd->entry_list = g_realloc ( pd->entry_list, ( pd->cmd_list_length + 2 ) * sizeof ( *( pd->entry_list ) ) );
                    if ( g_key_file_has_key ( kf, "Desktop Entry", "Name", NULL ) ) {
                        gchar *n  = NULL;
                        gchar *gn = NULL;
                        n  = g_key_file_get_locale_string ( kf, "Desktop Entry", "Name", NULL, NULL );
                        gn = g_key_file_get_locale_string ( kf, "Desktop Entry", "GenericName", NULL, NULL );
                        if ( gn == NULL ) {
                            pd->cmd_list[pd->cmd_list_length] = g_markup_escape_text ( n, -1 );
                        }
                        else {
                            ( pd->cmd_list )[( pd->cmd_list_length )] = g_markup_printf_escaped (
                                "%s <span weight='light' size='small'><i>(%s)</i></span>",
                                n,
                                gn ? gn : "" );
                        }
                        g_free ( n ); g_free ( gn );
                    }
                    else {
                        ( pd->cmd_list )[( pd->cmd_list_length )] = g_strdup ( dent->d_name );
                    }
                    pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, "Desktop Entry", "Exec", NULL );
                    if ( g_key_file_has_key ( kf, "Desktop Entry", "Terminal", NULL ) ) {
                        pd->entry_list[pd->cmd_list_length].terminal = g_key_file_get_boolean ( kf, "Desktop Entry", "Terminal", NULL );
                    }
                    ( pd->cmd_list )[( pd->cmd_list_length ) + 1] = NULL;
                    ( pd->cmd_list_length )++;
                }
            }
            else {
                g_error_free ( error );
            }
            g_key_file_free ( kf );
            g_free ( path );
        }

        closedir ( dir );
    }
}
static char *
parse_exec (EggDesktopFile  *desktop_file,
	    GSList         **documents,
	    GError         **error)
{
  char *exec, *p, *command;
  gboolean escape, single_quot, double_quot;
  GString *gs;

  exec = g_key_file_get_string (desktop_file->key_file,
				EGG_DESKTOP_FILE_GROUP,
				EGG_DESKTOP_FILE_KEY_EXEC,
				error);
  if (!exec)
    return NULL;

  /* Build the command */
  gs = g_string_new (NULL);
  escape = single_quot = double_quot = FALSE;

  for (p = exec; *p != '\0'; p++)
    {
      if (escape)
	{
	  escape = FALSE;
	  g_string_append_c (gs, *p);
	}
      else if (*p == '\\')
	{
	  if (!single_quot)
	    escape = TRUE;
	  g_string_append_c (gs, *p);
	}
      else if (*p == '\'')
	{
	  g_string_append_c (gs, *p);
	  if (!single_quot && !double_quot)
	    single_quot = TRUE;
	  else if (single_quot)
	    single_quot = FALSE;
	}
      else if (*p == '"')
	{
	  g_string_append_c (gs, *p);
	  if (!single_quot && !double_quot)
	    double_quot = TRUE;
	  else if (double_quot)
	    double_quot = FALSE;
	}
      else if (*p == '%' && p[1])
	{
	  do_percent_subst (desktop_file, p[1], gs, documents,
			    single_quot, double_quot);
	  p++;
	}
      else
	g_string_append_c (gs, *p);
    }

  g_free (exec);
  command = g_string_free (gs, FALSE);

  /* Prepend "xdg-terminal " if needed (FIXME: use gvfs) */
  if (g_key_file_has_key (desktop_file->key_file,
			  EGG_DESKTOP_FILE_GROUP,
			  EGG_DESKTOP_FILE_KEY_TERMINAL,
			  NULL))
    {
      GError *terminal_error = NULL;
      gboolean use_terminal =
	g_key_file_get_boolean (desktop_file->key_file,
				EGG_DESKTOP_FILE_GROUP,
				EGG_DESKTOP_FILE_KEY_TERMINAL,
				&terminal_error);
      if (terminal_error)
	{
	  g_free (command);
	  g_propagate_error (error, terminal_error);
	  return NULL;
	}

      if (use_terminal)
	{
	  gs = g_string_new ("xdg-terminal ");
	  append_quoted_word (gs, command, FALSE, FALSE);
	  g_free (command);
	  command = g_string_free (gs, FALSE);
	}
    }

  return command;
}
static char *
start_startup_notification (GdkDisplay     *display,
			    EggDesktopFile *desktop_file,
			    const char     *argv0,
			    int             screen,
			    int             workspace,
			    guint32         launch_time)
{
  static int sequence = 0;
  char *startup_id;
  char *description, *wmclass;
  char *screen_str, *workspace_str;

  if (g_key_file_has_key (desktop_file->key_file,
			  EGG_DESKTOP_FILE_GROUP,
			  EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
			  NULL))
    {
      if (!g_key_file_get_boolean (desktop_file->key_file,
				   EGG_DESKTOP_FILE_GROUP,
				   EGG_DESKTOP_FILE_KEY_STARTUP_NOTIFY,
				   NULL))
	return NULL;
      wmclass = NULL;
    }
  else
    {
      wmclass = g_key_file_get_string (desktop_file->key_file,
				       EGG_DESKTOP_FILE_GROUP,
				       EGG_DESKTOP_FILE_KEY_STARTUP_WM_CLASS,
				       NULL);
      if (!wmclass)
	return NULL;
    }

  if (launch_time == (guint32)-1)
    launch_time = gdk_x11_display_get_user_time (display);
  startup_id = g_strdup_printf ("%s-%lu-%s-%s-%d_TIME%lu",
				g_get_prgname (),
				(unsigned long)getpid (),
				g_get_host_name (),
				argv0,
				sequence++,
				(unsigned long)launch_time);

  description = g_strdup_printf (_("Starting %s"), desktop_file->name);
  screen_str = g_strdup_printf ("%d", screen);
  workspace_str = workspace == -1 ? NULL : g_strdup_printf ("%d", workspace);

  gdk_x11_display_broadcast_startup_message (display, "new",
					     "ID", startup_id,
					     "NAME", desktop_file->name,
					     "SCREEN", screen_str,
					     "BIN", argv0,
					     "ICON", desktop_file->icon,
					     "DESKTOP", workspace_str,
					     "DESCRIPTION", description,
					     "WMCLASS", wmclass,
					     NULL);

  g_free (description);
  g_free (wmclass);
  g_free (screen_str);
  g_free (workspace_str);

  return startup_id;
}
/**
 * egg_desktop_file_can_launch:
 * @desktop_file: an #EggDesktopFile
 * @desktop_environment: the name of the running desktop environment,
 * or %NULL
 *
 * Tests if @desktop_file can/should be launched in the current
 * environment. If @desktop_environment is non-%NULL, @desktop_file's
 * "OnlyShowIn" and "NotShowIn" keys are checked to make sure that
 * this desktop_file is appropriate for the named environment.
 *
 * Furthermore, if @desktop_file has type
 * %EGG_DESKTOP_FILE_TYPE_APPLICATION, its "TryExec" key (if any) is
 * also checked, to make sure the binary it points to exists.
 *
 * egg_desktop_file_can_launch() does NOT check the value of the
 * "Hidden" key.
 *
 * Return value: %TRUE if @desktop_file can be launched
 **/
gboolean
egg_desktop_file_can_launch (EggDesktopFile *desktop_file,
			     const char     *desktop_environment)
{
  char *try_exec, *found_program;
  char **only_show_in, **not_show_in;
  gboolean found;
  int i;

  if (desktop_file->type != EGG_DESKTOP_FILE_TYPE_APPLICATION &&
      desktop_file->type != EGG_DESKTOP_FILE_TYPE_LINK)
    return FALSE;

  if (desktop_environment)
    {
      only_show_in = g_key_file_get_string_list (desktop_file->key_file,
						 EGG_DESKTOP_FILE_GROUP,
						 EGG_DESKTOP_FILE_KEY_ONLY_SHOW_IN,
						 NULL, NULL);
      if (only_show_in)
	{
	  for (i = 0, found = FALSE; only_show_in[i] && !found; i++)
	    {
	      if (!strcmp (only_show_in[i], desktop_environment))
		found = TRUE;
	    }

	  g_strfreev (only_show_in);

	  if (!found)
	    return FALSE;
	}

      not_show_in = g_key_file_get_string_list (desktop_file->key_file,
						EGG_DESKTOP_FILE_GROUP,
						EGG_DESKTOP_FILE_KEY_NOT_SHOW_IN,
						NULL, NULL);
      if (not_show_in)
	{
	  for (i = 0, found = FALSE; not_show_in[i] && !found; i++)
	    {
	      if (!strcmp (not_show_in[i], desktop_environment))
		found = TRUE;
	    }

	  g_strfreev (not_show_in);

	  if (found)
	    return FALSE;
	}
    }

  if (desktop_file->type == EGG_DESKTOP_FILE_TYPE_APPLICATION)
    {
      try_exec = g_key_file_get_string (desktop_file->key_file,
					EGG_DESKTOP_FILE_GROUP,
					EGG_DESKTOP_FILE_KEY_TRY_EXEC,
					NULL);
      if (try_exec)
	{
	  found_program = g_find_program_in_path (try_exec);
	  g_free (try_exec);

	  if (!found_program)
	    return FALSE;
	  g_free (found_program);
	}
    }

  return TRUE;
}
/**
 * egg_desktop_file_new_from_key_file:
 * @key_file: a #GKeyFile representing a desktop file
 * @source: the path or URI that @key_file was loaded from, or %NULL
 * @error: error pointer
 *
 * Creates a new #EggDesktopFile for @key_file. Assumes ownership of
 * @key_file (on success or failure); you should consider @key_file to
 * be freed after calling this function.
 *
 * Return value: the new #EggDesktopFile, or %NULL on error.
 **/
EggDesktopFile *
egg_desktop_file_new_from_key_file (GKeyFile    *key_file,
				    const char  *source,
				    GError     **error)
{
  EggDesktopFile *desktop_file;
  char *version, *type;

  if (!g_key_file_has_group (key_file, EGG_DESKTOP_FILE_GROUP))
    {
      g_set_error (error, EGG_DESKTOP_FILE_ERROR,
		   EGG_DESKTOP_FILE_ERROR_INVALID,
		   _("File is not a valid .desktop file"));
      g_key_file_free (key_file);
      return NULL;
    }

  version = g_key_file_get_value (key_file, EGG_DESKTOP_FILE_GROUP,
				  EGG_DESKTOP_FILE_KEY_VERSION,
				  NULL);
  if (version)
    {
      double version_num;
      char *end;

      version_num = g_ascii_strtod (version, &end);
      if (*end)
	{
	  g_warning ("Invalid Version string '%s' in %s",
		     version, source ? source : "(unknown)");
	}
      else if (version_num > 1.0)
	{
	  g_set_error (error, EGG_DESKTOP_FILE_ERROR,
		       EGG_DESKTOP_FILE_ERROR_INVALID,
		       _("Unrecognized desktop file Version '%s'"), version);
	  g_free (version);
	  g_key_file_free (key_file);
	  return NULL;
	}
      g_free (version);
    }

  desktop_file = g_new0 (EggDesktopFile, 1);
  desktop_file->key_file = key_file;

  if (g_path_is_absolute (source))
    desktop_file->source = g_filename_to_uri (source, NULL, NULL);
  else
    desktop_file->source = g_strdup (source);

  desktop_file->name = g_key_file_get_string (key_file, EGG_DESKTOP_FILE_GROUP,
					      EGG_DESKTOP_FILE_KEY_NAME, error);
  if (!desktop_file->name)
    {
      egg_desktop_file_free (desktop_file);
      return NULL;
    }

  type = g_key_file_get_string (key_file, EGG_DESKTOP_FILE_GROUP,
				EGG_DESKTOP_FILE_KEY_TYPE, error);
  if (!type)
    {
      egg_desktop_file_free (desktop_file);
      return NULL;
    }

  if (!strcmp (type, "Application"))
    {
      char *exec, *p;

      desktop_file->type = EGG_DESKTOP_FILE_TYPE_APPLICATION;

      exec = g_key_file_get_string (key_file,
				    EGG_DESKTOP_FILE_GROUP,
				    EGG_DESKTOP_FILE_KEY_EXEC,
				    error);
      if (!exec)
	{
	  egg_desktop_file_free (desktop_file);
	  g_free (type);
	  return NULL;
	}

      /* See if it takes paths or URIs or neither */
      for (p = exec; *p; p++)
	{
	  if (*p == '%')
	    {
	      if (p[1] == '\0' || strchr ("FfUu", p[1]))
		{
		  desktop_file->document_code = p[1];
		  break;
		}
	      p++;
	    }
	}

      g_free (exec);
    }
  else if (!strcmp (type, "Link"))
    {
      char *url;

      desktop_file->type = EGG_DESKTOP_FILE_TYPE_LINK;

      url = g_key_file_get_string (key_file,
				   EGG_DESKTOP_FILE_GROUP,
				   EGG_DESKTOP_FILE_KEY_URL,
				   error);
      if (!url)
	{
	  egg_desktop_file_free (desktop_file);
	  g_free (type);
	  return NULL;
	}
      g_free (url);
    }
  else if (!strcmp (type, "Directory"))
    desktop_file->type = EGG_DESKTOP_FILE_TYPE_DIRECTORY;
  else
    desktop_file->type = EGG_DESKTOP_FILE_TYPE_UNRECOGNIZED;

  g_free (type);

  /* Check the Icon key */
  desktop_file->icon = g_key_file_get_string (key_file,
					      EGG_DESKTOP_FILE_GROUP,
					      EGG_DESKTOP_FILE_KEY_ICON,
					      NULL);
  if (desktop_file->icon && !g_path_is_absolute (desktop_file->icon))
    {
      char *ext;

      /* Lots of .desktop files still get this wrong */
      ext = strrchr (desktop_file->icon, '.');
      if (ext && (!strcmp (ext, ".png") ||
		  !strcmp (ext, ".xpm") ||
		  !strcmp (ext, ".svg")))
	{
	  g_warning ("Desktop file '%s' has malformed Icon key '%s'"
		     "(should not include extension)",
		     source ? source : "(unknown)",
		     desktop_file->icon);
	  *ext = '\0';
	}
    }

  return desktop_file;
}
Exemplo n.º 14
0
/* parse the config file, using the Settings struct */
static void parse_config_file(gchar *config_file) {
  GKeyFile *keyfile;
  GError *error = NULL;
  gchar *addid; 
  int i = 0;
  addid = (gchar *) g_malloc (3);

  keyfile = g_key_file_new();
  if (!g_key_file_load_from_file(keyfile, config_file, G_KEY_FILE_NONE, &error)) {
    g_warning("Error parsing config file %s: %s\n",
        config_file,
        error->message);
  }

  config = g_slice_new(Settings);

  /* General Settings */
  config->browser_command = g_key_file_get_string(
      keyfile, "general", "browser", NULL);


  /* UI Settings */
  config->audible_bell = g_key_file_get_boolean(
      keyfile, "ui", "audible_bell", NULL);
  config->autohide_mouse = g_key_file_get_boolean(
      keyfile, "ui", "autohide_mouse", NULL);
  config->allow_bold = g_key_file_get_boolean(
      keyfile, "ui", "allow_bold", NULL);
  config->font = g_key_file_get_string(
      keyfile, "ui", "font", NULL);
  config->fullscreen = g_key_file_get_boolean(
      keyfile, "ui", "fullscreen", NULL);
  config->num_scrollback_lines = g_key_file_get_integer(
      keyfile, "ui", "num_scrollback_lines", NULL);
  config->scroll_on_keystroke = g_key_file_get_boolean(
      keyfile, "ui", "scroll_on_keystroke", NULL);
  config->scroll_on_output = g_key_file_get_boolean(
      keyfile, "ui", "scroll_on_output", NULL);
  config->bg_transparent = g_key_file_get_boolean(
      keyfile, "ui", "bg_transparent", NULL);
  config->bg_image = g_key_file_get_string(
      keyfile, "ui", "bg_image", NULL);
  config->bg_saturation = g_key_file_get_double(
      keyfile, "ui", "bg_saturation", NULL);
  config->url_regex = g_key_file_get_string(
      keyfile, "ui", "url_regex", NULL);
  config->visible_bell = g_key_file_get_boolean(
      keyfile, "ui", "visible_bell", NULL);
  config->window_height = g_key_file_get_integer(
      keyfile, "ui", "window_height", NULL);
  config->window_width = g_key_file_get_integer(
      keyfile, "ui", "window_width", NULL);
  config->word_chars = g_key_file_get_string(
      keyfile, "ui", "word_chars", NULL);

  /* Color Scheme Settings */
  config->cursor = g_key_file_get_string(
      keyfile, "colour scheme", "cursor", NULL);

  config->colour_palette = (GdkColor *) g_malloc(sizeof(GdkColor) * DEFAULT_PALETTE_SIZE);
  for (i=0; i < DEFAULT_PALETTE_SIZE; i++){
    g_snprintf(addid, 3, "%d", i);
    gdk_color_parse(g_key_file_get_string(keyfile, "colour scheme", 
          addid , NULL), &config->colour_palette[i]);
  }

  if (!gdk_color_parse(g_key_file_get_string(
          keyfile, "colour scheme", "foreground", NULL), &config->foreground)){
    gdk_color_parse(DEFAULT_FOREGROUND_COLOR, &config->foreground);
    g_warning("Using default foreground color");
  }

  if (!gdk_color_parse(g_key_file_get_string(
          keyfile, "colour scheme", "background", NULL), &config->background)){
    gdk_color_parse(DEFAULT_BACKGROUND_COLOR, &config->background);
    g_warning("Using default background color");
  }

  if (NULL == config->font) {
    config->font = DEFAULT_FONT;
  }

  if(NULL == config->browser_command) {
    config->browser_command = DEFAULT_BROWSER_COMMAND; 
  }

  if (NULL == config->url_regex) {
    config->url_regex = DEFAULT_URL_REGEX;
  }

  g_free(addid);
  g_key_file_free(keyfile);
}
Exemplo n.º 15
0
/* Main code */
int main(int argc, char* argv[])
{
	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window), "Suse Control Center");
	gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
	g_signal_connect(G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL);

	bool is_root = getuid () == 0;

	View view;
	{  // adding groups
		GKeyFile *file = g_key_file_new();
		std::set <std::string> groups = subfiles (YAST_GROUPS);
		for (std::set <std::string>::iterator it = groups.begin();
		     it != groups.end(); it++) {
			if (!g_key_file_load_from_file (file, (YAST_GROUPS + (*it)).c_str(),
			                                G_KEY_FILE_NONE, NULL))
				continue;

			gchar* name = g_key_file_get_locale_string (file, "Desktop Entry", "Name", 0, NULL);
			gchar *nick = g_key_file_get_string (file, "Desktop Entry", "X-SuSE-YaST-Group", NULL);
			gchar *icon = g_key_file_get_string (file, "Desktop Entry", "Icon", NULL);
			gchar *sort_key = g_key_file_get_string (file, "Desktop Entry",
			                                         "X-SuSE-YaST-SortKey", NULL);
			if (name && nick)
				view.addGroup (name, icon, nick, sort_key);

			if (name)     g_free (name);
			if (nick)     g_free (nick);
			if (icon)     g_free (icon);
			if (sort_key) g_free (sort_key);
		}
		g_key_file_free (file);
	}
	{  // adding entries
		GKeyFile *file = g_key_file_new();
		std::set <std::string> entries = subfiles (YAST_ENTRIES);
		for (std::set <std::string>::iterator it = entries.begin();
		     it != entries.end(); it++) {
			if (!g_key_file_load_from_file (file, (YAST_ENTRIES + (*it)).c_str(),
			                                G_KEY_FILE_NONE, NULL))
				continue;

			gchar *group = g_key_file_get_string (file, "Desktop Entry", "X-SuSE-YaST-Group", NULL);
			gchar* name = g_key_file_get_locale_string (file, "Desktop Entry", "Name", 0, NULL);
			gchar *icon = g_key_file_get_string (file, "Desktop Entry", "Icon", NULL);
			gchar *command = g_key_file_get_string (file, "Desktop Entry", "Exec", NULL);
			gboolean needs_root = g_key_file_get_boolean (file, "Desktop Entry",
			                          "X-SuSE-YaST-RootOnly", NULL);

			if (group && name && command && (!needs_root || is_root))
				view.addEntry (group, name, icon, command);

			if (group)   g_free (group);
			if (name)    g_free (name);
			if (icon)    g_free (icon);
			if (command) g_free (command);
		}
		g_key_file_free (file);
	}

	gtk_container_add (GTK_CONTAINER (window), view.getWidget());
	gtk_widget_show_all (window);

	if (!is_root) {
		GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (window),
			GtkDialogFlags (0), GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
			"You are executing the control center as an ordinary user.\n"
			"Only a few modules will be available.");
		gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);
	}

	gtk_main();
	return 0;
}
Exemplo n.º 16
0
/**
 * @name parseConfig
 * @description Open and parse a name filename 
 * @param char *filename
 * @return config cfg;
 */
config parseConfig(char *filename) {

    GKeyFile *keyfile;

    keyfile = g_key_file_new();

    if(! (g_key_file_load_from_file(keyfile, filename, 0, NULL))){
        printf("Error opening %s: %s\n", filename, strerror(errno));
        exit(-1); 
    }

    /* config struct */
    config cfg;

    memset(&cfg, 0, sizeof(config));

    /* tcp daemon main configuration */
    cfg.listen_address  = g_key_file_get_string(keyfile, "main",  "address", NULL);
    cfg.listen_port     = g_key_file_get_integer(keyfile, "main",  "port", NULL);
    cfg.registry_prefix = g_key_file_get_string(keyfile, "main",  "registry_prefix", NULL);
    cfg.expire_seconds  = g_key_file_get_string(keyfile, "main", "expire_seconds", NULL);

    /* redis configuration */
    cfg.redis_address     = g_key_file_get_string(keyfile, "redis", "address", NULL);
    cfg.redis_port        = g_key_file_get_integer(keyfile, "redis", "port", NULL);
    cfg.redis_db_index    = g_key_file_get_string(keyfile, "redis", "db_index", NULL);
    cfg.redis_reload_time = g_key_file_get_integer(keyfile, "redis", "reload_time", NULL);

    /* mysql configuration */
    cfg.mysql_address  = g_key_file_get_string(keyfile, "mysql", "address", NULL);
    cfg.mysql_port     = g_key_file_get_integer(keyfile, "mysql", "port", NULL);
    cfg.mysql_username = g_key_file_get_string(keyfile, "mysql", "username", NULL);
    cfg.mysql_password = g_key_file_get_string(keyfile, "mysql", "password", NULL);
    cfg.mysql_dbname   = g_key_file_get_string(keyfile, "mysql", "dbname", NULL);
    cfg.mysql_enabled  = g_key_file_get_boolean(keyfile, "mysql", "enabled", NULL);
    cfg.missing_registry_mysql_query = g_key_file_get_string(keyfile, "mysql", "missing_registry_query", NULL);

    /* postgresql configuration */
    cfg.pgsql_address  = g_key_file_get_string(keyfile, "pgsql", "address", NULL);
    cfg.pgsql_port     = g_key_file_get_integer(keyfile, "pgsql", "port", NULL);
    cfg.pgsql_username = g_key_file_get_string(keyfile, "pgsql", "username", NULL);
    cfg.pgsql_password = g_key_file_get_string(keyfile, "pgsql", "password", NULL);
    cfg.pgsql_dbname   = g_key_file_get_string(keyfile, "pgsql", "dbname", NULL);
    cfg.pgsql_enabled  = g_key_file_get_boolean(keyfile, "pgsql", "enabled", NULL);
    cfg.missing_registry_pgsql_query = g_key_file_get_string(keyfile, "pgsql", "missing_registry_query", NULL);

    cfg.ldap_uri         = g_key_file_get_string(keyfile, "ldap", "uri", NULL);
    cfg.ldap_bind_dn     = g_key_file_get_string(keyfile, "ldap", "bind_dn", NULL);
    cfg.ldap_bind_pw     = g_key_file_get_string(keyfile, "ldap", "bind_pw", NULL);
    cfg.ldap_base        = g_key_file_get_string(keyfile, "ldap", "base", NULL);
    cfg.ldap_enabled     = g_key_file_get_boolean(keyfile, "ldap", "enabled", NULL);
    cfg.ldap_search_filter = g_key_file_get_string(keyfile, "ldap", "search_filter", NULL);
    cfg.ldap_result_attr = g_key_file_get_string(keyfile, "ldap", "result_attr", NULL);



    g_key_file_free(keyfile);

    return cfg;
}
Exemplo n.º 17
0
/**
 * pk_backend_load:
 *
 * Responsible for initialising the external backend object.
 *
 * Typically this will involve taking database locks for exclusive package access.
 * This method should only be called from the engine, unless the backend object
 * is used in self-check code, in which case the lock and unlock will have to
 * be done manually.
 **/
gboolean
pk_backend_load (PkBackend *backend, GError **error)
{
	GModule *handle;
	gboolean ret = FALSE;
	gpointer func = NULL;
	_cleanup_free_ gchar *backend_name = NULL;
	_cleanup_free_ gchar *path = NULL;

	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);

	/* already loaded */
	if (backend->priv->loaded) {
		g_set_error (error, 1, 0,
			     "already set name to %s",
			     backend->priv->name);
		return FALSE;
	}

	/* can we load it? */
	backend_name = g_key_file_get_string (backend->priv->conf,
					      "Daemon",
					      "DefaultBackend",
					      error);
	if (backend_name == NULL)
		return FALSE;

	/* the "hawkey" backend was renamed to "hif" */
	if (g_strcmp0 (backend_name, "hawkey") == 0) {
		g_free (backend_name);
		backend_name = g_strdup ("hif");
	}

	g_debug ("Trying to load : %s", backend_name);
	path = pk_backend_build_library_path (backend, backend_name);
	handle = g_module_open (path, 0);
	if (handle == NULL) {
		g_set_error (error, 1, 0, "opening module %s failed : %s",
			     backend_name, g_module_error ());
		return FALSE;
	}

	/* then check for the new style exported functions */
	ret = g_module_symbol (handle, "pk_backend_get_description", (gpointer *)&func);
	if (ret) {
		PkBackendDesc *desc;
		PkBackendGetCompatStringFunc backend_vfunc;
		desc = g_new0 (PkBackendDesc, 1);

		/* connect up exported methods */
		g_module_symbol (handle, "pk_backend_cancel", (gpointer *)&desc->cancel);
		g_module_symbol (handle, "pk_backend_destroy", (gpointer *)&desc->destroy);
		g_module_symbol (handle, "pk_backend_download_packages", (gpointer *)&desc->download_packages);
		g_module_symbol (handle, "pk_backend_get_categories", (gpointer *)&desc->get_categories);
		g_module_symbol (handle, "pk_backend_depends_on", (gpointer *)&desc->depends_on);
		g_module_symbol (handle, "pk_backend_get_details", (gpointer *)&desc->get_details);
		g_module_symbol (handle, "pk_backend_get_details_local", (gpointer *)&desc->get_details_local);
		g_module_symbol (handle, "pk_backend_get_files_local", (gpointer *)&desc->get_files_local);
		g_module_symbol (handle, "pk_backend_get_distro_upgrades", (gpointer *)&desc->get_distro_upgrades);
		g_module_symbol (handle, "pk_backend_get_files", (gpointer *)&desc->get_files);
		g_module_symbol (handle, "pk_backend_get_filters", (gpointer *)&desc->get_filters);
		g_module_symbol (handle, "pk_backend_get_groups", (gpointer *)&desc->get_groups);
		g_module_symbol (handle, "pk_backend_get_mime_types", (gpointer *)&desc->get_mime_types);
		g_module_symbol (handle, "pk_backend_supports_parallelization", (gpointer *)&desc->supports_parallelization);
		g_module_symbol (handle, "pk_backend_get_packages", (gpointer *)&desc->get_packages);
		g_module_symbol (handle, "pk_backend_get_repo_list", (gpointer *)&desc->get_repo_list);
		g_module_symbol (handle, "pk_backend_required_by", (gpointer *)&desc->required_by);
		g_module_symbol (handle, "pk_backend_get_roles", (gpointer *)&desc->get_roles);
		g_module_symbol (handle, "pk_backend_get_provides", (gpointer *)&desc->get_provides);
		g_module_symbol (handle, "pk_backend_get_update_detail", (gpointer *)&desc->get_update_detail);
		g_module_symbol (handle, "pk_backend_get_updates", (gpointer *)&desc->get_updates);
		g_module_symbol (handle, "pk_backend_initialize", (gpointer *)&desc->initialize);
		g_module_symbol (handle, "pk_backend_install_files", (gpointer *)&desc->install_files);
		g_module_symbol (handle, "pk_backend_install_packages", (gpointer *)&desc->install_packages);
		g_module_symbol (handle, "pk_backend_install_signature", (gpointer *)&desc->install_signature);
		g_module_symbol (handle, "pk_backend_refresh_cache", (gpointer *)&desc->refresh_cache);
		g_module_symbol (handle, "pk_backend_remove_packages", (gpointer *)&desc->remove_packages);
		g_module_symbol (handle, "pk_backend_repo_enable", (gpointer *)&desc->repo_enable);
		g_module_symbol (handle, "pk_backend_repo_set_data", (gpointer *)&desc->repo_set_data);
		g_module_symbol (handle, "pk_backend_repo_remove", (gpointer *)&desc->repo_remove);
		g_module_symbol (handle, "pk_backend_resolve", (gpointer *)&desc->resolve);
		g_module_symbol (handle, "pk_backend_search_details", (gpointer *)&desc->search_details);
		g_module_symbol (handle, "pk_backend_search_files", (gpointer *)&desc->search_files);
		g_module_symbol (handle, "pk_backend_search_groups", (gpointer *)&desc->search_groups);
		g_module_symbol (handle, "pk_backend_search_names", (gpointer *)&desc->search_names);
		g_module_symbol (handle, "pk_backend_start_job", (gpointer *)&desc->job_start);
		g_module_symbol (handle, "pk_backend_stop_job", (gpointer *)&desc->job_stop);
		g_module_symbol (handle, "pk_backend_reset_job", (gpointer *)&desc->job_reset);
		g_module_symbol (handle, "pk_backend_update_packages", (gpointer *)&desc->update_packages);
		g_module_symbol (handle, "pk_backend_what_provides", (gpointer *)&desc->what_provides);
		g_module_symbol (handle, "pk_backend_repair_system", (gpointer *)&desc->repair_system);

		/* get old static string data */
		ret = g_module_symbol (handle, "pk_backend_get_author", (gpointer *)&backend_vfunc);
		if (ret)
			desc->author = backend_vfunc (backend);
		ret = g_module_symbol (handle, "pk_backend_get_description", (gpointer *)&backend_vfunc);
		if (ret)
			desc->description = backend_vfunc (backend);

		/* make available */
		backend->priv->desc = desc;
	} else {
		g_module_close (handle);
		g_set_error (error, 1, 0,
			     "could not find description in plugin %s, not loading",
			     backend_name);
		return FALSE;
	}

	/* save the backend name and handle */
	g_free (backend->priv->name);
	backend->priv->name = g_strdup (backend_name);
	backend->priv->handle = handle;

	/* initialize if we can */
	if (backend->priv->desc->initialize != NULL) {
		backend->priv->during_initialize = TRUE;
		backend->priv->desc->initialize (backend->priv->conf, backend);
		backend->priv->during_initialize = FALSE;
	}
	backend->priv->loaded = TRUE;
	return TRUE;
}
Exemplo n.º 18
0
ProfAccount*
accounts_get_account(const char *const name)
{
    if (!g_key_file_has_group(accounts, name)) {
        return NULL;
    } else {
        gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL);

        // fix accounts that have no jid property by setting to name
        if (jid == NULL) {
            g_key_file_set_string(accounts, name, "jid", name);
            _save_accounts();
        }

        gchar *password = g_key_file_get_string(accounts, name, "password", NULL);
        gchar *eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL);
        gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL);

        gchar *server = g_key_file_get_string(accounts, name, "server", NULL);
        gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL);
        int port = g_key_file_get_integer(accounts, name, "port", NULL);

        gchar *last_presence = g_key_file_get_string(accounts, name, "presence.last", NULL);
        gchar *login_presence = g_key_file_get_string(accounts, name, "presence.login", NULL);

        int priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL);
        int priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL);
        int priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL);
        int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL);
        int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL);

        gchar *muc_service = NULL;
        if (g_key_file_has_key(accounts, name, "muc.service", NULL)) {
            muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
        } else {
            jabber_conn_status_t conn_status = connection_get_status();
            if (conn_status == JABBER_CONNECTED) {
                char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
                if (conf_jid) {
                    muc_service = strdup(conf_jid);
                }
            }
        }
        gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);

        gchar *otr_policy = NULL;
        if (g_key_file_has_key(accounts, name, "otr.policy", NULL)) {
            otr_policy = g_key_file_get_string(accounts, name, "otr.policy", NULL);
        }

        gsize length;
        GList *otr_manual = NULL;
        gchar **manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL);
        if (manual) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_manual = g_list_append(otr_manual, strdup(manual[i]));
            }
            g_strfreev(manual);
        }

        GList *otr_opportunistic = NULL;
        gchar **opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL);
        if (opportunistic) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i]));
            }
            g_strfreev(opportunistic);
        }

        GList *otr_always = NULL;
        gchar **always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL);
        if (always) {
            int i = 0;
            for (i = 0; i < length; i++) {
                otr_always = g_list_append(otr_always, strdup(always[i]));
            }
            g_strfreev(always);
        }

        gchar *pgp_keyid = NULL;
        if (g_key_file_has_key(accounts, name, "pgp.keyid", NULL)) {
            pgp_keyid = g_key_file_get_string(accounts, name, "pgp.keyid", NULL);
        }

        gchar *startscript = NULL;
        if (g_key_file_has_key(accounts, name, "script.start", NULL)) {
            startscript = g_key_file_get_string(accounts, name, "script.start", NULL);
        }

        gchar *theme = NULL;
        if (g_key_file_has_key(accounts, name, "theme", NULL)) {
            theme = g_key_file_get_string(accounts, name, "theme", NULL);
        }

        gchar *tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL);
        if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) &&
                (g_strcmp0(tls_policy, "allow") != 0) &&
                (g_strcmp0(tls_policy, "disable") != 0) &&
                (g_strcmp0(tls_policy, "legacy") != 0))) {
            g_free(tls_policy);
            tls_policy = NULL;
        }

        ProfAccount *new_account = account_new(name, jid, password, eval_password, enabled,
            server, port, resource, last_presence, login_presence,
            priority_online, priority_chat, priority_away, priority_xa,
            priority_dnd, muc_service, muc_nick, otr_policy, otr_manual,
            otr_opportunistic, otr_always, pgp_keyid, startscript, theme, tls_policy);

        g_free(jid);
        g_free(password);
        g_free(eval_password);
        g_free(server);
        g_free(resource);
        g_free(last_presence);
        g_free(login_presence);
        g_free(muc_service);
        g_free(muc_nick);
        g_free(otr_policy);
        g_free(pgp_keyid);
        g_free(startscript);
        g_free(theme);
        g_free(tls_policy);

        return new_account;
    }
}
Exemplo n.º 19
0
/**
 * pluma_plugin_info_new:
 * @filename: the filename where to read the plugin information
 *
 * Creates a new #PlumaPluginInfo from a file on the disk.
 *
 * Return value: a newly created #PlumaPluginInfo.
 */
PlumaPluginInfo *
_pluma_plugin_info_new (const gchar *file)
{
	PlumaPluginInfo *info;
	GKeyFile *plugin_file = NULL;
	gchar *str;

	g_return_val_if_fail (file != NULL, NULL);

	pluma_debug_message (DEBUG_PLUGINS, "Loading plugin: %s", file);

	info = g_new0 (PlumaPluginInfo, 1);
	info->refcount = 1;
	info->file = g_strdup (file);

	plugin_file = g_key_file_new ();
	if (!g_key_file_load_from_file (plugin_file, file, G_KEY_FILE_NONE, NULL))
	{
		g_warning ("Bad plugin file: %s", file);
		goto error;
	}

	if (!g_key_file_has_key (plugin_file,
			   	 "Pluma Plugin",
				 "IAge",
				 NULL))
	{
		pluma_debug_message (DEBUG_PLUGINS,
				     "IAge key does not exist in file: %s", file);
		goto error;
	}
	
	/* Check IAge=2 */
	if (g_key_file_get_integer (plugin_file,
				    "Pluma Plugin",
				    "IAge",
				    NULL) != 2)
	{
		pluma_debug_message (DEBUG_PLUGINS,
				     "Wrong IAge in file: %s", file);
		goto error;
	}
				    
	/* Get module name */
	str = g_key_file_get_string (plugin_file,
				     "Pluma Plugin",
				     "Module",
				     NULL);

	if ((str != NULL) && (*str != '\0'))
	{
		info->module_name = str;
	}
	else
	{
		g_warning ("Could not find 'Module' in %s", file);
		g_free (str);
		goto error;
	}

	/* Get the dependency list */
	info->dependencies = g_key_file_get_string_list (plugin_file,
							 "Pluma Plugin",
							 "Depends",
							 NULL,
							 NULL);
	if (info->dependencies == NULL)
	{
		pluma_debug_message (DEBUG_PLUGINS, "Could not find 'Depends' in %s", file);
		info->dependencies = g_new0 (gchar *, 1);
	}
Exemplo n.º 20
0
gboolean
accounts_rename(const char *const account_name, const char *const new_name)
{
    if (g_key_file_has_group(accounts, new_name)) {
        return FALSE;
    }

    if (!g_key_file_has_group(accounts, account_name)) {
        return FALSE;
    }

    // treat all properties as strings for copy
    gchar *string_keys[] = {
        "enabled",
        "jid",
        "server",
        "port",
        "resource",
        "password",
        "eval_password",
        "presence.last",
        "presence.laststatus",
        "presence.login",
        "priority.online",
        "priority.chat",
        "priority.away",
        "priority.xa",
        "priority.dnd",
        "muc.service",
        "muc.nick",
        "otr.policy",
        "otr.manual",
        "otr.opportunistic",
        "otr.always",
        "pgp.keyid",
        "last.activity",
        "script.start",
        "tls.policy"
    };

    int i;
    for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
        char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
        if (value) {
            g_key_file_set_string(accounts, new_name, string_keys[i], value);
            g_free(value);
        }
    }

    g_key_file_remove_group(accounts, account_name, NULL);
    _save_accounts();

    autocomplete_remove(all_ac, account_name);
    autocomplete_add(all_ac, new_name);
    if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
        autocomplete_remove(enabled_ac, account_name);
        autocomplete_add(enabled_ac, new_name);
    }

    return TRUE;
}
Exemplo n.º 21
0
static GIcon *
nemo_link_get_link_icon_from_desktop (GKeyFile *key_file)
{
	char *icon_str, *p, *type = NULL;
	GFile *file;
	GIcon *icon;

	/* Look at the Icon: key */
	icon_str = g_key_file_get_string (key_file, MAIN_GROUP, "Icon", NULL);

	/* if it's an absolute path, return a GFileIcon for that path */
	if (icon_str != NULL && g_path_is_absolute (icon_str)) {
		file = g_file_new_for_path (icon_str);
		icon = g_file_icon_new (file);

		g_object_unref (file);

		goto out;
	}

	type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);

	if (icon_str == NULL) {
		if (g_strcmp0 (type, "Application") == 0) {
			icon_str = g_strdup ("application-x-executable");
		} else if (g_strcmp0 (type, "FSDevice") == 0) {
			icon_str = g_strdup ("drive-harddisk");
		} else if (g_strcmp0 (type, "Directory") == 0) {
			icon_str = g_strdup (NEMO_ICON_FOLDER);
		} else if (g_strcmp0 (type, "Service") == 0 ||
			   g_strcmp0 (type, "ServiceType") == 0) {
			icon_str = g_strdup ("folder-remote");
		} else {
			icon_str = g_strdup ("text-x-preview");
		}
	} else {
		/* Strip out any extension on non-filename icons. Old desktop files may have this */
		p = strchr (icon_str, '.');
		/* Only strip known icon extensions */
		if ((p != NULL) &&
		    ((g_ascii_strcasecmp (p, ".png") == 0)
		     || (g_ascii_strcasecmp (p, ".svn") == 0)
		     || (g_ascii_strcasecmp (p, ".jpg") == 0)
		     || (g_ascii_strcasecmp (p, ".xpm") == 0)
		     || (g_ascii_strcasecmp (p, ".bmp") == 0)
		     || (g_ascii_strcasecmp (p, ".jpeg") == 0))) {
			*p = 0;
		}
	}

	icon = g_themed_icon_new_with_default_fallbacks (icon_str);

	/* apply a link emblem if it's a link */
	if (g_strcmp0 (type, "Link") == 0) {
		GIcon *emblemed, *emblem_icon;
		GEmblem *emblem;

		emblem_icon = g_themed_icon_new ("emblem-symbolic-link");
		emblem = g_emblem_new (emblem_icon);

		emblemed = g_emblemed_icon_new (icon, emblem);

		g_object_unref (icon);
		g_object_unref (emblem_icon);
		g_object_unref (emblem);

		icon = emblemed;
	}

 out:
	g_free (icon_str);
	g_free (type);

	return icon;
}
Exemplo n.º 22
0
char*
accounts_get_last_status(const char *const account_name)
{
    return g_key_file_get_string(accounts, account_name, "presence.laststatus", NULL);
}
Exemplo n.º 23
0
/** \brief Read QTH data from file.
 *  \param filename The file to read from.
 *  \param qth Pointer to a qth_t data structure where the data will be stored.
 *  \return FALSE if an error occurred, TRUE otherwise.
 *
 *  \note The function uses the new key=value file parser from glib.
 */
gint
qth_data_read (const gchar *filename, qth_t *qth)
{
    GError *error = NULL;
    gchar  *buff;
    gchar  **buffv;

    qth->data = g_key_file_new ();
    g_key_file_set_list_separator (qth->data, ';');

    /* bail out with error message if data can not be read */
    if (!g_key_file_load_from_file (qth->data, filename,
                                    G_KEY_FILE_KEEP_COMMENTS, &error)) {

        g_key_file_free (qth->data);
        qth->data = NULL;

        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Could not load data from %s (%s)"),
                     __FUNCTION__, filename, error->message);

        return FALSE;
    }

    /* send a debug message, then read data */
    sat_log_log (SAT_LOG_LEVEL_DEBUG,
                 _("%s: QTH data: %s"),
                 __FUNCTION__, filename);

    /*** FIXME: should check that strings are UTF-8? */
    /* QTH Name */
    buff = g_path_get_basename (filename);
    buffv = g_strsplit (buff, ".qth", 0);
    qth->name = g_strdup (buffv[0]);

    g_free (buff);
    g_strfreev (buffv);
    /* g_key_file_get_string (qth->data, */
    /*                        QTH_CFG_MAIN_SECTION, */
    /*                        QTH_CFG_NAME_KEY, */
    /*                        &error); */
    if (error != NULL) {
        sat_log_log (SAT_LOG_LEVEL_ERROR, 
                     _("%s: Error reading QTH name (%s)."),
                     __FUNCTION__, error->message);

        qth->name = g_strdup (_("ERROR"));
        g_clear_error (&error);
    }

    /* QTH location */
    qth->loc = g_key_file_get_string (qth->data,
                                      QTH_CFG_MAIN_SECTION,
                                      QTH_CFG_LOC_KEY,
                                      &error);
    if (error != NULL) {
        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: QTH has no location (%s)."),
                     __FUNCTION__, error->message);

        qth->loc = g_strdup ("");
        g_clear_error (&error);
    }

    /* QTH description */
    qth->desc = g_key_file_get_string (qth->data,
                                       QTH_CFG_MAIN_SECTION,
                                       QTH_CFG_DESC_KEY,
                                       &error);
    if ((qth->desc == NULL) || (error != NULL)) {
        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: QTH has no description."),
                     __FUNCTION__);

        qth->desc = g_strdup ("");
        g_clear_error (&error);
    }

    /* Weather station */
    qth->wx = g_key_file_get_string (qth->data,
                                     QTH_CFG_MAIN_SECTION,
                                     QTH_CFG_WX_KEY,
                                     &error);
    if ((qth->wx == NULL) || (error != NULL)) {
        sat_log_log (SAT_LOG_LEVEL_MSG,
                     _("%s: QTH has no weather station."),
                     __FUNCTION__);

        qth->wx = g_strdup ("");
        g_clear_error (&error);
    }

    /* QTH Latitude */
    buff = g_key_file_get_string (qth->data,
                                  QTH_CFG_MAIN_SECTION,
                                  QTH_CFG_LAT_KEY,
                                  &error);
    if (error != NULL) {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Error reading QTH latitude (%s)."),
                     __FUNCTION__, error->message);

        g_clear_error (&error);

        if (buff != NULL)
            g_free (buff);

        qth->lat = 0.0;
    }
    else {
        qth->lat = g_ascii_strtod (buff, NULL);
        g_free (buff);
    }

    /* QTH Longitude */
    buff = g_key_file_get_string (qth->data,
                                  QTH_CFG_MAIN_SECTION,
                                  QTH_CFG_LON_KEY,
                                  &error);
    if (error != NULL) {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Error reading QTH longitude (%s)."),
                     __FUNCTION__, error->message);

        g_clear_error (&error);

        if (buff != NULL)
            g_free (buff);

        qth->lon = 0.0;
    }
    else {
        qth->lon = g_ascii_strtod (buff, NULL);
        g_free (buff);
    }

    /* QTH Altitude */
    qth->alt = g_key_file_get_integer (qth->data,
                                       QTH_CFG_MAIN_SECTION,
                                       QTH_CFG_ALT_KEY,
                                       &error);
    if (error != NULL) {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s: Error reading QTH altitude (%s)."),
                     __FUNCTION__, error->message);

        g_clear_error (&error);

        if (buff != NULL)
            g_free (buff);

        qth->alt = 0;
    }
    else {
    }

    /* Now, send debug message and return */
    sat_log_log (SAT_LOG_LEVEL_MSG,
                 _("%s: QTH data: %s, %.4f, %.4f, %d"),
                 __FUNCTION__,
                 qth->name,
                 qth->lat,
                 qth->lon,
                 qth->alt);

    return TRUE;
}
Exemplo n.º 24
0
/**
 * as_app_parse_file_key:
 **/
static gboolean
as_app_parse_file_key (AsApp *app,
		       GKeyFile *kf,
		       const gchar *key,
		       AsAppParseFlags flags,
		       GError **error)
{
	gchar *dot = NULL;
	guint i;
	guint j;
	_cleanup_free_ gchar *locale = NULL;
	_cleanup_free_ gchar *tmp = NULL;
	_cleanup_strv_free_ gchar **list = NULL;

	/* NoDisplay */
	if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY) == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && strcasecmp (tmp, "True") == 0)
			as_app_add_veto (app, "NoDisplay=true");

	/* Type */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_TYPE) == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (g_strcmp0 (tmp, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) != 0) {
			g_set_error_literal (error,
					     AS_APP_ERROR,
					     AS_APP_ERROR_INVALID_TYPE,
					     "not an application");
			return FALSE;
		}

	/* Icon */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_ICON) == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0') {
			_cleanup_object_unref_ AsIcon *icon = NULL;
			icon = as_icon_new ();
			as_icon_set_name (icon, tmp);
			dot = g_strstr_len (tmp, -1, ".");
			if (dot != NULL)
				*dot = '\0';
			if (as_utils_is_stock_icon_name (tmp)) {
				as_icon_set_name (icon, tmp);
				as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
			} else if ((flags & AS_APP_PARSE_FLAG_USE_FALLBACKS) > 0 &&
				   _as_utils_is_stock_icon_name_fallback (tmp)) {
				as_icon_set_name (icon, tmp);
				as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
			} else {
				as_icon_set_kind (icon, AS_ICON_KIND_LOCAL);
			}
			as_app_add_icon (app, icon);
		}

	/* Categories */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_CATEGORIES) == 0) {
		list = g_key_file_get_string_list (kf,
						   G_KEY_FILE_DESKTOP_GROUP,
						   key,
						   NULL, NULL);
		for (i = 0; list[i] != NULL; i++) {

			/* check categories that if present would blacklist
			 * the application */
			if (fnmatch ("X-*-Settings-Panel", list[i], 0) == 0 ||
			    fnmatch ("X-*-Settings", list[i], 0) == 0 ||
			    fnmatch ("X-*-SettingsDialog", list[i], 0) == 0) {
				as_app_add_veto (app, "category '%s' blacklisted", list[i]);
				continue;
			}

			/* not a standard category */
			if (g_str_has_prefix (list[i], "X-"))
				continue;

			/* check the category is valid */
			if (!as_utils_is_category_id (list[i]))
				continue;

			/* ignore some useless keys */
			if (g_strcmp0 (list[i], "GTK") == 0)
				continue;
			if (g_strcmp0 (list[i], "Qt") == 0)
				continue;
			if (g_strcmp0 (list[i], "KDE") == 0)
				continue;
			if (g_strcmp0 (list[i], "GNOME") == 0)
				continue;
			as_app_add_category (app, list[i]);
		}

	} else if (g_strcmp0 (key, "Keywords") == 0) {
		list = g_key_file_get_string_list (kf,
						   G_KEY_FILE_DESKTOP_GROUP,
						   key,
						   NULL, NULL);
		for (i = 0; list[i] != NULL; i++) {
			_cleanup_strv_free_ gchar **kw_split = NULL;
			kw_split = g_strsplit (list[i], ",", -1);
			for (j = 0; kw_split[j] != NULL; j++) {
				if (kw_split[j][0] == '\0')
					continue;
				as_app_add_keyword (app, "C", kw_split[j]);
			}
		}

	} else if (g_str_has_prefix (key, "Keywords")) {
		locale = as_app_desktop_key_get_locale (key);
		list = g_key_file_get_locale_string_list (kf,
							  G_KEY_FILE_DESKTOP_GROUP,
							  key,
							  locale,
							  NULL, NULL);
		for (i = 0; list[i] != NULL; i++) {
			_cleanup_strv_free_ gchar **kw_split = NULL;
			kw_split = g_strsplit (list[i], ",", -1);
			for (j = 0; kw_split[j] != NULL; j++) {
				if (kw_split[j][0] == '\0')
					continue;
				as_app_add_keyword (app, locale, kw_split[j]);
			}
		}

	} else if (g_strcmp0 (key, "MimeType") == 0) {
		list = g_key_file_get_string_list (kf,
						   G_KEY_FILE_DESKTOP_GROUP,
						   key,
						   NULL, NULL);
		for (i = 0; list[i] != NULL; i++)
			as_app_add_mimetype (app, list[i]);

	} else if (g_strcmp0 (key, "X-AppInstall-Package") == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_add_pkgname (app, tmp);

	/* OnlyShowIn */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN) == 0) {
		/* if an app has only one entry, it's that desktop */
		list = g_key_file_get_string_list (kf,
						   G_KEY_FILE_DESKTOP_GROUP,
						   key,
						   NULL, NULL);
		if (g_strv_length (list) == 1)
			as_app_set_project_group (app, list[0]);

	/* Name */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_NAME) == 0 ||
	           g_strcmp0 (key, "_Name") == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_name (app, "C", tmp);

	/* Name[] */
	} else if (g_str_has_prefix (key, G_KEY_FILE_DESKTOP_KEY_NAME)) {
		locale = as_app_desktop_key_get_locale (key);
		tmp = g_key_file_get_locale_string (kf,
						    G_KEY_FILE_DESKTOP_GROUP,
						    G_KEY_FILE_DESKTOP_KEY_NAME,
						    locale,
						    NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_name (app, locale, tmp);

	/* Comment */
	} else if (g_strcmp0 (key, G_KEY_FILE_DESKTOP_KEY_COMMENT) == 0 ||
	           g_strcmp0 (key, "_Comment") == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_comment (app, "C", tmp);

	/* Comment[] */
	} else if (g_str_has_prefix (key, G_KEY_FILE_DESKTOP_KEY_COMMENT)) {
		locale = as_app_desktop_key_get_locale (key);
		tmp = g_key_file_get_locale_string (kf,
						    G_KEY_FILE_DESKTOP_GROUP,
						    G_KEY_FILE_DESKTOP_KEY_COMMENT,
						    locale,
						    NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_comment (app, locale, tmp);

	/* non-standard */
	} else if (g_strcmp0 (key, "X-Ubuntu-Software-Center-Name") == 0) {
		tmp = g_key_file_get_string (kf,
					     G_KEY_FILE_DESKTOP_GROUP,
					     key,
					     NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_name (app, "C", tmp);
	} else if (g_str_has_prefix (key, "X-Ubuntu-Software-Center-Name")) {
		locale = as_app_desktop_key_get_locale (key);
		tmp = g_key_file_get_locale_string (kf,
						    G_KEY_FILE_DESKTOP_GROUP,
						    "X-Ubuntu-Software-Center-Name",
						    locale,
						    NULL);
		if (tmp != NULL && tmp[0] != '\0')
			as_app_set_name (app, locale, tmp);
	}

	return TRUE;
}
static gboolean
ide_language_defaults_migrate (GKeyFile  *key_file,
                               gint       current_version,
                               gint       new_version,
                               GError   **error)
{
  gchar **groups;
  gsize i;

  g_assert (key_file);
  g_assert (current_version >= 0);
  g_assert (current_version >= 0);
  g_assert (new_version > current_version);

  groups = g_key_file_get_groups (key_file, NULL);

  for (i = 0; groups [i]; i++)
    {
      const gchar *group = groups [i];
      g_autoptr(GSettings) settings = NULL;
      g_autofree gchar *lang_path = NULL;
      gchar **keys;
      gsize j;

      g_assert (group != NULL);

      if (g_str_equal (group, "global"))
        continue;

      lang_path = g_strdup_printf (PATH_BASE"%s/", group);
      g_assert(lang_path);

      settings = g_settings_new_with_path (SCHEMA_ID, lang_path);
      g_assert (G_IS_SETTINGS (settings));

      keys = g_key_file_get_keys (key_file, group, NULL, NULL);
      g_assert (keys);

      for (j = 0; keys [j]; j++)
        {
          const gchar *key = keys [j];
          g_autoptr(GVariant) default_value = NULL;

          g_assert (key);

          default_value = g_settings_get_default_value (settings, key);
          g_assert (default_value);

          /*
           * For all of the variant types we support, check to see if the value
           * is matching the default schema value. If so, update the key to the
           * new override value.
           *
           * This will not overwrite any change settings for files that the
           * user has previously loaded, but will for others. Overriding things
           * we have overriden gets pretty nasty, since we change things out
           * from under the user.
           *
           * That may change in the future, but not today.
           */

          if (g_variant_is_of_type (default_value, G_VARIANT_TYPE_STRING))
            {
              g_autofree gchar *current_str = NULL;
              g_autofree gchar *override_str = NULL;
              const gchar *default_str;

              default_str = g_variant_get_string (default_value, NULL);
              current_str = g_settings_get_string (settings, key);
              override_str = g_key_file_get_string (key_file, group, key, NULL);

              if (0 == g_strcmp0 (default_str, current_str))
                g_settings_set_string (settings, key, override_str);
            }
          else if (g_variant_is_of_type (default_value, G_VARIANT_TYPE_BOOLEAN))
            {
              gboolean current_bool;
              gboolean override_bool;
              gboolean default_bool;

              default_bool = g_variant_get_boolean (default_value);
              current_bool = g_settings_get_boolean (settings, key);
              override_bool = g_key_file_get_boolean (key_file, group, key, NULL);

              if (default_bool != current_bool)
                g_settings_set_boolean (settings, key, override_bool);
            }
          else if (g_variant_is_of_type (default_value, G_VARIANT_TYPE_INT32))
            {
              gint32 current_int32;
              gint32 override_int32;
              gint32 default_int32;

              default_int32 = g_variant_get_int32 (default_value);
              current_int32 = g_settings_get_int (settings, key);
              override_int32 = g_key_file_get_integer (key_file, group, key, NULL);

              if (default_int32 != current_int32)
                g_settings_set_int (settings, key, override_int32);
            }
          else
            {
              g_error ("Teach me about variant type: %s",
                       g_variant_get_type_string (default_value));
              g_assert_not_reached ();
            }
        }
    }

  return TRUE;
}
Exemplo n.º 26
0
gboolean
ot_admin_builtin_status (int argc, char **argv, GCancellable *cancellable, GError **error)
{
  GOptionContext *context;
  glnx_unref_object OstreeSysroot *sysroot = NULL;
  gboolean ret = FALSE;
  glnx_unref_object OstreeRepo *repo = NULL;
  OstreeDeployment *booted_deployment = NULL;
  g_autoptr(GPtrArray) deployments = NULL;
  guint i;

  context = g_option_context_new ("List deployments");

  if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
                                          OSTREE_ADMIN_BUILTIN_FLAG_NONE,
                                          &sysroot, cancellable, error))
    goto out;

  if (!ostree_sysroot_load (sysroot, cancellable, error))
    goto out;

  if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
    goto out;

  deployments = ostree_sysroot_get_deployments (sysroot);
  booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);

  if (deployments->len == 0)
    {
      g_print ("No deployments.\n");
    }
  else
    {
      for (i = 0; i < deployments->len; i++)
        {
          OstreeDeployment *deployment = deployments->pdata[i];
          GKeyFile *origin;
          const char *ref = ostree_deployment_get_csum (deployment);
          g_autofree char *version = version_of_commit (repo, ref);
          glnx_unref_object OstreeGpgVerifyResult *result = NULL;
          GString *output_buffer;
          guint jj, n_signatures;
          GError *local_error = NULL;

          g_print ("%c %s %s.%d\n",
                   deployment == booted_deployment ? '*' : ' ',
                   ostree_deployment_get_osname (deployment),
                   ostree_deployment_get_csum (deployment),
                   ostree_deployment_get_deployserial (deployment));
          if (version)
            g_print ("    Version: %s\n", version);
          origin = ostree_deployment_get_origin (deployment);
          if (!origin)
            g_print ("    origin: none\n");
          else
            {
              g_autofree char *origin_refspec = g_key_file_get_string (origin, "origin", "refspec", NULL);
              if (!origin_refspec)
                g_print ("    origin: <unknown origin type>\n");
              else
                g_print ("    origin refspec: %s\n", origin_refspec);
            }

          if (deployment_get_gpg_verify (deployment, repo))
            {
              /* Print any digital signatures on this commit. */

              result = ostree_repo_verify_commit_ext (repo, ref, NULL, NULL,
                                                      cancellable, &local_error);

              /* G_IO_ERROR_NOT_FOUND just means the commit is not signed. */
              if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
                {
                  g_clear_error (&local_error);
                  continue;
                }
              else if (local_error != NULL)
                {
                  g_propagate_error (error, local_error);
                  goto out;
                }

              output_buffer = g_string_sized_new (256);
              n_signatures = ostree_gpg_verify_result_count_all (result);

              for (jj = 0; jj < n_signatures; jj++)
                {
                  ostree_gpg_verify_result_describe (result, jj, output_buffer, "    GPG: ",
                                                     OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT);
                }

              g_print ("%s", output_buffer->str);
              g_string_free (output_buffer, TRUE);
            }
        }
    }

  ret = TRUE;
 out:
  if (context)
    g_option_context_free (context);
  return ret;
}
Exemplo n.º 27
0
gboolean
ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
{
  GOptionContext *context;
  gboolean ret = FALSE;
  const char *op;
  gs_free char *key = NULL;
  guint i;
  GKeyFile *config = NULL;
  const char *remote_name;

  context = g_option_context_new ("OPERATION NAME [args] - Control remote repository configuration");
  g_option_context_add_main_entries (context, options, NULL);

  if (!g_option_context_parse (context, &argc, &argv, error))
    goto out;

  if (argc < 3)
    {
      if (argc == 1)
        usage_error (context, "OPERATION must be specified", error);
      else
        usage_error (context, "NAME must be specified", error);

      goto out;
    }

  op = argv[1];
  remote_name = argv[2];
  key = g_strdup_printf ("remote \"%s\"", remote_name);

  config = ostree_repo_copy_config (repo);

  if (!strcmp (op, "add"))
    {
      const char *url = argv[3];
      gs_unref_object GFile *etc_ostree_remotes_d = g_file_new_for_path (SYSCONFDIR "/ostree/remotes.d");
      gs_free char *target_name = NULL;
      gs_unref_object GFile *target_conf = NULL;
      local_cleanup_keyfile GKeyFile *new_keyfile = NULL;
      GKeyFile *target_keyfile = NULL;
      gs_unref_ptrarray GPtrArray *branches = NULL;

      if (strchr (remote_name, '/') != NULL)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Invalid character '/' in remote name: %s",
                       remote_name);
          goto out;
        }
      
      if (argc < 4)
        {
          usage_error (context, "URL must be specified", error);
          goto out;
        }

      branches = g_ptr_array_new ();
      for (i = 4; i < argc; i++)
        g_ptr_array_add (branches, argv[i]);

      if (ostree_repo_is_system (repo))
        {
          new_keyfile = g_key_file_new ();

          target_keyfile = new_keyfile;

          target_name = g_strconcat (remote_name, ".conf", NULL);
          target_conf = g_file_get_child (etc_ostree_remotes_d, target_name);
          
          if (g_file_query_exists (target_conf, NULL))
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Remote configuration already exists: %s",
                           gs_file_get_path_cached (target_conf));
              goto out;
            }
        }
      else
        {
          target_keyfile = config;
        }

      if (!add_remote_to_keyfile (target_keyfile, key, url, branches, error))
        goto out;

      /* For the system repository, write to /etc/ostree/remotes.d */
      if (ostree_repo_is_system (repo))
        {
          gsize len;
          gs_free char *data = g_key_file_to_data (target_keyfile, &len, error);
          if (!g_file_replace_contents (target_conf, data, len,
                                        NULL, FALSE, 0, NULL,
                                        cancellable, error))
            goto out;
        }
      else
        {
          if (!ostree_repo_write_config (repo, config, error))
            goto out;
        }
    }
  else if (!strcmp (op, "show-url"))
    {
      gs_free char *url = NULL;

      url = g_key_file_get_string (config, key, "url", error);
      if (url == NULL)
        goto out;

      g_print ("%s\n", url);
    }
  else
    {
      usage_error (context, "Unknown operation", error);
      goto out;
    }
 
  ret = TRUE;
 out:
  if (context)
    g_option_context_free (context);
  if (config)
    g_key_file_free (config);
  return ret;
}
Exemplo n.º 28
0
static gboolean
handle_file (const gchar *filename)
{
  GKeyFile *keyfile;
  GConfClient *client;
  GConfValue *value;
  gint i, j;
  gchar *gconf_key;
  gchar **groups;
  gchar **keys;
  GVariantBuilder *builder;
  GVariant *v;
  const gchar *s;
  gchar *str;
  gint ii;
  GSList *list, *l;
  GSettingsSchemaSource *source;
  GSettingsSchema *schema;
  GSettings *settings;
  GError *error;

  keyfile = g_key_file_new ();

  error = NULL;
  if (!g_key_file_load_from_file (keyfile, filename, 0, &error))
    {
      if (verbose)
        g_printerr ("%s: %s\n", filename, error->message);
      g_error_free (error);

      g_key_file_free (keyfile);

      return FALSE;
    }

  client = get_writable_client ();
  source = g_settings_schema_source_get_default ();

  groups = g_key_file_get_groups (keyfile, NULL);
  for (i = 0; groups[i]; i++)
    {
      gchar **schema_path;

      schema_path = g_strsplit (groups[i], ":", 2);

      schema = g_settings_schema_source_lookup (source, schema_path[0], TRUE);
      if (schema == NULL)
        {
          if (verbose)
            {
              g_print ("Schema '%s' not found, skipping\n", schema_path[0]);
            }

          g_strfreev (schema_path);
          continue;
        }

      g_settings_schema_unref (schema);

      if (verbose)
        {
          g_print ("Collecting settings for schema '%s'\n", schema_path[0]);
          if (schema_path[1])
            g_print ("for storage at '%s'\n", schema_path[1]);
        }

      if (schema_path[1] != NULL)
        settings = g_settings_new_with_path (schema_path[0], schema_path[1]);
      else
        settings = g_settings_new (schema_path[0]);

      g_settings_delay (settings);

      error = NULL;
      if ((keys = g_key_file_get_keys (keyfile, groups[i], NULL, &error)) == NULL)
        {
          g_printerr ("%s", error->message);
          g_error_free (error);

          continue;
        }

      for (j = 0; keys[j]; j++)
        {
          if (strchr (keys[j], '/') != 0)
            {
              g_printerr ("Key '%s' contains a '/'\n", keys[j]);

              continue;
            }

          error = NULL;
          if ((gconf_key = g_key_file_get_string (keyfile, groups[i], keys[j], &error)) ==  NULL)
            {
              g_printerr ("%s", error->message);
              g_error_free (error);

              continue;
            }

          error = NULL;
          if ((value = gconf_client_get_without_default (client, gconf_key, &error)) == NULL)
            {
              if (error)
                {
                  g_printerr ("Failed to get GConf key '%s': %s\n",
                              gconf_key, error->message);
                  g_error_free (error);
                }
              else
                {
                  if (verbose)
                    g_print ("Skipping GConf key '%s', no user value\n",
                             gconf_key);
                }

              g_free (gconf_key);

              continue;
            }

          switch (value->type)
            {
            case GCONF_VALUE_STRING:
              if (dry_run)
                g_print ("Set key '%s' to string '%s'\n", keys[j],
                         gconf_value_get_string (value));
              else
                g_settings_set (settings, keys[j], "s",
                                gconf_value_get_string (value));
              break;

            case GCONF_VALUE_INT:
              if (dry_run)
                g_print ("Set key '%s' to integer '%d'\n",
                         keys[j], gconf_value_get_int (value));
              else
                {
                  GVariant *range;
                  gchar *type;

                  range = g_settings_get_range (settings, keys[j]);
                  g_variant_get (range, "(&sv)", &type, NULL);

                  if (strcmp (type, "enum") == 0)
                    g_settings_set_enum (settings, keys[j], gconf_value_get_int (value));
                  else if (strcmp (type, "flags") == 0)
                    g_settings_set_flags (settings, keys[j], gconf_value_get_int (value));
                  else if (type_uint32 (settings, keys[j]))
                    g_settings_set (settings, keys[j], "u",
                                    gconf_value_get_int (value));
                  else
                    g_settings_set (settings, keys[j], "i",
                                    gconf_value_get_int (value));

                  g_variant_unref (range);
                }
              break;

            case GCONF_VALUE_BOOL:
              if (dry_run)
                g_print ("Set key '%s' to boolean '%d'\n",
                         keys[j], gconf_value_get_bool (value));
              else
                g_settings_set (settings, keys[j], "b",
                                gconf_value_get_bool (value));
              break;

            case GCONF_VALUE_FLOAT:
              if (dry_run)
                g_print ("Set key '%s' to double '%g'\n",
                         keys[j], gconf_value_get_float (value));
              else
                g_settings_set (settings, keys[j], "d",
                                gconf_value_get_float (value));
              break;

            case GCONF_VALUE_LIST:
              switch (gconf_value_get_list_type (value))
                {
                case GCONF_VALUE_STRING:
                  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
                  list = gconf_value_get_list (value);
                  if (list != NULL)
                    {
                      for (l = list; l; l = l->next)
                        {
                          GConfValue *lv = l->data;
                          s = gconf_value_get_string (lv);
                          g_variant_builder_add (builder, "s", s);
                        }
                      v = g_variant_new ("as", builder);
                    }
                  else
                    v = g_variant_new_array (G_VARIANT_TYPE_STRING, NULL, 0);
                  g_variant_ref_sink (v);

                  if (dry_run)
                    {
                      str = g_variant_print (v, FALSE);
                      g_print ("Set key '%s' to a list of strings: %s\n",
                               keys[j], str);
                      g_free (str);
                    }
                  else
                    g_settings_set_value (settings, keys[j], v);

                  g_variant_unref (v);
                  g_variant_builder_unref (builder);
                  break;

                case GCONF_VALUE_INT:
                  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
                  list = gconf_value_get_list (value);
                  if (list != NULL)
                    {
                      for (l = list; l; l = l->next)
                        {
                          GConfValue *lv = l->data;
                          ii = gconf_value_get_int (lv);
                          g_variant_builder_add (builder, "i", ii);
                        }
                      v = g_variant_new ("ai", builder);
                    }
                  else
                    v = g_variant_new_array (G_VARIANT_TYPE_INT32, NULL, 0);
                  g_variant_ref_sink (v);

                  if (dry_run)
                    {
                      str = g_variant_print (v, FALSE);
                      g_print ("Set key '%s' to a list of integers: %s\n",
                               keys[j], str);
                      g_free (str);
                    }
                  else
                    g_settings_set_value (settings, keys[j], v);

                  g_variant_unref (v);
                  g_variant_builder_unref (builder);
                  break;

                default:
                  g_printerr ("Keys of type 'list of %s' not handled yet\n",
                              gconf_value_type_to_string (gconf_value_get_list_type (value)));
                  break;
                }
              break;

            default:
              g_printerr ("Keys of type %s not handled yet\n",
                          gconf_value_type_to_string (value->type));
              break;
            }

          gconf_value_free (value);
          g_free (gconf_key);
        }

      g_strfreev (keys);

      if (!dry_run)
        g_settings_apply (settings);

      g_object_unref (settings);
      g_strfreev (schema_path);
    }

  g_strfreev (groups);

  g_object_unref (client);

  return TRUE;
}
Exemplo n.º 29
0
BlockBackend*
load_swift_block_backend(GKeyFile *config)
{
    BlockBackend *bend;
    char auth_url[2048];
    auth_url[0]='\0';
    char *scheme;
    char *host;
    char *port;
    char *api_version;
    char *auth_url_ext;
    char *containername;

    scheme = g_key_file_get_string (config, "block_backend",  "scheme", NULL);
    if (!scheme) {
        g_warning("Swift scheme not set in config.\n");
        return NULL;
    }
    else
    {
        
        strcat(auth_url,scheme);
        strcat(auth_url,"://");
    }

    host = g_key_file_get_string (config, "block_backend",  "host", NULL);
    if (!host) {
        g_warning("Swift Host not set in config.\n");
        return NULL;
    }
    else
    {
        strcat(auth_url,host);        
    }
    
    
    port = g_key_file_get_string (config, "block_backend",  "port", NULL);
    if (!port) {
        g_warning("Swift port not set in config.\n");
        return NULL;
    }
    else
    {
        strcat(auth_url,":");
        strcat(auth_url,port);
        strcat(auth_url,"/");
    }

    api_version = g_key_file_get_string (config, "block_backend",  "api_version", NULL);
    if (!api_version) {
        g_warning("Swift api_version  not set in config.\n");
        return NULL;
    }
    else
    {
        strcat(auth_url,api_version);        
    }

    auth_url_ext = g_key_file_get_string (config, "block_backend",  "auth_url_ext", NULL);
    if (!auth_url_ext) {
        g_warning("Swift auth_url_ext not set in config. Ignore...\n");       
    }
    else
    {
        strcat(auth_url,"/");
        strcat(auth_url,auth_url_ext);
    }   

    if (!auth_url) {
        g_warning("Swift Auth Url  not set in config.\n");
        return NULL;
    }

    containername = g_key_file_get_string (config, "block_backend", "container", NULL);
    if (!containername) {        
        g_warning("Swift container not set in config.\n");
        return NULL;
    } 

    bend = block_backend_swift_new (auth_url, containername);

    g_free (scheme);
    g_free (host);
    g_free (port);
    g_free (api_version);
    g_free (auth_url_ext);
    g_free (containername);

    return bend;
}
Exemplo n.º 30
0
static void
trash_item_get_trashinfo (GFile  *path,
                          GFile **original,
                          char  **date)
{
  GFile *files, *trashdir;
  GKeyFile *keyfile;
  char *trashpath;
  char *trashinfo;
  char *basename;

  files = g_file_get_parent (path);
  trashdir = g_file_get_parent (files);
  trashpath = g_file_get_path (trashdir);
  g_object_unref (files);

  basename = g_file_get_basename (path);

  trashinfo = g_strdup_printf ("%s/info/%s.trashinfo", trashpath, basename);
  g_free (trashpath);
  g_free (basename);

  keyfile = g_key_file_new ();

  *original = NULL;
  *date = NULL;

  if (g_key_file_load_from_file (keyfile, trashinfo, 0, NULL))
    {
      char *orig, *decoded;

      decoded = NULL;
      orig = g_key_file_get_string (keyfile,
                                    "Trash Info", "Path",
                                    NULL);

      if (orig == NULL)
        *original = NULL;
      else
	{
	  decoded = g_uri_unescape_string (orig, NULL);

	  if (g_path_is_absolute (decoded))
	    *original = g_file_new_for_path (decoded);
	  else
	    {
	      GFile *rootdir;
	      
	      rootdir = g_file_get_parent (trashdir);
	      *original = g_file_get_child (rootdir, decoded);
	      g_object_unref (rootdir);
	    }
	  g_free (decoded);
	}

      g_free (orig);

      *date = g_key_file_get_string (keyfile,
                                     "Trash Info", "DeletionDate",
                                     NULL);
    }

  g_object_unref (trashdir);
  g_key_file_free (keyfile);
  g_free (trashinfo);
}