diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c index 68206ee9fe91a5ece0a784a400dd4f9510fc394e..c55fca4a82e4c60ef024c69217830997a5916910 100644 --- a/src/gcal-source-dialog.c +++ b/src/gcal-source-dialog.c @@ -925,11 +925,11 @@ stack_visible_child_name_changed (GObject *object, auth = e_source_get_extension (self->source, E_SOURCE_EXTENSION_AUTHENTICATION); webdav = e_source_get_extension (self->source, E_SOURCE_EXTENSION_WEBDAV_BACKEND); soup = e_source_webdav_dup_soup_uri (webdav); - uri = g_strdup_printf ("%s://%s%s:%d", + uri = g_strdup_printf ("%s://%s:%d%s", soup_uri_get_scheme (soup), e_source_authentication_get_host (auth), - e_source_webdav_get_resource_path (webdav), - e_source_authentication_get_port (auth)); + e_source_authentication_get_port (auth), + e_source_webdav_get_resource_path (webdav)); gtk_link_button_set_uri (GTK_LINK_BUTTON (self->calendar_url_button), uri); gtk_button_set_label (GTK_BUTTON (self->calendar_url_button), uri); @@ -1234,14 +1234,15 @@ validate_url_cb (GcalSourceDialog *dialog) ESourceExtension *ext; ESourceWebdav *webdav; ESource *source; - SoupURI *soup_uri; + g_autoptr (SoupURI) soup_uri; const gchar *uri; - gchar *host, *path; - gboolean uri_valid, is_file; + const gchar *host, *path; + gboolean is_file; dialog->validate_url_resource_id = 0; soup_uri = NULL; host = path = NULL; + is_file = FALSE; /** * Remove any reminescent ESources @@ -1263,10 +1264,15 @@ validate_url_cb (GcalSourceDialog *dialog) /* Get the hostname and file path from the server */ uri = gtk_entry_get_text (GTK_ENTRY (dialog->calendar_address_entry)); - uri_valid = uri_get_fields (uri, NULL, &host, &path, &is_file); + soup_uri = soup_uri_new (uri); + if (!soup_uri) + return FALSE; - if (!host || !uri_valid) - goto out; + host = soup_uri_get_host (soup_uri); + path = soup_uri_get_path (soup_uri); + + if (soup_uri_get_scheme (soup_uri) == SOUP_URI_SCHEME_FILE) + is_file = TRUE; g_debug ("Detected host: '%s', path: '%s'", host, path); @@ -1285,7 +1291,6 @@ validate_url_cb (GcalSourceDialog *dialog) e_source_authentication_set_host (auth, host); /* Webdav */ - soup_uri = soup_uri_new (uri); webdav = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND); e_source_webdav_set_soup_uri (webdav, soup_uri); @@ -1302,7 +1307,7 @@ validate_url_cb (GcalSourceDialog *dialog) /* Update buttons */ gtk_widget_set_sensitive (dialog->add_button, source != NULL); - goto out; + return FALSE; } /* Pulse the entry while it performs the check */ @@ -1366,11 +1371,6 @@ validate_url_cb (GcalSourceDialog *dialog) e_named_parameters_free (credentials); -out: - g_clear_pointer (&soup_uri, soup_uri_free); - g_free (host); - g_free (path); - return FALSE; } @@ -1562,16 +1562,18 @@ discover_sources_cb (GObject *source, /* TODO: show a list of calendars */ for (aux = discovered_sources; aux != NULL; aux = aux->next) { + g_autoptr (SoupURI) soup_uri = NULL; EWebDAVDiscoveredSource *discovered_source; - gchar *resource_path = NULL; - gboolean uri_valid; + const gchar *resource_path = NULL; discovered_source = aux->data; + soup_uri = soup_uri_new (discovered_source->href); + /* Get the new resource path from the uri */ - uri_valid = uri_get_fields (discovered_source->href, NULL, NULL, &resource_path, NULL); + resource_path = soup_uri_get_path (soup_uri); - if (uri_valid) + if (soup_uri) { ESourceSelectable *selectable; ESourceWebdav *webdav; @@ -1609,8 +1611,6 @@ discover_sources_cb (GObject *source, gtk_widget_show_all (row); } - - g_free (resource_path); } /* Free things up */ diff --git a/src/gcal-utils.c b/src/gcal-utils.c index 4558f54080c480f2e5ba6cd5fa60d9d18cd631f2..61af5bf213b7488ae94cd61b25c912fd73bd8da8 100644 --- a/src/gcal-utils.c +++ b/src/gcal-utils.c @@ -874,86 +874,6 @@ fix_popover_menu_icons (GtkPopover *popover) g_list_free (menu_section_box_children); } -/** - * uri_get_fields: - * @uri: the URI - * @schema: (nullable): return location for the schema of the URI - * @host: (nullable): return location for the host of the URI - * @path: (nullable): return location for the resource path - * - * Split the given URI into the fields. - * - * Returns: #TRUE if @uri could be parsed, #FALSE otherwise - */ -gboolean -uri_get_fields (const gchar *uri, - gchar **schema, - gchar **host, - gchar **path, - gboolean *is_file) -{ - GRegex *regex; - GMatchInfo *match; - gboolean valid; - - g_return_val_if_fail (uri != NULL, FALSE); - - match = NULL; - valid = FALSE; - - regex = g_regex_new ("([a-zA-Z0-9\\+\\.\\-]*:\\/\\/){0,1}([-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b)([-a-zA-Z0-9@:%_\\+.//=]*)", - G_REGEX_CASELESS, 0, NULL); - - /* - * Retrieved matching URI. The whole url is - * checked and the regex groups are: - * 1. schema - * 2. host - * 3. server path - */ - if (g_regex_match (regex, uri, 0, &match)) - { - valid = TRUE; - - if (schema != NULL) - *schema = g_match_info_fetch (match, 1); - - if (host != NULL) - *host = g_match_info_fetch (match, 2); - - if (path != NULL) - *path = g_match_info_fetch (match, 3); - - g_match_info_free (match); - } - else - { - if (schema != NULL) - *schema = NULL; - - if (host != NULL) - *host = NULL; - - if (path != NULL) - *path = NULL; - } - - /* 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); - return valid; -} - /** * get_source_parent_name_color: * @manager: a #GcalManager diff --git a/src/gcal-utils.h b/src/gcal-utils.h index 3b5bd9ac9b05c7e848e080b2aee2108b6c315c51..99e7bb0923e8db00a60161e713316be8d64bf31b 100644 --- a/src/gcal-utils.h +++ b/src/gcal-utils.h @@ -134,12 +134,6 @@ gsize e_utf8_strftime_fix_am_pm (gchar void fix_popover_menu_icons (GtkPopover *popover); -gboolean uri_get_fields (const gchar *uri, - gchar **schema, - gchar **host, - gchar **path, - gboolean *is_file); - void get_source_parent_name_color (GcalManager *manager, ESource *source, gchar **name,