[Commits] ldap-plugin.c 1.2 1.3
miras at claws-mail.org
miras at claws-mail.org
Tue Oct 4 22:21:42 CEST 2011
Update of /home/claws-mail/contacts/plugins/ldap
In directory claws-mail:/tmp/cvs-serv4887/plugins/ldap
Modified Files:
ldap-plugin.c
Log Message:
2011-10-04 [mir] 0.6.0cvs20
* dbus-client/client.c
* plugins/example/example-plugin.c
* plugins/ldap/ldap-plugin.c
* plugins/xml/plugin-init.c
* plugins/xml/xml-plugin.c
* src/about.c
* src/callbacks.c
* src/claws-contacts.c
* src/contactwindow.c
* src/gtk-utils.c
* src/mainwindow.c
* src/plugin-loader.c
* src/plugin-loader.h
* src/plugin.h
* src/printing.c
* src/utils.c
* src/utils.h
* src/dbus/dbus-service.c
* src/dbus/server-object.c
* xmllib/parser.c
* xmllib/parser.h
- Implemented forgotten functionality to reactivate closed
address books.
- Fix a ton of bugs.
- Extended plugin API so that it is possible to get a list
of closed address books as well as splitting attributes
in mandatory and optional.
- Provide plugins a way to have a fixed set of attributes.
Eg. LDAP has a finite set of attributes while XML supports
an infinite set of attributes.
Index: ldap-plugin.c
===================================================================
RCS file: /home/claws-mail/contacts/plugins/ldap/ldap-plugin.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ldap-plugin.c 27 Sep 2011 17:13:04 -0000 1.2
+++ ldap-plugin.c 4 Oct 2011 20:21:40 -0000 1.3
@@ -48,10 +48,11 @@
static const gchar subtype[] = "LDAP support";
/* List of AddressBook */
static GList* abooks = NULL;
+/* List of closed AddressBook */
+static GList* closed_books = NULL;
/*
* HashTable containing names of supported attributes.
- * Currently only keys are used. can be extended to hold
- * AttribDef for each key
+ * Each keys holds an AttribDef.
*/
static GHashTable* attribs = NULL;
@@ -61,6 +62,10 @@
/* List of not active or inactive attributes this plugin supports*/
static GSList* remaining_attribs = NULL;
+static gchar self_home[] = "ldap";
+static gchar configrc[] = "ldaprc";
+static ConfigFile* config = NULL;
+
/**
* Free list of abooks.
* @param error Pointer to memory where error is supposed to be saved
@@ -274,8 +279,8 @@
*/
gboolean plugin_abook_close(AddressBook* abook, gchar** error) {
debug_print("List contains %d elements before\n", g_list_length(abooks));
- address_book_contacts_free(abook);
abooks = g_list_remove(abooks, abook);
+ address_book_contacts_free(abook);
debug_print("List contains %d elements after\n", g_list_length(abooks));
return TRUE;
}
@@ -342,15 +347,95 @@
}
/**
+ * Get list of closed address books. The list and data must be freed
+ * by the caller.
+ * @return GList of AddressBook
+ */
+GList* plugin_closed_books_get(void) {
+ GList *cur, *list = NULL;
+
+ for (cur = closed_books; cur; cur = g_list_next(cur)) {
+ }
+
+ return list;
+}
+
+/**
* Initialize plugin.
* @param Pointer to memory where error is supposed to be saved
* @return FALSE if success TRUE otherwise
*/
gboolean plugin_init(gchar** error) {
+ gchar *basedir, *path;
+ GSList *list = NULL, *cur;
+ ConfiguredBooks* cf_books;
+ ClosedBooks* cl_books;
+
if (*error != NULL) {
g_free(*error);
*error = NULL;
}
+
+ hash_table_free(&attribs);
+
+ basedir = get_self_home();
+ path = g_strconcat(
+ basedir, G_DIR_SEPARATOR_S, self_home,
+ G_DIR_SEPARATOR_S, configrc, NULL);
+
+ config = plugin_config_new(path);
+ config_get(config, error);
+
+ if (*error) {
+ show_message(NULL, GTK_UTIL_MESSAGE_ERROR, "%s", *error);
+ }
+ else {
+ if (config) {
+ cf_books = config->configured_books;
+ cl_books = config->closed_books;
+
+ if (cf_books) {
+ g_free(path);
+ path = g_strconcat(basedir, G_DIR_SEPARATOR_S,
+ self_home, G_DIR_SEPARATOR_S, NULL);
+ for (cur = cf_books->books; cur; cur = g_slist_next(cur)) {
+ gchar* book = (gchar *) cur->data;
+ if (! cl_books) {
+ AddressBook* abook = address_book_new();
+ abook->URL = g_strconcat(path, book, ".xml", NULL);
+ plugin_abook_open(abook, error);
+ }
+ }
+ }
+ config_get_value(config, "supported attributes", "attributes", &list);
+ attribs = hash_table_new();
+ for (cur = list; cur; cur = g_slist_next(cur)) {
+ gchar* key = (gchar *) cur->data;
+ debug_print("Adding '%s' to attributes\n", key);
+ AttribDef* attr = g_new0(AttribDef, 1);
+ attr->attrib_name = g_strdup(key);
+ attr->type = ATTRIB_TYPE_STRING;
+ g_hash_table_replace(attribs, g_strdup(key), attr);
+ }
+ gslist_free(&list, g_free);
+
+ config_get_value(config, "deactivated attributes", "attributes", &list);
+ for (cur = list; cur; cur = g_slist_next(cur)) {
+ gchar* key = (gchar *) cur->data;
+ debug_print("Adding '%s' to deactivated attributes\n", key);
+ AttribDef* attr = g_new0(AttribDef, 1);
+ attr->attrib_name = g_strdup(key);
+ attr->type = ATTRIB_TYPE_STRING;
+ inactive_attribs = g_slist_prepend(inactive_attribs, attr);
+ }
+ gslist_free(&list, g_free);
+
+ //hash_table_dump(attribs, stderr);
+ }
+ }
+ g_free(basedir);
+ g_free(path);
+
return FALSE;
}
More information about the Commits
mailing list