[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [RFC,PATCH] Port libsvn_auth_kwallet to KDE3.

From: Arfrever Frehtes Taifersar Arahesis <arfrever.fta_at_gmail.com>
Date: Thu, 4 Sep 2008 15:04:33 +0200

> Index: subversion/libsvn_auth_kwallet/kwallet.cpp
> ===================================================================
> --- subversion/libsvn_auth_kwallet/kwallet.cpp (revision 31484)
> +++ subversion/libsvn_auth_kwallet/kwallet.cpp (working copy)
> @@ -32,8 +32,14 @@
>
> #include "svn_private_config.h"
>
> +#ifdef SVN_HAVE_QT3
> +#include <qstring.h>
> +#include <qwidget.h>
> +#include <klocale.h>
> +#else
> #include <QtCore/QString>
> #include <QtGui/QWidget>
> +#endif
>
> #include <kapplication.h>
> #include <kcmdlineargs.h>
> @@ -44,16 +50,28 @@
> /* KWallet simple provider, puts passwords in KWallet */
> /*-----------------------------------------------------------------------*/
>
> -/* Implementation of svn_auth__password_get_t that retrieves
> - the password from KWallet. */
> -static svn_boolean_t
> -kwallet_password_get(const char **password,
> - apr_hash_t *creds,
> - const char *realmstring,
> - const char *username,
> - svn_boolean_t non_interactive,
> - apr_pool_t *pool)
> +class SvnKWallet
> {
> +public:
> + static svn_boolean_t init(svn_boolean_t non_interactive);
> + SvnKWallet(const char *realmstring, const char *username);
> + ~SvnKWallet();
> + svn_boolean_t get(const char **password, apr_pool_t *pool);
> + svn_boolean_t set(const char *password);
> +private:
> + bool open(bool check_key, bool create_wallet);
> +
> + KApplication application;

KApplication causes crashes in JavaHL.

> + QWidget widget;
> + WId wid;
> + KWallet::Wallet *wallet;
> + QString wallet_name;
> + QString folder;
> + QString key;
> +};
> +
> +svn_boolean_t SvnKWallet::init( svn_boolean_t non_interactive )
> +{
> if (non_interactive)
> {
> return FALSE;
> @@ -64,51 +82,107 @@
> return FALSE;
> }
>
> + char kdearg0[] = "svn";
> + char *kdeargs[1] = { kdearg0 };
> +#ifdef SVN_HAVE_QT3
> KCmdLineArgs::init(1,
> - (char *[1]) { "svn" },
> + kdeargs,
> "Subversion",
> "subversion",
> + i18n("Version control system"),
> + SVN_VER_NUMBER,
> + true);
> +#else
> + KCmdLineArgs::init(1,
> + kdeargs,
> + "Subversion",
> + "subversion",
> ki18n("Subversion"),
> SVN_VER_NUMBER,
> ki18n("Version control system"),
> KCmdLineArgs::CmdLineArgKDE);
> - KApplication application;
> - QWidget widget;
> - WId wid = widget.winId();
> - svn_boolean_t ret = FALSE;
> - QString wallet_name = KWallet::Wallet::NetworkWallet();
> - QString folder = QString::fromUtf8("Subversion");
> - QString key =
> - QString::fromUtf8(username) + "@" + QString::fromUtf8(realmstring);
> - if (! KWallet::Wallet::keyDoesNotExist(wallet_name, folder, key))
> - {
> - KWallet::Wallet *wallet =
> - KWallet::Wallet::openWallet(wallet_name,
> - wid,
> - KWallet::Wallet::Synchronous);
> - if (wallet)
> - {
> - if (wallet->hasFolder(folder))
> - {
> - if (wallet->setFolder(folder))
> - {
> - QString q_password;
> - if (wallet->readPassword(key, q_password) == 0);
> - {
> - *password = apr_pstrmemdup(pool,
> - q_password.toUtf8().data(),
> - q_password.size());
> - ret = TRUE;
> - }
> - }
> - }
> - }
> - }
> +#endif
> + return TRUE;
> +}
> +
> +SvnKWallet::SvnKWallet(const char *realmstring, const char *username)
> + : wallet(0)
> +{
> + wallet_name = KWallet::Wallet::NetworkWallet();
> + folder = QString::fromUtf8("Subversion");
> + key = QString::fromUtf8(username) + "@" + QString::fromUtf8(realmstring);
> +}
> +
> +SvnKWallet::~SvnKWallet()
> +{
> // KWallet::Wallet::disconnectApplication(wallet_name,
> // QString::fromUtf8("Subversion"));
> - return ret;
> + delete wallet;
> }
>
> +svn_boolean_t SvnKWallet::get(const char **password, apr_pool_t *pool)
> +{
> + if (!open(true, false))
> + return FALSE;
> + QString q_password;
> + if (wallet->readPassword(key, q_password) != 0)
> + return FALSE;
> +#ifdef SVN_HAVE_QT3
> + *password = apr_pstrmemdup(pool,
> + q_password.utf8().data(),
> + q_password.length());
> +#else
> + *password = apr_pstrmemdup(pool,
> + q_password.toUtf8().data(),
> + q_password.size());
> +#endif
> + return TRUE;
> +}
> +
> +svn_boolean_t SvnKWallet::set(const char *password)
> +{
> + if (!open(false, true))
> + return FALSE;
> + QString q_password = QString::fromUtf8(password);
> + if (wallet->writePassword(key, q_password) != 0)
> + return FALSE;
> + return TRUE;
> +}
> +
> +bool SvnKWallet::open(bool check_key, bool create_wallet)
> +{
> + if (check_key && KWallet::Wallet::keyDoesNotExist(wallet_name, folder, key))
> + return false;
> + wallet = KWallet::Wallet::openWallet(wallet_name,
> + wid,
> + KWallet::Wallet::Synchronous);
> + if (!wallet)
> + return false;
> + if (!wallet->hasFolder(folder))
> + {
> + if (!create_wallet)
> + return false;
> + if (!wallet->createFolder(folder))
> + return false;
> + }
> + return wallet->setFolder(folder);
> +}
> +
> +/* Implementation of svn_auth__password_get_t that retrieves
> + the password from KWallet. */
> +static svn_boolean_t
> +kwallet_password_get(const char **password,
> + apr_hash_t *creds,
> + const char *realmstring,
> + const char *username,
> + svn_boolean_t non_interactive,
> + apr_pool_t *pool)
> +{
> + if (!SvnKWallet::init(non_interactive))
> + return FALSE;
> + return SvnKWallet(realmstring, username).get(password, pool);
> +}
> +
> /* Implementation of svn_auth__password_set_t that stores
> the password in KWallet. */
> static svn_boolean_t
> @@ -119,57 +193,9 @@
> svn_boolean_t non_interactive,
> apr_pool_t *pool)
> {
> - if (non_interactive)
> - {
> - return FALSE;
> - }
> -
> - if (! KWallet::Wallet::isEnabled())
> - {
> - return FALSE;
> - }
> -
> - KCmdLineArgs::init(1,
> - (char *[1]) { "svn" },
> - "Subversion",
> - "subversion",
> - ki18n("Subversion"),
> - SVN_VER_NUMBER,
> - ki18n("Version control system"),
> - KCmdLineArgs::CmdLineArgKDE);
> - KApplication application;
> - QWidget widget;
> - WId wid = widget.winId();
> - svn_boolean_t ret = FALSE;
> - QString q_password = QString::fromUtf8(password);
> - QString wallet_name = KWallet::Wallet::NetworkWallet();
> - QString folder = QString::fromUtf8("Subversion");
> - KWallet::Wallet *wallet =
> - KWallet::Wallet::openWallet(wallet_name,
> - wid,
> - KWallet::Wallet::Synchronous);
> - if (wallet)
> - {
> - if (! wallet->hasFolder(folder))
> - {
> - wallet->createFolder(folder);
> - }
> - if (wallet->hasFolder(folder))
> - {
> - if (wallet->setFolder(folder))
> - {
> - QString key = QString::fromUtf8(username) + "@"
> - + QString::fromUtf8(realmstring);
> - if (wallet->writePassword(key, q_password) == 0)
> - {
> - ret = TRUE;
> - }
> - }
> - }
> - }
> -// KWallet::Wallet::disconnectApplication(wallet_name,
> -// QString::fromUtf8("Subversion"));
> - return ret;
> + if (!SvnKWallet::init(non_interactive))
> + return FALSE;
> + return SvnKWallet(realmstring, username).set(password);
> }
>
> /* Get cached encrypted credentials from the simple provider's cache. */

-- 
Arfrever Frehtes Taifersar Arahesis

Received on 2008-09-04 15:09:14 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.