aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--camel/camel-provider.c105
-rw-r--r--camel/camel-provider.h17
-rw-r--r--camel/camel-session.c2
-rw-r--r--camel/camel.h22
-rw-r--r--camel/providers/MH/Makefile.am1
-rw-r--r--camel/providers/MH/camel-mh-provider.c46
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/test7.c22
9 files changed, 221 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 15c5b77d66..3fee0827ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,17 @@
-1999-08-11 bertrand <Bertrand.Guiheneuf@aful.org>
+1999-08-12 bertrand <Bertrand.Guiheneuf@aful.org>
+
+ * camel/providers/MH/camel-mh-provider.c:
+ new file. MH provider registration stuff.
+
+ * camel/camel-provider.c (camel_provider_register_as_module):
+ load a provider from a shared object (plugin).
+ (camel_provider_register): register a provider
+ "by hand". Used for statically defined providers.
+
+ * tests/test7.c: new test.
+ tests providers loading framework.
+
+1999-08-11
* camel/camel-service.c (_finalize):
* camel/camel-stream-fs.c (_finalize):
diff --git a/camel/camel-provider.c b/camel/camel-provider.c
index 238b83ce29..0018e262e0 100644
--- a/camel/camel-provider.c
+++ b/camel/camel-provider.c
@@ -1,9 +1,9 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-provider.c : provider management */
+/* camel-provider.c : provider framework */
/*
*
- * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
+ * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@aful.org> .
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -22,8 +22,103 @@
*/
-
/*
+ A provider can be added "by hand" or by loading a module.
+
+
+ Adding providers with modules.
+ ------------------------------
+
+ The modules are shared libraries which must contain the
+ function
+
+ CamelProvider *camel_provider_module_init ();
+
+ returning the provider object defined in the module
+
+
+*/
+
+/* FIXME: Shouldn't we add a version number to providers ? */
+
+#include "config.h"
+#include "camel-provider.h"
+#include "camel-log.h"
+
+
+static GList *_provider_list = NULL;
+static gchar *_last_error;
+
+static gint
+_provider_name_cmp (gconstpointer a, gconstpointer b)
+{
+ CamelProvider *provider_a = CAMEL_PROVIDER (a);
+ CamelProvider *provider_b = CAMEL_PROVIDER (b);
+
+ return strcmp ( provider_a->name, provider_b->name);
+}
+
+void
+camel_provider_register (CamelProvider *provider)
+{
+ GList *old_provider_node = NULL;
+
+ g_assert (provider);
+
+ if (_provider_list)
+ old_provider_node = g_list_find_custom (_provider_list, provider, _provider_name_cmp);
+
+ if (old_provider_node != NULL) {
+ // camel_provider_unref (CAMEL_PROVIDER (old_provider_node->data));
+ old_provider_node->data = provider;
+ } else {
+ _provider_list = g_list_append (_provider_list, provider);
+ }
+ // camel_provider_ref (provider);
+
+}
+
+
+const CamelProvider *
+camel_provider_register_as_module (const gchar *module_path)
+{
+
+ CamelProvider *new_provider = NULL;
+ GModule *new_module = NULL;
+ CamelProvider * (*camel_provider_module_init) ();
+ gboolean has_module_init;
+
+ CAMEL_LOG_FULL_DEBUG ("Entering CamelProvider::register_as_module\n");
+
+ g_return_val_if_fail (module_path, NULL);
+
+ if (!g_module_supported ()) {
+ CAMEL_LOG_WARNING ("CamelProvider::register_as_module module loading not supported on this system\n");
+ CAMEL_LOG_FULL_DEBUG ("Leaving CamelProvider::register_as_module\n");
+ return NULL;
+ }
+
+
+ new_module = g_module_open (module_path, 0);
+ if (!new_module) {
+ CAMEL_LOG_WARNING ("CamelProvider::register_as_module Unable to load module %s\n", module_path);
+ CAMEL_LOG_FULL_DEBUG ("Leaving CamelProvider::register_as_module\n");
+ return NULL;
+ }
+
+ has_module_init = g_module_symbol (new_module, "camel_provider_module_init", (gpointer *)&camel_provider_module_init);
+ if (!has_module_init){
+ CAMEL_LOG_WARNING ("CamelProvider::register_as_module loading of module %s failed,\n"
+ "\t Symbol camel_provider_module_init not defined in it\n", module_path);
+ CAMEL_LOG_FULL_DEBUG ("Leaving CamelProvider::register_as_module\n");
+ return NULL;
+ }
+
+ new_provider = camel_provider_module_init();
+ new_provider->gmodule = new_module;
+
+ CAMEL_LOG_FULL_DEBUG ("Leaving CamelProvider::register_as_module\n");
+ return new_provider;
- Here will be the routine to load providers (plugins)
- and register them */
+
+}
diff --git a/camel/camel-provider.h b/camel/camel-provider.h
index 54b9ef2a2a..3099efa265 100644
--- a/camel/camel-provider.h
+++ b/camel/camel-provider.h
@@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-provider.h : provider management */
+/* camel-provider.h : provider definition */
/*
*
@@ -31,6 +31,11 @@ extern "C" {
#pragma }
#endif /* __cplusplus }*/
+#include <gtk/gtk.h>
+#include <gmodule.h>
+
+#define CAMEL_PROVIDER(obj) (CamelProvider *)(obj)
+
typedef enum {
PROVIDER_STORE,
PROVIDER_TRANSPORT
@@ -40,11 +45,15 @@ typedef enum {
typedef struct {
GtkType object_type; /* used to create instance of the provider */
ProviderType provider_type; /* is a store or a transport */
- gchar *protocol; /* name of the protocol ("imap"/"smtp"/"mh" ...) */
- gchar *provider_name; /* name of the provider ("Raymond the imap provider") */
- gchar *description; /* Useful when multiple providers are available for a same protocol */
+ gchar *protocol; /* name of the protocol ("imap"/"smtp"/"mh" ...) */
+ gchar *name; /* name of the provider ("Raymond the imap provider") */
+ gchar *description; /* Useful when multiple providers are available for a same protocol */
+
+ GModule *gmodule;
} CamelProvider;
+void camel_provider_register (CamelProvider *provider);
+const CamelProvider *camel_provider_register_as_module (const gchar *module_path);
#ifdef __cplusplus
diff --git a/camel/camel-session.c b/camel/camel-session.c
index f9916df6f6..fef670ece6 100644
--- a/camel/camel-session.c
+++ b/camel/camel-session.c
@@ -114,7 +114,7 @@ camel_session_set_provider (CamelSession *session, CamelProvider *provider)
*
*
*
- * Return value: the newly instantiated folder
+ * Return value: the newly instantiated store
**/
CamelStore *
camel_session_get_store_from_provider (CamelSession *session, CamelProvider *provider)
diff --git a/camel/camel.h b/camel/camel.h
index c0548f5e10..33bd0bdd92 100644
--- a/camel/camel.h
+++ b/camel/camel.h
@@ -33,6 +33,28 @@ extern "C" {
#include <gtk/gtk.h>
#include <config.h>
#include <camel/data-wrapper-repository.h>
+#include <camel/data-wrapper-repository.h>
+#include <camel/camel-log.h>
+#include <camel/camel-data-wrapper.h>
+#include <camel-simple-data-wrapper.h>
+#include <camel-folder.h>
+#include <camel-mime-body-part.h>
+#include <camel-mime-message.h>
+#include <camel-mime-part.h>
+#include <camel-multipart.h>
+#include <camel-provider.h>
+#include <camel-service.h>
+#include <camel-session.h>
+#include <camel-store.h>
+#include <camel-stream.h>
+#include <camel-stream-fs.h>
+#include <camel-stream-mem.h>
+#include <data-wrapper-repository.h>
+#include <gmime-content-field.h>
+#include <gmime-utils.h>
+#include <gstring-util.h>
+#include <string-utils.h>
+#include <url-util.h>
gint camel_init ();
diff --git a/camel/providers/MH/Makefile.am b/camel/providers/MH/Makefile.am
index 0f52c9fb40..35403a7347 100644
--- a/camel/providers/MH/Makefile.am
+++ b/camel/providers/MH/Makefile.am
@@ -13,6 +13,7 @@ INCLUDES = -I.. -I$(srcdir)/.. -I$(includedir) \
libcamelmh_la_SOURCES = \
camel-mh-folder.c \
+ camel-mh-provider.c \
camel-mh-store.c
libcamelmhinclude_HEADERS = \
diff --git a/camel/providers/MH/camel-mh-provider.c b/camel/providers/MH/camel-mh-provider.c
new file mode 100644
index 0000000000..6be4b11e9c
--- /dev/null
+++ b/camel/providers/MH/camel-mh-provider.c
@@ -0,0 +1,46 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* camel-mh-provider.c: mh provider registration code */
+
+/*
+ *
+ * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "config.h"
+#include "camel-mh-store.h"
+#include "camel-provider.h"
+#include "camel-log.h"
+
+
+static CamelProvider _mh_provider = {
+ (GtkType) 0,
+ PROVIDER_STORE,
+ "mh",
+ "Camel default mh provider",
+ "This is a very simple provider, mh is a bad protocol anyway",
+ (GModule *) NULL
+};
+
+
+
+CamelProvider *
+camel_provider_module_init ()
+{
+ _mh_provider.object_type = camel_mh_store_get_type();
+ return &_mh_provider;
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 55ef5048dd..77f5b37090 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,4 +22,5 @@ noinst_PROGRAMS = \
test1 \
test2 \
test3 \
- test4
+ test4 \
+ test7
diff --git a/tests/test7.c b/tests/test7.c
new file mode 100644
index 0000000000..aaf256f64b
--- /dev/null
+++ b/tests/test7.c
@@ -0,0 +1,22 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* test provider stuff */
+
+
+#include "camel.h"
+
+
+int
+main (int argc, char**argv)
+{
+ const CamelProvider *new_provider;
+
+ camel_debug_level = CAMEL_LOG_LEVEL_FULL_DEBUG;
+
+ gtk_init (&argc, &argv);
+ camel_init ();
+
+
+ new_provider = camel_provider_register_as_module ("../camel/providers/MH/.libs/libcamelmh.so");
+
+}