new file. MH provider registration stuff.
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. Providers modules loading Works !!! :)))) svn path=/trunk/; revision=1105
This commit is contained in:
committed by
Bertrand Guiheneuf
parent
33ffe9aadc
commit
a478ee7e9d
15
ChangeLog
15
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):
|
||||
|
||||
@ -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.
|
||||
|
||||
Here will be the routine to load providers (plugins)
|
||||
and register them */
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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 ();
|
||||
|
||||
|
||||
@ -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 = \
|
||||
|
||||
46
camel/providers/MH/camel-mh-provider.c
Normal file
46
camel/providers/MH/camel-mh-provider.c
Normal file
@ -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;
|
||||
}
|
||||
@ -22,4 +22,5 @@ noinst_PROGRAMS = \
|
||||
test1 \
|
||||
test2 \
|
||||
test3 \
|
||||
test4
|
||||
test4 \
|
||||
test7
|
||||
|
||||
22
tests/test7.c
Normal file
22
tests/test7.c
Normal file
@ -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");
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user