added 'username' and 'password' arguments to Cal::open method, so that we
authorRodrigo Moya <rodrigo@ximian.com>
Fri, 19 Dec 2003 16:29:33 +0000 (16:29 +0000)
committerRodrigo Moya <rodrigo@src.gnome.org>
Fri, 19 Dec 2003 16:29:33 +0000 (16:29 +0000)
2003-12-19  Rodrigo Moya <rodrigo@ximian.com>

* idl/Evolution-DataServer-Calendar.idl: added 'username' and 'password'
arguments to Cal::open method, so that we can send authentication
from the clients.

* libedata-cal/e-cal-backend.[ch] (e_cal_backend_open):
* libedata-cal/e-cal-backend-sync.[ch] (e_cal_backend_sync_open,
_e_cal_backend_open):
* libedata-cal/e-data-cal.c (impl_Cal_open):
* backends/http/e-cal-backend-http.c (e_cal_backend_http_open):
* backends/groupwise/e-cal-backend-groupwise.c
(e_cal_backend_groupwise_open):
* backends/file/e-cal-backend-file.c (e_cal_backend_file_open): adapted
to changes in above method.

* libecal/e-cal.[ch]: added E_CAL_LOAD_AUTHENTICATING to LoadState enum.
(e_cal_open): check with the ESource if the server needs authentication
or not, and if so, ask the client's provided auth function. Call
GNOME_Evolution_Calendar_Cal_Open with the new arguments.

12 files changed:
calendar/ChangeLog
calendar/backends/file/e-cal-backend-file.c
calendar/backends/groupwise/e-cal-backend-groupwise.c
calendar/backends/http/e-cal-backend-http.c
calendar/idl/Evolution-DataServer-Calendar.idl
calendar/libecal/e-cal.c
calendar/libecal/e-cal.h
calendar/libedata-cal/e-cal-backend-sync.c
calendar/libedata-cal/e-cal-backend-sync.h
calendar/libedata-cal/e-cal-backend.c
calendar/libedata-cal/e-cal-backend.h
calendar/libedata-cal/e-data-cal.c

index 7a59be4..2f4ac5b 100644 (file)
@@ -1,3 +1,24 @@
+2003-12-19  Rodrigo Moya <rodrigo@ximian.com>
+
+       * idl/Evolution-DataServer-Calendar.idl: added 'username' and 'password'
+       arguments to Cal::open method, so that we can send authentication
+       from the clients.
+
+       * libedata-cal/e-cal-backend.[ch] (e_cal_backend_open):
+       * libedata-cal/e-cal-backend-sync.[ch] (e_cal_backend_sync_open,
+       _e_cal_backend_open):
+       * libedata-cal/e-data-cal.c (impl_Cal_open):
+       * backends/http/e-cal-backend-http.c (e_cal_backend_http_open):
+       * backends/groupwise/e-cal-backend-groupwise.c
+       (e_cal_backend_groupwise_open):
+       * backends/file/e-cal-backend-file.c (e_cal_backend_file_open): adapted
+       to changes in above method.
+
+       * libecal/e-cal.[ch]: added E_CAL_LOAD_AUTHENTICATING to LoadState enum.
+       (e_cal_open): check with the ESource if the server needs authentication
+       or not, and if so, ask the client's provided auth function. Call
+       GNOME_Evolution_Calendar_Cal_Open with the new arguments.
+
 2003-12-18  Rodrigo Moya <rodrigo@ximian.com>
 
        * backends/groupwise/e-cal-backend-groupwise.c: use a GMutex for
index 67a528d..433f0fd 100644 (file)
@@ -828,7 +828,8 @@ get_uri_string (ECalBackend *backend)
 
 /* Open handler for the file backend */
 static ECalBackendSyncStatus
