diff --git a/doc/manual-src/en/aria2c.rst b/doc/manual-src/en/aria2c.rst index e595ff24..8e56600d 100644 --- a/doc/manual-src/en/aria2c.rst +++ b/doc/manual-src/en/aria2c.rst @@ -3209,6 +3209,12 @@ For *secret* parameter, see :ref:`rpc_auth`. except that any actions which takes time such as contacting BitTorrent tracker are skipped. This method returns ``OK``. +.. function:: aria2.saveSession([secret]) + + This method saves the current session to a file specified by + :option:`--save-session` option. This method returns ``OK`` if it + succeeds. + .. function:: system.multicall(methods) This methods encapsulates multiple method calls in a single request. diff --git a/doc/xmlrpc/aria2rpc b/doc/xmlrpc/aria2rpc index 646d5df7..cc5bd2b6 100755 --- a/doc/xmlrpc/aria2rpc +++ b/doc/xmlrpc/aria2rpc @@ -273,6 +273,7 @@ Usage: #{program_name} addUri URI... [options] #{program_name} shutdown [options] #{program_name} forceShutdown [options] #{program_name} getGlobalStat [options] + #{program_name} saveSession [options] #{program_name} appendUri GID fileIndex URI... [options] This command calls aria2.changeUri(GID, fileIndex, [], [URI,...]) internally. @@ -394,6 +395,8 @@ elsif command == "forceShutdown" then result=client_call(client, secret, "aria2."+command) elsif command == "getGlobalStat" then result=client_call(client, secret, "aria2."+command) +elsif command == "saveSession" then + result=client_call(client, secret, "aria2."+command) elsif command == "appendUri" then result=client_call(client, secret, "aria2.changeUri", resources[0], resources[1].to_i(), [], resources[2..-1]) diff --git a/src/RpcMethodFactory.cc b/src/RpcMethodFactory.cc index 8813a17b..7cc919de 100644 --- a/src/RpcMethodFactory.cc +++ b/src/RpcMethodFactory.cc @@ -126,6 +126,8 @@ createMethod(const std::string& methodName) return make_unique(); } else if(methodName == GetGlobalStatRpcMethod::getMethodName()) { return make_unique(); + } else if(methodName == SaveSessionRpcMethod::getMethodName()) { + return make_unique(); } else if(methodName == SystemMulticallRpcMethod::getMethodName()) { return make_unique(); } else { diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index 00cdcb27..824ab2a1 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -65,6 +65,7 @@ #include "PeerStat.h" #include "base64.h" #include "BitfieldMan.h" +#include "SessionSerializer.h" #ifdef ENABLE_MESSAGE_DIGEST # include "MessageDigest.h" # include "message_digest_helper.h" @@ -1347,6 +1348,23 @@ std::unique_ptr GetGlobalStatRpcMethod::process return std::move(res); } +std::unique_ptr SaveSessionRpcMethod::process +(const RpcRequest& req, DownloadEngine* e) +{ + const std::string& filename = e->getOption()->get(PREF_SAVE_SESSION); + if(filename.empty()) { + throw DL_ABORT_EX("Filename is not given."); + } + SessionSerializer sessionSerializer(e->getRequestGroupMan().get()); + if(sessionSerializer.save(filename)) { + A2_LOG_NOTICE(fmt(_("Serialized session to '%s' successfully."), + filename.c_str())); + return createOKResponse(); + } + throw DL_ABORT_EX(fmt("Failed to serialize session to '%s'.", + filename.c_str())); +} + std::unique_ptr SystemMulticallRpcMethod::process (const RpcRequest& req, DownloadEngine* e) { diff --git a/src/RpcMethodImpl.h b/src/RpcMethodImpl.h index b20087ae..ac349896 100644 --- a/src/RpcMethodImpl.h +++ b/src/RpcMethodImpl.h @@ -567,6 +567,17 @@ public: } }; +class SaveSessionRpcMethod:public RpcMethod { +protected: + virtual std::unique_ptr process + (const RpcRequest& req, DownloadEngine* e) CXX11_OVERRIDE; +public: + static const char* getMethodName() + { + return "aria2.saveSession"; + } +}; + class SystemMulticallRpcMethod:public RpcMethod { protected: virtual std::unique_ptr process