2009-05-08 07:58:50 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-05-08 07:58:50 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
2011-03-14 07:38:54 +00:00
|
|
|
#ifndef D_RPC_METHOD_IMPL_H
|
|
|
|
#define D_RPC_METHOD_IMPL_H
|
2009-05-08 07:58:50 +00:00
|
|
|
|
2011-03-14 07:38:54 +00:00
|
|
|
#include "RpcMethod.h"
|
2009-05-08 07:58:50 +00:00
|
|
|
|
2010-01-24 12:49:58 +00:00
|
|
|
#include <cassert>
|
2010-01-17 09:50:38 +00:00
|
|
|
#include <deque>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2011-03-14 07:38:54 +00:00
|
|
|
#include "RpcRequest.h"
|
2010-06-18 14:47:09 +00:00
|
|
|
#include "ValueBase.h"
|
|
|
|
#include "TorrentAttribute.h"
|
2010-06-19 17:54:54 +00:00
|
|
|
#include "DlAbortEx.h"
|
2011-09-25 14:36:00 +00:00
|
|
|
#include "fmt.h"
|
2012-12-19 14:03:48 +00:00
|
|
|
#include "IndexedList.h"
|
|
|
|
#include "GroupId.h"
|
|
|
|
#include "RequestGroupMan.h"
|
2010-01-17 09:50:38 +00:00
|
|
|
|
2009-05-08 07:58:50 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2010-06-13 02:21:40 +00:00
|
|
|
struct DownloadResult;
|
2009-12-20 09:49:43 +00:00
|
|
|
class RequestGroup;
|
|
|
|
|
2011-03-14 07:38:54 +00:00
|
|
|
namespace rpc {
|
2009-05-08 07:58:50 +00:00
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
template <typename T>
|
2011-09-25 14:36:00 +00:00
|
|
|
const T* checkParam(const RpcRequest& req, size_t index, bool required = false)
|
|
|
|
{
|
|
|
|
const T* p = 0;
|
2015-12-27 09:39:47 +00:00
|
|
|
if (req.params->size() > index) {
|
|
|
|
if ((p = downcast<T>(req.params->get(index))) == 0) {
|
2011-09-25 14:36:00 +00:00
|
|
|
throw DL_ABORT_EX(fmt("The parameter at %lu has wrong type.",
|
|
|
|
static_cast<unsigned long>(index)));
|
|
|
|
}
|
2015-12-27 09:39:47 +00:00
|
|
|
}
|
|
|
|
else if (required) {
|
2011-09-25 14:36:00 +00:00
|
|
|
throw DL_ABORT_EX(fmt("The parameter at %lu is required but missing.",
|
|
|
|
static_cast<unsigned long>(index)));
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
template <typename T>
|
2011-09-25 14:36:00 +00:00
|
|
|
const T* checkRequiredParam(const RpcRequest& req, size_t index)
|
|
|
|
{
|
|
|
|
return checkParam<T>(req, index, true);
|
|
|
|
}
|
|
|
|
|
2012-02-26 12:49:37 +00:00
|
|
|
struct IntegerGE {
|
2015-12-27 09:39:47 +00:00
|
|
|
IntegerGE(int32_t min) : min(min) {}
|
2012-02-26 12:49:37 +00:00
|
|
|
|
|
|
|
bool operator()(const Integer* param, std::string* error) const
|
|
|
|
{
|
2015-12-27 09:39:47 +00:00
|
|
|
if (min <= param->i()) {
|
2012-02-26 12:49:37 +00:00
|
|
|
return true;
|
2015-12-27 09:39:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (error) {
|
2012-02-26 12:49:37 +00:00
|
|
|
*error = fmt("the value must be greater than or equal to %d.", min);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t min;
|
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
template <typename Validator>
|
2012-02-26 12:49:37 +00:00
|
|
|
const Integer* checkRequiredInteger(const RpcRequest& req, size_t index,
|
|
|
|
Validator validator)
|
|
|
|
{
|
|
|
|
const Integer* param = checkRequiredParam<Integer>(req, index);
|
|
|
|
std::string error;
|
2015-12-27 09:39:47 +00:00
|
|
|
if (!validator(param, &error)) {
|
2012-02-26 12:49:37 +00:00
|
|
|
throw DL_ABORT_EX(fmt("The integer parameter at %lu has invalid value: %s",
|
|
|
|
static_cast<unsigned long>(index), error.c_str()));
|
|
|
|
}
|
|
|
|
return param;
|
|
|
|
}
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
template <typename OutputIterator>
|
2010-09-19 09:49:11 +00:00
|
|
|
void toStringList(OutputIterator out, const List* src)
|
|
|
|
{
|
2015-12-27 09:39:47 +00:00
|
|
|
if (!src) {
|
2010-09-19 09:49:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-12-27 09:39:47 +00:00
|
|
|
for (auto& elem : *src) {
|
2013-08-21 03:06:53 +00:00
|
|
|
const String* s = downcast<String>(elem);
|
2015-12-27 09:39:47 +00:00
|
|
|
if (s) {
|
2010-09-19 09:49:11 +00:00
|
|
|
*out++ = s->s();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class AddUriRpcMethod : public RpcMethod {
|
2009-05-08 07:58:50 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.addUri"; }
|
2009-05-08 07:58:50 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class RemoveRpcMethod : public RpcMethod {
|
2009-05-08 08:36:52 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.remove"; }
|
2009-05-08 08:36:52 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ForceRemoveRpcMethod : public RpcMethod {
|
2010-03-07 06:04:15 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-03-07 06:04:15 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.forceRemove"; }
|
2010-03-07 06:04:15 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class PauseRpcMethod : public RpcMethod {
|
2010-04-08 16:02:22 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-04-08 16:02:22 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.pause"; }
|
2010-04-08 16:02:22 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ForcePauseRpcMethod : public RpcMethod {
|
2010-04-11 09:39:46 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-04-11 09:39:46 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.forcePause"; }
|
2010-04-11 09:39:46 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class PauseAllRpcMethod : public RpcMethod {
|
2010-04-11 14:46:07 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-04-11 14:46:07 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.pauseAll"; }
|
2010-04-11 14:46:07 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ForcePauseAllRpcMethod : public RpcMethod {
|
2010-04-11 14:46:07 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-04-11 14:46:07 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.forcePauseAll"; }
|
2010-04-11 14:46:07 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class UnpauseRpcMethod : public RpcMethod {
|
2010-04-08 16:02:22 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-04-08 16:02:22 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.unpause"; }
|
2010-04-08 16:02:22 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class UnpauseAllRpcMethod : public RpcMethod {
|
2010-04-11 14:46:07 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-04-11 14:46:07 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.unpauseAll"; }
|
2010-04-11 14:46:07 +00:00
|
|
|
};
|
|
|
|
|
2009-05-27 17:27:05 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2015-12-27 09:39:47 +00:00
|
|
|
class AddTorrentRpcMethod : public RpcMethod {
|
2009-05-08 12:23:04 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.addTorrent"; }
|
2009-05-08 12:23:04 +00:00
|
|
|
};
|
2009-05-27 17:27:05 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2009-05-08 12:23:04 +00:00
|
|
|
|
2009-05-27 17:27:05 +00:00
|
|
|
#ifdef ENABLE_METALINK
|
2015-12-27 09:39:47 +00:00
|
|
|
class AddMetalinkRpcMethod : public RpcMethod {
|
2009-05-13 14:13:36 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.addMetalink"; }
|
2009-05-13 14:13:36 +00:00
|
|
|
};
|
2009-05-27 17:27:05 +00:00
|
|
|
#endif // ENABLE_METALINK
|
2009-05-13 14:13:36 +00:00
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class PurgeDownloadResultRpcMethod : public RpcMethod {
|
2009-05-14 13:48:26 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.purgeDownloadResult"; }
|
2009-05-14 13:48:26 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class RemoveDownloadResultRpcMethod : public RpcMethod {
|
2011-01-19 15:56:34 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2011-01-19 15:56:34 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.removeDownloadResult"; }
|
2011-01-19 15:56:34 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetUrisRpcMethod : public RpcMethod {
|
2009-05-10 14:35:51 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getUris"; }
|
2009-05-10 14:35:51 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetFilesRpcMethod : public RpcMethod {
|
2009-05-10 14:35:51 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getFiles"; }
|
2009-05-10 14:35:51 +00:00
|
|
|
};
|
|
|
|
|
2009-05-27 17:27:05 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetPeersRpcMethod : public RpcMethod {
|
2009-05-10 14:35:51 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getPeers"; }
|
2009-05-10 14:35:51 +00:00
|
|
|
};
|
2009-05-27 17:27:05 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2009-05-10 14:35:51 +00:00
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetServersRpcMethod : public RpcMethod {
|
2010-03-07 08:30:19 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-03-07 08:30:19 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getServers"; }
|
2010-03-07 08:30:19 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class TellStatusRpcMethod : public RpcMethod {
|
2009-05-09 12:41:37 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.tellStatus"; }
|
2009-05-09 12:41:37 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class TellActiveRpcMethod : public RpcMethod {
|
2009-05-08 13:47:33 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.tellActive"; }
|
2009-05-08 13:47:33 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
template <typename T> class AbstractPaginationRpcMethod : public RpcMethod {
|
2010-01-17 09:50:38 +00:00
|
|
|
private:
|
2015-12-27 09:39:47 +00:00
|
|
|
template <typename InputIterator>
|
2010-01-17 09:50:38 +00:00
|
|
|
std::pair<InputIterator, InputIterator>
|
2015-12-27 09:39:47 +00:00
|
|
|
getPaginationRange(int64_t offset, int64_t num, InputIterator first,
|
|
|
|
InputIterator last)
|
2010-01-17 09:50:38 +00:00
|
|
|
{
|
2015-12-27 09:39:47 +00:00
|
|
|
if (num <= 0) {
|
2014-05-01 02:34:27 +00:00
|
|
|
return std::make_pair(last, last);
|
|
|
|
}
|
|
|
|
|
2012-02-26 10:45:25 +00:00
|
|
|
int64_t size = std::distance(first, last);
|
2015-12-27 09:39:47 +00:00
|
|
|
if (offset < 0) {
|
|
|
|
int64_t tempoffset = offset + size;
|
|
|
|
if (tempoffset < 0) {
|
2010-01-17 09:50:38 +00:00
|
|
|
return std::make_pair(last, last);
|
|
|
|
}
|
2015-12-27 09:39:47 +00:00
|
|
|
offset = tempoffset - (num - 1);
|
|
|
|
if (offset < 0) {
|
2010-01-17 09:50:38 +00:00
|
|
|
offset = 0;
|
2015-12-27 09:39:47 +00:00
|
|
|
num = tempoffset + 1;
|
2010-01-17 09:50:38 +00:00
|
|
|
}
|
2015-12-27 09:39:47 +00:00
|
|
|
}
|
|
|
|
else if (size <= offset) {
|
2010-01-17 09:50:38 +00:00
|
|
|
return std::make_pair(last, last);
|
|
|
|
}
|
2012-02-26 10:45:25 +00:00
|
|
|
int64_t lastDistance;
|
2015-12-27 09:39:47 +00:00
|
|
|
if (size < offset + num) {
|
2010-01-17 09:50:38 +00:00
|
|
|
lastDistance = size;
|
2015-12-27 09:39:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastDistance = offset + num;
|
2010-01-17 09:50:38 +00:00
|
|
|
}
|
|
|
|
last = first;
|
|
|
|
std::advance(first, offset);
|
|
|
|
std::advance(last, lastDistance);
|
|
|
|
return std::make_pair(first, last);
|
|
|
|
}
|
2015-12-27 09:39:47 +00:00
|
|
|
|
2009-06-23 15:14:24 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
typedef IndexedList<a2_gid_t, std::shared_ptr<T>> ItemListType;
|
2012-12-19 14:03:48 +00:00
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE
|
2010-01-17 09:50:38 +00:00
|
|
|
{
|
2011-09-25 14:36:00 +00:00
|
|
|
const Integer* offsetParam = checkRequiredParam<Integer>(req, 0);
|
2012-02-26 12:49:37 +00:00
|
|
|
const Integer* numParam = checkRequiredInteger(req, 1, IntegerGE(0));
|
2011-09-25 14:36:00 +00:00
|
|
|
const List* keysParam = checkParam<List>(req, 2);
|
|
|
|
|
2012-02-26 10:45:25 +00:00
|
|
|
int64_t offset = offsetParam->i();
|
|
|
|
int64_t num = numParam->i();
|
2010-09-19 09:49:11 +00:00
|
|
|
std::vector<std::string> keys;
|
|
|
|
toStringList(std::back_inserter(keys), keysParam);
|
2012-12-19 14:03:48 +00:00
|
|
|
const ItemListType& items = getItems(e);
|
2015-12-27 09:39:47 +00:00
|
|
|
auto range =
|
|
|
|
getPaginationRange(offset, num, std::begin(items), std::end(items));
|
2013-07-11 12:09:51 +00:00
|
|
|
auto list = List::g();
|
2015-12-27 09:39:47 +00:00
|
|
|
for (; range.first != range.second; ++range.first) {
|
2013-07-11 12:09:51 +00:00
|
|
|
auto entryDict = Dict::g();
|
|
|
|
createEntry(entryDict.get(), *range.first, e, keys);
|
|
|
|
list->append(std::move(entryDict));
|
2010-01-17 09:50:38 +00:00
|
|
|
}
|
2015-12-27 09:39:47 +00:00
|
|
|
if (offset < 0) {
|
2010-06-19 17:54:54 +00:00
|
|
|
std::reverse(list->begin(), list->end());
|
2010-01-17 09:50:38 +00:00
|
|
|
}
|
2013-07-11 12:09:51 +00:00
|
|
|
return std::move(list);
|
2010-01-17 09:50:38 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 14:03:48 +00:00
|
|
|
virtual const ItemListType& getItems(DownloadEngine* e) const = 0;
|
2010-01-17 09:50:38 +00:00
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual void createEntry(Dict* entryDict, const std::shared_ptr<T>& item,
|
|
|
|
DownloadEngine* e,
|
|
|
|
const std::vector<std::string>& keys) const = 0;
|
2010-01-17 09:50:38 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class TellWaitingRpcMethod : public AbstractPaginationRpcMethod<RequestGroup> {
|
2010-01-17 09:50:38 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual const RequestGroupList&
|
|
|
|
getItems(DownloadEngine* e) const CXX11_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
createEntry(Dict* entryDict, const std::shared_ptr<RequestGroup>& item,
|
|
|
|
DownloadEngine* e,
|
|
|
|
const std::vector<std::string>& keys) const CXX11_OVERRIDE;
|
2010-01-17 09:50:38 +00:00
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.tellWaiting"; }
|
2009-06-23 15:14:24 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class TellStoppedRpcMethod
|
|
|
|
: public AbstractPaginationRpcMethod<DownloadResult> {
|
2009-12-25 14:46:22 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual const DownloadResultList&
|
|
|
|
getItems(DownloadEngine* e) const CXX11_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
createEntry(Dict* entryDict, const std::shared_ptr<DownloadResult>& item,
|
|
|
|
DownloadEngine* e,
|
|
|
|
const std::vector<std::string>& keys) const CXX11_OVERRIDE;
|
2010-01-17 09:50:38 +00:00
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.tellStopped"; }
|
2009-12-25 14:46:22 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ChangeOptionRpcMethod : public RpcMethod {
|
2009-05-14 15:23:50 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.changeOption"; }
|
2009-05-14 15:23:50 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ChangeGlobalOptionRpcMethod : public RpcMethod {
|
2009-05-14 15:44:59 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.changeGlobalOption"; }
|
2009-05-14 15:44:59 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetVersionRpcMethod : public RpcMethod {
|
2009-07-10 15:55:42 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getVersion"; }
|
2009-07-10 15:55:42 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetOptionRpcMethod : public RpcMethod {
|
2009-12-20 14:33:42 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getOption"; }
|
2009-12-20 14:33:42 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetGlobalOptionRpcMethod : public RpcMethod {
|
2009-12-20 14:33:42 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getGlobalOption"; }
|
2009-12-20 14:33:42 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ChangePositionRpcMethod : public RpcMethod {
|
2009-12-21 15:17:34 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.changePosition"; }
|
2009-12-21 15:17:34 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ChangeUriRpcMethod : public RpcMethod {
|
2010-03-06 14:21:43 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-03-06 14:21:43 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.changeUri"; }
|
2010-03-06 14:21:43 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetSessionInfoRpcMethod : public RpcMethod {
|
2010-01-17 11:55:22 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-01-17 11:55:22 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getSessionInfo"; }
|
2010-01-17 11:55:22 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ShutdownRpcMethod : public RpcMethod {
|
2010-04-02 14:50:33 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-04-02 14:50:33 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.shutdown"; }
|
2010-04-02 14:50:33 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GetGlobalStatRpcMethod : public RpcMethod {
|
2011-06-17 13:45:42 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2011-06-17 13:45:42 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.getGlobalStat"; }
|
2011-06-17 13:45:42 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class ForceShutdownRpcMethod : public RpcMethod {
|
2010-04-02 14:50:33 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2010-04-02 14:50:33 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.forceShutdown"; }
|
2010-04-02 14:50:33 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class SaveSessionRpcMethod : public RpcMethod {
|
2014-02-19 13:02:50 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
2014-02-19 13:02:50 +00:00
|
|
|
public:
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "aria2.saveSession"; }
|
2014-02-19 13:02:50 +00:00
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class SystemMulticallRpcMethod : public RpcMethod {
|
2009-12-26 10:16:56 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
2014-07-15 06:15:46 +00:00
|
|
|
|
2009-12-26 13:07:27 +00:00
|
|
|
public:
|
2014-07-15 06:15:46 +00:00
|
|
|
virtual RpcResponse execute(RpcRequest req, DownloadEngine* e) CXX11_OVERRIDE;
|
2014-02-02 08:34:07 +00:00
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
static const char* getMethodName() { return "system.multicall"; }
|
2009-12-26 10:16:56 +00:00
|
|
|
};
|
|
|
|
|
2015-12-26 11:57:33 +00:00
|
|
|
class SystemListMethodsRpcMethod : public RpcMethod {
|
|
|
|
protected:
|
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual RpcResponse execute(RpcRequest req, DownloadEngine* e) CXX11_OVERRIDE;
|
|
|
|
|
|
|
|
static const char* getMethodName() { return "system.listMethods"; }
|
|
|
|
};
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class NoSuchMethodRpcMethod : public RpcMethod {
|
2009-05-08 07:58:50 +00:00
|
|
|
protected:
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual std::unique_ptr<ValueBase> process(const RpcRequest& req,
|
|
|
|
DownloadEngine* e) CXX11_OVERRIDE;
|
2009-05-08 07:58:50 +00:00
|
|
|
};
|
|
|
|
|
2009-12-20 09:49:43 +00:00
|
|
|
// Helper function to store data to entryDict from ds. This function
|
|
|
|
// is used by tellStatus method.
|
2015-12-27 09:39:47 +00:00
|
|
|
void gatherStoppedDownload(Dict* entryDict,
|
|
|
|
const std::shared_ptr<DownloadResult>& ds,
|
|
|
|
const std::vector<std::string>& keys);
|
2009-12-20 09:49:43 +00:00
|
|
|
|
|
|
|
// Helper function to store data to entryDict from group. This
|
|
|
|
// function is used by tellStatus/tellActive/tellWaiting method
|
2015-12-27 09:39:47 +00:00
|
|
|
void gatherProgressCommon(Dict* entryDict,
|
|
|
|
const std::shared_ptr<RequestGroup>& group,
|
|
|
|
const std::vector<std::string>& keys);
|
2009-12-20 09:49:43 +00:00
|
|
|
|
2010-01-31 08:05:21 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2010-06-18 14:47:09 +00:00
|
|
|
// Helper function to store BitTorrent metadata from torrentAttrs.
|
2013-07-11 12:09:51 +00:00
|
|
|
void gatherBitTorrentMetadata(Dict* btDict, TorrentAttribute* torrentAttrs);
|
2010-01-31 08:05:21 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
|
|
|
|
2011-03-14 07:38:54 +00:00
|
|
|
} // namespace rpc
|
2009-05-08 07:58:50 +00:00
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
bool pauseRequestGroup(const std::shared_ptr<RequestGroup>& group,
|
|
|
|
bool reserved, bool forcePause);
|
2013-05-01 07:58:34 +00:00
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
void changeOption(const std::shared_ptr<RequestGroup>& group,
|
|
|
|
const Option& option, DownloadEngine* e);
|
2013-05-16 14:09:19 +00:00
|
|
|
|
2013-05-17 13:56:21 +00:00
|
|
|
void changeGlobalOption(const Option& option, DownloadEngine* e);
|
|
|
|
|
2009-05-08 07:58:50 +00:00
|
|
|
} // namespace aria2
|
|
|
|
|
2011-03-14 07:38:54 +00:00
|
|
|
#endif // D_RPC_METHOD_IMPL_H
|