Fix some file header comments.
[platform/upstream/evolution-data-server.git] / services / evolution-source-registry / evolution-source-registry-migrate-sources.c
index cabc692..9f3f677 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * migrate-from-gconf.c
+ * evolution-source-registry-migrate-sources.c
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #include <glib/gstdio.h>
 #include <camel/camel.h>
 #include <libsoup/soup.h>
-#include <gnome-keyring.h>
+
+/* XXX Yeah, yeah... */
+#define SECRET_API_SUBJECT_TO_CHANGE
+
+#include <libsecret/secret.h>
 
 #include <libebackend/libebackend.h>
 
@@ -137,15 +141,29 @@ struct _ParseData {
        PropertyFunc property_func;
 };
 
-static GnomeKeyringPasswordSchema schema = {
-       GNOME_KEYRING_ITEM_GENERIC_SECRET,
+/* XXX Probably want to share this with module-online-accounts.c */
+static const SecretSchema schema = {
+       "org.gnome.Evolution.DataSource",
+       SECRET_SCHEMA_DONT_MATCH_NAME,
        {
                { KEYRING_ITEM_ATTRIBUTE_NAME,
-                 GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+                 SECRET_SCHEMA_ATTRIBUTE_STRING },
                { NULL, 0 }
        }
 };
 
+/* XXX Probably want to share this with e-passwords.c */
+static const SecretSchema e_passwords_schema = {
+       "org.gnome.Evolution.Password",
+       SECRET_SCHEMA_DONT_MATCH_NAME,
+       {
+               { "application", SECRET_SCHEMA_ATTRIBUTE_STRING, },
+               { "user", SECRET_SCHEMA_ATTRIBUTE_STRING, },
+               { "server", SECRET_SCHEMA_ATTRIBUTE_STRING, },
+               { "protocol", SECRET_SCHEMA_ATTRIBUTE_STRING, },
+       }
+};
+
 /* Forward Declarations */
 void evolution_source_registry_migrate_sources (void);
 
@@ -252,47 +270,54 @@ migrate_keyring_entry (const gchar *uid,
                        const gchar *server,
                        const gchar *protocol)
 {
-       GnomeKeyringAttributeList *attributes;
+       GHashTable *attributes;
        GList *found_list = NULL;
        gchar *display_name;
 
+       /* Don't migrate entries with empty attributes */
+       if (!user || !server || !protocol) {
+             return;
+       }
+
        /* This is a best-effort routine, so we don't really care about
         * errors.  We leave the old keyring entry in place since it may
         * be reused for address book or calendar migration. */
 
        display_name = g_strdup_printf (KEYRING_ITEM_DISPLAY_FORMAT, uid);
 
-       attributes = gnome_keyring_attribute_list_new ();
-
-       gnome_keyring_attribute_list_append_string (
-               attributes, "application", "Evolution");
-       if (user != NULL)
-               gnome_keyring_attribute_list_append_string (
-                       attributes, "user", user);
-       if (server != NULL)
-               gnome_keyring_attribute_list_append_string (
-                       attributes, "server", server);
-       if (protocol != NULL)
-               gnome_keyring_attribute_list_append_string (
-                       attributes, "protocol", protocol);
-
-       gnome_keyring_find_items_sync (
-               GNOME_KEYRING_ITEM_NETWORK_PASSWORD, attributes, &found_list);
+       attributes = secret_attributes_build (
+               &e_passwords_schema,
+               "application", "Evolution",
+               "user", user,
+               "server", server,
+               "protocol", protocol,
+               NULL);
+
+       found_list = secret_service_search_sync (
+               NULL, &e_passwords_schema, attributes,
+               SECRET_SEARCH_ALL |
+               SECRET_SEARCH_UNLOCK |
+               SECRET_SEARCH_LOAD_SECRETS,
+               NULL, NULL);
 
        /* Pick the first match we find. */
        if (found_list != NULL) {
-               GnomeKeyringFound *found = found_list->data;
+               SecretItem *item = found_list->data;
+               SecretValue *secret = secret_item_get_secret (item);
 
                /* Sanity check. */
-               g_return_if_fail (found->secret != NULL);
+               g_return_if_fail (secret != NULL);
 
-               gnome_keyring_store_password_sync (
-                       &schema, GNOME_KEYRING_DEFAULT, display_name,
-                       found->secret, KEYRING_ITEM_ATTRIBUTE_NAME, uid, NULL);
+               secret_password_store_sync (
+                       &schema, SECRET_COLLECTION_DEFAULT, display_name,
+                       secret_value_get (secret, NULL), NULL, NULL,
+                       KEYRING_ITEM_ATTRIBUTE_NAME, uid, NULL);
+
+               secret_value_unref (secret);
        }
 
-       gnome_keyring_attribute_list_free (attributes);
-       gnome_keyring_found_list_free (found_list);
+       g_list_free_full (found_list, g_object_unref);
+       g_hash_table_unref (attributes);
 
        g_free (display_name);
 }
@@ -1024,6 +1049,25 @@ migrate_parse_url_rename_params (CamelURL *url)
                g_datalist_set_data_full (&url->params, key, value, g_free);
        }
 
