CCMExtension * ccm_extension_new (gchar * filename) { g_return_val_if_fail (filename != NULL, NULL); CCMExtension *self = g_object_new (CCM_TYPE_EXTENSION, NULL); GKeyFile *plugin_file = g_key_file_new (); gint cpt; gchar *dirname = NULL; /* Load plugin configuration file */ if (!g_key_file_load_from_file (plugin_file, filename, G_KEY_FILE_NONE, NULL)) { g_warning ("Error on load %s", filename); g_object_unref (self); return NULL; } /* Get plugin name */ if ((self->priv->name = g_key_file_get_string (plugin_file, PLUGIN_SECTION, "Plugin", NULL)) == NULL) { g_warning ("Error on get plugin name in %s", filename); g_object_unref (self); return NULL; } for (cpt = 0; self->priv->name[cpt]; ++cpt) { if (self->priv->name[cpt] == '-') self->priv->name[cpt] = '_'; } g_type_module_set_name (G_TYPE_MODULE (self), self->priv->name); /* Get Label */ self->priv->label = g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION, "Name", NULL, NULL); /* Get description */ self->priv->description = g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION, "Description", NULL, NULL); /* Get version */ self->priv->version = g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION, "Version", NULL, NULL); /* Get backends */ self->priv->backends = g_key_file_get_string_list (plugin_file, PLUGIN_SECTION, "Backends", NULL, NULL); /* Get plugin depends */ self->priv->depends = g_key_file_get_string_list (plugin_file, PLUGIN_SECTION, "Depends", NULL, NULL); g_key_file_free (plugin_file); dirname = g_path_get_dirname (filename); self->priv->filename = g_module_build_path (dirname, G_TYPE_MODULE (self)->name); g_free (dirname); g_type_module_use (G_TYPE_MODULE (self)); return self; }
/*! mod_source \brief check if the source IP has already been seen in a prior connection Parameters required: function = hash; backup = /etc/honeybrid/source.tb \param[in] args, struct that contain the node and the data to process \param[in] user_data, not used * \param[out] set result to 0 if attacker ip is found in search table, 1 if not */ mod_result_t mod_source(struct mod_args *args) { printdbg("%s Module called\n", H(args->pkt->conn->id)); mod_result_t result = DEFER; int expiration = 24 * 3600; gchar *backup_file; char *key_src; gchar **info; GKeyFile *backup; GTimeVal t; g_get_current_time(&t); gint now = (t.tv_sec); /*! get the IP address from the packet */ key_src = g_malloc0(snprintf(NULL, 0, "%u", args->pkt->packet.ip->saddr) + 1); sprintf(key_src, "%u", args->pkt->packet.ip->saddr); printdbg("%s source IP is %s\n", H(args->pkt->conn->id), key_src); /*! get the backup file for this module */ if (NULL == (backup = (GKeyFile *) g_hash_table_lookup(args->node->config, "backup"))) { /*! We can't decide */ printdbg("%s mandatory argument 'backup' undefined!\n", H(args->pkt->conn->id)); return result; } /*! get the backup file path for this module */ if (NULL == (backup_file = (gchar *) g_hash_table_lookup(args->node->config, "backup_file"))) { /*! We can't decide */ printdbg("%s error, backup file path missing\n", H(args->pkt->conn->id)); return result; } printdbg("%s searching for this IP in the database...\n", H(args->pkt->conn->id)); if (NULL == (info = g_key_file_get_string_list(backup, "source", /* generic group name \todo: group by port number? */ key_src, NULL, NULL))) { /*! Unknown IP, so we accept the packet */ result = ACCEPT; printdbg("%s IP not found... packet accepted and new entry created\n", H(args->pkt->conn->id)); info = malloc(3 * sizeof(char *)); /*! 20 characters should be enough to hold even very large numbers */ info[0] = malloc(20 * sizeof(gchar)); info[1] = malloc(20 * sizeof(gchar)); info[2] = malloc(20 * sizeof(gchar)); g_snprintf(info[0], 20, "1"); /*! counter */ g_snprintf(info[1], 20, "%d", now); /*! first seen */ g_snprintf(info[2], 20, "0"); /*! duration */ } else { /*! We check if we need to expire this entry */ int age = atoi(info[2]); if (age > expiration) { /*! Known IP but entry expired, so we accept the packet */ result = ACCEPT; printdbg( "%s IP found but expired... packet accepted and entry renewed\n", H(args->pkt->conn->id)); g_snprintf(info[0], 20, "1"); /*! counter */ g_snprintf(info[1], 20, "%d", now); /*! first seen */ g_snprintf(info[2], 20, "0"); /*! duration */ } else { /*! Known IP, so we reject the packet */ result = REJECT; printdbg("%s IP found... packet rejected and entry updated\n", H(args->pkt->conn->id)); g_snprintf(info[0], 20, "%d", atoi(info[0]) + 1); /*! counter */ g_snprintf(info[2], 20, "%d", now - atoi(info[1])); /*! duration */ } } g_key_file_set_string_list(backup, "source", key_src, (const gchar * const *) info, 3); save_backup(backup, backup_file); /*! clean and exit */ free(key_src); return result; }
int main(int argc, char *argv[]) { gboolean print_version = FALSE; gboolean one_shot = FALSE; gchar *output_plugin = NULL; gchar **servers_desc = NULL; gchar **streams_desc = NULL; gchar **input_plugins = NULL; gchar **order = NULL; gchar *config = NULL; int retval = 0; GError *error = NULL; GOptionContext *option_context = NULL; GOptionGroup *option_group; #if DEBUG g_setenv("G_MESSAGES_DEBUG", "all", FALSE); #endif /* ! DEBUG */ setlocale(LC_ALL, ""); #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); #endif /* ENABLE_NLS */ #if DEBUG const gchar *debug_log_filename = g_getenv("J4STATUS_DEBUG_LOG_FILENAME"); GDataOutputStream *debug_stream = NULL; if ( debug_log_filename != NULL ) { GFile *debug_log; debug_log = g_file_new_for_path(debug_log_filename); GError *error = NULL; GFileOutputStream *debug_log_stream; debug_log_stream = g_file_append_to(debug_log, G_FILE_CREATE_NONE, NULL, &error); if ( debug_log_stream == NULL ) { g_warning("Couldn't open debug log file: %s", error->message); g_clear_error(&error); } else { debug_stream = g_data_output_stream_new(G_OUTPUT_STREAM(debug_log_stream)); g_object_unref(debug_log_stream); g_log_set_default_handler(_j4status_core_debug_log_handler, debug_stream); } g_object_unref(debug_log); } #endif /* DEBUG */ GOptionEntry entries[] = { { "output", 'o', 0, G_OPTION_ARG_STRING, &output_plugin, "Output plugin to use", "<plugin>" }, { "listen", 'l', 0, G_OPTION_ARG_STRING_ARRAY, &servers_desc, "Socket to listen on, will create a stream on connection (may be specified several times)", "<listen description>" }, { "stream", 't', 0, G_OPTION_ARG_STRING_ARRAY, &streams_desc, "Stream to read from/write to (may be specified several times)", "<stream description>" }, { "input", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &input_plugins, "Input plugins to use (may be specified several times)", "<plugin>" }, { "order", 'O', 0, G_OPTION_ARG_STRING_ARRAY, &order, "Order of sections, specified once a section (see man)", "<section id>" }, { "one-shot", '1', 0, G_OPTION_ARG_NONE, &one_shot, "Tells j4status to stop right after starting", NULL }, { "config", 'c', 0, G_OPTION_ARG_STRING, &config, "Config file to use", "<config>" }, { "version", 'V', 0, G_OPTION_ARG_NONE, &print_version, "Print version", NULL }, { NULL } }; option_context = g_option_context_new("- status line generator"); option_group = g_option_group_new(NULL, NULL, NULL, NULL, NULL); g_option_group_set_translation_domain(option_group, GETTEXT_PACKAGE); g_option_group_add_entries(option_group, entries); g_option_context_set_main_group(option_context, option_group); if ( ! g_option_context_parse(option_context, &argc, &argv, &error) ) { g_warning("Option parsing failed: %s\n", error->message); g_clear_error(&error); retval = 1; goto end; } g_option_context_free(option_context); if ( print_version ) { g_fprintf(stdout, PACKAGE_NAME " " PACKAGE_VERSION "\n"); goto end; } if ( config != NULL ) { g_setenv("J4STATUS_CONFIG_FILE", config, TRUE); g_free(config); } GKeyFile *key_file; key_file = j4status_config_get_key_file("Plugins"); if ( key_file != NULL ) { if ( output_plugin == NULL ) output_plugin = g_key_file_get_string(key_file, "Plugins", "Output", NULL); if ( input_plugins == NULL ) input_plugins = g_key_file_get_string_list(key_file, "Plugins", "Input", NULL, NULL); if ( order == NULL ) order = g_key_file_get_string_list(key_file, "Plugins", "Order", NULL, NULL); g_key_file_free(key_file); } J4statusCoreContext *context; context = g_new0(J4statusCoreContext, 1); J4statusCoreInterface interface = { .context = context, .add_section = _j4status_core_add_section, .remove_section = _j4status_core_remove_section, .trigger_generate = _j4status_core_trigger_generate, .trigger_action = _j4status_core_trigger_action, }; #ifdef G_OS_UNIX g_unix_signal_add(SIGTERM, _j4status_core_source_quit, context); g_unix_signal_add(SIGINT, _j4status_core_source_quit, context); g_unix_signal_add(SIGUSR1, _j4status_core_signal_usr1, context); g_unix_signal_add(SIGUSR2, _j4status_core_signal_usr2, context); /* Ignore SIGPIPE as it is useless */ signal(SIGPIPE, SIG_IGN); #endif /* G_OS_UNIX */ context->output_plugin = j4status_plugins_get_output_plugin(&interface, output_plugin); if ( context->output_plugin == NULL ) { g_warning("No usable output plugin, tried '%s'", output_plugin); retval = 10; goto end; } gchar *header = NULL; if ( context->output_plugin->interface.generate_header != NULL ) header = context->output_plugin->interface.generate_header(context->output_plugin->context); /* Creating input/output stream */ context->io = j4status_io_new(context, header, (const gchar * const *) servers_desc, (const gchar * const *) streams_desc); if ( context->io == NULL ) { g_warning("Couldn't create input/output streams"); retval = 2; goto end; } if ( order != NULL ) { context->order_weights = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); gchar **id; for ( id = order ; *id != NULL ; ++id ) g_hash_table_insert(context->order_weights, *id, GINT_TO_POINTER(1 + id - order)); g_free(order); } context->sections_hash = g_hash_table_new(g_str_hash, g_str_equal); context->input_plugins = j4status_plugins_get_input_plugins(&interface, input_plugins); if ( context->input_plugins == NULL ) { g_warning("No input plugins, will stop early"); one_shot = TRUE; retval = 11; } context->sections = g_list_reverse(context->sections); if ( context->order_weights != NULL ) context->sections = g_list_sort(context->sections, _j4status_core_compare_sections); _j4status_core_start(context); if ( one_shot ) g_idle_add(_j4status_core_source_quit, context); context->loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(context->loop); g_main_loop_unref(context->loop); context->loop = NULL; GList *input_plugin_; J4statusInputPlugin *input_plugin; for ( input_plugin_ = context->input_plugins ; input_plugin_ != NULL ; input_plugin_ = g_list_next(input_plugin_) ) { input_plugin = input_plugin_->data; input_plugin->interface.uninit(input_plugin->context); } if ( context->output_plugin->interface.uninit != NULL ) context->output_plugin->interface.uninit(context->output_plugin->context); j4status_io_free(context->io); if ( context->order_weights != NULL ) g_hash_table_unref(context->order_weights); g_hash_table_unref(context->sections_hash); end: #if DEBUG if ( debug_stream != NULL ) g_object_unref(debug_stream); #endif /* DEBUG */ return retval; }
static bool irmpc_options_from_file () { GError *error = NULL; GKeyFile *key_file = g_key_file_new (); if (!g_key_file_load_from_file (key_file, irmpc_options.config_file, G_KEY_FILE_NONE, &error)) { fprintf (stderr, "Error parsing config file: %s\n", error->message); g_error_free (error); return false; } /* try finding options */ for (struct option_file_data *entry = &(cfg_file_entries[0]); entry->group_name != NULL; entry++) { g_clear_error (&error); if (entry->arg == G_OPTION_ARG_INT) { gint tempint; tempint = g_key_file_get_integer (key_file, entry->group_name, entry->key_name, &error); if (error == NULL) { int *targetint = (int *) entry->arg_data; *targetint = tempint; } else { if ((error->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND) && (error->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { g_key_file_free (key_file); fprintf (stderr, "Error parsing config file %s: %s\n", irmpc_options.config_file, error->message); g_error_free (error); return false; } } } else if ((entry->arg == G_OPTION_ARG_STRING) || (entry->arg == G_OPTION_ARG_FILENAME)) { gchar *tempstr; tempstr = g_key_file_get_string (key_file, entry->group_name, entry->key_name, &error); if (irmpc_options.debug) { printf ("INFO: parsed string %s for option %s\n", tempstr, entry->key_name); } if (tempstr != NULL) { gchar **targetstr = (gchar **) entry->arg_data; *targetstr = tempstr; } } } /* playlists */ gchar **tempstrlist; gsize listlen; tempstrlist = g_key_file_get_keys (key_file, "playlists", &listlen, &error); if (tempstrlist != NULL) { for (int i = 0; i < listlen; i++) { g_clear_error (&error); char *number_str = tempstrlist[i]; char *endptr; long int number = strtol (number_str, &endptr, 10); if ((*number_str == '\0') || (*endptr != '\0') || (number < 0)) continue; gsize entrylen; gchar **entrylist = g_key_file_get_string_list (key_file, "playlists", number_str, &entrylen, &error); if (entrylist == NULL) continue; if (entrylen > 0) { char *entryname = entrylist[0]; bool entryrand = false; if (entrylen > 1) { if (strcmp (entrylist[1], "r") == 0) { entryrand = true; } } irmpc_playlist_add (number, entryname, entryrand); } g_strfreev (entrylist); } g_strfreev (tempstrlist); } /* free */ g_key_file_free (key_file); if (error != NULL) { g_error_free (error); } return true; }
/** * conboy_plugin_info_new: * @filename: the filename where to read the plugin information * * Creates a new #ConboyPluginInfo from a file on the disk. * * Return value: a newly created #ConboyPluginInfo. */ ConboyPluginInfo * conboy_plugin_info_new (const gchar *file) { ConboyPluginInfo *info; GKeyFile *plugin_file = NULL; gchar *str; g_return_val_if_fail (file != NULL, NULL); g_printerr("INFO: Loading plugin description: %s\n", file); info = g_object_new(CONBOY_TYPE_PLUGIN_INFO, NULL); 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); return NULL; } /* Get module name */ str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, PLUGIN_MODULE, NULL); if ((str != NULL) && (*str != '\0')) { info->module_name = str; } else { g_warning ("ERROR: Could not find '%s' in %s", PLUGIN_MODULE, file); return NULL; } /* Get Name */ str = g_key_file_get_locale_string (plugin_file, PLUGIN_GROUP, PLUGIN_NAME, NULL, NULL); if (str) { info->name = str; } else { g_warning ("ERROR: Could not find 'Name' in %s", file); return NULL; } /* Get Kind */ str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, PLUGIN_KIND, NULL); if (str) { info->kind = str; } else { g_printerr("ERROR: Could not find '%s' in %s\n", PLUGIN_KIND, file); return NULL; } /* Get Description */ str = g_key_file_get_locale_string (plugin_file, PLUGIN_GROUP, PLUGIN_DESCRIPTION, NULL, NULL); if (str) { info->desc = str; } else { g_printerr("Could not find '%s' in %s\n", PLUGIN_DESCRIPTION, file); } /* Get Authors */ info->authors = g_key_file_get_string_list (plugin_file, PLUGIN_GROUP, PLUGIN_AUTHORS, NULL, NULL); if (info->authors == NULL) { g_printerr("Could not find '%s' in %s\n", PLUGIN_AUTHORS, file); } /* Get Copyright */ str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, PLUGIN_COPYRIGHT, NULL); if (str) { info->copyright = str; } else { g_printerr("Could not find '%s' in %s\n", PLUGIN_COPYRIGHT, file); } /* Get Version */ str = g_key_file_get_string (plugin_file, PLUGIN_GROUP, PLUGIN_VERSION, NULL); if (str) { info->version = str; } else { g_printerr("Could not find '%s' in %s\n", PLUGIN_VERSION, file); } g_key_file_free (plugin_file); info->available = TRUE; return info; }
static EomPluginInfo * eom_plugin_engine_load (const gchar *file) { EomPluginInfo *info; GKeyFile *plugin_file = NULL; gchar *str; g_return_val_if_fail (file != NULL, NULL); eom_debug_message (DEBUG_PLUGINS, "Loading plugin: %s", file); info = g_new0 (EomPluginInfo, 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, "Eom Plugin", "IAge", NULL)) { eom_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, "Eom Plugin", "IAge", NULL) != 2) { eom_debug_message (DEBUG_PLUGINS, "Wrong IAge in file: %s", file); goto error; } /* Get Location */ str = g_key_file_get_string (plugin_file, "Eom Plugin", "Module", NULL); if ((str != NULL) && (*str != '\0')) { info->location = str; } else { g_warning ("Could not find 'Module' in %s", file); goto error; } /* Get the loader for this plugin */ str = g_key_file_get_string (plugin_file, "Eom Plugin", "Loader", NULL); if (str && strcmp(str, "python") == 0) { info->loader = EOM_PLUGIN_LOADER_PY; #ifndef ENABLE_PYTHON g_warning ("Cannot load Python plugin '%s' since eom was not " "compiled with Python support.", file); goto error; #endif } else { info->loader = EOM_PLUGIN_LOADER_C; } g_free (str); /* Get Name */ str = g_key_file_get_locale_string (plugin_file, "Eom Plugin", "Name", NULL, NULL); if (str) { info->name = str; } else { g_warning ("Could not find 'Name' in %s", file); goto error; } /* Get Description */ str = g_key_file_get_locale_string (plugin_file, "Eom Plugin", "Description", NULL, NULL); if (str) { info->desc = str; } else { eom_debug_message (DEBUG_PLUGINS, "Could not find 'Description' in %s", file); } /* Get Icon */ str = g_key_file_get_locale_string (plugin_file, "Eom Plugin", "Icon", NULL, NULL); if (str) { info->icon_name = str; } else { eom_debug_message (DEBUG_PLUGINS, "Could not find 'Icon' in %s, " "using 'eom-plugin'", file); } /* Get Authors */ info->authors = g_key_file_get_string_list (plugin_file, "Eom Plugin", "Authors", NULL, NULL); if (info->authors == NULL) eom_debug_message (DEBUG_PLUGINS, "Could not find 'Authors' in %s", file); /* Get Copyright */ str = g_key_file_get_string (plugin_file, "Eom Plugin", "Copyright", NULL); if (str) { info->copyright = str; } else { eom_debug_message (DEBUG_PLUGINS, "Could not find 'Copyright' in %s", file); } /* Get Website */ str = g_key_file_get_string (plugin_file, "Eom Plugin", "Website", NULL); if (str) { info->website = str; } else { eom_debug_message (DEBUG_PLUGINS, "Could not find 'Website' in %s", file); } g_key_file_free (plugin_file); /* If we know nothing about the availability of the plugin, set it as available */ info->available = TRUE; return info; error: g_free (info->file); g_free (info->location); g_free (info->name); g_free (info); g_key_file_free (plugin_file); return NULL; }
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)); } }
bool sydbox_config_load(const gchar * const file, const gchar * const profile) { gchar *config_file; GKeyFile *config_fd; GError *config_error = NULL; g_return_val_if_fail(!config, true); // Initialize config structure config = g_new0(struct sydbox_config, 1); if (g_getenv(ENV_NO_CONFIG)) { /* ENV_NO_CONFIG set, set the defaults, * and return without parsing the configuration file. */ sydbox_config_set_defaults(); return true; } // Figure out the path to the configuration file if (file) config_file = g_strdup(file); else if (profile) config_file = g_strdup_printf(DATADIR G_DIR_SEPARATOR_S "sydbox" G_DIR_SEPARATOR_S "%s.conf", profile); else if (g_getenv(ENV_CONFIG)) config_file = g_strdup(g_getenv(ENV_CONFIG)); else config_file = g_strdup(SYSCONFDIR G_DIR_SEPARATOR_S "sydbox.conf"); // Initialize key file config_fd = g_key_file_new(); if (!g_key_file_load_from_file(config_fd, config_file, G_KEY_FILE_NONE, &config_error)) { switch (config_error->code) { case G_FILE_ERROR_NOENT: /* Configuration file not found! * Set the defaults and return true. */ g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); sydbox_config_set_defaults(); return true; default: g_printerr("failed to parse config file: %s\n", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; } } // Get main.colour config->colourise_output = g_key_file_get_boolean(config_fd, "main", "colour", &config_error); if (!config->colourise_output) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("main.colour not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->colourise_output = true; break; default: g_assert_not_reached(); break; } } // Get main.lock config->disallow_magic_commands = g_key_file_get_boolean(config_fd, "main", "lock", &config_error); if (!config->disallow_magic_commands && config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("main.lock not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->disallow_magic_commands = false; break; default: g_assert_not_reached(); break; } } // Get main.wait_all config->wait_all = g_key_file_get_boolean(config_fd, "main", "wait_all", &config_error); if (!config->wait_all && config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("main.wait_all not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->wait_all = true; break; default: g_assert_not_reached(); break; } } // Get main.allow_proc_pid config->allow_proc_pid = g_key_file_get_boolean(config_fd, "main", "allow_proc_pid", &config_error); if (!config->allow_proc_pid && config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("main.allow_proc_pid not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->allow_proc_pid = true; break; default: g_assert_not_reached(); break; } } config->wrap_lstat = g_key_file_get_boolean(config_fd, "main", "wrap_lstat", &config_error); if (!config->wrap_lstat && config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("main.wrap_lstat not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->wrap_lstat = true; break; default: g_assert_not_reached(); break; } } // Get main.filters char **filterlist = g_key_file_get_string_list(config_fd, "main", "filters", NULL, NULL); if (NULL != filterlist) { for (unsigned int i = 0; NULL != filterlist[i]; i++) sydbox_config_addfilter(filterlist[i]); g_strfreev(filterlist); } // Get log.file config->logfile = g_key_file_get_string(config_fd, "log", "file", NULL); // Get log.level config->verbosity = g_key_file_get_integer(config_fd, "log", "level", &config_error); if (config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("log.level not an integer: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->verbosity = 1; break; default: g_assert_not_reached(); break; } } // Get sandbox.path config->sandbox_path = g_key_file_get_boolean(config_fd, "sandbox", "path", &config_error); if (config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("sandbox.path not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->sandbox_path = true; break; default: g_assert_not_reached(); break; } } // Get sandbox.exec config->sandbox_exec = g_key_file_get_boolean(config_fd, "sandbox", "exec", &config_error); if (config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("sandbox.exec not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->sandbox_exec = false; break; default: g_assert_not_reached(); break; } } // Get sandbox.network config->sandbox_network = g_key_file_get_boolean(config_fd, "sandbox", "network", &config_error); if (config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("main.network not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->sandbox_network = false; break; default: g_assert_not_reached(); break; } } // Get prefix.write char **write_prefixes = g_key_file_get_string_list(config_fd, "prefix", "write", NULL, NULL); if (NULL != write_prefixes) { for (unsigned int i = 0; NULL != write_prefixes[i]; i++) pathnode_new_early(&config->write_prefixes, write_prefixes[i], 1); g_strfreev(write_prefixes); } // Get prefix.exec char **exec_prefixes = g_key_file_get_string_list(config_fd, "prefix", "exec", NULL, NULL); if (NULL != exec_prefixes) { for (unsigned int i = 0; NULL != exec_prefixes[i]; i++) pathnode_new_early(&config->exec_prefixes, exec_prefixes[i], 1); g_strfreev(exec_prefixes); } // Get net.default gchar *netdefault = g_key_file_get_string(config_fd, "net", "default", NULL); if (NULL != netdefault) { if (0 == strncmp(netdefault, "allow", 6)) config->network_mode = SYDBOX_NETWORK_ALLOW; else if (0 == strncmp(netdefault, "deny", 5)) config->network_mode = SYDBOX_NETWORK_DENY; else if (0 == strncmp(netdefault, "local", 6)) config->network_mode = SYDBOX_NETWORK_LOCAL; else { g_printerr("error: invalid value for net.default `%s'\n", netdefault); g_free(netdefault); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; } g_free(netdefault); } // Get net.restrict_connect config->network_restrict_connect = g_key_file_get_boolean(config_fd, "net", "restrict_connect", &config_error); if (config_error) { switch (config_error->code) { case G_KEY_FILE_ERROR_INVALID_VALUE: g_printerr("net.restrict_connect not a boolean: %s", config_error->message); g_error_free(config_error); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; case G_KEY_FILE_ERROR_GROUP_NOT_FOUND: case G_KEY_FILE_ERROR_KEY_NOT_FOUND: g_error_free(config_error); config_error = NULL; config->network_restrict_connect = false; break; default: g_assert_not_reached(); break; } } // Get net.whitelist char **netwhitelist = g_key_file_get_string_list(config_fd, "net", "whitelist", NULL, NULL); if (NULL != netwhitelist) { for (unsigned int i = 0; NULL != netwhitelist[i]; i++) { if (0 > netlist_new_from_string(&config->network_whitelist, netwhitelist[i], false)) { g_printerr("error: malformed address `%s' at position %d of net.whitelist\n", netwhitelist[i], i); g_strfreev(netwhitelist); g_key_file_free(config_fd); g_free(config_file); g_free(config); return false; } } g_strfreev(netwhitelist); } // Cleanup and return g_key_file_free(config_fd); g_free(config_file); return true; }
/* Get list of storage nodes admind host/ports from /etc/4store.conf, default to localhost */ fsa_node_addr *fsa_get_node_list(GKeyFile *config_file) { fsa_node_addr *first_na = NULL; fsa_node_addr *na = NULL; int default_port = fsa_get_admind_port(config_file); gsize len; GError *err = NULL; gchar **nodes = g_key_file_get_string_list(config_file, "4s-boss", "nodes", &len, &err); if (nodes == NULL) { g_error_free(err); first_na = fsa_node_addr_new("localhost"); first_na->port = default_port; return first_na; } gchar *cur; char *tok; /* build list in reverse order to keep string order from conf */ for (int i = len-1; i >= 0; i--) { cur = nodes[i]; if (cur[0] == '[') { int cur_len = strlen(cur); int start = 1; int end = 1; while (cur[end] != ']' && end < cur_len) { end += 1; } char *v6addr = (char *)malloc(end - start + 1); strncpy(v6addr, &cur[start], end - start); v6addr[end - start] = '\0'; na = fsa_node_addr_new(v6addr); free(v6addr); end += 1; if (end >= cur_len || cur[end] != ':') { na->port = default_port; } else { na->port = atoi(&cur[end+1]); } } else { /* treat as v4 addr or hostname */ tok = strtok(cur, ":"); na = fsa_node_addr_new(tok); tok = strtok(NULL, ":"); if (tok != NULL) { na->port = atoi(tok); } else { na->port = default_port; } } na->next = first_na; first_na = na; } g_strfreev(nodes); return first_na; }
static gboolean key_file_get_show_in (GKeyFile *key_file) { const gchar *current_desktop; gchar **strv; gboolean show_in = TRUE; int i; gchar *exec; current_desktop = get_current_desktop (); if (!current_desktop) return TRUE; exec = g_key_file_get_string (key_file, DESKTOP_ENTRY_GROUP, "Exec", NULL); if (exec) { if (g_str_has_prefix (exec, "gnome-control-center")) { g_free (exec); return FALSE; } g_free (exec); } strv = g_key_file_get_string_list (key_file, DESKTOP_ENTRY_GROUP, "OnlyShowIn", NULL, NULL); if (strv) { show_in = FALSE; for (i = 0; strv[i]; i++) { if (!strcmp (strv[i], "GNOME") || !strcmp (strv[i], "X-Cinnamon")) { show_in = TRUE; break; } } } else { strv = g_key_file_get_string_list (key_file, DESKTOP_ENTRY_GROUP, "NotShowIn", NULL, NULL); if (strv) { show_in = TRUE; for (i = 0; strv[i]; i++) { if (!strcmp (strv[i], current_desktop)) { show_in = FALSE; } } } } g_strfreev (strv); return show_in; }
/** * as_app_parse_file_key: **/ static gboolean as_app_parse_file_key (AsApp *app, GKeyFile *kf, const gchar *key, 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, -1); 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, -1); 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], -1); } } 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], -1); } } } 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], -1); } } } 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], -1); } 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, -1); /* 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], -1); /* 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, -1); /* 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, -1); /* 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, -1); /* 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, -1); /* 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, -1); } 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, -1); } return TRUE; }
static gboolean migrate_keyfile_to_settings (TrackerConfigMigrationEntry *entries, TrackerConfigFile *file, GSettings *settings) { gint i; for (i = 0; entries[i].type != G_TYPE_INVALID; i++) { if (!g_key_file_has_key (file->key_file, entries[i].file_section, entries[i].file_key, NULL)) { g_settings_reset (settings, entries[i].settings_key); continue; } switch (entries[i].type) { case G_TYPE_INT: case G_TYPE_ENUM: { gint val; val = g_key_file_get_integer (file->key_file, entries[i].file_section, entries[i].file_key, NULL); if (entries[i].type == G_TYPE_INT) { g_settings_set_int (settings, entries[i].settings_key, val); } else { g_settings_set_enum (settings, entries[i].settings_key, val); } break; } case G_TYPE_BOOLEAN: { gboolean val; val = g_key_file_get_boolean (file->key_file, entries[i].file_section, entries[i].file_key, NULL); g_settings_set_boolean (settings, entries[i].settings_key, val); break; } case G_TYPE_POINTER: { gchar **vals; vals = g_key_file_get_string_list (file->key_file, entries[i].file_section, entries[i].file_key, NULL, NULL); if (vals) { g_settings_set_strv (settings, entries[i].settings_key, (const gchar * const *) vals); g_strfreev (vals); } break; } default: g_assert_not_reached (); break; } } return TRUE; }
/************************************************** * 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; }
static void environment_override() { const gchar *path; gchar *env_file; GKeyFile *keyfile=g_key_file_new(); GError *error; gchar **env_vars; gsize param_count; gint i; gboolean got_keyfile; if ((path = g_getenv("GNC_CONFIG_PATH"))) config_path = g_strdup(path); if ((path = g_getenv("GNC_SHARE_PATH"))) share_path = g_strdup(path); if ((path = g_getenv("GNC_DOC_PATH"))) help_path = g_strdup(path); if ((path = g_getenv("GNC_GCONF_PATH"))) gconf_path = g_strdup(path); #ifdef G_OS_WIN32 { /* unhide files without extension */ gchar *pathext = g_build_path(";", ".", g_getenv("PATHEXT"), (gchar*) NULL); g_setenv("PATHEXT", pathext, TRUE); g_free(pathext); } #endif env_file = g_strjoin(G_DIR_SEPARATOR_S, config_path, "environment", NULL); got_keyfile = g_key_file_load_from_file (keyfile, env_file, G_KEY_FILE_NONE, &error); g_free (env_file); if ( !got_keyfile ) return; /* Read the environment overrides and apply them */ env_vars = g_key_file_get_keys(keyfile, "Variables", ¶m_count, &error); for ( i = 0; i < param_count; i++ ) { gchar **val_list; gsize val_count; gint j; gchar *new_val = NULL, *tmp_val; /* For each variable, read its new value, optionally expand it and (un)set it */ val_list = g_key_file_get_string_list (keyfile, "Variables", env_vars[i], &val_count, &error ); if (!val_list) g_unsetenv (env_vars[i]); else { /* Set an initial return value, so we can always use g_build_path below) */ tmp_val = g_strdup ("x"); for ( j = 0; j < val_count; j++ ) { gchar *expanded = environment_expand (val_list[j]); new_val = g_build_path (G_SEARCHPATH_SEPARATOR_S, tmp_val, expanded, NULL); g_free (tmp_val); tmp_val = new_val; } g_strfreev (val_list); /* Remove the "x" from our result */ if (g_strcmp0 (tmp_val, "x")) new_val = g_strdup (tmp_val + sizeof (G_SEARCHPATH_SEPARATOR_S)); g_free (tmp_val); if (!g_setenv (env_vars[i], new_val, TRUE)) g_warning ("Couldn't properly override environment variable \"%s\". " "This may lead to unexpected results", env_vars[i]); } } g_strfreev(env_vars); }
static gboolean ril_get_net_config(struct radio_data *rsd) { GKeyFile *keyfile; GError *err = NULL; char *config_path = RIL_CONFIG_DIR; char **alreadyset = NULL; gboolean needsconfig = FALSE; gboolean value = FALSE; gboolean found = FALSE; rsd->ratmode = PREF_NET_TYPE_GSM_WCDMA_AUTO; GDir *config_dir; const gchar *config_file; gsize length; gchar **codes = NULL; int i; /* * First we need to check should the LTE be on * or not */ keyfile = g_key_file_new(); g_key_file_set_list_separator(keyfile, ','); config_dir = g_dir_open(config_path, 0, NULL); while ((config_file = g_dir_read_name(config_dir)) != NULL) { char *path = g_strconcat(RIL_CONFIG_DIR "/", config_file, NULL); DBG("Rilconfig handling %s", path); gboolean ok = g_key_file_load_from_file(keyfile, path, 0, &err); g_free(path); if (!ok) { g_error_free(err); DBG("Rilconfig file skipped"); continue; } if (g_key_file_has_group(keyfile, LTE_FLAG)) found = TRUE; else if (g_key_file_has_group(keyfile, MCC_LIST)) { codes = g_key_file_get_string_list(keyfile, MCC_LIST, MCC_KEY, &length, NULL); if (codes) { for (i = 0; codes[i]; i++) { if (g_str_equal(codes[i], ofono_sim_get_mcc(get_sim())) == TRUE) { found = TRUE; break; } } g_strfreev(codes); } } if (found) { rsd->ratmode = PREF_NET_TYPE_LTE_GSM_WCDMA; break; } } g_key_file_free(keyfile); g_dir_close(config_dir); /* Then we need to check if it already set */ keyfile = storage_open(NULL, RIL_STORE); alreadyset = g_key_file_get_groups(keyfile, NULL); if (alreadyset[0]) value = g_key_file_get_boolean( keyfile, alreadyset[0], LTE_FLAG, NULL); else if (rsd->ratmode == PREF_NET_TYPE_GSM_WCDMA_AUTO) value = TRUE; if (!value && rsd->ratmode == PREF_NET_TYPE_LTE_GSM_WCDMA) { g_key_file_set_boolean(keyfile, LTE_FLAG, LTE_FLAG, TRUE); needsconfig = TRUE; } else if (value && rsd->ratmode == PREF_NET_TYPE_GSM_WCDMA_AUTO) { g_key_file_set_boolean(keyfile, LTE_FLAG, LTE_FLAG, FALSE); needsconfig = TRUE; } g_strfreev(alreadyset); storage_close(NULL, RIL_STORE, keyfile, TRUE); return needsconfig; }
int chassis_keyfile_to_options(GKeyFile *keyfile, const gchar *ini_group_name, GOptionEntry *config_entries) { GError *gerr = NULL; int ret = 0; int i, j; /* all the options are in the group for "mysql-proxy" */ if (!keyfile) return -1; if (!g_key_file_has_group(keyfile, ini_group_name)) return 0; /* set the defaults */ for (i = 0; config_entries[i].long_name; i++) { GOptionEntry *entry = &(config_entries[i]); gchar *arg_string; gchar **arg_string_array; gboolean arg_bool = 0; gint arg_int = 0; gdouble arg_double = 0; gsize len = 0; switch (entry->arg) { case G_OPTION_ARG_FILENAME: case G_OPTION_ARG_STRING: /* is this option set already */ if (NULL == entry->arg_data || NULL != *(gchar **)(entry->arg_data)) break; arg_string = g_key_file_get_string(keyfile, ini_group_name, entry->long_name, &gerr); if (!gerr) { /* strip trailing spaces */ *(gchar **)(entry->arg_data) = g_strchomp(arg_string); } break; case G_OPTION_ARG_FILENAME_ARRAY: case G_OPTION_ARG_STRING_ARRAY: /* is this option set already */ if (NULL == entry->arg_data || NULL != *(gchar ***)(entry->arg_data)) break; arg_string_array = g_key_file_get_string_list(keyfile, ini_group_name, entry->long_name, &len, &gerr); if (!gerr) { for (j = 0; arg_string_array[j]; j++) { arg_string_array[j] = g_strstrip(arg_string_array[j]); } *(gchar ***)(entry->arg_data) = arg_string_array; } break; case G_OPTION_ARG_NONE: arg_bool = g_key_file_get_boolean(keyfile, ini_group_name, entry->long_name, &gerr); if (!gerr) { *(int *)(entry->arg_data) = arg_bool; } break; case G_OPTION_ARG_INT: arg_int = g_key_file_get_integer(keyfile, ini_group_name, entry->long_name, &gerr); if (!gerr) { *(gint *)(entry->arg_data) = arg_int; } break; #if GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 12 case G_OPTION_ARG_DOUBLE: arg_double = g_key_file_get_double(keyfile, ini_group_name, entry->long_name, &gerr); if (!gerr) { *(gdouble *)(entry->arg_data) = arg_double; } break; #endif default: g_log_dbproxy(g_error, "(keyfile) the option %d can't be handled", entry->arg); break; } if (gerr) { if (gerr->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND) { g_log_dbproxy(g_critical, "%s", gerr->message); ret = -1; } g_error_free(gerr); gerr = NULL; } } return ret; }
/** * 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; }
/** * parse_encoding_profile: * @in: a #GKeyFile * @parentprofilename: the parent profile name (including 'profile-' or 'streamprofile-' header) * @profilename: the profile name group to parse * @nbgroups: the number of top-level groups * @groups: the top-level groups */ static GstEncodingProfile * parse_encoding_profile (GKeyFile * in, gchar * parentprofilename, gchar * profilename, gsize nbgroups, gchar ** groups) { GstEncodingProfile *sprof = NULL; gchar **parent; gchar *proftype, *format, *preset, *restriction, *pname, *description, *locale; GstCaps *formatcaps = NULL; GstCaps *restrictioncaps = NULL; gboolean variableframerate; gint pass, presence; gsize i, nbencprofiles; GST_DEBUG ("parentprofilename : %s , profilename : %s", parentprofilename, profilename); if (parentprofilename) { gboolean found = FALSE; parent = g_key_file_get_string_list (in, profilename, "parent", &nbencprofiles, NULL); if (!parent || !nbencprofiles) { return NULL; } /* Check if this streamprofile is used in <profilename> */ for (i = 0; i < nbencprofiles; i++) { if (!g_strcmp0 (parent[i], parentprofilename)) { found = TRUE; break; } } g_strfreev (parent); if (!found) { GST_DEBUG ("Stream profile '%s' isn't used in profile '%s'", profilename, parentprofilename); return NULL; } } pname = g_key_file_get_value (in, profilename, "name", NULL); locale = get_locale (); /* will try to fall back to untranslated string if no translation found */ description = g_key_file_get_locale_string (in, profilename, "description", locale, NULL); g_free (locale); /* Note: a missing description is normal for non-container profiles */ if (description == NULL) { GST_LOG ("Missing 'description' field for streamprofile %s", profilename); } /* Parse the remaining fields */ proftype = g_key_file_get_value (in, profilename, "type", NULL); if (!proftype) { GST_WARNING ("Missing 'type' field for streamprofile %s", profilename); return NULL; } format = g_key_file_get_value (in, profilename, "format", NULL); if (format) { formatcaps = gst_caps_from_string (format); g_free (format); } preset = g_key_file_get_value (in, profilename, "preset", NULL); restriction = g_key_file_get_value (in, profilename, "restriction", NULL); if (restriction) { restrictioncaps = gst_caps_from_string (restriction); g_free (restriction); } presence = g_key_file_get_integer (in, profilename, "presence", NULL); pass = g_key_file_get_integer (in, profilename, "pass", NULL); variableframerate = g_key_file_get_boolean (in, profilename, "variableframerate", NULL); /* Build the streamprofile ! */ if (!g_strcmp0 (proftype, "container")) { GstEncodingProfile *pprof; sprof = (GstEncodingProfile *) gst_encoding_container_profile_new (pname, description, formatcaps, preset); /* Now look for the stream profiles */ for (i = 0; i < nbgroups; i++) { if (!g_ascii_strncasecmp (groups[i], "streamprofile-", 13)) { pprof = parse_encoding_profile (in, pname, groups[i], nbgroups, groups); if (pprof) { gst_encoding_container_profile_add_profile ( (GstEncodingContainerProfile *) sprof, pprof); } } } } else if (!g_strcmp0 (proftype, "video")) { sprof = (GstEncodingProfile *) gst_encoding_video_profile_new (formatcaps, preset, restrictioncaps, presence); gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *) sprof, variableframerate); gst_encoding_video_profile_set_pass ((GstEncodingVideoProfile *) sprof, pass); gst_encoding_profile_set_name (sprof, pname); gst_encoding_profile_set_description (sprof, description); } else if (!g_strcmp0 (proftype, "audio")) { sprof = (GstEncodingProfile *) gst_encoding_audio_profile_new (formatcaps, preset, restrictioncaps, presence); gst_encoding_profile_set_name (sprof, pname); gst_encoding_profile_set_description (sprof, description); } else GST_ERROR ("Unknown profile format '%s'", proftype); if (restrictioncaps) gst_caps_unref (restrictioncaps); if (formatcaps) gst_caps_unref (formatcaps); g_free (pname); g_free (description); g_free (preset); g_free (proftype); return sprof; }
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 = g_key_file_get_string(accounts, name, "muc.service", NULL); 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_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; } }
int main(int argc, char * argv[]) { ///g_warning("Sample warning"); ///g_message("Loading *.desktop files"); // pointer array for storing menu items GPtrArray *items = g_ptr_array_new (); // read all files from applications directory gchar *path = g_strdup("/usr/share/applications"); GDir *d = g_dir_open(path,0,NULL); const gchar *n; while ( (n = g_dir_read_name(d)) ) { // get filename from dir content gchar *fn = g_build_filename(path,n,NULL); //printf("--> fn=%s\n",fn); // is it .desktop file if (!g_str_has_suffix(fn,".desktop")) continue; // load .desktop file GKeyFile *kf = g_key_file_new(); gboolean b = g_key_file_load_from_file(kf, fn, G_KEY_FILE_NONE, NULL); if (!b) { fprintf(stderr, "error: cannot load .desktop file %s\n", fn); g_key_file_free(kf); continue; } g_assert(b); // load categories gsize length = 0; char **cats = g_key_file_get_string_list(kf,"Desktop Entry","Categories",&length,NULL); gchar *name = g_key_file_get_value(kf,"Desktop Entry","Name",NULL); gchar *exec = g_key_file_get_value(kf,"Desktop Entry","Exec",NULL); fix(exec); gchar *icon = g_key_file_get_value(kf,"Desktop Entry","Icon",NULL); gchar *type = g_key_file_get_value(kf,"Desktop Entry","Type",NULL); gboolean no_display = g_key_file_get_boolean(kf,"Desktop Entry","NoDisplay",NULL); // sort it to categories in application menu // determine best matching category ItemCategory c = icOther; for (guint i=0; i<length; i++) { //printf(" Category[%d]: %s\n",i,cats[i]); if (strstr("DesktopSettings, HardwareSettings, Monitor, PackageManager, Settings, System, X-GNOME-NetworkSettings, X-GNOME-PersonalSettings, X-LXDE-Settings, X-SuSE-ControlCenter-System, X-XFCE",cats[i])) c = icSettings; if (strstr("ArcadeGame, BlocksGame, BoardGame, CardGame, Game, LogicGame",cats[i])) c = icGames; if (strstr("Archiving, Compression, Core, DiscBurning, Documentation, FileManager, TerminalEmulator, Utility",cats[i])) c = icUtility; if (strstr("Astronomy, Dictionary, Education, Math, Science, Translation",cats[i])) c = icScienceEducation; if (strstr("Audio, AudioVideo, AudioVideoEditing, Mixer, Player, Recorder, Video",cats[i])) c = icAudioVideo; if (strstr("Calculator, Calendar, ContactManagement, Office, Presentation, Printing, TextEditor, Spreadsheet, WordProcessor",cats[i])) c = icOffice; if (strstr("Development, Emulator, Engineering, GTK, GUIDesigner, IDE, Qt",cats[i])) c = icDevelopment; if (strstr("Email, FileTransfer, Chat, InstantMessaging, Internet, IRCClient, Network, P2P, RemoteAccess, Security, WebBrowser",cats[i])) c = icInternet; if (strstr("Graphics, Photography, RasterGraphics, Scanning, VectorGraphics, Viewer, 2DGraphics, 3DGraphics",cats[i])) c = icGraphics; } // add items to array if ((!no_display)&&(name)&&(exec)&&(icon)) g_ptr_array_add (items, item_new(c, name, exec, icon)); // free temp vars g_strfreev(cats); g_free(name); g_free(exec); g_free(icon); g_free(type); g_key_file_free(kf); } // close dir g_dir_close(d); // sort items by categories and by name g_ptr_array_sort(items,&item_compare); // print what we get printf("<?xml version=\"1.0\"?>\n"); printf("<JWM>\n"); //jwm_category(items,"Accessibility",icAccessibility); jwm_category(items,"Audio and video",icAudioVideo); jwm_category(items,"Development",icDevelopment); jwm_category(items,"Games",icGames); jwm_category(items,"Graphics",icGraphics); jwm_category(items,"Internet",icInternet); jwm_category(items,"Office",icOffice); jwm_category(items,"Other",icOther); jwm_category(items,"Science and education",icScienceEducation); jwm_category(items,"Settings",icSettings); jwm_category(items,"Utility",icUtility); printf("</JWM>\n"); ///g_error("dont know what to do now"); return 0; }
static void parse_config(GKeyFile *config) { GError *error = NULL; gboolean boolean; char **timeservers; char **interfaces; char **str_list; char **tethering; char **ipv4url; char **ipv6url; gsize len; int timeout; if (config == NULL) { connman_settings.auto_connect = parse_service_types(default_auto_connect, 3); connman_settings.blacklisted_interfaces = g_strdupv(default_blacklist); return; } DBG("parsing %s", MAINFILE); boolean = g_key_file_get_boolean(config, "General", CONF_BG_SCAN, &error); if (error == NULL) connman_settings.bg_scan = boolean; g_clear_error(&error); timeservers = g_key_file_get_string_list(config, "General", CONF_PREF_TIMESERVERS, NULL, &error); if (error == NULL) connman_settings.pref_timeservers = timeservers; g_clear_error(&error); str_list = g_key_file_get_string_list(config, "General", CONF_AUTO_CONNECT, &len, &error); if (error == NULL) connman_settings.auto_connect = parse_service_types(str_list, len); else connman_settings.auto_connect = parse_service_types(default_auto_connect, 3); g_strfreev(str_list); g_clear_error(&error); str_list = g_key_file_get_string_list(config, "General", CONF_PREFERRED_TECHS, &len, &error); if (error == NULL) connman_settings.preferred_techs = parse_service_types(str_list, len); g_strfreev(str_list); g_clear_error(&error); str_list = g_key_file_get_string_list(config, "General", CONF_FALLBACK_NAMESERVERS, &len, &error); if (error == NULL) connman_settings.fallback_nameservers = parse_fallback_nameservers(str_list, len); g_strfreev(str_list); g_clear_error(&error); timeout = g_key_file_get_integer(config, "General", CONF_TIMEOUT_INPUTREQ, &error); if (error == NULL && timeout >= 0) connman_settings.timeout_inputreq = timeout * 1000; g_clear_error(&error); timeout = g_key_file_get_integer(config, "General", CONF_TIMEOUT_BROWSERLAUNCH, &error); if (error == NULL && timeout >= 0) connman_settings.timeout_browserlaunch = timeout * 1000; g_clear_error(&error); interfaces = g_key_file_get_string_list(config, "General", CONF_BLACKLISTED_INTERFACES, &len, &error); if (error == NULL) connman_settings.blacklisted_interfaces = interfaces; else connman_settings.blacklisted_interfaces = g_strdupv(default_blacklist); g_clear_error(&error); boolean = g_key_file_get_boolean(config, "General", CONF_ALLOW_HOSTNAME_UPDATES, &error); if (error == NULL) connman_settings.allow_hostname_updates = boolean; g_clear_error(&error); boolean = g_key_file_get_boolean(config, "General", CONF_SINGLE_TECH, &error); if (error == NULL) connman_settings.single_tech = boolean; g_clear_error(&error); boolean = g_key_file_get_boolean(config, "General", CONF_START_SESSION, &error); if (error == NULL) connman_settings.start_session = boolean; g_clear_error(&error); tethering = g_key_file_get_string_list(config, "General", CONF_TETHERING_TECHNOLOGIES, &len, &error); if (error == NULL) connman_settings.tethering_technologies = tethering; g_clear_error(&error); boolean = g_key_file_get_boolean(config, "General", CONF_PERSISTENT_TETHERING_MODE, &error); if (error == NULL) connman_settings.persistent_tethering_mode = boolean; g_clear_error(&error); ipv4url = g_key_file_get_string(config, "General", CONF_STATUS_URL_IPV4, &error); if (error == NULL) connman_settings.ipv4_status_url = ipv4url; else connman_settings.ipv4_status_url = "http://ipv4.connman.net/online/status.html"; g_clear_error(&error); ipv6url = g_key_file_get_string(config, "General", CONF_STATUS_URL_IPV6, &error); if (error == NULL) connman_settings.ipv6_status_url = ipv6url; else connman_settings.ipv6_status_url = "http://ipv6.connman.net/online/status.html"; g_clear_error(&error); }
static Capabilities * _caps_get(const char * const caps_str) { if (g_key_file_has_group(cache, caps_str)) { Capabilities *new_caps = malloc(sizeof(struct capabilities_t)); char *category = g_key_file_get_string(cache, caps_str, "category", NULL); if (category) { new_caps->category = strdup(category); } else { new_caps->category = NULL; } char *type = g_key_file_get_string(cache, caps_str, "type", NULL); if (type) { new_caps->type = strdup(type); } else { new_caps->type = NULL; } char *name = g_key_file_get_string(cache, caps_str, "name", NULL); if (name) { new_caps->name = strdup(name); } else { new_caps->name = NULL; } char *software = g_key_file_get_string(cache, caps_str, "software", NULL); if (software) { new_caps->software = strdup(software); } else { new_caps->software = NULL; } char *software_version = g_key_file_get_string(cache, caps_str, "software_version", NULL); if (software_version) { new_caps->software_version = strdup(software_version); } else { new_caps->software_version = NULL; } char *os = g_key_file_get_string(cache, caps_str, "os", NULL); if (os) { new_caps->os = strdup(os); } else { new_caps->os = NULL; } char *os_version = g_key_file_get_string(cache, caps_str, "os_version", NULL); if (os_version) { new_caps->os_version = strdup(os_version); } else { new_caps->os_version = NULL; } gsize features_len = 0; gchar **features = g_key_file_get_string_list(cache, caps_str, "features", &features_len, NULL); if (features != NULL && features_len > 0) { GSList *features_list = NULL; int i; for (i = 0; i < features_len; i++) { features_list = g_slist_append(features_list, strdup(features[i])); } new_caps->features = features_list; g_strfreev(features); } else { new_caps->features = NULL; } return new_caps; } else { return NULL; } }
void prefs_load(void) { GError *err; prefs_loc = _get_preferences_file(); if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) { g_chmod(prefs_loc, S_IRUSR | S_IWUSR); } prefs = g_key_file_new(); g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); err = NULL; log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err); if (err) { log_maxsize = 0; g_error_free(err); } // move pre 0.5.0 autoaway.time to autoaway.awaytime if (g_key_file_has_key(prefs, PREF_GROUP_PRESENCE, "autoaway.time", NULL)) { gint time = g_key_file_get_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.time", NULL); g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "autoaway.awaytime", time); g_key_file_remove_key(prefs, PREF_GROUP_PRESENCE, "autoaway.time", NULL); } // move pre 0.5.0 autoaway.message to autoaway.awaymessage if (g_key_file_has_key(prefs, PREF_GROUP_PRESENCE, "autoaway.message", NULL)) { char *message = g_key_file_get_string(prefs, PREF_GROUP_PRESENCE, "autoaway.message", NULL); g_key_file_set_string(prefs, PREF_GROUP_PRESENCE, "autoaway.awaymessage", message); g_key_file_remove_key(prefs, PREF_GROUP_PRESENCE, "autoaway.message", NULL); prefs_free_string(message); } // migrate pre 0.5.0 time settings if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time", NULL)) { char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time", NULL); char *val = NULL; if (time) { val = time; } else { val = "off"; } g_key_file_set_string(prefs, PREF_GROUP_UI, "time.console", val); g_key_file_set_string(prefs, PREF_GROUP_UI, "time.chat", val); g_key_file_set_string(prefs, PREF_GROUP_UI, "time.muc", val); g_key_file_set_string(prefs, PREF_GROUP_UI, "time.mucconfig", val); g_key_file_set_string(prefs, PREF_GROUP_UI, "time.private", val); g_key_file_set_string(prefs, PREF_GROUP_UI, "time.xmlconsole", val); g_key_file_remove_key(prefs, PREF_GROUP_UI, "time", NULL); prefs_free_string(time); } // move pre 0.5.0 notify settings if (g_key_file_has_key(prefs, PREF_GROUP_NOTIFICATIONS, "room", NULL)) { char *value = g_key_file_get_string(prefs, PREF_GROUP_NOTIFICATIONS, "room", NULL); if (g_strcmp0(value, "on") == 0) { g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", TRUE); } else if (g_strcmp0(value, "off") == 0) { g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", FALSE); } else if (g_strcmp0(value, "mention") == 0) { g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", FALSE); g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room.mention", TRUE); } prefs_free_string(value); } _save_prefs(); boolean_choice_ac = autocomplete_new(); autocomplete_add(boolean_choice_ac, "on"); autocomplete_add(boolean_choice_ac, "off"); room_trigger_ac = autocomplete_new(); gsize len = 0; gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); int i = 0; for (i = 0; i < len; i++) { autocomplete_add(room_trigger_ac, triggers[i]); } g_strfreev(triggers); }
static void hd_plugin_configuration_configuration_loaded (HDPluginConfiguration *configuration, GKeyFile *keyfile) { HDPluginConfigurationPrivate *priv = configuration->priv; GError *error = NULL; gsize n_plugin_dir; gchar *items_config_filename; /* free old configuration */ if (priv->plugin_dirs != NULL) { guint i; for (i = 0; priv->plugin_dirs[i] != NULL; i++) { g_file_monitor_cancel (priv->plugin_dir_monitors[i]); g_object_unref (priv->plugin_dir_monitors[i]); g_object_unref (priv->plugin_dir_files[i]); } priv->plugin_dir_monitors = (g_free (priv->plugin_dir_monitors), NULL); priv->plugin_dir_files = (g_free (priv->plugin_dir_files), NULL); priv->plugin_dirs = (g_strfreev (priv->plugin_dirs), NULL); } if (priv->items_config_file) priv->items_config_file = (g_object_unref (priv->items_config_file), NULL); g_hash_table_remove_all (priv->available_plugins); /* Load configuration ([X-PluginConfiguration] group) */ if (!g_key_file_has_group (keyfile, HD_PLUGIN_CONFIGURATION_CONFIG_GROUP)) { g_warning ("Error configuration file doesn't contain group '%s'", HD_PLUGIN_CONFIGURATION_CONFIG_GROUP); return; } priv->plugin_dirs = g_key_file_get_string_list (keyfile, HD_PLUGIN_CONFIGURATION_CONFIG_GROUP, HD_DESKTOP_CONFIG_KEY_PLUGIN_DIR, &n_plugin_dir, &error); if (!priv->plugin_dirs) { g_warning ("Error loading configuration file. No plugin dirs defined: %s", error->message); g_error_free (error); return; } else { guint i; priv->plugin_dir_files = g_new0 (GFile*, n_plugin_dir); priv->plugin_dir_monitors = g_new0 (GFileMonitor*, n_plugin_dir); for (i = 0; priv->plugin_dirs[i] != NULL; i++) { GDir *dir; GError *error = NULL; const gchar *name; /* Strip spaces */ g_strstrip (priv->plugin_dirs[i]); /* Add monitor */ priv->plugin_dir_files[i] = g_file_new_for_path (priv->plugin_dirs[i]); priv->plugin_dir_monitors[i] = g_file_monitor_directory (priv->plugin_dir_files[i], G_FILE_MONITOR_NONE, NULL,NULL); g_signal_connect (G_OBJECT (priv->plugin_dir_monitors[i]), "changed", G_CALLBACK (hd_plugin_configuration_plugin_dir_changed), (gpointer)configuration); /* Get available .desktop files */ dir = g_dir_open (priv->plugin_dirs[i], 0, &error); if (dir == NULL) { g_warning ("%s. Couldn't read plugin_paths in dir %s. Error: %s", __FUNCTION__, priv->plugin_dirs[i], error->message); g_error_free (error); continue; } for (name = g_dir_read_name (dir); name != NULL; name = g_dir_read_name (dir)) { gchar *filename; /* Ignore non .desktop files. */ if (!g_str_has_suffix (name, ".desktop")) continue; filename = g_build_filename (priv->plugin_dirs[i], name, NULL); g_hash_table_insert (priv->available_plugins, filename, GUINT_TO_POINTER (1)); } g_dir_close (dir); } } items_config_filename = g_key_file_get_string (keyfile, HD_PLUGIN_CONFIGURATION_CONFIG_GROUP, HD_PLUGIN_CONFIGURATION_CONFIG_KEY_PLUGIN_CONFIGURATION, NULL); if (items_config_filename) { gchar *system_conf_dir, *user_conf_dir; g_strstrip (items_config_filename); /* Get config file directories */ g_object_get (G_OBJECT (priv->config_file), "system-conf-dir", &system_conf_dir, "user-conf-dir", &user_conf_dir, NULL); priv->items_config_file = hd_config_file_new (system_conf_dir, user_conf_dir, items_config_filename); g_signal_connect_object (priv->items_config_file, "changed", G_CALLBACK (hd_plugin_configuration_load_plugin_configuration), configuration, G_CONNECT_SWAPPED); g_free (system_conf_dir); g_free (user_conf_dir); } g_free (items_config_filename); hd_plugin_configuration_load_plugin_configuration (configuration); }
gboolean plugin_init(GKeyFile *config, const char *enable, const char *disable) { GSList *list; GDir *dir; const gchar *file; char **conf_disabled, **cli_disabled, **cli_enabled; unsigned int i; /* Make a call to BtIO API so its symbols got resolved before the * plugins are loaded. */ bt_io_error_quark(); if (config) conf_disabled = g_key_file_get_string_list(config, "General", "DisablePlugins", NULL, NULL); else conf_disabled = NULL; if (enable) cli_enabled = g_strsplit_set(enable, ", ", -1); else cli_enabled = NULL; if (disable) cli_disabled = g_strsplit_set(disable, ", ", -1); else cli_disabled = NULL; DBG("Loading builtin plugins"); for (i = 0; __bluetooth_builtin[i]; i++) { if (!enable_plugin(__bluetooth_builtin[i]->name, conf_disabled, cli_enabled, cli_disabled)) continue; add_plugin(NULL, __bluetooth_builtin[i]); } if (strlen(PLUGINDIR) == 0) goto start; DBG("Loading plugins %s", PLUGINDIR); dir = g_dir_open(PLUGINDIR, 0, NULL); if (!dir) goto start; while ((file = g_dir_read_name(dir)) != NULL) { struct bluetooth_plugin_desc *desc; void *handle; gchar *filename; if (g_str_has_prefix(file, "lib") == TRUE || g_str_has_suffix(file, ".so") == FALSE) continue; filename = g_build_filename(PLUGINDIR, file, NULL); handle = dlopen(filename, RTLD_NOW); if (handle == NULL) { error("Can't load plugin %s: %s", filename, dlerror()); g_free(filename); continue; } g_free(filename); desc = dlsym(handle, "bluetooth_plugin_desc"); if (desc == NULL) { error("Can't load plugin description: %s", dlerror()); dlclose(handle); continue; } if (!enable_plugin(desc->name, conf_disabled, cli_enabled, cli_disabled)) { dlclose(handle); continue; } if (add_plugin(handle, desc) == FALSE) dlclose(handle); } g_dir_close(dir); start: for (list = plugins; list; list = list->next) { struct bluetooth_plugin *plugin = list->data; if (plugin->desc->init() < 0) { error("Failed to init %s plugin", plugin->desc->name); continue; } plugin->active = TRUE; } g_strfreev(conf_disabled); g_strfreev(cli_enabled); g_strfreev(cli_disabled); return TRUE; }
int load_keyfile_to_options(GKeyFile *keyfile, const gchar *ini_group_name, chassis *chas) { GError *gerr = NULL; chassis_private *g = chas->priv; gchar **arg_string_array; int i, j, array_size, count; gsize len; gchar* reload_items[] = {"proxy-backend-addresses", "proxy-read-only-backend-addresses", "proxy-master-standby-address", "client-ips", "pwds" }; g_mutex_lock(g->backends->backends_mutex); count = g->backends->backends->len; for (i = 0; i < count; i++) { network_backends_remove_unlock(g->backends, 0);/*erase the whole always from the index of zero*/ } array_size = sizeof(reload_items) / sizeof(gchar*); if (!keyfile) { g_mutex_unlock(g->backends->backends_mutex); return -1; } if (!g_key_file_has_group(keyfile, ini_group_name)) { g_mutex_unlock(g->backends->backends_mutex); return 0; } for (i = 0;i < array_size; i++) { if (!g_key_file_has_key(keyfile, ini_group_name, reload_items[i], &gerr)) { if (i == 3) {/*client-ips*/ chassis_plugin* p = chas->modules->pdata[1]; p->insert_clientips(NULL, p->config); } continue; } arg_string_array = g_key_file_get_string_list(keyfile, ini_group_name, reload_items[i], &len, &gerr); if (!gerr) { if (i < 3) { for (j = 0; arg_string_array[j]; j++) { arg_string_array[j] = g_strstrip(arg_string_array[j]); switch (i) { case 0: network_backends_add_unlock(g->backends, arg_string_array[j], BACKEND_TYPE_RW); break; case 1: network_backends_add_unlock(g->backends, arg_string_array[j], BACKEND_TYPE_RO); break; case 2: network_backends_add_unlock(g->backends, arg_string_array[j], BACKEND_TYPE_SY); break; } } }else if(i == 3) { chassis_plugin* p = chas->modules->pdata[1]; p->insert_clientips(arg_string_array, p->config); }else if(i == 4) { chassis_plugin* p = chas->modules->pdata[1]; p->insert_pwds(arg_string_array, p->config); } g_strfreev(arg_string_array); } else { g_message("%s:load keyfile_to options fail, gerr is :%s", G_STRLOC, gerr->message); g_error_free(gerr); gerr = NULL; g_mutex_unlock(g->backends->backends_mutex); return -1; } } for (i = 0; i < g->backends->backends->len; i++ ) { network_backend_t* b = g_ptr_array_index(g->backends->backends, i); b->state = BACKEND_STATE_UP; } g->backends->global_wrr->max_weight = 0; //Reinitialize all backend weight g_mutex_unlock(g->backends->backends_mutex); return 0; }
void Settings::load(const char* settingsFile) { GKeyFile* keyfile; GKeyFileFlags flags; GError* error = 0; keyfile = g_key_file_new(); if(!keyfile) return; flags = GKeyFileFlags( G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS); if( !g_key_file_load_from_file( keyfile, settingsFile, flags, &error ) ) { g_key_file_free( keyfile ); if (error) g_error_free(error); return ; } // Fill in with the macros above. KEY_STRING("General","ApplicationPath", lunaAppsPath ); // apps path can now be multiple paths, separated by : (setenv PATH style) KEY_STRING("General","AppInstallBase", appInstallBase); // due to all the churn surrounding moving of apps around, this is now a conf option KEY_STRING("General","AppInstallRelative", appInstallRelative); // due to all the churn surrounding moving of apps around, this is now a conf option // KEY_STRING("General","PackageInstallBase", packageInstallBase); KEY_STRING("General","PackageInstallRelative", packageInstallRelative); KEY_STRING("General","DownloadPathMedia",downloadPathMedia); //validate path, reset to default if necessary if (!validateDownloadPath(downloadPathMedia)) { downloadPathMedia = "/media/internal/downloads"; } KEY_STRING("General","AppInstallTemp",appInstallerTmp); KEY_STRING("General","SystemPath", lunaSystemPath ); KEY_STRING("General","AppLauncherPath", lunaAppLauncherPath ); KEY_STRING("General","SystemResourcesPath", lunaSystemResourcesPath ); KEY_STRING("General","SystemLocalePath", lunaSystemLocalePath ); KEY_STRING("General","PresetLaunchPointsPath",lunaPresetLaunchPointsPath); KEY_STRING("General","LaunchPointsPath", lunaLaunchPointsPath); KEY_STRING("General", "PreferencesPath", lunaPrefsPath); KEY_STRING("General","UiComponentsPath", lunaQmlUiComponentsPath ); KEY_BOOLEAN("General", "ShowReticle", showReticle); KEY_INTEGER("General", "NotificationSoundDuration", notificationSoundDuration); KEY_INTEGER( "CoreNavi", "ThrobberBrightnessInLight", ledPulseMaxBrightness); KEY_INTEGER( "CoreNavi", "ThrobberBrightnessInDark", ledPulseDarkBrightness); KEY_BOOLEAN( "CoreNavi", "EnableLightBar", lightbarEnabled); KEY_INTEGER( "CoreNavi", "CoreNaviBrightnessScaler", coreNaviScaler); KEY_INTEGER( "CoreNavi", "GestureAnimationSpeedInMs", gestureAnimationSpeed); KEY_INTEGER( "CoreNavi", "HomeDoubleClickDuration", homeDoubleClickDuration); KEY_INTEGER( "Display", "BrightnessOutdoorScale", backlightOutdoorScale); KEY_INTEGER( "Display", "BrightnessDimScale", backlightDimScale); KEY_INTEGER( "Display", "BrightnessDarkScale", backlightDarkScale); KEY_BOOLEAN( "Display", "EnableALS", enableAls); KEY_BOOLEAN( "Display", "TurnOffAccelerometerWhenDimmed", turnOffAccelWhenDimmed); KEY_BOOLEAN( "Display", "DisableLocking", disableLocking); KEY_INTEGER( "Display", "LockScreenTimeoutMs", lockScreenTimeout); KEY_INTEGER( "Memory", "CardLimit", cardLimit ); KEY_INTEGER( "General","DisplayWidth",displayWidth); KEY_INTEGER( "General","DisplayHeight",displayHeight); KEY_INTEGER( "General","DisplayNumBuffers", displayNumBuffers); KEY_INTEGER("General", "MaxPenMoveFreq", maxPenMoveFreq); KEY_INTEGER("General", "MaxPaintLoad", maxPaintLoad); KEY_INTEGER("General", "MaxGestureChangeFreq", maxGestureChangeFreq); KEY_INTEGER("General", "MaxTouchChangeFreq", maxTouchChangeFreq); KEY_BOOLEAN( "Debug", "WatchPenEvents", debug_trackInputEvents ); KEY_BOOLEAN( "Debug", "EnableDebugModeByDefault", debug_enabled ); KEY_BOOLEAN( "Debug", "PiranhaDrawColoredOutlines", debug_piranhaDrawColoredOutlines); KEY_BOOLEAN( "Debug", "PiranhaDisplayFps", debug_piranhaDisplayFps); KEY_BOOLEAN( "Debug", "ShowGestures", debug_showGestures); KEY_BOOLEAN( "Debug", "DoVerboseCrashLogging", debug_doVerboseCrashLogging); KEY_BOOLEAN( "Debug", "LoopInCrashHandler", debug_loopInCrashHandler); KEY_INTEGER( "Debug", "AppInstallerCleaner",debug_appInstallerCleaner ); KEY_STRING( "General", "CmdResourceHandlers", lunaCmdHandlerPath ); KEY_STRING( "General", "CmdResourceHandlersActiveCopy", lunaCmdHandlerSavedPath); KEY_STRING( "Fonts", "Banner", fontBanner ); KEY_STRING( "Fonts", "ActiveBanner", fontActiveBanner ); KEY_STRING( "Fonts", "LockWindow", fontLockWindow ); KEY_STRING( "Fonts", "DockMode", fontDockMode ); KEY_STRING( "Fonts", "Quicklaunch", fontQuicklaunch ); KEY_STRING( "Fonts", "StatusBar", fontStatusBar ); KEY_STRING( "Fonts", "KeyboardKeys", fontKeyboardKeys ); KEY_STRING( "Fonts", "StatusBar", fontStatusBar ); KEY_INTEGER("TouchEvents", "TapRadiusMax", tapRadius); KEY_INTEGER("TouchEvents", "TapRadiusMin", tapRadiusMin); KEY_INTEGER("TouchEvents", "TapRadiusShrinkPerc", tapRadiusShrinkPercent); KEY_INTEGER("TouchEvents", "TapRadiusShrinkGranMs", tapRadiusShrinkGranMs); KEY_BOOLEAN("TouchEvents", "EnableForWebApps", enableTouchEventsForWebApps); tapRadiusSquared = tapRadius * tapRadius; KEY_INTEGER("TouchEvents", "DoubleClickDuration", tapDoubleClickDuration); // Clamp to sensible values if (tapDoubleClickDuration < 50) tapDoubleClickDuration = 50; else if (tapDoubleClickDuration > 2000) tapDoubleClickDuration = 2000; KEY_INTEGER("VTrackBall", "PixelsPerMoveH", h_trackball_pixels_per_move ); KEY_INTEGER("VTrackBall", "PixelsPerMoveV", v_trackball_pixels_per_move ); KEY_INTEGER("VTrackBall", "AccelRateH1", h_accel_rate1 ); KEY_INTEGER("VTrackBall", "AccelRateV1", v_accel_rate1 ); KEY_INTEGER("VTrackBall", "AccelConstH1", h_accel_const1 ); KEY_INTEGER("VTrackBall", "AccelConstV1", v_accel_const1 ); KEY_INTEGER("VTrackBall", "AccelRateH2", h_accel_rate2 ); KEY_INTEGER("VTrackBall", "AccelRateV2", v_accel_rate2 ); KEY_INTEGER("VTrackBall", "AccelConstH2", h_accel_const2 ); KEY_INTEGER("VTrackBall", "AccelConstV2", v_accel_const2 ); KEY_STRING("General", "QuickLaunchDefaultPositions", quicklaunchDefaultPositions ); #if defined(TARGET_DESKTOP) //If we don't have a home directory, we'll set it to /tmp. Otherwise, this does nothing. setenv("HOME", "/tmp", 0); const std::string homeFolder = getenv("HOME"); quicklaunchUserPositions = homeFolder + "/.user-dock-positions.json"; #endif KEY_STRING("General", "QuickLaunchUserPositions", quicklaunchUserPositions ); KEY_INTEGER( "General", "StatusBarTitleMaxWidth", statusBarTitleMaxWidth); KEY_BOOLEAN( "DockMode", "DockModePrelaunchAllApps", dockModePrelaunchAllApps); KEY_BOOLEAN( "DockMode", "DockModeCloseAppOnMinimize", dockModeCloseOnMinimize); KEY_BOOLEAN( "DockMode", "DockModeCloseAppsOnExit", dockModeCloseOnExit); KEY_INTEGER( "DockMode", "DockModeMaxApps", dockModeMaxApps); KEY_INTEGER( "DockMode", "DockModeNightBrightness", dockModeNightBrightness); KEY_INTEGER( "DockMode", "DockModeMenuHeight", dockModeMenuHeight); KEY_STRING("DockMode", "DockModeDefaultPositions", quicklaunchDefaultPositions ); #if defined(TARGET_DESKTOP) dockModeUserPositions = homeFolder + "/.user-dock-mode-launcher-positions.json"; #endif KEY_STRING("DockMode", "DockModeUserPositions", quicklaunchUserPositions ); KEY_BOOLEAN( "VirtualKeyboard", "VirtualKeyboardEnabled", virtualKeyboardEnabled); KEY_BOOLEAN( "VirtualCoreNavi", "VirtualCoreNaviEnabled", virtualCoreNaviEnabled); KEY_INTEGER( "VirtualCoreNavi", "VirtualCoreNaviHeight", virtualCoreNaviHeight); KEY_DOUBLE("Launcher", "CardSideScrollSwipeThreshold", launcherSideSwipeThreshold); KEY_BOOLEAN("Launcher", "UseOGLHardwareAntialias", launcherUsesHwAA); KEY_INTEGER("Launcher", "LauncherItemRowSpacingAdjust",launcherRowSpacingAdjust); KEY_INTEGER("Launcher", "LauncherLabelWidthAdjust",launcherLabelWidthAdjust); KEY_INTEGER("Launcher", "LauncherLabelXPadding",launcherLabelXPadding); KEY_DOUBLE("Launcher","LauncherIconReorderPositionThreshold",launcherIconReorderPositionThreshold); KEY_BOOLEAN("UI", "DisplayUiRotates", displayUiRotates); KEY_BOOLEAN("UI", "TabletUi", tabletUi); KEY_INTEGER("UI", "HomeButtonOrientationAngle", homeButtonOrientationAngle); KEY_INTEGER("UI", "EmuModeOrientationAngle", emuModeOrientationAngle); KEY_INTEGER("UI", "PositiveSpaceTopPadding", positiveSpaceTopPadding); KEY_INTEGER("UI", "PositiveSpaceBottomPadding", positiveSpaceBottomPadding); KEY_DOUBLE("UI", "MaximumNegativeSpaceHeightRatio", maximumNegativeSpaceHeightRatio); KEY_DOUBLE("UI", "ActiveCardWindowRatio", activeCardWindowRatio); KEY_DOUBLE("UI", "NonActiveCardWindowRatio", nonActiveCardWindowRatio); KEY_DOUBLE("UI", "GhostCardFinalRatio", ghostCardFinalRatio); KEY_INTEGER("UI", "CardGroupRotFactor", cardGroupRotFactor); KEY_INTEGER("UI", "GapBetweenCardGroups", gapBetweenCardGroups); KEY_INTEGER("UI", "OverlayNotificationsHeight", overlayNotificationsHeight); KEY_INTEGER("UI", "SplashIconSize", splashIconSize); KEY_BOOLEAN("UI", "EnableSplashBackgrounds", enableSplashBackgrounds); KEY_BOOLEAN("UI", "AtlasEnabled", atlasEnabled); KEY_INTEGER("UI", "EmulatedCardWidth", emulatedCardWidth); KEY_INTEGER("UI", "EmulatedCardHeight", emulatedCardHeight); KEY_INTEGER("UI", "ModalWindowWidth", modalWindowWidth); KEY_INTEGER("UI", "ModalWindowHeight", modalWindowHeight); KEY_DOUBLE("UI", "CardGroupingXDistanceFactor", cardGroupingXDistanceFactor); KEY_DOUBLE("UI", "CardDimmPercentage", cardDimmPercentage); KEY_INTEGER("UI", "AtlasMemThreshold", atlasMemThreshold); KEY_BOOLEAN("Debug", "LauncherAtlasStatistics", launcherAtlasStatistics); KEY_BOOLEAN("Debug", "DumpLauncherAtlas", launcherDumpAtlas); if (forceSoftwareRendering) { atlasEnabled = false; launcherAtlasStatistics = false; } else if (atlasEnabled && atlasMemThreshold > 0 && MeasureTotalRAM() < atlasMemThreshold * 1024) { g_message("Atlas disabled because physical memory below %dMB threshold\n", atlasMemThreshold); atlasEnabled = false; } KEY_INTEGER("DownloadManager", "MaxQueueLength", maxDownloadManagerQueueLength); KEY_INTEGER("DownloadManager", "MaxConcurrent", maxDownloadManagerConcurrent); KEY_INTEGER("DownloadManager", "MaxRecvSpeed", maxDownloadManagerRecvSpeed); KEY_STRING( "Demo", "GestureRepeaterIp", cesGestureRepeaterIp ); KEY_INTEGER( "Demo", "GestureRepeaterPort", cesGestureRepeaterPort ); KEY_BOOLEAN( "Demo", "EnableGestureRepeater", enableGestureRepeater ); KEY_BOOLEAN( "Demo", "DemoMode", demoMode ); KEY_BOOLEAN( "Debug", "ShowAppStats", showAppStats ); KEY_BOOLEAN( "General", "CollectUseStats", collectUseStats ); KEY_BOOLEAN( "General" , "UsePartialKeywordMatchForAppSearch",usePartialKeywordAppSearch); KEY_BOOLEAN( "General" , "ScanCalculatesAppSizes",scanCalculatesAppSizes); KEY_INTEGER("KeepAlive", "MaxParked", maxNumParkedApps ); KEY_INTEGER("CpuShare", "UiMainLow", uiMainCpuShareLow); KEY_INTEGER("CpuShare", "UiOtherLow", uiOtherCpuShareLow); KEY_INTEGER("CpuShare", "JavaLow", javaCpuShareLow); KEY_INTEGER("CpuShare", "WebLow", webCpuShareLow); KEY_INTEGER("CpuShare", "GameLow", gameCpuShareLow); KEY_INTEGER("CpuShare", "Default", cpuShareDefault); KEY_BOOLEAN("AllowTurboMode", "General", allowTurboMode); KEY_STRING( "General", "WifiInterfaceName", wifiInterfaceName ); KEY_STRING( "General", "WanInterfaceName", wanInterfaceName ); KEY_BOOLEAN( "Memory", "CanRestartHeadlessApps", canRestartHeadlessApps ); KEY_BOOLEAN( "Debug", "PerformanceLogs", perfTesting); KEY_INTEGER("General", "schemaValidationOption", schemaValidationOption); // apps to launch at boot time gchar** appsToLaunchAtBootStr = g_key_file_get_string_list(keyfile, "LaunchAtBoot", "Applications", NULL, NULL); if (appsToLaunchAtBootStr) { int index = 0; appsToLaunchAtBoot.clear(); while (appsToLaunchAtBootStr[index]) { appsToLaunchAtBoot.insert(appsToLaunchAtBootStr[index]); SETTINGS_TRACE("App to launch at boot time: %s\n", appsToLaunchAtBootStr[index]); ++index; } g_strfreev(appsToLaunchAtBootStr); } // apps to keep alive gchar** appsToKeepAliveStr = g_key_file_get_string_list(keyfile, "KeepAlive", "Applications", NULL, NULL); if (appsToKeepAliveStr) { int index = 0; appsToKeepAlive.clear(); while (appsToKeepAliveStr[index]) { appsToKeepAlive.insert(appsToKeepAliveStr[index]); SETTINGS_TRACE("App to keep alive: %s\n", appsToKeepAliveStr[index]); ++index; } g_strfreev(appsToKeepAliveStr); } // apps to keep alive forever (pinned) gchar** appsToKeepAliveForeverStr = g_key_file_get_string_list(keyfile, "KeepAliveUntilMemPressure", "Applications", NULL, NULL); if (appsToKeepAliveForeverStr) { int index = 0; appsToKeepAliveUntilMemPressure.clear(); while (appsToKeepAliveForeverStr[index]) { appsToKeepAliveUntilMemPressure.insert(appsToKeepAliveForeverStr[index]); SETTINGS_TRACE("App to keep alive until memory pressure: %s\n", appsToKeepAliveForeverStr[index]); ++index; } g_strfreev(appsToKeepAliveForeverStr); } // apps to allow under low memory conditions gchar** appsToAllowInLowMemoryStr = g_key_file_get_string_list(keyfile, "Memory", "AppsToAllowInLowMemory", NULL, NULL); if (appsToAllowInLowMemoryStr) { int index = 0; appsToAllowInLowMemory.clear(); while (appsToAllowInLowMemoryStr[index]) { appsToAllowInLowMemory.insert(appsToAllowInLowMemoryStr[index]); g_message("App to allow in Low memory: %s", appsToAllowInLowMemoryStr[index]); ++index; } g_strfreev(appsToAllowInLowMemoryStr); } // apps with accelerated compositing disabled gchar** appsToDisableAccelCompositingStr = g_key_file_get_string_list(keyfile, "AccelCompositingDisabled", "Applications", NULL, NULL); if (appsToDisableAccelCompositingStr) { int index = 0; appsToDisableAccelCompositing.clear(); while (appsToDisableAccelCompositingStr[index]) { appsToDisableAccelCompositing.insert(appsToDisableAccelCompositingStr[index]); SETTINGS_TRACE("App with accelerated compositing disabled: %s\n", appsToDisableAccelCompositingStr[index]); ++index; } g_strfreev(appsToDisableAccelCompositingStr); } // SUC apps that have special launch privs gchar** sucAppsList = g_key_file_get_string_list(keyfile, "SUCApps", "Applications", NULL, NULL); if (sucAppsList) { int index = 0; sucApps.clear(); while (sucAppsList[index]) { sucApps.insert(sucAppsList[index]); SETTINGS_TRACE("SUC App with special launch priviledge: %s\n", sucAppsList[index]); ++index; } g_strfreev(sucAppsList); } // ... g_key_file_free( keyfile ); // sanity check on the homeButtonOrientationAngle value: if(homeButtonOrientationAngle >= 360) homeButtonOrientationAngle = homeButtonOrientationAngle%360; if(homeButtonOrientationAngle < -90) homeButtonOrientationAngle += 360; if((homeButtonOrientationAngle != 0) && (homeButtonOrientationAngle != 90) && (homeButtonOrientationAngle != 180) && (homeButtonOrientationAngle != 270) && (homeButtonOrientationAngle != -90)) homeButtonOrientationAngle = 0; // sanity check on the emuModeOrientationAngle value: if(emuModeOrientationAngle >= 360) emuModeOrientationAngle = emuModeOrientationAngle%360; if(emuModeOrientationAngle < -90) emuModeOrientationAngle += 360; if((emuModeOrientationAngle != 0) && (emuModeOrientationAngle != 90) && (emuModeOrientationAngle != 180) && (emuModeOrientationAngle != 270) && (emuModeOrientationAngle != -90)) emuModeOrientationAngle = 0; }
/** * Load and initialize all modules from directory. * * @param modules_directory The directory with modules. * * @return TRUE if at least one module was successfully loaded. */ gboolean u_module_load_directory (char *modules_directory) { DIR *dip; struct dirent *dit; char rpath[PATH_MAX+1]; char **disabled; gsize disabled_len; g_info("Loading modules from directory '%s/' ...", modules_directory); if ((dip = opendir(modules_directory)) == NULL) { g_warning ("Couldn't load modules (directory '%s': %s)", modules_directory, g_strerror(errno)); return FALSE; } disabled = g_key_file_get_string_list(config_data, CONFIG_CORE, "disabled_modules", &disabled_len, NULL); while ((dit = readdir(dip)) != NULL) { gchar *module_name; gboolean skip; gsize i; if (fnmatch ("*.so", dit->d_name, 0)) continue; module_name = g_strndup(dit->d_name,strlen(dit->d_name)-3); skip = FALSE; for (i = 0; i < disabled_len; i++) if (!g_ascii_strcasecmp (disabled[i], module_name)) { skip = TRUE; break; } if(!skip) { GModule *module; snprintf (rpath, PATH_MAX, "%s/%s", modules_directory, dit->d_name); g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Loading module %s", dit->d_name); module = g_module_open (rpath, G_MODULE_BIND_LAZY); if (!module) { g_warning ("%s", g_module_error()); } } else { g_debug ("Skipped module %s", module_name); } g_free(module_name); } g_strfreev (disabled); closedir (dip); return TRUE; }
static char* get_actions( const char* dir, const char* type, GArray* actions ) { //g_print( "get_actions( %s, %s )\n", dir, type ); GKeyFile* file; gboolean opened; int n; char** apps = NULL; char** removed = NULL; gboolean is_removed; gsize n_removed = 0, r; char* names[] = { "applications/mimeapps.list", "applications/mimeinfo.cache" }; char* sections[] = { "Added Associations", "MIME Cache" }; for ( n = 0; n < G_N_ELEMENTS( names ); n++ ) { char* path = g_build_filename( dir, names[n], NULL ); //g_print( " path = %s\n", path ); file = g_key_file_new(); opened = g_key_file_load_from_file( file, path, 0, NULL ); g_free( path ); if( G_LIKELY( opened ) ) { gsize n_apps = 0, i; apps = g_key_file_get_string_list( file, sections[n], type, &n_apps, NULL ); if ( n == 0 ) { // get removed associations in this dir removed = g_key_file_get_string_list( file, "Removed Associations", type, &n_removed, NULL ); } for ( i = 0; i < n_apps; ++i ) { g_strstrip( apps[i] ); //g_print( " %s\n", apps[i] ); // check if removed is_removed = FALSE; if ( removed && n > 0 ) { for ( r = 0; r < n_removed; ++r ) { g_strstrip( removed[r] ); if ( !strcmp( removed[r], apps[i] ) ) { //g_print( " REMOVED\n" ); is_removed = TRUE; break; } } } if( !is_removed && -1 == strv_index( (char**)actions->data, apps[i] ) ) { /* check for app existence */ path = mime_type_locate_desktop_file( NULL, apps[i] ); if( G_LIKELY(path) ) { //g_print( " EXISTS\n"); g_array_append_val( actions, apps[i] ); g_free( path ); } else g_free( apps[i] ); apps[i] = NULL; /* steal the string */ } else { g_free( apps[i] ); apps[i] = NULL; } } g_free( apps ); /* don't call g_strfreev since all strings in the array was stolen. */ } g_key_file_free( file ); } g_strfreev( removed ); return NULL; /* return NULL so the for_each operation doesn't stop. */ }
/** * cedit_plugin_info_new: * @filename: the filename where to read the plugin information * * Creates a new #CeditPluginInfo from a file on the disk. * * Return value: a newly created #CeditPluginInfo. */ CeditPluginInfo * _cedit_plugin_info_new (const gchar *file) { CeditPluginInfo *info; GKeyFile *plugin_file = NULL; gchar *str; g_return_val_if_fail (file != NULL, NULL); cedit_debug_message (DEBUG_PLUGINS, "Loading plugin: %s", file); info = g_new0 (CeditPluginInfo, 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, "Cedit Plugin", "IAge", NULL)) { cedit_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, "Cedit Plugin", "IAge", NULL) != 2) { cedit_debug_message (DEBUG_PLUGINS, "Wrong IAge in file: %s", file); goto error; } /* Get module name */ str = g_key_file_get_string (plugin_file, "Cedit 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, "Cedit Plugin", "Depends", NULL, NULL); if (info->dependencies == NULL) { cedit_debug_message (DEBUG_PLUGINS, "Could not find 'Depends' in %s", file); info->dependencies = g_new0 (gchar *, 1); }