-e_cal_backend_file_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists)
+e_cal_backend_file_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists,
+                        const char *username, const char *password)
 {
        ECalBackendFile *cbfile;
        ECalBackendFilePrivate *priv;
index abc1205..5ca99a3 100644 (file)
@@ -113,7 +113,7 @@ e_cal_backend_groupwise_is_read_only (ECalBackendSync *backend, EDataCal *cal, g
        return GNOME_Evolution_Calendar_Success;
 }
 
-/*return email address of the person who opened the calender */
+/* return email address of the person who opened the calender */
 static ECalBackendSyncStatus
 e_cal_backend_groupwise_get_cal_address (ECalBackendSync *backend, EDataCal *cal, char **address)
 {
@@ -176,7 +176,8 @@ convert_uri (const char *gw_uri)
 
 /* Open handler for the file backend */
 static ECalBackendSyncStatus
-e_cal_backend_groupwise_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists)
+e_cal_backend_groupwise_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists,
+                             const char *username, const char *password)
 {
        ECalBackendGroupwise *cbgw;
        ECalBackendGroupwisePrivate *priv;
@@ -214,8 +215,8 @@ e_cal_backend_groupwise_open (ECalBackendSync *backend, EDataCal *cal, gboolean
                                            GNOME_VFS_URI_HIDE_USER_NAME |
                                            GNOME_VFS_URI_HIDE_PASSWORD);
        priv->cnc = e_gw_connection_new (real_uri,
-                                        gnome_vfs_uri_get_user_name (vuri),
-                                        gnome_vfs_uri_get_password (vuri));
+                                        username ? username : gnome_vfs_uri_get_user_name (vuri),
+                                        password ? password : gnome_vfs_uri_get_password (vuri));
 
        gnome_vfs_uri_unref (vuri);
        g_free (real_uri);
index 5000aa9..2717764 100644 (file)
@@ -365,7 +365,8 @@ begin_retrieval_cb (ECalBackendHttp *cbhttp)
 
 /* Open handler for the file backend */
 static ECalBackendSyncStatus
-e_cal_backend_http_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists)
+e_cal_backend_http_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists,
+                        const char *username, const char *password)
 {
        ECalBackendHttp *cbhttp;
        ECalBackendHttpPrivate *priv;
@@ -393,7 +394,7 @@ e_cal_backend_http_open (ECalBackendSync *backend, EDataCal *cal, gboolean only_
                g_idle_add ((GSourceFunc) begin_retrieval_cb, cbhttp);
        }
 
-       e_cal_backend_sync_open (priv->file_backend, cal, FALSE);
+       e_cal_backend_sync_open (priv->file_backend, cal, FALSE, username, password);
        return GNOME_Evolution_Calendar_Success;
 }
 
index 76a010f..05cba3d 100644 (file)
@@ -154,7 +154,7 @@ module Calendar {
                /* A calendar is identified by its URI */
                readonly attribute string uri;
 
-               oneway void open (in boolean only_if_exists);
+               oneway void open (in boolean only_if_exists, in string username, in string password);
                oneway void remove ();
 
                /* Check write permissions for calendar */
index fa9e305..4f9c742 100644 (file)
@@ -1274,7 +1274,7 @@ e_cal_new (ESource *source, CalObjType type)
 
                return NULL;
        }
-       
+
        return ecal;
 }
 
@@ -1358,6 +1358,7 @@ e_cal_open (ECal *ecal, gboolean only_if_exists, GError **error)
        CORBA_Environment ev;
        ECalendarStatus status;
        ECalendarOp *our_op;
+       const char *username = NULL, *password = NULL;
        
        g_return_val_if_fail (ecal != NULL, FALSE);
        g_return_val_if_fail (E_IS_CAL (ecal), FALSE);
@@ -1371,6 +1372,35 @@ e_cal_open (ECal *ecal, gboolean only_if_exists, GError **error)
                E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_BUSY, error);
        }
 
+       /* see if the backend needs authentication */
+       if (e_source_get_property (priv->source, "auth")) {
+               char *prompt, *key;
+
+               priv->load_state = E_CAL_LOAD_AUTHENTICATING;
+
+               if (priv->auth_func == NULL) {
+                       g_mutex_unlock (priv->mutex);
+                       E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED, error);
+               }
+
+               username = e_source_get_property (priv->source, "username");
+               if (!username) {
+                       g_mutex_unlock (priv->mutex);
+                       E_CALENDAR_CHECK_STATUS (E_CALENDAR_STATUS_AUTHENTICATION_REQUIRED, error);
+               }
+
+               /* actually ask the client for authentication */
+               prompt = g_strdup_printf (_("Enter password for %s (user %s)"),
+                                         e_source_peek_name (priv->source), username);
+               key = e_source_get_uri (priv->source);
+
+               password = priv->auth_func (ecal, prompt, key, priv->auth_user_data);
+
+               g_free (prompt);
+               g_free (key);
+       }
+
+       /* start the open operation */
        our_op = e_calendar_new_op (ecal);
 
        g_mutex_lock (our_op->mutex);
