Proceed proxy settings to csync thread.

This commit is contained in:
Klaas Freitag 2012-08-02 11:17:15 +03:00
parent eb2d93de38
commit d3bb223898
3 changed files with 73 additions and 6 deletions

View file

@ -29,10 +29,25 @@ namespace Mirall {
/* static variables to hold the credentials */
QString CSyncThread::_user;
QString CSyncThread::_passwd;
QString CSyncThread::_proxyType;
QString CSyncThread::_proxyPwd;
QString CSyncThread::_proxyPort;
QString CSyncThread::_proxyHost;
QString CSyncThread::_proxyUser;
QString CSyncThread::_csyncConfigDir; // to be able to remove the lock file.
QMutex CSyncThread::_mutex;
struct ProxyInfo {
char *proxyType;
char *proxyHost;
char *proxyPort;
char *proxyUser;
char *proxyPwd;
};
int CSyncThread::checkPermissions( TREE_WALK_FILE* file, void *data )
{
WalkStats *wStats = static_cast<WalkStats*>(data);
@ -122,7 +137,6 @@ CSyncThread::~CSyncThread()
void CSyncThread::run()
{
CSYNC *csync;
WalkStats *wStats = new WalkStats;
QTime walkTime;
@ -137,9 +151,16 @@ void CSyncThread::run()
wStats->seenFiles = 0;
wStats->conflicts = 0;
wStats->error = 0;
const char *statedb = 0;
ProxyInfo *proxyInfo = new ProxyInfo;
_mutex.lock();
proxyInfo->proxyType = qstrdup( _proxyType.toAscii().constData() );
proxyInfo->proxyHost = qstrdup( _proxyHost.toAscii().constData() );
proxyInfo->proxyPort = qstrdup( _proxyPort.toAscii().constData() );
proxyInfo->proxyUser = qstrdup( _proxyUser.toAscii().constData() );
proxyInfo->proxyPwd = qstrdup( _proxyPwd.toAscii().constData() );
if( csync_create(&csync,
_source.toUtf8().data(),
_target.toUtf8().data()) < 0 ) {
@ -170,6 +191,7 @@ void CSyncThread::run()
if( _localCheckOnly ) {
csync_set_local_only( csync, true );
}
csync_set_userdata(csync, (void*) proxyInfo);
_mutex.unlock();
if( csync_init(csync) < 0 ) {
@ -223,7 +245,7 @@ void CSyncThread::run()
qDebug() << "############################################################### >>";
if( csync_update(csync) < 0 ) {
emit csyncError(tr("CSync Update failed."));
emit csyncError(tr("CSync Update failed wiht errno."));
goto cleanup;
}
qDebug() << "<<###############################################################";
@ -272,6 +294,15 @@ void CSyncThread::run()
}
cleanup:
csync_destroy(csync);
if( proxyInfo->proxyType ) free( proxyInfo->proxyType );
if( proxyInfo->proxyHost ) free( proxyInfo->proxyHost );
if( proxyInfo->proxyPort ) free( proxyInfo->proxyPort );
if( proxyInfo->proxyUser ) free( proxyInfo->proxyUser );
if( proxyInfo->proxyPwd ) free( proxyInfo->proxyPwd );
free( proxyInfo );
/*
* Attention: do not delete the wStat memory here. it is deleted in the
* slot catching the signel treeWalkResult because this thread can faster
@ -294,11 +325,18 @@ void CSyncThread::emitStateDb( CSYNC *csync )
}
}
void CSyncThread::setUserPwd( const QString& user, const QString& passwd )
void CSyncThread::setConnectionDetails( const QString& user, const QString& passwd,
const QString& proxyType, const QString& proxyHost,
int proxyPort , const QString& proxyUser, const QString& proxyPwd )
{
_mutex.lock();
_user = user;
_passwd = passwd;
_proxyType = proxyType;
_proxyHost = proxyHost;
_proxyPort = proxyPort;
_proxyUser = proxyUser;
_proxyPwd = proxyPwd;
_mutex.unlock();
}

View file

@ -62,7 +62,9 @@ public:
virtual void run();
static void setUserPwd( const QString&, const QString& );
static void setConnectionDetails( const QString&, const QString&,
const QString&, const QString&, int,
const QString&, const QString& );
static int checkPermissions( TREE_WALK_FILE* file, void *data);
static QString csyncConfigDir();
@ -87,6 +89,12 @@ private:
static QMutex _mutex;
static QString _user;
static QString _passwd;
static QString _proxyType;
static QString _proxyHost;
static QString _proxyPort;
static QString _proxyUser;
static QString _proxyPwd;
static QString _csyncConfigDir;
QString _source;

View file

@ -26,6 +26,7 @@
#include <QStringList>
#include <QTextStream>
#include <QTimer>
#include <QNetworkProxy>
namespace Mirall {
@ -141,8 +142,28 @@ void ownCloudFolder::startSync(const QStringList &pathList)
qDebug() << "*** Start syncing url to ownCloud: " << url.toString() << ", with localOnly: " << _localCheckOnly;
_csync = new CSyncThread( path(), url.toString(), _localCheckOnly );
_csync->setUserPwd( cfgFile.ownCloudUser(), cfgFile.ownCloudPasswd() );
// Proxy settings. Proceed them as strings to csync thread.
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
QString proxyType;
if( proxy.type() == QNetworkProxy::NoProxy )
proxyType = QLatin1String("NoProxy");
else if( proxy.type() == QNetworkProxy::DefaultProxy )
proxyType = QLatin1String("DefaultProxy");
else if( proxy.type() == QNetworkProxy::Socks5Proxy )
proxyType = QLatin1String("Socks5Proxy");
else if( proxy.type() == QNetworkProxy::HttpProxy )
proxyType = QLatin1String("HttpProxy");
else if( proxy.type() == QNetworkProxy::HttpCachingProxy )
proxyType = QLatin1String("HttpCachingProxy");
else if( proxy.type() == QNetworkProxy::FtpCachingProxy )
proxyType = QLatin1String("FtpCachingProxy");
_csync->setConnectionDetails( cfgFile.ownCloudUser(), cfgFile.ownCloudPasswd(), proxyType,
proxy.hostName(), proxy.port(), proxy.user(), proxy.password() );
QObject::connect(_csync, SIGNAL(started()), SLOT(slotCSyncStarted()));
QObject::connect(_csync, SIGNAL(finished()), SLOT(slotCSyncFinished()));
QObject::connect(_csync, SIGNAL(terminated()), SLOT(slotCSyncTerminated()));