Skip to content

Commit

Permalink
Add an experimental ProppatchJob #3235
Browse files Browse the repository at this point in the history
  • Loading branch information
ckamm committed Nov 23, 2015
1 parent bd72642 commit bdf830f
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/libsync/networkjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,81 @@ bool PropfindJob::finished()

/*********************************************************************************************/

ProppatchJob::ProppatchJob(AccountPtr account, const QString &path, QObject *parent)
: AbstractNetworkJob(account, path, parent)
{

}

void ProppatchJob::start()
{
if (_properties.isEmpty()) {
qWarning() << "Proppatch with no properties!";
}
QNetworkRequest req;

QByteArray propStr;
QMapIterator<QByteArray, QByteArray> it(_properties);
while (it.hasNext()) {
it.next();
QByteArray keyName = it.key();
QByteArray keyNs;
if (keyName.contains(':')) {
int colIdx = keyName.lastIndexOf(":");
keyNs = keyName.left(colIdx);
keyName = keyName.mid(colIdx+1);
}

propStr += " <" + keyName;
if (!keyNs.isEmpty()) {
propStr += " xmlns=\"" + keyNs + "\" ";
}
propStr += ">";
propStr += it.value();
propStr += "</" + keyName + ">\n";
}
QByteArray xml = "<?xml version=\"1.0\" ?>\n"
"<d:propertyupdate xmlns:d=\"DAV:\">\n"
" <d:set><d:prop>\n"
+ propStr +
" </d:prop></d:set>\n"
"</d:propertyupdate>\n";

QBuffer *buf = new QBuffer(this);
buf->setData(xml);
buf->open(QIODevice::ReadOnly);
setReply(davRequest("PROPPATCH", path(), req, buf));
buf->setParent(reply());
setupConnections(reply());
AbstractNetworkJob::start();
}

void ProppatchJob::setProperties(QMap<QByteArray, QByteArray> properties)
{
_properties = properties;
}

QMap<QByteArray, QByteArray> ProppatchJob::properties() const
{
return _properties;
}

bool ProppatchJob::finished()
{
int http_result_code = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

if (http_result_code == 207) {
emit success();
} else {
qDebug() << "PROPPATCH request *not* successful, http result code is" << http_result_code
<< (http_result_code == 302 ? reply()->header(QNetworkRequest::LocationHeader).toString() : QLatin1String(""));
emit finishedWithError();
}
return true;
}

/*********************************************************************************************/

EntityExistsJob::EntityExistsJob(AccountPtr account, const QString &path, QObject *parent)
: AbstractNetworkJob(account, path, parent)
{
Expand Down
37 changes: 37 additions & 0 deletions src/libsync/networkjobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,43 @@ private slots:
QList<QByteArray> _properties;
};

/**
* @brief Send a Proppatch request
*
* Setting the desired properties with setProperties() is mandatory.
*
* WARNING: Untested!
*
* @ingroup libsync
*/
class OWNCLOUDSYNC_EXPORT ProppatchJob : public AbstractNetworkJob {
Q_OBJECT
public:
explicit ProppatchJob(AccountPtr account, const QString &path, QObject *parent = 0);
void start() Q_DECL_OVERRIDE;

/**
* Used to specify which properties shall be set.
*
* The property keys can
* - contain no colon: they refer to a property in the DAV: namespace
* - contain a colon: and thus specify an explicit namespace,
* e.g. "ns:with:colons:bar", which is "bar" in the "ns:with:colons" namespace
*/
void setProperties(QMap<QByteArray, QByteArray> properties);
QMap<QByteArray, QByteArray> properties() const;

signals:
void success();
void finishedWithError();

private slots:
virtual bool finished() Q_DECL_OVERRIDE;

private:
QMap<QByteArray, QByteArray> _properties;
};

/**
* @brief The MkColJob class
* @ingroup libsync
Expand Down

0 comments on commit bdf830f

Please sign in to comment.