@@ -1381,7 +1411,13 @@ e_cal_open (ECal *ecal, gboolean only_if_exists, GError **error)
 
        priv->load_state = E_CAL_LOAD_LOADING;
 
-       GNOME_Evolution_Calendar_Cal_open (priv->cal, only_if_exists, &ev);
+       GNOME_Evolution_Calendar_Cal_open (priv->cal, only_if_exists,
+                                          username ? username : "",
+                                          password ? password : "",
+                                          &ev);
+       if (password)
+               g_free (password);
+
        if (BONOBO_EX (&ev)) {
                e_calendar_remove_op (ecal, our_op);
                g_mutex_unlock (our_op->mutex);
index 6301079..7e1c8d1 100644 (file)
@@ -55,6 +55,7 @@ typedef enum {
 /* Whether the ecal is not loaded, is being loaded, or is already loaded */
 typedef enum {
        E_CAL_LOAD_NOT_LOADED,
+       E_CAL_LOAD_AUTHENTICATING,
        E_CAL_LOAD_LOADING,
        E_CAL_LOAD_LOADED
 } ECalLoadState;
@@ -83,10 +84,10 @@ struct _ECalClass {
        void (* backend_died) (ECal *ecal);
 };
 
-typedef gchar * (* ECalAuthFunc) (ECal *ecal,
-                                 const gchar *prompt,
-                                 const gchar *key,
-                                 gpointer user_data);
+typedef char * (* ECalAuthFunc) (ECal *ecal,
+                                const char *prompt,
+                                const char *key,
+                                gpointer user_data);
 
 GType e_cal_get_type (void);
 
index 23cb3a4..db3cc2e 100644 (file)
@@ -75,7 +75,8 @@ e_cal_backend_sync_get_static_capabilities  (ECalBackendSync *backend, EDataCal
 }
 
 ECalBackendSyncStatus
-e_cal_backend_sync_open  (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists)
+e_cal_backend_sync_open  (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists,
+                         const char *username, const char *password)
 {
        ECalBackendSyncPrivate *priv;
        ECalBackendSyncStatus status;
@@ -86,7 +87,7 @@ e_cal_backend_sync_open  (ECalBackendSync *backend, EDataCal *cal, gboolean only
 
        g_mutex_lock (priv->sync_mutex);
 
-       status = (* E_CAL_BACKEND_SYNC_GET_CLASS (backend)->open_sync) (backend, cal, only_if_exists);
+       status = (* E_CAL_BACKEND_SYNC_GET_CLASS (backend)->open_sync) (backend, cal, only_if_exists, username, password);
 
        g_mutex_unlock (priv->sync_mutex);
 
@@ -319,11 +320,12 @@ _e_cal_backend_get_static_capabilities (ECalBackend *backend, EDataCal *cal)
 }
 
 static void
-_e_cal_backend_open (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists)
+_e_cal_backend_open (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists,
+                    const char *username, const char *password)
 {
        ECalBackendSyncStatus status;
 
-       status = e_cal_backend_sync_open (E_CAL_BACKEND_SYNC (backend), cal, only_if_exists);
+       status = e_cal_backend_sync_open (E_CAL_BACKEND_SYNC (backend), cal, only_if_exists, username, password);
 
        e_data_cal_notify_open (cal, status);
 }
index 76525a0..08de3c2 100644 (file)
@@ -39,7 +39,7 @@ struct _ECalBackendSyncClass {
        ECalBackendSyncStatus (*get_ldap_attribute_sync)  (ECalBackendSync *backend, EDataCal *cal, char **attribute);
        ECalBackendSyncStatus (*get_static_capabilities_sync)  (ECalBackendSync *backend, EDataCal *cal, char **capabilities);
 
-       ECalBackendSyncStatus (*open_sync)  (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists);
+       ECalBackendSyncStatus (*open_sync)  (ECalBackendSync *backend, EDataCal *cal, gboolean only_if_exists, const char *username, const char *password);
        ECalBackendSyncStatus (*remove_sync)  (ECalBackendSync *backend, EDataCal *cal);
 
        ECalBackendSyncStatus (*create_object_sync)  (ECalBackendSync *backend, EDataCal *cal, const char *calobj, char **uid);
@@ -89,8 +89,10 @@ ECalBackendSyncStatus e_cal_backend_sync_get_static_capabilities (ECalBackendSyn
                                                               EDataCal             *cal,
                                                               char           **capabiliites);
 ECalBackendSyncStatus e_cal_backend_sync_open                    (ECalBackendSync  *backend,
-                                                              EDataCal             *cal,
-                                                              gboolean         only_if_exists);
+                                                                 EDataCal             *cal,
+                                                                 gboolean         only_if_exists,
+                                                                 const char *username,
+                                                                 const char *password);
 ECalBackendSyncStatus e_cal_backend_sync_remove                  (ECalBackendSync  *backend,
                                                               EDataCal             *cal);
 ECalBackendSyncStatus e_cal_backend_sync_create_object           (ECalBackendSync  *backend,
index 89287d3..866814c 100644 (file)
@@ -562,6 +562,8 @@ e_cal_backend_get_static_capabilities (ECalBackend *backend, EDataCal *cal)
  * @only_if_exists: Whether the calendar should be opened only if it already
  * exists.  If FALSE, a new calendar will be created when the specified @uri
  * does not exist.
+ * @username: User name to use for authentication (if needed).
+ * @password: Password for @username.
  *
  * Opens a calendar backend with data from a calendar stored at the specified
  * URI.
@@ -569,13 +571,14 @@ e_cal_backend_get_static_capabilities (ECalBackend *backend, EDataCal *cal)
  * Return value: An operation status code.
  **/
 void
-e_cal_backend_open (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists)
+e_cal_backend_open (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists,
+                   const char *username, const char *password)
 {
        g_return_if_fail (backend != NULL);
        g_return_if_fail (E_IS_CAL_BACKEND (backend));
 
        g_assert (CLASS (backend)->open != NULL);
-       (* CLASS (backend)->open) (backend, cal, only_if_exists);
+       (* CLASS (backend)->open) (backend, cal, only_if_exists, username, password);
 }
 
 void
index 80ede5e..9650a1d 100644 (file)
@@ -73,7 +73,7 @@ struct _ECalBackendClass {
        void (* get_ldap_attribute) (ECalBackend *backend, EDataCal *cal);
        void (* get_static_capabilities) (ECalBackend *backend, EDataCal *cal);
        
-       void (* open) (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists);
+       void (* open) (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists, const char *username, const char *password);
        void (* remove) (ECalBackend *backend, EDataCal *cal);
 
        /* Object related virtual methods */
@@ -127,7 +127,7 @@ void e_cal_backend_get_alarm_email_address (ECalBackend *backend, EDataCal *cal)
 void e_cal_backend_get_ldap_attribute (ECalBackend *backend, EDataCal *cal);
 void e_cal_backend_get_static_capabilities (ECalBackend *backend, EDataCal *cal);
 
-void e_cal_backend_open (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists);
+void e_cal_backend_open (ECalBackend *backend, EDataCal *cal, gboolean only_if_exists, const char *username, const char *password);
 void e_cal_backend_remove (ECalBackend *backend, EDataCal *cal);
 
 void e_cal_backend_create_object (ECalBackend *backend, EDataCal *cal, const char *calobj);
index 5613bdf..4090ba3 100644 (file)
@@ -65,6 +65,8 @@ impl_Cal_get_uri (PortableServer_Servant servant,
 static void
 impl_Cal_open (PortableServer_Servant servant,
               CORBA_boolean only_if_exists,
+              const CORBA_char *username,
+              const CORBA_char *password,
               CORBA_Environment *ev)
 {
        EDataCal *cal;
@@ -73,7 +75,7 @@ impl_Cal_open (PortableServer_Servant servant,
        cal = E_DATA_CAL (bonobo_object_from_servant (servant));
        priv = cal->priv;
 
-       e_cal_backend_open (priv->backend, cal, only_if_exists);
+       e_cal_backend_open (priv->backend, cal, only_if_exists, username, password);
 }
 
 static void