+       /* missing "security-method" means STARTTLS, as it was the default value in 3.4- */
+       if (!g_datalist_get_data (&url->params, "security-method")) {
+               GEnumClass *enum_class;
+               GEnumValue *enum_value;
+               gchar *value = NULL;
+
+               enum_class = g_type_class_ref (CAMEL_TYPE_NETWORK_SECURITY_METHOD);
+               enum_value = g_enum_get_value (
+                       enum_class,
+                       CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT);
+               if (enum_value != NULL) {
+                       value = g_strdup (enum_value->value_nick);
+               } else
+                       g_warn_if_reached ();
+               g_type_class_unref (enum_class);
+
+               g_datalist_set_data_full (&url->params, "security-method", value, g_free);
+       }
+
        /* A few more adjustments...
         *
         * These are all CAMEL_PROVIDER_CONF_CHECKSPIN settings.  The spin
@@ -2254,6 +2298,12 @@ migrate_parse_caldav_source (ParseData *parse_data)
                        E_SOURCE_EXTENSION_WEBDAV_BACKEND,
                        "ResourcePath", parse_data->soup_uri->path);
 
+       if (parse_data->soup_uri->query != NULL)
+               g_key_file_set_string (
+                       parse_data->key_file,
+                       E_SOURCE_EXTENSION_WEBDAV_BACKEND,
+                       "ResourceQuery", parse_data->soup_uri->query);
+
        parse_data->property_func = migrate_parse_caldav_property;
 }
 
@@ -2502,6 +2552,12 @@ migrate_parse_webcal_source (ParseData *parse_data)
                        E_SOURCE_EXTENSION_WEBDAV_BACKEND,
                        "ResourcePath", parse_data->soup_uri->path);
 
+       if (parse_data->soup_uri->query != NULL)
+               g_key_file_set_string (
+                       parse_data->key_file,
+                       E_SOURCE_EXTENSION_WEBDAV_BACKEND,
+                       "ResourceQuery", parse_data->soup_uri->query);
+
        /* Webcal Backend has no special properties to parse. */
 }
 
@@ -2546,6 +2602,12 @@ migrate_parse_webdav_source (ParseData *parse_data)
                        E_SOURCE_EXTENSION_WEBDAV_BACKEND,
                        "ResourcePath", parse_data->soup_uri->path);
 
+       if (parse_data->soup_uri->query != NULL)
+               g_key_file_set_string (
+                       parse_data->key_file,
+                       E_SOURCE_EXTENSION_WEBDAV_BACKEND,
+                       "ResourceQuery", parse_data->soup_uri->query);
+
        parse_data->property_func = migrate_parse_webdav_property;
 }
 
@@ -3147,6 +3209,9 @@ migrate_parse_gconf_xml_start_element (GMarkupParseContext *context,
                        "mtime", NULL,
                        G_MARKUP_COLLECT_STRING |
                        G_MARKUP_COLLECT_OPTIONAL,
+                       "muser", NULL,
+                       G_MARKUP_COLLECT_STRING |
+                       G_MARKUP_COLLECT_OPTIONAL,
                        "type", NULL,
                        G_MARKUP_COLLECT_STRING |
                        G_MARKUP_COLLECT_OPTIONAL,