static void e_book_backend_vcf_load_source (EBookBackend *backend, ESource *source, gboolean only_if_exists, GError **perror) { EBookBackendVCF *bvcf = E_BOOK_BACKEND_VCF (backend); gchar *dirname; gboolean writable = FALSE; gchar *uri; gint fd; uri = e_source_get_uri (source); dirname = e_book_backend_vcf_extract_path_from_uri (uri); bvcf->priv->filename = g_build_filename (dirname, "addressbook.vcf", NULL); fd = g_open (bvcf->priv->filename, O_RDWR | O_BINARY, 0); bvcf->priv->contacts = g_hash_table_new_full ( g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) NULL); if (fd != -1) { writable = TRUE; } else { fd = g_open (bvcf->priv->filename, O_RDONLY | O_BINARY, 0); if (fd == -1 && !only_if_exists) { gint rv; /* the database didn't exist, so we create the directory then the .vcf file */ rv = g_mkdir_with_parents (dirname, 0700); if (rv == -1 && errno != EEXIST) { g_warning ("failed to make directory %s: %s", dirname, g_strerror (errno)); if (errno == EACCES || errno == EPERM) { g_propagate_error (perror, EDB_ERROR (PERMISSION_DENIED)); } else { g_propagate_error (perror, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Failed to make directory %s: %s", dirname, g_strerror (errno))); } return; } fd = g_open (bvcf->priv->filename, O_CREAT | O_BINARY, 0666); if (fd != -1) { #ifdef CREATE_DEFAULT_VCARD EContact *contact; contact = do_create (bvcf, XIMIAN_VCARD, FALSE); save_file (bvcf); /* XXX check errors here */ g_object_unref (contact); #endif writable = TRUE; } } } if (fd == -1) { g_warning ("Failed to open addressbook at uri `%s'", uri); g_warning ("error == %s", g_strerror(errno)); g_propagate_error (perror, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Failed to open addressbook at uri '%s': %s", uri, g_strerror (errno))); g_free (uri); return; } load_file (bvcf, fd); e_book_backend_set_is_loaded (backend, TRUE); e_book_backend_set_is_writable (backend, writable); g_free (uri); }
/* ************************************************************************* */ static GNOME_Evolution_Addressbook_CallStatus e_book_backend_scalix_load_source (EBookBackend * backend, ESource * source, gboolean only_if_exists) { EBookBackendScalix *bs; EBookBackendScalixPrivate *priv; ScalixContainer *container; const char *prop_ssl; gchar *uri; bs = E_BOOK_BACKEND_SCALIX (backend); priv = E_BOOK_BACKEND_SCALIX_GET_PRIVATE (bs); if (priv->container != NULL) { /* Source already loaded! */ return GNOME_Evolution_Addressbook_Success; } uri = e_source_get_uri (source); if ((prop_ssl = e_source_get_property (source, "use_ssl"))) { CamelURL *url; url = camel_url_new (uri, NULL); camel_url_set_param (url, "use_ssl", prop_ssl); g_free (uri); uri = camel_url_to_string (url, 0); } container = scalix_container_open (uri); g_free (uri); if (container == NULL) { return GNOME_Evolution_Addressbook_OtherError; } e_book_backend_set_is_loaded (E_BOOK_BACKEND (backend), TRUE); e_book_backend_set_is_writable (E_BOOK_BACKEND (backend), TRUE); if (only_if_exists == FALSE) { GLOG_CAT_DEBUG (&slbook, "Only if exists == FALSE"); g_object_set (container, "only_if_exists", FALSE, "type", "Contacts", NULL); } priv->container = container; // go online here? if (priv->mode == GNOME_Evolution_Addressbook_MODE_REMOTE) { go_online (bs); } g_signal_connect (container, "object_added", G_CALLBACK (container_object_added_cb), (gpointer) backend); g_signal_connect (container, "object_removed", G_CALLBACK (container_object_removed_cb), (gpointer) backend); g_signal_connect (container, "object_changed", G_CALLBACK (container_object_changed_cb), (gpointer) backend); return GNOME_Evolution_Addressbook_Success; }