Esempio n. 1
0
/** Restore all persistent program state.  This function finds the
 *  "new" state file associated with the current session.  It then
 *  iterates through this state information, calling a helper function
 *  to recreate each open window.
 *
 *  @note The name of the state file is based on the name of the data
 *  file, not the path name of the data file.  If there are multiple
 *  data files with the same name, the state files will be suffixed
 *  with a number.  E.G. test_account, test_account_2, test_account_3,
 *  etc.
 *
 *  @param session A pointer to the current session.
 *
 *  @param unused An unused pointer. */
static void
gnc_restore_all_state (gpointer session, gpointer unused)
{
    GKeyFile *keyfile = NULL;
    gchar *file_guid = NULL;
    GError *error = NULL;

    keyfile = gnc_state_load (session);

#ifdef DEBUG
    /*  Debugging: dump a copy to the trace log */
    {
        gchar *file_data;
        gsize file_length;
        file_data = g_key_file_to_data(keyfile, &file_length, NULL);
        DEBUG("=== File Data Read===\n%s\n=== File End ===\n", file_data);
        g_free(file_data);
    }
#endif

    /* If no state file was found, keyfile will be empty
     * In that case, let's load the default state */
    if (!g_key_file_has_group (keyfile, STATE_FILE_TOP))
    {
        gnc_main_window_restore_default_state(NULL);
        LEAVE("no state file");
        goto cleanup;
    }

    /* report any other keyfile read error as a warning
     * but still load default state */
    file_guid = g_key_file_get_string(keyfile, STATE_FILE_TOP,
                                      STATE_FILE_BOOK_GUID, &error);
    if (error)
    {
        gnc_main_window_restore_default_state(NULL);
        g_warning("error reading group %s key %s: %s",
                  STATE_FILE_TOP, STATE_FILE_BOOK_GUID, error->message);
        LEAVE("no guid in state file");
        goto cleanup;
    }

    gnc_main_window_restore_all_windows(keyfile);

    /* Clean up */
    LEAVE("ok");
cleanup:
    if (error)
        g_error_free(error);
    if (file_guid)
        g_free(file_guid);

    gnc_totd_dialog_reparent ();
}
Esempio n. 2
0
void
accounts_add(const char *account_name, const char *altdomain, const int port)
{
    // set account name and resource
    const char *barejid = account_name;
    const char *resource = "profanity";
    Jid *jid = jid_create(account_name);
    if (jid) {
        barejid = jid->barejid;
        if (jid->resourcepart) {
            resource = jid->resourcepart;
        }
    }

    // doesn't yet exist
    if (!g_key_file_has_group(accounts, account_name)) {
        g_key_file_set_boolean(accounts, account_name, "enabled", TRUE);
        g_key_file_set_string(accounts, account_name, "jid", barejid);
        g_key_file_set_string(accounts, account_name, "resource", resource);
        if (altdomain) {
            g_key_file_set_string(accounts, account_name, "server", altdomain);
        }
        if (port != 0) {
            g_key_file_set_integer(accounts, account_name, "port", port);
        }

        Jid *jidp = jid_create(barejid);
        GString *muc_service = g_string_new("conference.");
        g_string_append(muc_service, jidp->domainpart);
        g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str);
        g_string_free(muc_service, TRUE);
        if (jidp->localpart == NULL) {
            g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
        } else {
            g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
        }
        jid_destroy(jidp);

        g_key_file_set_string(accounts, account_name, "presence.last", "online");
        g_key_file_set_string(accounts, account_name, "presence.login", "online");
        g_key_file_set_integer(accounts, account_name, "priority.online", 0);
        g_key_file_set_integer(accounts, account_name, "priority.chat", 0);
        g_key_file_set_integer(accounts, account_name, "priority.away", 0);
        g_key_file_set_integer(accounts, account_name, "priority.xa", 0);
        g_key_file_set_integer(accounts, account_name, "priority.dnd", 0);

        _save_accounts();
        autocomplete_add(all_ac, account_name);
        autocomplete_add(enabled_ac, account_name);
    }

    jid_destroy(jid);
}
Esempio n. 3
0
static void
_eventd_nd_xcb_global_parse(EventdNdBackendContext *self, GKeyFile *config_file)
{
    if ( ! g_key_file_has_group(config_file, "NotificationXcb") )
        return;

    guint64 enum_value;

    if ( evhelpers_config_key_file_get_enum_with_default(config_file, "NotificationXcb", "FollowFocus", _eventd_nd_xcb_follow_focus, G_N_ELEMENTS(_eventd_nd_xcb_follow_focus), EVENTD_ND_XCB_FOLLOW_FOCUS_NONE, &enum_value) == 0 )
        self->follow_focus = enum_value;
    evhelpers_config_key_file_get_string_list(config_file, "NotificationXcb", "Outputs", &self->outputs, NULL);
}
Esempio n. 4
0
gboolean
accounts_disable(const char *const name)
{
    if (g_key_file_has_group(accounts, name)) {
        g_key_file_set_boolean(accounts, name, "enabled", FALSE);
        _save_accounts();
        autocomplete_remove(enabled_ac, name);
        return TRUE;
    } else {
        return FALSE;
    }
}
Esempio n. 5
0
static GtkPageSetup *
load_page_setup (GKeyFile *key_file)
{
	GtkPageSetup *page_setup;

	page_setup = gtk_page_setup_new ();

	if (g_key_file_has_group (key_file, PAGE_SETUP_GROUP_NAME))
		gtk_page_setup_load_key_file (
			page_setup, key_file, PAGE_SETUP_GROUP_NAME, NULL);

	return page_setup;
}
Esempio n. 6
0
static void
_eventd_config_parse_global(EventdConfig *config, GKeyFile *config_file)
{
    if ( g_tls_backend_supports_tls(g_tls_backend_get_default()) && g_key_file_has_group(config_file, "Server") )
    {
        gchar *priorities;
        if ( ( config->gnutls_priorities_env == NULL ) && ( evhelpers_config_key_file_get_string(config_file, "Server", "GnuTLSPriority", &priorities) == 0 ) )
        {
            g_free(config->gnutls_priorities);
            config->gnutls_priorities = priorities;
        }

    }
}
static void
search_panel_add_one_provider (CcSearchPanel *self,
                               GFile *provider)
{
  gchar *path, *desktop_id;
  GKeyFile *keyfile;
  GAppInfo *app_info;
  GError *error = NULL;
  gboolean default_disabled;

  path = g_file_get_path (provider);
  keyfile = g_key_file_new ();
  g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error);

  if (error != NULL)
    {
      g_warning ("Error loading %s: %s - search provider will be ignored",
                 path, error->message);
      goto out;
    }

  if (!g_key_file_has_group (keyfile, SHELL_PROVIDER_GROUP))
    goto out;

  desktop_id = g_key_file_get_string (keyfile, SHELL_PROVIDER_GROUP,
                                      "DesktopId", &error);

  if (error != NULL)
    {
      g_warning ("Unable to read desktop ID from %s: %s - search provider will be ignored",
                 path, error->message);
      goto out;
    }

  app_info = G_APP_INFO (g_desktop_app_info_new (desktop_id));
  g_free (desktop_id);

  if (app_info == NULL)
    goto out;

  default_disabled = g_key_file_get_boolean (keyfile, SHELL_PROVIDER_GROUP,
                                             "DefaultDisabled", NULL);
  search_panel_add_one_app_info (self, app_info, !default_disabled);
  g_object_unref (app_info);

 out:
  g_free (path);
  g_clear_error (&error);
  g_key_file_unref (keyfile);
}
Esempio n. 8
0
File: config.c Progetto: worr/eventd
static void
_eventd_config_parse_global(EventdConfig *config, GKeyFile *config_file)
{
    Int integer;

    if ( ! g_key_file_has_group(config_file, "Event") )
        return;

    if ( libeventd_config_key_file_get_int(config_file, "Event", "Stack", &integer) == 0 )
        config->stack = integer.value;

    if ( libeventd_config_key_file_get_int(config_file, "Event", "Timeout", &integer) == 0 )
        config->timeout = integer.value;
}
Esempio n. 9
0
static struct scrobbler_config *
load_scrobbler(GKeyFile *fd, const char *grp)
{
	char *p;
	struct scrobbler_config *scrobbler = g_new(struct scrobbler_config, 1);
	GError *cerr = NULL;

	if (!g_key_file_has_group(fd, grp))
		return NULL;

	scrobbler->name = g_strdup(grp);
	scrobbler->url = g_key_file_get_string(fd, grp, "url", &cerr);
	if (cerr != NULL) {
		mpdcron_log(LOG_ERR, "Error while reading url from group %s: %s",
				grp, cerr->message);
		g_free(scrobbler);
		g_error_free(cerr);
		return NULL;
	}
	scrobbler->username = g_key_file_get_string(fd, grp, "username", &cerr);
	if (cerr != NULL) {
		mpdcron_log(LOG_ERR, "Error while reading username from group %s: %s",
				grp, cerr->message);
		g_free(scrobbler);
		g_error_free(cerr);
		return NULL;
	}
	scrobbler->password = g_key_file_get_string(fd, grp, "password", &cerr);
	if (cerr != NULL) {
		mpdcron_log(LOG_ERR, "Error while reading password from group %s: %s",
				grp, cerr->message);
		g_free(scrobbler);
		g_error_free(cerr);
		return NULL;
	}
	/* Parse password */
	if (strncmp(scrobbler->password, "md5:", 4) == 0) {
		p = g_strdup(scrobbler->password + 4);
		g_free(scrobbler->password);
		scrobbler->password = p;
	}
	else {
		p = g_compute_checksum_for_string(G_CHECKSUM_MD5, scrobbler->password, -1);
		g_free(scrobbler->password);
		scrobbler->password = p;
	}

	scrobbler->journal = g_key_file_get_string(fd, grp, "journal", NULL);
	return scrobbler;
}
Esempio n. 10
0
/* check_uuid 0 or NULL don't check presence of uuid */
int check_configuration ( GKeyFile *config , int check_uuid ) {

    if ( ! g_key_file_has_group( config , AMEBA_UPDATER_MAIN_SECTION ) )
        return 0;

    if ( ! g_key_file_has_key( config , AMEBA_UPDATER_MAIN_SECTION , "url" , NULL ) )
        return 0;

    if ( check_uuid )
        if ( ! g_key_file_has_key( config , AMEBA_UPDATER_MAIN_SECTION , "uuid" , NULL ) )
            return 0;

    return 1;
}
Esempio n. 11
0
static void
load_session_file (const char              *id,
                   const char              *path)
{
        GKeyFile          *key_file;
        GError            *error;
        gboolean           res;
        GdmSessionFile    *session;

        key_file = g_key_file_new ();

        error = NULL;
        res = g_key_file_load_from_file (key_file, path, 0, &error);

        if (!res) {
                g_debug ("Failed to load \"%s\": %s\n", path, error->message);
                g_error_free (error);
                goto out;
        }

        if (! g_key_file_has_group (key_file, G_KEY_FILE_DESKTOP_GROUP)) {
                goto out;
        }

        res = g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, "Name", NULL);
        if (! res) {
                g_debug ("\"%s\" contains no \"Name\" key\n", path);
                goto out;
        }

        if (!key_file_is_relevant (key_file)) {
                g_debug ("\"%s\" is hidden or contains non-executable TryExec program\n", path);
                goto out;
        }

        session = g_new0 (GdmSessionFile, 1);

        session->id = g_strdup (id);
        session->path = g_strdup (path);

        session->translated_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Name", NULL, NULL);
        session->translated_comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Comment", NULL, NULL);

        g_hash_table_insert (gdm_available_sessions_map,
                             g_strdup (id),
                             session);
 out:
        g_key_file_free (key_file);
}
Esempio n. 12
0
File: erln8.c Progetto: mkb/erln8
// which version of erlang is configured for this particular
// branch of the dir tree
gchar* which_erlang() {
  gchar* cfgfile = configcheckfromcwd();
  if(cfgfile == NULL) {
    // check for a system root. 
    // if one doesn't exist, return the system_default
    gchar *sysroot = systemrootcheck_from_cwd();
    if(sysroot != NULL) {
      return sysroot;
    } else {
      return get_system_default();
    }
  } else {
    if(g_file_test(cfgfile, G_FILE_TEST_EXISTS |
          G_FILE_TEST_IS_REGULAR)) {
      GKeyFile* kf = g_key_file_new();
      GError* err = NULL;
      if(!g_key_file_load_from_file(kf, cfgfile, G_KEY_FILE_NONE, &err)) {
        if(err != NULL) {
          g_error("Cannot load %s: %s\n", cfgfile, err->message);
        } else {
          g_error("Cannot load %s\n", cfgfile);
        }
      } else {
        if(!g_key_file_has_group(kf, "Config")) {
          g_error("Config group not defined in %s\n", cfgfile);
          return NULL;
        } else {
          err = NULL;
          if(g_key_file_has_key(kf, "Config", "Erlang", &err)) {
            gchar* erlversion = g_key_file_get_string(kf, "Config", "Erlang", &err);
            g_free(cfgfile);
            // THIS VALUE MUST BE FREED
            return erlversion;
          } else {
            if(err != NULL) {
              g_error("Missing Erlang | version: %s\n", err->message);
            } else {
              g_error("Missing Erlang | version\n");
            }
            return NULL;
          }
        }
      }
    } else {
      return NULL;
    }
  }
  return NULL;
}
Esempio n. 13
0
void config_clear_section (const char * section)
{
    g_return_if_fail (defaults && keyfile);
    pthread_mutex_lock (& mutex);

    if (! section)
        section = DEFAULT_SECTION;

    if (g_key_file_has_group (keyfile, section))
    {
        g_key_file_remove_group (keyfile, section, NULL);
        modified = TRUE;
    }

    pthread_mutex_unlock (& mutex);
}
Esempio n. 14
0
File: evp.c Progetto: worr/eventd
static void
_eventd_evp_global_parse(EventdPluginContext *context, GKeyFile *config_file)
{
    gchar *avahi_name;

    if ( ! g_key_file_has_group(config_file, "Server") )
        return;

    if ( libeventd_config_key_file_get_string(config_file, "Server", "AvahiName", &avahi_name) < 0 )
        return;
    if ( avahi_name != NULL )
    {
        g_free(context->avahi_name);
        context->avahi_name = avahi_name;
    }
}
Esempio n. 15
0
File: evp.c Progetto: worr/eventd
static void
_eventd_evp_event_parse(EventdPluginContext *context, const gchar *id, GKeyFile *config_file)
{
    gboolean disable;
    gint8 r;

    if ( ! g_key_file_has_group(config_file, "Event") )
        return;

    r = libeventd_config_key_file_get_boolean(config_file, "Event", "Disable", &disable);
    if ( r < 0 )
        return;

    if ( disable )
        g_hash_table_insert(context->events, g_strdup(id), GUINT_TO_POINTER(disable));
}
Esempio n. 16
0
/**
 * ethos_plugin_info_load_from_key_file:
 * @plugin_info: An #EthosPluginInfo
 * @group: the name of the group to load
 * @key_file: A #GKeyFile
 * @error: A location for a #GError or %NULL
 *
 * Loads the plugin information from @key_file.  The information is loaded from the group named
 * @group within the keyfile.  Therfore, if @group where "Sample Plugin" then the keyfile should
 * have a group header such as "[Sample Plugin]" within it.
 *
 * Upon failure, @error is set and %FALSE is returned.
 *
 * Return value: %TRUE on success
 */
