[gnote] Migrate to libsecret
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Migrate to libsecret
- Date: Tue, 7 Aug 2012 18:30:00 +0000 (UTC)
commit ac0b5c04af3b5b862e13b6d1344d7b6502e4d3a0
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Tue Aug 7 21:26:57 2012 +0300
Migrate to libsecret
* Drop dependency on libgnome-keyring
* Depend on libsecret instead
configure.ac | 4 +-
data/org.gnome.gnote.gschema.xml.in | 10 ++
src/Makefile.am | 10 +-
src/addins/addins.mk.in | 2 +-
.../webdavsyncservice/webdavsyncserviceaddin.cpp | 54 ++-----
src/gnome_keyring/genericitemdata.cpp | 38 -----
src/gnome_keyring/genericitemdata.hpp | 52 -------
src/gnome_keyring/itemdata.cpp | 66 ---------
src/gnome_keyring/itemdata.hpp | 61 --------
src/gnome_keyring/keyringexception.cpp | 61 --------
src/gnome_keyring/keyringexception.hpp | 20 +--
src/gnome_keyring/netitemdata.cpp | 55 --------
src/gnome_keyring/netitemdata.hpp | 60 --------
src/gnome_keyring/noteitemdata.hpp | 48 -------
src/gnome_keyring/ring.cpp | 145 ++++++--------------
src/gnome_keyring/ring.hpp | 22 ++--
src/preferences.cpp | 2 +
src/preferences.hpp | 2 +
18 files changed, 92 insertions(+), 620 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0ea6a75..80ad23b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,7 @@ LIBGLIBMM_VERSION=2.28
LIBGTKMM_VERSION=3.4
GTKSPELL_VERSION=2.0.9
BOOST_VERSION=1.34
-GNOME_KEYRING_VERSION=3.0
+LIBSECRET_VERSION=0.8
AC_PROG_CXX
AC_GNU_SOURCE
@@ -89,7 +89,7 @@ AC_SUBST(GTKSPELL_LIBS)
AM_CONDITIONAL(FIXED_GTKSPELL, test "$FIXED_GTKSPELL" = "yes")
-PKG_CHECK_MODULES(GNOME_KEYRING, [gnome-keyring-1 >= $GNOME_KEYRING_VERSION])
+PKG_CHECK_MODULES(LIBSECRET, [libsecret-1 >= $LIBSECRET_VERSION])
diff --git a/data/org.gnome.gnote.gschema.xml.in b/data/org.gnome.gnote.gschema.xml.in
index 0bd9e30..7477f22 100644
--- a/data/org.gnome.gnote.gschema.xml.in
+++ b/data/org.gnome.gnote.gschema.xml.in
@@ -203,6 +203,16 @@
<_summary>Accept SSL Certificates</_summary>
<_description>Use wdfs option "-ac" to accept SSL certificates without prompting the user.</_description>
</key>
+ <key name="url" type="s">
+ <default>''</default>
+ <_summary>Share URL</_summary>
+ <_description>WebDAV share URL where notes are synchronized to.</_description>
+ </key>
+ <key name="username" type="s">
+ <default>''</default>
+ <_summary>Share username</_summary>
+ <_description>Username to access WebDAV share.</_description>
+ </key>
</schema>
<schema id="org.gnome.gnote.insert-timestamp" path="/org/gnome/gnote/insert-timestamp/">
<key name="format" type="s">
diff --git a/src/Makefile.am b/src/Makefile.am
index e43469c..995230a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,7 +8,7 @@ AM_CPPFLAGS= LIBGTKMM_CFLAGS@ @LIBGLIBMM_CFLAGS@ \
@GTKSPELL_CFLAGS@ @LIBXML_CFLAGS@ \
@LIBXSLT_CFLAGS@ \
@UUID_CFLAGS@ \
- @GNOME_KEYRING_CFLAGS@ \
+ @LIBSECRET_CFLAGS@ \
-DGNOTE_LOCALEDIR=\"@GNOTE_LOCALEDIR \" \
-DDATADIR=\"$(datadir)\" -DLIBDIR=\"$(libdir)\"
@@ -19,7 +19,7 @@ LIBGNOTE_LIBS = $(top_builddir)/libtomboy/libtomboy.la \
@LIBXSLT_LIBS@ \
@GTKSPELL_LIBS@ @GTK_LIBS@ \
@UUID_LIBS@ \
- @GNOME_KEYRING_LIBS@
+ @LIBSECRET_LIBS@
GNOTE_LIBS = libgnote.la $(LIBGNOTE_LIBS)
lib_LTLIBRARIES = libgnote.la
@@ -70,11 +70,7 @@ libgnote_la_SOURCES = \
base/singleton.hpp \
base/macros.hpp \
base/inifile.hpp base/inifile.cpp \
- gnome_keyring/genericitemdata.hpp gnome_keyring/genericitemdata.cpp \
- gnome_keyring/itemdata.hpp gnome_keyring/itemdata.cpp \
- gnome_keyring/netitemdata.hpp gnome_keyring/netitemdata.cpp \
- gnome_keyring/noteitemdata.hpp \
- gnome_keyring/keyringexception.hpp gnome_keyring/keyringexception.cpp \
+ gnome_keyring/keyringexception.hpp \
gnome_keyring/ring.hpp gnome_keyring/ring.cpp \
sharp/addinstreemodel.hpp sharp/addinstreemodel.cpp \
sharp/datetime.hpp sharp/datetime.cpp \
diff --git a/src/addins/addins.mk.in b/src/addins/addins.mk.in
index b6ec513..a524341 100644
--- a/src/addins/addins.mk.in
+++ b/src/addins/addins.mk.in
@@ -5,7 +5,7 @@ INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
AM_CPPFLAGS= LIBGTKMM_CFLAGS@ @LIBGLIBMM_CFLAGS@ \
@LIBXML_CFLAGS@ \
- @GNOME_KEYRING_CFLAGS@ \
+ @LIBSECRET_CFLAGS@ \
-DDATADIR=\"$(datadir)\" -DLIBDIR=\"$(libdir)\"
AM_LDFLAGS = -avoid-version -module -export-dynamic
diff --git a/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp b/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
index 1e6bba5..e5107bb 100644
--- a/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
+++ b/src/addins/webdavsyncservice/webdavsyncserviceaddin.cpp
@@ -30,9 +30,9 @@
#include "synchronization/syncmanager.hpp"
-using gnome::keyring::ItemData;
using gnome::keyring::KeyringException;
using gnome::keyring::Ring;
+using gnote::Preferences;
namespace webdavsyncserviceaddin {
@@ -243,33 +243,22 @@ std::vector<std::string> WebDavSyncServiceAddin::get_fuse_mount_exe_args(const s
bool WebDavSyncServiceAddin::get_config_settings(std::string & url, std::string & username, std::string & password)
{
- // Retrieve configuration from the GNOME Keyring
+ // Retrieve configuration from the GNOME Keyring and GSettings
url = "";
username = "";
password = "";
try {
- std::vector<ItemData::Ptr> data = Ring::find(gnome::keyring::NETWORK_PASSWORD, s_request_attributes);
- for(std::vector<ItemData::Ptr>::iterator iter = data.begin(); iter != data.end(); ++iter) {
- ItemData::Ptr result = *iter;
- if(result->attributes["name"] != KEYRING_ITEM_NAME) {
- continue;
- }
-
- username = sharp::string_trim(result->attributes["user"]);
- url = sharp::string_trim(result->attributes["url"]);
- password = sharp::string_trim(result->secret);
+ password = sharp::string_trim(Ring::find_password(s_request_attributes));
+ if(password != "") {
+ Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
+ .get_schema_settings(Preferences::SCHEMA_SYNC_WDFS);
+ username = sharp::string_trim(settings->get_string(Preferences::SYNC_FUSE_WDFS_USERNAME));
+ url = sharp::string_trim(settings->get_string(Preferences::SYNC_FUSE_WDFS_URL));
}
}
catch(KeyringException & ke) {
DBG_OUT("Getting configuration from the GNOME keyring failed with the following message: %s", ke.what());
- // TODO: If the following fails, retrieve all but password from GConf,
- // and prompt user for password. (some password caching would be nice, too)
- // Retrieve configuration from GConf
- //url = Preferences.Get ("/apps/tomboy/sync_wdfs_url") as String;
- //username = Preferences.Get ("/apps/tomboy/sync_wdfs_username") as String;
- //password = null; // TODO: Prompt user for password
- //throw;
}
return url != "" && username != "" && password != "";
@@ -277,24 +266,14 @@ bool WebDavSyncServiceAddin::get_config_settings(std::string & url, std::string
void WebDavSyncServiceAddin::save_config_settings(const std::string & url, const std::string & username, const std::string & password)
{
- // Save configuration into the GNOME Keyring
+ // Save configuration into the GNOME Keyring and GSettings
try {
- std::map<std::string, std::string> update_request_attributes = s_request_attributes;
- update_request_attributes["user"] = username;
- update_request_attributes["url"] = url;
+ Glib::RefPtr<Gio::Settings> settings = Preferences::obj()
+ .get_schema_settings(Preferences::SCHEMA_SYNC_WDFS);
+ settings->set_string(Preferences::SYNC_FUSE_WDFS_USERNAME, username);
+ settings->set_string(Preferences::SYNC_FUSE_WDFS_URL, url);
- std::vector<ItemData::Ptr> items = Ring::find(gnome::keyring::NETWORK_PASSWORD, s_request_attributes);
- std::string keyring = Ring::default_keyring();
-
- if(items.size() == 0) {
- Ring::create_item(keyring, gnome::keyring::NETWORK_PASSWORD, KEYRING_ITEM_NAME,
- update_request_attributes, password, true);
- }
- else {
- Ring::set_item_info(keyring, items[0]->item_id, gnome::keyring::NETWORK_PASSWORD,
- KEYRING_ITEM_NAME, password);
- Ring::set_item_attributes(keyring, items[0]->item_id, update_request_attributes);
- }
+ Ring::create_password(Ring::default_keyring(), KEYRING_ITEM_NAME, s_request_attributes, password);
}
catch(KeyringException & ke) {
DBG_OUT("Saving configuration to the GNOME keyring failed with the following message: %s", ke.what());
@@ -320,9 +299,8 @@ bool WebDavSyncServiceAddin::get_pref_widget_settings(std::string & url, std::st
bool WebDavSyncServiceAddin::accept_ssl_cert()
{
try {
- return gnote::Preferences::obj()
- .get_schema_settings(gnote::Preferences::SCHEMA_SYNC_WDFS)->get_boolean(
- gnote::Preferences::SYNC_FUSE_WDFS_ACCEPT_SSLCERT);
+ return Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC_WDFS)->get_boolean(
+ Preferences::SYNC_FUSE_WDFS_ACCEPT_SSLCERT);
}
catch(...) {
return false;
diff --git a/src/gnome_keyring/keyringexception.hpp b/src/gnome_keyring/keyringexception.hpp
index eade27a..4d877d5 100644
--- a/src/gnome_keyring/keyringexception.hpp
+++ b/src/gnome_keyring/keyringexception.hpp
@@ -23,8 +23,6 @@
#include <stdexcept>
-#include <gnome-keyring.h>
-
namespace gnome {
@@ -34,20 +32,16 @@ class KeyringException
: public std::exception
{
public:
- KeyringException(GnomeKeyringResult);
- GnomeKeyringResult result() const
- {
- return m_result;
- }
- virtual const char * what() const throw()
+ KeyringException(const std::string & msg)
+ : m_what(msg)
+ {}
+ virtual ~KeyringException() throw() {}
+ virtual const char *what() const throw()
{
- return m_what;
+ return m_what.c_str();
}
private:
- static const char * get_msg(GnomeKeyringResult);
-
- GnomeKeyringResult m_result;
- const char * m_what;
+ std::string m_what;
};
}
diff --git a/src/gnome_keyring/ring.cpp b/src/gnome_keyring/ring.cpp
index d44e9e5..63538c6 100644
--- a/src/gnome_keyring/ring.cpp
+++ b/src/gnome_keyring/ring.cpp
@@ -28,130 +28,65 @@
namespace gnome {
namespace keyring {
-std::vector<ItemData::Ptr> Ring::find(ItemType type, const std::map<std::string, std::string> & atts)
-{
- std::vector<ItemData::Ptr> res;
- GList *list = NULL;
- GnomeKeyringAttributeList *attributes = keyring_attributes(atts);
- GnomeKeyringResult result = gnome_keyring_find_items_sync(keyring_item_type(type), attributes, &list);
- gnome_keyring_attribute_list_free(attributes);
- if(result == GNOME_KEYRING_RESULT_OK) {
- for(GList *item = g_list_first(list); item; item = g_list_next(item)) {
- GnomeKeyringFound *found_item = static_cast<GnomeKeyringFound*>(item->data);
- ItemData::Ptr item_data = ItemData::get_instance_from_item_type(type);
- item_data->keyring = found_item->keyring;
- item_data->item_id = found_item->item_id;
- item_data->secret = found_item->secret;
- transfer_attributes(item_data, found_item);
- res.push_back(item_data);
- }
- gnome_keyring_found_list_free(list);
- }
- else if(result != GNOME_KEYRING_RESULT_NO_MATCH) {
- throw KeyringException(result);
- }
-
- return res;
-}
-
-GnomeKeyringItemType Ring::keyring_item_type(ItemType type)
-{
- switch(type) {
- case GENERIC_SECRET:
- return GNOME_KEYRING_ITEM_GENERIC_SECRET;
- case NETWORK_PASSWORD:
- return GNOME_KEYRING_ITEM_NETWORK_PASSWORD;
- case NOTE:
- default:
- return GNOME_KEYRING_ITEM_NOTE;
- }
-}
-GnomeKeyringAttributeList *Ring::keyring_attributes(const std::map<std::string, std::string> & atts)
-{
- GnomeKeyringAttributeList *list = gnome_keyring_attribute_list_new();
- for(std::map<std::string, std::string>::const_iterator iter = atts.begin(); iter != atts.end(); ++iter) {
- gnome_keyring_attribute_list_append_string(list, iter->first.c_str(), iter->second.c_str());
+SecretSchema Ring::s_schema = {
+ "org.gnome.Gnote.Password", SECRET_SCHEMA_NONE,
+ {
+ {"name", SECRET_SCHEMA_ATTRIBUTE_STRING},
}
- return list;
-}
+};
-void Ring::transfer_attributes(ItemData::Ptr item_data, GnomeKeyringFound *found_item)
-{
- if(!found_item->attributes) {
- return;
- }
- for(unsigned i = 0; i < found_item->attributes->len; ++i) {
- GnomeKeyringAttribute att = g_array_index(found_item->attributes, GnomeKeyringAttribute, i);
- std::string value = att.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING
- ? att.value.string
- : boost::lexical_cast<std::string>(att.value.integer);
- item_data->attributes[att.name] = value;
- }
-}
-std::string Ring::default_keyring()
+std::string Ring::find_password(const std::map<std::string, std::string> & atts)
{
- char *keyring = NULL;
- GnomeKeyringResult result = gnome_keyring_get_default_keyring_sync(&keyring);
- if(result == GNOME_KEYRING_RESULT_OK) {
- std::string res;
- if(keyring) {
- res = keyring;
- g_free(keyring);
- }
- return res;
+ GList *list = NULL;
+ GHashTable *attributes = keyring_attributes(atts);
+ GError *error = NULL;
+ gchar *result = secret_password_lookupv_sync(&s_schema, attributes, NULL, &error);
+ g_hash_table_unref(attributes);
+ if(error) {
+ KeyringException e(error->message);
+ g_error_free(error);
+ throw e;
}
- throw KeyringException(result);
-}
-int Ring::create_item(const std::string & keyring, ItemType type, const std::string & displayName,
- const std::map<std::string, std::string> & attributes,
- const std::string & secret, bool updateIfExists)
-{
- GnomeKeyringAttributeList *atts = keyring_attributes(attributes);
- guint32 item_id = 0;
- GnomeKeyringResult result = gnome_keyring_item_create_sync(keyring_c_str(keyring), keyring_item_type(type),
- displayName.c_str(), atts, secret.c_str(),
- updateIfExists ? TRUE : FALSE, &item_id);
- gnome_keyring_attribute_list_free(atts);
- if(result == GNOME_KEYRING_RESULT_OK) {
- return item_id;
+ std::string res;
+ if(result) {
+ res = result;
+ secret_password_free(result);
}
- throw KeyringException(result);
+ return res;
}
-void Ring::set_item_info(const std::string & keyring, int id, ItemType type,
- const std::string & displayName, const std::string & secret)
+std::string Ring::default_keyring()
{
- GnomeKeyringItemInfo *info = gnome_keyring_item_info_new();
- gnome_keyring_item_info_set_type(info, keyring_item_type(type));
- gnome_keyring_item_info_set_display_name(info, displayName.c_str());
- gnome_keyring_item_info_set_secret(info, secret.c_str());
- GnomeKeyringResult result = gnome_keyring_item_set_info_sync(keyring_c_str(keyring), id, info);
- gnome_keyring_item_info_free(info);
- if(result != GNOME_KEYRING_RESULT_OK) {
- throw KeyringException(result);
- }
+ return SECRET_COLLECTION_DEFAULT;
}
-void Ring::set_item_attributes(const std::string & keyring, int id, const std::map<std::string, std::string> & atts)
+void Ring::create_password(const std::string & keyring, const std::string & displayName,
+ const std::map<std::string, std::string> & attributes,
+ const std::string & secret)
{
- GnomeKeyringAttributeList *attributes = keyring_attributes(atts);
- GnomeKeyringResult result = gnome_keyring_item_set_attributes_sync(keyring_c_str(keyring), id, attributes);
- gnome_keyring_attribute_list_free(attributes);
- if(result != GNOME_KEYRING_RESULT_OK) {
- throw KeyringException(result);
+ GHashTable *atts = keyring_attributes(attributes);
+ GError *error = NULL;
+ secret_password_storev_sync(&s_schema, atts, keyring.c_str(), displayName.c_str(),
+ secret.c_str(), NULL, &error);
+ g_hash_table_unref(atts);
+ if(error) {
+ KeyringException e(error->message);
+ g_error_free(error);
+ throw e;
}
}
-const char * Ring::keyring_c_str(const std::string & keyring)
+GHashTable *Ring::keyring_attributes(const std::map<std::string, std::string> & atts)
{
- const char *key_ring = NULL;
- if(keyring != "") {
- key_ring = keyring.c_str();
+ GHashTable *result = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
+ for(std::map<std::string, std::string>::const_iterator iter = atts.begin();
+ iter != atts.end(); ++iter) {
+ g_hash_table_insert(result, strdup(iter->first.c_str()), strdup(iter->second.c_str()));
}
- return key_ring;
+ return result;
}
}
diff --git a/src/gnome_keyring/ring.hpp b/src/gnome_keyring/ring.hpp
index e42f8a0..2caf5f4 100644
--- a/src/gnome_keyring/ring.hpp
+++ b/src/gnome_keyring/ring.hpp
@@ -22,10 +22,10 @@
#define _GNOME_KEYRING_RING_HPP_
#include <vector>
+#include <map>
-#include <gnome-keyring.h>
+#include <libsecret/secret.h>
-#include "itemdata.hpp"
namespace gnome {
@@ -34,19 +34,15 @@ namespace keyring {
class Ring
{
public:
- static std::vector<ItemData::Ptr> find(ItemType type, const std::map<std::string, std::string> & atts);
+ static std::string find_password(const std::map<std::string, std::string> & atts);
static std::string default_keyring();
- static int create_item(const std::string & keyring, ItemType type, const std::string & displayName,
- const std::map<std::string, std::string> & attributes,
- const std::string & secret, bool updateIfExists);
- static void set_item_info(const std::string & keyring, int id, ItemType type,
- const std::string & displayName, const std::string & secret);
- static void set_item_attributes(const std::string & keyring, int id, const std::map<std::string, std::string> & atts);
+ static void create_password(const std::string & keyring, const std::string & displayName,
+ const std::map<std::string, std::string> & attributes,
+ const std::string & secret);
private:
- static GnomeKeyringItemType keyring_item_type(ItemType type);
- static GnomeKeyringAttributeList *keyring_attributes(const std::map<std::string, std::string> & atts);
- static void transfer_attributes(ItemData::Ptr, GnomeKeyringFound*);
- static const char * keyring_c_str(const std::string &);
+ static GHashTable *keyring_attributes(const std::map<std::string, std::string> & atts);
+
+ static SecretSchema s_schema;
};
}
diff --git a/src/preferences.cpp b/src/preferences.cpp
index b881c2c..e7e5753 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -70,6 +70,8 @@ namespace gnote {
const char * Preferences::SYNC_FUSE_MOUNT_TIMEOUT = "sync-fuse-mount-timeout-ms";
const char * Preferences::SYNC_FUSE_WDFS_ACCEPT_SSLCERT = "accept-sslcert";
+ const char * Preferences::SYNC_FUSE_WDFS_URL = "url";
+ const char * Preferences::SYNC_FUSE_WDFS_USERNAME = "username";
const char * Preferences::DESKTOP_GNOME_FONT = "document-font-name";
const char * Preferences::DESKTOP_GNOME_KEY_THEME = "gtk-key-theme";
diff --git a/src/preferences.hpp b/src/preferences.hpp
index cbd5f76..04448f4 100644
--- a/src/preferences.hpp
+++ b/src/preferences.hpp
@@ -80,6 +80,8 @@ namespace gnote {
static const char *SYNC_FUSE_MOUNT_TIMEOUT;
static const char *SYNC_FUSE_WDFS_ACCEPT_SSLCERT;
+ static const char *SYNC_FUSE_WDFS_URL;
+ static const char *SYNC_FUSE_WDFS_USERNAME;
static const char *DESKTOP_GNOME_FONT;
static const char *DESKTOP_GNOME_KEY_THEME;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]