コード例 #1
0
EVENTD_EXPORT
gint8
evhelpers_config_key_file_get_int_list(GKeyFile *config_file, const gchar *group, const gchar *key, Int *values, gsize *length)
{
    gint *value;
    gsize value_length;
    GError *error = NULL;
    gint8 ret;

    value = g_key_file_get_integer_list(config_file, group, key, &value_length, &error);
    ret = _evhelpers_config_key_file_error(&error, group, key);

    if ( ret != 0 )
        return ret;

    if ( value_length > *length )
    {
        g_warning("Couldn't read the key [%s] '%s': Too many values", group, key);
        g_free(value);
        return -1;
    }

    gsize i;
    for ( i = 0 ; i < value_length ; ++i )
    {
        values[i].set = TRUE;
        values[i].value = value[i];
    }
    for ( ; i < *length ; ++i )
        values[i].set = FALSE;

    g_free(value);
    return 0;
}
コード例 #2
0
ファイル: rclib-settings.c プロジェクト: horc-fn/RhythmCat2
gint *rclib_settings_get_integer_list(const gchar *group_name,
    const gchar *key, gsize *length, GError **error)
{
    if(settings_keyfile==NULL) return NULL;
    return g_key_file_get_integer_list(settings_keyfile, group_name, key,
        length, error);
}
コード例 #3
0
void test_setinteger()
{
	GKeyFile *keyfile;
	gint *value;
	gsize n = 2;
	
	gint list[2] = {111,222};
	
	const gchar *data = 
	    "[1]\n"
	    "key1=123\n"
	    "key2=456\n";

	keyfile = load_data (data, 0);
	
	check_integer_value (keyfile, "1", "key1", 123);
	g_key_file_set_integer(keyfile,"1","key1",789);
	check_integer_value (keyfile, "1", "key1", 789);
	
	g_key_file_set_integer_list(keyfile,"1","key1",list,2);
	
	value = g_key_file_get_integer_list(keyfile, "1", "key1",&n, NULL);
	
	g_assert(value[0] == 111);
	g_assert(value[1] == 222);
	
}
コード例 #4
0
ファイル: reader.c プロジェクト: T100012/NetworkManager
static void
mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
{
	const char *setting_name = nm_setting_get_name (setting);
	char *tmp_string = NULL, *p;
	gint *tmp_list;
	GByteArray *array = NULL;
	gsize length;
	int i, type;

	p = tmp_string = g_key_file_get_string (keyfile, setting_name, key, NULL);
	if (tmp_string) {
		/* Look for enough ':' characters to signify a MAC address */
		i = 0;
		while (*p) {
			if (*p == ':')
				i++;
			p++;
		}

		/* If we found enough it's probably a string-format MAC address */
		type = nm_utils_hwaddr_type (i + 1);
		if (type > 0)
			array = nm_utils_hwaddr_atoba (tmp_string, type);
	}
	g_free (tmp_string);

	if (array == NULL) {
		/* Old format; list of ints */
		tmp_list = g_key_file_get_integer_list (keyfile, setting_name, key, &length, NULL);
		type = nm_utils_hwaddr_type (length);
		if (type < 0) {
			array = g_byte_array_sized_new (length);
			for (i = 0; i < length; i++) {
				int val = tmp_list[i];
				const guint8 v = (guint8) (val & 0xFF);

				if (val < 0 || val > 255) {
					g_warning ("%s: %s / %s ignoring invalid byte element '%d' (not "
							   " between 0 and 255 inclusive)", __func__, setting_name,
							   key, val);
					g_byte_array_free (array, TRUE);
					array = NULL;
					break;
				}
				g_byte_array_append (array, &v, 1);
			}
		}
		g_free (tmp_list);
	}

	if (array) {
		g_object_set (setting, key, array, NULL);
		g_byte_array_free (array, TRUE);
	} else {
		g_warning ("%s: ignoring invalid MAC address for %s / %s",
		           __func__, setting_name, key);
	}
}
コード例 #5
0
static void
mac_address_parser (NMSetting *setting, const char *key, GKeyFile *keyfile)
{
	const char *setting_name = nm_setting_get_name (setting);
	struct ether_addr *eth;
	char *tmp_string = NULL, *p;
	gint *tmp_list;
	GByteArray *array = NULL;
	gsize length;
	int i;

	p = tmp_string = g_key_file_get_string (keyfile, setting_name, key, NULL);
	if (tmp_string) {
		/* Look for enough ':' characters to signify a MAC address */
		i = 0;
		while (*p) {
			if (*p == ':')
				i++;
			p++;
		}
		if (i == 5) {
			/* parse as a MAC address */
			eth = ether_aton (tmp_string);
			if (eth) {
				g_free (tmp_string);
				array = g_byte_array_sized_new (ETH_ALEN);
				g_byte_array_append (array, eth->ether_addr_octet, ETH_ALEN);
				goto done;
			}
		}
	}
	g_free (tmp_string);

	/* Old format; list of ints */
	tmp_list = g_key_file_get_integer_list (keyfile, setting_name, key, &length, NULL);
	array = g_byte_array_sized_new (length);
	for (i = 0; i < length; i++) {
		int val = tmp_list[i];
		unsigned char v = (unsigned char) (val & 0xFF);

		if (val < 0 || val > 255) {
			g_warning ("%s: %s / %s ignoring invalid byte element '%d' (not "
			           " between 0 and 255 inclusive)", __func__, setting_name,
			           key, val);
		} else
			g_byte_array_append (array, (const unsigned char *) &v, sizeof (v));
	}
	g_free (tmp_list);

done:
	if (array->len == ETH_ALEN) {
		g_object_set (setting, key, array, NULL);
	} else {
		g_warning ("%s: ignoring invalid MAC address for %s / %s",
		           __func__, setting_name, key);
	}
	g_byte_array_free (array, TRUE);
}
コード例 #6
0
ファイル: get.c プロジェクト: MidnightCommander/mc
int *
mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
                        const gchar * param, gsize * length)
{
    if (!mc_config || !group || !param)
        return NULL;

    return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
}
コード例 #7
0
ファイル: pragha-preferences.c プロジェクト: pingax/pragha
/**
 * pragha_preferences_get_integer_list:
 *
 */