gboolean
ethos_plugin_info_load_from_key_file (EthosPluginInfo  *plugin_info,
                                      const gchar      *group,
                                      GKeyFile         *key_file,
				      GError          **error)
{
	EthosPluginInfoPrivate *priv;

	g_return_val_if_fail (ETHOS_IS_PLUGIN_INFO (plugin_info), FALSE);
	g_return_val_if_fail (key_file != NULL, FALSE);

	priv = plugin_info->priv;

	ethos_plugin_info_clear (plugin_info);

	if (!g_key_file_has_group (key_file, group)) {
		g_set_error (error, ETHOS_ERROR, ETHOS_ERROR_INVALID_KEY_FILE,
		             "Could not find group %s in key file", group);
		return FALSE;
	}

	priv->loader    = g_key_file_get_string  (key_file, group, "Loader", NULL);
	priv->authors   = g_key_file_get_string_list
	                                         (key_file, group, "Authors", NULL, NULL);
	priv->desc      = g_key_file_get_locale_string  (key_file, group, "Description", NULL, NULL);
	priv->copyright = g_key_file_get_string  (key_file, group, "Copyright", NULL);
	priv->website   = g_key_file_get_string  (key_file, group, "Website", NULL);
	priv->deps      = g_key_file_get_string  (key_file, group, "Dependencies", NULL);
	priv->name      = g_key_file_get_locale_string  (key_file, group, "Name", NULL, NULL);
	priv->module    = g_key_file_get_string  (key_file, group, "Module", NULL);
	priv->icon      = g_key_file_get_string  (key_file, group, "Icon", NULL);
	priv->version   = g_key_file_get_string  (key_file, group, "Version", NULL);
	priv->iage      = g_key_file_get_integer (key_file, group, "IAge", NULL);

	if (!priv->name) {
		g_set_error (error, ETHOS_ERROR, ETHOS_ERROR_INVALID_KEY_FILE,
		             "No \"Name\" in key file");
		return FALSE;
	}
	else if (!priv->module) {
		g_set_error (error, ETHOS_ERROR, ETHOS_ERROR_INVALID_KEY_FILE,
		             "No \"Module\" in key file");
		return FALSE;
	}

	return TRUE;
}
Esempio n. 17
0
gboolean desmume_config_read_joykeys(GKeyFile *keyfile)
{
    GError *error = NULL;

    if (!g_key_file_has_group(keyfile, "JOYKEYS"))
        return TRUE;

    for (int i = 0; i < NB_KEYS; i++) {
        joypad_cfg[i] = g_key_file_get_integer(keyfile, "JOYKEYS", key_names[i], &error);
        if (error != NULL) {
            g_error_free(error);
            return FALSE;
        }
    }

    return TRUE;
}
Esempio n. 18
0
static void
preset_merge (GKeyFile * system, GKeyFile * user)
{
  gchar *str;
  gchar **groups, **keys;
  gsize i, j, num_groups, num_keys;

  /* copy file comment if there is any */
  if ((str = g_key_file_get_comment (user, NULL, NULL, NULL))) {
    g_key_file_set_comment (system, NULL, NULL, str, NULL);
    g_free (str);
  }

  /* get groups in user and copy into system */
  groups = g_key_file_get_groups (user, &num_groups);
  for (i = 0; i < num_groups; i++) {
    /* copy group comment if there is any */
    if ((str = g_key_file_get_comment (user, groups[i], NULL, NULL))) {
      g_key_file_set_comment (system, groups[i], NULL, str, NULL);
      g_free (str);
    }

    /* ignore private groups */
    if (groups[i][0] == '_')
      continue;

    /* if group already exists in system, remove and re-add keys from user */
    if (g_key_file_has_group (system, groups[i])) {
      g_key_file_remove_group (system, groups[i], NULL);
    }

    keys = g_key_file_get_keys (user, groups[i], &num_keys, NULL);
    for (j = 0; j < num_keys; j++) {
      /* copy key comment if there is any */
      if ((str = g_key_file_get_comment (user, groups[i], keys[j], NULL))) {
        g_key_file_set_comment (system, groups[i], keys[j], str, NULL);
        g_free (str);
      }
      str = g_key_file_get_value (user, groups[i], keys[j], NULL);
      g_key_file_set_value (system, groups[i], keys[j], str);
      g_free (str);
    }
    g_strfreev (keys);
  }
  g_strfreev (groups);
}
Esempio n. 19
0
/**
 * pragha_preferences_remove_key:
 *
 */
