aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-02-22 03:56:49 +0800
committerDan Winship <danw@src.gnome.org>2000-02-22 03:56:49 +0800
commit8ea1212d992c564a3a7849a41be9000ce50d0f6b (patch)
treeebc891496db9d1ad04a43153bd79f2b068902c07
parent0eff8e4321d63ef1dce20cceae8314b3628767a4 (diff)
downloadgsoc2013-evolution-8ea1212d992c564a3a7849a41be9000ce50d0f6b.tar.gz
gsoc2013-evolution-8ea1212d992c564a3a7849a41be9000ce50d0f6b.tar.zst
gsoc2013-evolution-8ea1212d992c564a3a7849a41be9000ce50d0f6b.zip
Add "authenticator" to CamelSession and update things to use it.
svn path=/trunk/; revision=1890
-rw-r--r--ChangeLog5
-rw-r--r--camel/ChangeLog9
-rw-r--r--camel/camel-exception-list.def1
-rw-r--r--camel/camel-session.c41
-rw-r--r--camel/camel-session.h15
-rw-r--r--mail/ChangeLog5
-rw-r--r--mail/session.c42
-rw-r--r--tests/test10.c11
-rw-r--r--tests/test11.c11
9 files changed, 130 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 46970b1676..ca36709fcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2000-02-21 Dan Winship <danw@helixcode.com>
+
+ * tests/test10.c:
+ * tests/test11.c: update for camel changes
+
2000-02-20 Matt Loper <matt@helixcode.com>
* tests/Makefile.am: Changed dependencies on libibex.la to
diff --git a/camel/ChangeLog b/camel/ChangeLog
index c8ec75d11f..00eb1cd4d3 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,6 +1,13 @@
2000-02-21 Dan Winship <danw@helixcode.com>
- * camel-session.h:
+ * camel-session.h: (struct _CamelSession): Add authenticator.
+
+ * camel-session.c (camel_session_new): Add authenticator.
+ (camel_session_query_authenticator): New function to query the
+ session authenticator for password, etc, information.
+
+2000-02-21 Dan Winship <danw@helixcode.com>
+
* camel-session.c: add CamelExceptions to several functions. Use
camel_session_new to initialize the session and URL fields of
created CamelStores as appropriate.
diff --git a/camel/camel-exception-list.def b/camel/camel-exception-list.def
index c157d9544c..e99f0c90d9 100644
--- a/camel/camel-exception-list.def
+++ b/camel/camel-exception-list.def
@@ -10,6 +10,7 @@ CAMEL_EXCEPTION_NONE = 0,
/* Generic exceptions */
CAMEL_EXCEPTION_INVALID_PARAM,
CAMEL_EXCEPTION_SYSTEM,
+CAMEL_EXCEPTION_USER_CANCEL,
/* CamelFolderException */
CAMEL_EXCEPTION_FOLDER_NULL = 100,
diff --git a/camel/camel-session.c b/camel/camel-session.c
index cf5db3c57f..f014d46596 100644
--- a/camel/camel-session.c
+++ b/camel/camel-session.c
@@ -85,9 +85,12 @@ camel_session_get_type (void)
CamelSession *
-camel_session_new (void)
+camel_session_new (CamelAuthCallback authenticator)
{
- return gtk_type_new (CAMEL_SESSION_TYPE);
+ CamelSession *session = gtk_type_new (CAMEL_SESSION_TYPE);
+
+ session->authenticator = authenticator;
+ return session;
}
/**
@@ -240,3 +243,37 @@ camel_session_get_store (CamelSession *session, const char *url_string,
g_url_free (url);
return store;
}
+
+
+
+/**
+ * camel_session_query_authenticator: query the session authenticator
+ * @session: session object
+ * @prompt: prompt to use if authenticator can query the user
+ * @secret: whether or not the data is secret (eg, a password)
+ * @service: the service this query is being made by
+ * @item: an identifier, unique within this service, for the information
+ * @ex: a CamelException
+ *
+ * This function is used by a CamelService to request authentication
+ * information it needs to complete a connection. If the authenticator
+ * stores any authentication information in configuration files, it
+ * should use @service and @item as keys to find the right piece of
+ * information. If it doesn't store authentication information in config
+ * files, it should use the given @prompt to ask the user for the
+ * information. If @secret is set, the user's input should not be
+ * echoed back. The authenticator should set @ex to
+ * CAMEL_EXCEPTION_USER_CANCEL if the user did not provide the
+ * information. The caller must g_free() the information when it is
+ * done with it.
+ *
+ * Return value: the authentication information or NULL.
+ **/
+char *
+camel_session_query_authenticator (CamelSession *session, char *prompt,
+ gboolean secret,
+ CamelService *service, char *item,
+ CamelException *ex)
+{
+ return session->authenticator (prompt, secret, service, item, ex);
+}
diff --git a/camel/camel-session.h b/camel/camel-session.h
index 0b65326323..272417644c 100644
--- a/camel/camel-session.h
+++ b/camel/camel-session.h
@@ -44,15 +44,19 @@ extern "C" {
#define CAMEL_IS_SESSION(o) (GTK_CHECK_TYPE((o), CAMEL_SESSION_TYPE))
+typedef char *(*CamelAuthCallback) (char *prompt, gboolean secret,
+ CamelService *service, char *item,
+ CamelException *ex);
struct _CamelSession
{
GtkObject parent_object;
+
+ CamelAuthCallback authenticator;
GHashTable *store_provider_list; /* providers are identified by their protocol */
GHashTable *transport_provider_list;
-
-
+
};
@@ -71,7 +75,7 @@ typedef struct {
GtkType camel_session_get_type (void);
-CamelSession *camel_session_new (void);
+CamelSession *camel_session_new (CamelAuthCallback authenticator);
void camel_session_set_provider (CamelSession *session, CamelProvider *provider);
CamelStore *camel_session_get_store_for_protocol (CamelSession *session,
const gchar *protocol,
@@ -79,7 +83,10 @@ CamelStore *camel_session_get_store_for_protocol (CamelSession *session,
CamelStore *camel_session_get_store (CamelSession *session,
const char *url_string,
CamelException *ex);
-
+char *camel_session_query_authenticator (CamelSession *session, char *prompt,
+ gboolean secret,
+ CamelService *service, char *item,
+ CamelException *ex);
#ifdef __cplusplus
}
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 198b2c612d..33f9690fcd 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,5 +1,10 @@
2000-02-21 Dan Winship <danw@helixcode.com>
+ * session.c (session_store_new): Pass a CamelAuthCallback
+ (evolution_auth_callback) to camel_session_new.
+
+2000-02-21 Dan Winship <danw@helixcode.com>
+
* session.c (session_store_new): Update session_store_new to
deal with the fact that camel_session_get_store takes a
CamelException now. Doesn't actually do anything with the
diff --git a/mail/session.c b/mail/session.c
index e0390c380f..a97b70ed26 100644
--- a/mail/session.c
+++ b/mail/session.c
@@ -7,6 +7,7 @@
* (C) 2000 Helix Code, Inc. http://www.helixcode.com
*/
#include <config.h>
+#include <gnome.h>
#include "session.h"
#include "e-util/e-setup.h"
#include "camel/camel.h"
@@ -14,6 +15,45 @@
SessionStore *default_session;
static void
+request_callback (gchar *string, gpointer data)
+{
+ char **ans = data;
+
+ if (string)
+ *ans = g_strdup(string);
+ else
+ *ans = NULL;
+}
+
+static char *
+evolution_auth_callback (char *prompt, gboolean secret,
+ CamelService *service, char *item,
+ CamelException *ex)
+{
+ GtkWidget *dialog;
+ char *ans;
+
+ /* XXX look up stored passwords */
+
+ /* XXX parent window? */
+ dialog = gnome_request_dialog (secret, prompt, NULL, 0,
+ request_callback, &ans, NULL);
+ if (!dialog) {
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not create dialog box.");
+ return NULL;
+ }
+ if (gnome_dialog_run_and_close (GNOME_DIALOG (dialog)) == -1 ||
+ ans == NULL) {
+ camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
+ "User cancelled query.");
+ return NULL;
+ }
+
+ return ans;
+}
+
+static void
session_providers_init (void)
{
camel_provider_register_as_module (CAMEL_PROVIDERDIR "/libcamelmbox.so");
@@ -25,7 +65,7 @@ session_store_new (const char *uri)
SessionStore *ss = g_new (SessionStore, 1);
CamelException *ex;
- ss->session = camel_session_new ();
+ ss->session = camel_session_new (evolution_auth_callback);
ex = camel_exception_new ();
ss->store = camel_session_get_store (ss->session, uri, ex);
camel_exception_free (ex);
diff --git a/tests/test10.c b/tests/test10.c
index d8a8090138..1d1d2904b9 100644
--- a/tests/test10.c
+++ b/tests/test10.c
@@ -60,6 +60,15 @@ create_sample_mime_message ()
return message;
}
+static char *
+auth_callback(char *prompt, gboolean secret,
+ CamelService *service, char *item,
+ CamelException *ex)
+{
+ printf ("auth_callback called: %s\n", prompt);
+ return NULL;
+}
+
@@ -80,7 +89,7 @@ main (int argc, char**argv)
ex = camel_exception_new ();
camel_provider_register_as_module ("../camel/providers/mbox/.libs/libcamelmbox.so");
- session = camel_session_new ();
+ session = camel_session_new (auth_callback);
store = camel_session_get_store (session, store_url, ex);
if (camel_exception_get_id (ex)) {
printf ("Exception caught in camel_session_get_store\n"
diff --git a/tests/test11.c b/tests/test11.c
index de605365a6..36ec9c6159 100644
--- a/tests/test11.c
+++ b/tests/test11.c
@@ -22,6 +22,15 @@
#include <fcntl.h>
#include <glib.h>
+static char *
+auth_callback(char *prompt, gboolean secret,
+ CamelService *service, char *item,
+ CamelException *ex)
+{
+ printf ("auth_callback called: %s\n", prompt);
+ return NULL;
+}
+
int
main (int argc, char**argv)
{
@@ -40,7 +49,7 @@ main (int argc, char**argv)
ex = camel_exception_new ();
camel_provider_register_as_module ("../camel/providers/mbox/.libs/libcamelmbox.so.0");
- session = camel_session_new ();
+ session = camel_session_new (auth_callback);
store = camel_session_get_store (session, store_url, ex);
if (camel_exception_get_id (ex)) {
printf ("Exception caught in camel_session_get_store\n"