2011-10-05 19:49:03 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2012-02-17 18:54:39 +04:00
|
|
|
#include "mirall/owncloudinfo.h"
|
|
|
|
#include "mirall/mirallconfigfile.h"
|
2012-03-14 13:02:52 +04:00
|
|
|
#include "mirall/version.h"
|
2012-04-12 13:37:48 +04:00
|
|
|
#include "mirall/sslerrordialog.h"
|
2011-10-05 19:49:03 +04:00
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
#include <QtCore>
|
|
|
|
#include <QtGui>
|
|
|
|
#include <QAuthenticator>
|
|
|
|
|
2012-04-21 01:58:09 +04:00
|
|
|
#if QT46_IMPL
|
|
|
|
#include <QHttp>
|
|
|
|
#endif
|
|
|
|
|
2011-10-05 19:49:03 +04:00
|
|
|
namespace Mirall
|
|
|
|
{
|
|
|
|
|
2012-07-26 12:16:18 +04:00
|
|
|
ownCloudInfo *ownCloudInfo::_instance = 0;
|
|
|
|
|
|
|
|
ownCloudInfo* ownCloudInfo::instance()
|
|
|
|
{
|
|
|
|
static QMutex mutex;
|
|
|
|
if (!_instance)
|
|
|
|
{
|
|
|
|
mutex.lock();
|
|
|
|
|
|
|
|
if (!_instance) {
|
|
|
|
_instance = new ownCloudInfo;
|
|
|
|
|
|
|
|
}
|
|
|
|
mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _instance;
|
|
|
|
}
|
2012-04-06 10:53:57 +04:00
|
|
|
|
2012-02-17 18:54:39 +04:00
|
|
|
ownCloudInfo::ownCloudInfo( const QString& connectionName, QObject *parent ) :
|
2012-04-06 10:53:57 +04:00
|
|
|
QObject(parent)
|
2011-10-05 19:49:03 +04:00
|
|
|
{
|
2012-02-17 18:54:39 +04:00
|
|
|
if( connectionName.isEmpty() )
|
2012-07-26 12:16:18 +04:00
|
|
|
_connection = QLatin1String( "ownCloud");
|
2012-02-17 18:54:39 +04:00
|
|
|
else
|
|
|
|
_connection = connectionName;
|
2012-03-16 18:16:45 +04:00
|
|
|
|
2012-07-26 12:16:18 +04:00
|
|
|
_manager = new QNetworkAccessManager;
|
2012-08-02 13:02:46 +04:00
|
|
|
MirallConfigFile cfg( _configHandle );
|
|
|
|
QSettings settings( cfg.configFile(), QSettings::IniFormat);
|
|
|
|
QByteArray certs = settings.value(QLatin1String("CaCertificates")).toByteArray();
|
|
|
|
QSslSocket::addDefaultCaCertificates(QSslCertificate::fromData(certs));
|
|
|
|
|
2012-04-06 10:53:57 +04:00
|
|
|
connect( _manager, SIGNAL( sslErrors(QNetworkReply*, QList<QSslError>)),
|
2012-07-26 12:16:18 +04:00
|
|
|
_instance, SLOT(slotSSLFailed(QNetworkReply*, QList<QSslError>)) );
|
2012-04-14 21:08:53 +04:00
|
|
|
|
|
|
|
connect( _manager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
|
2012-07-26 12:16:18 +04:00
|
|
|
_instance, SLOT(slotAuthentication(QNetworkReply*,QAuthenticator*)));
|
2012-08-02 13:02:46 +04:00
|
|
|
resetSSLUntrust();
|
2012-03-16 18:16:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ownCloudInfo::~ownCloudInfo()
|
|
|
|
{
|
|
|
|
delete _manager;
|
2012-04-12 13:37:48 +04:00
|
|
|
delete _sslErrorDialog;
|
2011-10-05 19:49:03 +04:00
|
|
|
}
|
|
|
|
|
2012-06-12 14:28:07 +04:00
|
|
|
void ownCloudInfo::setCustomConfigHandle( const QString& handle )
|
|
|
|
{
|
|
|
|
_configHandle = handle;
|
2012-06-13 13:37:20 +04:00
|
|
|
_authAttempts = 0; // allow a couple of tries again.
|
2012-06-12 14:28:07 +04:00
|
|
|
resetSSLUntrust();
|
|
|
|
}
|
|
|
|
|
2011-10-05 19:49:03 +04:00
|
|
|
bool ownCloudInfo::isConfigured()
|
|
|
|
{
|
2012-06-12 14:28:07 +04:00
|
|
|
MirallConfigFile cfgFile( _configHandle );
|
2012-02-17 18:54:39 +04:00
|
|
|
return cfgFile.connectionExists( _connection );
|
2011-10-05 19:49:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ownCloudInfo::checkInstallation()
|
|
|
|
{
|
2012-02-18 20:02:10 +04:00
|
|
|
getRequest( "status.php", false );
|
|
|
|
}
|
2011-10-05 19:49:03 +04:00
|
|
|
|
2012-02-18 20:02:10 +04:00
|
|
|
void ownCloudInfo::getWebDAVPath( const QString& path )
|
|
|
|
{
|
|
|
|
getRequest( path, true );
|
|
|
|
}
|
2012-02-17 18:54:39 +04:00
|
|
|
|
2012-02-18 20:02:10 +04:00
|
|
|
void ownCloudInfo::getRequest( const QString& path, bool webdav )
|
|
|
|
{
|
2012-03-16 18:16:45 +04:00
|
|
|
qDebug() << "Get Request to " << path;
|
2012-04-06 10:53:57 +04:00
|
|
|
|
2012-06-12 14:28:07 +04:00
|
|
|
MirallConfigFile cfgFile( _configHandle );
|
2012-02-18 20:02:10 +04:00
|
|
|
QString url = cfgFile.ownCloudUrl( _connection, webdav ) + path;
|
|
|
|
QNetworkRequest request;
|
|
|
|
request.setUrl( QUrl( url ) );
|
2012-04-15 15:54:16 +04:00
|
|
|
setupHeaders( request, 0 );
|
|
|
|
|
2012-04-06 10:53:57 +04:00
|
|
|
QNetworkReply *reply = _manager->get( request );
|
2012-04-10 22:55:50 +04:00
|
|
|
connect( reply, SIGNAL(finished()), SLOT(slotReplyFinished()));
|
|
|
|
_directories[reply] = path;
|
2012-02-18 20:02:10 +04:00
|
|
|
|
2012-06-13 13:37:20 +04:00
|
|
|
if( !_configHandle.isEmpty() ) {
|
|
|
|
qDebug() << "Setting config handle " << _configHandle;
|
|
|
|
_configHandleMap[reply] = _configHandle;
|
|
|
|
}
|
|
|
|
|
2012-04-06 10:53:57 +04:00
|
|
|
connect( reply, SIGNAL( error(QNetworkReply::NetworkError )),
|
2012-02-18 20:02:10 +04:00
|
|
|
this, SLOT(slotError( QNetworkReply::NetworkError )));
|
2012-04-21 01:58:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if QT46_IMPL
|
|
|
|
void ownCloudInfo::mkdirRequest( const QString& dir )
|
|
|
|
{
|
|
|
|
qDebug() << "OCInfo Making dir " << dir;
|
|
|
|
|
2012-06-12 14:28:07 +04:00
|
|
|
MirallConfigFile cfgFile( _configHandle );
|
2012-04-21 01:58:09 +04:00
|
|
|
QUrl url = QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir );
|
|
|
|
QHttp::ConnectionMode conMode = QHttp::ConnectionModeHttp;
|
|
|
|
if (url.scheme() == "https")
|
|
|
|
conMode = QHttp::ConnectionModeHttps;
|
|
|
|
|
|
|
|
QHttp* qhttp = new QHttp(url.host(), conMode, 0, this);
|
|
|
|
qhttp->setUser( cfgFile.ownCloudUser( _connection ), cfgFile.ownCloudPasswd( _connection ));
|
|
|
|
|
|
|
|
connect(qhttp, SIGNAL(requestStarted(int)), this,SLOT(qhttpRequestStarted(int)));
|
|
|
|
connect(qhttp, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
|
|
|
|
connect(qhttp, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), this, SLOT(qhttpResponseHeaderReceived(QHttpResponseHeader)));
|
|
|
|
//connect(qhttp, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), this, SLOT(qhttpAuthenticationRequired(QString,quint16,QAuthenticator*)));
|
|
|
|
|
|
|
|
QHttpRequestHeader header("MKCOL", url.path(), 1,1); /* header */
|
|
|
|
header.setValue("Host", url.host() );
|
|
|
|
header.setValue("User-Agent", QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii() );
|
|
|
|
header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
|
|
|
|
header.setValue("Accept-Language", "it,de-de;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2");
|
|
|
|
header.setValue("Connection", "keep-alive");
|
|
|
|
header.setContentType("application/x-www-form-urlencoded"); //important
|
|
|
|
header.setContentLength(0);
|
|
|
|
header.setValue("Authorization", cfgFile.basicAuthHeader());
|
|
|
|
|
|
|
|
int david = qhttp->request(header,0,0);
|
|
|
|
//////////////// connect(davinfo, SIGNAL(dataSendProgress(int,int)), this, SLOT(SendStatus(int, int)));
|
|
|
|
/////////////////connect(davinfo, SIGNAL(done(bool)), this,SLOT(DavWake(bool)));
|
|
|
|
//connect(_http, SIGNAL(requestFinished(int, bool)), this,SLOT(qhttpRequestFinished(int,bool)));
|
|
|
|
///////////connect(davinfo, SIGNAL(responseHeaderReceived(constQHttpResponseHeader &)), this, SLOT(RegisterBackHeader(constQHttpResponseHeader &)));
|
|
|
|
|
2012-04-06 10:53:57 +04:00
|
|
|
|
2011-10-05 19:49:03 +04:00
|
|
|
}
|
|
|
|
|
2012-04-21 01:58:09 +04:00
|
|
|
void ownCloudInfo::qhttpResponseHeaderReceived(const QHttpResponseHeader& header)
|
|
|
|
{
|
|
|
|
qDebug() << "Resp:" << header.toString();
|
|
|
|
if (header.statusCode() == 201)
|
|
|
|
emit webdavColCreated( QNetworkReply::NoError );
|
|
|
|
else
|
|
|
|
qDebug() << "http request failed" << header.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ownCloudInfo::qhttpRequestStarted(int id)
|
|
|
|
{
|
|
|
|
qDebug() << "QHttp based request started " << id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ownCloudInfo::qhttpRequestFinished(int id, bool success )
|
|
|
|
{
|
|
|
|
qDebug() << "HIT!";
|
|
|
|
QHttp* qhttp = qobject_cast<QHttp*>(sender());
|
|
|
|
|
|
|
|
if( success ) {
|
|
|
|
qDebug() << "QHttp based request successful";
|
|
|
|
} else {
|
|
|
|
qDebug() << "QHttp based request failed: " << qhttp->errorString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2012-04-14 21:08:53 +04:00
|
|
|
void ownCloudInfo::mkdirRequest( const QString& dir )
|
|
|
|
{
|
2012-04-15 16:36:24 +04:00
|
|
|
qDebug() << "OCInfo Making dir " << dir;
|
2012-06-13 13:37:20 +04:00
|
|
|
_authAttempts = 0;
|
2012-06-12 14:28:07 +04:00
|
|
|
MirallConfigFile cfgFile( _configHandle );
|
2012-04-14 21:08:53 +04:00
|
|
|
QNetworkRequest req;
|
|
|
|
req.setUrl( QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir ) );
|
|
|
|
QNetworkReply *reply = davRequest("MKCOL", req, 0);
|
|
|
|
|
2012-06-13 13:37:20 +04:00
|
|
|
// remember the confighandle used for this request
|
|
|
|
if( ! _configHandle.isEmpty() )
|
|
|
|
qDebug() << "Setting config handle " << _configHandle;
|
|
|
|
_configHandleMap[reply] = _configHandle;
|
|
|
|
|
2012-04-18 13:59:56 +04:00
|
|
|
if( reply->error() != QNetworkReply::NoError ) {
|
|
|
|
qDebug() << "mkdir request network error: " << reply->errorString();
|
|
|
|
}
|
2012-06-13 13:37:20 +04:00
|
|
|
|
2012-04-14 21:08:53 +04:00
|
|
|
connect( reply, SIGNAL(finished()), SLOT(slotMkdirFinished()) );
|
|
|
|
connect( reply, SIGNAL( error(QNetworkReply::NetworkError )),
|
2012-04-15 15:54:16 +04:00
|
|
|
this, SLOT(slotError(QNetworkReply::NetworkError )));
|
2012-04-14 21:08:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ownCloudInfo::slotMkdirFinished()
|
|
|
|
{
|
|
|
|
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
|
|
|
|
|
|
|
|
if( ! reply ) {
|
|
|
|
qDebug() << "ownCloudInfo: Reply empty!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-21 01:58:09 +04:00
|
|
|
emit webdavColCreated( reply->error() );
|
2012-05-11 12:09:57 +04:00
|
|
|
qDebug() << "mkdir slot hit with status: " << reply->error();
|
2012-06-13 13:37:20 +04:00
|
|
|
if( _configHandleMap.contains( reply ) ) {
|
|
|
|
_configHandleMap.remove( reply );
|
|
|
|
}
|
|
|
|
|
2012-04-14 21:08:53 +04:00
|
|
|
reply->deleteLater();
|
|
|
|
}
|
2012-04-21 01:58:09 +04:00
|
|
|
#endif
|
2012-04-14 21:08:53 +04:00
|
|
|
|
2012-04-17 15:06:25 +04:00
|
|
|
void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *auth )
|
2011-10-06 18:55:28 +04:00
|
|
|
{
|
2012-06-13 13:37:20 +04:00
|
|
|
if( !(auth && reply) ) return;
|
|
|
|
QString configHandle;
|
|
|
|
|
|
|
|
// an empty config handle is ok for the default config.
|
|
|
|
if( _configHandleMap.contains(reply) ) {
|
|
|
|
configHandle = _configHandleMap[reply];
|
|
|
|
qDebug() << "Auth: Have a custom config handle: " << configHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Auth request to me and I am " << this;
|
|
|
|
_authAttempts++;
|
|
|
|
MirallConfigFile cfgFile( configHandle );
|
|
|
|
qDebug() << "Authenticating request for " << reply->url();
|
|
|
|
if( reply->url().toString().startsWith( cfgFile.ownCloudUrl( _connection, true )) ) {
|
|
|
|
auth->setUser( cfgFile.ownCloudUser( _connection ) );
|
|
|
|
auth->setPassword( cfgFile.ownCloudPasswd( _connection ));
|
|
|
|
} else {
|
|
|
|
qDebug() << "WRN: attempt to authenticate to different url - attempt " <<_authAttempts;
|
|
|
|
}
|
|
|
|
if( _authAttempts > 10 ) {
|
|
|
|
qDebug() << "Too many attempts to authenticate. Stop request.";
|
|
|
|
reply->close();
|
2012-02-17 18:54:39 +04:00
|
|
|
}
|
2012-06-13 13:37:20 +04:00
|
|
|
|
2011-10-06 18:55:28 +04:00
|
|
|
}
|
2011-10-05 19:49:03 +04:00
|
|
|
|
2012-04-06 10:53:57 +04:00
|
|
|
void ownCloudInfo::slotSSLFailed( QNetworkReply *reply, QList<QSslError> errors )
|
|
|
|
{
|
2012-04-12 13:37:48 +04:00
|
|
|
qDebug() << "SSL-Warnings happened for url " << reply->url().toString();
|
2012-04-06 10:53:57 +04:00
|
|
|
|
2012-06-13 13:37:20 +04:00
|
|
|
QString configHandle;
|
2012-06-18 12:42:30 +04:00
|
|
|
if( !configHandle.isEmpty() ) {
|
|
|
|
qDebug() << "Custom config handle: " << configHandle;
|
|
|
|
}
|
2012-06-13 13:37:20 +04:00
|
|
|
// an empty config handle is ok for the default config.
|
|
|
|
if( _configHandleMap.contains(reply) ) {
|
|
|
|
configHandle = _configHandleMap[reply];
|
|
|
|
qDebug() << "SSL: Have a custom config handle: " << configHandle;
|
|
|
|
}
|
|
|
|
|
2012-04-12 13:37:48 +04:00
|
|
|
if( _certsUntrusted ) {
|
|
|
|
// User decided once to untrust. Honor this decision.
|
2012-06-18 12:42:30 +04:00
|
|
|
qDebug() << "Untrusted by user decision, returning.";
|
2012-04-12 13:37:48 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-04-06 10:53:57 +04:00
|
|
|
|
2012-04-12 13:37:48 +04:00
|
|
|
if( _sslErrorDialog == 0 ) {
|
|
|
|
_sslErrorDialog = new SslErrorDialog();
|
2012-04-06 10:53:57 +04:00
|
|
|
}
|
|
|
|
|
2012-06-13 13:37:20 +04:00
|
|
|
// make the ssl dialog aware of the custom config. It loads known certs.
|
|
|
|
_sslErrorDialog->setCustomConfigHandle( configHandle );
|
|
|
|
|
2012-04-12 13:37:48 +04:00
|
|
|
if( _sslErrorDialog->setErrorList( errors ) ) {
|
|
|
|
// all ssl certs are known and accepted. We can ignore the problems right away.
|
|
|
|
qDebug() << "Certs are already known and trusted, Warnings are not valid.";
|
|
|
|
reply->ignoreSslErrors();
|
|
|
|
} else {
|
|
|
|
if( _sslErrorDialog->exec() == QDialog::Accepted ) {
|
|
|
|
if( _sslErrorDialog->trustConnection() ) {
|
|
|
|
reply->ignoreSslErrors();
|
|
|
|
} else {
|
|
|
|
// User does not want to trust.
|
|
|
|
_certsUntrusted = true;
|
|
|
|
}
|
2012-06-15 13:18:16 +04:00
|
|
|
} else {
|
|
|
|
_certsUntrusted = true;
|
2012-04-12 13:37:48 +04:00
|
|
|
}
|
|
|
|
}
|
2012-04-06 10:53:57 +04:00
|
|
|
}
|
|
|
|
|
2012-04-10 22:55:50 +04:00
|
|
|
//
|
|
|
|
// There have been problems with the finish-signal coming from the networkmanager.
|
|
|
|
// To avoid that, the reply-signals were connected and the data is taken from the
|
|
|
|
// sender() method.
|
|
|
|
//
|
|
|
|
void ownCloudInfo::slotReplyFinished()
|
2011-10-05 19:49:03 +04:00
|
|
|
{
|
2012-04-10 22:55:50 +04:00
|
|
|
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
|
|
|
|
|
2012-04-10 16:51:45 +04:00
|
|
|
if( ! reply ) {
|
|
|
|
qDebug() << "ownCloudInfo: Reply empty!";
|
|
|
|
return;
|
|
|
|
}
|
2012-04-10 22:55:50 +04:00
|
|
|
|
2012-04-10 16:51:45 +04:00
|
|
|
const QString version( reply->readAll() );
|
|
|
|
const QString url = reply->url().toString();
|
|
|
|
QString plainUrl(url);
|
2012-05-21 18:48:49 +04:00
|
|
|
plainUrl.remove( QLatin1String("/status.php"));
|
2012-04-10 16:51:45 +04:00
|
|
|
|
|
|
|
QString info( version );
|
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
if( url.endsWith( QLatin1String("status.php")) ) {
|
2012-04-10 16:51:45 +04:00
|
|
|
// it was a call to status.php
|
2012-04-10 22:55:50 +04:00
|
|
|
if( reply->error() == QNetworkReply::NoError && info.isEmpty() ) {
|
|
|
|
// This seems to be a bit strange behaviour of QNetworkAccessManager.
|
|
|
|
// It calls the finised slot multiple times but only the first read wins.
|
|
|
|
// That happend when the code connected the finished signal of the manager.
|
|
|
|
// It did not happen when the code connected to the reply finish signal.
|
|
|
|
qDebug() << "WRN: NetworkReply with not content but also no error! " << reply;
|
|
|
|
reply->deleteLater();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qDebug() << "status.php returns: " << info << " " << reply->error() << " Reply: " << reply;
|
2012-04-10 16:51:45 +04:00
|
|
|
if( info.contains("installed") && info.contains("version") && info.contains("versionstring") ) {
|
|
|
|
info.remove(0,1); // remove first char which is a "{"
|
|
|
|
info.remove(-1,1); // remove the last char which is a "}"
|
|
|
|
QStringList li = info.split( QChar(',') );
|
|
|
|
|
|
|
|
QString versionStr;
|
2012-05-14 18:22:30 +04:00
|
|
|
QString version;
|
|
|
|
QString edition;
|
|
|
|
|
2012-05-21 18:48:49 +04:00
|
|
|
foreach ( const QString& infoString, li ) {
|
2012-05-14 18:22:30 +04:00
|
|
|
QStringList touple = infoString.split( QChar(':'));
|
|
|
|
QString key = touple[0];
|
|
|
|
key.remove(QChar('"'));
|
|
|
|
QString val = touple[1];
|
|
|
|
val.remove(QChar('"'));
|
|
|
|
|
|
|
|
if( key == QLatin1String("versionstring") ) {
|
|
|
|
// get the versionstring out.
|
|
|
|
versionStr = val;
|
|
|
|
} else if( key == QLatin1String( "version") ) {
|
|
|
|
// get version out
|
|
|
|
version = val;
|
|
|
|
} else if( key == QLatin1String( "edition") ) {
|
|
|
|
// get version out
|
|
|
|
edition = val;
|
|
|
|
} else {
|
|
|
|
qDebug() << "Unknown info from ownCloud status.php: "<< key << "=" << val;
|
2012-04-10 16:51:45 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-14 18:22:30 +04:00
|
|
|
emit ownCloudInfoFound( plainUrl, versionStr, version, edition );
|
2012-04-10 16:51:45 +04:00
|
|
|
} else {
|
|
|
|
qDebug() << "No proper answer on " << url;
|
|
|
|
emit noOwncloudFound( reply );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// it was a general GET request.
|
2012-04-10 22:55:50 +04:00
|
|
|
QString dir("unknown");
|
|
|
|
if( _directories.contains(reply) ) {
|
|
|
|
dir = _directories[reply];
|
|
|
|
_directories.remove(reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit ownCloudDirExists( dir, reply );
|
2012-04-10 16:51:45 +04:00
|
|
|
}
|
2012-06-13 13:37:20 +04:00
|
|
|
if( _configHandleMap.contains(reply)) {
|
|
|
|
_configHandleMap.remove(reply);
|
|
|
|
}
|
2012-04-10 16:51:45 +04:00
|
|
|
reply->deleteLater();
|
2011-10-05 19:49:03 +04:00
|
|
|
}
|
|
|
|
|
2012-04-12 13:37:48 +04:00
|
|
|
void ownCloudInfo::resetSSLUntrust()
|
|
|
|
{
|
|
|
|
_certsUntrusted = false;
|
|
|
|
}
|
|
|
|
|
2011-10-12 17:14:39 +04:00
|
|
|
void ownCloudInfo::slotError( QNetworkReply::NetworkError err)
|
2011-10-05 19:49:03 +04:00
|
|
|
{
|
2012-03-30 22:42:40 +04:00
|
|
|
qDebug() << "ownCloudInfo Network Error: " << err;
|
2011-10-05 19:49:03 +04:00
|
|
|
}
|
|
|
|
|
2012-04-14 21:08:53 +04:00
|
|
|
// ============================================================================
|
2012-04-15 15:54:16 +04:00
|
|
|
void ownCloudInfo::setupHeaders( QNetworkRequest & req, quint64 size )
|
2012-04-14 21:08:53 +04:00
|
|
|
{
|
2012-06-12 14:28:07 +04:00
|
|
|
MirallConfigFile cfgFile(_configHandle );
|
2012-04-15 15:54:16 +04:00
|
|
|
|
|
|
|
QUrl url( cfgFile.ownCloudUrl( QString(), false ) );
|
|
|
|
qDebug() << "Setting up host header: " << url.host();
|
|
|
|
req.setRawHeader( QByteArray("Host"), url.host().toUtf8() );
|
|
|
|
req.setRawHeader( QByteArray("User-Agent"), QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii());
|
|
|
|
req.setRawHeader( QByteArray("Authorization"), cfgFile.basicAuthHeader() );
|
|
|
|
|
|
|
|
if (size) {
|
|
|
|
req.setHeader( QNetworkRequest::ContentLengthHeader, QVariant(size));
|
|
|
|
req.setHeader( QNetworkRequest::ContentTypeHeader, QVariant("text/xml; charset=utf-8"));
|
|
|
|
}
|
2012-04-14 21:08:53 +04:00
|
|
|
}
|
|
|
|
|
2012-04-21 23:03:29 +04:00
|
|
|
#if QT46_IMPL
|
|
|
|
#else
|
2012-04-14 21:08:53 +04:00
|
|
|
QNetworkReply* ownCloudInfo::davRequest(const QString& reqVerb, QNetworkRequest& req, QByteArray *data)
|
|
|
|
{
|
2012-04-15 15:54:16 +04:00
|
|
|
setupHeaders(req, quint64(data ? data->size() : 0));
|
2012-04-14 21:08:53 +04:00
|
|
|
if( data ) {
|
|
|
|
QBuffer iobuf( data );
|
|
|
|
return _manager->sendCustomRequest(req, reqVerb.toUtf8(), &iobuf );
|
|
|
|
} else {
|
|
|
|
return _manager->sendCustomRequest(req, reqVerb.toUtf8(), 0 );
|
|
|
|
}
|
|
|
|
}
|
2012-04-21 23:03:29 +04:00
|
|
|
#endif
|
2012-04-15 15:54:16 +04:00
|
|
|
|
2011-10-05 19:49:03 +04:00
|
|
|
}
|
|
|
|
|