Exemple #1
0
/*
 * Reopens a connection after the server has closed it (possibly because of a timeout)
 */
gboolean
gda_ldap_rebind (GdaLdapConnection *cnc, GError **error)
{
	g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (cnc), FALSE);
	gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */

	LdapConnectionData *cdata;
	cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc));
        if (!cdata) {
		gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */
		g_warning ("cdata != NULL failed");
		return FALSE;
	}

	GdaServerProviderConnectionData *pcdata;
	pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL);

	GdaWorker *worker;
	worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata));

	GMainContext *context;
	context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc);

	gpointer retval;
	gda_worker_do_job (worker, context, 0, &retval, NULL,
			   (GdaWorkerFunc) worker_gda_ldap_rebind, (gpointer) cdata, NULL, NULL, error);
	if (context)
		g_main_context_unref (context);

	gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */

	gda_worker_unref (worker);

	return retval ? TRUE : FALSE;
}
Exemple #2
0
/*
 * Unbinds the connection if possible (i.e. if cdata->keep_bound_count is 0)
 * This allows to avoid keeping the connection to the LDAP server if unused
 */
void
gda_ldap_may_unbind (GdaLdapConnection *cnc)
{
	gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */

	LdapConnectionData *cdata;
	cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc));
	if (!cdata || (cdata->keep_bound_count > 0)) {
		gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */
		return;
	}

	GdaServerProviderConnectionData *pcdata;
	pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL);

	GdaWorker *worker;
	worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata));

	GMainContext *context;
	context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc);

	gpointer retval;
	gda_worker_do_job (worker, context, 0, &retval, NULL,
			   (GdaWorkerFunc) worker_gda_ldap_may_unbind, (gpointer) cdata, NULL, NULL, NULL);
	if (context)
		g_main_context_unref (context);

	gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */

	gda_worker_unref (worker);
}
Exemple #3
0
/*
 * Test 2:
 */
static gpointer
test2_th (GdaConnection *cnc)
{
	/* setup main context */
	guint counter = 0;
	setup_main_context (cnc, 10, &counter);
#define LOCK_DELAY 50000
	gda_lockable_lock (GDA_LOCKABLE (cnc));
	/*g_print ("Locked by %p\n", g_thread_self());*/
	g_usleep (LOCK_DELAY);
	gda_lockable_unlock (GDA_LOCKABLE (cnc));
	g_thread_yield ();

	gda_lockable_lock (GDA_LOCKABLE (cnc));
	/*g_print ("Locked by %p\n", g_thread_self());*/
	g_usleep (LOCK_DELAY);
	gda_lockable_unlock (GDA_LOCKABLE (cnc));
	g_thread_yield ();

	gda_lockable_lock (GDA_LOCKABLE (cnc));
	/*g_print ("Locked by %p\n", g_thread_self());*/
	g_usleep (LOCK_DELAY);
	gda_lockable_unlock (GDA_LOCKABLE (cnc));
	g_thread_yield ();

	gda_lockable_lock (GDA_LOCKABLE (cnc));
	/*g_print ("Locked by %p\n", g_thread_self());*/
	g_usleep (LOCK_DELAY);
	gda_lockable_unlock (GDA_LOCKABLE (cnc));

	guint *ret;
	ret = g_new (guint, 1);
	*ret = counter;
	return ret;
}
Exemple #4
0
/**
 * gdaprov_ldap_get_class_info:
 * @cnc: a #GdaLdapConnection (not %NULL)
 * @classname: the class name (not %NULL)
 *
 * Returns: the #GdaLdapClass for @classname, or %NULL
 */