void
pragha_preferences_remove_key (PraghaPreferences *preferences,
                               const gchar *group_name,
                               const gchar *key)
{
	g_return_if_fail(PRAGHA_IS_PREFERENCES(preferences));

	if (g_key_file_has_group(preferences->priv->rc_keyfile, group_name) &&
	    g_key_file_has_key(preferences->priv->rc_keyfile,
	                       group_name,
	                       key,
	                       NULL))
		g_key_file_remove_key(preferences->priv->rc_keyfile,
		                      group_name,
		                      key,
		                      NULL);
}
Esempio n. 20
0
File: config.c Progetto: worr/eventd
static void
_eventd_config_read_dir(EventdConfig *config, GHashTable *config_files, const gchar *config_dir_name)
{
    GError *error = NULL;
    GDir *config_dir;

    config_dir = g_dir_open(config_dir_name, 0, &error);
    if ( config_dir == NULL )
    {
        g_warning("Can't read configuration directory '%s': %s", config_dir_name, error->message);
        g_clear_error(&error);
        return;
    }

    gchar *config_file_name = NULL;
    GKeyFile *config_file = NULL;
    const gchar *file;
    while ( ( file = g_dir_read_name(config_dir) ) != NULL )
    {
        if ( g_str_has_prefix(file, ".") )
            continue;

        config_file_name = g_build_filename(config_dir_name, file, NULL);

        if ( g_str_has_suffix(file, ".event") && g_file_test(config_file_name, G_FILE_TEST_IS_REGULAR) )
        {
            config_file = g_key_file_new();
            if ( ! g_key_file_load_from_file(config_file, config_file_name, G_KEY_FILE_NONE, &error) )
            {
                g_warning("Can't read the defaults file '%s': %s", config_file_name, error->message);
                g_clear_error(&error);
                g_key_file_free(config_file);
            }
            else if ( ! g_key_file_has_group(config_file, "Event") )
                g_key_file_free(config_file);
            else
                g_hash_table_insert(config_files, g_strdup(file), config_file);
        }
        else if ( g_file_test(config_file_name, G_FILE_TEST_IS_DIR) )
            _eventd_config_read_dir(config, config_files, config_file_name);

        g_free(config_file_name);
    }
    g_dir_close(config_dir);
}
Esempio n. 21
0
static EntityCapabilities*
_caps_by_ver(const char *const ver)
{
    if (!g_key_file_has_group(cache, ver)) {
        return NULL;
    }

    char *category = g_key_file_get_string(cache, ver, "category", NULL);
    char *type = g_key_file_get_string(cache, ver, "type", NULL);
    char *name = g_key_file_get_string(cache, ver, "name", NULL);

    char *software = g_key_file_get_string(cache, ver, "software", NULL);
    char *software_version = g_key_file_get_string(cache, ver, "software_version", NULL);
    char *os = g_key_file_get_string(cache, ver, "os", NULL);
    char *os_version = g_key_file_get_string(cache, ver, "os_version", NULL);

    gsize features_len = 0;
    gchar **features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL);
    GSList *features = NULL;
    if (features_list && features_len > 0) {
        int i;
        for (i = 0; i < features_len; i++) {
            features = g_slist_append(features, features_list[i]);
        }
    }

    EntityCapabilities *result = caps_create(
        category, type, name,
        software, software_version, os, os_version,
        features);

    g_free(category);
    g_free(type);
    g_free(name);
    g_free(software);
    g_free(software_version);
    g_free(os);
    g_free(os_version);
    if (features_list) {
        g_strfreev(features_list);
    }
    g_slist_free(features);

    return result;
}
Esempio n. 22
0
static void
_eventd_libcanberra_global_parse(EventdPluginContext *context, GKeyFile *config_file)
{
    if ( ! g_key_file_has_group(config_file, "Libcanberra") )
        return;

    gchar * sound_theme = NULL;

    if ( libeventd_config_key_file_get_string(config_file, "Libcanberra", "Theme", &sound_theme) < 0 )
        goto skip;

    /*
     * TODO: handle that
     */

skip:
    g_free(sound_theme);
}
Esempio n. 23
0
/**
 * Reads keys in keyfile if groupname is in that keyfile and fills
 * options_t *opt structure accordingly.
 * @param[in,out] opt : options_t * structure to store options read from the
 *                configuration file "filename".
 * @param keyfile is the GKeyFile structure that is used by glib to read
 *        groups and keys from.
 * @param filename : the filename of the configuration file to read from
 */
