Exemplo n.º 1
0
/**
 * midgard_connection_open_all:
 * @userdir: switch to read configuration from system or user's directory
 *
 * Every key is configuration name, and value is #MidgardConnection object.
 * Use g_hash_table_destroy to free hashtable and all opened connections.
 *
 * Returns: Newly allocated full #GHashTable.
 */
extern GHashTable *midgard_connection_open_all(gboolean userdir)
{
	GHashTable *cncs = 
		g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
	GHashTable *hash = NULL;

	gchar **cfgs = midgard_config_list_files(userdir);
	
	if(!cfgs) 
		return FALSE;

	guint i = 0;

	while(cfgs[i] != NULL) {
		
		MidgardConnection *cnc = midgard_connection_new();
		g_debug("Initialize new connection using '%s' configuration", cfgs[i]);
		
		GError *error = NULL;
		MidgardConfig *config = midgard_config_new();
		
		if(!midgard_config_read_file(config, cfgs[i], userdir, &error)) {

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

			i++;
			continue;
		}

		cnc->priv->config = config;

		if(__midgard_connection_open(cnc, &hash, TRUE)) {

			g_hash_table_insert(cncs, g_strdup(cfgs[i]), cnc);
		
		} else {
			
			g_object_unref(cnc);
			g_warning("Configuration %s failed", cfgs[i]);
		}
		
		i++;
	}
	
	if(hash)
		g_hash_table_destroy(hash);

	g_strfreev(cfgs);
	
	return cncs;
}
Exemplo n.º 2
0
static PHP_METHOD(midgard_config, list_files)
{
	RETVAL_FALSE;
	zend_bool user = FALSE;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &user) == FAILURE) {
		return;
	}

	array_init(return_value);

	gchar **files = midgard_config_list_files(user);

	if (!files)
		return;

	size_t i = 0;
	while (files[i] != NULL) {
		add_index_string(return_value, i, files[i], 1);
		i++;
	}

	g_strfreev(files);
}