gint *
pragha_preferences_get_integer_list (PraghaPreferences *preferences,
                                     const gchar *group_name,
                                     const gchar *key,
                                     gsize *length)
{
	g_return_val_if_fail(PRAGHA_IS_PREFERENCES(preferences), NULL);

	return g_key_file_get_integer_list(preferences->priv->rc_keyfile,
	                                   group_name,
	                                   key,
	                                   length,
	                                   NULL);
}
コード例 #8
0
ファイル: settings.c プロジェクト: SilverDeath/viking
static gboolean settings_get_integer_list ( const gchar *group, const gchar *name, gint **vals, gsize *length )
{
	GError *error = NULL;
	gboolean success = TRUE;
	gint *ints = g_key_file_get_integer_list ( keyfile, group, name, length, &error );
	if ( error ) {
		// Only print on debug - as often may have requests for keys not in the file
		g_debug ( "%s", error->message );
		g_error_free ( error );
		success = FALSE;
	}
	*vals = ints;
	return success;
}
コード例 #9
0
ファイル: prefs.c プロジェクト: Cw1X/pnmixer
gint* get_vol_meter_colors() {
  gsize numcols = 3;
  gint* vol_meter_clrs = NULL;
  if (g_key_file_has_key(keyFile,"PNMixer","VolMeterColor",NULL))
    vol_meter_clrs = g_key_file_get_integer_list(keyFile,"PNMixer","VolMeterColor",&numcols,NULL);
  if (!vol_meter_clrs || (numcols != 3)) {
    if (vol_meter_clrs) { // corrupt value somehow
      report_error(_("Invalid color for volume meter in config file.  Reverting to default."));
      g_free(vol_meter_clrs);
    }
    vol_meter_clrs = g_malloc(3*sizeof(gint));
    vol_meter_clrs[0] = 59624;
    vol_meter_clrs[1] = 28270;
    vol_meter_clrs[2] = 28270;
  }
  return vol_meter_clrs;
}
コード例 #10
0
ファイル: reader.c プロジェクト: T100012/NetworkManager
static gboolean
read_array_of_uint (GKeyFile *file,
                    NMSetting *setting,
                    const char *key)
{
	GArray *array = NULL;
	gsize length;
	int i;
	gint *tmp;

	tmp = g_key_file_get_integer_list (file, nm_setting_get_name (setting), key, &length, NULL);
	array = g_array_sized_new (FALSE, FALSE, sizeof (guint32), length);
	g_return_val_if_fail (array != NULL, FALSE);

	for (i = 0; i < length; i++)
		g_array_append_val (array, tmp[i]);

	g_object_set (setting, key, array, NULL);
	g_array_unref (array);

	return TRUE;
}
コード例 #11
0
ファイル: keyfile.c プロジェクト: andrewdavis12/cutter
static void
check_integer_list_value (GKeyFile    *keyfile,
			  const gchar *group,
			  const gchar *key,
			  ...)
{
  gint i;
  gint v, *value;
  va_list args;
  gsize len;
  GError *error = NULL;

  value = g_key_file_get_integer_list (keyfile, group, key, &len, &error);
  check_no_error (error);
  cut_assert (value);
  
  va_start (args, key);
  i = 0;
  v = va_arg (args, gint);
  while (v != -100)
    {
      cut_assert (i != len,
      		  cut_message ("Group %s key %s: list too short (%d)",
                               group, key, i));
      cut_assert_equal_int (v, value[i],
		      	    cut_message ("Group %s key %s: mismatch at %d, "
                                         "expected %d, got %d",
                                         group, key, i, v, value[i]));
      i++;
      v = va_arg (args, gint);
    }

  va_end (args);
  
  g_free (value);
}
コード例 #12
0
ファイル: gui_prefs.c プロジェクト: davewongillies/gmameui
static void
mame_gui_prefs_init (MameGuiPrefs *pr)
{
	gboolean load_result;
	gint *int_array;
	gsize columnsize;
	guint i;
	
	GMAMEUI_DEBUG ("Creating GUI prefs object");	
	pr->priv = g_new0 (MameGuiPrefsPrivate, 1);
	
	int_array = g_new0 (gint, NUMBER_COLUMN);       /* Used for loading integer lists from prefs file */
	
	pr->priv->cols_shown = g_value_array_new (NUMBER_COLUMN);
	pr->priv->cols_width = g_value_array_new (NUMBER_COLUMN);
	
	pr->priv->executable_paths = g_value_array_new (4);     /* FIXME TODO MAX_EXECUTABLES */
	pr->priv->rom_paths = g_value_array_new (4);    /* FIXME TODO - define max number */
	pr->priv->sample_paths = g_value_array_new (4); /* FIXME TODO - define max number */

	/* The gmameui.ini pref file should be stored in the following locations:
	     ~/.config/gmameui (on Linux)
	 */
	pr->priv->filename = g_build_filename (get_gmameui_config_dir (), "gmameui.ini", NULL);

	pr->priv->prefs_ini_file = g_key_file_new ();
	GError *error = NULL;
	load_result = g_key_file_load_from_file (pr->priv->prefs_ini_file, pr->priv->filename,
						 G_KEY_FILE_KEEP_COMMENTS, &error);

	if (!load_result) {
		GMAMEUI_DEBUG ("Error loading %s - %s", pr->priv->filename, error->message);	
	
		g_error_free (error);
		error = NULL;
	}

	/* UI preferences */
	pr->priv->ui_width = mame_gui_prefs_get_int_property_from_key_file (pr, "ui-width");
	pr->priv->ui_height = mame_gui_prefs_get_int_property_from_key_file (pr, "ui-height");
	pr->priv->show_toolbar = mame_gui_prefs_get_bool_property_from_key_file (pr, "show-toolbar");
	pr->priv->show_statusbar = mame_gui_prefs_get_bool_property_from_key_file (pr, "show-statusbar");
	pr->priv->show_filterlist = mame_gui_prefs_get_bool_property_from_key_file (pr, "show-filterlist");
	pr->priv->show_screenshot = mame_gui_prefs_get_bool_property_from_key_file (pr, "show-screenshot");
	pr->priv->current_rom_filter = mame_gui_prefs_get_int_property_from_key_file (pr, "current-rom-filter");
	pr->priv->current_mode = mame_gui_prefs_get_int_property_from_key_file (pr, "current-mode");
	pr->priv->previous_mode = mame_gui_prefs_get_int_property_from_key_file (pr, "previous-mode");
	int_array = g_key_file_get_integer_list (pr->priv->prefs_ini_file, "Preferences", "cols-shown", &columnsize, &error);
	for (i = 0; i < NUMBER_COLUMN; ++i) {
		GValue val = { 0, };
		
		g_value_init (&val, G_TYPE_INT);
		g_value_set_int (&val, int_array != NULL ? int_array[i] : 1);	/* If not available, default to shown */

		GMAMEUI_DEBUG ("Value for cols-shown at %d is %d", i, g_value_get_int (&val));
		g_value_array_append (pr->priv->cols_shown, &val);
	}
	if (error) {
		GMAMEUI_DEBUG ("Error retrieving cols-shown: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	int_array = g_key_file_get_integer_list (pr->priv->prefs_ini_file, "Preferences", "cols-width", &columnsize, &error);
	for (i = 0; i < NUMBER_COLUMN; ++i) {
		GValue val = { 0, };
		/* FIXME TODO 0 means auto sized columns */
		g_value_init (&val, G_TYPE_INT);
		g_value_set_int (&val, int_array != NULL ? int_array[i] : 0);	/* If not available, default to 0 */
		GMAMEUI_DEBUG ("Value for cols-width at %d is %d", i, g_value_get_int (&val));
		g_value_array_append (pr->priv->cols_width, &val);
	}
	if (error) {
		GMAMEUI_DEBUG ("Error retrieving cols-width: %s", error->message);
		g_error_free (error);
		error = NULL;
	}

	pr->priv->sort_col = mame_gui_prefs_get_int_property_from_key_file (pr, "sort-col");
	pr->priv->sort_col_direction = mame_gui_prefs_get_int_property_from_key_file (pr, "sort-col-direction");
	pr->priv->xpos_filters = mame_gui_prefs_get_int_property_from_key_file (pr, "xpos-filters");
	pr->priv->xpos_gamelist = mame_gui_prefs_get_int_property_from_key_file (pr, "xpos-gamelist");
	
	/* Startup preferences */
	pr->priv->GameCheck = mame_gui_prefs_get_bool_property_from_key_file (pr, "gamecheck");
	pr->priv->VersionCheck = mame_gui_prefs_get_bool_property_from_key_file (pr, "versioncheck");
	pr->priv->use_xmame_options = mame_gui_prefs_get_bool_property_from_key_file (pr, "usexmameoptions");
	pr->priv->prefercustomicons = mame_gui_prefs_get_bool_property_from_key_file (pr, "prefercustomicons");
	pr->priv->gui_joy = mame_gui_prefs_get_bool_property_from_key_file (pr, "usejoyingui");
	pr->priv->joystick_name = mame_gui_prefs_get_string_property_from_key_file (pr, "joystick-name");
	if (!pr->priv->joystick_name)
		pr->priv->joystick_name = g_strdup (get_joy_dev ());
	
	/* Miscellaneous preferences */
	pr->priv->theprefix = mame_gui_prefs_get_bool_property_from_key_file (pr, "theprefix");

	pr->priv->current_rom_name = mame_gui_prefs_get_string_property_from_key_file (pr, "current-rom");
	pr->priv->current_executable_name = mame_gui_prefs_get_string_property_from_key_file (pr, "current-executable");

	/* Load the executable paths */
	pr->priv->executable_paths = mame_gui_prefs_get_stringlist_property_from_key_file (pr, "Preferences", "executable-paths");
	
	/* Load the ROM paths */
	pr->priv->rom_paths = mame_gui_prefs_get_stringlist_property_from_key_file (pr, "Preferences", "rom-paths");
	
	/* Load the Samples paths */
	pr->priv->sample_paths = mame_gui_prefs_get_stringlist_property_from_key_file (pr, "Preferences", "sample-paths");

	/* Directory preferences */
	GMAMEUI_DEBUG ("Reading directories preferences from file");
	for (i = 0; i < NUM_DIRS; i++) {
		pr->priv->directories[i] = mame_gui_prefs_get_string_property_from_key_file (pr, directory_prefs[i].name);
		
		/* If no values set, set default values */
		if (!pr->priv->directories[i])
			pr->priv->directories[i] = g_strdup (directory_prefs[i].default_dir);   /* strdup, since we free in finalize */
		GMAMEUI_DEBUG ("Setting directory %d (%s) to %s", i, directory_prefs[i].name, pr->priv->directories[i]);
		
		/* If directory does not exist under $HOME/.config/mame, create it */
		if (i >= DIR_CFG) {
			gchar *dir;
			dir = g_build_filename (g_get_user_config_dir (), "mame", directory_prefs[i].default_dir, NULL);
			if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
				GMAMEUI_DEBUG ("Directory %s does not exist, creating it", dir);
				g_mkdir (dir, S_IRWXU);
			}
			g_free (dir);
		}
		
	}
	GMAMEUI_DEBUG ("Reading directories preferences from file... done");
	
	/* Set handlers so that whenever the values are changed (from anywhere), the signal handler
	   is invoked; the callback then saves to the g_key_file */
	g_signal_connect (pr, "notify::ui-width", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::ui-height", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::show-toolbar", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::show-statusbar", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::show-filterlist", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::show-screenshot", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::current-rom-filter", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::current-mode", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::previous-mode", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::cols-shown", (GCallback) mame_gui_prefs_save_int_arr, NULL);
	g_signal_connect (pr, "notify::cols-width", (GCallback) mame_gui_prefs_save_int_arr, NULL);
	g_signal_connect (pr, "notify::sort-col", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::sort-col-direction", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::xpos-filters", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::xpos-gamelist", (GCallback) mame_gui_prefs_save_int, NULL);
	g_signal_connect (pr, "notify::gamecheck", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::versioncheck", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::usexmameoptions", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::prefercustomicons", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::usejoyingui", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::joystick-name", (GCallback) mame_gui_prefs_save_string, NULL);
	g_signal_connect (pr, "notify::theprefix", (GCallback) mame_gui_prefs_save_bool, NULL);
	g_signal_connect (pr, "notify::current-rom", (GCallback) mame_gui_prefs_save_string, NULL);
	g_signal_connect (pr, "notify::current-executable", (GCallback) mame_gui_prefs_save_string, NULL);
	g_signal_connect (pr, "notify::executable-paths", (GCallback) mame_gui_prefs_save_string_arr, NULL);
	g_signal_connect (pr, "notify::rom-paths", (GCallback) mame_gui_prefs_save_string_arr, NULL);
	g_signal_connect (pr, "notify::sample-paths", (GCallback) mame_gui_prefs_save_string_arr, NULL); 
	
	for (i = 0; i < NUM_DIRS; i++) {
		gchar *signal_name;
		signal_name = g_strdup_printf("notify::%s", directory_prefs[i].name);
		GMAMEUI_DEBUG("Connecting signal %s", signal_name);
		g_signal_connect (pr, signal_name, (GCallback) mame_gui_prefs_save_string, NULL);
		g_free (signal_name);
	}
GMAMEUI_DEBUG ("Creating GUI prefs object... done");
}
コード例 #13
0
void 
cid_read_key_file (CidMainContainer **pCid, const gchar *f) 
{   
    CidMainContainer *cid = *pCid;
    if (!cid_load_key_file(pCid, f))
        cid_exit(CID_ERROR_READING_FILE,"Key File error");

    bChangedDesktop = cid->config->bAllDesktop;
    iPlayerChanged  = cid->config->iPlayer;
    iSymbolChanged  = cid->config->iSymbolColor;
    iOldWidth       = cid->config->iWidth;
    iOldHeight      = cid->config->iHeight;
    
    gint *pSize;
    gsize iReadSize;

    GError *error = NULL;
    bUnvalidKey = FALSE;
    
    // [System] configuration
    cid->config->iPlayer         = CID_CONFIG_GET_INTEGER ("System", "PLAYER");
    cid->config->iInter          = CID_CONFIG_GET_INTEGER_WITH_DEFAULT ("System", "INTER", DEFAULT_TIMERS) SECONDES;
    cid->config->bMonitorPlayer  = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("System", "MONITOR", TRUE);
    cid->config->bPlayerState    = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("System", "STATE", TRUE);
    cid->config->bDisplayTitle   = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("System", "TITLE", TRUE);
    cid->config->iSymbolColor    = CID_CONFIG_GET_INTEGER ("System", "SYMBOL_COLOR");
    cid->config->bDisplayControl = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("System", "CONTROLS", TRUE);
    cid->config->dPoliceSize     = g_key_file_get_double  (cid->pKeyFile, "System", "POLICE_SIZE", &error);
    cid_free_and_debug_error(&error);
    cid->config->dPoliceColor    = g_key_file_get_double_list (cid->pKeyFile, "System", "POLICE_COLOR", &cid->config->gPlainTextSize, &error);
    cid_free_and_debug_error(&error);
    cid->config->dOutlineTextColor = g_key_file_get_double_list (cid->pKeyFile, "System", "OUTLINE_COLOR", &cid->config->gOutlineTextSize, &error);
    cid_free_and_debug_error(&error);

    // [Options] configuration
    cid->config->bHide           = CID_CONFIG_GET_BOOLEAN ("Options", "HIDE");
    cid->config->cDefaultImage   = CID_CONFIG_GET_FILE_PATH  ("Options", "IMAGE", cid->config->bDevMode ? TESTING_DIR"/"TESTING_COVER : CID_DEFAULT_IMAGE);
    cid->config->bRunAnimation   = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Options", "ANIMATION", TRUE);
    cid->config->iAnimationType  = CID_CONFIG_GET_INTEGER ("Options", "ANIMATION_TYPE");
    cid->config->iAnimationSpeed = CID_CONFIG_GET_INTEGER ("Options", "ANIMATION_SPEED");
    cid->config->bThreaded       = CID_CONFIG_GET_BOOLEAN ("Options", "THREAD");
    cid->config->bDownload       = CID_CONFIG_GET_BOOLEAN ("Options", "DOWNLOAD");
    cid->config->cDLPath         = CID_CONFIG_GET_STRING_WITH_DEFAULT ("Options", "DL_PATH", cid->defaut->cDLPath);
    cid->config->iImageSize      = CID_CONFIG_GET_INTEGER ("Options", "D_SIZE");
    cid->config->iTimeToWait     = CID_CONFIG_GET_INTEGER_WITH_DEFAULT ("Options", "DELAY", DEFAULT_TIMERS);
    cid->config->bUnstable       = cid->config->bTesting && CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Options", "B_UNSTABLE", TRUE);
    
    // [Behaviour] configuration
    cid->config->iPosX          = CID_CONFIG_GET_INTEGER ("Behaviour", "GAP_X");
    cid->config->iPosY          = CID_CONFIG_GET_INTEGER ("Behaviour", "GAP_Y");
    pSize               = g_key_file_get_integer_list (cid->pKeyFile, "Behaviour", "SIZE", &iReadSize, &error);
    if (cid_free_and_debug_error(&error) || iReadSize != 2)
    {
        pSize = g_realloc (pSize, 2 * sizeof(int));
        if (pSize != NULL)
        {
            pSize[0] = DEFAULT_SIZE;
            pSize[1] = DEFAULT_SIZE;
        }
        else
        {
            cid_exit (CID_ERROR_READING_FILE, "cannot allocate memory");
        }
    }
    cid->config->dRotate        = g_key_file_get_double  (cid->pKeyFile, "Behaviour", "ROTATION", &error);
    cid_free_and_debug_error(&error);
    cid->config->dColor         = g_key_file_get_double_list (cid->pKeyFile, "Behaviour", "COLOR", &cid->config->gColorSize, &error);
    cid_free_and_debug_error(&error);
    cid->config->dFlyingColor   = g_key_file_get_double_list (cid->pKeyFile, "Behaviour", "FLYING_COLOR", &cid->config->gFlyingColorSize, &error);
    cid_free_and_debug_error(&error);
    cid->config->bKeepCorners   = CID_CONFIG_GET_BOOLEAN ("Behaviour", "KEEP_CORNERS");
    cid->config->bAllDesktop    = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Behaviour", "ALL_DESKTOP", TRUE);
    cid->config->bLockPosition  = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Behaviour", "LOCK", TRUE);
    cid->config->bMask          = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Behaviour", "MASK", TRUE);
    cid->config->bShowAbove     = CID_CONFIG_GET_BOOLEAN_WITH_DEFAULT ("Behaviour", "SWITCH_ABOVE", TRUE);
    
    // MPD configurations
    cid->mpd_dir   = CID_CONFIG_GET_DIR_PATH ("MPD", "MPD_DIR", g_strdup_printf ("%s/Music",g_getenv ("HOME")));
    cid->mpd_host  = CID_CONFIG_GET_STRING ("MPD", "MPD_HOST");
    if (cid->mpd_host != NULL && strcmp (cid->mpd_host, "") == 0)
    {
        g_free (cid->mpd_host);
        cid->mpd_host = g_strdup ("localhost");
    }
    gchar *cEncrypted = NULL;
    cEncrypted     = CID_CONFIG_GET_STRING ("MPD", "MPD_PASS");
    //cid_decrypt_string (cEncrypted, &cid->mpd_pass);
    cid->mpd_pass = g_strdup (cEncrypted);
    g_free (cEncrypted);
    cid->mpd_port  = CID_CONFIG_GET_INTEGER_WITH_DEFAULT ("MPD", "MPD_PORT", 6600);
    
    cid->config->iWidth = pSize[0] <= MAX_SIZE ? pSize[0] : MAX_SIZE;
    cid->config->iHeight = pSize[1] <= MAX_SIZE ? pSize[1] : MAX_SIZE;
    
    if (!bUnvalidKey) 
    {
        cid->config->dRed            = cid->config->dColor[0];
        cid->config->dGreen          = cid->config->dColor[1];
        cid->config->dBlue           = cid->config->dColor[2];
        cid->config->dAlpha          = cid->config->dColor[3];
        cid->runtime->dFocusVariation = cid->config->dFlyingColor[3]>cid->config->dAlpha ? +1 : -1;
        cid->config->iExtraSize      = (cid->config->iHeight + cid->config->iWidth)/20;
        cid->config->iPrevNextSize   = cid->config->iExtraSize * 2;
        cid->config->iPlayPauseSize  = cid->config->iExtraSize * 3;
    }
    
    cid_key_file_free(pCid);

    if (bUnvalidKey && !bReloaded)
    {
        cid_save_data (pCid);
        cid_read_key_file (pCid, f);
        bReloaded = TRUE;
    }
}
コード例 #14
0
static void
ssid_parser (NMSetting *setting, const char *key, GKeyFile *keyfile)
{
	const char *setting_name = nm_setting_get_name (setting);
	GByteArray *array = NULL;
	char *p, *tmp_string;
	gint *tmp_list;
	gsize length;
	int i;

	/* New format: just a string.  We try parsing the new format if there are
	 * no ';' in the string or it's not just numbers.
	 */
	p = tmp_string = g_key_file_get_string (keyfile, setting_name, key, NULL);
	if (tmp_string) {
		gboolean new_format = FALSE;

		if (strchr (p, ';') == NULL)
			new_format = TRUE;
		else {
			new_format = TRUE;
			while (p && *p) {
				if (!isdigit (*p++)) {
					new_format = FALSE;
					break;
				}
			}
		}

		if (new_format) {
			array = g_byte_array_sized_new (strlen (tmp_string));
			g_byte_array_append (array, (guint8 *) tmp_string, strlen (tmp_string));
			goto done;
		}
	}
	g_free (tmp_string);

	/* Old format; list of ints */
	tmp_list = g_key_file_get_integer_list (keyfile, setting_name, key, &length, NULL);
	array = g_byte_array_sized_new (length);
	for (i = 0; i < length; i++) {
		int val = tmp_list[i];
		unsigned char v = (unsigned char) (val & 0xFF);

		if (val < 0 || val > 255) {
			g_warning ("%s: %s / %s ignoring invalid byte element '%d' (not "
			           " between 0 and 255 inclusive)", __func__, setting_name,
			           key, val);
		} else
			g_byte_array_append (array, (const unsigned char *) &v, sizeof (v));
	}
	g_free (tmp_list);

done:
	if (array->len)
		g_object_set (setting, key, array, NULL);
	else {
		g_warning ("%s: ignoring invalid SSID for %s / %s",
		           __func__, setting_name, key);
	}
	g_byte_array_free (array, TRUE);
}
コード例 #15
0
/**************************************************
 * load_common
 *
 * load the settings from a state key file
 **************************************************/
bool
CsvImportSettings::load_common (void)
{
    GError *key_error = nullptr;
    m_load_error = false;
    auto group = csv_group_prefix + m_settings_type + " - " + m_name;
    auto keyfile = gnc_state_get_current ();

    m_skip_start_lines = g_key_file_get_integer (keyfile, group.c_str(), CSV_SKIP_START, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    m_skip_end_lines = g_key_file_get_integer (keyfile, group.c_str(), CSV_SKIP_END, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    m_skip_alt_lines = g_key_file_get_boolean (keyfile, group.c_str(), CSV_SKIP_ALT, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    auto csv_format = g_key_file_get_boolean (keyfile, group.c_str(), CSV_FORMAT, &key_error);
    if (key_error) csv_format = true; // default to true, but above command will return false in case of error
    m_load_error |= handle_load_error (&key_error, group);
    if (csv_format)
        m_file_format = GncImpFileFormat::CSV;
    else
        m_file_format = GncImpFileFormat::FIXED_WIDTH;

    gchar *key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_SEP, &key_error);
    if (key_char && *key_char != '\0')
        m_separators = key_char;
    m_load_error |= handle_load_error (&key_error, group);
    if (key_char)
        g_free (key_char);

    m_date_format = g_key_file_get_integer (keyfile, group.c_str(), CSV_DATE, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    m_currency_format = g_key_file_get_integer (keyfile, group.c_str(), CSV_CURRENCY, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_ENCODING, &key_error);
    if (key_char && *key_char != '\0')
        m_encoding = key_char;
    else
        m_encoding = "UTF-8";
    m_load_error |= handle_load_error (&key_error, group);
    if (key_char)
        g_free (key_char);

    // Widths
    gsize list_len;
    m_column_widths.clear();
    gint *col_widths_int = g_key_file_get_integer_list (keyfile, group.c_str(), CSV_COL_WIDTHS,
            &list_len, &key_error);
    for (uint32_t i = 0; i < list_len; i++)
    {
        if (col_widths_int[i] > 0)
            m_column_widths.push_back(col_widths_int[i]);
    }
    m_load_error |= handle_load_error (&key_error, group);
    if (col_widths_int)
        g_free (col_widths_int);

    return m_load_error;
}
コード例 #16
0
ファイル: gclue-config.c プロジェクト: ankitstarski/Geoclue
static void
load_app_configs (GClueConfig *config)
{
        const char *known_groups[] = { "agent", "wifi", NULL };
        GClueConfigPrivate *priv = config->priv;
        gsize num_groups = 0, i;
        char **groups;

        groups = g_key_file_get_groups (priv->key_file, &num_groups);
        if (num_groups == 0)
                return;

        for (i = 0; i < num_groups; i++) {
                AppConfig *app_config;
                int* users;
                gsize num_users = 0, j;
                gboolean allowed, system;
                gboolean ignore = FALSE;
                GError *error = NULL;

                for (j = 0; known_groups[j] != NULL; j++)
                        if (strcmp (groups[i], known_groups[j]) == 0) {
                                ignore = TRUE;

                                continue;
                        }

                if (ignore)
                        continue;

                allowed = g_key_file_get_boolean (priv->key_file,
                                                  groups[i],
                                                  "allowed",
                                                  &error);
                if (error != NULL)
                        goto error_out;

                system = g_key_file_get_boolean (priv->key_file,
                                                 groups[i],
                                                 "system",
                                                 &error);
                if (error != NULL)
                        goto error_out;

                users = g_key_file_get_integer_list (priv->key_file,
                                                     groups[i],
                                                     "users",
                                                     &num_users,
                                                     &error);
                if (error != NULL)
                        goto error_out;

                app_config = g_slice_new0 (AppConfig);
                app_config->id = g_strdup (groups[i]);
                app_config->allowed = allowed;
                app_config->system = system;
                app_config->users = users;
                app_config->num_users = num_users;

                priv->app_configs = g_list_prepend (priv->app_configs, app_config);

                continue;
error_out:
                g_warning ("Failed to load configuration for app '%s': %s",
                           groups[i],
                           error->message);
                g_error_free (error);
        }

        g_strfreev (groups);
}
コード例 #17
0
ファイル: reader.c プロジェクト: T100012/NetworkManager
static void
read_one_setting_value (NMSetting *setting,
                        const char *key,
                        const GValue *value,
                        GParamFlags flags,
                        gpointer user_data)
{
	ReadInfo *info = user_data;
	const char *setting_name;
	GType type;
	GError *err = NULL;
	gboolean check_for_key = TRUE;
	KeyParser *parser = &key_parsers[0];

	/* Property is not writable */
	if (!(flags & G_PARAM_WRITABLE))
		return;

	/* Setting name gets picked up from the keyfile's section name instead */
	if (!strcmp (key, NM_SETTING_NAME))
		return;

	/* Don't read the NMSettingConnection object's 'read-only' property */
	if (   NM_IS_SETTING_CONNECTION (setting)
	    && !strcmp (key, NM_SETTING_CONNECTION_READ_ONLY))
		return;

	setting_name = nm_setting_get_name (setting);

	/* Look through the list of handlers for non-standard format key values */
	while (parser->setting_name) {
		if (!strcmp (parser->setting_name, setting_name) && !strcmp (parser->key, key)) {
			check_for_key = parser->check_for_key;
			break;
		}
		parser++;
	}

	/* VPN properties don't have the exact key name */
	if (NM_IS_SETTING_VPN (setting))
		check_for_key = FALSE;

	/* Check for the exact key in the GKeyFile if required.  Most setting
	 * properties map 1:1 to a key in the GKeyFile, but for those properties
	 * like IP addresses and routes where more than one value is actually
	 * encoded by the setting property, this won't be true.
	 */
	if (check_for_key && !g_key_file_has_key (info->keyfile, setting_name, key, &err)) {
		/* Key doesn't exist or an error ocurred, thus nothing to do. */
		if (err) {
			g_warning ("Error loading setting '%s' value: %s", setting_name, err->message);
			g_error_free (err);
		}
		return;
	}

	/* If there's a custom parser for this key, handle that before the generic
	 * parsers below.
	 */
	if (parser && parser->setting_name) {
		(*parser->parser) (setting, key, info->keyfile, info->keyfile_path);
		return;
	}

	type = G_VALUE_TYPE (value);

	if (type == G_TYPE_STRING) {
		char *str_val;

		str_val = g_key_file_get_string (info->keyfile, setting_name, key, NULL);
		g_object_set (setting, key, str_val, NULL);
		g_free (str_val);
	} else if (type == G_TYPE_UINT) {
		int int_val;

		int_val = g_key_file_get_integer (info->keyfile, setting_name, key, NULL);
		if (int_val < 0)
			g_warning ("Casting negative value (%i) to uint", int_val);
		g_object_set (setting, key, int_val, NULL);
	} else if (type == G_TYPE_INT) {
		int int_val;

		int_val = g_key_file_get_integer (info->keyfile, setting_name, key, NULL);
		g_object_set (setting, key, int_val, NULL);
	} else if (type == G_TYPE_BOOLEAN) {
		gboolean bool_val;

		bool_val = g_key_file_get_boolean (info->keyfile, setting_name, key, NULL);
		g_object_set (setting, key, bool_val, NULL);
	} else if (type == G_TYPE_CHAR) {
		int int_val;

		int_val = g_key_file_get_integer (info->keyfile, setting_name, key, NULL);
		if (int_val < G_MININT8 || int_val > G_MAXINT8)
			g_warning ("Casting value (%i) to char", int_val);

		g_object_set (setting, key, int_val, NULL);
	} else if (type == G_TYPE_UINT64) {
		char *tmp_str;
		guint64 uint_val;

		tmp_str = g_key_file_get_value (info->keyfile, setting_name, key, NULL);
		uint_val = g_ascii_strtoull (tmp_str, NULL, 10);
		g_free (tmp_str);
		g_object_set (setting, key, uint_val, NULL);
 	} else if (type == DBUS_TYPE_G_UCHAR_ARRAY) {
		gint *tmp;
		GByteArray *array;
		gsize length;
		int i;

		tmp = g_key_file_get_integer_list (info->keyfile, setting_name, key, &length, NULL);

		array = g_byte_array_sized_new (length);
		for (i = 0; i < length; i++) {
			int val = tmp[i];
			unsigned char v = (unsigned char) (val & 0xFF);

			if (val < 0 || val > 255) {
				g_warning ("%s: %s / %s ignoring invalid byte element '%d' (not "
				           " between 0 and 255 inclusive)", __func__, setting_name,
				           key, val);
			} else
				g_byte_array_append (array, (const unsigned char *) &v, sizeof (v));
		}

		g_object_set (setting, key, array, NULL);
		g_byte_array_free (array, TRUE);
		g_free (tmp);
 	} else if (type == DBUS_TYPE_G_LIST_OF_STRING) {
		gchar **sa;
		gsize length;
		int i;
		GSList *list = NULL;

		sa = g_key_file_get_string_list (info->keyfile, setting_name, key, &length, NULL);
		for (i = 0; i < length; i++)
			list = g_slist_prepend (list, sa[i]);

		list = g_slist_reverse (list);
		g_object_set (setting, key, list, NULL);

		g_slist_free (list);
		g_strfreev (sa);
	} else if (type == DBUS_TYPE_G_MAP_OF_STRING) {
		read_hash_of_string (info->keyfile, setting, key);
	} else if (type == DBUS_TYPE_G_UINT_ARRAY) {
		if (!read_array_of_uint (info->keyfile, setting, key)) {
			g_warning ("Unhandled setting property type (read): '%s/%s' : '%s'",
					 setting_name, key, G_VALUE_TYPE_NAME (value));
		}
	} else {
		g_warning ("Unhandled setting property type (read): '%s/%s' : '%s'",
				 setting_name, key, G_VALUE_TYPE_NAME (value));
	}
}
コード例 #18
0
ファイル: reader.c プロジェクト: T100012/NetworkManager
static GByteArray *
get_uchar_array (GKeyFile *keyfile,
                 const char *setting_name,
                 const char *key,
                 gboolean zero_terminate,
                 gboolean unescape_semicolon)
{
	GByteArray *array = NULL;
	char *tmp_string;
	gint *tmp_list;
	gsize length;
	int i;

	/* New format: just a string
	 * Old format: integer list; e.g. 11;25;38;
	 */
	tmp_string = g_key_file_get_string (keyfile, setting_name, key, NULL);
	if (tmp_string) {
		GRegex *regex;
		GMatchInfo *match_info;
		const char *pattern = "^[[:space:]]*[[:digit:]]{1,3}[[:space:]]*;([[:space:]]*[[:digit:]]{1,3}[[:space:]]*;)*([[:space:]]*)?$";

		regex = g_regex_new (pattern, 0, 0, NULL);
		g_regex_match (regex, tmp_string, 0, &match_info);
		if (!g_match_info_matches (match_info)) {
			/* Handle as a simple string (ie, new format) */
			if (unescape_semicolon)
				unescape_semicolons (tmp_string);
			length = strlen (tmp_string);
			if (zero_terminate)
				length++;
			array = g_byte_array_sized_new (length);
			g_byte_array_append (array, (guint8 *) tmp_string, length);
		}
		g_match_info_free (match_info);
		g_regex_unref (regex);
		g_free (tmp_string);
	}

	if (!array) {
		/* Old format; list of ints */
		tmp_list = g_key_file_get_integer_list (keyfile, setting_name, key, &length, NULL);
		array = g_byte_array_sized_new (length);
		for (i = 0; i < length; i++) {
			int val = tmp_list[i];
			unsigned char v = (unsigned char) (val & 0xFF);

			if (val < 0 || val > 255) {
				g_warning ("%s: %s / %s ignoring invalid byte element '%d' (not "
					       " between 0 and 255 inclusive)", __func__, setting_name,
					       key, val);
			} else
				g_byte_array_append (array, (const unsigned char *) &v, sizeof (v));
		}
		g_free (tmp_list);
	}

	if (array->len == 0) {
		g_byte_array_free (array, TRUE);
		array = NULL;
	}
	return array;
}
コード例 #19
0
/**************************************************
 * load
 *
 * load the settings from a state key file
 **************************************************/
bool
CsvTransSettings::load (void)
{
    if (trans_preset_is_reserved_name (m_name))
        return true;

    GError *key_error = nullptr;
    m_load_error = false;
    auto group = csv_group_prefix + m_name;
    auto keyfile = gnc_state_get_current ();

    m_skip_start_lines = g_key_file_get_integer (keyfile, group.c_str(), CSV_SKIP_START, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    m_skip_end_lines = g_key_file_get_integer (keyfile, group.c_str(), CSV_SKIP_END, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    m_skip_alt_lines = g_key_file_get_boolean (keyfile, group.c_str(), CSV_SKIP_ALT, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    m_multi_split = g_key_file_get_boolean (keyfile, group.c_str(), CSV_MULTI_SPLIT, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    auto csv_format = g_key_file_get_boolean (keyfile, group.c_str(), CSV_FORMAT, &key_error);
    if (key_error) csv_format = true; // default to true, but above command will return false in case of error
    m_load_error |= handle_load_error (&key_error, group);
    if (csv_format)
        m_file_format = GncImpFileFormat::CSV;
    else
        m_file_format = GncImpFileFormat::FIXED_WIDTH;

    gchar *key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_SEP, &key_error);
    if (key_char && *key_char != '\0')
        m_separators = key_char;
    m_load_error |= handle_load_error (&key_error, group);
    if (key_char)
        g_free (key_char);

    m_date_format = g_key_file_get_integer (keyfile, group.c_str(), CSV_DATE, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    m_currency_format = g_key_file_get_integer (keyfile, group.c_str(), CSV_CURRENCY, &key_error);
    m_load_error |= handle_load_error (&key_error, group);

    key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_ENCODING, &key_error);
    if (key_char && *key_char != '\0')
        m_encoding = key_char;
    else
        m_encoding = "UTF-8";
    m_load_error |= handle_load_error (&key_error, group);
    if (key_char)
        g_free (key_char);

    key_char = g_key_file_get_string (keyfile, group.c_str(), CSV_ACCOUNT, &key_error);
    if (key_char && *key_char != '\0')
        m_base_account = gnc_account_lookup_by_full_name (gnc_get_current_root_account(), key_char);
    m_load_error |= handle_load_error (&key_error, group);
    if (key_char)
        g_free (key_char);

    m_column_types.clear();
    gsize list_len;
    gchar** col_types_str = g_key_file_get_string_list (keyfile, group.c_str(), CSV_COL_TYPES,
            &list_len, &key_error);
    for (uint32_t i = 0; i < list_len; i++)
    {
        auto col_types_it = std::find_if (gnc_csv_col_type_strs.begin(),
                gnc_csv_col_type_strs.end(), test_prop_type_str (col_types_str[i]));
        if (col_types_it != gnc_csv_col_type_strs.end())
        {
            /* Found a valid column type. Now check whether it is allowed
             * in the selected mode (two-split vs multi-split) */
            auto prop = sanitize_trans_prop (col_types_it->first, m_multi_split);
                m_column_types.push_back(prop);
            if (prop != col_types_it->first)
                PWARN("Found column type '%s', but this is blacklisted when multi-split mode is %s. "
                        "Inserting column type 'NONE' instead'.",
                        col_types_it->second, m_multi_split ? "enabled" : "disabled");
        }
        else
            PWARN("Found invalid column type '%s'. Inserting column type 'NONE' instead'.",
                    col_types_str[i]);

    }
    if (col_types_str)
        g_strfreev (col_types_str);

    m_column_widths.clear();
    gint *col_widths_int = g_key_file_get_integer_list (keyfile, group.c_str(), CSV_COL_WIDTHS,
            &list_len, &key_error);
    for (uint32_t i = 0; i < list_len; i++)
    {
        if (col_widths_int[i] > 0)
            m_column_widths.push_back(col_widths_int[i]);
    }
    m_load_error |= handle_load_error (&key_error, group);
    if (col_widths_int)
        g_free (col_widths_int);

    return m_load_error;
}