static void read_from_group_server(options_t *opt, GKeyFile *keyfile, gchar *filename)
{
    gint port = 0;

    if (opt != NULL && keyfile != NULL && filename != NULL && g_key_file_has_group(keyfile, GN_SERVER) == TRUE)
    {
        /* Reading the port number if any */
        port = read_int_from_file(keyfile, filename, GN_SERVER, KN_SERVER_PORT, _("Could not load server port number from file."), SERVER_PORT);

        if (port > 1024 && port < 65535)
        {
            opt->port = port;
        }

        /* Reading IP address of server's host if any */
        opt->ip = read_string_from_file(keyfile, filename, GN_SERVER, KN_SERVER_IP, _("Could not load cache database name"));
    }
}
Esempio n. 24
0
/**
* builder: The GTKBuilder
* password_type: password type description
*
* Reads the encrypted data from the prompt and transfers it using output_data.
* If crypto is available, it uses crypto.
*
**/
static void
gather_password (GtkBuilder *builder, const gchar *password_type)
{
	GtkEntry *entry;
	gchar iv[16];
	gpointer data;
	gsize n_data;
	gchar *name;
	const gchar *text;
	gchar *value;

	name = g_strdup_printf ("%s_entry", password_type);
	entry = GTK_ENTRY (gtk_builder_get_object (builder, name));
	g_return_if_fail (GTK_IS_ENTRY (entry));
	g_free (name);

	if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
		return;

	/* A non-encrypted password: just send the value back */
	if (!g_key_file_has_group (input_data, "transport")) {
		text = gtk_entry_get_text (entry);
		value = egg_hex_encode ((const guchar*)text, strlen (text));
		g_key_file_set_string (output_data, password_type, "parameter", "");
		g_key_file_set_string (output_data, password_type, "value", value);
		g_free (value);
		return;
	}

	if (!the_key && !negotiate_transport_crypto ()) {
		g_warning ("couldn't negotiate transport crypto for password");
		return;
	}

	gcry_create_nonce (iv, sizeof (iv));
	data = gku_prompt_util_encrypt_text (the_key, n_the_key, iv, sizeof (iv),
	                                     gtk_entry_get_text (entry), &n_data);
	g_return_if_fail (data);

	gku_prompt_util_encode_hex (output_data, password_type, "parameter", iv, sizeof (iv));
	gku_prompt_util_encode_hex (output_data, password_type, "value", data, n_data);

	g_free (data);
}
Esempio n. 25
0
static void ril_get_net_config(struct radio_data *rsd)
{
	GKeyFile *keyfile;
	GError *err = NULL;
	char *path = RIL_CONFIG;
	rsd->ratmode = PREF_NET_TYPE_GSM_WCDMA_AUTO;

	keyfile = g_key_file_new();

	g_key_file_set_list_separator(keyfile, ',');

	if (!g_key_file_load_from_file(keyfile, path, 0, &err))
		g_error_free(err);
	else {
		if (g_key_file_has_group(keyfile, LTE_FLAG))
			rsd->ratmode = PREF_NET_TYPE_LTE_GSM_WCDMA;
	}
	g_key_file_free(keyfile);
}
Esempio n. 26
0
static void read_colors ()
{

  GError *error = NULL;
  color_config = g_key_file_new ();

  if (!g_key_file_load_from_file (color_config, options.color_file, 0, &error)) {
    g_printerr ("%s\n", error->message);
    return;
  }

  fallback_size = 0;

  const gchar *group = "colors";
  if (g_key_file_has_group (color_config, group)) {
    if (g_key_file_has_key (color_config, group, "fallback", &error))
      fallback_colors = g_key_file_get_string_list (color_config, group, "fallback", &fallback_size, &error);
  }
}
Esempio n. 27
0
static GtkPrintSettings *
load_settings (GKeyFile *key_file)
{
	GtkPrintSettings *settings;
	GError *error = NULL;

	settings = gtk_print_settings_new ();

	if (g_key_file_has_group (key_file, PRINT_SETTINGS_GROUP_NAME))
		gtk_print_settings_load_key_file (
			settings, key_file, PRINT_SETTINGS_GROUP_NAME, &error);

	if (error != NULL) {
		g_warning ("%s", error->message);
		g_error_free (error);
	}

	return settings;
}
Esempio n. 28
0
static
char* _find_app_id_by_filter(const char* name, const char* keys_str, GKeyFile* filter)
{
    if (filter == NULL) return NULL;
    g_assert(name != NULL && keys_str != NULL);
    if (g_key_file_has_group(filter, name)) {
        gsize size = 0;
        char** keys = g_key_file_get_keys(filter, name, &size, NULL);
        for (gsize i=0; i<size; i++) {
            if (g_strstr_len(keys_str , -1, keys[i])) {
                char* value = g_key_file_get_string(filter, name, keys[i], NULL);
                g_strfreev(keys);
                return value;
            }
        }
        g_strfreev(keys);
        /*g_debug("find \"%s\" in filter.ini but can't find the really desktop file\n", name);*/
    }
    return NULL;
}
Esempio n. 29
0
static void
_eventd_exec_event_parse(EventdPluginContext *context, const gchar *config_id, GKeyFile *config_file)
{
    gboolean disable;
    gchar *command = NULL;

    if ( ! g_key_file_has_group(config_file, "Exec") )
        return;

    if ( libeventd_config_key_file_get_boolean(config_file, "Exec", "Disable", &disable) < 0 )
        return;

    if ( ! disable )
    {
        if ( libeventd_config_key_file_get_string(config_file, "Exec", "Command", &command) < 0 )
            return;
    }

    g_hash_table_insert(context->events, g_strdup(config_id), command);
}
Esempio n. 30
0
static void
_eventd_sound_event_parse(EventdPluginContext *context, const gchar *id, GKeyFile *config_file)
{
    gboolean disable;
    gchar *sound = NULL;

    if ( ! g_key_file_has_group(config_file, "Sound") )
        return;

    if ( libeventd_config_key_file_get_boolean(config_file, "Sound", "Disable", &disable) < 0 )
        return;

    if ( ! disable )
    {
        if ( libeventd_config_key_file_get_string_with_default(config_file, "Sound", "File", "sound-file", &sound) < 0 )
            return;
    }

    g_hash_table_insert(context->events, g_strdup(id), sound);
}