diff --git a/libresapi/src/api/FileSharingHandler.cpp b/libresapi/src/api/FileSharingHandler.cpp index a6296973d..44c94cfad 100644 --- a/libresapi/src/api/FileSharingHandler.cpp +++ b/libresapi/src/api/FileSharingHandler.cpp @@ -37,6 +37,16 @@ FileSharingHandler::FileSharingHandler(StateTokenServer *sts, RsFiles *files, addResourceHandler("get_dir_parent", this, &FileSharingHandler::handleGetDirectoryParent); addResourceHandler("get_dir_childs", this, &FileSharingHandler::handleGetDirectoryChilds); + addResourceHandler( "get_download_directory", this, + &FileSharingHandler::handleGetDownloadDirectory ); + addResourceHandler( "set_download_directory", this, + &FileSharingHandler::handleSetDownloadDirectory ); + + addResourceHandler( "get_partials_directory", this, + &FileSharingHandler::handleGetPartialsDirectory ); + addResourceHandler( "set_partials_directory", this, + &FileSharingHandler::handleSetPartialsDirectory ); + addResourceHandler("is_dl_dir_shared", this, &FileSharingHandler::handleIsDownloadDirShared); addResourceHandler("share_dl_dir", this, &FileSharingHandler::handleShareDownloadDirectory); @@ -513,4 +523,48 @@ void FileSharingHandler::handleDownload(Request& req, Response& resp) resp.setFail("Couldn't download file"); } +void FileSharingHandler::handleGetDownloadDirectory( Request& /*req*/, + Response& resp ) +{ + std::string dlDir = mRsFiles->getDownloadDirectory(); + resp.mDataStream << makeKeyValueReference("download_directory", dlDir); + resp.setOk(); +} + +void FileSharingHandler::handleSetDownloadDirectory( Request& req, + Response& resp ) +{ + std::string dlDir; + req.mStream << makeKeyValueReference("download_directory", dlDir); + + if(dlDir.empty()) resp.setFail("missing download_directory"); + else + { + mRsFiles->setDownloadDirectory(dlDir); + resp.setOk(); + } +} + +void FileSharingHandler::handleGetPartialsDirectory( Request& /*req*/, + Response& resp ) +{ + std::string partialsDir = mRsFiles->getPartialsDirectory(); + resp.mDataStream << makeKeyValueReference("partials_directory", partialsDir); + resp.setOk(); +} + +void FileSharingHandler::handleSetPartialsDirectory( Request& req, + Response& resp ) +{ + std::string partialsDir; + req.mStream << makeKeyValueReference("partials_directory", partialsDir); + + if(partialsDir.empty()) resp.setFail("missing partials_directory"); + else + { + mRsFiles->setPartialsDirectory(partialsDir); + resp.setOk(); + } +} + } // namespace resource_api diff --git a/libresapi/src/api/FileSharingHandler.h b/libresapi/src/api/FileSharingHandler.h index 0eb67764e..cd78f338f 100644 --- a/libresapi/src/api/FileSharingHandler.h +++ b/libresapi/src/api/FileSharingHandler.h @@ -57,6 +57,12 @@ private: void handleDownload(Request& req, Response& resp); + void handleGetDownloadDirectory(Request& req, Response& resp); + void handleSetDownloadDirectory(Request& req, Response& resp); + + void handleGetPartialsDirectory(Request& req, Response& resp); + void handleSetPartialsDirectory(Request& req, Response& resp); + /// Token indicating change in local shared files StateToken mLocalDirStateToken; diff --git a/libresapi/src/api/TransfersHandler.cpp b/libresapi/src/api/TransfersHandler.cpp index c696411da..dc28e9596 100644 --- a/libresapi/src/api/TransfersHandler.cpp +++ b/libresapi/src/api/TransfersHandler.cpp @@ -15,6 +15,14 @@ TransfersHandler::TransfersHandler(StateTokenServer *sts, RsFiles *files, RsPeer addResourceHandler("downloads", this, &TransfersHandler::handleDownloads); addResourceHandler("uploads", this, &TransfersHandler::handleUploads); addResourceHandler("control_download", this, &TransfersHandler::handleControlDownload); + + addResourceHandler( "set_file_destination_directory", this, + &TransfersHandler::handleSetFileDestinationDirectory ); + addResourceHandler( "set_file_destination_name", this, + &TransfersHandler::handleSetFileDestinationName ); + addResourceHandler( "set_file_chunk_strategy", this, + &TransfersHandler::handleSetFileChunkStrategy ); + mStateToken = mStateTokenServer->getNewToken(); mStateTokenServer->registerTickClient(this); mNotify.registerNotifyClient(this); @@ -288,4 +296,58 @@ void TransfersHandler::handleUploads(Request & /* req */, Response &resp) resp.setOk(); } +void TransfersHandler::handleSetFileDestinationDirectory( Request& req, + Response& resp ) +{ + mStateTokenServer->replaceToken(mStateToken); + + std::string hashString; + std::string newPath; + req.mStream << makeKeyValueReference("path", newPath); + req.mStream << makeKeyValueReference("hash", hashString); + RsFileHash hash(hashString); + + if (mFiles->setDestinationDirectory(hash, newPath)) resp.setOk(); + else resp.setFail(); +} + +void TransfersHandler::handleSetFileDestinationName( Request& req, + Response& resp ) +{ + mStateTokenServer->replaceToken(mStateToken); + + std::string hashString; + std::string newName; + req.mStream << makeKeyValueReference("name", newName); + req.mStream << makeKeyValueReference("hash", hashString); + RsFileHash hash(hashString); + + if (mFiles->setDestinationName(hash, newName)) resp.setOk(); + else resp.setFail(); +} + +void TransfersHandler::handleSetFileChunkStrategy(Request& req, Response& resp) +{ + mStateTokenServer->replaceToken(mStateToken); + + std::string hashString; + std::string newChunkStrategyStr; + req.mStream << makeKeyValueReference("chuck_stategy", newChunkStrategyStr); + req.mStream << makeKeyValueReference("hash", hashString); + + RsFileHash hash(hashString); + FileChunksInfo::ChunkStrategy newStrategy = + FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE; + + if ( newChunkStrategyStr == "streaming" ) + newStrategy = FileChunksInfo::CHUNK_STRATEGY_STREAMING; + else if ( newChunkStrategyStr == "random" ) + newStrategy = FileChunksInfo::CHUNK_STRATEGY_RANDOM; + else if ( newChunkStrategyStr == "progressive" ) + newStrategy = FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE; + + if (mFiles->setChunkStrategy(hash, newStrategy)) resp.setOk(); + else resp.setFail(); +} + } // namespace resource_api diff --git a/libresapi/src/api/TransfersHandler.h b/libresapi/src/api/TransfersHandler.h index 7d07a7198..7e43c3614 100644 --- a/libresapi/src/api/TransfersHandler.h +++ b/libresapi/src/api/TransfersHandler.h @@ -30,6 +30,9 @@ private: void handleControlDownload(Request& req, Response& resp); void handleDownloads(Request& req, Response& resp); void handleUploads(Request& req, Response& resp); + void handleSetFileDestinationDirectory(Request& req, Response& resp); + void handleSetFileDestinationName(Request& req, Response& resp); + void handleSetFileChunkStrategy(Request& req, Response& resp); StateTokenServer* mStateTokenServer; RsFiles* mFiles; diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index ccd4428be..83301de98 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -168,10 +168,9 @@ public: class RsFiles { - public: - - RsFiles() { return; } - virtual ~RsFiles() { return; } +public: + RsFiles() {} + virtual ~RsFiles() {} /** * Provides file data for the gui: media streaming or rpc clients.