forked from QtWebDAV/QtWebDAV
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqwebdav.cpp
More file actions
704 lines (565 loc) · 20.9 KB
/
qwebdav.cpp
File metadata and controls
704 lines (565 loc) · 20.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/****************************************************************************
** QWebDAV Library (qwebdavlib) - LGPL v2.1
**
** HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)
** from June 2007
** http://tools.ietf.org/html/rfc4918
**
** Web Distributed Authoring and Versioning (WebDAV) SEARCH
** from November 2008
** http://tools.ietf.org/html/rfc5323
**
** Missing:
** - process WebDAV SEARCH responses
**
** Copyright (C) 2021 Benoît Rouits <brouits@free.fr>
** for LOCK/UNLOCK support
**
** Copyright (C) 2012 Martin Haller <martin.haller@rebnil.com>
** for QWebDAV library (qwebdavlib) version 1.0
** https://github.com/mhaller/qwebdavlib
**
** Copyright (C) 2012 Timo Zimmermann <meedav@timozimmermann.de>
** for portions from QWebdav plugin for MeeDav (LGPL v2.1)
** http://projects.developer.nokia.com/meedav/
**
** Copyright (C) 2009-2010 Corentin Chary <corentin.chary@gmail.com>
** for portions from QWebdav - WebDAV lib for Qt4 (LGPL v2.1)
** http://xf.iksaif.net/dev/qwebdav.html
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** for naturalCompare() (LGPL v2.1)
** http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/dialogs/qfilesystemmodel.cpp
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Library General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This library 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
** Library General Public License for more details.
**
** You should have received a copy of the GNU Library General Public License
** along with this library; see the file COPYING.LIB. If not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
** Boston, MA 02110-1301, USA.
**
** http://www.gnu.org/licenses/lgpl-2.1-standalone.html
**
****************************************************************************/
#include "qwebdav.h"
QWebdav::QWebdav (QObject *parent) : QNetworkAccessManager(parent)
,m_rootPath()
,m_username()
,m_password()
,m_baseUrl()
,m_currentConnectionType(QWebdav::HTTP)
,m_authenticator_lastReply(nullptr)
,m_sslCertDigestMd5("")
,m_sslCertDigestSha1("")
{
qRegisterMetaType<QNetworkReply*>("QNetworkReply*");
connect(this, &QWebdav::finished, this, &QWebdav::replyFinished);
connect(this, &QWebdav::authenticationRequired, this, &QWebdav::provideAuthenication);
}
QWebdav::~QWebdav()
{
}
QString QWebdav::hostname() const
{
return m_baseUrl.host();
}
int QWebdav::port() const
{
return m_baseUrl.port();
}
QString QWebdav::rootPath() const
{
return m_rootPath;
}
QString QWebdav::username() const
{
return m_username;
}
QString QWebdav::password() const
{
return m_password;
}
QWebdav::QWebdavConnectionType QWebdav::connectionType() const
{
return m_currentConnectionType;
}
bool QWebdav::isSSL() const
{
return (m_currentConnectionType==QWebdav::HTTPS);
}
void QWebdav::setConnectionSettings(const QWebdavConnectionType connectionType,
const QString& hostname,
const QString& rootPath,
const QString& username,
const QString& password,
int port,
const QString &sslCertDigestMd5,
const QString &sslCertDigestSha1)
{
m_rootPath = rootPath;
if ((m_rootPath.size()>0) && (m_rootPath.endsWith("/")))
m_rootPath.chop(1);
QString uriScheme;
switch (connectionType)
{
case QWebdav::HTTP:
uriScheme = "http";
break;
case QWebdav::HTTPS:
uriScheme = "https";
break;
}
m_currentConnectionType = connectionType;
m_baseUrl.setScheme(uriScheme);
m_baseUrl.setHost(hostname);
m_baseUrl.setPath(rootPath);
if (port != 0) {
// use user-defined port number
if ( ! ( ( (port == 80) && (m_currentConnectionType==QWebdav::HTTP) ) ||
( (port == 443) && (m_currentConnectionType==QWebdav::HTTPS) ) ) )
m_baseUrl.setPort(port);
}
m_sslCertDigestMd5 = hexToDigest(sslCertDigestMd5);
m_sslCertDigestSha1 = hexToDigest(sslCertDigestSha1);
m_username = username;
m_password = password;
}
void QWebdav::acceptSslCertificate(const QString &sslCertDigestMd5,
const QString &sslCertDigestSha1)
{
m_sslCertDigestMd5 = hexToDigest(sslCertDigestMd5);
m_sslCertDigestSha1 = hexToDigest(sslCertDigestSha1);
}
void QWebdav::replyReadyRead()
{
auto reply = qobject_cast<QNetworkReply*>(QObject::sender());
if (reply->bytesAvailable() < 256000)
return;
QIODevice* dataIO = m_inDataDevices.value(reply, 0);
if(dataIO == nullptr)
return;
dataIO->write(reply->readAll());
}
void QWebdav::replyFinished(QNetworkReply* reply)
{
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::replyFinished()";
#endif
disconnect(reply, &QNetworkReply::redirectAllowed, this, &QWebdav::replyReadyRead);
disconnect(reply, &QNetworkReply::errorOccurred, this, &QWebdav::replyError);
QIODevice* dataIO = m_inDataDevices.value(reply, 0);
if (dataIO != 0) {
dataIO->write(reply->readAll());
static_cast<QFile*>(dataIO)->flush();
dataIO->close();
delete dataIO;
}
m_inDataDevices.remove(reply);
QMetaObject::invokeMethod(this,"replyDeleteLater", Qt::QueuedConnection, Q_ARG(QNetworkReply*, reply));
}
void QWebdav::replyDeleteLater(QNetworkReply* reply)
{
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::replyDeleteLater()";
#endif
QIODevice *outDataDevice = m_outDataDevices.value(reply, 0);
if (outDataDevice!=nullptr)
outDataDevice->deleteLater();
m_outDataDevices.remove(reply);
}
void QWebdav::replyError(QNetworkReply::NetworkError)
{
auto reply = qobject_cast<QNetworkReply*>(QObject::sender());
if (reply==nullptr)
return;
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::replyError() reply->url() == " << reply->url().toString(QUrl::RemoveUserInfo);
#endif
if ( reply->error() == QNetworkReply::OperationCanceledError) {
QIODevice* dataIO = m_inDataDevices.value(reply, 0);
if (dataIO!=nullptr) {
delete dataIO;
m_inDataDevices.remove(reply);
}
return;
}
emit errorChanged(reply->errorString());
}
void QWebdav::provideAuthenication(QNetworkReply *reply, QAuthenticator *authenticator)
{
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::authenticationRequired()";
QVariantHash opts = authenticator->options();
QVariant optVar;
foreach(optVar, opts) {
qDebug() << "QWebdav::authenticationRequired() option == " << optVar.toString();
}
#endif
if (reply == m_authenticator_lastReply) {
reply->abort();
emit errorChanged("WebDAV server requires authentication. Check WebDAV share settings!");
reply->deleteLater();
reply=nullptr;
}
m_authenticator_lastReply = reply;
authenticator->setUser(m_username);
authenticator->setPassword(m_password);
}
void QWebdav::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
{
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::sslErrors() reply->url == " << reply->url().toString(QUrl::RemoveUserInfo);
#endif
QSslCertificate sslcert = errors[0].certificate();
if ( ( sslcert.digest(QCryptographicHash::Md5) == m_sslCertDigestMd5 ) &&
( sslcert.digest(QCryptographicHash::Sha1) == m_sslCertDigestSha1) )
{
// user accepted this SSL certifcate already ==> ignore SSL errors
reply->ignoreSslErrors();
} else {
// user has to check the SSL certificate and has to accept manually
emit checkSslCertifcate(errors);
reply->abort();
}
}
QString QWebdav::digestToHex(const QByteArray &input)
{
QByteArray inputHex = input.toHex();
QString result = "";
for (int i = 0; i<inputHex.size(); i+=2) {
result.append(inputHex.at(i));
result.append(inputHex.at(i+1));
result.append(":");
}
result.chop(1);
result = result.toUpper();
return result;
}
QByteArray QWebdav::hexToDigest(const QString &input)
{
QByteArray result;
int i = 2;
int l = static_cast<int>(input.size());
result.append(input.left(2).toLatin1());
while ((i<l) && (input.at(i) == ':')) {
++i;
result.append(input.mid(i,2).toLatin1());
i+=2;
}
return QByteArray::fromHex(result);
}
QString QWebdav::absolutePath(const QString &relPath)
{
return QString(m_rootPath + relPath);
}
QNetworkReply* QWebdav::createRequest(const QString& method, QNetworkRequest& req, QIODevice* outgoingData)
{
if(outgoingData != nullptr && outgoingData->size() !=0) {
req.setHeader(QNetworkRequest::ContentLengthHeader, outgoingData->size());
req.setHeader(QNetworkRequest::ContentTypeHeader, "text/xml; charset=utf-8");
}
#ifdef DEBUG_WEBDAV
qDebug() << " QWebdav::createRequest1";
qDebug() << " " << method << " " << req.url().toString();
QList<QByteArray> rawHeaderList = req.rawHeaderList();
QByteArray rawHeaderItem;
foreach(rawHeaderItem, rawHeaderList) {
qDebug() << " " << rawHeaderItem << ": " << req.rawHeader(rawHeaderItem);
}
#endif
return sendCustomRequest(req, method.toLatin1(), outgoingData);
}
QNetworkReply* QWebdav::createRequest(const QString& method, QNetworkRequest& req, const QByteArray& outgoingData )
{
auto dataIO = new QBuffer;
dataIO->setData(outgoingData);
dataIO->open(QIODevice::ReadOnly);
#ifdef DEBUG_WEBDAV
qDebug() << " QWebdav::createRequest2";
qDebug() << " " << method << " " << req.url().toString();
QList<QByteArray> rawHeaderList = req.rawHeaderList();
QByteArray rawHeaderItem;
foreach(rawHeaderItem, rawHeaderList) {
qDebug() << " " << rawHeaderItem << ": " << req.rawHeader(rawHeaderItem);
}
#endif
QNetworkReply* reply = createRequest(method, req, dataIO);
m_outDataDevices.insert(reply, dataIO);
return reply;
}
QNetworkReply* QWebdav::list(const QString& path)
{
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::list() path = " << path;
#endif
return list(path, 1);
}
QNetworkReply* QWebdav::list(const QString& path, int depth)
{
QWebdav::PropNames query;
QStringList props;
// Small set of properties
// href in response contains also the name
// e.g. /container/front.html
props << "getlastmodified"; // http://www.webdav.org/specs/rfc4918.html#PROPERTY_getlastmodified
// e.g. Mon, 12 Jan 1998 09:25:56 GMT
props << "getcontentlength"; // http://www.webdav.org/specs/rfc4918.html#PROPERTY_getcontentlength
// e.g. "4525"
props << "resourcetype"; // http://www.webdav.org/specs/rfc4918.html#PROPERTY_resourcetype
// e.g. "collection" for a directory
// Following properties are available as well.
//props << "creationdate"; // http://www.webdav.org/specs/rfc4918.html#PROPERTY_creationdate
// e.g. "1997-12-01T18:27:21-08:00"
//props << "displayname"; // http://www.webdav.org/specs/rfc4918.html#PROPERTY_displayname
// e.g. "Example HTML resource"
//props << "getcontentlanguage"; // http://www.webdav.org/specs/rfc4918.html#PROPERTY_getcontentlanguage
// e.g. "en-US"
//props << "getcontenttype"; // http://www.webdav.org/specs/rfc4918.html#PROPERTY_getcontenttype
// e.g "text/html"
//props << "getetag"; // http://www.webdav.org/specs/rfc4918.html#PROPERTY_getetag
// e.g. "zzyzx"
// Additionally, there are also properties for locking
query["DAV:"] = props;
return propfind(path, query, depth);
}
QNetworkReply* QWebdav::search(const QString& path, const QString& q )
{
QByteArray query = "<?xml version=\"1.0\"?>\r\n";
query.append( "<D:searchrequest xmlns:D=\"DAV:\">\r\n" );
query.append( q.toUtf8() );
query.append( "</D:searchrequest>\r\n" );
QNetworkRequest req;
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
return this->createRequest("SEARCH", req, query);
}
QNetworkReply* QWebdav::get(const QString& path)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::get() url = " << req.url().toString(QUrl::RemoveUserInfo);
#endif
req.setUrl(reqUrl);
return QNetworkAccessManager::get(req);
}
QNetworkReply* QWebdav::get(const QString& path, QIODevice* data)
{
return get(path, data, 0);
}
QNetworkReply* QWebdav::get(const QString& path, QIODevice* data, quint64 fromRangeInBytes)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::get() url = " << req.url().toString(QUrl::RemoveUserInfo);
#endif
if (fromRangeInBytes>0) {
// RFC2616 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
QByteArray fromRange = "bytes=" + QByteArray::number(fromRangeInBytes) + "-"; // byte-ranges-specifier
req.setRawHeader("Range",fromRange);
}
QNetworkReply* reply = QNetworkAccessManager::get(req);
m_inDataDevices.insert(reply, data);
connect(reply, &QNetworkReply::readyRead, this, &QWebdav::replyReadyRead);
connect(reply, &QNetworkReply::errorOccurred, this, &QWebdav::replyError);
return reply;
}
QNetworkReply* QWebdav::put(const QString& path, QIODevice* data, const QDateTime& dt)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
if (dt.isValid()) {
QLocale us(QLocale::English, QLocale::UnitedStates);
req.setRawHeader("Date", us.toString(dt.toUTC(), "ddd, dd MMM yyyy hh:mm:ss").toUtf8());
}
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::put() url = " << req.url().toString(QUrl::RemoveUserInfo) << " date = " << req.rawHeader("Date");
#endif
return QNetworkAccessManager::put(req, data);
}
QNetworkReply* QWebdav::put(const QString& path, const QByteArray& data, const QDateTime& dt)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
if (dt.isValid()) {
QLocale us(QLocale::English, QLocale::UnitedStates);
req.setRawHeader("Date", us.toString(dt.toUTC(), "ddd, dd MMM yyyy hh:mm:ss").toUtf8());
}
#ifdef DEBUG_WEBDAV
qDebug() << "QWebdav::put() url = " << req.url().toString(QUrl::RemoveUserInfo) << " date = " << req.rawHeader("Date");
#endif
return QNetworkAccessManager::put(req, data);
}
QNetworkReply* QWebdav::propfind(const QString& path, const QWebdav::PropNames& props, int depth)
{
// QByteArray query;
QString query;
query = R"(<?xml version="1.0" encoding="utf-8" ?>)";
query += R"(<D:propfind xmlns:D="DAV:" >)";
query += "<D:prop>";
for(const auto& ns: props.keys()) {
for(const auto& key: props[ns]) {
if (ns == "DAV:")
query += "<D:" + key + "/>";
else
query += "<" + key + " xmlns=\"" + ns + "\"/>";
}
}
query += "</D:prop>";
query += "</D:propfind>";
return propfind(path, query.toUtf8(), depth);
}
QNetworkReply* QWebdav::propfind(const QString& path, const QByteArray& query, int depth)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
req.setRawHeader("Depth", depth == 2 ? QString("infinity").toUtf8() : QString::number(depth).toUtf8());
return createRequest("PROPFIND", req, query);
}
QNetworkReply* QWebdav::proppatch(const QString& path, const QWebdav::PropValues& props)
{
// QByteArray query;
QString query;
query = R"(<?xml version="1.0" encoding="utf-8" ?>)";
query += R"(<D:proppatch xmlns:D="DAV:" >)";
query += "<D:prop>";
for (const auto& ns: props.keys())
{
QMap < QString , QVariant >::const_iterator i;
for (i = props[ns].constBegin(); i != props[ns].constEnd(); ++i) {
if (ns == "DAV:") {
query += "<D:" + i.key() + ">";
query += i.value().toString();
query += "</D:" + i.key() + ">" ;
} else {
query += "<" + i.key() + " xmlns=\"" + ns + "\">";
query += i.value().toString();
query += "</" + i.key() + " xmlns=\"" + ns + "\"/>";
}
}
}
query += "</D:prop>";
query += "</D:propfind>";
return proppatch(path, query.toUtf8());
}
QNetworkReply* QWebdav::proppatch(const QString& path, const QByteArray& query)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
return createRequest("PROPPATCH", req, query);
}
QNetworkReply *QWebdav::lock(const QString &path, qint64 secs, const QString &token, QWebdavLockScope scope, QWebdavLockDepth depth, const QString &owner)
{
QString lockscope = scope == LOCK_SCOPE_EXCLUSIVE ? "exclusive" : "shared";
QByteArray query = "<?xml version=\"1.0\"?>\r\n";
query.append( "<D:lockinfo xmlns:D=\"DAV:\">\r\n" );
query.append( " <D:lockscope><D:" + lockscope.toUtf8() + "/>" + "</D:lockscope>\r\n");
query.append( " <D:locktype><D:write/></D:locktype>\r\n");
if (!owner.isEmpty())
query.append( " <D:owner><D:href>" + owner.toUtf8() + "</D:href></D:owner>\r\n");
query.append( "</D:lockinfo>\r\n" );
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
QString lockdepth = depth == LOCK_DEPTH_INFINITY ? "infinity" : "0";
req.setRawHeader("Depth", lockdepth.toUtf8());
QString seconds = secs < 0 ? "Infinite" : "Second-" + QString::number(secs);
req.setRawHeader("Timeout", seconds.toUtf8());
if (!token.isEmpty()) {
req.setRawHeader("If", "(<" + token.toUtf8() + ">)");
}
return createRequest("LOCK", req, query);
}
QNetworkReply *QWebdav::unlock(const QString &path, const QString &token)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
req.setRawHeader("Lock-Token", "<" + token.toUtf8() + ">");
return createRequest("UNLOCK", req);
}
QNetworkReply* QWebdav::mkdir (const QString& path)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
return createRequest("MKCOL", req);
}
QNetworkReply* QWebdav::copy(const QString& pathFrom, const QString& pathTo, bool overwrite)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(pathFrom));
req.setUrl(reqUrl);
// RFC4918 Section 10.3 requires an absolute URI for destination raw header
// http://tools.ietf.org/html/rfc4918#section-10.3
// RFC3986 Section 4.3 specifies the term absolute URI
// http://tools.ietf.org/html/rfc3986#section-4.3
QUrl dstUrl(m_baseUrl);
//dstUrl.setUserInfo("");
dstUrl.setPath(absolutePath(pathTo));
req.setRawHeader("Destination", dstUrl.toString().toUtf8());
req.setRawHeader("Depth", "infinity");
req.setRawHeader("Overwrite", overwrite ? "T" : "F");
return createRequest("COPY", req);
}
QNetworkReply* QWebdav::move(const QString& pathFrom, const QString& pathTo, bool overwrite)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(pathFrom));
req.setUrl(reqUrl);
// RFC4918 Section 10.3 requires an absolute URI for destination raw header
// http://tools.ietf.org/html/rfc4918#section-10.3
// RFC3986 Section 4.3 specifies the term absolute URI
// http://tools.ietf.org/html/rfc3986#section-4.3
QUrl dstUrl(m_baseUrl);
//dstUrl.setUserInfo("");
dstUrl.setPath(absolutePath(pathTo));
req.setRawHeader("Destination", dstUrl.toString().toUtf8());
req.setRawHeader("Depth", "infinity");
req.setRawHeader("Overwrite", overwrite ? "T" : "F");
return createRequest("MOVE", req);
}
QNetworkReply* QWebdav::remove(const QString& path)
{
QNetworkRequest req = buildRequest();
QUrl reqUrl(m_baseUrl);
reqUrl.setPath(absolutePath(path));
req.setUrl(reqUrl);
return createRequest("DELETE", req);
}
QNetworkRequest QWebdav::buildRequest() {
QNetworkRequest req;
if (isSSL()) {
QString concatenated = m_username + ":" + m_password;
QByteArray data = concatenated.toLocal8Bit().toBase64();
QString headerData = "Basic " + data;
req.setRawHeader("Authorization", headerData.toLocal8Bit());
}
return req;
}