diff options
Diffstat (limited to 'addressbook/backend/pas')
-rw-r--r-- | addressbook/backend/pas/.cvsignore | 11 | ||||
-rw-r--r-- | addressbook/backend/pas/Makefile.am | 53 | ||||
-rw-r--r-- | addressbook/backend/pas/TODO | 2 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 1443 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.h | 32 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-ldap.c | 1846 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-ldap.h | 32 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend.c | 178 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend.h | 77 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book-factory.c | 595 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book-factory.h | 50 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book-view.c | 334 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book-view.h | 55 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.c | 754 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-book.h | 101 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-card-cursor.c | 227 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-card-cursor.h | 58 |
17 files changed, 0 insertions, 5848 deletions
diff --git a/addressbook/backend/pas/.cvsignore b/addressbook/backend/pas/.cvsignore deleted file mode 100644 index 071cef99ae..0000000000 --- a/addressbook/backend/pas/.cvsignore +++ /dev/null @@ -1,11 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -addressbook-stubs.c -addressbook-skels.c -addressbook-common.c -addressbook.h -*.lo -*.la diff --git a/addressbook/backend/pas/Makefile.am b/addressbook/backend/pas/Makefile.am deleted file mode 100644 index 819f99e57d..0000000000 --- a/addressbook/backend/pas/Makefile.am +++ /dev/null @@ -1,53 +0,0 @@ -CORBA_SOURCE = \ - addressbook.h \ - addressbook-common.c \ - addressbook-stubs.c \ - addressbook-skels.c - -idls = \ - $(srcdir)/../idl/addressbook.idl - -idl_flags = `$(GNOME_CONFIG) --cflags idl` -I $(datadir)/idl - -$(CORBA_SOURCE): $(idls) - $(ORBIT_IDL) $(srcdir)/../idl/addressbook.idl $(idl_flags) - -INCLUDES = \ - -DGNOMELOCALEDIR=\""$(localedir)"\" \ - -DG_LOG_DOMAIN=\"wombat-pas\" \ - -I$(top_srcdir) \ - -I$(top_srcdir)/addressbook/backend \ - -I$(top_builddir)/addressbook/backend \ - $(BONOBO_GNOME_CFLAGS) \ - $(EXTRA_GNOME_CFLAGS) - -LDAP_BACKEND_SOURCES = pas-backend-ldap.c pas-backend-ldap.h - -if ENABLE_LDAP -LDAP_BACKEND = $(LDAP_BACKEND_SOURCES) -else -LDAP_BACKEND = -endif - -noinst_LIBRARIES = libpas.a - -libpas_a_SOURCES = \ - $(CORBA_SOURCE) \ - pas-book-factory.c \ - pas-book-factory.h \ - pas-book-view.c \ - pas-book-view.h \ - pas-book.c \ - pas-book.h \ - pas-backend-file.c \ - pas-backend-file.h \ - $(LDAP_BACKEND) \ - pas-backend.c \ - pas-backend.h \ - pas-card-cursor.c \ - pas-card-cursor.h - -BUILT_SOURCES = $(CORBA_SOURCE) -CLEANFILES += $(BUILT_SOURCES) - -EXTRA_DIST = $(LDAP_BACKEND_SOURCES) diff --git a/addressbook/backend/pas/TODO b/addressbook/backend/pas/TODO deleted file mode 100644 index 0c77c1b200..0000000000 --- a/addressbook/backend/pas/TODO +++ /dev/null @@ -1,2 +0,0 @@ -* Implement pas_book_factory_activate -* Authentication
\ No newline at end of file diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c deleted file mode 100644 index 84a21d4c6f..0000000000 --- a/addressbook/backend/pas/pas-backend-file.c +++ /dev/null @@ -1,1443 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Author: - * Nat Friedman (nat@helixcode.com) - * - * Copyright 2000, Helix Code, Inc. - */ - -#include "config.h" -#include <gtk/gtksignal.h> -#include <unistd.h> -#include <fcntl.h> -#include <time.h> -#ifdef HAVE_DB_185_H -#include <db_185.h> -#else -#ifdef HAVE_DB1_DB_H -#include <db1/db.h> -#else -#include <db.h> -#endif -#endif - -#include "pas-backend-file.h" -#include "pas-book.h" -#include "pas-card-cursor.h" -#include <ebook/e-card-simple.h> -#include <e-util/e-sexp.h> -#include <gal/util/e-util.h> -#include <gal/widgets/e-unicode.h> - -#define PAS_BACKEND_FILE_VERSION_NAME "PAS-DB-VERSION" -#define PAS_BACKEND_FILE_VERSION "0.1" - -static PASBackendClass *pas_backend_file_parent_class; -typedef struct _PASBackendFileCursorPrivate PASBackendFileCursorPrivate; -typedef struct _PASBackendFileBookView PASBackendFileBookView; -typedef struct _PASBackendFileSearchContext PASBackendFileSearchContext; - -struct _PASBackendFilePrivate { - GList *clients; - gboolean loaded; - char *uri; - DB *file_db; - EList *book_views; -}; - -struct _PASBackendFileCursorPrivate { - PASBackend *backend; - PASBook *book; - - GList *elements; - guint32 num_elements; -}; - -struct _PASBackendFileBookView { - PASBookView *book_view; - gchar *search; - ESExp *search_sexp; - PASBackendFileSearchContext *search_context; -}; - -struct _PASBackendFileSearchContext { - ECardSimple *card; -}; - -static PASBackendFileBookView * -pas_backend_file_book_view_copy(const PASBackendFileBookView *book_view, void *closure) -{ - PASBackendFileBookView *new_book_view; - new_book_view = g_new(PASBackendFileBookView, 1); - new_book_view->book_view = book_view->book_view; - new_book_view->search = g_strdup(book_view->search); - new_book_view->search_sexp = book_view->search_sexp; - if (new_book_view->search_sexp) - gtk_object_ref(GTK_OBJECT(new_book_view->search_sexp)); - new_book_view->search_context = g_new(PASBackendFileSearchContext, 1); - new_book_view->search_context->card = book_view->search_context->card; - return new_book_view; -} - -static void -pas_backend_file_book_view_free(PASBackendFileBookView *book_view, void *closure) -{ - g_free(book_view->search); - if (book_view->search_sexp) - gtk_object_unref(GTK_OBJECT(book_view->search_sexp)); - g_free(book_view->search_context); - g_free(book_view); -} - -static long -get_length(PASCardCursor *cursor, gpointer data) -{ - PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; - - return cursor_data->num_elements; -} - -static char * -get_nth(PASCardCursor *cursor, long n, gpointer data) -{ - PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; - GList *nth_item = g_list_nth(cursor_data->elements, n); - - return g_strdup((char*)nth_item->data); -} - -static void -cursor_destroy(GtkObject *object, gpointer data) -{ - CORBA_Environment ev; - Evolution_Book corba_book; - PASBackendFileCursorPrivate *cursor_data = (PASBackendFileCursorPrivate *) data; - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(cursor_data->book)); - - CORBA_exception_init(&ev); - - Evolution_Book_unref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("cursor_destroy: Exception unreffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); - - g_list_foreach(cursor_data->elements, (GFunc)g_free, NULL); - g_list_free (cursor_data->elements); - - g_free(cursor_data); -} - -static void -view_destroy(GtkObject *object, gpointer data) -{ - CORBA_Environment ev; - Evolution_Book corba_book; - PASBook *book = (PASBook *)data; - PASBackendFile *bf; - EIterator *iterator; - - bf = PAS_BACKEND_FILE(pas_book_get_backend(book)); - for (iterator = e_list_get_iterator(bf->priv->book_views); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const PASBackendFileBookView *view = e_iterator_get(iterator); - if (view->book_view == PAS_BOOK_VIEW(object)) { - e_iterator_delete(iterator); - break; - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(book)); - - CORBA_exception_init(&ev); - - Evolution_Book_unref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("view_destroy: Exception unreffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); -} - -static void -string_to_dbt(const char *str, DBT *dbt) -{ - dbt->data = (void*)str; - dbt->size = strlen (str) + 1; -} - -static char * -pas_backend_file_create_unique_id (char *vcard) -{ - /* use a 32 counter and the 32 bit timestamp to make an id. - it's doubtful 2^32 id's will be created in a second, so we - should be okay. */ - static guint c = 0; - return g_strdup_printf ("pas-id-%08lX%08X", time(NULL), c++); -} - -static gboolean -compare_email (ECardSimple *card, const char *str, - char *(*compare)(const char*, const char*)) -{ - int i; - - for (i = E_CARD_SIMPLE_EMAIL_ID_EMAIL; i < E_CARD_SIMPLE_EMAIL_ID_LAST; i ++) { - const char *email = e_card_simple_get_email (card, i); - - if (email && compare(email, str)) - return TRUE; - } - - return FALSE; -} - -static gboolean -compare_phone (ECardSimple *card, const char *str, - char *(*compare)(const char*, const char*)) -{ - int i; - - for (i = E_CARD_SIMPLE_PHONE_ID_ASSISTANT; i < E_CARD_SIMPLE_PHONE_ID_LAST; i ++) { - const ECardPhone *phone = e_card_simple_get_phone (card, i); - - if (phone && compare(phone->number, str)) - return TRUE; - } - - return FALSE; -} - -static gboolean -compare_address (ECardSimple *card, const char *str, - char *(*compare)(const char*, const char*)) -{ - g_warning("address searching not implemented\n"); - return FALSE; -} - -static struct prop_info { - ECardSimpleField field_id; - const char *query_prop; - const char *ecard_prop; -#define PROP_TYPE_NORMAL 0x01 -#define PROP_TYPE_LIST 0x02 -#define PROP_TYPE_LISTITEM 0x03 - int prop_type; - gboolean (*list_compare)(ECardSimple *ecard, const char *str, - char *(*compare)(const char*, const char*)); - -} prop_info_table[] = { -#define NORMAL_PROP(f,q,e) {f, q, e, PROP_TYPE_NORMAL, NULL} -#define LIST_PROP(q,e,c) {0, q, e, PROP_TYPE_LIST, c} - - /* query prop, ecard prop, type, list compare function */ - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_FILE_AS, "file_as", "file_as" ), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "full_name" ), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_URL, "url", "url" ), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_MAILER, "mailer", "mailer"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ORG, "org", "org"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ORG_UNIT, "org_unit", "org_unit"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_OFFICE, "office", "office"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_TITLE, "title", "title"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ROLE, "role", "role"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_MANAGER, "manager", "manager"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_ASSISTANT, "assistant", "assistant"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_NICKNAME, "nickname", "nickname"), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_SPOUSE, "spouse", "spouse" ), - NORMAL_PROP ( E_CARD_SIMPLE_FIELD_NOTE, "note", "note"), - LIST_PROP ( "email", "email", compare_email ), - LIST_PROP ( "phone", "phone", compare_phone ), - LIST_PROP ( "address", "address", compare_address ), -}; -static int num_prop_infos = sizeof(prop_info_table) / sizeof(prop_info_table[0]); - -static ESExpResult * -entry_compare(PASBackendFileSearchContext *ctx, struct _ESExp *f, - int argc, struct _ESExpResult **argv, - char *(*compare)(const char*, const char*)) -{ - ESExpResult *r; - int truth = FALSE; - - if (argc == 2 - && argv[0]->type == ESEXP_RES_STRING - && argv[1]->type == ESEXP_RES_STRING) { - char *propname; - struct prop_info *info = NULL; - int i; - gboolean any_field; - - propname = argv[0]->value.string; - - any_field = !strcmp(propname, "x-evolution-any-field"); - for (i = 0; i < num_prop_infos; i ++) { - if (any_field - || !strcmp (prop_info_table[i].query_prop, propname)) { - info = &prop_info_table[i]; - - if (info->prop_type == PROP_TYPE_NORMAL) { - char *prop = NULL; - /* searches where the query's property - maps directly to an ecard property */ - - prop = e_card_simple_get (ctx->card, info->field_id); - - if (prop && compare(prop, argv[1]->value.string)) { - truth = TRUE; - } - if ((!prop) && compare("", argv[1]->value.string)) { - truth = TRUE; - } - } - else if (info->prop_type == PROP_TYPE_LIST) { - /* the special searches that match any of the list elements */ - truth = info->list_compare (ctx->card, argv[1]->value.string, compare); - } - - /* if we're looking at all fields and find a match, - or if we're just looking at this one field, - break. */ - if ((any_field && truth) - || !any_field) - break; - } - } - - } - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = truth; - - return r; -} - -static ESExpResult * -func_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - PASBackendFileSearchContext *ctx = data; - - return entry_compare (ctx, f, argc, argv, (char *(*)(const char*, const char*)) e_utf8_strstrcase); -} - -static char * -is_helper (const char *s1, const char *s2) -{ - if (!strcmp(s1, s2)) - return (char*)s1; - else - return NULL; -} - -static ESExpResult * -func_is(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - PASBackendFileSearchContext *ctx = data; - - return entry_compare (ctx, f, argc, argv, is_helper); -} - -static char * -endswith_helper (const char *s1, const char *s2) -{ - char *p; - if ((p = strstr(s1, s2)) - && (strlen(p) == strlen(s2))) - return p; - else - return NULL; -} - -static ESExpResult * -func_endswith(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - PASBackendFileSearchContext *ctx = data; - - return entry_compare (ctx, f, argc, argv, endswith_helper); -} - -static char * -beginswith_helper (const char *s1, const char *s2) -{ - char *p; - if ((p = strstr(s1, s2)) - && (p == s1)) - return p; - else - return NULL; -} - -static ESExpResult * -func_beginswith(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - PASBackendFileSearchContext *ctx = data; - - return entry_compare (ctx, f, argc, argv, beginswith_helper); -} - -/* 'builtin' functions */ -static struct { - char *name; - ESExpFunc *func; - int type; /* set to 1 if a function can perform shortcut evaluation, or - doesn't execute everything, 0 otherwise */ -} symbols[] = { - { "contains", func_contains, 0 }, - { "is", func_is, 0 }, - { "beginswith", func_beginswith, 0 }, - { "endswith", func_endswith, 0 }, -}; - -static gboolean -vcard_matches_search (const PASBackendFileBookView *view, char *vcard_string) -{ - ESExpResult *r; - gboolean retval; - ECard *card; - - card = e_card_new (vcard_string); - view->search_context->card = e_card_simple_new (card); - gtk_object_unref(GTK_OBJECT(card)); - - /* if it's not a valid vcard why is it in our db? :) */ - if (!view->search_context->card) - return FALSE; - - r = e_sexp_eval(view->search_sexp); - - retval = (r && r->type == ESEXP_RES_BOOL && r->value.bool); - - - gtk_object_unref(GTK_OBJECT(view->search_context->card)); - - e_sexp_result_free(r); - - return retval; -} - -static void -pas_backend_file_search (PASBackendFile *bf, - PASBook *book, - const PASBackendFileBookView *cnstview) -{ - int db_error = 0; - GList *cards = NULL; - DB *db = bf->priv->file_db; - DBT id_dbt, vcard_dbt; - int i; - PASBackendFileBookView *view = (PASBackendFileBookView *)cnstview; - - if (!bf->priv->loaded) - return; - - if (view->search_sexp) - gtk_object_unref(GTK_OBJECT(view->search_sexp)); - view->search_sexp = e_sexp_new(); - - for(i=0;i<sizeof(symbols)/sizeof(symbols[0]);i++) { - if (symbols[i].type == 1) { - e_sexp_add_ifunction(view->search_sexp, 0, symbols[i].name, - (ESExpIFunc *)symbols[i].func, view->search_context); - } else { - e_sexp_add_function(view->search_sexp, 0, symbols[i].name, - symbols[i].func, view->search_context); - } - } - - e_sexp_input_text(view->search_sexp, view->search, strlen(view->search)); - e_sexp_parse(view->search_sexp); - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_FIRST); - - while (db_error == 0) { - - /* don't include the version in the list of cards */ - if (id_dbt.size != strlen(PAS_BACKEND_FILE_VERSION_NAME) + 1 - || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { - char *vcard_string = vcard_dbt.data; - - /* check if the vcard matches the search sexp */ - if (vcard_matches_search (view, vcard_string)) { - cards = g_list_append (cards, strdup(vcard_string)); - } - } - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_NEXT); - } - - if (db_error == -1) { - g_warning ("pas_backend_file_search: error building list\n"); - } - else { - pas_book_view_notify_add (view->book_view, cards); - pas_book_view_notify_complete (view->book_view); - } - - /* - ** It's fine to do this now since the data has been handed off. - */ - g_list_foreach (cards, (GFunc)g_free, NULL); - g_list_free (cards); -} - -typedef enum { - VCardChangeNone, - VCardChangeAdded, - VCardChangeModified, - VCardChangeDeleted -} VCardChangeType; - -static VCardChangeType -vcard_change_type (const PASBackendFileBookView *view, char *vcard_string) -{ - ECard *card; - - card = e_card_new (vcard_string); - view->search_context->card = e_card_simple_new (card); - gtk_object_unref(GTK_OBJECT(card)); - - /* if it's not a valid vcard why is it in our db? :) */ - if (!view->search_context->card) - return VCardChangeNone; - - /* FIX ME, actually need to implement this */ - - gtk_object_unref(GTK_OBJECT(view->search_context->card)); - - return VCardChangeNone; -} - -static void -pas_backend_file_search_changes (PASBackendFile *bf, - PASBook *book, - const PASBackendFileBookView *cnstview) -{ - int db_error = 0; - GList *add_cards = NULL; - GList *mod_cards = NULL; - GList *del_cards = NULL; - DB *db = bf->priv->file_db; - DBT id_dbt, vcard_dbt; - PASBackendFileBookView *view = (PASBackendFileBookView *)cnstview; - - if (!bf->priv->loaded) - return; - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_FIRST); - - while (db_error == 0) { - - /* don't include the version in the list of cards */ - if (id_dbt.size != strlen(PAS_BACKEND_FILE_VERSION_NAME) + 1 - || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { - char *vcard_string = vcard_dbt.data; - - /* check what type of change has occurred, if any */ - switch (vcard_change_type (view, vcard_string)) { - case VCardChangeNone: - break; - case VCardChangeAdded: - add_cards = g_list_append (add_cards, strdup(vcard_string)); - break; - case VCardChangeModified: - mod_cards = g_list_append (mod_cards, strdup(vcard_string)); - break; - case VCardChangeDeleted: - del_cards = g_list_append (del_cards, strdup(vcard_string)); - break; - } - } - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_NEXT); - } - - if (db_error == -1) { - g_warning ("pas_backend_file_search_changes: error building list\n"); - } else { - GList *l; - - pas_book_view_notify_add (view->book_view, add_cards); - pas_book_view_notify_change (view->book_view, mod_cards); - - for (l = del_cards; l != NULL; l = l->next){ - char *card = l->data; - pas_book_view_notify_remove (view->book_view, card); - } - - pas_book_view_notify_complete (view->book_view); - } - - /* - ** It's fine to do this now since the data has been handed off. - */ - g_list_foreach (add_cards, (GFunc)g_free, NULL); - g_list_foreach (mod_cards, (GFunc)g_free, NULL); - g_list_foreach (del_cards, (GFunc)g_free, NULL); - g_list_free (add_cards); - g_list_free (mod_cards); - g_list_free (del_cards); -} - -static char * -do_create(PASBackend *backend, - char *vcard_req, - char **vcard_ptr) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - DB *db = bf->priv->file_db; - DBT id_dbt, vcard_dbt; - int db_error; - char *id; - ECard *card; - char *vcard; - char *ret_val; - - id = pas_backend_file_create_unique_id (vcard_req); - - string_to_dbt (id, &id_dbt); - - card = e_card_new(vcard_req); - e_card_set_id(card, id); - vcard = e_card_get_vcard(card); - - string_to_dbt (vcard, &vcard_dbt); - - db_error = db->put (db, &id_dbt, &vcard_dbt, 0); - - if (0 == db_error) { - db_error = db->sync (db, 0); - if (db_error != 0) - g_warning ("db->sync failed.\n"); - ret_val = id; - - } - else { - ret_val = NULL; - } - - gtk_object_unref(GTK_OBJECT(card)); - card = NULL; - - if (vcard_ptr && ret_val) - *vcard_ptr = vcard; - else - g_free (vcard); - - return ret_val; -} - -static void -pas_backend_file_process_create_card (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - char *id; - char *vcard; - EIterator *iterator; - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - - id = do_create(backend, req->vcard, &vcard); - if (id) { - for (iterator = e_list_get_iterator(bf->priv->book_views); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const PASBackendFileBookView *view = e_iterator_get(iterator); - if (vcard_matches_search (view, vcard)) { - pas_book_view_notify_add_1 (view->book_view, vcard); - pas_book_view_notify_complete (view->book_view); - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - - pas_book_respond_create ( - book, - Evolution_BookListener_Success, - id); - g_free(vcard); - g_free(id); - } - else { - /* XXX need a different call status for this case, i - think */ - pas_book_respond_create ( - book, - Evolution_BookListener_CardNotFound, - ""); - } - - g_free(req->vcard); -} - -static void -pas_backend_file_process_remove_card (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - DB *db = bf->priv->file_db; - DBT id_dbt, vcard_dbt; - int db_error; - EIterator *iterator; - char *vcard_string; - - string_to_dbt (req->id, &id_dbt); - - db_error = db->get (db, &id_dbt, &vcard_dbt, 0); - if (0 != db_error) { - pas_book_respond_remove ( - book, - Evolution_BookListener_CardNotFound); - g_free (req->id); - return; - } - - db_error = db->del (db, &id_dbt, 0); - if (0 != db_error) { - pas_book_respond_remove ( - book, - Evolution_BookListener_CardNotFound); - g_free (req->id); - return; - } - - db_error = db->sync (db, 0); - if (db_error != 0) - g_warning ("db->sync failed.\n"); - - - vcard_string = vcard_dbt.data; - for (iterator = e_list_get_iterator (bf->priv->book_views); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - const PASBackendFileBookView *view = e_iterator_get(iterator); - if (vcard_matches_search (view, vcard_string)) { - pas_book_view_notify_remove (view->book_view, req->id); - pas_book_view_notify_complete (view->book_view); - } - } - gtk_object_unref(GTK_OBJECT(iterator)); - - pas_book_respond_remove ( - book, - Evolution_BookListener_Success); - - g_free (req->id); -} - -static void -pas_backend_file_process_modify_card (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - DB *db = bf->priv->file_db; - DBT id_dbt, vcard_dbt; - int db_error; - EIterator *iterator; - ECard *card; - char *id; - char *old_vcard_string; - - /* create a new ecard from the request data */ - card = e_card_new(req->vcard); - id = e_card_get_id(card); - - string_to_dbt (id, &id_dbt); - - /* get the old ecard - the one that's presently in the db */ - db_error = db->get (db, &id_dbt, &vcard_dbt, 0); - if (0 != db_error) { - pas_book_respond_modify ( - book, - Evolution_BookListener_CardNotFound); - g_free (req->id); - return; - } - old_vcard_string = g_strdup(vcard_dbt.data); - - string_to_dbt (req->vcard, &vcard_dbt); - - db_error = db->put (db, &id_dbt, &vcard_dbt, 0); - - if (0 == db_error) { - db_error = db->sync (db, 0); - if (db_error != 0) - g_warning ("db->sync failed.\n"); - - for (iterator = e_list_get_iterator(bf->priv->book_views); e_iterator_is_valid(iterator); e_iterator_next(iterator)) { - CORBA_Environment ev; - const PASBackendFileBookView *view = e_iterator_get(iterator); - gboolean old_match, new_match; - - CORBA_exception_init(&ev); - - bonobo_object_dup_ref(bonobo_object_corba_objref(BONOBO_OBJECT(view->book_view)), &ev); - - old_match = vcard_matches_search (view, old_vcard_string); - new_match = vcard_matches_search (view, req->vcard); - if (old_match && new_match) - pas_book_view_notify_change_1 (view->book_view, req->vcard); - else if (new_match) - pas_book_view_notify_add_1 (view->book_view, req->vcard); - else /* if (old_match) */ - pas_book_view_notify_remove (view->book_view, id); - pas_book_view_notify_complete (view->book_view); - - bonobo_object_release_unref(bonobo_object_corba_objref(BONOBO_OBJECT(view->book_view)), &ev); - } - gtk_object_unref(GTK_OBJECT(iterator)); - - pas_book_respond_modify ( - book, - Evolution_BookListener_Success); - } - else { - pas_book_respond_modify ( - book, - Evolution_BookListener_CardNotFound); - } - - g_free(old_vcard_string); - - gtk_object_unref(GTK_OBJECT(card)); - g_free (req->vcard); -} - -static void -pas_backend_file_build_all_cards_list(PASBackend *backend, - PASBackendFileCursorPrivate *cursor_data) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - DB *db = bf->priv->file_db; - int db_error; - DBT id_dbt, vcard_dbt; - - cursor_data->elements = NULL; - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_FIRST); - - while (db_error == 0) { - - /* don't include the version in the list of cards */ - if (id_dbt.size != strlen(PAS_BACKEND_FILE_VERSION_NAME) + 1 - || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { - - cursor_data->elements = g_list_append(cursor_data->elements, - g_strdup(vcard_dbt.data)); - - } - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_NEXT); - - } - - if (db_error == -1) { - g_warning ("pas_backend_file_build_all_cards_list: error building list\n"); - } - else { - cursor_data->num_elements = g_list_length (cursor_data->elements); - } -} - -static void -pas_backend_file_process_get_cursor (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - /* - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - DB *db = bf->priv->file_db; - DBT id_dbt, vcard_dbt; - */ - CORBA_Environment ev; - int db_error = 0; - PASBackendFileCursorPrivate *cursor_data; - PASCardCursor *cursor; - Evolution_Book corba_book; - - cursor_data = g_new(PASBackendFileCursorPrivate, 1); - cursor_data->backend = backend; - cursor_data->book = book; - - pas_backend_file_build_all_cards_list(backend, cursor_data); - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(book)); - - CORBA_exception_init(&ev); - - Evolution_Book_ref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("pas_backend_file_process_get_cursor: Exception reffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); - - cursor = pas_card_cursor_new(get_length, - get_nth, - cursor_data); - - gtk_signal_connect(GTK_OBJECT(cursor), "destroy", - GTK_SIGNAL_FUNC(cursor_destroy), cursor_data); - - pas_book_respond_get_cursor ( - book, - (db_error == 0 - ? Evolution_BookListener_Success - : Evolution_BookListener_CardNotFound), - cursor); -} - -static void -pas_backend_file_process_get_book_view (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - CORBA_Environment ev; - PASBookView *book_view; - Evolution_Book corba_book; - PASBackendFileBookView view; - PASBackendFileSearchContext ctx; - EIterator *iterator; - - g_return_if_fail (req->listener != NULL); - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(book)); - - CORBA_exception_init(&ev); - - Evolution_Book_ref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("pas_backend_file_process_get_book_view: Exception reffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); - - book_view = pas_book_view_new (req->listener); - - gtk_signal_connect(GTK_OBJECT(book_view), "destroy", - GTK_SIGNAL_FUNC(view_destroy), book); - - pas_book_respond_get_book_view (book, - (book_view != NULL - ? Evolution_BookListener_Success - : Evolution_BookListener_CardNotFound /* XXX */), - book_view); - - view.book_view = book_view; - view.search = req->search; - view.search_sexp = NULL; - view.search_context = &ctx; - ctx.card = NULL; - - e_list_append(bf->priv->book_views, &view); - - iterator = e_list_get_iterator(bf->priv->book_views); - e_iterator_last(iterator); - pas_backend_file_search (bf, book, e_iterator_get(iterator)); - gtk_object_unref(GTK_OBJECT(iterator)); - - g_free(req->search); -} - -static void -pas_backend_file_process_get_changes (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - CORBA_Environment ev; - PASBookView *book_view; - Evolution_Book corba_book; - PASBackendFileBookView view; - PASBackendFileSearchContext ctx; - EIterator *iterator; - - g_return_if_fail (req->listener != NULL); - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(book)); - - CORBA_exception_init(&ev); - - Evolution_Book_ref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("pas_backend_file_process_get_book_view: Exception reffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); - - book_view = pas_book_view_new (req->listener); - - gtk_signal_connect(GTK_OBJECT(book_view), "destroy", - GTK_SIGNAL_FUNC(view_destroy), book); - - pas_book_respond_get_changes (book, - (book_view != NULL - ? Evolution_BookListener_Success - : Evolution_BookListener_CardNotFound /* XXX */), - book_view); - - view.book_view = book_view; - view.search = req->search; - view.search_sexp = NULL; - view.search_context = &ctx; - ctx.card = NULL; - - e_list_append(bf->priv->book_views, &view); - - iterator = e_list_get_iterator(bf->priv->book_views); - e_iterator_last(iterator); - pas_backend_file_search_changes (bf, book, e_iterator_get(iterator)); - gtk_object_unref(GTK_OBJECT(iterator)); - - g_free(req->search); -} - -static void -pas_backend_file_process_check_connection (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - - pas_book_report_connection (book, bf->priv->file_db != NULL); -} - -static char * -pas_backend_file_extract_path_from_uri (const char *uri) -{ - g_assert (strncasecmp (uri, "file:", 5) == 0); - - return g_strdup (uri + 5); -} - -static gboolean -can_write (PASBackend *backend) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - char *path = pas_backend_file_extract_path_from_uri (bf->priv->uri); - gboolean retval; - - retval = (access (path, W_OK) != -1); - - g_free (path); - - return retval; -} - -static gboolean -pas_backend_file_can_write (PASBook *book) -{ - PASBackend* backend = pas_book_get_backend (book); - - return can_write(backend); -} - -static gboolean -pas_backend_file_can_write_card (PASBook *book, - const char *id) -{ - PASBackend* backend = pas_book_get_backend (book); - - return can_write(backend); -} - -static void -pas_backend_file_process_client_requests (PASBook *book) -{ - PASBackend *backend; - PASRequest *req; - - backend = pas_book_get_backend (book); - - req = pas_book_pop_request (book); - if (req == NULL) - return; - - switch (req->op) { - case CreateCard: - pas_backend_file_process_create_card (backend, book, req); - break; - - case RemoveCard: - pas_backend_file_process_remove_card (backend, book, req); - break; - - case ModifyCard: - pas_backend_file_process_modify_card (backend, book, req); - break; - - case CheckConnection: - pas_backend_file_process_check_connection (backend, book, req); - break; - - case GetCursor: - pas_backend_file_process_get_cursor (backend, book, req); - break; - - case GetBookView: - pas_backend_file_process_get_book_view (backend, book, req); - break; - - case GetChanges: - pas_backend_file_process_get_changes (backend, book, req); - break; - } - - g_free (req); -} - -static void -pas_backend_file_book_destroy_cb (PASBook *book, gpointer data) -{ - PASBackendFile *backend; - - backend = PAS_BACKEND_FILE (data); - - pas_backend_remove_client (PAS_BACKEND (backend), book); -} - -static char * -pas_backend_file_get_vcard (PASBook *book, const char *id) -{ - PASBackendFile *bf; - DBT id_dbt, vcard_dbt; - DB *db; - int db_error; - - bf = PAS_BACKEND_FILE (pas_book_get_backend (book)); - db = bf->priv->file_db; - - string_to_dbt (id, &id_dbt); - - db_error = db->get (db, &id_dbt, &vcard_dbt, 0); - if (db_error == 0) { - /* success */ - return g_strdup (vcard_dbt.data); - } - else if (db_error == 1) { - /* key was not in file */ - return g_strdup (""); /* XXX */ - } - else /* if (db_error < 0)*/ { - /* error */ - return g_strdup (""); /* XXX */ - } -} - -static gboolean -pas_backend_file_upgrade_db (PASBackendFile *bf, char *old_version) -{ - if (!strcmp (old_version, "0.0")) { - /* 0.0 is the same as 0.1, we just need to add the version */ - DB *db = bf->priv->file_db; - DBT version_name_dbt, version_dbt; - int db_error; - - string_to_dbt (PAS_BACKEND_FILE_VERSION_NAME, &version_name_dbt); - string_to_dbt (PAS_BACKEND_FILE_VERSION, &version_dbt); - - db_error = db->put (db, &version_name_dbt, &version_dbt, 0); - if (db_error == 0) - return TRUE; - else - return FALSE; - } - else { - g_warning ("unsupported version '%s' found in PAS backend file\n", - old_version); - return FALSE; - } -} - -static gboolean -pas_backend_file_maybe_upgrade_db (PASBackendFile *bf) -{ - DB *db = bf->priv->file_db; - DBT version_name_dbt, version_dbt; - int db_error; - char *version; - gboolean ret_val = TRUE; - - string_to_dbt (PAS_BACKEND_FILE_VERSION_NAME, &version_name_dbt); - - db_error = db->get (db, &version_name_dbt, &version_dbt, 0); - if (db_error == 0) { - /* success */ - version = g_strdup (version_dbt.data); - } - else { - /* key was not in file */ - version = g_strdup ("0.0"); - } - - if (strcmp (version, PAS_BACKEND_FILE_VERSION)) - ret_val = pas_backend_file_upgrade_db (bf, version); - - g_free (version); - - return ret_val; -} - -#define INITIAL_VCARD "BEGIN:VCARD\n\ -X-EVOLUTION-FILE-AS:Helix Code, Inc.\n\ -LABEL;WORK;QUOTED-PRINTABLE:101 Rogers St. Ste. 214=0ACambridge, MA 02142=0AUSA\n\ -TEL;WORK;VOICE:(617) 679-1984\n\ -TEL;WORK;FAX:(617) 679-1949\n\ -EMAIL;INTERNET:hello@helixcode.com\n\ -URL:http://www.helixcode.com/\n\ -ORG:Helix Code, Inc.;\n\ -NOTE:Welcome to the Helix Code Addressbook.\n\ -END:VCARD" - -static gboolean -pas_backend_file_load_uri (PASBackend *backend, - const char *uri) -{ - PASBackendFile *bf = PAS_BACKEND_FILE (backend); - char *filename; - - g_assert (bf->priv->loaded == FALSE); - - filename = pas_backend_file_extract_path_from_uri (uri); - - bf->priv->file_db = dbopen (filename, O_RDWR, 0666, DB_HASH, NULL); - if (bf->priv->file_db == NULL) { - bf->priv->file_db = dbopen (filename, O_RDWR | O_CREAT, 0666, DB_HASH, NULL); - - if (bf->priv->file_db) { - char *id; - id = do_create(backend, INITIAL_VCARD, NULL); - g_free (id); - } - } - - g_free (filename); - - if (bf->priv->file_db != NULL) { - if (pas_backend_file_maybe_upgrade_db (bf)) - bf->priv->loaded = TRUE; - /* XXX what if we fail to upgrade it? */ - - g_free(bf->priv->uri); - bf->priv->uri = g_strdup (uri); - } else - return FALSE; - - return TRUE; -} - -/* Get_uri handler for the addressbook file backend */ -static const char * -pas_backend_file_get_uri (PASBackend *backend) -{ - PASBackendFile *bf; - - bf = PAS_BACKEND_FILE (backend); - - g_return_val_if_fail (bf->priv->loaded, NULL); - g_assert (bf->priv->uri != NULL); - - return bf->priv->uri; -} - -static gboolean -pas_backend_file_add_client (PASBackend *backend, - Evolution_BookListener listener) -{ - PASBackendFile *bf; - PASBook *book; - - g_assert (backend != NULL); - g_assert (PAS_IS_BACKEND_FILE (backend)); - - bf = PAS_BACKEND_FILE (backend); - - book = pas_book_new ( - backend, listener, - pas_backend_file_get_vcard, - pas_backend_file_can_write, - pas_backend_file_can_write_card); - - if (!book) { - if (!bf->priv->clients) - pas_backend_last_client_gone (backend); - - return FALSE; - } - - gtk_signal_connect (GTK_OBJECT (book), "destroy", - pas_backend_file_book_destroy_cb, backend); - - gtk_signal_connect (GTK_OBJECT (book), "requests_queued", - pas_backend_file_process_client_requests, NULL); - - bf->priv->clients = g_list_prepend ( - bf->priv->clients, book); - - if (bf->priv->loaded) { - pas_book_respond_open ( - book, Evolution_BookListener_Success); - } else { - /* Open the book. */ - pas_book_respond_open ( - book, Evolution_BookListener_Success); - } - - return TRUE; -} - -static void -pas_backend_file_remove_client (PASBackend *backend, - PASBook *book) -{ - PASBackendFile *bf; - GList *l; - PASBook *lbook; - - g_return_if_fail (backend != NULL); - g_return_if_fail (PAS_IS_BACKEND_FILE (backend)); - g_return_if_fail (book != NULL); - g_return_if_fail (PAS_IS_BOOK (book)); - - bf = PAS_BACKEND_FILE (backend); - - /* Find the book in the list of clients */ - - for (l = bf->priv->clients; l; l = l->next) { - lbook = PAS_BOOK (l->data); - - if (lbook == book) - break; - } - - g_assert (l != NULL); - - /* Disconnect */ - - bf->priv->clients = g_list_remove_link (bf->priv->clients, l); - g_list_free_1 (l); - - /* When all clients go away, notify the parent factory about it so that - * it may decide whether to kill the backend or not. - */ - if (!bf->priv->clients) - pas_backend_last_client_gone (backend); -} - -static char * -pas_backend_file_get_static_capabilities (PASBackend *backend) -{ - return g_strdup("local"); -} - -static gboolean -pas_backend_file_construct (PASBackendFile *backend) -{ - g_assert (backend != NULL); - g_assert (PAS_IS_BACKEND_FILE (backend)); - - if (! pas_backend_construct (PAS_BACKEND (backend))) - return FALSE; - - return TRUE; -} - -/** - * pas_backend_file_new: - */ -PASBackend * -pas_backend_file_new (void) -{ - PASBackendFile *backend; - - backend = gtk_type_new (pas_backend_file_get_type ()); - - if (! pas_backend_file_construct (backend)) { - gtk_object_unref (GTK_OBJECT (backend)); - - return NULL; - } - - return PAS_BACKEND (backend); -} - -static void -pas_backend_file_destroy (GtkObject *object) -{ - PASBackendFile *bf; - - bf = PAS_BACKEND_FILE (object); - - gtk_object_unref(GTK_OBJECT(bf->priv->book_views)); - g_free (bf->priv->uri); - - GTK_OBJECT_CLASS (pas_backend_file_parent_class)->destroy (object); -} - -static void -pas_backend_file_class_init (PASBackendFileClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - PASBackendClass *parent_class; - - pas_backend_file_parent_class = gtk_type_class (pas_backend_get_type ()); - - parent_class = PAS_BACKEND_CLASS (klass); - - /* Set the virtual methods. */ - parent_class->load_uri = pas_backend_file_load_uri; - parent_class->get_uri = pas_backend_file_get_uri; - parent_class->add_client = pas_backend_file_add_client; - parent_class->remove_client = pas_backend_file_remove_client; - parent_class->get_static_capabilities = pas_backend_file_get_static_capabilities; - - object_class->destroy = pas_backend_file_destroy; -} - -static void -pas_backend_file_init (PASBackendFile *backend) -{ - PASBackendFilePrivate *priv; - - priv = g_new0 (PASBackendFilePrivate, 1); - priv->loaded = FALSE; - priv->clients = NULL; - priv->book_views = e_list_new((EListCopyFunc) pas_backend_file_book_view_copy, (EListFreeFunc) pas_backend_file_book_view_free, NULL); - priv->uri = NULL; - - backend->priv = priv; -} - -/** - * pas_backend_file_get_type: - */ -GtkType -pas_backend_file_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "PASBackendFile", - sizeof (PASBackendFile), - sizeof (PASBackendFileClass), - (GtkClassInitFunc) pas_backend_file_class_init, - (GtkObjectInitFunc) pas_backend_file_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (pas_backend_get_type (), &info); - } - - return type; -} diff --git a/addressbook/backend/pas/pas-backend-file.h b/addressbook/backend/pas/pas-backend-file.h deleted file mode 100644 index 4da9a29cc5..0000000000 --- a/addressbook/backend/pas/pas-backend-file.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2000, Helix Code, Inc. - */ - -#ifndef __PAS_BACKEND_FILE_H__ -#define __PAS_BACKEND_FILE_H__ - -#include <libgnome/gnome-defs.h> -#include "pas-backend.h" - -typedef struct _PASBackendFilePrivate PASBackendFilePrivate; - -typedef struct { - PASBackend parent_object; - PASBackendFilePrivate *priv; -} PASBackendFile; - -typedef struct { - PASBackendClass parent_class; -} PASBackendFileClass; - -PASBackend *pas_backend_file_new (void); -GtkType pas_backend_file_get_type (void); - -#define PAS_BACKEND_FILE_TYPE (pas_backend_file_get_type ()) -#define PAS_BACKEND_FILE(o) (GTK_CHECK_CAST ((o), PAS_BACKEND_FILE_TYPE, PASBackendFile)) -#define PAS_BACKEND_FILE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_BACKEND_TYPE, PASBackendFileClass)) -#define PAS_IS_BACKEND_FILE(o) (GTK_CHECK_TYPE ((o), PAS_BACKEND_FILE_TYPE)) -#define PAS_IS_BACKEND_FILE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_BACKEND_FILE_TYPE)) - -#endif /* ! __PAS_BACKEND_FILE_H__ */ - diff --git a/addressbook/backend/pas/pas-backend-ldap.c b/addressbook/backend/pas/pas-backend-ldap.c deleted file mode 100644 index f9842d2406..0000000000 --- a/addressbook/backend/pas/pas-backend-ldap.c +++ /dev/null @@ -1,1846 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Author: - * Chris Toshok (toshok@helixcode.com) - * - * Copyright 2000, Helix Code, Inc. - */ - -/*#define DEBUG*/ - -#include "config.h" -#include <gtk/gtksignal.h> -#include <fcntl.h> -#include <time.h> -#include <lber.h> - -#ifdef DEBUG -#define LDAP_DEBUG -#endif -#include <ldap.h> -#ifdef DEBUG -#undef LDAP_DEBUG -#endif - -#include "pas-backend-ldap.h" -#include "pas-book.h" -#include "pas-card-cursor.h" - -#include <e-util/e-sexp.h> -#include <ebook/e-card-simple.h> - -#define LDAP_MAX_SEARCH_RESPONSES 100 - -/* this really needs addressing */ -#define OBJECT_CLASS "person" - - -static gchar *query_prop_to_ldap(gchar *query_prop); - -static PASBackendClass *pas_backend_ldap_parent_class; -typedef struct _PASBackendLDAPCursorPrivate PASBackendLDAPCursorPrivate; -typedef struct _PASBackendLDAPBookView PASBackendLDAPBookView; -typedef struct LDAPOp LDAPOp; - -struct _PASBackendLDAPPrivate { - char *uri; - gboolean connected; - GList *clients; - gchar *ldap_host; - gchar *ldap_rootdn; - int ldap_port; - int ldap_scope; - GList *book_views; - - LDAP *ldap; - - /* whether or not there's a request in process on our LDAP* */ - LDAPOp *current_op; - GList *pending_ops; - int op_idle; -}; - -struct _PASBackendLDAPCursorPrivate { - PASBackend *backend; - PASBook *book; - - GList *elements; - long num_elements; -}; - -struct _PASBackendLDAPBookView { - PASBookView *book_view; - PASBackendLDAPPrivate *blpriv; - gchar *search; - int search_idle; - int search_msgid; - LDAPOp *search_op; -}; - -typedef gboolean (*LDAPOpHandler)(PASBackend *backend, LDAPOp *op); -typedef void (*LDAPOpDtor)(PASBackend *backend, LDAPOp *op); - -struct LDAPOp { - LDAPOpHandler handler; - LDAPOpDtor dtor; - PASBackend *backend; - PASBook *book; - PASBookView *view; -}; - -static void ldap_op_init (LDAPOp *op, PASBackend *backend, PASBook *book, PASBookView *view, LDAPOpHandler handler, LDAPOpDtor dtor); -static void ldap_op_process_current (PASBackend *backend); -static void ldap_op_process (LDAPOp *op); -static void ldap_op_restart (LDAPOp *op); -static gboolean ldap_op_process_on_idle (PASBackend *backend); -static void ldap_op_finished (LDAPOp *op); - -static ECardSimple *build_card_from_entry (LDAP *ldap, LDAPMessage *e); - -static void email_populate_func(ECardSimple *card, char **values); -struct berval** email_ber_func(ECardSimple *card); -gboolean email_compare_func (ECardSimple *ecard1, ECardSimple *ecard2); - -struct prop_info { - ECardSimpleField field_id; - char *query_prop; - char *ldap_attr; -#define PROP_TYPE_NORMAL 0x01 -#define PROP_TYPE_LIST 0x02 -#define PROP_DN 0x04 - int prop_type; - - /* the remaining items are only used for the TYPE_LIST props */ - - /* used when reading from the ldap server populates ECard with the values in **values. */ - void (*populate_ecard_func)(ECardSimple *card, char **values); - /* used when writing to an ldap server. returns a NULL terminated array of berval*'s */ - struct berval** (*ber_func)(ECardSimple *card); - /* used to compare list attributes */ - gboolean (*compare_func)(ECardSimple *card1, ECardSimple *card2); - -} prop_info[] = { - -#define DN_NORMAL_PROP(fid,q,a) {fid, q, a, PROP_TYPE_NORMAL | PROP_DN, NULL} -#define DN_LIST_PROP(fid,q,a,ctor,ber,cmp) {fid, q, a, PROP_TYPE_LIST | PROP_DN, ctor, ber, cmp} -#define NORMAL_PROP(fid,q,a) {fid, q, a, PROP_TYPE_NORMAL, NULL} - - DN_NORMAL_PROP (E_CARD_SIMPLE_FIELD_FULL_NAME, "full_name", "cn" ), - DN_NORMAL_PROP (E_CARD_SIMPLE_FIELD_FAMILY_NAME, "family_name", "sn" ), - NORMAL_PROP (E_CARD_SIMPLE_FIELD_TITLE, "title", "title"), - DN_NORMAL_PROP (E_CARD_SIMPLE_FIELD_ORG, "org", "o"), - NORMAL_PROP (E_CARD_SIMPLE_FIELD_PHONE_PRIMARY, "phone", "telephonenumber"), - DN_LIST_PROP (E_CARD_SIMPLE_FIELD_EMAIL, "email", "mail", email_populate_func, email_ber_func, email_compare_func) - -#undef DN_NORMAL_PROP -#undef DN_LIST_PROP -#undef NORMAL_PROP -}; - -static int num_prop_infos = sizeof(prop_info) / sizeof(prop_info[0]); - -static void -view_destroy(GtkObject *object, gpointer data) -{ - CORBA_Environment ev; - Evolution_Book corba_book; - PASBook *book = (PASBook *)data; - PASBackendLDAP *bl; - GList *list; - - bl = PAS_BACKEND_LDAP(pas_book_get_backend(book)); - for (list = bl->priv->book_views; list; list = g_list_next(list)) { - PASBackendLDAPBookView *view = list->data; - if (view->book_view == PAS_BOOK_VIEW(object)) { - if (view->search_idle != 0) { - /* we have a search running on the - ldap connection. remove the idle - handler and anbandon the msg id */ - g_source_remove(view->search_idle); - pas_book_view_notify_status_message (view->book_view, "Abandoning pending search"); - if (view->search_msgid != -1) - ldap_abandon (bl->priv->ldap, view->search_msgid); - - /* if the search op is the current op, - finish it. else, remove it from the - list and nuke it ourselves. */ - if (view->search_op == bl->priv->current_op) - ldap_op_finished (view->search_op); - else { - bl->priv->pending_ops = g_list_remove (bl->priv->pending_ops, - view->search_op); - view->search_op->dtor (view->search_op->backend, - view->search_op); - } - } - g_free (view->search); - g_free (view); - bl->priv->book_views = g_list_remove_link(bl->priv->book_views, list); - g_list_free_1(list); - break; - } - } - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(book)); - - CORBA_exception_init(&ev); - - Evolution_Book_unref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("view_destroy: Exception unreffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); -} - -static void -pas_backend_ldap_connect (PASBackendLDAP *bl) -{ - PASBackendLDAPPrivate *blpriv = bl->priv; - -#ifdef DEBUG - { - extern int ldap_debug; - ldap_debug = LDAP_DEBUG_ANY; - } -#endif - - /* close connection first if it's open first */ - if (blpriv->ldap) - ldap_unbind (blpriv->ldap); - - blpriv->ldap = ldap_open (blpriv->ldap_host, blpriv->ldap_port); - if (NULL != blpriv->ldap) { - ldap_simple_bind_s(blpriv->ldap, - NULL /*binddn*/, NULL /*passwd*/); - blpriv->connected = TRUE; - } - else { - g_warning ("pas_backend_ldap_connect failed for " - "'ldap://%s:%d/%s'\n", - blpriv->ldap_host, - blpriv->ldap_port, - blpriv->ldap_rootdn ? blpriv->ldap_rootdn : ""); - blpriv->connected = FALSE; - } -} - -static void -ldap_op_init (LDAPOp *op, PASBackend *backend, - PASBook *book, PASBookView *view, - LDAPOpHandler handler, LDAPOpDtor dtor) -{ - op->backend = backend; - op->book = book; - op->view = view; - op->handler = handler; - op->dtor = dtor; -} - -static void -ldap_op_process_current (PASBackend *backend) -{ - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - LDAPOp *op = bl->priv->current_op; - - if (!bl->priv->connected) { - if (op->view) - pas_book_view_notify_status_message (op->view, "Connecting to LDAP server"); - pas_backend_ldap_connect(bl); - } - - if (bl->priv->connected) { - if (op->handler (backend, op)) - ldap_op_finished (op); - } - else { - if (op->view) - pas_book_view_notify_status_message (op->view, "Unable to connect to LDAP server"); - - ldap_op_finished (op); - } -} - -static void -ldap_op_process (LDAPOp *op) -{ - PASBackendLDAP *bl = PAS_BACKEND_LDAP (op->backend); - - if (bl->priv->current_op) { - /* operation in progress. queue this op for later and return. */ - if (op->view) - pas_book_view_notify_status_message (op->view, "Waiting for connection to ldap server..."); - bl->priv->pending_ops = g_list_append (bl->priv->pending_ops, op); - } - else { - /* nothing going on, do this op now */ - bl->priv->current_op = op; - ldap_op_process_current (op->backend); - } -} - -static gboolean -ldap_op_process_on_idle (PASBackend *backend) -{ - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - - bl->priv->op_idle = 0; - - ldap_op_process_current (backend); - - return FALSE; -} - -static void -ldap_op_restart (LDAPOp *op) -{ - PASBackend *backend = op->backend; - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - - g_return_if_fail (op == bl->priv->current_op); - - bl->priv->op_idle = g_idle_add((GSourceFunc)ldap_op_process_on_idle, backend); -} - -static void -ldap_op_finished (LDAPOp *op) -{ - PASBackend *backend = op->backend; - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - - g_return_if_fail (op == bl->priv->current_op); - - op->dtor (backend, op); - - if (bl->priv->pending_ops) { - bl->priv->current_op = bl->priv->pending_ops->data; - bl->priv->pending_ops = g_list_remove_link (bl->priv->pending_ops, bl->priv->pending_ops); - - bl->priv->op_idle = g_idle_add((GSourceFunc)ldap_op_process_on_idle, backend); - } - else { - bl->priv->current_op = NULL; - } -} - -static int -ldap_error_to_response (int ldap_error) -{ - if (ldap_error == LDAP_SUCCESS) - return Evolution_BookListener_Success; - else if (NAME_ERROR (ldap_error)) - return Evolution_BookListener_CardNotFound; - else if (ldap_error == LDAP_INSUFFICIENT_ACCESS) - return Evolution_BookListener_PermissionDenied; - else if (ldap_error == LDAP_SERVER_DOWN) - return Evolution_BookListener_RepositoryOffline; - else - return Evolution_BookListener_OtherError; -} - - -static char * -create_dn_from_ecard (ECardSimple *card) -{ - char *o, *o_part = NULL; - const char *mail; - char *mail_part = NULL; - char *cn, *cn_part = NULL; - char *dn; - gboolean need_comma = FALSE; - - o = e_card_simple_get (card, E_CARD_SIMPLE_FIELD_ORG); - if (o) { - o_part = g_strdup_printf ("o=%s", o); - need_comma = TRUE; - } - else { - o_part = g_strdup (""); - need_comma = FALSE; - } - - mail = e_card_simple_get_email (card, E_CARD_SIMPLE_EMAIL_ID_EMAIL); - if (mail) { - mail_part = g_strdup_printf ("mail=%s%s", mail, need_comma ? "," : ""); - need_comma = TRUE; - } - else { - mail_part = g_strdup (""); - } - - cn = e_card_simple_get (card, E_CARD_SIMPLE_FIELD_FULL_NAME); - if (cn) { - cn_part = g_strdup_printf ("cn=\"%s\"%s", cn, need_comma ? "," : ""); - } - else { - cn_part = g_strdup (""); - } - - dn = g_strdup_printf ("%s%s%s", cn_part, mail_part, o_part); - - g_free (cn_part); - g_free (mail_part); - g_free (o_part); - - g_print ("generated dn: %s\n", dn); - - return dn; -} - -static GPtrArray* -build_mods_from_ecards (ECardSimple *current, ECardSimple *new, gboolean *new_dn_needed) -{ - gboolean adding = (current == NULL); - GPtrArray *result = g_ptr_array_new(); - int i; - - if (new_dn_needed) - *new_dn_needed = FALSE; - - /* we walk down the list of properties we can deal with (that - big table at the top of the file) */ - - for (i = 0; i < num_prop_infos; i ++) { - char *new_prop = NULL; - char *current_prop = NULL; - gboolean include; - - /* get the value for the new card, and compare it to - the value in the current card to see if we should - update it -- if adding is TRUE, short circuit the - check. */ - new_prop = e_card_simple_get (new, prop_info[i].field_id); - - /* need to set INCLUDE to true if the field needs to - show up in the ldap modify request */ - if (adding) { - /* if we're creating a new card, include it if the - field is there at all */ - include = (new_prop != NULL); - } - else { - /* if we're modifying an existing card, - include it if the current field value is - different than the new one, if it didn't - exist previously, or if it's been - removed. */ - current_prop = e_card_simple_get (current, prop_info[i].field_id); - - if (new_prop && current_prop) - include = strcmp (new_prop, current_prop); - else - include = (!!new_prop != !!current_prop); - } - - if (include) { - LDAPMod *mod = g_new (LDAPMod, 1); - - /* the included attribute has changed - we - need to update the dn if it's one of the - attributes we compute the dn from. */ - if (new_dn_needed) - *new_dn_needed |= prop_info[i].prop_type & PROP_DN; - - if (adding) { - mod->mod_op = LDAP_MOD_ADD; - } - else { - if (!new_prop) - mod->mod_op = LDAP_MOD_DELETE; - else if (!current_prop) - mod->mod_op = LDAP_MOD_ADD; - else - mod->mod_op = LDAP_MOD_REPLACE; - } - - mod->mod_type = g_strdup (prop_info[i].ldap_attr); - - if (prop_info[i].prop_type & PROP_TYPE_NORMAL) { - mod->mod_values = g_new (char*, 2); - mod->mod_values[0] = e_card_simple_get (new, prop_info[i].field_id); - mod->mod_values[1] = NULL; - } - else { - mod->mod_bvalues = prop_info[i].ber_func (new); - } - - g_ptr_array_add (result, mod); - } - } - - /* NULL terminate the list of modifications */ - g_ptr_array_add (result, NULL); - - return result; -} - -static void -free_mods (GPtrArray *mods) -{ - int i = 0; - LDAPMod *mod; - - while ((mod = g_ptr_array_index (mods, i++))) { - g_free (mod->mod_type); - - /* XXX we leak the values */ - g_free (mod); - } - - g_ptr_array_free (mods, TRUE /* XXX ? */); -} - -typedef struct { - LDAPOp op; - char *vcard; -} LDAPCreateOp; - -static gboolean -create_card_handler (PASBackend *backend, LDAPOp *op) -{ - LDAPCreateOp *create_op = (LDAPCreateOp*)op; - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - ECard *new_ecard; - ECardSimple *new_card; - char *dn; - int response; - int ldap_error; - GPtrArray *mod_array; - LDAPMod **ldap_mods; - LDAPMod *objectclass_mod; - LDAP *ldap; - - new_ecard = e_card_new (create_op->vcard); - new_card = e_card_simple_new (new_ecard); - - dn = create_dn_from_ecard (new_card); - - ldap = bl->priv->ldap; - - /* build our mods */ - mod_array = build_mods_from_ecards (NULL, new_card, NULL); - objectclass_mod = g_new (LDAPMod, 1); - - objectclass_mod->mod_op = LDAP_MOD_ADD; - objectclass_mod->mod_type = g_strdup ("objectclass"); - objectclass_mod->mod_values = g_new (char*, 1); - objectclass_mod->mod_values[0] = g_strdup (OBJECT_CLASS); - objectclass_mod->mod_values[1] = NULL; - - g_ptr_array_add (mod_array, objectclass_mod); - - ldap_mods = (LDAPMod**)mod_array->pdata; - - /* actually perform the ldap add */ - ldap_error = ldap_add_s (ldap, dn, ldap_mods); - - g_print ("ldap_add_s returned 0x%x (%s) status\n", ldap_error, ldap_err2string(ldap_error)); - - /* and clean up */ - free_mods (mod_array); - g_free (dn); - - gtk_object_unref (GTK_OBJECT(new_card)); - - /* and lastly respond */ - response = ldap_error_to_response (ldap_error); - pas_book_respond_create (create_op->op.book, - response, - dn); - - /* we're synchronous */ - return TRUE; -} - -static void -create_card_dtor (PASBackend *backend, LDAPOp *op) -{ - LDAPCreateOp *create_op = (LDAPCreateOp*)op; - - g_free (create_op->vcard); - g_free (create_op); -} - -static void -pas_backend_ldap_process_create_card (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - LDAPCreateOp *create_op = g_new (LDAPCreateOp, 1); - - ldap_op_init ((LDAPOp*)create_op, backend, book, NULL, create_card_handler, create_card_dtor); - - create_op->vcard = req->vcard; - - ldap_op_process ((LDAPOp*)create_op); -} - - -typedef struct { - LDAPOp op; - char *id; -} LDAPRemoveOp; - -static gboolean -remove_card_handler (PASBackend *backend, LDAPOp *op) -{ - LDAPRemoveOp *remove_op = (LDAPRemoveOp*)op; - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - int response; - int ldap_error; - - ldap_error = ldap_delete_s (bl->priv->ldap, remove_op->id); - - response = ldap_error_to_response (ldap_error); - - pas_book_respond_remove (remove_op->op.book, - response); - - /* we're synchronous */ - return TRUE; -} - -static void -remove_card_dtor (PASBackend *backend, LDAPOp *op) -{ - LDAPRemoveOp *remove_op = (LDAPRemoveOp*)op; - - g_free (remove_op->id); - g_free (remove_op); -} - -static void -pas_backend_ldap_process_remove_card (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - LDAPRemoveOp *remove_op = g_new (LDAPRemoveOp, 1); - - ldap_op_init ((LDAPOp*)remove_op, backend, book, NULL, remove_card_handler, remove_card_dtor); - - remove_op->id = req->id; - - ldap_op_process ((LDAPOp*)remove_op); -} - - -typedef struct { - LDAPOp op; - char *vcard; -} LDAPModifyOp; - -static gboolean -modify_card_handler (PASBackend *backend, LDAPOp *op) -{ - LDAPModifyOp *modify_op = (LDAPModifyOp*)op; - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - ECard *new_ecard; - char *id; - int response; - int ldap_error; - LDAPMessage *res, *e; - char *query; - GPtrArray *mod_array; - LDAPMod **ldap_mods; - LDAP *ldap; - - new_ecard = e_card_new (modify_op->vcard); - id = e_card_get_id(new_ecard); - - ldap = bl->priv->ldap; - - /* we don't get sent the original vcard along with the new one - in this call, so we have to query the ldap server for the - original record so we can compute our delta. */ - query = g_strdup_printf ("(dn=%s)", id); - ldap_error = ldap_search_s (ldap, - bl->priv->ldap_rootdn, - bl->priv->ldap_scope, - query, NULL, 0, &res); - - if (ldap_error == LDAP_SUCCESS) { - /* get the single card from the list (we're guaranteed - either 1 or 0 since we looked up by dn, which is - unique) */ - e = ldap_first_entry (ldap, res); - if (e) { - ECardSimple *new_card = e_card_simple_new (new_ecard); - ECardSimple *current_card = build_card_from_entry (ldap, e); - gboolean need_new_dn; - - /* build our mods */ - mod_array = build_mods_from_ecards (current_card, new_card, &need_new_dn); - if (mod_array->len > 0) { - ldap_mods = (LDAPMod**)mod_array->pdata; - - /* actually perform the ldap modify */ - ldap_error = ldap_modify_s (ldap, id, ldap_mods); - g_print ("ldap_modify_s returned 0x%x (%s) status\n", ldap_error, ldap_err2string(ldap_error)); - } - else { - g_print ("modify list empty. on modification sent\n"); - } - - /* and clean up */ - free_mods (mod_array); - gtk_object_unref (GTK_OBJECT(new_card)); - gtk_object_unref (GTK_OBJECT(current_card)); - } - else { - g_print ("didn't find original card\n"); - } - - ldap_msgfree(res); - } - else { - g_print ("ldap_search_s returned 0x%x (%s) status\n", ldap_error, ldap_err2string(ldap_error)); - } - - response = ldap_error_to_response (ldap_error); - pas_book_respond_modify (modify_op->op.book, - response); - - /* we're synchronous */ - return TRUE; -} - -static void -modify_card_dtor (PASBackend *backend, LDAPOp *op) -{ - LDAPModifyOp *modify_op = (LDAPModifyOp*)op; - - g_free (modify_op->vcard); - g_free (modify_op); -} - -static void -pas_backend_ldap_process_modify_card (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - LDAPModifyOp *modify_op = g_new (LDAPModifyOp, 1); - - ldap_op_init ((LDAPOp*)modify_op, backend, book, NULL, modify_card_handler, modify_card_dtor); - - modify_op->vcard = req->vcard; - - ldap_op_process ((LDAPOp*)modify_op); -} - - -typedef struct { - LDAPOp op; - PASBook *book; -} LDAPGetCursorOp; - -static long -get_length(PASCardCursor *cursor, gpointer data) -{ - PASBackendLDAPCursorPrivate *cursor_data = (PASBackendLDAPCursorPrivate *) data; - - return cursor_data->num_elements; -} - -static char * -get_nth(PASCardCursor *cursor, long n, gpointer data) -{ - PASBackendLDAPCursorPrivate *cursor_data = (PASBackendLDAPCursorPrivate *) data; - - g_return_val_if_fail (n < cursor_data->num_elements, NULL); - - return (char*)g_list_nth (cursor_data->elements, n); -} - -static void -cursor_destroy(GtkObject *object, gpointer data) -{ - CORBA_Environment ev; - Evolution_Book corba_book; - PASBackendLDAPCursorPrivate *cursor_data = (PASBackendLDAPCursorPrivate *) data; - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(cursor_data->book)); - - CORBA_exception_init(&ev); - - Evolution_Book_unref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("cursor_destroy: Exception unreffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); - - /* free the ldap specific cursor information */ - g_list_foreach (cursor_data->elements, (GFunc)g_free, NULL); - g_list_free (cursor_data->elements); - - g_free(cursor_data); -} - -static void -pas_backend_ldap_build_all_cards_list(PASBackend *backend, - PASBackendLDAPCursorPrivate *cursor_data) -{ - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - LDAP *ldap = bl->priv->ldap; - int ldap_error; - LDAPMessage *res, *e; - - if ((ldap_error = ldap_search_s (ldap, - bl->priv->ldap_rootdn, - bl->priv->ldap_scope, - "(objectclass=*)", - NULL, 0, &res)) == -1) { - g_warning ("ldap error '%s' in " - "pas_backend_ldap_build_all_cards_list\n", - ldap_err2string(ldap_error)); - } - - cursor_data->elements = NULL; - - cursor_data->num_elements = ldap_count_entries (ldap, res); - - e = ldap_first_entry(ldap, res); - - while (NULL != e) { - - /* for now just make a list of the dn's */ -#if 0 - for ( a = ldap_first_attribute( ldap, e, &ber ); a != NULL; - a = ldap_next_attribute( ldap, e, ber ) ) { - } -#else - cursor_data->elements = g_list_prepend(cursor_data->elements, - g_strdup(ldap_get_dn(ldap, e))); -#endif - - e = ldap_next_entry(ldap, e); - } - - ldap_msgfree(res); -} - - -static gboolean -get_cursor_handler (PASBackend *backend, LDAPOp *op) -{ - LDAPGetCursorOp *cursor_op = (LDAPGetCursorOp*)op; - CORBA_Environment ev; - int ldap_error = 0; - PASCardCursor *cursor; - Evolution_Book corba_book; - PASBackendLDAPCursorPrivate *cursor_data; - PASBook *book = cursor_op->book; - - cursor_data = g_new(PASBackendLDAPCursorPrivate, 1); - cursor_data->backend = backend; - cursor_data->book = book; - - pas_backend_ldap_build_all_cards_list(backend, cursor_data); - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(book)); - - CORBA_exception_init(&ev); - - Evolution_Book_ref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("pas_backend_file_process_get_cursor: Exception reffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); - - cursor = pas_card_cursor_new(get_length, - get_nth, - cursor_data); - - gtk_signal_connect(GTK_OBJECT(cursor), "destroy", - GTK_SIGNAL_FUNC(cursor_destroy), cursor_data); - - pas_book_respond_get_cursor (book, - ldap_error_to_response (ldap_error), - cursor); - - /* we're synchronous */ - return TRUE; -} - -static void -get_cursor_dtor (PASBackend *backend, LDAPOp *op) -{ - g_free (op); -} - -static void -pas_backend_ldap_process_get_cursor (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - LDAPGetCursorOp *op = g_new (LDAPGetCursorOp, 1); - - ldap_op_init ((LDAPOp*)op, backend, book, NULL, get_cursor_handler, get_cursor_dtor); - - ldap_op_process ((LDAPOp*)op); -} - -static void -email_populate_func(ECardSimple *card, char **values) -{ - int i; - - for (i = 0; values[i] && i < 3; i ++) { - e_card_simple_set_email (card, i, values[i]); - } -} - -struct berval** -email_ber_func(ECardSimple *card) -{ - struct berval** result; - const char *emails[3]; - int i, j, num; - - num = 0; - for (i = 0; i < 3; i ++) { - emails[i] = e_card_simple_get_email (card, E_CARD_SIMPLE_EMAIL_ID_EMAIL + i); - if (emails[i]) - num++; - } - - result = g_new (struct berval*, num + 1); - - for (i = 0; i < num; i ++) - result[i] = g_new (struct berval, 1); - - j = 0; - for (i = 0; i < 3; i ++) { - if (emails[i]) - result[j++]->bv_val = g_strdup (emails[i]); - } - - result[num] = NULL; - - return result; -} - -gboolean -email_compare_func (ECardSimple *ecard1, ECardSimple *ecard2) -{ - const char *email1, *email2; - int i; - - for (i = 0; i < 3; i ++) { - gboolean equal; - email1 = e_card_simple_get_email (ecard1, E_CARD_SIMPLE_EMAIL_ID_EMAIL + i); - email2 = e_card_simple_get_email (ecard2, E_CARD_SIMPLE_EMAIL_ID_EMAIL + i); - - if (email1 && email2) - equal = !strcmp (email1, email2); - else - equal = (!!email1 == !!email2); - - if (!equal) - return equal; - } - - return FALSE;; -} - -static ESExpResult * -func_and(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - GList **list = data; - ESExpResult *r; - char ** strings; - - if (argc > 0) { - int i; - - strings = g_new(char*, argc+3); - strings[0] = g_strdup ("(&"); - strings[argc+3 - 2] = g_strdup (")"); - strings[argc+3 - 1] = NULL; - - for (i = 0; i < argc; i ++) { - GList *list_head = *list; - strings[argc - i] = (*list)->data; - *list = g_list_remove_link(*list, *list); - g_list_free_1(list_head); - } - - *list = g_list_prepend(*list, g_strjoinv(" ", strings)); - - for (i = 0 ; i < argc + 2; i ++) - g_free (strings[i]); - - g_free (strings); - } - - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = FALSE; - - return r; -} - -static ESExpResult * -func_or(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - GList **list = data; - ESExpResult *r; - char ** strings; - - if (argc > 0) { - int i; - - strings = g_new(char*, argc+3); - strings[0] = g_strdup ("(|"); - strings[argc+3 - 2] = g_strdup (")"); - strings[argc+3 - 1] = NULL; - for (i = 0; i < argc; i ++) { - GList *list_head = *list; - strings[argc - i] = (*list)->data; - *list = g_list_remove_link(*list, *list); - g_list_free_1(list_head); - } - - *list = g_list_prepend(*list, g_strjoinv(" ", strings)); - - for (i = 0 ; i < argc + 2; i ++) - g_free (strings[i]); - - g_free (strings); - } - - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = FALSE; - - return r; -} - -static ESExpResult * -func_not(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - GList **list = data; - ESExpResult *r; - - /* just replace the head of the list with the NOT of it. */ - if (argc > 0) { - char *term = (*list)->data; - (*list)->data = g_strdup_printf("(!%s)", term); - g_free (term); - } - - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = FALSE; - - return r; -} - -static ESExpResult * -func_contains(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - GList **list = data; - ESExpResult *r; - - if (argc == 2 - && argv[0]->type == ESEXP_RES_STRING - && argv[1]->type == ESEXP_RES_STRING) { - char *propname = argv[0]->value.string; - char *str = argv[1]->value.string; - gboolean one_star = FALSE; - - if (strlen(str) == 0) - one_star = TRUE; - - if (!strcmp (propname, "x-evolution-any-field")) { - int i; - int query_length; - char *big_query; - char *header, *footer; - char *match_str; - - header = g_malloc0((num_prop_infos - 1) * 2 + 1); - footer = g_malloc0(num_prop_infos + 1); - for (i = 0; i < num_prop_infos - 1; i ++) { - strcat (header, "(|"); - strcat (footer, ")"); - } - - match_str = g_strdup_printf("=*%s%s)", - str, one_star ? "" : "*"); - - query_length = strlen (header); - - for (i = 0; i < num_prop_infos; i ++) { - query_length += 1 + strlen(prop_info[i].ldap_attr) + strlen (match_str); - } - - big_query = g_malloc0(query_length + 1); - strcat (big_query, header); - for (i = 0; i < num_prop_infos; i ++) { - strcat (big_query, "("); - strcat (big_query, prop_info[i].ldap_attr); - strcat (big_query, match_str); - } - strcat (big_query, footer); - - *list = g_list_prepend(*list, big_query); - - g_free (match_str); - g_free (header); - g_free (footer); - } - else { - char *ldap_attr = query_prop_to_ldap(propname); - - if (ldap_attr) - *list = g_list_prepend(*list, - g_strdup_printf("(%s=*%s%s)", - ldap_attr, - str, - one_star ? "" : "*")); - } - } - - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = FALSE; - - return r; -} - -static ESExpResult * -func_is(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - GList **list = data; - ESExpResult *r; - - if (argc == 2 - && argv[0]->type == ESEXP_RES_STRING - && argv[1]->type == ESEXP_RES_STRING) { - char *propname = argv[0]->value.string; - char *str = argv[1]->value.string; - char *ldap_attr = query_prop_to_ldap(propname); - - if (ldap_attr) - *list = g_list_prepend(*list, - g_strdup_printf("(%s=%s)", - ldap_attr, str)); - } - - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = FALSE; - - return r; -} - -static ESExpResult * -func_beginswith(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - GList **list = data; - ESExpResult *r; - - if (argc == 2 - && argv[0]->type == ESEXP_RES_STRING - && argv[1]->type == ESEXP_RES_STRING) { - char *propname = argv[0]->value.string; - char *str = argv[1]->value.string; - char *ldap_attr = query_prop_to_ldap(propname); - gboolean one_star = FALSE; - - if (strlen(str) == 0) - one_star = TRUE; - - if (ldap_attr) - *list = g_list_prepend(*list, - g_strdup_printf("(%s=%s*)", - ldap_attr, - str)); - } - - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = FALSE; - - return r; -} - -static ESExpResult * -func_endswith(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - GList **list = data; - ESExpResult *r; - - if (argc == 2 - && argv[0]->type == ESEXP_RES_STRING - && argv[1]->type == ESEXP_RES_STRING) { - char *propname = argv[0]->value.string; - char *str = argv[1]->value.string; - char *ldap_attr = query_prop_to_ldap(propname); - gboolean one_star = FALSE; - - if (strlen(str) == 0) - one_star = TRUE; - - if (ldap_attr) - *list = g_list_prepend(*list, - g_strdup_printf("(%s=*%s)", - ldap_attr, - str)); - } - - r = e_sexp_result_new(ESEXP_RES_BOOL); - r->value.bool = FALSE; - - return r; -} - -/* 'builtin' functions */ -static struct { - char *name; - ESExpFunc *func; - int type; /* set to 1 if a function can perform shortcut evaluation, or - doesn't execute everything, 0 otherwise */ -} symbols[] = { - { "and", func_and, 0 }, - { "or", func_or, 0 }, - { "not", func_not, 0 }, - { "contains", func_contains, 0 }, - { "is", func_is, 0 }, - { "beginswith", func_beginswith, 0 }, - { "endswith", func_endswith, 0 }, -}; - -static gchar * -pas_backend_ldap_build_query (gchar *query) -{ - ESExp *sexp; - ESExpResult *r; - gchar *retval; - GList *list = NULL; - int i; - - sexp = e_sexp_new(); - - for(i=0;i<sizeof(symbols)/sizeof(symbols[0]);i++) { - if (symbols[i].type == 1) { - e_sexp_add_ifunction(sexp, 0, symbols[i].name, - (ESExpIFunc *)symbols[i].func, &list); - } else { - e_sexp_add_function(sexp, 0, symbols[i].name, - symbols[i].func, &list); - } - } - - e_sexp_input_text(sexp, query, strlen(query)); - e_sexp_parse(sexp); - - r = e_sexp_eval(sexp); - - gtk_object_unref(GTK_OBJECT(sexp)); - e_sexp_result_free(r); - - if (list->next) { - g_warning ("conversion to ldap query string failed"); - retval = NULL; - g_list_foreach (list, (GFunc)g_free, NULL); - } - else { - retval = list->data; - } - - g_list_free (list); - return retval; -} - -static gchar * -query_prop_to_ldap(gchar *query_prop) -{ - int i; - - for (i = 0; i < num_prop_infos; i ++) - if (!strcmp (query_prop, prop_info[i].query_prop)) - return prop_info[i].ldap_attr; - - return NULL; -} - - -typedef struct { - LDAPOp op; - char *ldap_query; - PASBackendLDAP *bl; - PASBackendLDAPBookView *view; -} LDAPSearchOp; - -static ECardSimple * -build_card_from_entry (LDAP *ldap, LDAPMessage *e) -{ - ECard *ecard = E_CARD(gtk_type_new(e_card_get_type())); - ECardSimple *card = e_card_simple_new (ecard); - char *dn = ldap_get_dn(ldap, e); - char *attr; - BerElement *ber = NULL; - - g_print ("build_card_from_entry, dn = %s\n", dn); - e_card_simple_set_id (card, dn); - - for (attr = ldap_first_attribute (ldap, e, &ber); attr; - attr = ldap_next_attribute (ldap, e, ber)) { - int i; - struct prop_info *info = NULL; - - for (i = 0; i < num_prop_infos; i ++) - if (!strcmp (attr, prop_info[i].ldap_attr)) - info = &prop_info[i]; - - if (info) { - char **values; - values = ldap_get_values (ldap, e, attr); - - if (info->prop_type & PROP_TYPE_NORMAL) { - /* if it's a normal property just set the string */ - e_card_simple_set (card, info->field_id, values[0]); - - } - else if (info->prop_type & PROP_TYPE_LIST) { - /* if it's a list call the ecard-populate function, - which calls gtk_object_set to set the property */ - info->populate_ecard_func(card, - values); - } - - ldap_value_free (values); - } - } - - /* if ldap->ld_errno == LDAP_DECODING_ERROR there was an - error decoding an attribute, and we shouldn't free ber, - since the ldap library already did it. */ - if (ldap->ld_errno != LDAP_DECODING_ERROR && ber) - ber_free (ber, 0); - - e_card_simple_sync_card (card); - - return card; -} - -static gboolean -poll_ldap (LDAPSearchOp *op) -{ - PASBackendLDAPBookView *view = op->view; - PASBackendLDAP *bl = op->bl; - LDAP *ldap = bl->priv->ldap; - int rc; - LDAPMessage *res, *e; - GList *cards = NULL; - static int received = 0; - - pas_book_view_notify_status_message (view->book_view, "Polling for LDAP search result"); - - rc = ldap_result (ldap, view->search_msgid, 0, NULL, &res); - - if (rc == -1 && received == 0) { - pas_book_view_notify_status_message (view->book_view, "Restarting search"); - /* connection went down and we never got any. */ - bl->priv->connected = FALSE; - - /* this will reopen the connection */ - ldap_op_restart ((LDAPOp*)op); - return FALSE; - } - - if (rc != LDAP_RES_SEARCH_ENTRY) { - view->search_idle = 0; - pas_book_view_notify_complete (view->book_view); - ldap_op_finished ((LDAPOp*)op); - received = 0; - pas_book_view_notify_status_message (view->book_view, "Search complete"); - return FALSE; - } - - received = 1; - - e = ldap_first_entry(ldap, res); - - while (NULL != e) { - ECardSimple *card = build_card_from_entry (ldap, e); - - cards = g_list_append (cards, e_card_simple_get_vcard (card)); - - gtk_object_unref (GTK_OBJECT(card)); - - e = ldap_next_entry(ldap, e); - } - - if (cards) { - pas_book_view_notify_add (view->book_view, cards); - - g_list_foreach (cards, (GFunc)g_free, NULL); - g_list_free (cards); - cards = NULL; - } - - ldap_msgfree(res); - - return TRUE; -} - -static gboolean -ldap_search_handler (PASBackend *backend, LDAPOp *op) -{ - LDAPSearchOp *search_op = (LDAPSearchOp*) op; - - if (op->view) - pas_book_view_notify_status_message (op->view, "Searching..."); - - /* it might not be NULL if we've been restarted */ - if (search_op->ldap_query == NULL) - search_op->ldap_query = pas_backend_ldap_build_query(search_op->view->search); - - if (search_op->ldap_query != NULL) { - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - PASBackendLDAPBookView *view = search_op->view; - LDAP *ldap = bl->priv->ldap; - - ldap->ld_sizelimit = LDAP_MAX_SEARCH_RESPONSES; - ldap->ld_deref = LDAP_DEREF_ALWAYS; - - if ((view->search_msgid = ldap_search (ldap, - bl->priv->ldap_rootdn, - bl->priv->ldap_scope, - search_op->ldap_query, - NULL, 0)) == -1) { - pas_book_view_notify_status_message (view->book_view, ldap_err2string(ldap->ld_errno)); - return TRUE; /* act synchronous in this case */ - } - else { - view->search_idle = g_idle_add((GSourceFunc)poll_ldap, search_op); - } - - /* we're async */ - return FALSE; - } - else { - /* error doing the conversion to an ldap query, let's - end this now by acting like we're synchronous. */ - g_warning ("LDAP problem converting search query %s\n", search_op->view->search); - return TRUE; - } -} - -static void -ldap_search_dtor (PASBackend *backend, LDAPOp *op) -{ - LDAPSearchOp *search_op = (LDAPSearchOp*) op; - - g_free (search_op->ldap_query); - g_free (search_op); -} - -static void -pas_backend_ldap_search (PASBackendLDAP *bl, - PASBook *book, - PASBackendLDAPBookView *view) -{ - LDAPSearchOp *op = g_new (LDAPSearchOp, 1); - - ldap_op_init ((LDAPOp*)op, PAS_BACKEND(bl), book, view->book_view, ldap_search_handler, ldap_search_dtor); - - op->ldap_query = NULL; - op->view = view; - op->bl = bl; - - /* keep track of the search op so we can delete it from the - list if the view is destroyed */ - view->search_op = (LDAPOp*)op; - - ldap_op_process ((LDAPOp*)op); -} - -static void -pas_backend_ldap_process_get_book_view (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - CORBA_Environment ev; - Evolution_Book corba_book; - PASBookView *book_view; - PASBackendLDAPBookView *view; - - g_return_if_fail (req->listener != NULL); - - corba_book = bonobo_object_corba_objref(BONOBO_OBJECT(book)); - - CORBA_exception_init(&ev); - - Evolution_Book_ref(corba_book, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("pas_backend_file_process_get_book_view: Exception reffing " - "corba book.\n"); - } - - CORBA_exception_free(&ev); - - book_view = pas_book_view_new (req->listener); - - gtk_signal_connect(GTK_OBJECT(book_view), "destroy", - GTK_SIGNAL_FUNC(view_destroy), book); - - pas_book_respond_get_book_view (book, - (book_view != NULL - ? Evolution_BookListener_Success - : Evolution_BookListener_CardNotFound /* XXX */), - book_view); - - view = g_new0(PASBackendLDAPBookView, 1); - view->book_view = book_view; - view->search = g_strdup(req->search); - view->blpriv = bl->priv; - - bl->priv->book_views = g_list_prepend(bl->priv->book_views, view); - - pas_backend_ldap_search (bl, book, view); - -} - -static void -pas_backend_ldap_process_check_connection (PASBackend *backend, - PASBook *book, - PASRequest *req) -{ - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - - pas_book_report_connection (book, bl->priv->connected); -} - -static gboolean -pas_backend_ldap_can_write (PASBook *book) -{ - return TRUE; /* XXX */ -} - -static gboolean -pas_backend_ldap_can_write_card (PASBook *book, - const char *id) -{ - return TRUE; /* XXX */ -} - -static void -pas_backend_ldap_process_client_requests (PASBook *book) -{ - PASBackend *backend; - PASRequest *req; - - backend = pas_book_get_backend (book); - - req = pas_book_pop_request (book); - if (req == NULL) - return; - - switch (req->op) { - case CreateCard: - pas_backend_ldap_process_create_card (backend, book, req); - break; - - case RemoveCard: - pas_backend_ldap_process_remove_card (backend, book, req); - break; - - case ModifyCard: - pas_backend_ldap_process_modify_card (backend, book, req); - break; - - case CheckConnection: - pas_backend_ldap_process_check_connection (backend, book, req); - break; - - case GetCursor: - pas_backend_ldap_process_get_cursor (backend, book, req); - break; - - case GetBookView: - pas_backend_ldap_process_get_book_view (backend, book, req); - break; - } - - g_free (req); -} - -static void -pas_backend_ldap_book_destroy_cb (PASBook *book, gpointer data) -{ - PASBackendLDAP *backend; - - backend = PAS_BACKEND_LDAP (data); - - pas_backend_remove_client (PAS_BACKEND (backend), book); -} - -static char * -pas_backend_ldap_get_vcard (PASBook *book, const char *id) -{ - PASBackendLDAP *bl; - int ldap_error = LDAP_SUCCESS; /* XXX */ - - bl = PAS_BACKEND_LDAP (pas_book_get_backend (book)); - - /* XXX use ldap_search */ - - if (ldap_error == LDAP_SUCCESS) { - /* success */ - return g_strdup (""); - } - else { - return g_strdup (""); - } -} - -static gboolean -pas_backend_ldap_load_uri (PASBackend *backend, - const char *uri) -{ - PASBackendLDAP *bl = PAS_BACKEND_LDAP (backend); - LDAPURLDesc *lud; - int ldap_error; - - g_assert (bl->priv->connected == FALSE); - - ldap_error = ldap_url_parse ((char*)uri, &lud); - if (ldap_error == LDAP_SUCCESS) { - g_free(bl->priv->uri); - bl->priv->uri = g_strdup (uri); - bl->priv->ldap_host = g_strdup(lud->lud_host); - bl->priv->ldap_port = lud->lud_port; - /* if a port wasn't specified, default to LDAP_PORT */ - if (bl->priv->ldap_port == 0) - bl->priv->ldap_port = LDAP_PORT; - bl->priv->ldap_rootdn = g_strdup(lud->lud_dn); - bl->priv->ldap_scope = lud->lud_scope; - - ldap_free_urldesc(lud); - - pas_backend_ldap_connect (bl); - if (bl->priv->ldap == NULL) - return FALSE; - else - return TRUE; - } else - return FALSE; -} - -/* Get_uri handler for the addressbook LDAP backend */ -static const char * -pas_backend_ldap_get_uri (PASBackend *backend) -{ - PASBackendLDAP *bl; - - bl = PAS_BACKEND_LDAP (backend); - return bl->priv->uri; -} - -static gboolean -pas_backend_ldap_add_client (PASBackend *backend, - Evolution_BookListener listener) -{ - PASBackendLDAP *bl; - PASBook *book; - - g_assert (backend != NULL); - g_assert (PAS_IS_BACKEND_LDAP (backend)); - - bl = PAS_BACKEND_LDAP (backend); - - book = pas_book_new ( - backend, listener, - pas_backend_ldap_get_vcard, - pas_backend_ldap_can_write, - pas_backend_ldap_can_write_card); - - if (!book) { - if (!bl->priv->clients) - pas_backend_last_client_gone (backend); - - return FALSE; - } - - gtk_signal_connect (GTK_OBJECT (book), "destroy", - pas_backend_ldap_book_destroy_cb, backend); - - gtk_signal_connect (GTK_OBJECT (book), "requests_queued", - pas_backend_ldap_process_client_requests, NULL); - - bl->priv->clients = g_list_prepend ( - bl->priv->clients, book); - - if (bl->priv->connected) { - pas_book_respond_open ( - book, Evolution_BookListener_Success); - } else { - /* Open the book. */ - pas_book_respond_open ( - book, Evolution_BookListener_Success); - } - - return TRUE; -} - -static void -pas_backend_ldap_remove_client (PASBackend *backend, - PASBook *book) -{ - PASBackendLDAP *bl; - GList *l; - PASBook *lbook; - - g_return_if_fail (backend != NULL); - g_return_if_fail (PAS_IS_BACKEND_LDAP (backend)); - g_return_if_fail (book != NULL); - g_return_if_fail (PAS_IS_BOOK (book)); - - bl = PAS_BACKEND_LDAP (backend); - - /* Find the book in the list of clients */ - - for (l = bl->priv->clients; l; l = l->next) { - lbook = PAS_BOOK (l->data); - - if (lbook == book) - break; - } - - g_assert (l != NULL); - - /* Disconnect */ - - bl->priv->clients = g_list_remove_link (bl->priv->clients, l); - g_list_free_1 (l); - - /* When all clients go away, notify the parent factory about it so that - * it may decide whether to kill the backend or not. - */ - if (!bl->priv->clients) - pas_backend_last_client_gone (backend); -} - -static char * -pas_backend_ldap_get_static_capabilites (PASBackend *backend) -{ - return g_strdup("net"); -} - -static gboolean -pas_backend_ldap_construct (PASBackendLDAP *backend) -{ - g_assert (backend != NULL); - g_assert (PAS_IS_BACKEND_LDAP (backend)); - - if (! pas_backend_construct (PAS_BACKEND (backend))) - return FALSE; - - return TRUE; -} - -/** - * pas_backend_ldap_new: - */ -PASBackend * -pas_backend_ldap_new (void) -{ - PASBackendLDAP *backend; - - backend = gtk_type_new (pas_backend_ldap_get_type ()); - - if (! pas_backend_ldap_construct (backend)) { - gtk_object_unref (GTK_OBJECT (backend)); - - return NULL; - } - - return PAS_BACKEND (backend); -} - -static void -call_dtor (LDAPOp *op, gpointer data) -{ - op->dtor (op->backend, op); -} - -static void -pas_backend_ldap_destroy (GtkObject *object) -{ - PASBackendLDAP *bl; - - bl = PAS_BACKEND_LDAP (object); - - g_list_foreach (bl->priv->pending_ops, (GFunc)call_dtor, NULL); - g_list_free (bl->priv->pending_ops); - - g_free (bl->priv->uri); - - GTK_OBJECT_CLASS (pas_backend_ldap_parent_class)->destroy (object); -} - -static void -pas_backend_ldap_class_init (PASBackendLDAPClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - PASBackendClass *parent_class; - - pas_backend_ldap_parent_class = gtk_type_class (pas_backend_get_type ()); - - parent_class = PAS_BACKEND_CLASS (klass); - - /* Set the virtual methods. */ - parent_class->load_uri = pas_backend_ldap_load_uri; - parent_class->get_uri = pas_backend_ldap_get_uri; - parent_class->add_client = pas_backend_ldap_add_client; - parent_class->remove_client = pas_backend_ldap_remove_client; - parent_class->get_static_capabilities = pas_backend_ldap_get_static_capabilites; - - object_class->destroy = pas_backend_ldap_destroy; -} - -static void -pas_backend_ldap_init (PASBackendLDAP *backend) -{ - PASBackendLDAPPrivate *priv; - - priv = g_new0 (PASBackendLDAPPrivate, 1); - priv->connected = FALSE; - priv->clients = NULL; - priv->uri = NULL; - - backend->priv = priv; -} - -/** - * pas_backend_ldap_get_type: - */ -GtkType -pas_backend_ldap_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "PASBackendLDAP", - sizeof (PASBackendLDAP), - sizeof (PASBackendLDAPClass), - (GtkClassInitFunc) pas_backend_ldap_class_init, - (GtkObjectInitFunc) pas_backend_ldap_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (pas_backend_get_type (), &info); - } - - return type; -} diff --git a/addressbook/backend/pas/pas-backend-ldap.h b/addressbook/backend/pas/pas-backend-ldap.h deleted file mode 100644 index a59cdf3857..0000000000 --- a/addressbook/backend/pas/pas-backend-ldap.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2000, Helix Code, Inc. - */ - -#ifndef __PAS_BACKEND_LDAP_H__ -#define __PAS_BACKEND_LDAP_H__ - -#include <libgnome/gnome-defs.h> -#include "pas-backend.h" - -typedef struct _PASBackendLDAPPrivate PASBackendLDAPPrivate; - -typedef struct { - PASBackend parent_object; - PASBackendLDAPPrivate *priv; -} PASBackendLDAP; - -typedef struct { - PASBackendClass parent_class; -} PASBackendLDAPClass; - -PASBackend *pas_backend_ldap_new (void); -GtkType pas_backend_ldap_get_type (void); - -#define PAS_BACKEND_LDAP_TYPE (pas_backend_ldap_get_type ()) -#define PAS_BACKEND_LDAP(o) (GTK_CHECK_CAST ((o), PAS_BACKEND_LDAP_TYPE, PASBackendLDAP)) -#define PAS_BACKEND_LDAP_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_BACKEND_TYPE, PASBackendLDAPClass)) -#define PAS_IS_BACKEND_LDAP(o) (GTK_CHECK_TYPE ((o), PAS_BACKEND_LDAP_TYPE)) -#define PAS_IS_BACKEND_LDAP_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_BACKEND_LDAP_TYPE)) - -#endif /* ! __PAS_BACKEND_LDAP_H__ */ - diff --git a/addressbook/backend/pas/pas-backend.c b/addressbook/backend/pas/pas-backend.c deleted file mode 100644 index 1568918560..0000000000 --- a/addressbook/backend/pas/pas-backend.c +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Author: - * Nat Friedman (nat@helixcode.com) - * - * Copyright 2000, Helix Code, Inc. - */ - -#include <config.h> -#include <gtk/gtkobject.h> -#include <gtk/gtksignal.h> -#include "pas-backend.h" - -#define CLASS(o) PAS_BACKEND_CLASS (GTK_OBJECT (o)->klass) - -/* Signal IDs */ -enum { - LAST_CLIENT_GONE, - LAST_SIGNAL -}; - -static guint pas_backend_signals[LAST_SIGNAL]; - - -gboolean -pas_backend_construct (PASBackend *backend) -{ - return TRUE; -} - -gboolean -pas_backend_load_uri (PASBackend *backend, - const char *uri) -{ - g_return_val_if_fail (backend != NULL, FALSE); - g_return_val_if_fail (PAS_IS_BACKEND (backend), FALSE); - g_return_val_if_fail (uri != NULL, FALSE); - - g_assert (CLASS (backend)->load_uri != NULL); - - return (* CLASS (backend)->load_uri) (backend, uri); -} - -/** - * pas_backend_get_uri: - * @backend: An addressbook backend. - * - * Queries the URI that an addressbook backend is serving. - * - * Return value: URI for the backend. - **/ -const char * -pas_backend_get_uri (PASBackend *backend) -{ - g_return_val_if_fail (backend != NULL, NULL); - g_return_val_if_fail (PAS_IS_BACKEND (backend), NULL); - - g_assert (CLASS (backend)->get_uri != NULL); - - return (* CLASS (backend)->get_uri) (backend); -} - -/** - * pas_backend_add_client: - * @backend: An addressbook backend. - * @listener: Listener for notification to the client. - * - * Adds a client to an addressbook backend. - * - * Return value: TRUE on success, FALSE on failure to add the client. - */ -gboolean -pas_backend_add_client (PASBackend *backend, - Evolution_BookListener listener) -{ - g_return_val_if_fail (backend != NULL, FALSE); - g_return_val_if_fail (PAS_IS_BACKEND (backend), FALSE); - g_return_val_if_fail (listener != CORBA_OBJECT_NIL, FALSE); - - g_assert (CLASS (backend)->add_client != NULL); - - return CLASS (backend)->add_client (backend, listener); -} - -void -pas_backend_remove_client (PASBackend *backend, - PASBook *book) -{ - g_return_if_fail (backend != NULL); - g_return_if_fail (PAS_IS_BACKEND (backend)); - g_return_if_fail (book != NULL); - g_return_if_fail (PAS_IS_BOOK (book)); - - g_assert (CLASS (backend)->remove_client != NULL); - - CLASS (backend)->remove_client (backend, book); -} - -char * -pas_backend_get_static_capabilities (PASBackend *backend) -{ - g_return_val_if_fail (backend != NULL, NULL); - g_return_val_if_fail (PAS_IS_BACKEND (backend), NULL); - - g_assert (CLASS (backend)->get_static_capabilities != NULL); - - return CLASS (backend)->get_static_capabilities (backend); -} - -/** - * pas_backend_last_client_gone: - * @backend: An addressbook backend. - * - * Emits the "last_client_gone" signal for the specified backend. Should - * only be called from backend implementations if the backend really does - * not have any more clients. - **/ -void -pas_backend_last_client_gone (PASBackend *backend) -{ - g_return_if_fail (backend != NULL); - g_return_if_fail (PAS_IS_BACKEND (backend)); - - gtk_signal_emit (GTK_OBJECT (backend), pas_backend_signals[LAST_CLIENT_GONE]); -} - -static void -pas_backend_init (PASBackend *backend) -{ -} - -static void -pas_backend_class_init (PASBackendClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) klass; - - pas_backend_signals[LAST_CLIENT_GONE] = - gtk_signal_new ("last_client_gone", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (PASBackendClass, last_client_gone), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, pas_backend_signals, LAST_SIGNAL); - - klass->add_client = NULL; - klass->remove_client = NULL; - klass->get_static_capabilities = NULL; -} - -/** - * pas_backend_get_type: - */ -GtkType -pas_backend_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "PASBackend", - sizeof (PASBackend), - sizeof (PASBackendClass), - (GtkClassInitFunc) pas_backend_class_init, - (GtkObjectInitFunc) pas_backend_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} diff --git a/addressbook/backend/pas/pas-backend.h b/addressbook/backend/pas/pas-backend.h deleted file mode 100644 index 4045074284..0000000000 --- a/addressbook/backend/pas/pas-backend.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * An abstract class which defines the API to a given backend. - * There will be one PASBackend object for every URI which is loaded. - * - * Two people will call into the PASBackend API: - * - * 1. The PASBookFactory, when it has been asked to load a book. - * It will create a new PASBackend if one is not already running - * for the requested URI. It will call pas_backend_add_client to - * add a new client to an existing PASBackend server. - * - * 2. A PASBook, when a client has requested an operation on the - * Evolution_Book interface. - * - * Author: - * Nat Friedman (nat@helixcode.com) - * - * Copyright 2000, Helix Code, Inc. - */ - -#ifndef __PAS_BACKEND_H__ -#define __PAS_BACKEND_H__ - -#include <libgnome/gnome-defs.h> -#include <gtk/gtkobject.h> -#include <pas/addressbook.h> - -typedef struct _PASBackend PASBackend; -typedef struct _PASBackendPrivate PASBackendPrivate; - -#include <pas/pas-book.h> - -struct _PASBackend { - GtkObject parent_object; - PASBackendPrivate *priv; -}; - -typedef struct { - GtkObjectClass parent_class; - - /* Virtual methods */ - gboolean (*load_uri) (PASBackend *backend, const char *uri); - const char *(* get_uri) (PASBackend *backend); - gboolean (*add_client) (PASBackend *backend, Evolution_BookListener listener); - void (*remove_client) (PASBackend *backend, PASBook *book); - char *(*get_static_capabilities) (PASBackend *backend); - - /* Notification signals */ - void (* last_client_gone) (PASBackend *backend); -} PASBackendClass; - -typedef PASBackend * (*PASBackendFactoryFn) (void); - -gboolean pas_backend_construct (PASBackend *backend); -gboolean pas_backend_load_uri (PASBackend *backend, - const char *uri); -const char *pas_backend_get_uri (PASBackend *backend); - -gboolean pas_backend_add_client (PASBackend *backend, - Evolution_BookListener listener); -void pas_backend_remove_client (PASBackend *backend, - PASBook *book); -char *pas_backend_get_static_capabilities (PASBackend *backend); - -void pas_backend_last_client_gone (PASBackend *backend); - -GtkType pas_backend_get_type (void); - -#define PAS_BACKEND_TYPE (pas_backend_get_type ()) -#define PAS_BACKEND(o) (GTK_CHECK_CAST ((o), PAS_BACKEND_TYPE, PASBackend)) -#define PAS_BACKEND_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_BACKEND_TYPE, PASBackendClass)) -#define PAS_IS_BACKEND(o) (GTK_CHECK_TYPE ((o), PAS_BACKEND_TYPE)) -#define PAS_IS_BACKEND_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_BACKEND_TYPE)) - -#endif /* ! __PAS_BACKEND_H__ */ - diff --git a/addressbook/backend/pas/pas-book-factory.c b/addressbook/backend/pas/pas-book-factory.c deleted file mode 100644 index 02dedbabe5..0000000000 --- a/addressbook/backend/pas/pas-book-factory.c +++ /dev/null @@ -1,595 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * - * Author: - * Nat Friedman (nat@helixcode.com) - * - * Copyright 2000, Helix Code, Inc. - */ - -#include <config.h> -#include <ctype.h> -#include <gnome.h> -#include <liboaf/liboaf.h> - -#include "addressbook.h" -#include "pas-book-factory.h" - -#define PAS_BOOK_FACTORY_OAF_ID "OAFIID:evolution:addressbook-server:0fbc844d-c721-4615-98d0-d67eacf42d80" - -static BonoboObjectClass *pas_book_factory_parent_class; -POA_Evolution_BookFactory__vepv pas_book_factory_vepv; - -typedef struct { - char *uri; - Evolution_BookListener listener; -} PASBookFactoryQueuedRequest; - -struct _PASBookFactoryPrivate { - gint idle_id; - GHashTable *backends; - GHashTable *active_server_map; - GList *queued_requests; -}; - -/* Signal IDs */ -enum { - LAST_BOOK_GONE, - LAST_SIGNAL -}; - -static guint factory_signals[LAST_SIGNAL]; - -static char * -pas_book_factory_canonicalize_uri (const char *uri) -{ - /* FIXME: What do I do here? */ - - return g_strdup (uri); -} - -static char * -pas_book_factory_extract_proto_from_uri (const char *uri) -{ - char *proto; - char *p; - - p = strchr (uri, ':'); - - if (p == NULL) - return NULL; - - proto = g_malloc0 (p - uri + 1); - - strncpy (proto, uri, p - uri); - - return proto; -} - -/** - * pas_book_factory_register_backend: - * @factory: - * @proto: - * @backend: - */ -void -pas_book_factory_register_backend (PASBookFactory *factory, - const char *proto, - PASBackendFactoryFn backend) -{ - g_return_if_fail (factory != NULL); - g_return_if_fail (PAS_IS_BOOK_FACTORY (factory)); - g_return_if_fail (proto != NULL); - g_return_if_fail (backend != NULL); - - if (g_hash_table_lookup (factory->priv->backends, proto) != NULL) { - g_warning ("pas_book_factory_register_backend: " - "Proto \"%s\" already registered!\n", proto); - } - - g_hash_table_insert (factory->priv->backends, - g_strdup (proto), backend); -} - -/** - * pas_book_factory_get_n_backends: - * @factory: An addressbook factory. - * - * Queries the number of running addressbook backends in an addressbook factory. - * - * Return value: Number of running backends. - **/ -int -pas_book_factory_get_n_backends (PASBookFactory *factory) -{ - g_return_val_if_fail (factory != NULL, -1); - g_return_val_if_fail (PAS_IS_BOOK_FACTORY (factory), -1); - - return g_hash_table_size (factory->priv->active_server_map); -} - -/* Callback used when a backend loses its last connected client */ -static void -backend_last_client_gone_cb (PASBackend *backend, gpointer data) -{ - PASBookFactory *factory; - const char *uri; - gpointer orig_key; - gboolean result; - char *orig_uri; - - factory = PAS_BOOK_FACTORY (data); - - /* Remove the backend from the active server map */ - - uri = pas_backend_get_uri (backend); - g_assert (uri != NULL); - - result = g_hash_table_lookup_extended (factory->priv->active_server_map, uri, - &orig_key, NULL); - g_assert (result != FALSE); - - orig_uri = orig_key; - - g_hash_table_remove (factory->priv->active_server_map, orig_uri); - g_free (orig_uri); - - gtk_object_unref (GTK_OBJECT (backend)); - - /* Notify upstream if there are no more backends */ - - if (g_hash_table_size (factory->priv->active_server_map) == 0) - gtk_signal_emit (GTK_OBJECT (factory), factory_signals[LAST_BOOK_GONE]); -} - -static PASBackendFactoryFn -pas_book_factory_lookup_backend_factory (PASBookFactory *factory, - const char *uri) -{ - PASBackendFactoryFn backend_fn; - char *proto; - char *canonical_uri; - - g_assert (factory != NULL); - g_assert (PAS_IS_BOOK_FACTORY (factory)); - g_assert (uri != NULL); - - canonical_uri = pas_book_factory_canonicalize_uri (uri); - if (canonical_uri == NULL) - return NULL; - - proto = pas_book_factory_extract_proto_from_uri (canonical_uri); - if (proto == NULL) { - g_free (canonical_uri); - return NULL; - } - - backend_fn = g_hash_table_lookup (factory->priv->backends, proto); - - g_free (proto); - g_free (canonical_uri); - - return backend_fn; -} - -static PASBackend * -pas_book_factory_launch_backend (PASBookFactory *factory, - Evolution_BookListener listener, - const char *uri) -{ - PASBackendFactoryFn backend_factory; - PASBackend *backend; - - backend_factory = pas_book_factory_lookup_backend_factory ( - factory, uri); - - if (!backend_factory) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - Evolution_BookListener_respond_open_book ( - listener, - Evolution_BookListener_ProtocolNotSupported, - CORBA_OBJECT_NIL, - &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("pas_book_factory_launch_backend(): could not notify " - "the listener"); - - CORBA_exception_free (&ev); - return NULL; - } - - backend = (* backend_factory) (); - if (!backend) { - CORBA_Environment ev; - - CORBA_exception_init (&ev); - Evolution_BookListener_respond_open_book ( - listener, - Evolution_BookListener_OtherError, - CORBA_OBJECT_NIL, - &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("pas_book_factory_launch_backend(): could not notify " - "the listener"); - - CORBA_exception_free (&ev); - return NULL; - } - - g_hash_table_insert (factory->priv->active_server_map, - g_strdup (uri), - backend); - - gtk_signal_connect (GTK_OBJECT (backend), "last_client_gone", - backend_last_client_gone_cb, - factory); - - return backend; -} - -static void -pas_book_factory_process_request (PASBookFactory *factory, - PASBookFactoryQueuedRequest *request) -{ - PASBackend *backend; - char *uri; - Evolution_BookListener listener; - CORBA_Environment ev; - - uri = request->uri; - listener = request->listener; - g_free (request); - - /* Look up the backend and create one if needed */ - - backend = g_hash_table_lookup (factory->priv->active_server_map, uri); - - if (!backend) { - backend = pas_book_factory_launch_backend (factory, listener, uri); - if (!backend) - goto out; - - if (!pas_backend_add_client (backend, listener)) - goto out; - - pas_backend_load_uri (backend, uri); - - goto out; - } - - pas_backend_add_client (backend, listener); - - out: - g_free (uri); - - CORBA_exception_init (&ev); - CORBA_Object_release (listener, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("pas_book_factory_process_request(): could not release the listener"); - - CORBA_exception_free (&ev); -} - -static gboolean -pas_book_factory_process_queue (PASBookFactory *factory) -{ - /* Process pending Book-creation requests. */ - if (factory->priv->queued_requests != NULL) { - PASBookFactoryQueuedRequest *request; - GList *l; - - l = factory->priv->queued_requests; - request = l->data; - - pas_book_factory_process_request (factory, request); - - factory->priv->queued_requests = g_list_remove_link ( - factory->priv->queued_requests, l); - g_list_free_1 (l); - } - - if (factory->priv->queued_requests == NULL) { - - factory->priv->idle_id = 0; - return FALSE; - } - - return TRUE; -} - -static void -pas_book_factory_queue_request (PASBookFactory *factory, - const char *uri, - const Evolution_BookListener listener) -{ - PASBookFactoryQueuedRequest *request; - Evolution_BookListener listener_copy; - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - listener_copy = CORBA_Object_duplicate (listener, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("PASBookFactory: Could not duplicate BookListener!\n"); - CORBA_exception_free (&ev); - return; - } - - CORBA_exception_free (&ev); - - request = g_new0 (PASBookFactoryQueuedRequest, 1); - request->listener = listener_copy; - request->uri = g_strdup (uri); - - factory->priv->queued_requests = - g_list_prepend (factory->priv->queued_requests, request); - - if (! factory->priv->idle_id) { - factory->priv->idle_id = - g_idle_add ((GSourceFunc) pas_book_factory_process_queue, factory); - } -} - - -static void -impl_Evolution_BookFactory_open_book (PortableServer_Servant servant, - const CORBA_char *uri, - const Evolution_BookListener listener, - CORBA_Environment *ev) -{ - PASBookFactory *factory = - PAS_BOOK_FACTORY (bonobo_object_from_servant (servant)); - PASBackendFactoryFn backend_factory; - - backend_factory = pas_book_factory_lookup_backend_factory (factory, uri); - - if (backend_factory == NULL) { - Evolution_BookListener_respond_open_book ( - listener, - Evolution_BookListener_ProtocolNotSupported, - CORBA_OBJECT_NIL, - ev); - - return; - } - - pas_book_factory_queue_request (factory, uri, listener); -} - -static gboolean -pas_book_factory_construct (PASBookFactory *factory) -{ - POA_Evolution_BookFactory *servant; - CORBA_Environment ev; - CORBA_Object obj; - - g_assert (factory != NULL); - g_assert (PAS_IS_BOOK_FACTORY (factory)); - - servant = (POA_Evolution_BookFactory *) g_new0 (BonoboObjectServant, 1); - servant->vepv = &pas_book_factory_vepv; - - CORBA_exception_init (&ev); - - POA_Evolution_BookFactory__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_free (servant); - CORBA_exception_free (&ev); - - return FALSE; - } - - CORBA_exception_free (&ev); - - obj = bonobo_object_activate_servant (BONOBO_OBJECT (factory), servant); - if (obj == CORBA_OBJECT_NIL) { - g_free (servant); - - return FALSE; - } - - bonobo_object_construct (BONOBO_OBJECT (factory), obj); - - return TRUE; -} - -/** - * pas_book_factory_new: - */ -PASBookFactory * -pas_book_factory_new (void) -{ - PASBookFactory *factory; - - factory = gtk_type_new (pas_book_factory_get_type ()); - - if (! pas_book_factory_construct (factory)) { - g_warning ("pas_book_factory_new: Could not construct PASBookFactory!\n"); - gtk_object_unref (GTK_OBJECT (factory)); - - return NULL; - } - - return factory; -} - -static gboolean -register_factory (CORBA_Object obj) -{ - OAF_RegistrationResult result; - - puts ("about to register addressbook"); - - result = oaf_active_server_register (PAS_BOOK_FACTORY_OAF_ID, obj); - - switch (result) { - case OAF_REG_SUCCESS: - return TRUE; - case OAF_REG_NOT_LISTED: - g_message ("Error registering the PAS factory: not listed"); - return FALSE; - case OAF_REG_ALREADY_ACTIVE: - g_message ("Error registering the PAS factory: already active"); - return FALSE; - case OAF_REG_ERROR: - default: - g_message ("Error registering the PAS factory: generic error"); - return FALSE; - } -} - -/** - * pas_book_factory_activate: - */ -void -pas_book_factory_activate (PASBookFactory *factory) -{ - g_return_if_fail (factory != NULL); - g_return_if_fail (PAS_IS_BOOK_FACTORY (factory)); - - register_factory (bonobo_object_corba_objref (BONOBO_OBJECT (factory))); -} - -static void -pas_book_factory_init (PASBookFactory *factory) -{ - factory->priv = g_new0 (PASBookFactoryPrivate, 1); - - factory->priv->active_server_map = g_hash_table_new (g_str_hash, g_str_equal); - factory->priv->backends = g_hash_table_new (g_str_hash, g_str_equal); - factory->priv->queued_requests = NULL; -} - -static void -free_active_server_map_entry (gpointer key, gpointer value, gpointer data) -{ - char *uri; - PASBackend *backend; - - uri = key; - g_free (uri); - - backend = PAS_BACKEND (value); - gtk_object_unref (GTK_OBJECT (backend)); -} - -static void -remove_backends_entry (gpointer key, gpointer value, gpointer data) -{ - char *uri; - - uri = key; - g_free (uri); -} - -static void -pas_book_factory_destroy (GtkObject *object) -{ - PASBookFactory *factory = PAS_BOOK_FACTORY (object); - GList *l; - - for (l = factory->priv->queued_requests; l != NULL; l = l->next) { - PASBookFactoryQueuedRequest *request = l->data; - CORBA_Environment ev; - - g_free (request->uri); - - CORBA_exception_init (&ev); - CORBA_Object_release (request->listener, &ev); - CORBA_exception_free (&ev); - - g_free (request); - } - g_list_free (factory->priv->queued_requests); - factory->priv->queued_requests = NULL; - - g_hash_table_foreach (factory->priv->active_server_map, - free_active_server_map_entry, - NULL); - g_hash_table_destroy (factory->priv->active_server_map); - factory->priv->active_server_map = NULL; - - g_hash_table_foreach (factory->priv->backends, - remove_backends_entry, - NULL); - g_hash_table_destroy (factory->priv->backends); - factory->priv->backends = NULL; - - g_free (factory->priv); - - GTK_OBJECT_CLASS (pas_book_factory_parent_class)->destroy (object); -} - -static POA_Evolution_BookFactory__epv * -pas_book_factory_get_epv (void) -{ - POA_Evolution_BookFactory__epv *epv; - - epv = g_new0 (POA_Evolution_BookFactory__epv, 1); - - epv->open_book = impl_Evolution_BookFactory_open_book; - - return epv; - -} - -static void -pas_book_factory_corba_class_init (void) -{ - pas_book_factory_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); - pas_book_factory_vepv.Evolution_BookFactory_epv = pas_book_factory_get_epv (); -} - -static void -pas_book_factory_class_init (PASBookFactoryClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - pas_book_factory_parent_class = gtk_type_class (bonobo_object_get_type ()); - - factory_signals[LAST_BOOK_GONE] = - gtk_signal_new ("last_book_gone", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (PASBookFactoryClass, last_book_gone), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, factory_signals, LAST_SIGNAL); - - object_class->destroy = pas_book_factory_destroy; - - pas_book_factory_corba_class_init (); -} - -/** - * pas_book_factory_get_type: - */ -GtkType -pas_book_factory_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "PASBookFactory", - sizeof (PASBookFactory), - sizeof (PASBookFactoryClass), - (GtkClassInitFunc) pas_book_factory_class_init, - (GtkObjectInitFunc) pas_book_factory_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (bonobo_object_get_type (), &info); - } - - return type; -} diff --git a/addressbook/backend/pas/pas-book-factory.h b/addressbook/backend/pas/pas-book-factory.h deleted file mode 100644 index 7e4690adf1..0000000000 --- a/addressbook/backend/pas/pas-book-factory.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2000, Helix Code, Inc. - */ - -#include <bonobo/bonobo-object.h> -#include <libgnome/gnome-defs.h> - -#include <pas/pas-backend.h> - -#ifndef __PAS_BOOK_FACTORY_H__ -#define __PAS_BOOK_FACTORY_H__ - -BEGIN_GNOME_DECLS - -typedef struct _PASBookFactoryPrivate PASBookFactoryPrivate; - -typedef struct { - BonoboObject parent_object; - PASBookFactoryPrivate *priv; -} PASBookFactory; - -typedef struct { - BonoboObjectClass parent_class; - - /* Notification signals */ - - void (* last_book_gone) (PASBookFactory *factory); -} PASBookFactoryClass; - -PASBookFactory *pas_book_factory_new (void); - -void pas_book_factory_register_backend (PASBookFactory *factory, - const char *proto, - PASBackendFactoryFn backend_factory); - -int pas_book_factory_get_n_backends (PASBookFactory *factory); - -void pas_book_factory_activate (PASBookFactory *factory); - -GtkType pas_book_factory_get_type (void); - -#define PAS_BOOK_FACTORY_TYPE (pas_book_factory_get_type ()) -#define PAS_BOOK_FACTORY(o) (GTK_CHECK_CAST ((o), PAS_BOOK_FACTORY_TYPE, PASBookFactory)) -#define PAS_BOOK_FACTORY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_BOOK_FACTORY_TYPE, PASBookFactoryClass)) -#define PAS_IS_BOOK_FACTORY(o) (GTK_CHECK_TYPE ((o), PAS_BOOK_FACTORY_TYPE)) -#define PAS_IS_BOOK_FACTORY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_BOOK_FACTORY_TYPE)) - -END_GNOME_DECLS - -#endif /* ! __PAS_BOOK_FACTORY_H__ */ diff --git a/addressbook/backend/pas/pas-book-view.c b/addressbook/backend/pas/pas-book-view.c deleted file mode 100644 index 94babf6280..0000000000 --- a/addressbook/backend/pas/pas-book-view.c +++ /dev/null @@ -1,334 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * pas-book-view.c - * - * Copyright 2000, Helix Code, Inc. - */ - -#include <config.h> -#include <glib.h> -#include "pas-book-view.h" - -static BonoboObjectClass *pas_book_view_parent_class; -POA_Evolution_BookView__vepv pas_book_view_vepv; - -struct _PASBookViewPrivate { - Evolution_BookViewListener listener; -}; - -/** - * pas_book_view_notify_change: - */ -void -pas_book_view_notify_change (PASBookView *book_view, - const GList *cards) -{ - CORBA_Environment ev; - gint i, length; - CORBA_sequence_Evolution_VCard card_sequence; - - length = g_list_length((GList *) cards); - - card_sequence._buffer = CORBA_sequence_Evolution_VCard_allocbuf(length); - card_sequence._maximum = length; - card_sequence._length = length; - - for ( i = 0; cards; cards = g_list_next(cards), i++ ) { - card_sequence._buffer[i] = CORBA_string_dup((char *) cards->data); - } - - CORBA_exception_init (&ev); - - Evolution_BookViewListener_signal_card_changed ( - book_view->priv->listener, &card_sequence, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_view_notify_change: Exception signaling BookViewListener!\n"); - } - - CORBA_exception_free (&ev); - - CORBA_free(card_sequence._buffer); -} - -void -pas_book_view_notify_change_1 (PASBookView *book_view, - const char *card) -{ - GList *list = g_list_append(NULL, (char *) card); - pas_book_view_notify_change(book_view, list); - g_list_free(list); -} - -/** - * pas_book_view_notify_remove: - */ -void -pas_book_view_notify_remove (PASBookView *book_view, - const char *id) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - Evolution_BookViewListener_signal_card_removed ( - book_view->priv->listener, (Evolution_CardId) id, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_view_notify_remove: Exception signaling BookViewListener!\n"); - } - - CORBA_exception_free (&ev); -} - -/** - * pas_book_view_notify_add: - */ -void -pas_book_view_notify_add (PASBookView *book_view, - const GList *cards) -{ - CORBA_Environment ev; - gint i, length; - CORBA_sequence_Evolution_VCard card_sequence; - - length = g_list_length((GList *)cards); - - card_sequence._buffer = CORBA_sequence_Evolution_VCard_allocbuf(length); - card_sequence._maximum = length; - card_sequence._length = length; - - for ( i = 0; cards; cards = g_list_next(cards), i++ ) { - card_sequence._buffer[i] = CORBA_string_dup((char *) cards->data); - } - - CORBA_exception_init (&ev); - - Evolution_BookViewListener_signal_card_added ( - book_view->priv->listener, &card_sequence, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_view_notify_add: Exception signaling BookViewListener!\n"); - } - - CORBA_exception_free (&ev); - - CORBA_free(card_sequence._buffer); -} - -void -pas_book_view_notify_add_1 (PASBookView *book_view, - const char *card) -{ - GList *list = g_list_append(NULL, (char *) card); - pas_book_view_notify_add(book_view, list); - g_list_free(list); -} - -void -pas_book_view_notify_complete (PASBookView *book_view) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - Evolution_BookViewListener_signal_sequence_complete ( - book_view->priv->listener, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_view_notify_complete: Exception signaling BookViewListener!\n"); - } - - CORBA_exception_free (&ev); -} - -void -pas_book_view_notify_status_message (PASBookView *book_view, - const char *message) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - Evolution_BookViewListener_signal_status_message ( - book_view->priv->listener, message, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_view_notify_complete: Exception signaling BookViewListener!\n"); - } - - CORBA_exception_free (&ev); -} - -static gboolean -pas_book_view_construct (PASBookView *book_view, - Evolution_BookViewListener listener) -{ - POA_Evolution_BookView *servant; - CORBA_Environment ev; - CORBA_Object obj; - - g_assert (book_view != NULL); - g_assert (PAS_IS_BOOK_VIEW (book_view)); - g_assert (listener != CORBA_OBJECT_NIL); - - servant = (POA_Evolution_BookView *) g_new0 (BonoboObjectServant, 1); - servant->vepv = &pas_book_view_vepv; - - CORBA_exception_init (&ev); - - POA_Evolution_BookView__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_free (servant); - CORBA_exception_free (&ev); - - return FALSE; - } - - CORBA_Object_duplicate (listener, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("Unable to duplicate listener object in pas-book-view.c\n"); - CORBA_exception_free (&ev); - - return FALSE; - } - - Evolution_BookViewListener_ref (listener, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("Unable to ref listener object in pas-book-view.c\n"); - CORBA_exception_free (&ev); - - return FALSE; - } - - CORBA_exception_free (&ev); - - obj = bonobo_object_activate_servant (BONOBO_OBJECT (book_view), servant); - if (obj == CORBA_OBJECT_NIL) { - g_free (servant); - - return FALSE; - } - - bonobo_object_construct (BONOBO_OBJECT (book_view), obj); - - book_view->priv->listener = listener; - - return TRUE; -} - -/** - * pas_book_view_new: - */ -PASBookView * -pas_book_view_new (Evolution_BookViewListener listener) -{ - PASBookView *book_view; - - g_return_val_if_fail (listener != CORBA_OBJECT_NIL, NULL); - - book_view = gtk_type_new (pas_book_view_get_type ()); - - if (! pas_book_view_construct (book_view, listener)) { - gtk_object_unref (GTK_OBJECT (book_view)); - - return NULL; - } - - return book_view; -} - -static void -pas_book_view_destroy (GtkObject *object) -{ - PASBookView *book_view = PAS_BOOK_VIEW (object); - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - Evolution_BookViewListener_unref (book_view->priv->listener, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("Unable to unref listener object in pas-book-view.c\n"); - CORBA_exception_free (&ev); - - return; - } - - CORBA_Object_release (book_view->priv->listener, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning("Unable to release listener object in pas-book-view.c\n"); - CORBA_exception_free (&ev); - - return; - } - - CORBA_exception_free (&ev); - - g_free (book_view->priv); - - GTK_OBJECT_CLASS (pas_book_view_parent_class)->destroy (object); -} - -static POA_Evolution_BookView__epv * -pas_book_view_get_epv (void) -{ - POA_Evolution_BookView__epv *epv; - - epv = g_new0 (POA_Evolution_BookView__epv, 1); - - return epv; - -} - -static void -pas_book_view_corba_class_init (void) -{ - pas_book_view_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); - pas_book_view_vepv.Evolution_BookView_epv = pas_book_view_get_epv (); -} - -static void -pas_book_view_class_init (PASBookViewClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - pas_book_view_parent_class = gtk_type_class (bonobo_object_get_type ()); - - object_class->destroy = pas_book_view_destroy; - - pas_book_view_corba_class_init (); -} - -static void -pas_book_view_init (PASBookView *book_view) -{ - book_view->priv = g_new0 (PASBookViewPrivate, 1); - book_view->priv->listener = CORBA_OBJECT_NIL; -} - -/** - * pas_book_view_get_type: - */ -GtkType -pas_book_view_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "PASBookView", - sizeof (PASBookView), - sizeof (PASBookViewClass), - (GtkClassInitFunc) pas_book_view_class_init, - (GtkObjectInitFunc) pas_book_view_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (bonobo_object_get_type (), &info); - } - - return type; -} - diff --git a/addressbook/backend/pas/pas-book-view.h b/addressbook/backend/pas/pas-book-view.h deleted file mode 100644 index df6aed5bbb..0000000000 --- a/addressbook/backend/pas/pas-book-view.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * A wrapper object which exports the Evolution_Book CORBA interface - * and which maintains a request queue. - * - * Author: - * Nat Friedman (nat@helixcode.com) - * - * Copyright 2000, Helix Code, Inc. - */ - -#ifndef __PAS_BOOK_VIEW_H__ -#define __PAS_BOOK_VIEW_H__ - -#include <bonobo/bonobo-object.h> -#include <libgnome/gnome-defs.h> -#include <pas/addressbook.h> - -typedef struct _PASBookView PASBookView; -typedef struct _PASBookViewClass PASBookViewClass; -typedef struct _PASBookViewPrivate PASBookViewPrivate; - -struct _PASBookView { - BonoboObject parent_object; - PASBookViewPrivate *priv; -}; - -struct _PASBookViewClass { - BonoboObjectClass parent_class; -}; -PASBookView *pas_book_view_new (Evolution_BookViewListener listener); - -void pas_book_view_notify_change (PASBookView *book_view, - const GList *cards); -void pas_book_view_notify_change_1 (PASBookView *book_view, - const char *card); -void pas_book_view_notify_remove (PASBookView *book_view, - const char *id); -void pas_book_view_notify_add (PASBookView *book_view, - const GList *cards); -void pas_book_view_notify_add_1 (PASBookView *book_view, - const char *card); -void pas_book_view_notify_complete (PASBookView *book_view); -void pas_book_view_notify_status_message (PASBookView *book_view, - const char *message); - -GtkType pas_book_view_get_type (void); - -#define PAS_BOOK_VIEW_TYPE (pas_book_view_get_type ()) -#define PAS_BOOK_VIEW(o) (GTK_CHECK_CAST ((o), PAS_BOOK_VIEW_TYPE, PASBookView)) -#define PAS_BOOK_VIEW_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_BOOK_VIEW_FACTORY_TYPE, PASBookViewClass)) -#define PAS_IS_BOOK_VIEW(o) (GTK_CHECK_TYPE ((o), PAS_BOOK_VIEW_TYPE)) -#define PAS_IS_BOOK_VIEW_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_BOOK_VIEW_TYPE)) - -#endif /* ! __PAS_BOOK_VIEW_H__ */ diff --git a/addressbook/backend/pas/pas-book.c b/addressbook/backend/pas/pas-book.c deleted file mode 100644 index 6a8c17a584..0000000000 --- a/addressbook/backend/pas/pas-book.c +++ /dev/null @@ -1,754 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * pas-book.c - * - * Copyright 2000, Helix Code, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "pas-book.h" - -static BonoboObjectClass *pas_book_parent_class; -POA_Evolution_Book__vepv pas_book_vepv; - -enum { - REQUESTS_QUEUED, - LAST_SIGNAL -}; - -static guint pas_book_signals [LAST_SIGNAL]; - -struct _PASBookPrivate { - PASBackend *backend; - Evolution_BookListener listener; - PASBookGetVCardFn get_vcard; - PASBookCanWriteFn can_write; - PASBookCanWriteCardFn can_write_card; - - GList *request_queue; - gint idle_id; -}; - -static gboolean -pas_book_check_queue (PASBook *book) -{ - if (book->priv->request_queue != NULL) { - gtk_signal_emit (GTK_OBJECT (book), - pas_book_signals [REQUESTS_QUEUED]); - } - - if (book->priv->request_queue == NULL) { - book->priv->idle_id = 0; - return FALSE; - } - - return TRUE; -} - -static void -pas_book_queue_request (PASBook *book, PASRequest *req) -{ - book->priv->request_queue = - g_list_append (book->priv->request_queue, req); - - if (book->priv->idle_id == 0) { - book->priv->idle_id = g_idle_add ((GSourceFunc) pas_book_check_queue, book); - } -} - -static void -pas_book_queue_create_card (PASBook *book, const char *vcard) -{ - PASRequest *req; - - req = g_new0 (PASRequest, 1); - req->op = CreateCard; - req->vcard = g_strdup (vcard); - - pas_book_queue_request (book, req); -} - -static void -pas_book_queue_remove_card (PASBook *book, const char *id) -{ - PASRequest *req; - - req = g_new0 (PASRequest, 1); - req->op = RemoveCard; - req->id = g_strdup (id); - - pas_book_queue_request (book, req); -} - -static void -pas_book_queue_modify_card (PASBook *book, const char *vcard) -{ - PASRequest *req; - - req = g_new0 (PASRequest, 1); - req->op = ModifyCard; - req->vcard = g_strdup (vcard); - - pas_book_queue_request (book, req); -} - -static void -pas_book_queue_get_cursor (PASBook *book, const char *search) -{ - PASRequest *req; - - req = g_new0 (PASRequest, 1); - req->op = GetCursor; - req->search = g_strdup(search); - - pas_book_queue_request (book, req); -} - -static void -pas_book_queue_get_book_view (PASBook *book, const Evolution_BookViewListener listener, const char *search) -{ - PASRequest *req; - CORBA_Environment ev; - - req = g_new0 (PASRequest, 1); - req->op = GetBookView; - req->search = g_strdup(search); - - CORBA_exception_init (&ev); - - req->listener = CORBA_Object_duplicate(listener, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_queue_get_book_view: Exception " - "duplicating BookViewListener!\n"); - } - - CORBA_exception_free (&ev); - - pas_book_queue_request (book, req); -} - -static void -pas_book_queue_get_changes (PASBook *book, const Evolution_BookViewListener listener, const char *search) -{ - PASRequest *req; - CORBA_Environment ev; - - req = g_new0 (PASRequest, 1); - req->op = GetChanges; - req->search = g_strdup(search); - - CORBA_exception_init (&ev); - - req->listener = CORBA_Object_duplicate(listener, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_queue_get_changes: Exception " - "duplicating BookViewListener!\n"); - } - - CORBA_exception_free (&ev); - - pas_book_queue_request (book, req); -} - -static void -pas_book_queue_check_connection (PASBook *book) -{ - PASRequest *req; - - req = g_new0 (PASRequest, 1); - req->op = CheckConnection; - - pas_book_queue_request (book, req); -} - -static CORBA_char * -impl_Evolution_Book_get_vcard (PortableServer_Servant servant, - const Evolution_CardId id, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - char *vcard; - CORBA_char *retval; - - vcard = (book->priv->get_vcard) (book, (const char *) id); - retval = CORBA_string_dup (vcard); - g_free (vcard); - - return retval; -} - -static CORBA_boolean -impl_Evolution_Book_can_write (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - CORBA_boolean retval; - - retval = (book->priv->can_write) (book); - - return retval; -} - -static CORBA_boolean -impl_Evolution_Book_can_write_card (PortableServer_Servant servant, - const Evolution_CardId id, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - CORBA_boolean retval; - - retval = (book->priv->can_write_card) (book, (const char *) id); - - return retval; -} - -static void -impl_Evolution_Book_create_card (PortableServer_Servant servant, - const Evolution_VCard vcard, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - - pas_book_queue_create_card (book, (const char *) vcard); -} - -static void -impl_Evolution_Book_remove_card (PortableServer_Servant servant, - const Evolution_CardId id, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - - pas_book_queue_remove_card (book, (const char *) id); -} - -static void -impl_Evolution_Book_modify_card (PortableServer_Servant servant, - const Evolution_VCard vcard, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - - pas_book_queue_modify_card (book, (const char *) vcard); -} - -static void -impl_Evolution_Book_get_cursor (PortableServer_Servant servant, - const CORBA_char *search, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - - pas_book_queue_get_cursor (book, search); -} - -static void -impl_Evolution_Book_get_book_view (PortableServer_Servant servant, - const Evolution_BookViewListener listener, - const CORBA_char *search, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - - pas_book_queue_get_book_view (book, listener, search); -} - -static void -impl_Evolution_Book_get_changes (PortableServer_Servant servant, - const Evolution_BookViewListener listener, - const CORBA_char *search, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - - pas_book_queue_get_changes (book, listener, search); -} - -static void -impl_Evolution_Book_check_connection (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - - pas_book_queue_check_connection (book); -} - -static char * -impl_Evolution_Book_get_static_capabilities (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - PASBook *book = PAS_BOOK (bonobo_object_from_servant (servant)); - char *temp; - char *ret_val; - - temp = pas_backend_get_static_capabilities (book->priv->backend); - ret_val = CORBA_string_dup(temp); - g_free(temp); - return ret_val; -} - -/** - * pas_book_get_backend: - */ -PASBackend * -pas_book_get_backend (PASBook *book) -{ - g_return_val_if_fail (book != NULL, NULL); - g_return_val_if_fail (PAS_IS_BOOK (book), NULL); - - return book->priv->backend; -} - -/** - * pas_book_get_listener: - */ -Evolution_BookListener -pas_book_get_listener (PASBook *book) -{ - g_return_val_if_fail (book != NULL, CORBA_OBJECT_NIL); - g_return_val_if_fail (PAS_IS_BOOK (book), CORBA_OBJECT_NIL); - - return book->priv->listener; -} - -/** - * pas_book_check_pending - */ -gint -pas_book_check_pending (PASBook *book) -{ - g_return_val_if_fail (book != NULL, -1); - g_return_val_if_fail (PAS_IS_BOOK (book), -1); - - return g_list_length (book->priv->request_queue); -} - -/** - * pas_book_pop_request: - */ -PASRequest * -pas_book_pop_request (PASBook *book) -{ - GList *popped; - PASRequest *req; - - g_return_val_if_fail (book != NULL, NULL); - g_return_val_if_fail (PAS_IS_BOOK (book), NULL); - - if (book->priv->request_queue == NULL) - return NULL; - - req = book->priv->request_queue->data; - - popped = book->priv->request_queue; - book->priv->request_queue = - g_list_remove_link (book->priv->request_queue, popped); - - g_list_free_1 (popped); - - return req; -} - -/** - * pas_book_respond_open: - */ -void -pas_book_respond_open (PASBook *book, - Evolution_BookListener_CallStatus status) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - if (status == Evolution_BookListener_Success) { - Evolution_BookListener_respond_open_book ( - book->priv->listener, status, - bonobo_object_corba_objref (BONOBO_OBJECT (book)), - &ev); - } else { - Evolution_BookListener_respond_open_book ( - book->priv->listener, status, - CORBA_OBJECT_NIL, &ev); - } - - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_respond_open: Exception " - "responding to BookListener!\n"); - } - - CORBA_exception_free (&ev); -} - -/** - * pas_book_respond_create: - */ -void -pas_book_respond_create (PASBook *book, - Evolution_BookListener_CallStatus status, - const char *id) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - Evolution_BookListener_respond_create_card ( - book->priv->listener, status, (char *)id, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_respond_create: Exception " - "responding to BookListener!\n"); - } - - CORBA_exception_free (&ev); -} - -/** - * pas_book_respond_remove: - */ -void -pas_book_respond_remove (PASBook *book, - Evolution_BookListener_CallStatus status) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - Evolution_BookListener_respond_remove_card ( - book->priv->listener, status, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_respond_remove: Exception " - "responding to BookListener!\n"); - } - - CORBA_exception_free (&ev); -} - -/** - * pas_book_respond_modify: - */ -void -pas_book_respond_modify (PASBook *book, - Evolution_BookListener_CallStatus status) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - Evolution_BookListener_respond_modify_card ( - book->priv->listener, status, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_respond_modify: Exception " - "responding to BookListener!\n"); - } - - CORBA_exception_free (&ev); -} - -/** - * pas_book_respond_get_cursor: - */ -void -pas_book_respond_get_cursor (PASBook *book, - Evolution_BookListener_CallStatus status, - PASCardCursor *cursor) -{ - CORBA_Environment ev; - CORBA_Object object; - - CORBA_exception_init (&ev); - - object = bonobo_object_corba_objref(BONOBO_OBJECT(cursor)); - - Evolution_BookListener_respond_get_cursor ( - book->priv->listener, status, object, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_respond_get_cursor: Exception " - "responding to BookListener!\n"); - } - - CORBA_exception_free (&ev); -} - -/** - * pas_book_respond_get_book_view: - */ -void -pas_book_respond_get_book_view (PASBook *book, - Evolution_BookListener_CallStatus status, - PASBookView *book_view) -{ - CORBA_Environment ev; - CORBA_Object object; - - CORBA_exception_init (&ev); - - object = bonobo_object_corba_objref(BONOBO_OBJECT(book_view)); - - Evolution_BookListener_respond_get_view ( - book->priv->listener, status, object, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_respond_get_book_view: Exception " - "responding to BookListener!\n"); - } - - CORBA_exception_free (&ev); -} - -/** - * pas_book_respond_get_changes: - */ -void -pas_book_respond_get_changes (PASBook *book, - Evolution_BookListener_CallStatus status, - PASBookView *book_view) -{ - CORBA_Environment ev; - CORBA_Object object; - - CORBA_exception_init (&ev); - - object = bonobo_object_corba_objref(BONOBO_OBJECT(book_view)); - - Evolution_BookListener_respond_get_changes ( - book->priv->listener, status, object, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_respond_get_changes: Exception " - "responding to BookListener!\n"); - } - - CORBA_exception_free (&ev); -} - -/** - * pas_book_report_connection: - */ -void -pas_book_report_connection (PASBook *book, - gboolean connected) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - Evolution_BookListener_report_connection_status ( - book->priv->listener, (CORBA_boolean) connected, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) { - g_warning ("pas_book_report_connection: Exception " - "responding to BookListener!\n"); - } - - CORBA_exception_free (&ev); -} - -static gboolean -pas_book_construct (PASBook *book, - PASBackend *backend, - Evolution_BookListener listener, - PASBookGetVCardFn get_vcard, - PASBookCanWriteFn can_write, - PASBookCanWriteCardFn can_write_card) -{ - POA_Evolution_Book *servant; - CORBA_Environment ev; - CORBA_Object obj; - - g_assert (book != NULL); - g_assert (PAS_IS_BOOK (book)); - g_assert (listener != CORBA_OBJECT_NIL); - g_assert (get_vcard != NULL); - g_assert (can_write != NULL); - g_assert (can_write_card != NULL); - - servant = (POA_Evolution_Book *) g_new0 (BonoboObjectServant, 1); - servant->vepv = &pas_book_vepv; - - CORBA_exception_init (&ev); - - POA_Evolution_Book__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION) { - g_free (servant); - CORBA_exception_free (&ev); - - return FALSE; - } - - CORBA_exception_free (&ev); - - obj = bonobo_object_activate_servant (BONOBO_OBJECT (book), servant); - if (obj == CORBA_OBJECT_NIL) { - g_free (servant); - - return FALSE; - } - - bonobo_object_construct (BONOBO_OBJECT (book), obj); - - CORBA_exception_init (&ev); - book->priv->listener = CORBA_Object_duplicate (listener, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("pas_book_construct(): could not duplicate the listener"); - - CORBA_exception_free (&ev); - - book->priv->listener = listener; - book->priv->get_vcard = get_vcard; - book->priv->can_write = can_write; - book->priv->can_write_card = can_write_card; - book->priv->backend = backend; - - return TRUE; -} - -/** - * pas_book_new: - */ -PASBook * -pas_book_new (PASBackend *backend, - Evolution_BookListener listener, - PASBookGetVCardFn get_vcard, - PASBookCanWriteFn can_write, - PASBookCanWriteCardFn can_write_card) -{ - PASBook *book; - - g_return_val_if_fail (listener != CORBA_OBJECT_NIL, NULL); - g_return_val_if_fail (get_vcard != NULL, NULL); - - book = gtk_type_new (pas_book_get_type ()); - - if (! pas_book_construct (book, backend, listener, - get_vcard, can_write, can_write_card)) { - gtk_object_unref (GTK_OBJECT (book)); - - return NULL; - } - - return book; -} - -static void -pas_book_destroy (GtkObject *object) -{ - PASBook *book = PAS_BOOK (object); - GList *l; - CORBA_Environment ev; - - for (l = book->priv->request_queue; l != NULL; l = l->next) { - PASRequest *req = l->data; - - g_free (req->id); - g_free (req->vcard); - g_free (req); - } - g_list_free (book->priv->request_queue); - - CORBA_exception_init (&ev); - CORBA_Object_release (book->priv->listener, &ev); - - if (ev._major != CORBA_NO_EXCEPTION) - g_message ("pas_book_construct(): could not release the listener"); - - CORBA_exception_free (&ev); - - g_free (book->priv); - - GTK_OBJECT_CLASS (pas_book_parent_class)->destroy (object); -} - -static POA_Evolution_Book__epv * -pas_book_get_epv (void) -{ - POA_Evolution_Book__epv *epv; - - epv = g_new0 (POA_Evolution_Book__epv, 1); - - epv->get_vcard = impl_Evolution_Book_get_vcard; - epv->can_write = impl_Evolution_Book_can_write; - epv->can_write_card = impl_Evolution_Book_can_write_card; - epv->create_card = impl_Evolution_Book_create_card; - epv->remove_card = impl_Evolution_Book_remove_card; - epv->modify_card = impl_Evolution_Book_modify_card; - epv->check_connection = impl_Evolution_Book_check_connection; - epv->get_static_capabilities = impl_Evolution_Book_get_static_capabilities; - epv->get_cursor = impl_Evolution_Book_get_cursor; - epv->get_book_view = impl_Evolution_Book_get_book_view; - epv->get_changes = impl_Evolution_Book_get_changes; - - return epv; - -} - -static void -pas_book_corba_class_init (void) -{ - pas_book_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); - pas_book_vepv.Evolution_Book_epv = pas_book_get_epv (); -} - -static void -pas_book_class_init (PASBookClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - pas_book_parent_class = gtk_type_class (bonobo_object_get_type ()); - - pas_book_signals [REQUESTS_QUEUED] = - gtk_signal_new ("requests_queued", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (PASBookClass, requests_queued), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, pas_book_signals, LAST_SIGNAL); - - object_class->destroy = pas_book_destroy; - - pas_book_corba_class_init (); -} - -static void -pas_book_init (PASBook *book) -{ - book->priv = g_new0 (PASBookPrivate, 1); - book->priv->idle_id = 0; - book->priv->request_queue = NULL; -} - -/** - * pas_book_get_type: - */ -GtkType -pas_book_get_type (void) -{ - static GtkType type = 0; - - if (! type) { - GtkTypeInfo info = { - "PASBook", - sizeof (PASBook), - sizeof (PASBookClass), - (GtkClassInitFunc) pas_book_class_init, - (GtkObjectInitFunc) pas_book_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (bonobo_object_get_type (), &info); - } - - return type; -} - diff --git a/addressbook/backend/pas/pas-book.h b/addressbook/backend/pas/pas-book.h deleted file mode 100644 index ab59d7bb3e..0000000000 --- a/addressbook/backend/pas/pas-book.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * A wrapper object which exports the Evolution_Book CORBA interface - * and which maintains a request queue. - * - * Author: - * Nat Friedman (nat@helixcode.com) - * - * Copyright 2000, Helix Code, Inc. - */ - -#ifndef __PAS_BOOK_H__ -#define __PAS_BOOK_H__ - -#include <bonobo/bonobo-object.h> -#include <libgnome/gnome-defs.h> -#include <pas/addressbook.h> -#include <pas/pas-book-view.h> - -typedef struct _PASBook PASBook; -typedef struct _PASBookPrivate PASBookPrivate; - -#include <pas/pas-backend.h> -#include <pas/pas-card-cursor.h> - -typedef enum { - CreateCard, - RemoveCard, - ModifyCard, - GetCursor, - GetBookView, - GetChanges, - CheckConnection -} PASOperation; - -typedef struct { - PASOperation op; - char *id; - char *vcard; - char *search; - Evolution_BookViewListener listener; -} PASRequest; - -struct _PASBook { - BonoboObject parent_object; - PASBookPrivate *priv; -}; - -typedef struct { - BonoboObjectClass parent_class; - - /* Signals */ - void (*requests_queued) (void); -} PASBookClass; - -typedef char * (*PASBookGetVCardFn) (PASBook *book, const char *id); -typedef gboolean (*PASBookCanWriteFn) (PASBook *book); -typedef gboolean (*PASBookCanWriteCardFn) (PASBook *book, const char *id); - -PASBook *pas_book_new (PASBackend *backend, - Evolution_BookListener listener, - PASBookGetVCardFn get_vcard, - PASBookCanWriteFn can_write, - PASBookCanWriteCardFn can_write_card); -PASBackend *pas_book_get_backend (PASBook *book); -Evolution_BookListener pas_book_get_listener (PASBook *book); -int pas_book_check_pending (PASBook *book); -PASRequest *pas_book_pop_request (PASBook *book); -void pas_book_respond_open (PASBook *book, - Evolution_BookListener_CallStatus status); -void pas_book_respond_create (PASBook *book, - Evolution_BookListener_CallStatus status, - const char *id); -void pas_book_respond_remove (PASBook *book, - Evolution_BookListener_CallStatus status); -void pas_book_respond_modify (PASBook *book, - Evolution_BookListener_CallStatus status); -void pas_book_respond_get_cursor (PASBook *book, - Evolution_BookListener_CallStatus status, - PASCardCursor *cursor); -void pas_book_respond_get_book_view (PASBook *book, - Evolution_BookListener_CallStatus status, - PASBookView *book_view); -void pas_book_respond_get_changes (PASBook *book, - Evolution_BookListener_CallStatus status, - PASBookView *book_view); -void pas_book_report_connection (PASBook *book, - gboolean connected); - -gboolean pas_book_can_write (PASBook *book); -gboolean pas_book_can_write_card (PASBook *book, - const char *id); -GtkType pas_book_get_type (void); - -#define PAS_BOOK_TYPE (pas_book_get_type ()) -#define PAS_BOOK(o) (GTK_CHECK_CAST ((o), PAS_BOOK_TYPE, PASBook)) -#define PAS_BOOK_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_BOOK_FACTORY_TYPE, PASBookClass)) -#define PAS_IS_BOOK(o) (GTK_CHECK_TYPE ((o), PAS_BOOK_TYPE)) -#define PAS_IS_BOOK_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_BOOK_TYPE)) - -#endif /* ! __PAS_BOOK_H__ */ diff --git a/addressbook/backend/pas/pas-card-cursor.c b/addressbook/backend/pas/pas-card-cursor.c deleted file mode 100644 index c2bbe1c9b0..0000000000 --- a/addressbook/backend/pas/pas-card-cursor.c +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * pas-card-cursor.c: Implements card cursors. - * - * Author: - * Christopher James Lahey <clahey@helixcode.com. - */ - -#include <config.h> -#include <bonobo.h> -#include "addressbook.h" -#include "pas-card-cursor.h" - -struct _PASCardCursorPrivate { - long (*get_length) (PASCardCursor *cursor, gpointer data); - char * (*get_nth) (PASCardCursor *cursor, long n, gpointer data); - gpointer data; -}; - -/* - * A pointer to our parent object class - */ -static BonoboObjectClass *parent_class; - -/* - * The VEPV for the CardCursor object - */ -static POA_Evolution_CardCursor__vepv cursor_vepv; - -/* - * Implemented GtkObject::destroy - */ -static void -pas_card_cursor_destroy (GtkObject *object) -{ - PASCardCursor *cursor = PAS_CARD_CURSOR (object); - - if ( cursor->priv ) - g_free ( cursor->priv ); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -/* - * CORBA Demo::Echo::echo method implementation - */ -static CORBA_long -impl_pas_card_cursor_get_length (PortableServer_Servant servant, - CORBA_Environment *ev) -{ - PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object_from_servant (servant)); - if ( cursor->priv->get_length ) - return cursor->priv->get_length( cursor, cursor->priv->data ); - else - return 0; -} - -/* - * CORBA Demo::Echo::echo method implementation - */ -static char * -impl_pas_card_cursor_get_nth (PortableServer_Servant servant, - const CORBA_long n, - CORBA_Environment *ev) -{ - PASCardCursor *cursor = PAS_CARD_CURSOR (bonobo_object_from_servant (servant)); - if ( cursor->priv->get_nth ) { - char *vcard = cursor->priv->get_nth( cursor, n, cursor->priv->data ); - char *retval = CORBA_string_dup (vcard); - g_free (vcard); - return retval; - } else - return CORBA_string_dup (""); -} - -/* - * If you want users to derive classes from your implementation - * you need to support this method. - */ -POA_Evolution_CardCursor__epv * -pas_card_cursor_get_epv (void) -{ - POA_Evolution_CardCursor__epv *epv; - - epv = g_new0 (POA_Evolution_CardCursor__epv, 1); - - /* - * This is the method invoked by CORBA - */ - epv->get_length = impl_pas_card_cursor_get_length; - epv->get_nth = impl_pas_card_cursor_get_nth; - - return epv; -} - -static void -init_pas_card_cursor_corba_class (void) -{ - cursor_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); - cursor_vepv.Evolution_CardCursor_epv = pas_card_cursor_get_epv (); -} - -static void -pas_card_cursor_class_init (PASCardCursorClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *) klass; - - parent_class = gtk_type_class (bonobo_object_get_type ()); - - object_class->destroy = pas_card_cursor_destroy; - - init_pas_card_cursor_corba_class (); -} - -static void -pas_card_cursor_init (PASCardCursor *cursor) -{ - cursor->priv = g_new(PASCardCursorPrivate, 1); - cursor->priv->get_length = NULL; - cursor->priv->get_nth = NULL; - cursor->priv->data = NULL; -} - -GtkType -pas_card_cursor_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "PASCardCursor", - sizeof (PASCardCursor), - sizeof (PASCardCursorClass), - (GtkClassInitFunc) pas_card_cursor_class_init, - (GtkObjectInitFunc) pas_card_cursor_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (bonobo_object_get_type (), &info); - } - - return type; -} - -PASCardCursor * -pas_card_cursor_construct (PASCardCursor *cursor, - Evolution_CardCursor corba_cursor, - PASCardCursorLengthFunc get_length, - PASCardCursorNthFunc get_nth, - gpointer data) -{ - g_return_val_if_fail (cursor != NULL, NULL); - g_return_val_if_fail (PAS_IS_CARD_CURSOR (cursor), NULL); - g_return_val_if_fail (corba_cursor != CORBA_OBJECT_NIL, NULL); - - /* - * Call parent constructor - */ - if (!bonobo_object_construct (BONOBO_OBJECT (cursor), (CORBA_Object) corba_cursor)) - return NULL; - - /* - * Initialize cursor - */ - cursor->priv->get_length = get_length; - cursor->priv->get_nth = get_nth; - cursor->priv->data = data; - - /* - * Success: return the GtkType we were given - */ - return cursor; -} - -/* - * This routine creates the ORBit CORBA server and initializes the - * CORBA side of things - */ -static Evolution_CardCursor -create_cursor (BonoboObject *cursor) -{ - POA_Evolution_CardCursor *servant; - CORBA_Environment ev; - - servant = (POA_Evolution_CardCursor *) g_new0 (BonoboObjectServant, 1); - servant->vepv = &cursor_vepv; - - CORBA_exception_init (&ev); - POA_Evolution_CardCursor__init ((PortableServer_Servant) servant, &ev); - if (ev._major != CORBA_NO_EXCEPTION){ - g_free (servant); - CORBA_exception_free (&ev); - return CORBA_OBJECT_NIL; - } - - CORBA_exception_free (&ev); - - /* - * Activates the CORBA object. - */ - return (Evolution_CardCursor) bonobo_object_activate_servant (cursor, servant); -} - -PASCardCursor * -pas_card_cursor_new (PASCardCursorLengthFunc get_length, - PASCardCursorNthFunc get_nth, - gpointer data) -{ - PASCardCursor *cursor; - Evolution_CardCursor corba_cursor; - - cursor = gtk_type_new (pas_card_cursor_get_type ()); - corba_cursor = create_cursor (BONOBO_OBJECT (cursor)); - - if (corba_cursor == CORBA_OBJECT_NIL){ - gtk_object_unref (GTK_OBJECT (cursor)); - return NULL; - } - - return pas_card_cursor_construct (cursor, - corba_cursor, - get_length, - get_nth, - data); -} diff --git a/addressbook/backend/pas/pas-card-cursor.h b/addressbook/backend/pas/pas-card-cursor.h deleted file mode 100644 index 300e3e3ce1..0000000000 --- a/addressbook/backend/pas/pas-card-cursor.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * - * Author: - * Nat Friedman (nat@helixcode.com) - * - * Copyright 2000, Helix Code, Inc. - */ - -#ifndef __PAS_CARD_CURSOR_H__ -#define __PAS_CARD_CURSOR_H__ - -#include <libgnome/gnome-defs.h> -#include <bonobo/bonobo-object.h> -#include <pas/addressbook.h> - -BEGIN_GNOME_DECLS - -typedef struct _PASCardCursor PASCardCursor; -typedef struct _PASCardCursorPrivate PASCardCursorPrivate; -typedef struct _PASCardCursorClass PASCardCursorClass; - -typedef long (*PASCardCursorLengthFunc) (PASCardCursor *cursor, gpointer data); -typedef char * (*PASCardCursorNthFunc) (PASCardCursor *cursor, long n, gpointer data); - -struct _PASCardCursor { - BonoboObject parent; - PASCardCursorPrivate *priv; -}; - -struct _PASCardCursorClass { - BonoboObjectClass parent; -}; - -/* Creating a new addressbook. */ -PASCardCursor *pas_card_cursor_new (PASCardCursorLengthFunc get_length, - PASCardCursorNthFunc get_nth, - gpointer data); -PASCardCursor *pas_card_cursor_construct (PASCardCursor *cursor, - Evolution_CardCursor corba_cursor, - PASCardCursorLengthFunc get_length, - PASCardCursorNthFunc get_nth, - gpointer data); - -GtkType pas_card_cursor_get_type (void); -POA_Evolution_CardCursor__epv * - pas_card_cursor_get_epv (void); - -/* Fetching cards. */ -#define PAS_CARD_CURSOR_TYPE (pas_card_cursor_get_type ()) -#define PAS_CARD_CURSOR(o) (GTK_CHECK_CAST ((o), PAS_CARD_CURSOR_TYPE, PASCardCursor)) -#define PAS_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_CAST((k), PAS_CARD_CURSOR_TYPE, PASCardCursorClass)) -#define PAS_IS_CARD_CURSOR(o) (GTK_CHECK_TYPE ((o), PAS_CARD_CURSOR_TYPE)) -#define PAS_IS_CARD_CURSOR_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), PAS_CARD_CURSOR_TYPE)) - -END_GNOME_DECLS - -#endif /* ! __PAS_CARD_CURSOR_H__ */ |