diff --git a/xroot_plugins/CMakeLists.txt b/xroot_plugins/CMakeLists.txt index 5e4ee8eec8b79b90ecb1c836cd6d13f473ed1fa4..c33b24a1f9c5d119e6ae3d8f0801d2c3a1969bf0 100644 --- a/xroot_plugins/CMakeLists.txt +++ b/xroot_plugins/CMakeLists.txt @@ -4,4 +4,4 @@ list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) find_package (xrootd REQUIRED) include_directories (${XROOTD_INCLUDE_DIR} ${XROOTD_PRIVATE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}) -add_library (XrdProFst MODULE XrdProFilesystem.cpp ParsedArchiveCmdLine.cpp ParsedCreateStorageClassCmdLine.cpp ParsedDeleteStorageClassCmdLine.cpp ParsedListStorageClassCmdLine.cpp ParsedMkdirCmdLine.cpp ParsedRmdirCmdLine.cpp ParsedChangeStorageClassCmdLine.cpp) +add_library (XrdProFst MODULE XrdProFilesystem.cpp ParsedRequest.cpp) diff --git a/xroot_plugins/ParsedArchiveCmdLine.cpp b/xroot_plugins/ParsedArchiveCmdLine.cpp deleted file mode 100644 index e677bd8665e948fe254adadff3ee429c11556b56..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedArchiveCmdLine.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "ParsedArchiveCmdLine.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -ParsedArchiveCmdLine::ParsedArchiveCmdLine() throw() -{ - -} diff --git a/xroot_plugins/ParsedArchiveCmdLine.hpp b/xroot_plugins/ParsedArchiveCmdLine.hpp deleted file mode 100644 index b81fe13bd3b08c22e96b4ce26cd969f205f6ed5e..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedArchiveCmdLine.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "XrdOuc/XrdOucString.hh" - -#include <list> -#include <string> - -/** - * Data type used to store the results of parsing the archive command-line. - */ -struct ParsedArchiveCmdLine { - - /** - * The source files to be archived - */ - std::list<std::string> srcFiles; - - /** - * The destination path (in the tape namespace) - */ - std::string dstPath; - - /** - * Constructor. - */ - ParsedArchiveCmdLine() throw(); - -}; // struct ParsedArchiveCmdLine - diff --git a/xroot_plugins/ParsedChangeStorageClassCmdLine.cpp b/xroot_plugins/ParsedChangeStorageClassCmdLine.cpp deleted file mode 100644 index cab5e123056695751bda3dd5741d9a46bc663b80..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedChangeStorageClassCmdLine.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "ParsedChangeStorageClassCmdLine.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -ParsedChangeStorageClassCmdLine::ParsedChangeStorageClassCmdLine() throw() -{ - -} diff --git a/xroot_plugins/ParsedChangeStorageClassCmdLine.hpp b/xroot_plugins/ParsedChangeStorageClassCmdLine.hpp deleted file mode 100644 index ce41c6f60caaab3030384607e27e58bd515a8183..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedChangeStorageClassCmdLine.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "XrdOuc/XrdOucString.hh" - -#include <list> -#include <string> - -/** - * Data type used to store the results of parsing the create-storage-class command-line. - */ -struct ParsedChangeStorageClassCmdLine { - - /** - * The directory name - */ - std::string dirName; - - /** - * The storage class name - */ - std::string storageClassName; - - /** - * Constructor. - */ - ParsedChangeStorageClassCmdLine() throw(); - -}; // struct ParsedChangeStorageClassCmdLine - diff --git a/xroot_plugins/ParsedCreateStorageClassCmdLine.cpp b/xroot_plugins/ParsedCreateStorageClassCmdLine.cpp deleted file mode 100644 index 894682037a3e345284247b8464d08310f6a2b025..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedCreateStorageClassCmdLine.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "ParsedCreateStorageClassCmdLine.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -ParsedCreateStorageClassCmdLine::ParsedCreateStorageClassCmdLine() throw(): numberOfCopies(0) -{ - -} diff --git a/xroot_plugins/ParsedCreateStorageClassCmdLine.hpp b/xroot_plugins/ParsedCreateStorageClassCmdLine.hpp deleted file mode 100644 index a573e27fc3b948f2d17536ca9115c1b5706e2b3f..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedCreateStorageClassCmdLine.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "XrdOuc/XrdOucString.hh" - -#include <list> -#include <string> - -/** - * Data type used to store the results of parsing the create-storage-class command-line. - */ -struct ParsedCreateStorageClassCmdLine { - - /** - * The storage class name - */ - std::string storageClassName; - - /** - * The number of copies on tape - */ - int numberOfCopies; - - /** - * Constructor. - */ - ParsedCreateStorageClassCmdLine() throw(); - -}; // struct ParsedCreateStorageClassCmdLine - diff --git a/xroot_plugins/ParsedDeleteStorageClassCmdLine.cpp b/xroot_plugins/ParsedDeleteStorageClassCmdLine.cpp deleted file mode 100644 index 80c1730a24cdb98563a90cd9fd3fa5d3fc4205f9..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedDeleteStorageClassCmdLine.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "ParsedDeleteStorageClassCmdLine.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -ParsedDeleteStorageClassCmdLine::ParsedDeleteStorageClassCmdLine() throw() -{ - -} diff --git a/xroot_plugins/ParsedDeleteStorageClassCmdLine.hpp b/xroot_plugins/ParsedDeleteStorageClassCmdLine.hpp deleted file mode 100644 index 72756f976ed7c10cbc9c39212a6ff6dcdf2e7af7..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedDeleteStorageClassCmdLine.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "XrdOuc/XrdOucString.hh" - -#include <list> -#include <string> - -/** - * Data type used to store the results of parsing the delete-storage-class command-line. - */ -struct ParsedDeleteStorageClassCmdLine { - - /** - * The storage class name - */ - std::string storageClassName; - - /** - * Constructor. - */ - ParsedDeleteStorageClassCmdLine() throw(); - -}; // struct ParsedDeleteStorageClassCmdLine - diff --git a/xroot_plugins/ParsedListStorageClassCmdLine.cpp b/xroot_plugins/ParsedListStorageClassCmdLine.cpp deleted file mode 100644 index 3cb98be9d6eb50396a74ccb4bd43f8ae77a79500..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedListStorageClassCmdLine.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "ParsedListStorageClassCmdLine.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -ParsedListStorageClassCmdLine::ParsedListStorageClassCmdLine() throw() -{ - -} diff --git a/xroot_plugins/ParsedListStorageClassCmdLine.hpp b/xroot_plugins/ParsedListStorageClassCmdLine.hpp deleted file mode 100644 index e52d4d593afca68f577cb2304e0c3507bb7cea1b..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedListStorageClassCmdLine.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "XrdOuc/XrdOucString.hh" - -#include <list> -#include <string> - -/** - * Data type used to store the results of parsing the list-storage-class command-line. - */ -struct ParsedListStorageClassCmdLine { - - /** - * Constructor. - */ - ParsedListStorageClassCmdLine() throw(); - -}; // struct ParsedListStorageClassCmdLine - diff --git a/xroot_plugins/ParsedMkdirCmdLine.hpp b/xroot_plugins/ParsedMkdirCmdLine.hpp deleted file mode 100644 index 4a239a6f98f7e0cb20237875a56eae4d439b53f2..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedMkdirCmdLine.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "XrdOuc/XrdOucString.hh" - -#include <list> -#include <string> - -/** - * Data type used to store the results of parsing the mkdir command-line. - */ -struct ParsedMkdirCmdLine { - - /** - * The directory name - */ - std::string dirName; - - /** - * Constructor. - */ - ParsedMkdirCmdLine() throw(); - -}; // struct ParsedMkdirCmdLine - diff --git a/xroot_plugins/ParsedMkdirCmdLine.cpp b/xroot_plugins/ParsedRequest.cpp similarity index 69% rename from xroot_plugins/ParsedMkdirCmdLine.cpp rename to xroot_plugins/ParsedRequest.cpp index a773c6ea312a64fe7abf83053ab4f3520a26e046..7dc9a78b9d231239813a3af5759f2a3a240b0a7a 100644 --- a/xroot_plugins/ParsedMkdirCmdLine.cpp +++ b/xroot_plugins/ParsedRequest.cpp @@ -1,9 +1,9 @@ -#include "ParsedMkdirCmdLine.hpp" +#include "ParsedRequest.hpp" //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -ParsedMkdirCmdLine::ParsedMkdirCmdLine() throw() +ParsedRequest::ParsedRequest() throw() { } diff --git a/xroot_plugins/ParsedRequest.hpp b/xroot_plugins/ParsedRequest.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c0568c96d5dc6e2578721e365710e09890332a2a --- /dev/null +++ b/xroot_plugins/ParsedRequest.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "XrdOuc/XrdOucString.hh" + +#include <vector> +#include <string> + +/** + * Data type used to store the results of parsing the request. + */ +struct ParsedRequest { + + /** + * The command name + */ + std::string cmd; + + /** + * The command arguments + */ + std::vector<std::string> args; + + /** + * Constructor. + */ + ParsedRequest() throw(); + +}; // struct ParsedRequest + diff --git a/xroot_plugins/ParsedRmdirCmdLine.cpp b/xroot_plugins/ParsedRmdirCmdLine.cpp deleted file mode 100644 index edf69858793f40d0430ac6250ce0bb8c53e57be2..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedRmdirCmdLine.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "ParsedRmdirCmdLine.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -ParsedRmdirCmdLine::ParsedRmdirCmdLine() throw() -{ - -} diff --git a/xroot_plugins/ParsedRmdirCmdLine.hpp b/xroot_plugins/ParsedRmdirCmdLine.hpp deleted file mode 100644 index 95594d04e2887a14cb89b44332903dbcb2f9d59e..0000000000000000000000000000000000000000 --- a/xroot_plugins/ParsedRmdirCmdLine.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include "XrdOuc/XrdOucString.hh" - -#include <list> -#include <string> - -/** - * Data type used to store the results of parsing the rmdir command-line. - */ -struct ParsedRmdirCmdLine { - - /** - * The directory name - */ - std::string dirName; - - /** - * Constructor. - */ - ParsedRmdirCmdLine() throw(); - -}; // struct ParsedRmdirCmdLine - diff --git a/xroot_plugins/XrdProFilesystem.cpp b/xroot_plugins/XrdProFilesystem.cpp index 4cd594f32462e0c5e7f6f68999172f335948d417..6ed17bbc6abd2366377e46c6f4e215bfe2716fc6 100644 --- a/xroot_plugins/XrdProFilesystem.cpp +++ b/xroot_plugins/XrdProFilesystem.cpp @@ -19,15 +19,6 @@ extern "C" } } -//------------------------------------------------------------------------------ -// isDir -//------------------------------------------------------------------------------ -bool XrdProFilesystem::isDir(const char *path) throw() { - size_t length = strlen(path); - if('/' == path[length-1]) return true; - else return false; -} - //------------------------------------------------------------------------------ // checkClient //------------------------------------------------------------------------------ @@ -86,17 +77,16 @@ int XrdProFilesystem::checkClient(const XrdSecEntity *client, XrdOucErrInfo &eIn //------------------------------------------------------------------------------ // parseArchiveRequest //------------------------------------------------------------------------------ -int XrdProFilesystem::parseArchiveRequest(const XrdSfsFSctl &args, ParsedArchiveCmdLine &cmdLine, XrdOucErrInfo &eInfo) { +int XrdProFilesystem::parseRequest(const XrdSfsFSctl &args, ParsedRequest &req, XrdOucErrInfo &eInfo) { std::stringstream ss(args.Arg1); std::string s; getline(ss, s, '?'); + req.cmd = s; while (getline(ss, s, '+')) { - cmdLine.srcFiles.push_back(s); + req.args.push_back(s); } - cmdLine.srcFiles.pop_back(); - cmdLine.dstPath = s; - if(cmdLine.srcFiles.empty() || cmdLine.dstPath.empty()) { - eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); + if(req.cmd.empty()) { + eInfo.setErrInfo(EINVAL, "[ERROR] No command supplied"); return SFS_ERROR; } return SFS_OK; @@ -105,158 +95,95 @@ int XrdProFilesystem::parseArchiveRequest(const XrdSfsFSctl &args, ParsedArchive //------------------------------------------------------------------------------ // executeArchiveCommand //------------------------------------------------------------------------------ -int XrdProFilesystem::executeArchiveCommand(ParsedArchiveCmdLine &cmdLine, XrdOucErrInfo &eInfo) { +int XrdProFilesystem::executeArchiveCommand(ParsedRequest &req, XrdOucErrInfo &eInfo) { + if(req.args.size() < 2) { + eInfo.setErrInfo(EINVAL, "[ERROR] Too few arguments provided"); + return SFS_ERROR; + } std::cout << "archive request received:\n"; - for(std::list<std::string>::iterator it = cmdLine.srcFiles.begin(); it != cmdLine.srcFiles.end(); it++) { - std::cout << "SRC: " << *it << std::endl; + for(int i=0; i<req.args.size()-1; i++) { + std::cout << "SRC: " << req.args.at(i) << std::endl; } - std::cout << "DST: " << cmdLine.dstPath << std::endl; + std::cout << "DST: " << req.args.at(req.args.size()-1) << std::endl; return SFS_OK; } //------------------------------------------------------------------------------ -// parseCreateStorageClassRequest +// executeCreateStorageClassCommand //------------------------------------------------------------------------------ -int XrdProFilesystem::parseCreateStorageClassRequest(const XrdSfsFSctl &args, ParsedCreateStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { - std::stringstream ss(args.Arg1); - std::string s; - getline(ss, s, '?'); - getline(ss, s, '+'); - cmdLine.storageClassName = s; - getline(ss, s, '+'); - cmdLine.numberOfCopies = atoi(s.c_str()); - if(cmdLine.storageClassName.empty() || cmdLine.numberOfCopies==0) { - eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); +int XrdProFilesystem::executeCreateStorageClassCommand(ParsedRequest &req, XrdOucErrInfo &eInfo) { + if(req.args.size() != 2) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong number of arguments provided"); return SFS_ERROR; } - return SFS_OK; -} - -//------------------------------------------------------------------------------ -// executeCreateStorageClassCommand -//------------------------------------------------------------------------------ -int XrdProFilesystem::executeCreateStorageClassCommand(ParsedCreateStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { std::cout << "create-storage-class request received:\n"; - std::cout << "NAME: " << cmdLine.storageClassName << std::endl; - std::cout << "Number of copies on tape: " << cmdLine.numberOfCopies << std::endl; + std::cout << "NAME: " << req.args.at(0) << std::endl; + std::cout << "Number of copies on tape: " << req.args.at(1) << std::endl; return SFS_OK; } //------------------------------------------------------------------------------ -// parseChangeStorageClassRequest +// executeCreateStorageClassCommand //------------------------------------------------------------------------------ -int XrdProFilesystem::parseChangeStorageClassRequest(const XrdSfsFSctl &args, ParsedChangeStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { - std::stringstream ss(args.Arg1); - std::string s; - getline(ss, s, '?'); - getline(ss, s, '+'); - cmdLine.dirName = s; - getline(ss, s, '+'); - cmdLine.storageClassName = s; - if(cmdLine.storageClassName.empty() || cmdLine.dirName.empty()) { - eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); +int XrdProFilesystem::executeChangeStorageClassCommand(ParsedRequest &req, XrdOucErrInfo &eInfo) { + if(req.args.size() != 2) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong number of arguments provided"); return SFS_ERROR; } - return SFS_OK; -} - -//------------------------------------------------------------------------------ -// executeCreateStorageClassCommand -//------------------------------------------------------------------------------ -int XrdProFilesystem::executeChangeStorageClassCommand(ParsedChangeStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { std::cout << "change-storage-class request received:\n"; - std::cout << "DIR: " << cmdLine.dirName << std::endl; - std::cout << "NAME: " << cmdLine.storageClassName << std::endl; + std::cout << "DIR: " << req.args.at(0) << std::endl; + std::cout << "NAME: " << req.args.at(1) << std::endl; return SFS_OK; } //------------------------------------------------------------------------------ -// parseDeleteStorageClassRequest +// executeDeleteStorageClassCommand //------------------------------------------------------------------------------ -int XrdProFilesystem::parseDeleteStorageClassRequest(const XrdSfsFSctl &args, ParsedDeleteStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { - std::stringstream ss(args.Arg1); - std::string s; - getline(ss, s, '?'); - getline(ss, s, '+'); - cmdLine.storageClassName = s; - if(cmdLine.storageClassName.empty()) { - eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); +int XrdProFilesystem::executeDeleteStorageClassCommand(ParsedRequest &req, XrdOucErrInfo &eInfo) { + if(req.args.size() != 1) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong number of arguments provided"); return SFS_ERROR; } - return SFS_OK; -} - -//------------------------------------------------------------------------------ -// executeDeleteStorageClassCommand -//------------------------------------------------------------------------------ -int XrdProFilesystem::executeDeleteStorageClassCommand(ParsedDeleteStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { std::cout << "delete-storage-class request received:\n"; - std::cout << "NAME: " << cmdLine.storageClassName << std::endl; - return SFS_OK; -} - -//------------------------------------------------------------------------------ -// parseListStorageClassRequest -//------------------------------------------------------------------------------ -int XrdProFilesystem::parseListStorageClassRequest(const XrdSfsFSctl &args, ParsedListStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::cout << "NAME: " << req.args.at(0) << std::endl; return SFS_OK; } //------------------------------------------------------------------------------ // executeListStorageClassCommand //------------------------------------------------------------------------------ -int XrdProFilesystem::executeListStorageClassCommand(ParsedListStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { - std::cout << "list-storage-class request received:\n"; - return SFS_OK; -} - -//------------------------------------------------------------------------------ -// parseMkdirRequest -//------------------------------------------------------------------------------ -int XrdProFilesystem::parseMkdirRequest(const XrdSfsFSctl &args, ParsedMkdirCmdLine &cmdLine, XrdOucErrInfo &eInfo) { - std::stringstream ss(args.Arg1); - std::string s; - getline(ss, s, '?'); - getline(ss, s, '+'); - cmdLine.dirName = s; - if(cmdLine.dirName.empty()) { - eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); +int XrdProFilesystem::executeListStorageClassCommand(ParsedRequest &req, XrdOucErrInfo &eInfo) { + if(req.args.size() != 0) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong number of arguments provided"); return SFS_ERROR; } + std::cout << "list-storage-class request received:\n"; return SFS_OK; } //------------------------------------------------------------------------------ // executeMkdirCommand //------------------------------------------------------------------------------ -int XrdProFilesystem::executeMkdirCommand(ParsedMkdirCmdLine &cmdLine, XrdOucErrInfo &eInfo) { - std::cout << "mkdir request received:\n"; - std::cout << "DIR: " << cmdLine.dirName << std::endl; - return SFS_OK; -} - -//------------------------------------------------------------------------------ -// parseRmdirRequest -//------------------------------------------------------------------------------ -int XrdProFilesystem::parseRmdirRequest(const XrdSfsFSctl &args, ParsedRmdirCmdLine &cmdLine, XrdOucErrInfo &eInfo) { - std::stringstream ss(args.Arg1); - std::string s; - getline(ss, s, '?'); - getline(ss, s, '+'); - cmdLine.dirName = s; - if(cmdLine.dirName.empty()) { - eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); +int XrdProFilesystem::executeMkdirCommand(ParsedRequest &req, XrdOucErrInfo &eInfo) { + if(req.args.size() != 1) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong number of arguments provided"); return SFS_ERROR; } + std::cout << "mkdir request received:\n"; + std::cout << "DIR: " << req.args.at(0) << std::endl; return SFS_OK; } //------------------------------------------------------------------------------ // executeRmdirCommand //------------------------------------------------------------------------------ -int XrdProFilesystem::executeRmdirCommand(ParsedRmdirCmdLine &cmdLine, XrdOucErrInfo &eInfo) { +int XrdProFilesystem::executeRmdirCommand(ParsedRequest &req, XrdOucErrInfo &eInfo) { + if(req.args.size() != 1) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong number of arguments provided"); + return SFS_ERROR; + } std::cout << "rmdir request received:\n"; - std::cout << "DIR: " << cmdLine.dirName << std::endl; + std::cout << "DIR: " << req.args.at(0) << std::endl; return SFS_OK; } @@ -264,100 +191,42 @@ int XrdProFilesystem::executeRmdirCommand(ParsedRmdirCmdLine &cmdLine, XrdOucErr // dispatchRequest //------------------------------------------------------------------------------ int XrdProFilesystem::dispatchRequest(XrdSfsFSctl &args, XrdOucErrInfo &eInfo) { - if(strncmp(args.Arg1, "/archive?", strlen("/archive?")) == 0) + ParsedRequest req; + int checkParse = parseRequest(args, req, eInfo); + if(SFS_OK!=checkParse) { + return checkParse; + } + if(strcmp(req.cmd.c_str(), "/archive") == 0) { - ParsedArchiveCmdLine cmdLine; - int checkParse = parseArchiveRequest(args, cmdLine, eInfo); - if(SFS_OK!=checkParse) { - return checkParse; - } - int checkExecute = executeArchiveCommand(cmdLine, eInfo); - if(SFS_OK!=checkExecute) { - return checkExecute; - } - return SFS_OK; + return executeArchiveCommand(req, eInfo); } - else if(strncmp(args.Arg1, "/create-storage-class?", strlen("/create-storage-class?")) == 0) + else if(strcmp(req.cmd.c_str(), "/create-storage-class") == 0) { - ParsedCreateStorageClassCmdLine cmdLine; - int checkParse = parseCreateStorageClassRequest(args, cmdLine, eInfo); - if(SFS_OK!=checkParse) { - return checkParse; - } - int checkExecute = executeCreateStorageClassCommand(cmdLine, eInfo); - if(SFS_OK!=checkExecute) { - return checkExecute; - } - return SFS_OK; + return executeCreateStorageClassCommand(req, eInfo); } - else if(strncmp(args.Arg1, "/change-storage-class?", strlen("/change-storage-class?")) == 0) + else if(strcmp(req.cmd.c_str(), "/change-storage-class") == 0) { - ParsedChangeStorageClassCmdLine cmdLine; - int checkParse = parseChangeStorageClassRequest(args, cmdLine, eInfo); - if(SFS_OK!=checkParse) { - return checkParse; - } - int checkExecute = executeChangeStorageClassCommand(cmdLine, eInfo); - if(SFS_OK!=checkExecute) { - return checkExecute; - } - return SFS_OK; + return executeChangeStorageClassCommand(req, eInfo); } - else if(strncmp(args.Arg1, "/delete-storage-class?", strlen("/delete-storage-class?")) == 0) + else if(strcmp(req.cmd.c_str(), "/delete-storage-class") == 0) { - ParsedDeleteStorageClassCmdLine cmdLine; - int checkParse = parseDeleteStorageClassRequest(args, cmdLine, eInfo); - if(SFS_OK!=checkParse) { - return checkParse; - } - int checkExecute = executeDeleteStorageClassCommand(cmdLine, eInfo); - if(SFS_OK!=checkExecute) { - return checkExecute; - } - return SFS_OK; + return executeDeleteStorageClassCommand(req, eInfo); } - else if(strncmp(args.Arg1, "/list-storage-class?", strlen("/list-storage-class?")) == 0) + else if(strcmp(req.cmd.c_str(), "/list-storage-class") == 0) { - ParsedListStorageClassCmdLine cmdLine; - int checkParse = parseListStorageClassRequest(args, cmdLine, eInfo); - if(SFS_OK!=checkParse) { - return checkParse; - } - int checkExecute = executeListStorageClassCommand(cmdLine, eInfo); - if(SFS_OK!=checkExecute) { - return checkExecute; - } - return SFS_OK; + return executeListStorageClassCommand(req, eInfo); } - else if(strncmp(args.Arg1, "/mkdir?", strlen("/mkdir?")) == 0) + else if(strcmp(req.cmd.c_str(), "/mkdir") == 0) { - ParsedMkdirCmdLine cmdLine; - int checkParse = parseMkdirRequest(args, cmdLine, eInfo); - if(SFS_OK!=checkParse) { - return checkParse; - } - int checkExecute = executeMkdirCommand(cmdLine, eInfo); - if(SFS_OK!=checkExecute) { - return checkExecute; - } - return SFS_OK; + return executeMkdirCommand(req, eInfo); } - else if(strncmp(args.Arg1, "/rmdir?", strlen("/rmdir?")) == 0) + else if(strcmp(req.cmd.c_str(), "/rmdir") == 0) { - ParsedRmdirCmdLine cmdLine; - int checkParse = parseRmdirRequest(args, cmdLine, eInfo); - if(SFS_OK!=checkParse) { - return checkParse; - } - int checkExecute = executeRmdirCommand(cmdLine, eInfo); - if(SFS_OK!=checkExecute) { - return checkExecute; - } - return SFS_OK; + return executeRmdirCommand(req, eInfo); } else { - eInfo.setErrInfo(EINVAL, "[ERROR] Unknown plugin request string received"); + eInfo.setErrInfo(EINVAL, "[ERROR] Unknown command received"); return SFS_ERROR; } } diff --git a/xroot_plugins/XrdProFilesystem.hpp b/xroot_plugins/XrdProFilesystem.hpp index e1ed5c0b22c775f25290025726c17b7d36b90ddc..8dc1f8b048e88c5dcfa6e7e986c80487039a5175 100644 --- a/xroot_plugins/XrdProFilesystem.hpp +++ b/xroot_plugins/XrdProFilesystem.hpp @@ -2,13 +2,7 @@ #include "XrdSfs/XrdSfsInterface.hh" -#include "ParsedArchiveCmdLine.hpp" -#include "ParsedCreateStorageClassCmdLine.hpp" -#include "ParsedDeleteStorageClassCmdLine.hpp" -#include "ParsedChangeStorageClassCmdLine.hpp" -#include "ParsedListStorageClassCmdLine.hpp" -#include "ParsedMkdirCmdLine.hpp" -#include "ParsedRmdirCmdLine.hpp" +#include "ParsedRequest.hpp" class XrdProFilesystem : public XrdSfsFileSystem { public: @@ -35,156 +29,88 @@ public: ~XrdProFilesystem(); protected: - + /** - * Function that checks whether a path is a directory or not + * Parses the rmdir request into the command line structure * - * @param path to be checked - * @return true if it's a directory false otherwise + * @param args the request string + * @param req resulting parsed request + * @param eInfo Error information + * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise */ - bool isDir(const char *path) throw(); + int parseRequest(const XrdSfsFSctl &args, ParsedRequest &req, XrdOucErrInfo &eInfo); /** * Checks whether client has correct permissions * - * @param client client information + * @param req parsed request * @param eInfo Error information * @return SFS_OK in case check is passed, SFS_ERROR otherwise */ int checkClient(const XrdSecEntity *client, XrdOucErrInfo &eInfo); - /** - * Parses the archive request into the command line structure - * - * @param args the request string - * @param cmdLine the resulting command line structure - * @param eInfo Error information - * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise - */ - int parseArchiveRequest(const XrdSfsFSctl &args, ParsedArchiveCmdLine &cmdLine, XrdOucErrInfo &eInfo); - /** * Executes the command contained within the command line structure * - * @param cmdLine command to execute + * @param req parsed request * @param eInfo Error information * @return SFS_OK in case executed correctly, SFS_ERROR otherwise */ - int executeArchiveCommand(ParsedArchiveCmdLine &cmdLine, XrdOucErrInfo &eInfo); - - /** - * Parses the create-storage-class request into the command line structure - * - * @param args the request string - * @param cmdLine the resulting command line structure - * @param eInfo Error information - * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise - */ - int parseCreateStorageClassRequest(const XrdSfsFSctl &args, ParsedCreateStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + int executeArchiveCommand(ParsedRequest &req, XrdOucErrInfo &eInfo); /** * Executes the command contained within the command line structure * - * @param cmdLine command to execute + * @param req parsed request * @param eInfo Error information * @return SFS_OK in case executed correctly, SFS_ERROR otherwise */ - int executeCreateStorageClassCommand(ParsedCreateStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); - - /** - * Parses the change-storage-class request into the command line structure - * - * @param args the request string - * @param cmdLine the resulting command line structure - * @param eInfo Error information - * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise - */ - int parseChangeStorageClassRequest(const XrdSfsFSctl &args, ParsedChangeStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + int executeCreateStorageClassCommand(ParsedRequest &req, XrdOucErrInfo &eInfo); /** * Executes the command contained within the command line structure * - * @param cmdLine command to execute + * @param req parsed request * @param eInfo Error information * @return SFS_OK in case executed correctly, SFS_ERROR otherwise */ - int executeChangeStorageClassCommand(ParsedChangeStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); - - /** - * Parses the delete-storage-class request into the command line structure - * - * @param args the request string - * @param cmdLine the resulting command line structure - * @param eInfo Error information - * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise - */ - int parseDeleteStorageClassRequest(const XrdSfsFSctl &args, ParsedDeleteStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + int executeChangeStorageClassCommand(ParsedRequest &req, XrdOucErrInfo &eInfo); /** * Executes the command contained within the command line structure * - * @param cmdLine command to execute + * @param req parsed request * @param eInfo Error information * @return SFS_OK in case executed correctly, SFS_ERROR otherwise */ - int executeDeleteStorageClassCommand(ParsedDeleteStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); - - /** - * Parses the list-storage-class request into the command line structure - * - * @param args the request string - * @param cmdLine the resulting command line structure - * @param eInfo Error information - * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise - */ - int parseListStorageClassRequest(const XrdSfsFSctl &args, ParsedListStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + int executeDeleteStorageClassCommand(ParsedRequest &req, XrdOucErrInfo &eInfo); /** * Executes the command contained within the command line structure * - * @param cmdLine command to execute + * @param req parsed request * @param eInfo Error information * @return SFS_OK in case executed correctly, SFS_ERROR otherwise */ - int executeListStorageClassCommand(ParsedListStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); - - /** - * Parses the mkdir request into the command line structure - * - * @param args the request string - * @param cmdLine the resulting command line structure - * @param eInfo Error information - * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise - */ - int parseMkdirRequest(const XrdSfsFSctl &args, ParsedMkdirCmdLine &cmdLine, XrdOucErrInfo &eInfo); + int executeListStorageClassCommand(ParsedRequest &req, XrdOucErrInfo &eInfo); /** * Executes the command contained within the command line structure * - * @param cmdLine command to execute + * @param req parsed request * @param eInfo Error information * @return SFS_OK in case executed correctly, SFS_ERROR otherwise */ - int executeMkdirCommand(ParsedMkdirCmdLine &cmdLine, XrdOucErrInfo &eInfo); - - /** - * Parses the rmdir request into the command line structure - * - * @param args the request string - * @param cmdLine the resulting command line structure - * @param eInfo Error information - * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise - */ - int parseRmdirRequest(const XrdSfsFSctl &args, ParsedRmdirCmdLine &cmdLine, XrdOucErrInfo &eInfo); + int executeMkdirCommand(ParsedRequest &req, XrdOucErrInfo &eInfo); /** * Executes the command contained within the command line structure * - * @param cmdLine command to execute + * @param req parsed request * @param eInfo Error information * @return SFS_OK in case executed correctly, SFS_ERROR otherwise */ - int executeRmdirCommand(ParsedRmdirCmdLine &cmdLine, XrdOucErrInfo &eInfo); + int executeRmdirCommand(ParsedRequest &req, XrdOucErrInfo &eInfo); /** * Dispatches the request based on the query