Top |
This is a connection, as opened by the LDAP provider. Use
gda_connection_open_from_string()
or gda_connection_open_from_dsn()
to create
a GdaLdapConnection connection.
Warning: if you create a GdaLdapConnection using g_object_new()
, then the resulting
object won't be functionnal.
A GdaLdapConnection is a virtual connection which accepts any of SQLite's SQL dialect. However, some SQL commands have been added to manipulate virtual tables mapped to LDAP searches. These commands are:
The CREATE LDAP TABLE:
CREATE LDAP TABLE <table name> [BASE=<base DN>] [FILTER=<LDAP filter>] [ATTRIBUTES=<LDAP attributes>] [SCOPE=<search scope>]
Each of the BASE, FILTER, ATTRIBUTES and SCOPE specifications is optional. Use this command to declare a table, for example:
CREATE LDAP TABLE users FILTER='(cn=*doe*)' SCOPE= 'SUBTREE';
. The allowed SCOPE values are: 'BASE', 'ONELEVEL' and 'SUBTREE'.
See the gda_ldap_connection_declare_table()
for more information about the ATTRIBUTES syntax.
The DROP LDAP TABLE:
DROP LDAP TABLE <table name>
Use this command to undeclare a table, for example:
DROP LDAP TABLE users;
Note that it is also possible to use the normal command to remove a table:
DROP TABLE users;
The ALTER LDAP TABLE:
ALTER LDAP TABLE <table name>
or
ALTER LDAP TABLE <table name> [BASE=<base DN>] [FILTER=<LDAP filter>] [ATTRIBUTES=<LDAP attributes>] [SCOPE=<search scope>]
Use this command to modify the definition of a virtual table, for example:
ALTER LDAP TABLE users FILTER='(cn=*doe*)' SCOPE='BASE';
If no argument is specified after the table name, then the definition of the virtual table is returned instead. When altering the virtual table, only the specified parameters are altered (ie. you don't need to repeat the parameters you don't want to be modified)
The DESCRIBE LDAP TABLE:
DESCRIBE LDAP TABLE <table name>
Use this command to get the definition of the virtual table.
Each "LDAP" table can then be used like any other table, but you should keep in mind that Libgda can optimize the LDAP search command executed when the table's data is actually read if you use a "WHERE" clause which involves a search criteria on an LDAP attribute. For example the following SQL:
SELECT * FROM users WHERE cn MATCH 'doe
%';
will actually be optimized by requesting an LDAP search with the filter
(cn=*doe*)
Optimizations can be done on MATCH, =, <, <=, > and >= operators, the LIKE operator will not be optimized.
However a command like
SELECT * FROM users WHERE cn MATCH 'doe
%' OR uid=123;
can't be optimized (because of the "OR") whereas the
SELECT * FROM users WHERE cn MATCH '%doe%' AND uid=123;
will be optimized because of the "AND".
const gchar *
gda_ldap_connection_get_base_dn (GdaLdapConnection *cnc
);
Get the base DN which was used when the LDAP connection was opened
Since: 4.2.8
gboolean gda_ldap_connection_declare_table (GdaLdapConnection *cnc
,const gchar *table_name
,const gchar *base_dn
,const gchar *filter
,const gchar *attributes
,GdaLdapSearchScope scope
,GError **error
);
Declare a virtual table based on an LDAP search.
The filter
argument, if not NULL
, must be a valid LDAP filter string (including the opening and
closing parenthesis).
The attribute
, if not NULL
, is a list of comma separated LDAP entry attribute names. For each attribute
it is also possible to specify a requested GType, and how to behave in case of multi valued attributes
So the general format for an attribute is:
"<attribute name>::<type>", where:
"::<type>" is optional, see gda_g_type_from_string()
for more
information about valie values for <type>
"::<muti value handler>" is also optional and specifies how a multi values attributed is treated. The possibilities for <muti value handler> are:
"NULL" or "0": a NULL value will be returned
"CSV": a comma separated value with all the values of the attribute will be returned. This only works for G_TYPE_STRING attribute types.
"MULT" of "*": a row will be returned for each value of the attribute, effectively multiplying the number of returned rows
"1": only the first vakue of the attribute will be used, the other values ignored
"CONCAT": the attributes' values are concatenated (with a newline char between each value)
"ERROR": an error value will be returned (this is the default behaviour)
After each attribute
name (and before the comma for the next attribute if any), it is possible to specify the GType type using
the "::<type>" syntax (see gda_g_type_from_string()
for more information).
The following example specifies the "uidNumber" attribute to be returned as a string, the "mail" attribute, and the "objectClass" attribute to be handled as one row per value of that attribute:
"uidNumber::string,mail,objectClass::*"
cnc |
||
table_name |
a table name, not |
|
base_dn |
the base DN of the LDAP search, or |
[allow-none] |
filter |
the search filter of the LDAP search, or |
[allow-none] |
attributes |
the search attributes of the LDAP search, or |
[allow-none] |
scope |
the search scope of the LDAP search |
|
error |
a place to store errors, or |
Since: 4.2.8
gboolean gda_ldap_connection_undeclare_table (GdaLdapConnection *cnc
,const gchar *table_name
,GError **error
);
Remove a table which has been declared using gda_ldap_connection_declare_table()
.
Since: 4.2.8
gboolean
gda_ldap_is_dn (const gchar *dn
);
Tells if dn
represents a distinguished name (it only checks for the syntax, not for
the actual existence of the entry with that distinguished name).
Since: 4.2.8
gchar ** gda_ldap_dn_split (const gchar *dn
,gboolean all
);
Splits dn
into its components.
a NULL
terminated array containing the DN parts (free using g_strfreev()
), or NULL
if an error occurred because dn
is not a valid DN expression.
[transfer full][Free-function: g_strfreev]
Since: 4.2.8
GdaLdapEntry * gda_ldap_describe_entry (GdaLdapConnection *cnc
,const gchar *dn
,GError **error
);
Describes the LDAP entry which DN is dn
. If dn
is NULL
, then the top entry (as specified when
the LDAP connection was opened) is described.
cnc |
a GdaLdapConnection connection |
|
dn |
the Distinguished Name of the LDAP entry to describe. |
[allow-none] |
error |
a place to store errors, or |
[allow-none] |
a new GdaLdapEntry, or NULL
if an error occurred or if the dn
entry does not exist.
[transfer full][Free-function: gda_ldap_entry_free]
Since: 4.2.8
GdaLdapEntry ** gda_ldap_get_entry_children (GdaLdapConnection *cnc
,const gchar *dn
,gchar **attributes
,GError **error
);
Get the list of children entries for the LDAP entry which DN is dn
. If the dn
entry does not have any
child, then this function returns an array which first element is NULL
.
If dn
is NULL
, then the top entry (as specified when the LDAP connection was opened) is used.
cnc |
a GdaLdapConnection connection |
|
dn |
the Distinguished Name of the LDAP entry to get children from. |
[allow-none] |
attributes |
a |
[allow-none][array zero-terminated=1][element-type gchar*] |
error |
a place to store errors, or |
[allow-none] |
a NULL
terminated array of GdaLdapEntry for each child entry, or NULL
if an error occurred or if the dn
entry does not exist.
[transfer full][element_type GdaLdapEntry][array zero-terminated=1]
Since: 4.2.8
void gda_ldap_entry_add_attribute (GdaLdapEntry *entry
,gboolean merge
,const gchar *attr_name
,guint nb_values
,GValue **values
);
Add an attribute (ans its values) to entry
. If the attribute is already present in entry
,
then the attribute's values are merged or replaced depending on the merge
argument.
entry |
a GdaLdapEntry pointer |
|
merge |
set to |
|
attr_name |
the name of the attribute to add |
|
nb_values |
number of values in |
|
values |
an array of GValue (as much values as specified by |
[array length=nb_values] |
Since: 5.2.0
GdaLdapEntry *
gda_ldap_entry_new (const gchar *dn
);
Creates a new GdaLdapEntry. This function is useful when using gda_ldap_modify_entry()
Since: 5.2.0
GSList * gda_ldap_entry_get_attributes_list (GdaLdapConnection *cnc
,GdaLdapEntry *entry
);
Get a list of all the possible attributes which entry
can have. Each possible attribute is represented
by a GdaLdapAttributeDefinition strunture.
a GSList of GdaLdapAttributeDefinition pointers, free the list using gda_ldap_attributes_list_free()
.
[transfer full][element-type GdaLdapAttributeDefinition]
Since: 5.2.0
void
gda_ldap_attributes_list_free (GSList *list
);
Frees the list returned by gda_ldap_entry_get_attributes_list()
.
Since: 5.2.0
gboolean gda_ldap_add_entry (GdaLdapConnection *cnc
,GdaLdapEntry *entry
,GError **error
);
Creates a new LDAP entry.
cnc |
||
entry |
a GdaLDapEntry describing the LDAP entry to add |
|
error |
a place to store an error, or |
[allow-none] |
Since: 5.2.0
gboolean gda_ldap_remove_entry (GdaLdapConnection *cnc
,const gchar *dn
,GError **error
);
Delete an LDAP entry.
cnc |
||
entry |
a GdaLDapEntry describing the LDAP entry to remove |
|
error |
a place to store an error, or |
[allow-none] |
Since: 5.2.0
gboolean gda_ldap_rename_entry (GdaLdapConnection *cnc
,const gchar *current_dn
,const gchar *new_dn
,GError **error
);
Renames an LDAP entry.
cnc |
||
current_dn |
the current DN of the entry |
|
new_dn |
the new DN of the entry |
|
error |
a place to store an error, or |
[allow-none] |
Since: 5.2.0
gboolean gda_ldap_modify_entry (GdaLdapConnection *cnc
,GdaLdapModificationType modtype
,GdaLdapEntry *entry
,GdaLdapEntry *ref_entry
,GError **error
);
Modifies an LDAP entry.
cnc |
||
modtype |
the type of modification to perform |
|
entry |
a GdaLDapEntry describing the LDAP entry to apply modifications, along with the attributes which will be modified |
|
ref_entry |
a GdaLDapEntry describing the reference LDAP entry, if |
[allow-none] |
error |
a place to store an error, or |
[allow-none] |
Since: 5.2.0
GdaLdapClass * gda_ldap_get_class_info (GdaLdapConnection *cnc
,const gchar *classname
);
Get information about an LDAP class
Since: 4.2.8
const GSList *
gda_ldap_get_top_classes (GdaLdapConnection *cnc
);
get a list of the top level LDAP classes (ie. classes which don't have any parent)
a list of GdaLdapClass pointers (don't modify it).
[transfer none][element-type GdaLdapClass]
Since: 4.2.8
struct GdaLdapConnection { GdaVconnectionDataModel parent; GdaLdapConnectionPrivate *priv; };
struct GdaLdapConnectionClass { GdaVconnectionDataModelClass parent_class; };
typedef struct { gchar *attr_name; guint nb_values; GValue **values; } GdaLdapAttribute;
This structure holds information about the values of a single attribute (of a single LDAP entry).
typedef struct { gchar *dn; guint nb_attributes; GdaLdapAttribute **attributes; GHashTable *attributes_hash; } GdaLdapEntry;
This structure holds information about the attributes of a single LDAP entry.
gchar * |
the Distinguished Name of the entry |
|
guint |
the number of attributes in |
|
GdaLdapAttribute ** |
the entry's attributes, (terminated by a |
[allow-none][array length=nb_attributes][array zero-terminated=1] |
GHashTable * |
a hash table where the key is an attribute name, and the value the correcponding GdaLdapAttribute |
typedef struct { gchar *name; GType g_type; gboolean required; } GdaLdapAttributeDefinition;
Speficies the type of operation requested when writing to an LDAP directory.
modification corresponds to a new LDAP entry |
||
modification corresponds to removing an LDAP entry |
||
modification correspond to adding attributes to an existing LDAP entry |
||
modification correspond to removing attributes from an existing LDAP entry |
||
modification correspond to replacing attributes of an existing LDAP entry |
||
modification correspond to modifying attributes to an existing LDAP entry |
typedef struct { gchar *oid; guint nb_names; /* always >= 1 */ gchar **names; gchar *description; GdaLdapClassKind kind; gboolean obsolete; guint nb_req_attributes; gchar **req_attributes; guint nb_opt_attributes; gchar **opt_attributes; GSList *parents; /* list of #GdaLdapClass */ GSList *children; /* list of #GdaLdapClass */ } GdaLdapClass;
Represents an LDAP declared class.
gchar * |
the OID of the class |
|
guint |
the number of values in |
|
gchar ** |
all the class names |
|
gchar * |
the class's description, or |
[allow-none] |
GdaLdapClassKind |
the class kind |
|
gboolean |
defines is LDAP class is obsolete |
|
guint |
the number of values in |
|
gchar ** |
names of required attributes in class |
|
guint |
the number of values in |
|
gchar ** |
names of optional attributes in class |
|
GSList * |
GSList of the parent classes (pointers to GdaLdapClass) |
|
GSList * |
GSList of the children classes (pointers to GdaLdapClass) |