[evolution-data-server] I#96 - Limit properties receive based on expected collection type in WebDAV discover



commit aa09559fee0c4207a01b903a450b0204b961c2a1
Author: Milan Crha <mcrha redhat com>
Date:   Mon Mar 18 14:11:54 2019 +0100

    I#96 - Limit properties receive based on expected collection type in WebDAV discover
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/issues/96

 src/libedataserver/e-webdav-discover.c          | 16 ++++++++----
 src/libedataserver/e-webdav-session.c           | 33 ++++++++++++++++++-------
 src/libedataserver/e-webdav-session.h           |  4 ++-
 src/libedataserverui/e-webdav-discover-widget.c |  8 +++---
 4 files changed, 43 insertions(+), 18 deletions(-)
---
diff --git a/src/libedataserver/e-webdav-discover.c b/src/libedataserver/e-webdav-discover.c
index a8efac8b5..c7944bb10 100644
--- a/src/libedataserver/e-webdav-discover.c
+++ b/src/libedataserver/e-webdav-discover.c
@@ -103,6 +103,7 @@ e_webdav_discover_traverse_propfind_response_cb (EWebDAVSession *webdav,
        } else if (status_code == SOUP_STATUS_OK) {
                xmlXPathObjectPtr xpath_obj;
                gchar *principal_href, *full_href;
+               gboolean is_calendar, is_addressbook;
 
                xpath_obj = e_xml_xpath_eval (xpath_ctx, "%s/A:addressbook-home-set/D:href", 
xpath_prop_prefix);
                if (xpath_obj) {
@@ -122,7 +123,8 @@ e_webdav_discover_traverse_propfind_response_cb (EWebDAVSession *webdav,
                                        full_href = e_webdav_session_ensure_full_uri (webdav, request_uri, 
home_set_href);
                                        if (full_href && *full_href && !g_hash_table_contains 
(wdd->covered_hrefs, full_href) &&
                                            e_webdav_session_list_sync (webdav, full_href, 
E_WEBDAV_DEPTH_THIS_AND_CHILDREN,
-                                               E_WEBDAV_LIST_SUPPORTS | E_WEBDAV_LIST_DISPLAY_NAME | 
E_WEBDAV_LIST_DESCRIPTION | E_WEBDAV_LIST_COLOR,
+                                               E_WEBDAV_LIST_SUPPORTS | E_WEBDAV_LIST_DISPLAY_NAME | 
E_WEBDAV_LIST_DESCRIPTION |
+                                               E_WEBDAV_LIST_COLOR | E_WEBDAV_LIST_ONLY_ADDRESSBOOK,
                                                &resources, wdd->cancellable, wdd->error)) {
                                                e_webdav_discover_split_resources (wdd, resources);
                                                g_slist_free_full (resources, e_webdav_resource_free);
@@ -155,7 +157,8 @@ e_webdav_discover_traverse_propfind_response_cb (EWebDAVSession *webdav,
                                        full_href = e_webdav_session_ensure_full_uri (webdav, request_uri, 
home_set_href);
                                        if (full_href && *full_href && !g_hash_table_contains 
(wdd->covered_hrefs, full_href) &&
                                            e_webdav_session_list_sync (webdav, full_href, 
E_WEBDAV_DEPTH_THIS_AND_CHILDREN,
-                                               E_WEBDAV_LIST_SUPPORTS | E_WEBDAV_LIST_DISPLAY_NAME | 
E_WEBDAV_LIST_DESCRIPTION | E_WEBDAV_LIST_COLOR,
+                                               E_WEBDAV_LIST_SUPPORTS | E_WEBDAV_LIST_DISPLAY_NAME | 
E_WEBDAV_LIST_DESCRIPTION |
+                                               E_WEBDAV_LIST_COLOR | E_WEBDAV_LIST_ONLY_CALENDAR,
                                                &resources, wdd->cancellable, wdd->error)) {
                                                e_webdav_discover_split_resources (wdd, resources);
                                                g_slist_free_full (resources, e_webdav_resource_free);
@@ -233,14 +236,17 @@ e_webdav_discover_traverse_propfind_response_cb (EWebDAVSession *webdav,
 
                g_free (principal_href);
 
-               if (e_xml_xpath_eval_exists (xpath_ctx, "%s/D:resourcetype/C:calendar", xpath_prop_prefix) ||
-                   e_xml_xpath_eval_exists (xpath_ctx, "%s/D:resourcetype/A:addressbook", 
xpath_prop_prefix)) {
+               is_calendar = e_xml_xpath_eval_exists (xpath_ctx, "%s/D:resourcetype/C:calendar", 
xpath_prop_prefix);
+               is_addressbook = e_xml_xpath_eval_exists (xpath_ctx, "%s/D:resourcetype/A:addressbook", 
xpath_prop_prefix);
+
+               if (is_calendar || is_addressbook) {
                        GSList *resources = NULL;
 
                        if (!g_hash_table_contains (wdd->covered_hrefs, href) &&
                            !g_cancellable_is_cancelled (wdd->cancellable) &&
                            e_webdav_session_list_sync (webdav, href, E_WEBDAV_DEPTH_THIS,
-                               E_WEBDAV_LIST_SUPPORTS | E_WEBDAV_LIST_DISPLAY_NAME | 
E_WEBDAV_LIST_DESCRIPTION | E_WEBDAV_LIST_COLOR,
+                               E_WEBDAV_LIST_SUPPORTS | E_WEBDAV_LIST_DISPLAY_NAME | 
E_WEBDAV_LIST_DESCRIPTION | E_WEBDAV_LIST_COLOR |
+                               (is_calendar ? E_WEBDAV_LIST_ONLY_CALENDAR : 0) | (is_addressbook ? 
E_WEBDAV_LIST_ONLY_ADDRESSBOOK : 0),
                                &resources, wdd->cancellable, wdd->error)) {
                                e_webdav_discover_split_resources (wdd, resources);
                                g_slist_free_full (resources, e_webdav_resource_free);
diff --git a/src/libedataserver/e-webdav-session.c b/src/libedataserver/e-webdav-session.c
index c2b587497..32f8bcf92 100644
--- a/src/libedataserver/e-webdav-session.c
+++ b/src/libedataserver/e-webdav-session.c
@@ -3618,6 +3618,7 @@ e_webdav_session_list_sync (EWebDAVSession *webdav,
                            GError **error)
 {
        EXmlDocument *xml;
+       gboolean calendar_props, addressbook_props;
        gboolean success;
 
        g_return_val_if_fail (E_IS_WEBDAV_SESSION (webdav), FALSE);
@@ -3625,6 +3626,14 @@ e_webdav_session_list_sync (EWebDAVSession *webdav,
 
        *out_resources = NULL;
 
+       if (!(flags & (E_WEBDAV_LIST_ONLY_CALENDAR | E_WEBDAV_LIST_ONLY_ADDRESSBOOK))) {
+               calendar_props = TRUE;
+               addressbook_props = TRUE;
+       } else {
+               calendar_props = (flags & E_WEBDAV_LIST_ONLY_CALENDAR) != 0;
+               addressbook_props = (flags & E_WEBDAV_LIST_ONLY_ADDRESSBOOK) != 0;
+       }
+
        xml = e_xml_document_new (E_WEBDAV_NS_DAV, "propfind");
        g_return_val_if_fail (xml != NULL, FALSE);
 
@@ -3632,13 +3641,14 @@ e_webdav_session_list_sync (EWebDAVSession *webdav,
 
        e_xml_document_add_empty_element (xml, NULL, "resourcetype");
 
-       if ((flags & E_WEBDAV_LIST_SUPPORTS) != 0 ||
+       if (calendar_props && (
+           (flags & E_WEBDAV_LIST_SUPPORTS) != 0 ||
            (flags & E_WEBDAV_LIST_DESCRIPTION) != 0 ||
-           (flags & E_WEBDAV_LIST_COLOR) != 0) {
+           (flags & E_WEBDAV_LIST_COLOR) != 0)) {
                e_xml_document_add_namespaces (xml, "C", E_WEBDAV_NS_CALDAV, NULL);
        }
 
-       if ((flags & E_WEBDAV_LIST_SUPPORTS) != 0) {
+       if (calendar_props && (flags & E_WEBDAV_LIST_SUPPORTS) != 0) {
                e_xml_document_add_empty_element (xml, E_WEBDAV_NS_CALDAV, 
"supported-calendar-component-set");
        }
 
@@ -3649,9 +3659,11 @@ e_webdav_session_list_sync (EWebDAVSession *webdav,
        if ((flags & E_WEBDAV_LIST_ETAG) != 0) {
                e_xml_document_add_empty_element (xml, NULL, "getetag");
 
-               e_xml_document_add_namespaces (xml, "CS", E_WEBDAV_NS_CALENDARSERVER, NULL);
+               if (calendar_props) {
+                       e_xml_document_add_namespaces (xml, "CS", E_WEBDAV_NS_CALENDARSERVER, NULL);
 
-               e_xml_document_add_empty_element (xml, E_WEBDAV_NS_CALENDARSERVER, "getctag");
+                       e_xml_document_add_empty_element (xml, E_WEBDAV_NS_CALENDARSERVER, "getctag");
+               }
        }
 
        if ((flags & E_WEBDAV_LIST_CONTENT_TYPE) != 0) {
@@ -3671,14 +3683,17 @@ e_webdav_session_list_sync (EWebDAVSession *webdav,
        }
 
        if ((flags & E_WEBDAV_LIST_DESCRIPTION) != 0) {
-               e_xml_document_add_empty_element (xml, E_WEBDAV_NS_CALDAV, "calendar-description");
+               if (calendar_props)
+                       e_xml_document_add_empty_element (xml, E_WEBDAV_NS_CALDAV, "calendar-description");
 
-               e_xml_document_add_namespaces (xml, "A", E_WEBDAV_NS_CARDDAV, NULL);
+               if (addressbook_props) {
+                       e_xml_document_add_namespaces (xml, "A", E_WEBDAV_NS_CARDDAV, NULL);
 
-               e_xml_document_add_empty_element (xml, E_WEBDAV_NS_CARDDAV, "addressbook-description");
+                       e_xml_document_add_empty_element (xml, E_WEBDAV_NS_CARDDAV, 
"addressbook-description");
+               }
        }
 
-       if ((flags & E_WEBDAV_LIST_COLOR) != 0) {
+       if (calendar_props && (flags & E_WEBDAV_LIST_COLOR) != 0) {
                e_xml_document_add_namespaces (xml, "IC", E_WEBDAV_NS_ICAL, NULL);
 
                e_xml_document_add_empty_element (xml, E_WEBDAV_NS_ICAL, "calendar-color");
diff --git a/src/libedataserver/e-webdav-session.h b/src/libedataserver/e-webdav-session.h
index 67971a691..397078506 100644
--- a/src/libedataserver/e-webdav-session.h
+++ b/src/libedataserver/e-webdav-session.h
@@ -143,7 +143,9 @@ typedef enum {
        E_WEBDAV_LIST_CREATION_DATE     = 1 << 5,
        E_WEBDAV_LIST_LAST_MODIFIED     = 1 << 6,
        E_WEBDAV_LIST_DESCRIPTION       = 1 << 7,
-       E_WEBDAV_LIST_COLOR             = 1 << 8
+       E_WEBDAV_LIST_COLOR             = 1 << 8,
+       E_WEBDAV_LIST_ONLY_CALENDAR     = 1 << 9,
+       E_WEBDAV_LIST_ONLY_ADDRESSBOOK  = 1 << 10
 } EWebDAVListFlags;
 
 /**
diff --git a/src/libedataserverui/e-webdav-discover-widget.c b/src/libedataserverui/e-webdav-discover-widget.c
index 73c2a6f49..83444d2db 100644
--- a/src/libedataserverui/e-webdav-discover-widget.c
+++ b/src/libedataserverui/e-webdav-discover-widget.c
@@ -581,6 +581,7 @@ typedef struct _RefreshData {
        gchar *base_url;
        ENamedParameters *credentials;
        ESourceRegistry *registry;
+       guint32 supports_filter;
 } RefreshData;
 
 static void
@@ -642,7 +643,7 @@ e_webdav_discover_content_trust_prompt_done_cb (GObject *source_object,
                refresh_data_free (rd);
        } else if (response == E_TRUST_PROMPT_RESPONSE_ACCEPT || response == 
E_TRUST_PROMPT_RESPONSE_ACCEPT_TEMPORARILY) {
                /* Use NULL credentials to reuse those from the last time. */
-               e_webdav_discover_sources_full (source, rd->base_url, E_WEBDAV_DISCOVER_SUPPORTS_NONE, 
rd->credentials,
+               e_webdav_discover_sources_full (source, rd->base_url, rd->supports_filter, rd->credentials,
                        rd->registry ? (EWebDAVDiscoverRefSourceFunc) e_source_registry_ref_source : NULL, 
rd->registry,
                        rd->cancellable, e_webdav_discover_content_refresh_done_cb, rd);
        } else {
@@ -689,7 +690,7 @@ e_webdav_discover_content_credentials_prompt_done_cb (GObject *source_object,
                        e_source_authentication_set_user (auth_extension, e_named_parameters_get 
(rd->credentials, E_SOURCE_CREDENTIAL_USERNAME));
                }
 
-               e_webdav_discover_sources_full (source, rd->base_url, E_WEBDAV_DISCOVER_SUPPORTS_NONE, 
rd->credentials,
+               e_webdav_discover_sources_full (source, rd->base_url, rd->supports_filter, rd->credentials,
                        rd->registry ? (EWebDAVDiscoverRefSourceFunc) e_source_registry_ref_source : NULL, 
rd->registry,
                        rd->cancellable, e_webdav_discover_content_refresh_done_cb, rd);
        }
@@ -849,6 +850,7 @@ e_webdav_discover_content_refresh (GtkWidget *content,
        rd->base_url = g_strdup (data->base_url);
        rd->credentials = NULL;
        rd->registry = e_credentials_prompter_get_registry (data->credentials_prompter);
+       rd->supports_filter = data->supports_filter;
 
        if (rd->registry)
                g_object_ref (rd->registry);
@@ -896,7 +898,7 @@ e_webdav_discover_content_refresh (GtkWidget *content,
 
        gtk_grid_attach (GTK_GRID (content), GTK_WIDGET (data->info_bar), 0, 2, 1, 1);
 
-       e_webdav_discover_sources_full (source, rd->base_url, E_WEBDAV_DISCOVER_SUPPORTS_NONE, 
rd->credentials,
+       e_webdav_discover_sources_full (source, rd->base_url, rd->supports_filter, rd->credentials,
                rd->registry ? (EWebDAVDiscoverRefSourceFunc) e_source_registry_ref_source : NULL, 
rd->registry,
                rd->cancellable, e_webdav_discover_content_refresh_done_cb, rd);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]