![]() |
![]() |
![]() |
GNOME Data Access 5 manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces | Properties |
#include <virtual/gda-ldap-connection.h> struct GdaLdapConnection; struct GdaLdapConnectionClass; GdaLdapConnectionPrivate; const gchar * gda_ldap_connection_get_base_dn (GdaLdapConnection *cnc
); 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
); gboolean gda_ldap_connection_undeclare_table (GdaLdapConnection *cnc
,const gchar *table_name
,GError **error
); GdaLdapAttribute; GdaLdapEntry; gboolean gda_ldap_is_dn (const gchar *dn
); gchar ** gda_ldap_dn_split (const gchar *dn
,gboolean all
); GdaLdapEntry * gda_ldap_describe_entry (GdaLdapConnection *cnc
,const gchar *dn
,GError **error
); void gda_ldap_entry_free (GdaLdapEntry *entry
); GdaLdapEntry ** gda_ldap_get_entry_children (GdaLdapConnection *cnc
,const gchar *dn
,gchar **attributes
,GError **error
); enum GdaLdapClassKind; GdaLdapClass; GdaLdapClass * gda_ldap_get_class_info (GdaLdapConnection *cnc
,const gchar *classname
); const GSList * gda_ldap_get_top_classes (GdaLdapConnection *cnc
);
GObject +----GdaConnection +----GdaVirtualConnection +----GdaVconnectionDataModel +----GdaLdapConnection
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".
struct GdaLdapConnectionClass { GdaVconnectionDataModelClass parent_class; };
const gchar * gda_ldap_connection_get_base_dn (GdaLdapConnection *cnc
);
Get the base DN which was used when the LDAP connection was opened
|
a GdaLdapConnection |
Returns : |
the base DN, or NULL
|
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>][::<muti value handler>]", 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::*"
|
a GdaLdapConnection |
|
a table name, not NULL
|
|
the base DN of the LDAP search, or NULL for cnc 's own base DN. [allow-none]
|
|
the search filter of the LDAP search, or NULL for a default filter of "(ObjectClass=*)". [allow-none]
|
|
the search attributes of the LDAP search, or NULL if only the DN is required. [allow-none]
|
|
the search scope of the LDAP search |
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred |
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()
.
|
a GdaLdapConnection |
|
a table name, not NULL
|
|
a place to store errors, or NULL
|
Returns : |
TRUE if no error occurred |
Since 4.2.8
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).
the name of the attribute | |
the number of values in values , or 0
|
|
the attribute' values as GValue values, (terminated by a NULL ). [allow-none][array length=nb_values][array zero-terminated=1]
|
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.
the Distinguished Name of the entry | |
the number of attributes in attributes , or 0
|
|
GdaLdapAttribute ** |
the entry's attributes, (terminated by a NULL ). [allow-none][array length=nb_attributes][array zero-terminated=1]
|
a hash table where the key is an attribute name, and the value the correcponding GdaLdapAttribute |
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).
|
a Distinguished Name string |
Returns : |
TRUE if dn is a valid representation of a distinguished name |
Since 4.2.8
gchar ** gda_ldap_dn_split (const gchar *dn
,gboolean all
);
Splits dn
into its components.
|
a Distinguished Name string |
|
set to FALSE to split dn into its RND and its parent DN, or TRUE to completely split dn
|
Returns : |
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.
|
a GdaLdapConnection connection |
|
the Distinguished Name of the LDAP entry to describe. [allow-none] |
|
a place to store errors, or NULL . [allow-none]
|
Returns : |
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
void gda_ldap_entry_free (GdaLdapEntry *entry
);
Frees entry
|
a GdaLdapEntry pointer. [transfer full] |
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.
|
a GdaLdapConnection connection |
|
the Distinguished Name of the LDAP entry to get children from. [allow-none] |
|
a NULL terminated array of attributes to fetch for each child, or NULL if no attribute is requested. [allow-none][array zero-terminated=1][element-type gchar*]
|
|
a place to store errors, or NULL . [allow-none]
|
Returns : |
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
typedef enum { GDA_LDAP_CLASS_KIND_ABSTRACT = 1, GDA_LDAP_CLASS_KIND_STRUTURAL = 2, GDA_LDAP_CLASS_KIND_AUXILIARY = 3, GDA_LDAP_CLASS_KIND_UNKNOWN = 4 } GdaLdapClassKind;
Defines the LDAP class type
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 #LdapClass */ GSList *children; /* list of #LdapClass */ } GdaLdapClass;
Represents an LDAP declared class.
the OID of the class | |
the number of values in values (always >= 1) |
|
all the class names | |
the class's description, or NULL . [allow-none]
|
|
GdaLdapClassKind |
the class kind |
defines is LDAP class is obsolete | |
the number of values in req_attributes
|
|
names of required attributes in class | |
the number of values in opt_attributes
|
|
names of optional attributes in class | |
GSList of the parent classes (pointers to GdaLdapClass) | |
GSList of the children classes (pointers to GdaLdapClass) |
GdaLdapClass * gda_ldap_get_class_info (GdaLdapConnection *cnc
,const gchar *classname
);
Get information about an LDAP class
|
a GdaLdapConnection |
|
an LDAP class name |
Returns : |
a GdaLdapClass. [transfer none] |
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 GdaLdapConnection |
Returns : |
a list of GdaLdapClass pointers (don't modify it). [transfer none][element-type GdaLdapClass] |
Since 4.2.8