static gboolean idle_cb (gpointer data) { EGwConnection *cnc; cnc = e_gw_connection_new (arg_hostname, arg_username, arg_password); if (E_IS_GW_CONNECTION (cnc)) { GList *container_list = NULL; g_print ("Connected to %s!\n", arg_hostname); /* get list of containers */ g_print ("Getting list of containers...\n"); if (e_gw_connection_get_container_list (cnc, "folders", &container_list) == E_GW_CONNECTION_STATUS_OK) { GList *container; for (container = container_list; container != NULL; container = container->next) display_container (E_GW_CONTAINER (container->data)); e_gw_connection_free_container_list (container_list); } g_object_unref (cnc); } else g_print ("ERROR: Could not connect to %s\n", arg_hostname); g_main_loop_quit (main_loop); return FALSE; }
static CamelFolder * groupwise_store_get_folder_sync (CamelStore *store, const gchar *folder_name, CamelStoreGetFolderFlags flags, GCancellable *cancellable, GError **error) { CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = gw_store->priv; CamelFolder *folder; CamelGroupwiseSummary *summary; gchar *container_id, *folder_dir, *storage_path; EGwConnectionStatus status; GList *list = NULL; gboolean done = FALSE, all_ok = TRUE; const gchar *position = E_GW_CURSOR_POSITION_END; gint count = 0, cursor, summary_count = 0; CamelStoreInfo *si = NULL; guint total = 0; GError *local_error = NULL; folder = groupwise_get_folder_from_disk ( store, folder_name, flags, cancellable, &local_error); if (folder) { groupwise_store_set_current_folder (gw_store, folder); return folder; /* Ignore "no such folder" errors, fail on any other error. */ } else if (!g_error_matches (local_error, CAMEL_STORE_ERROR, CAMEL_STORE_ERROR_NO_FOLDER)) { g_propagate_error (error, local_error); return NULL; } else g_clear_error (&local_error); camel_service_lock (CAMEL_SERVICE (gw_store), CAMEL_SERVICE_REC_CONNECT_LOCK); groupwise_store_set_current_folder (gw_store, NULL); if (!camel_groupwise_store_connected (gw_store, cancellable, error)) { camel_service_unlock (CAMEL_SERVICE (gw_store), CAMEL_SERVICE_REC_CONNECT_LOCK); return NULL; } if (!E_IS_GW_CONNECTION ( priv->cnc)) { if (!groupwise_connect_sync (CAMEL_SERVICE (store), cancellable, error)) { camel_service_unlock (CAMEL_SERVICE (gw_store), CAMEL_SERVICE_REC_CONNECT_LOCK); return NULL; } } container_id = g_strdup (g_hash_table_lookup (priv->name_hash, folder_name)); storage_path = g_strdup_printf("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path, folder_name); g_free (storage_path); folder = camel_gw_folder_new (store, folder_name, folder_dir, cancellable, NULL); if (!folder) { camel_service_unlock (CAMEL_SERVICE (gw_store), CAMEL_SERVICE_REC_CONNECT_LOCK); g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID, _("Authentication failed")); g_free (folder_dir); g_free (container_id); return NULL; } g_free (folder_dir); si = camel_store_summary_path ((CamelStoreSummary *)gw_store->summary, folder_name); if (si) { total = si->total; camel_store_summary_info_free ((CamelStoreSummary *)(gw_store)->summary, si); } summary = (CamelGroupwiseSummary *) folder->summary; summary_count = camel_folder_summary_count (folder->summary); if (!summary_count || !summary->time_string) { d(g_print ("\n\n** %s **: No summary as yet : using get cursor request\n\n", folder->name);)
static gboolean groupwise_connect_sync (CamelService *service, GCancellable *cancellable, GError **error) { CamelGroupwiseStore *store = CAMEL_GROUPWISE_STORE (service); CamelGroupwiseStorePrivate *priv = store->priv; CamelGroupwiseStoreNamespace *ns; CamelSession *session = service->session; d("in groupwise store connect\n"); if (service->status == CAMEL_SERVICE_DISCONNECTED) return FALSE; if (!priv) { store->priv = g_new0 (CamelGroupwiseStorePrivate, 1); priv = store->priv; camel_service_construct (service, service->session, service->provider, service->url, error); } camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); if (priv->cnc) { camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); return TRUE; } if (!check_for_connection (service, cancellable, error) || !groupwise_auth_loop (service, cancellable, error)) { camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); camel_service_disconnect_sync (service, TRUE, NULL); return FALSE; } service->status = CAMEL_SERVICE_CONNECTED; camel_offline_store_set_online_sync ( CAMEL_OFFLINE_STORE (store), TRUE, cancellable, NULL); if (!e_gw_connection_get_version (priv->cnc)) { camel_session_alert_user (session, CAMEL_SESSION_ALERT_WARNING, _("Some features may not work correctly with your current server version"), FALSE); } ns = camel_groupwise_store_summary_namespace_new (store->summary, priv->storage_path, '/'); camel_groupwise_store_summary_namespace_set (store->summary, ns); if (camel_store_summary_count ((CamelStoreSummary *)store->summary) == 0) { /*Settting the refresh stamp to the current time*/ store->refresh_stamp = time (NULL); } camel_store_summary_save ((CamelStoreSummary *) store->summary); camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK); if (E_IS_GW_CONNECTION (priv->cnc)) { return TRUE; } return FALSE; }
static gboolean groupwise_auth_loop (CamelService *service, GCancellable *cancellable, GError **error) { CamelSession *session = camel_service_get_session (service); CamelStore *store = CAMEL_STORE (service); CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = groupwise_store->priv; gboolean authenticated = FALSE; gchar *uri; guint32 prompt_flags = CAMEL_SESSION_PASSWORD_SECRET; EGwConnectionErrors errors = {E_GW_CONNECTION_STATUS_INVALID_OBJECT, NULL}; if (priv->use_ssl && !g_str_equal (priv->use_ssl, "never")) uri = g_strconcat ("https://", priv->server_name, ":", priv->port, "/soap", NULL); else uri = g_strconcat ("http://", priv->server_name, ":", priv->port, "/soap", NULL); service->url->passwd = NULL; while (!authenticated) { if (!service->url->passwd && !(store->flags & CAMEL_STORE_PROXY)) { gchar *prompt; prompt = camel_session_build_password_prompt ( "GroupWise", service->url->user, service->url->host); service->url->passwd = camel_session_get_password (session, service, "Groupwise", prompt, "password", prompt_flags, error); g_free (prompt); if (!service->url->passwd) { g_set_error ( error, G_IO_ERROR, G_IO_ERROR_CANCELLED, _("You did not enter a password.")); return FALSE; } } priv->cnc = e_gw_connection_new_with_error_handler (uri, priv->user, service->url->passwd, &errors); if (!E_IS_GW_CONNECTION(priv->cnc) && priv->use_ssl && g_str_equal (priv->use_ssl, "when-possible")) { gchar *http_uri = g_strconcat ("http://", uri + 8, NULL); priv->cnc = e_gw_connection_new (http_uri, priv->user, service->url->passwd); g_free (http_uri); } if (!E_IS_GW_CONNECTION (priv->cnc)) { if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) { /* We need to un-cache the password before prompting again */ prompt_flags |= CAMEL_SESSION_PASSWORD_REPROMPT; g_free (service->url->passwd); service->url->passwd = NULL; } else { g_set_error ( error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_UNAVAILABLE, "%s", errors.description ? errors.description : _("You must be working online to complete this operation")); return FALSE; } } else authenticated = TRUE; } return TRUE; }
static CamelFolder * groupwise_get_folder (CamelStore *store, const char *folder_name, guint32 flags, CamelException *ex) { CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = gw_store->priv; CamelFolder *folder; CamelGroupwiseSummary *summary; char *container_id, *folder_dir, *storage_path; EGwConnectionStatus status; GList *list = NULL; gboolean done = FALSE, all_ok = TRUE; const char *position = E_GW_CURSOR_POSITION_END; int count = 0, cursor, summary_count = 0; CamelStoreInfo *si = NULL; guint total = 0; folder = groupwise_get_folder_from_disk (store, folder_name, flags, ex); if (folder) { camel_object_ref (folder); return folder; } camel_exception_clear (ex); CAMEL_SERVICE_REC_LOCK (gw_store, connect_lock); if (!camel_groupwise_store_connected (gw_store, ex)) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); return NULL; } if (gw_store->current_folder) { camel_object_unref (gw_store->current_folder); gw_store->current_folder = NULL; } if (!E_IS_GW_CONNECTION( priv->cnc)) { if (!groupwise_connect (CAMEL_SERVICE(store), ex)) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); return NULL; } } container_id = g_strdup (g_hash_table_lookup (priv->name_hash, folder_name)); storage_path = g_strdup_printf("%s/folders", priv->storage_path); folder_dir = e_path_to_physical (storage_path, folder_name); g_free(storage_path); folder = camel_gw_folder_new (store, folder_name, folder_dir, ex); if (!folder) { CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_INVALID, _("Authentication failed")); g_free (folder_dir); g_free (container_id); return NULL; } g_free (folder_dir); si = camel_store_summary_path ((CamelStoreSummary *)gw_store->summary, folder_name); if (si) { total = si->total; camel_store_summary_info_free ((CamelStoreSummary *)(gw_store)->summary, si); } summary = (CamelGroupwiseSummary *) folder->summary; summary_count = camel_folder_summary_count (folder->summary); if(!summary_count || !summary->time_string) { d(g_print ("\n\n** %s **: No summary as yet : using get cursor request\n\n", folder->name);)
static gboolean groupwise_auth_loop (CamelService *service, CamelException *ex) { CamelSession *session = camel_service_get_session (service); CamelStore *store = CAMEL_STORE (service); CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store); CamelGroupwiseStorePrivate *priv = groupwise_store->priv; gboolean authenticated = FALSE; char *uri; EGwConnectionErrors errors; if (priv->use_ssl && !g_str_equal (priv->use_ssl, "never")) uri = g_strconcat ("https://", priv->server_name, ":", priv->port, "/soap", NULL); else uri = g_strconcat ("http://", priv->server_name, ":", priv->port, "/soap", NULL); service->url->passwd = NULL; while (!authenticated) { if (!service->url->passwd && !(store->flags & CAMEL_STORE_PROXY)) { char *prompt; prompt = camel_session_build_password_prompt ( "GroupWise", service->url->user, service->url->host); service->url->passwd = camel_session_get_password (session, service, "Groupwise", prompt, "password", CAMEL_SESSION_PASSWORD_SECRET, ex); g_free (prompt); if (!service->url->passwd) { camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("You did not enter a password.")); return FALSE; } } priv->cnc = e_gw_connection_new_with_error_handler (uri, priv->user, service->url->passwd, &errors); if (!E_IS_GW_CONNECTION(priv->cnc) && priv->use_ssl && g_str_equal (priv->use_ssl, "when-possible")) { char *http_uri = g_strconcat ("http://", uri + 8, NULL); priv->cnc = e_gw_connection_new (http_uri, priv->user, service->url->passwd); g_free (http_uri); } if (!E_IS_GW_CONNECTION(priv->cnc)) { if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) { /* We need to un-cache the password before prompting again */ camel_session_forget_password (session, service, "Groupwise", "password", ex); g_free (service->url->passwd); service->url->passwd = NULL; camel_exception_clear (ex); } else { camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, g_strdup (errors.description)); return FALSE; } } else authenticated = TRUE; } return TRUE; }