GdaLdapClass *
gdaprov_ldap_get_class_info (GdaLdapConnection *cnc, const gchar *classname)
{
	g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (cnc), NULL);
	g_return_val_if_fail (classname, NULL);

	gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */

	LdapConnectionData *cdata;
        cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc));
        if (!cdata) {
		gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */
                return NULL;
	}

	if (cdata->classes_hash) {
		gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */
		return g_hash_table_lookup (cdata->classes_hash, classname);
	}

	GdaServerProviderConnectionData *pcdata;
	pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL);

	GdaWorker *worker;
	worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata));

	GMainContext *context;
	context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc);

	WorkerLdapClassInfoData data;
	data.cnc = cnc;
	data.cdata = cdata;
	data.classname = classname;

	gda_connection_increase_usage ((GdaConnection*) cnc); /* USAGE ++ */
	gpointer retval;
	gda_worker_do_job (worker, context, 0, &retval, NULL,
			   (GdaWorkerFunc) worker_gdaprov_ldap_get_class_info, (gpointer) &data, NULL, NULL, NULL);
	if (context)
		g_main_context_unref (context);

	gda_connection_decrease_usage ((GdaConnection*) cnc); /* USAGE -- */
	gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */

	gda_worker_unref (worker);
	return (GdaLdapClass*) retval;
}
Exemple #5
0
GdaLdapEntry *
gdaprov_ldap_describe_entry (GdaLdapConnection *cnc, const gchar *dn, GError **error)
{
	g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (cnc), NULL);
	g_return_val_if_fail (!dn || (dn && *dn), NULL);

	gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */

	LdapConnectionData *cdata;
        cdata = (LdapConnectionData*) gda_virtual_connection_internal_get_provider_data (GDA_VIRTUAL_CONNECTION (cnc));
        if (!cdata) {
		gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */
                return NULL;
	}

	GdaServerProviderConnectionData *pcdata;
	pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL);

	GdaWorker *worker;
	worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata));

	GMainContext *context;
	context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc);

	WorkerLdapDescrEntryData data;
	data.cnc = cnc;
	data.cdata = cdata;
	data.dn = dn;

	gda_connection_increase_usage ((GdaConnection*) cnc); /* USAGE ++ */
	gpointer retval;
	gda_worker_do_job (worker, context, 0, &retval, NULL,
			   (GdaWorkerFunc) worker_gdaprov_ldap_describe_entry, (gpointer) &data, NULL, NULL, error);
	if (context)
		g_main_context_unref (context);

	gda_connection_decrease_usage ((GdaConnection*) cnc); /* USAGE -- */
	gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */

	gda_worker_unref (worker);
	return (GdaLdapEntry*) retval;
}
Exemple #6
0
/**
 * gda_ldap_get_attr_info:
 * @cnc: a #GdaLdapConnection
 * @cdata:
 * @attribute:
 *
 * Returns: (transfer none): the #LdapAttribute for @attribute, or %NULL
 */
LdapAttribute *
gda_ldap_get_attr_info (GdaLdapConnection *cnc, LdapConnectionData *cdata, const gchar *attribute)
{
	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
	if (! attribute || !cdata)
		return NULL;

	gda_lockable_lock ((GdaLockable*) cnc); /* CNC LOCK */

	GdaServerProviderConnectionData *pcdata;
	pcdata = gda_connection_internal_get_provider_data_error ((GdaConnection*) cnc, NULL);

	GdaWorker *worker;
	worker = gda_worker_ref (gda_connection_internal_get_worker (pcdata));

	GMainContext *context;
	context = gda_server_provider_get_real_main_context ((GdaConnection *) cnc);

	WorkerLdapAttrInfoData data;
	data.cnc = cnc;
	data.cdata = cdata;
	data.attribute = attribute;

	gda_connection_increase_usage ((GdaConnection*) cnc); /* USAGE ++ */
	gpointer retval;
	gda_worker_do_job (worker, context, 0, &retval, NULL,
			   (GdaWorkerFunc) worker_gda_ldap_get_attr_info, (gpointer) &data, NULL, NULL, NULL);
	if (context)
		g_main_context_unref (context);

	gda_connection_decrease_usage ((GdaConnection*) cnc); /* USAGE -- */
	gda_lockable_unlock ((GdaLockable*) cnc); /* CNC UNLOCK */

	gda_worker_unref (worker);
	return (LdapAttribute*) retval;
}