source-dialog: improve URI handler
Now we have a more reliable way to detect whether the passed URI is a file or a resource. https://bugzilla.gnome.org/show_bug.cgi?id=780455
This commit is contained in:
@@ -159,6 +159,7 @@ PKG_CHECK_MODULES([CALENDAR], [
|
|||||||
libedataserver-1.2 >= $EDATASERVER_REQUIRED
|
libedataserver-1.2 >= $EDATASERVER_REQUIRED
|
||||||
libedataserverui-1.2 >= $EDATASERVERUI_REQUIRED
|
libedataserverui-1.2 >= $EDATASERVERUI_REQUIRED
|
||||||
libical >= $LIBICAL_REQUIRED
|
libical >= $LIBICAL_REQUIRED
|
||||||
|
libsoup-2.4
|
||||||
gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED])
|
gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED])
|
||||||
|
|
||||||
AC_CHECK_LIB([ical], [icaltime_days_in_year], [],
|
AC_CHECK_LIB([ical], [icaltime_days_in_year], [],
|
||||||
|
|||||||
+67
-53
@@ -25,6 +25,7 @@
|
|||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
#include <goa/goa.h>
|
#include <goa/goa.h>
|
||||||
#include <libedataserverui/libedataserverui.h>
|
#include <libedataserverui/libedataserverui.h>
|
||||||
|
#include <libsoup/soup.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:gcal-source-dialog
|
* SECTION:gcal-source-dialog
|
||||||
@@ -1116,13 +1117,17 @@ static gboolean
|
|||||||
validate_url_cb (GcalSourceDialog *dialog)
|
validate_url_cb (GcalSourceDialog *dialog)
|
||||||
{
|
{
|
||||||
ESourceAuthentication *auth;
|
ESourceAuthentication *auth;
|
||||||
|
ENamedParameters *credentials;
|
||||||
ESourceExtension *ext;
|
ESourceExtension *ext;
|
||||||
ESourceWebdav *webdav;
|
ESourceWebdav *webdav;
|
||||||
ESource *source;
|
ESource *source;
|
||||||
|
SoupURI *soup_uri;
|
||||||
|
const gchar *uri;
|
||||||
gchar *host, *path;
|
gchar *host, *path;
|
||||||
gboolean uri_valid;
|
gboolean uri_valid, is_file;
|
||||||
|
|
||||||
dialog->validate_url_resource_id = 0;
|
dialog->validate_url_resource_id = 0;
|
||||||
|
soup_uri = NULL;
|
||||||
host = path = NULL;
|
host = path = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1144,13 +1149,14 @@ validate_url_cb (GcalSourceDialog *dialog)
|
|||||||
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (dialog->calendar_address_entry), GTK_ENTRY_ICON_SECONDARY, NULL);
|
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (dialog->calendar_address_entry), GTK_ENTRY_ICON_SECONDARY, NULL);
|
||||||
|
|
||||||
/* Get the hostname and file path from the server */
|
/* Get the hostname and file path from the server */
|
||||||
uri_valid = uri_get_fields (gtk_entry_get_text (GTK_ENTRY (dialog->calendar_address_entry)), NULL, &host, &path);
|
uri = gtk_entry_get_text (GTK_ENTRY (dialog->calendar_address_entry));
|
||||||
|
uri_valid = uri_get_fields (uri, NULL, &host, &path, &is_file);
|
||||||
|
|
||||||
g_debug ("[source-dialog] host: '%s', path: '%s'", host, path);
|
if (!host || !uri_valid)
|
||||||
|
|
||||||
if (host == NULL || !uri_valid)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
g_debug ("Detected host: '%s', path: '%s'", host, path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the new source and add the needed
|
* Create the new source and add the needed
|
||||||
* extensions.
|
* extensions.
|
||||||
@@ -1166,81 +1172,89 @@ validate_url_cb (GcalSourceDialog *dialog)
|
|||||||
e_source_authentication_set_host (auth, host);
|
e_source_authentication_set_host (auth, host);
|
||||||
|
|
||||||
/* Webdav */
|
/* Webdav */
|
||||||
|
soup_uri = soup_uri_new (uri);
|
||||||
webdav = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
|
webdav = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
|
||||||
e_source_webdav_set_resource_path (webdav, path);
|
e_source_webdav_set_soup_uri (webdav, soup_uri);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're dealing with an absolute file path,
|
* If we're dealing with an absolute file path,
|
||||||
* there is no need to check the server for more
|
* there is no need to check the server for more
|
||||||
* sources.
|
* sources.
|
||||||
*/
|
*/
|
||||||
if (g_str_has_suffix (path, ".ics"))
|
if (is_file)
|
||||||
{
|
{
|
||||||
/* Set the private source so it saves at closing */
|
/* Set the private source so it saves at closing */
|
||||||
dialog->remote_sources = g_list_append (dialog->remote_sources, source);
|
dialog->remote_sources = g_list_append (dialog->remote_sources, source);
|
||||||
|
|
||||||
/* Update buttons */
|
/* Update buttons */
|
||||||
gtk_widget_set_sensitive (dialog->add_button, source != NULL);
|
gtk_widget_set_sensitive (dialog->add_button, source != NULL);
|
||||||
|
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pulse the entry while it performs the check */
|
||||||
|
dialog->calendar_address_id = g_timeout_add (ENTRY_PROGRESS_TIMEOUT, (GSourceFunc) pulse_web_entry, dialog);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to retrieve the sources without prompting
|
||||||
|
* username and password. If we get any error,
|
||||||
|
* then it prompts and retry.
|
||||||
|
*/
|
||||||
|
credentials = e_named_parameters_new ();
|
||||||
|
|
||||||
|
if (!dialog->prompt_password)
|
||||||
|
{
|
||||||
|
g_debug ("Trying to connect without credentials...");
|
||||||
|
|
||||||
|
/* NULL credentials */
|
||||||
|
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_USERNAME, NULL);
|
||||||
|
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_PASSWORD, NULL);
|
||||||
|
|
||||||
|
e_webdav_discover_sources (source,
|
||||||
|
uri,
|
||||||
|
E_WEBDAV_DISCOVER_SUPPORTS_EVENTS,
|
||||||
|
credentials,
|
||||||
|
NULL,
|
||||||
|
discover_sources_cb,
|
||||||
|
dialog);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ENamedParameters *credentials;
|
gint response;
|
||||||
|
gchar *user, *password;
|
||||||
|
|
||||||
/* Pulse the entry while it performs the check */
|
g_debug ("No credentials failed, retrying with user credentials...");
|
||||||
dialog->calendar_address_id = g_timeout_add (ENTRY_PROGRESS_TIMEOUT, (GSourceFunc) pulse_web_entry, dialog);
|
|
||||||
|
user = password = NULL;
|
||||||
|
response = prompt_credentials (dialog, &user, &password);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to retrieve the sources without prompting
|
* User entered username and password, let's try
|
||||||
* username and password. If we get any error,
|
* with it.
|
||||||
* then it prompts and retry.
|
|
||||||
*/
|
*/
|
||||||
credentials = e_named_parameters_new ();
|
if (response == GTK_RESPONSE_OK)
|
||||||
|
|
||||||
if (!dialog->prompt_password)
|
|
||||||
{
|
{
|
||||||
g_debug ("[source-dialog] Trying to connect without credentials...");
|
/* User inputted credentials */
|
||||||
|
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_USERNAME, user);
|
||||||
|
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_PASSWORD, password);
|
||||||
|
|
||||||
/* NULL credentials */
|
e_webdav_discover_sources (source,
|
||||||
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_USERNAME, NULL);
|
uri,
|
||||||
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_PASSWORD, NULL);
|
E_WEBDAV_DISCOVER_SUPPORTS_EVENTS,
|
||||||
|
credentials,
|
||||||
e_webdav_discover_sources (source, gtk_entry_get_text (GTK_ENTRY (dialog->calendar_address_entry)),
|
NULL,
|
||||||
E_WEBDAV_DISCOVER_SUPPORTS_EVENTS, credentials, NULL, discover_sources_cb,
|
discover_sources_cb,
|
||||||
dialog);
|
dialog);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
gint response;
|
|
||||||
gchar *user, *password;
|
|
||||||
|
|
||||||
g_debug ("[source-dialog] No credentials failed, retrying with user credentials...");
|
g_free (user);
|
||||||
|
g_free (password);
|
||||||
user = password = NULL;
|
|
||||||
response = prompt_credentials (dialog, &user, &password);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* User entered username and password, let's try
|
|
||||||
* with it.
|
|
||||||
*/
|
|
||||||
if (response == GTK_RESPONSE_OK)
|
|
||||||
{
|
|
||||||
/* User inputted credentials */
|
|
||||||
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_USERNAME, user);
|
|
||||||
e_named_parameters_set (credentials, E_SOURCE_CREDENTIAL_PASSWORD, password);
|
|
||||||
|
|
||||||
e_webdav_discover_sources (source, gtk_entry_get_text (GTK_ENTRY (dialog->calendar_address_entry)),
|
|
||||||
E_WEBDAV_DISCOVER_SUPPORTS_EVENTS, credentials, NULL, discover_sources_cb,
|
|
||||||
dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (user);
|
|
||||||
g_free (password);
|
|
||||||
}
|
|
||||||
|
|
||||||
e_named_parameters_free (credentials);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e_named_parameters_free (credentials);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
g_clear_pointer (&soup_uri, soup_uri_free);
|
||||||
g_free (host);
|
g_free (host);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
|
|
||||||
@@ -1439,7 +1453,7 @@ discover_sources_cb (GObject *source,
|
|||||||
src = aux->data;
|
src = aux->data;
|
||||||
|
|
||||||
/* Get the new resource path from the uri */
|
/* Get the new resource path from the uri */
|
||||||
uri_valid = uri_get_fields (src->href, NULL, NULL, &resource_path);
|
uri_valid = uri_get_fields (src->href, NULL, NULL, &resource_path, NULL);
|
||||||
|
|
||||||
if (uri_valid)
|
if (uri_valid)
|
||||||
{
|
{
|
||||||
|
|||||||
+16
-2
@@ -906,7 +906,8 @@ gboolean
|
|||||||
uri_get_fields (const gchar *uri,
|
uri_get_fields (const gchar *uri,
|
||||||
gchar **schema,
|
gchar **schema,
|
||||||
gchar **host,
|
gchar **host,
|
||||||
gchar **path)
|
gchar **path,
|
||||||
|
gboolean *is_file)
|
||||||
{
|
{
|
||||||
GRegex *regex;
|
GRegex *regex;
|
||||||
GMatchInfo *match;
|
GMatchInfo *match;
|
||||||
@@ -939,6 +940,8 @@ uri_get_fields (const gchar *uri,
|
|||||||
|
|
||||||
if (path != NULL)
|
if (path != NULL)
|
||||||
*path = g_match_info_fetch (match, 3);
|
*path = g_match_info_fetch (match, 3);
|
||||||
|
|
||||||
|
g_match_info_free (match);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -952,7 +955,18 @@ uri_get_fields (const gchar *uri,
|
|||||||
*path = NULL;
|
*path = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_match_info_free (match);
|
/* File extension */
|
||||||
|
if (is_file)
|
||||||
|
{
|
||||||
|
GRegex *extension_regex;
|
||||||
|
|
||||||
|
extension_regex = g_regex_new ("(\\.[a-zA-Z0-9]+)$", G_REGEX_CASELESS, 0, NULL);
|
||||||
|
|
||||||
|
*is_file = g_regex_match (extension_regex, uri, 0, NULL);
|
||||||
|
|
||||||
|
g_regex_unref (extension_regex);
|
||||||
|
}
|
||||||
|
|
||||||
g_regex_unref (regex);
|
g_regex_unref (regex);
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -121,7 +121,8 @@ void fix_popover_menu_icons (GtkPopover
|
|||||||
gboolean uri_get_fields (const gchar *uri,
|
gboolean uri_get_fields (const gchar *uri,
|
||||||
gchar **schema,
|
gchar **schema,
|
||||||
gchar **host,
|
gchar **host,
|
||||||
gchar **path);
|
gchar **path,
|
||||||
|
gboolean *is_file);
|
||||||
|
|
||||||
void get_source_parent_name_color (GcalManager *manager,
|
void get_source_parent_name_color (GcalManager *manager,
|
||||||
ESource *source,
|
ESource *source,
|
||||||
|
|||||||
Reference in New Issue
Block a user