diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 92 |
2 files changed, 101 insertions, 4 deletions
@@ -1,3 +1,16 @@ +2000-03-26 Chris Toshok <toshok@laptoph.xtoph.org> + + * addressbook/backend/pas/pas-backend-file.c + (pas_backend_file_process_create_card): add db calls to flesh out + the interface. hardcoded id that needs to change, once we decide + how we're going to create it. + (pas_backend_file_process_remove_card): add db calls to flesh out + the interface. + (pas_backend_file_process_modify_card): likewise + (pas_backend_file_process_check_connection): likewise + (pas_backend_file_get_vcard): likewise + (pas_backend_file_load_uri): likewise + 2000-03-26 Christopher James Lahey <clahey@helixcode.com> * addressbook/backend/ebook/e-book.c: Set the card id properly diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index ad5679c7e1..93e92df76a 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Author: * Nat Friedman (nat@helixcode.com) @@ -6,6 +7,7 @@ */ #include <gtk/gtksignal.h> +#include <fcntl.h> #include <db.h> #include <pas-backend-file.h> @@ -16,6 +18,7 @@ static PASBackendClass *pas_backend_file_parent_class; struct _PASBackendFilePrivate { GList *clients; gboolean loaded; + DB *file_db; }; static void @@ -23,8 +26,24 @@ pas_backend_file_process_create_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; + + id_dbt.data = "foo"; /* XXX create unique id here */ + id_dbt.size = strlen(id_dbt.data); + + vcard_dbt.data = (void*)req->vcard; + vcard_dbt.size = strlen(req->vcard); + + db_error = db->put(db, &id_dbt, &vcard_dbt, 0); + pas_book_respond_create ( - book, Evolution_BookListener_Success); + book, + (db_error == 0 + ? Evolution_BookListener_Success + : Evolution_BookListener_CardNotFound)); g_free (req->vcard); } @@ -34,8 +53,21 @@ 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; + int db_error; + + id_dbt.data = (void*)req->id; + id_dbt.size = strlen(req->id); + + db_error = db->del(db, &id_dbt, 0); + pas_book_respond_remove ( - book, Evolution_BookListener_Success); + book, + (db_error == 0 + ? Evolution_BookListener_Success + : Evolution_BookListener_CardNotFound)); g_free (req->id); } @@ -45,8 +77,24 @@ 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; + + id_dbt.data = (void*)req->id; + id_dbt.size = strlen(req->id); + + vcard_dbt.data = (void*)req->vcard; + vcard_dbt.size = strlen(req->vcard); + + db_error = db->put(db, &id_dbt, &vcard_dbt, 0); + pas_book_respond_modify ( - book, Evolution_BookListener_Success); + book, + (db_error == 0 + ? Evolution_BookListener_Success + : Evolution_BookListener_CardNotFound)); g_free (req->vcard); } @@ -56,7 +104,9 @@ pas_backend_file_process_check_connection (PASBackend *backend, PASBook *book, PASRequest *req) { - pas_book_report_connection (book, TRUE); + PASBackendFile *bf = PAS_BACKEND_FILE (backend); + + pas_book_report_connection (book, bf->priv->file_db != NULL); } static void @@ -104,6 +154,31 @@ pas_backend_file_book_destroy_cb (PASBook *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; + + id_dbt.data = (void*)id; + id_dbt.size = strlen(id); + + db_error = db->get(db, &id_dbt, &vcard_dbt, 0); + if (db_error == 0) { + /* success */ + return g_strndup(vcard_dbt.data, vcard_dbt.size); + } + else if (db_error == 1) { + /* key was not in file */ + return g_strdup(""); /* XXX */ + } + else /* if (db_error < 0)*/ { + /* error */ + return g_strdup(""); /* XXX */ + } + return g_strdup ("blah blah blah"); } @@ -125,6 +200,15 @@ pas_backend_file_load_uri (PASBackend *backend, g_assert (bf->priv->loaded == FALSE); filename = pas_backend_file_extract_path_from_uri (uri); + + bf->priv->file_db = dbopen (filename, O_RDWR | O_CREAT, 0666, DB_HASH, NULL); + + if (bf->priv->file_db != NULL) + bf->priv->loaded = TRUE; + else + g_warning("pas_backend_file_load_uri failed for '%s'\n", filename); + + g_free (filename); } static void |