2015-09-07 14:50:01 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
|
|
|
* 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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-09-07 14:50:01 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OCSJOB_H
|
|
|
|
#define OCSJOB_H
|
|
|
|
|
|
|
|
#include "accountfwd.h"
|
|
|
|
#include "abstractnetworkjob.h"
|
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
#include <QList>
|
|
|
|
#include <QPair>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2016-03-14 17:41:20 +03:00
|
|
|
#define OCS_SUCCESS_STATUS_CODE 100
|
2017-08-03 19:03:58 +03:00
|
|
|
// Apparantly the v2.php URLs can return that
|
|
|
|
#define OCS_SUCCESS_STATUS_CODE_V2 200
|
2018-04-09 11:54:30 +03:00
|
|
|
// not modified when using ETag
|
|
|
|
#define OCS_NOT_MODIFIED_STATUS_CODE_V2 304
|
2016-03-14 17:41:20 +03:00
|
|
|
|
2017-04-26 12:38:10 +03:00
|
|
|
class QJsonDocument;
|
|
|
|
|
2015-09-07 14:50:01 +03:00
|
|
|
namespace OCC {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The OcsShareJob class
|
|
|
|
* @ingroup gui
|
2015-10-15 21:54:52 +03:00
|
|
|
*
|
|
|
|
* Base class for jobs that talk to the OCS endpoints on the server.
|
2015-10-16 13:51:24 +03:00
|
|
|
* All the communication logic is handled in this class.
|
2015-10-15 21:54:52 +03:00
|
|
|
*
|
|
|
|
* All OCS jobs (e.g. sharing) should extend this class.
|
2015-09-07 14:50:01 +03:00
|
|
|
*/
|
2017-05-17 11:55:42 +03:00
|
|
|
class OcsJob : public AbstractNetworkJob
|
|
|
|
{
|
2015-09-07 14:50:01 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
protected:
|
2015-11-11 15:28:20 +03:00
|
|
|
explicit OcsJob(AccountPtr account);
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the verb for the job
|
|
|
|
*
|
|
|
|
* @param verb currently supported PUT POST DELETE
|
|
|
|
*/
|
2017-05-17 11:55:42 +03:00
|
|
|
void setVerb(const QByteArray &verb);
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
/**
|
2015-10-15 22:58:16 +03:00
|
|
|
* Add a new parameter to the request.
|
|
|
|
* Depending on the verb this is GET or POST parameter
|
2015-09-07 14:50:01 +03:00
|
|
|
*
|
2015-10-15 22:58:16 +03:00
|
|
|
* @param name The name of the parameter
|
|
|
|
* @param value The value of the parameter
|
2015-09-07 14:50:01 +03:00
|
|
|
*/
|
2017-05-17 11:55:42 +03:00
|
|
|
void addParam(const QString &name, const QString &value);
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the post parameters
|
|
|
|
*
|
|
|
|
* @param postParams list of pairs to add (urlEncoded) to the body of the
|
|
|
|
* request
|
|
|
|
*/
|
2017-05-17 11:55:42 +03:00
|
|
|
void setPostParams(const QList<QPair<QString, QString>> &postParams);
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of expected statuscodes for this request
|
|
|
|
* A warning will be printed to the debug log if a different status code is
|
|
|
|
* encountered
|
|
|
|
*
|
|
|
|
* @param code Accepted status code
|
|
|
|
*/
|
|
|
|
void addPassStatusCode(int code);
|
|
|
|
|
2015-10-16 09:28:13 +03:00
|
|
|
/**
|
2015-10-16 13:51:24 +03:00
|
|
|
* The base path for an OcsJob is always the same. But it could be the case that
|
2015-10-16 09:28:13 +03:00
|
|
|
* certain operations need to append something to the URL.
|
|
|
|
*
|
2015-10-16 13:51:24 +03:00
|
|
|
* This function appends the common id. so <PATH>/<ID>
|
2015-10-16 09:28:13 +03:00
|
|
|
*/
|
2015-10-29 13:09:10 +03:00
|
|
|
void appendPath(const QString &id);
|
2015-10-16 09:28:13 +03:00
|
|
|
|
2015-09-07 14:50:01 +03:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Parse the response and return the status code and the message of the
|
|
|
|
* reply (metadata)
|
|
|
|
*
|
|
|
|
* @param json The reply from OCS
|
|
|
|
* @param message The message that is set in the metadata
|
|
|
|
* @return The statuscode of the OCS response
|
|
|
|
*/
|
2017-04-26 12:38:10 +03:00
|
|
|
static int getJsonReturnCode(const QJsonDocument &json, QString &message);
|
2015-09-07 14:50:01 +03:00
|
|
|
|
2018-04-09 11:54:30 +03:00
|
|
|
/**
|
|
|
|
* @brief Adds header to the request e.g. "If-None-Match"
|
|
|
|
* @param headerName a string with the header name
|
|
|
|
* @param value a string with the value
|
|
|
|
*/
|
|
|
|
void addRawHeader(const QByteArray &headerName, const QByteArray &value);
|
|
|
|
|
|
|
|
|
2015-09-07 14:50:01 +03:00
|
|
|
protected slots:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the OCS request
|
|
|
|
*/
|
2018-11-11 13:09:29 +03:00
|
|
|
void start() override;
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Result of the OCS request
|
|
|
|
*
|
|
|
|
* @param reply the reply
|
|
|
|
*/
|
2018-04-09 11:54:30 +03:00
|
|
|
void jobFinished(QJsonDocument reply, int statusCode);
|
2015-09-07 14:50:01 +03:00
|
|
|
|
2015-10-29 18:56:23 +03:00
|
|
|
/**
|
|
|
|
* The status code was not one of the expected (passing)
|
|
|
|
* status code for this command
|
|
|
|
*
|
|
|
|
* @param statusCode The actual status code
|
|
|
|
* @param message The message provided by the server
|
|
|
|
*/
|
|
|
|
void ocsError(int statusCode, const QString &message);
|
|
|
|
|
2018-04-09 11:54:30 +03:00
|
|
|
/**
|
|
|
|
* @brief etagResponseHeaderReceived - signal to report the ETag response header value
|
|
|
|
* from ocs api v2
|
|
|
|
* @param value - the ETag response header value
|
|
|
|
* @param statusCode - the OCS status code: 100 (!) for success
|
|
|
|
*/
|
|
|
|
void etagResponseHeaderReceived(const QByteArray &value, int statusCode);
|
|
|
|
|
2015-09-07 14:50:01 +03:00
|
|
|
private slots:
|
2018-11-11 13:09:29 +03:00
|
|
|
bool finished() override;
|
2015-09-07 14:50:01 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
QByteArray _verb;
|
2017-05-17 11:55:42 +03:00
|
|
|
QList<QPair<QString, QString>> _params;
|
2015-09-07 14:50:01 +03:00
|
|
|
QVector<int> _passStatusCodes;
|
2018-04-09 11:54:30 +03:00
|
|
|
QNetworkRequest _request;
|
2015-09-07 14:50:01 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // OCSJOB_H
|