New async function that will be used for SSL certs later.

2001-03-09  Jeffrey Stedfast  <fejj@ximian.com>

	* mail-mt.c (mail_get_accept): New async function that will be
	used for SSL certs later.

	* session.c (auth_callback): Changed to return a gpointer value.
	(mail_session_accept_dialog): New function to handle the new
	_ACCEPT authenticator mode.

svn path=/trunk/; revision=8622
This commit is contained in:
Jeffrey Stedfast
2001-03-10 00:14:11 +00:00
committed by Jeffrey Stedfast
parent 5b49e84e6a
commit b860bc0e2d
5 changed files with 163 additions and 21 deletions

View File

@ -1,3 +1,12 @@
2001-03-09 Jeffrey Stedfast <fejj@ximian.com>
* mail-mt.c (mail_get_accept): New async function that will be
used for SSL certs later.
* session.c (auth_callback): Changed to return a gpointer value.
(mail_session_accept_dialog): New function to handle the new
_ACCEPT authenticator mode.
2001-03-08 Jeffrey Stedfast <fejj@ximian.com>
* folder-browser-factory.c: Set the Forward->Quoted callback.

View File

@ -554,7 +554,7 @@ void mail_statusf(const char *fmt, ...)
struct _pass_msg {
struct _mail_msg msg;
char *prompt;
const char *prompt;
int secret;
char *result;
};
@ -609,7 +609,7 @@ struct _mail_msg_op get_pass_op = {
/* returns the password, or NULL if cancelled */
char *
mail_get_password(char *prompt, gboolean secret)
mail_get_password(const char *prompt, gboolean secret)
{
char *ret;
struct _pass_msg *m, *r;
@ -648,6 +648,92 @@ mail_get_password(char *prompt, gboolean secret)
/* ******************** */
/* ********************************************************************** */
struct _accept_msg {
struct _mail_msg msg;
const char *prompt;
gboolean result;
};
static void
do_get_accept (struct _mail_msg *mm)
{
struct _accept_msg *m = (struct _accept_msg *)mm;
GtkWidget *dialog;
GtkWidget *label;
dialog = gnome_dialog_new (_("Do you accept?"),
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO);
gnome_dialog_set_default (GNOME_DIALOG (dialog), 1);
label = gtk_label_new (m->prompt);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label,
TRUE, TRUE, 0);
/* hrm, we can't run this async since the gui_port from which we're called
will reply to our message for us */
m->result = gnome_dialog_run_and_close (GNOME_DIALOG (dialog)) == 0;
}
static void
do_free_accept (struct _mail_msg *mm)
{
/*struct _accept_msg *m = (struct _accept_msg *)mm;*/
/* nothing to do here */
}
struct _mail_msg_op get_accept_op = {
NULL,
do_get_accept,
NULL,
do_free_accept,
};
/* prompt the user with a yes/no question and return the response */
gboolean
mail_get_accept (const char *prompt)
{
struct _accept_msg *m, *r;
EMsgPort *accept_reply;
gboolean accept;
accept_reply = e_msgport_new ();
m = mail_msg_new (&get_accept_op, accept_reply, sizeof (*m));
m->prompt = prompt;
if (pthread_self () == mail_gui_thread) {
do_get_accept ((struct _mail_msg *)m);
r = m;
} else {
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
/* we want this single-threaded, this is the easiest way to do it without blocking ? */
pthread_mutex_lock (&lock);
e_msgport_put (mail_gui_port, (EMsg *)m);
e_msgport_wait (accept_reply);
r = (struct _accept_msg *)e_msgport_get (accept_reply);
pthread_mutex_unlock (&lock);
}
g_assert (r == m);
accept = m->result;
mail_msg_free (m);
e_msgport_destroy (accept_reply);
return accept;
}
/* ******************** */
struct _proxy_msg {
struct _mail_msg msg;
CamelObjectEventHookFunc func;

View File

@ -66,7 +66,10 @@ void mail_statusf(const char *fmt, ...);
void mail_status(const char *msg);
/* request a string/password */
char *mail_get_password(char *prompt, gboolean secret);
char *mail_get_password (const char *prompt, gboolean secret);
/* request a yes/no response as to whether or not to accept (a certificate?) */
gboolean mail_get_accept (const char *prompt);
/* forward a camel event (or other call) to the gui thread */
int mail_proxy_event(CamelObjectEventHookFunc func, CamelObject *o, void *event_data, void *data);

View File

@ -36,6 +36,8 @@ void mail_session_init (void);
void mail_session_enable_interaction (gboolean enable);
char *mail_session_request_dialog (const char *prompt, gboolean secret,
const char *key, gboolean async);
gboolean mail_session_accept_dialog (const char *prompt, const char *key,
gboolean async);
void mail_session_forget_passwords (BonoboUIComponent *uih, void *user_data,
const char *path);
void mail_session_remember_password (const char *url);

View File

@ -69,31 +69,63 @@ mail_session_request_dialog (const char *prompt, gboolean secret, const char *ke
ans == NULL)
return NULL;
} else {
if ((ans = mail_get_password ((char *) prompt, secret)) == NULL)
if ((ans = mail_get_password (prompt, secret)) == NULL)
return NULL;
}
g_hash_table_insert (passwords, g_strdup (key), g_strdup (ans));
return ans;
}
static char *
gboolean
mail_session_accept_dialog (const char *prompt, const char *key, gboolean async)
{
GtkWidget *dialog;
GtkWidget *label;
if (!interaction_enabled)
return FALSE;
if (!async) {
dialog = gnome_dialog_new (_("Do you accept?"),
GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO);
gnome_dialog_set_default (GNOME_DIALOG (dialog), 1);
label = gtk_label_new (prompt);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label,
TRUE, TRUE, 0);
if (gnome_dialog_run_and_close (GNOME_DIALOG (dialog)) == 0)
return TRUE;
else
return FALSE;
} else {
return mail_get_accept (prompt);
}
}
static gpointer
auth_callback (CamelAuthCallbackMode mode, char *data, gboolean secret,
CamelService *service, char *item, CamelException *ex)
{
char *key, *ans, *url;
gboolean accept;
url = camel_url_to_string (service->url, FALSE);
key = g_strdup_printf ("%s:%s", url, item);
g_free (url);
if (mode == CAMEL_AUTHENTICATOR_TELL) {
switch (mode) {
case CAMEL_AUTHENTICATOR_TELL:
if (!data) {
g_hash_table_remove (passwords, key);
g_free (key);
} else {
gpointer old_key, old_data;
if (g_hash_table_lookup_extended (passwords, key,
&old_key,
&old_data)) {
@ -103,19 +135,29 @@ auth_callback (CamelAuthCallbackMode mode, char *data, gboolean secret,
} else
g_hash_table_insert (passwords, key, data);
}
return NULL;
break;
case CAMEL_AUTHENTICATOR_ASK:
ans = mail_session_request_dialog (data, secret, key, TRUE);
g_free (key);
if (!ans) {
camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
"User canceled operation.");
}
return ans;
break;
case CAMEL_AUTHENTICATOR_ACCEPT:
accept = mail_session_accept_dialog (data, key, TRUE);
g_free (key);
return GINT_TO_POINTER (accept);
break;
}
ans = mail_session_request_dialog (data, secret, key, TRUE);
g_free (key);
if (!ans) {
camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
"User canceled operation.");
}
return ans;
return NULL;
}
static char *