diff --git a/proto/Response.proto b/proto/Response.proto index cce31783c6476c823955e0abf5eedce93b2679c1..216a990210406b4c6d86e62cce80f61e6f2f3932 100644 --- a/proto/Response.proto +++ b/proto/Response.proto @@ -4,8 +4,13 @@ message Response { enum State { - ACCEPTED = 0; - REJECTED = 1; + REQUEST_ACCEPTED = 0; + ACCESS_DENY = 1; + TABLE_NOT_EXPORTED = 2; + METADATA_NOT_FOUND = 3; + FILE_NOT_DOWNLOADED = 4; + FILE_NOT_FOUND = 5; + GENERIC_ERROR = 6; } required State state = 1; diff --git a/src/DBManager.cpp b/src/DBManager.cpp index fe0639b4bdbba4dbbd47e3d062674a66dd2a2620..084bd4add6555e30ca9d0bc1e35ee6506afefbdd 100644 --- a/src/DBManager.cpp +++ b/src/DBManager.cpp @@ -19,7 +19,7 @@ DBManager::DBManager(Tango::DeviceImpl* deviceImpl_p, } //============================================================================== -// DBManager::DBManager() +// DBManager::~DBManager() //============================================================================== DBManager::~DBManager() { @@ -27,7 +27,7 @@ DBManager::~DBManager() } //============================================================================== -// DBManager::DBManager() +// DBManager::create() //============================================================================== DBManager::SP DBManager::create(Tango::DeviceImpl* deviceImpl_p, Configuration::SP configuration_sp) @@ -82,7 +82,7 @@ void DBManager::disconnect() //============================================================================== DBManager::FileTuple DBManager::retrieveFileInfo(std::string schema, std::string table, int version, std::string name) - throw(soci::soci_error, std::runtime_error) + throw(soci::soci_error) { DEBUG_STREAM << "DBManager::retrieveFileInfo()" << endl; @@ -108,7 +108,7 @@ DBManager::FileTuple DBManager::retrieveFileInfo(std::string schema, std::stringstream errorStream; errorStream << "Table " << schema << "." << table << " does not contain file " << name << " version " << version; - throw std::runtime_error(errorStream.str()); + throw soci::soci_error(errorStream.str()); } if(fileTupleList.size()>1) @@ -116,7 +116,7 @@ DBManager::FileTuple DBManager::retrieveFileInfo(std::string schema, std::stringstream errorStream; errorStream << "Table " << schema << "." << table << " has duplicate for file " << name << " version " << version; - throw std::runtime_error(errorStream.str()); + throw soci::soci_error(errorStream.str()); } return fileTupleList.at(0); diff --git a/src/DBManager.h b/src/DBManager.h index 747eddda01168db80831fd18f1574600114ae993..4315538039e5a5f8c0bc617c62282ec2312ed4b2 100644 --- a/src/DBManager.h +++ b/src/DBManager.h @@ -67,8 +67,8 @@ public: typedef boost::tuple< boost::optional<std::string>, boost::optional<std::string> > FileTuple; - virtual FileTuple retrieveFileInfo(std::string, std::string, int, - std::string) throw(soci::soci_error, std::runtime_error); + virtual FileTuple retrieveFileInfo(std::string, std::string, int, std::string) + throw(soci::soci_error); protected: //------------------------------------------------------------------------------ diff --git a/src/FileManager.cpp b/src/FileManager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e10e0ff068fda8853fa0462417ee92746a791582 --- /dev/null +++ b/src/FileManager.cpp @@ -0,0 +1,82 @@ +#include <FileManager.h> +#include <stdexcept> + +namespace DataExporter_ns +{ + +//============================================================================== +// FileManager::FileManager() +//============================================================================== +FileManager::FileManager(Tango::DeviceImpl* deviceImpl_p, + boost::filesystem::path& path) : Tango::LogAdapter(deviceImpl_p) +{ + DEBUG_STREAM << "FileManager::FileManager()" << endl; + + m_inputFileStream.open(path.string(), std::ios::binary | std::ios::ate); + + m_inputFileSize = m_inputFileStream.tellg(); + + m_inputFileStream.seekg(0, m_inputFileStream.beg); +} + +//============================================================================== +// FileManager::~FileManager() +//============================================================================== +FileManager::~FileManager() +{ + DEBUG_STREAM << "FileManager::~FileManager()" << endl; + + m_inputFileStream.close(); +} + +//============================================================================== +// FileManager::create() +//============================================================================== +FileManager::SP FileManager::create(Tango::DeviceImpl* deviceImpl_p, + boost::filesystem::path& path) +{ + FileManager::SP d_sp(new FileManager(deviceImpl_p, path), + FileManager::Deleter()); + + return d_sp; +} + +//============================================================================== +// FileManager::isOpen() +//============================================================================== +bool FileManager::isOpen() +{ + return m_inputFileStream.is_open(); +} + +//============================================================================== +// FileManager::isCompleted() +//============================================================================== +bool FileManager::isCompleted() +{ + return m_inputFileStream.tellg() >= m_inputFileSize; +} + +//============================================================================== +// FileManager::read() +//============================================================================== +void FileManager::read(std::vector<char>& writeBuff) throw(std::runtime_error) +{ + if(m_inputFileStream.tellg() >= m_inputFileSize) + throw std::runtime_error("Already completed"); + + int leftToRead = m_inputFileSize - m_inputFileStream.tellg(); + + int bufferSize = 0; + + if(leftToRead < BUFFER_SIZE) + bufferSize = leftToRead; + else + bufferSize = BUFFER_SIZE; + + writeBuff.resize(bufferSize); + + m_inputFileStream.read(&writeBuff[0], bufferSize); +} + +} diff --git a/src/FileManager.h b/src/FileManager.h new file mode 100644 index 0000000000000000000000000000000000000000..58aff7dc50c5e7b8fac940929e80f45b5e2cc60f --- /dev/null +++ b/src/FileManager.h @@ -0,0 +1,68 @@ +#ifndef FILEMANAGER_H +#define FILEMANAGER_H + +#include <Configuration.h> + +#include <tango.h> + +#include <boost/filesystem.hpp> + +namespace DataExporter_ns +{ + +class FileManager : public Tango::LogAdapter +{ +public: +//------------------------------------------------------------------------------ +// [Public] Shared pointer typedef +//------------------------------------------------------------------------------ + typedef boost::shared_ptr<FileManager> SP; + +protected: +//------------------------------------------------------------------------------ +// [Protected] Constructor destructor deleter +//------------------------------------------------------------------------------ + FileManager(Tango::DeviceImpl*, boost::filesystem::path&); + + virtual ~FileManager(); + + class Deleter; + friend Deleter; + class Deleter + { + public: + void operator()(FileManager* d) { delete d; } + }; + +public: +//------------------------------------------------------------------------------ +// [Public] Class creation method +//------------------------------------------------------------------------------ + static FileManager::SP create(Tango::DeviceImpl*, boost::filesystem::path&); + +//------------------------------------------------------------------------------ +// [Public] Input stream methods +//------------------------------------------------------------------------------ + virtual bool isOpen(); + + virtual bool isCompleted(); + + virtual void read(std::vector<char>&) throw(std::runtime_error); + +protected: +//------------------------------------------------------------------------------ +// [Protected] Class variables +//------------------------------------------------------------------------------ + //Input file size + int m_inputFileSize; + + //Input file stream + std::ifstream m_inputFileStream; + + //Read buffer size + const int BUFFER_SIZE = 1024; +}; + +} //End of namespace + +#endif /* FILEMANAGER_H */ diff --git a/src/PlainSession.cpp b/src/PlainSession.cpp index e6071e6261d81446180d306401516f6993d7e18b..a8c6a631e947815323bda5ac005b189c877c6980 100644 --- a/src/PlainSession.cpp +++ b/src/PlainSession.cpp @@ -163,8 +163,6 @@ void PlainSession::startWriteResponse() //============================================================================== void PlainSession::startWriteData() { - //DEBUG_STREAM << "PlainSession::startWriteData()" << endl; - try { if(!m_inputStream.bad()) @@ -173,8 +171,6 @@ void PlainSession::startWriteData() { int leftToRead = m_inputStreamSize - m_inputStream.tellg(); - //DEBUG_STREAM << "PlainSession::startWriteData() left to read " << leftToRead << endl; - int bufferSize = 0; if(leftToRead < BUFFER_SIZE) @@ -182,8 +178,6 @@ void PlainSession::startWriteData() else bufferSize = BUFFER_SIZE; - //DEBUG_STREAM << "PlainSession::startWriteData() buffer size " << bufferSize << endl; - std::vector<char> writeBuff; writeBuff.resize(bufferSize); diff --git a/src/ProtocolManager.cpp b/src/ProtocolManager.cpp index c8c7c16b9dc8de97e710adee9c1520d98606a127..d7da7eb88fc3e73eadfd53f07a32d9c5b017e135 100644 --- a/src/ProtocolManager.cpp +++ b/src/ProtocolManager.cpp @@ -1,7 +1,7 @@ #include <ProtocolManager.h> #include <boost/date_time.hpp> -#include <boost/filesystem.hpp> + namespace DataExporter_ns { @@ -15,10 +15,6 @@ ProtocolManager::ProtocolManager(Tango::DeviceImpl* deviceImpl_p, m_dBManager_sp(dBManager_sp) { DEBUG_STREAM << "ProtocolManager::ProtocolManager()" << endl; - - m_isAuthorised = false; - m_isValidated = false; - m_isTransferRequest = false; } //============================================================================== @@ -52,7 +48,7 @@ void ProtocolManager::setRemoteEndpoint(std::string remoteEndpoint) } //============================================================================== -// ProtocolManager::setRemoteEndpoint() +// ProtocolManager::prepareResponse() //============================================================================== ResponseSP ProtocolManager::prepareResponse(RequestSP request_sp) throw(std::runtime_error) @@ -62,305 +58,122 @@ ResponseSP ProtocolManager::prepareResponse(RequestSP request_sp) if(!request_sp->IsInitialized()) throw std::runtime_error("Not initialized request!"); - ResponseSP response_sp; - - switch(request_sp->type()) - { - case Request::AUTHORIZATION: - { - response_sp = prepareAuthroisation(request_sp); - break; - } - case Request::VALIDATION: - { - response_sp = prepareValidation(request_sp); - break; - } - case Request::TRANSFER: - { - response_sp = prepareTransfer(request_sp); - break; - } - case Request::KEEPALIVE: - { - response_sp = prepareKeepAlive(request_sp); - break; - } - default: - throw std::runtime_error("Unknown request type!"); - } - - if(!response_sp->IsInitialized()) - throw std::runtime_error("Not initialized response!"); - - return response_sp; -} - -//============================================================================== -// ProtocolManager::isTransferRequest() -//============================================================================== -bool ProtocolManager::isTransferRequest() -{ - DEBUG_STREAM << "ProtocolManager::isTransferRequest()" << endl; - - return m_isTransferRequest; -} - -//============================================================================== -// ProtocolManager::getFilePath() -//============================================================================== -std::string ProtocolManager::getFilePath() -{ - DEBUG_STREAM << "ProtocolManager::getFilePath()" << endl; - - return m_filePath; -} - -//============================================================================== -// ProtocolManager::getFileSize() -//============================================================================== -int ProtocolManager::getFileSize() -{ - DEBUG_STREAM << "ProtocolManager::getFileSize()" << endl; - - return m_fileSize; -} - -//============================================================================== -// ProtocolManager::prepareAuthroisation() -//============================================================================== -ResponseSP ProtocolManager::prepareAuthroisation(RequestSP request_sp) -{ - DEBUG_STREAM << "ProtocolManager::prepareAuthroisation()" << endl; + std::string username = request_sp->username(); + std::string password = request_sp->password(); ResponseSP response_sp(new Response()); - response_sp->set_type(Response::AUTHORIZATION); - - Response::Authorization* authResp = response_sp->mutable_authorization(); - - if(!m_isAuthorised) + if(m_configuration_sp->isUserAuthorized(username, password)) { - const Request::Authorization& authReq = request_sp->authorization(); - std::string username = authReq.username(); - std::string password = authReq.password(); + std::string schema = request_sp->schema(); + std::string table =request_sp->table(); - if(m_configuration_sp->isUserAuthorized(username, password)) + if(m_configuration_sp->isTableExported(schema, table)) { - INFO_STREAM << "ProtocolManager::prepareAuthroisation() " - << "Authorization accepted from " << m_remoteEndpoint << endl; - - m_isAuthorised = true; - - authResp->set_state(Response::Authorization::ACCEPTED); - authResp->set_status("Authorization accepted"); - } - else - { - WARN_STREAM << "ProtocolManager::prepareAuthroisation() " - << "Invalid username or password from " << m_remoteEndpoint << endl; - - m_isAuthorised = false; - - authResp->set_state(Response::Authorization::REJECTED); - authResp->set_status("Invalid username or password"); - } - } - else - { - WARN_STREAM << "ProtocolManager::prepareAuthroisation() " - << "Already authorized from " << m_remoteEndpoint << endl; - - authResp->set_state(Response::Authorization::REJECTED); - authResp->set_status("Already authorized"); - } - - return response_sp; -} - -//============================================================================== -// ProtocolManager::prepareValidation() -//============================================================================== -ResponseSP ProtocolManager::prepareValidation(RequestSP request_sp) -{ - DEBUG_STREAM << "ProtocolManager::prepareValidation()" << endl; - - ResponseSP response_sp(new Response()); - - response_sp->set_type(Response::VALIDATION); - - Response::Validation* validationRes = response_sp->mutable_validation(); - - if(m_isAuthorised) - { - if(!m_isValidated) - { - const Request::Validation& validationReq = request_sp->validation(); - - m_validatedSchema = validationReq.schema(); - m_validatedTable = validationReq.table(); - - if(m_configuration_sp->isTableExported(m_validatedSchema, m_validatedTable)) - { - INFO_STREAM << "ProtocolManager::prepareValidation() " - << "Validation accepted for " << m_validatedSchema << "." - << m_validatedTable << " from " << m_remoteEndpoint << endl; - - m_isValidated = true; - - validationRes->set_state(Response::Validation::ACCEPTED); - validationRes->set_status("Table validated"); - } - else - { - WARN_STREAM << "ProtocolManager::prepareValidation() " - << "Not exported table from " << m_remoteEndpoint << endl; - - validationRes->set_state(Response::Validation::REJECTED); - validationRes->set_status("Not exported table"); - } - } - else - { - WARN_STREAM << "ProtocolManager::prepareValidation() " - << "Already validated from " << m_remoteEndpoint << endl; - - validationRes->set_state(Response::Validation::REJECTED); - validationRes->set_status("Already validated"); - } - } - else - { - WARN_STREAM << "ProtocolManager::prepareValidation() " - << "Not authorised from " << m_remoteEndpoint << endl; - - validationRes->set_state(Response::Validation::REJECTED); - validationRes->set_status("Not authorised"); - } - - return response_sp; -} - -//============================================================================== -// ProtocolManager::prepareTransfer() -//============================================================================== -ResponseSP ProtocolManager::prepareTransfer(RequestSP request_sp) -{ - DEBUG_STREAM << "ProtocolManager::prepareTransfer()" << endl; - - ResponseSP response_sp(new Response()); - - response_sp->set_type(Response::TRANSFER); - - Response::Transfer* transferRes = response_sp->mutable_transfer(); - - if(m_isAuthorised) - { - if(m_isValidated) - { - const Request::Transfer& transferReq = request_sp->transfer(); - - int fileVersion = transferReq.file_version(); - std::string fileName = transferReq.file_name(); + int fileVersion = request_sp->file_version(); + std::string fileName = request_sp->file_name(); try { - m_isTransferRequest = false; + DBManager::FileTuple fileTuple = m_dBManager_sp->retrieveFileInfo( + schema, table, fileVersion, fileName); - DBManager::FileTuple fileTuple = - m_dBManager_sp->retrieveFileInfo(m_validatedSchema, - m_validatedTable, fileVersion, fileName); - - if(!fileTuple.get<0>() || !fileTuple.get<1>()) + if(fileTuple.get<0>() && fileTuple.get<1>()) { - std::stringstream errorStream; - errorStream << "File " << fileName << " version " - << fileVersion << " not yet downloaded in storage"; - throw std::runtime_error(errorStream.str()); + std::string storagePath = fileTuple.get<0>().get(); + std::string filePath = fileTuple.get<1>().get(); + + boost::filesystem::path absolutePath = composePath( + storagePath, filePath, fileVersion,fileName); + + if(boost::filesystem::is_regular_file(absolutePath)) + { + boost::uint64_t fileSize = + boost::filesystem::file_size(absolutePath); + + DEBUG_STREAM << "ProtocolManager::prepareResponse() " + << "file size " << fileSize << endl; + + response_sp->set_state(Response::REQUEST_ACCEPTED); + response_sp->set_status("Request accepted"); + + response_sp->set_file_path(filePath); + response_sp->set_file_version(fileVersion); + response_sp->set_file_name(fileName); + response_sp->set_size(fileSize); + } + else + { + WARN_STREAM << "ProtocolManager::prepareResponse() file " + << "not found from " << m_remoteEndpoint << endl; + + response_sp->set_state(Response::FILE_NOT_FOUND); + response_sp->set_status("File not found"); + } } - - std::string storagePath = fileTuple.get<0>().get(); - boost::filesystem::path absPath(storagePath); - - std::string filePath = fileTuple.get<1>().get(); - boost::filesystem::path relPath(filePath); - - absPath /= relPath; - - std::stringstream pathStream; - pathStream << "/" << fileVersion << "/" << fileName; - boost::filesystem::path lastPath(pathStream.str()); - - absPath /= lastPath; - - DEBUG_STREAM << "FILE: " << absPath.string() << endl; - - if(!boost::filesystem::is_regular_file(absPath)) + else { - std::stringstream errorStream; - errorStream << "File " << fileName << " version " - << fileVersion << " not exists in storage"; - throw std::runtime_error(errorStream.str()); - } - - transferRes->set_file_path(filePath); - transferRes->set_file_version(fileVersion); - transferRes->set_file_name(fileName); - transferRes->set_size(boost::filesystem::file_size(absPath)); - - transferRes->set_state(Response::Transfer::ACCEPTED); - transferRes->set_status("File found"); + WARN_STREAM << "ProtocolManager::prepareResponse() file not " + << "downloaded from " << m_remoteEndpoint << endl; - m_isTransferRequest = true; - m_filePath = absPath.string(); - m_fileSize = boost::filesystem::file_size(absPath); + response_sp->set_state(Response::FILE_NOT_DOWNLOADED); + response_sp->set_status("File not downloaded"); + } } - catch(std::exception& ex) + catch(soci::soci_error& ex) { - WARN_STREAM << "ProtocolManager::prepareMetadata() " + WARN_STREAM << "ProtocolManager::prepareResponse() " << ex.what() << " from " << m_remoteEndpoint << endl; - transferRes->set_state(Response::Transfer::REJECTED); - transferRes->set_status(ex.what()); + response_sp->set_state(Response::METADATA_NOT_FOUND); + response_sp->set_status(ex.what()); } } else { - WARN_STREAM << "ProtocolManager::prepareMetadata() " - << "Not validated from " << m_remoteEndpoint << endl; + WARN_STREAM << "ProtocolManager::prepareResponse() " + << "Not exported table from " << m_remoteEndpoint << endl; - transferRes->set_state(Response::Transfer::REJECTED); - transferRes->set_status("Not validated"); + response_sp->set_state(Response::TABLE_NOT_EXPORTED); + response_sp->set_status("Table not exported"); } } else { - WARN_STREAM << "ProtocolManager::prepareData() " - << "Not authorised from " << m_remoteEndpoint << endl; + WARN_STREAM << "ProtocolManager::prepareResponse() Invalid username " + << "or password from " << m_remoteEndpoint << endl; - transferRes->set_state(Response::Transfer::REJECTED); - transferRes->set_status("Not authorised"); + response_sp->set_state(Response::ACCESS_DENY); + response_sp->set_status("Invalid credential"); } + if(!response_sp->IsInitialized()) + throw std::runtime_error("Not initialized response!"); + return response_sp; } //============================================================================== -// ProtocolManager::prepareKeepAlive() +// ProtocolManager::composePath() //============================================================================== -ResponseSP ProtocolManager::prepareKeepAlive(RequestSP request_sp) +boost::filesystem::path ProtocolManager::composePath(std::string storagePath, + std::string filePath, int fileVersion, std::string fileName) { - ResponseSP response_sp(new Response()); + DEBUG_STREAM << "ProtocolManager::composePath()" << endl; - response_sp->set_type(Response::KEEPALIVE); + boost::filesystem::path absolutePath(storagePath); - m_isTransferRequest = false; + absolutePath /= filePath; - m_filePath.clear(); + std::stringstream fileStream; + fileStream << "/" << fileVersion << "/" << fileName; - m_fileSize = 0; + absolutePath /= fileStream.str(); - return response_sp; + DEBUG_STREAM << "ProtocolManager::composePath() " + << absolutePath.string() << endl; + + return absolutePath; } } //namespace diff --git a/src/ProtocolManager.h b/src/ProtocolManager.h index 9b38336edfc9b63b081ed92bae2ee885a21365a5..b2468b738ebd9b8699f4384e66ccd25337fcef40 100644 --- a/src/ProtocolManager.h +++ b/src/ProtocolManager.h @@ -8,6 +8,8 @@ #include <tango.h> +#include <boost/filesystem.hpp> + namespace DataExporter_ns { @@ -59,26 +61,12 @@ public: virtual ResponseSP prepareResponse(RequestSP) throw(std::runtime_error); -//------------------------------------------------------------------------------ -// [Public] File transfer methods -//------------------------------------------------------------------------------ - virtual bool isTransferRequest(); - - virtual std::string getFilePath(); - - virtual int getFileSize(); - protected: //------------------------------------------------------------------------------ -// [Protected] Request specific methods +// [Protected] //------------------------------------------------------------------------------ - virtual ResponseSP prepareAuthroisation(RequestSP); - - virtual ResponseSP prepareValidation(RequestSP); - - virtual ResponseSP prepareTransfer(RequestSP); - - virtual ResponseSP prepareKeepAlive(RequestSP); + virtual boost::filesystem::path composePath(std::string, std::string, + int, std::string); //------------------------------------------------------------------------------ // [Protected] Class variables @@ -89,26 +77,8 @@ protected: //Database manger shared pointer DBManager::SP m_dBManager_sp; - //Client is authorised - bool m_isAuthorised; - - //Table is validated - bool m_isValidated; - - //Validate schema name - std::string m_validatedSchema; - - //Validate table name - std::string m_validatedTable; - //Address and port of remote endpoint std::string m_remoteEndpoint; - - bool m_isTransferRequest; - - std::string m_filePath; - - int m_fileSize; }; } //End of namespace diff --git a/src/Response.pb.cc b/src/Response.pb.cc index 26e3bef603a31fdcefc0f6ce668d9952570b562a..e1f94d607d51eedd2e92724f71e661cf4b70920e 100644 --- a/src/Response.pb.cc +++ b/src/Response.pb.cc @@ -85,12 +85,15 @@ void protobuf_AddDesc_Response_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - "\n\016Response.proto\022\017DataExporter_ns\"\271\001\n\010Re" + "\n\016Response.proto\022\017DataExporter_ns\"\265\002\n\010Re" "sponse\022.\n\005state\030\001 \002(\0162\037.DataExporter_ns." "Response.State\022\016\n\006status\030\002 \002(\t\022\021\n\tfile_p" "ath\030\003 \001(\t\022\024\n\014file_version\030\004 \001(\005\022\021\n\tfile_" - "name\030\005 \001(\t\022\014\n\004size\030\006 \001(\004\"#\n\005State\022\014\n\010ACC" - "EPTED\020\000\022\014\n\010REJECTED\020\001", 221); + "name\030\005 \001(\t\022\014\n\004size\030\006 \001(\004\"\236\001\n\005State\022\024\n\020RE" + "QUEST_ACCEPTED\020\000\022\017\n\013ACCESS_DENY\020\001\022\026\n\022TAB" + "LE_NOT_EXPORTED\020\002\022\026\n\022METADATA_NOT_FOUND\020" + "\003\022\027\n\023FILE_NOT_DOWNLOADED\020\004\022\022\n\016FILE_NOT_F" + "OUND\020\005\022\021\n\rGENERIC_ERROR\020\006", 345); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "Response.proto", &protobuf_RegisterTypes); Response::default_instance_ = new Response(); @@ -115,6 +118,11 @@ bool Response_State_IsValid(int value) { switch(value) { case 0: case 1: + case 2: + case 3: + case 4: + case 5: + case 6: return true; default: return false; @@ -122,8 +130,13 @@ bool Response_State_IsValid(int value) { } #ifndef _MSC_VER -const Response_State Response::ACCEPTED; -const Response_State Response::REJECTED; +const Response_State Response::REQUEST_ACCEPTED; +const Response_State Response::ACCESS_DENY; +const Response_State Response::TABLE_NOT_EXPORTED; +const Response_State Response::METADATA_NOT_FOUND; +const Response_State Response::FILE_NOT_DOWNLOADED; +const Response_State Response::FILE_NOT_FOUND; +const Response_State Response::GENERIC_ERROR; const Response_State Response::State_MIN; const Response_State Response::State_MAX; const int Response::State_ARRAYSIZE; diff --git a/src/Response.pb.h b/src/Response.pb.h index d78346a3113b21466604b589d349ced046bfc8ce..c810e040841aa4429d657adfea3b07bed1f99525 100644 --- a/src/Response.pb.h +++ b/src/Response.pb.h @@ -37,12 +37,17 @@ void protobuf_ShutdownFile_Response_2eproto(); class Response; enum Response_State { - Response_State_ACCEPTED = 0, - Response_State_REJECTED = 1 + Response_State_REQUEST_ACCEPTED = 0, + Response_State_ACCESS_DENY = 1, + Response_State_TABLE_NOT_EXPORTED = 2, + Response_State_METADATA_NOT_FOUND = 3, + Response_State_FILE_NOT_DOWNLOADED = 4, + Response_State_FILE_NOT_FOUND = 5, + Response_State_GENERIC_ERROR = 6 }; bool Response_State_IsValid(int value); -const Response_State Response_State_State_MIN = Response_State_ACCEPTED; -const Response_State Response_State_State_MAX = Response_State_REJECTED; +const Response_State Response_State_State_MIN = Response_State_REQUEST_ACCEPTED; +const Response_State Response_State_State_MAX = Response_State_GENERIC_ERROR; const int Response_State_State_ARRAYSIZE = Response_State_State_MAX + 1; const ::google::protobuf::EnumDescriptor* Response_State_descriptor(); @@ -110,8 +115,13 @@ class Response : public ::google::protobuf::Message { // nested types ---------------------------------------------------- typedef Response_State State; - static const State ACCEPTED = Response_State_ACCEPTED; - static const State REJECTED = Response_State_REJECTED; + static const State REQUEST_ACCEPTED = Response_State_REQUEST_ACCEPTED; + static const State ACCESS_DENY = Response_State_ACCESS_DENY; + static const State TABLE_NOT_EXPORTED = Response_State_TABLE_NOT_EXPORTED; + static const State METADATA_NOT_FOUND = Response_State_METADATA_NOT_FOUND; + static const State FILE_NOT_DOWNLOADED = Response_State_FILE_NOT_DOWNLOADED; + static const State FILE_NOT_FOUND = Response_State_FILE_NOT_FOUND; + static const State GENERIC_ERROR = Response_State_GENERIC_ERROR; static inline bool State_IsValid(int value) { return Response_State_IsValid(value); } diff --git a/src/SSLSession.cpp b/src/SSLSession.cpp index 13d34fc673232c6704278b49bd3f6818e0c45df1..02a29b87e450687fbe64eab9454f573bcafa7a4f 100644 --- a/src/SSLSession.cpp +++ b/src/SSLSession.cpp @@ -198,18 +198,14 @@ void SSLSession::startWriteResponse() //============================================================================== void SSLSession::startWriteData() { - //DEBUG_STREAM << "SSLSession::startWriteData()" << endl; - try { if(!m_inputStream.bad()) { - if(m_inputStream.tellg()<m_inputStreamSize) + if(m_inputStream.tellg() < m_inputStreamSize) { int leftToRead = m_inputStreamSize - m_inputStream.tellg(); - //DEBUG_STREAM << "SSLSession::startWriteData() left to read " << leftToRead << endl; - int bufferSize = 0; if(leftToRead < BUFFER_SIZE) @@ -217,8 +213,6 @@ void SSLSession::startWriteData() else bufferSize = BUFFER_SIZE; - //DEBUG_STREAM << "SSLSession::startWriteData() buffer size " << bufferSize << endl; - std::vector<char> writeBuff; writeBuff.resize(bufferSize); diff --git a/src/Session.cpp b/src/Session.cpp index b7472b63e7889edca99a7430f63bda2b0ce90865..56af6c25eeffbd299e5183b9b50f7cb95e93d968 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -82,36 +82,14 @@ void Session::handleWriteResponse(const boost::system::error_code& errorCode) if(!errorCode) { - if(m_protocolManager_sp->isTransferRequest()) - { - std::string filePath = m_protocolManager_sp->getFilePath(); - int fileSize = m_protocolManager_sp->getFileSize(); - - INFO_STREAM << "Session::handleWriteResponse() transfer request " - << filePath << " size " << fileSize << " from " - << m_remoteEndpoint << endl; - - m_inputStreamSize = fileSize; - - if(m_inputStream.is_open()) - m_inputStream.close(); - - m_inputStream.open(filePath.c_str(), std::ios::binary); - - if(m_inputStream) - { - startWriteData(); - } - else - { - ERROR_STREAM << "Session::handleWriteResponse() Cannot open " - << filePath << endl; - } - } - else - { - startReadRequestHeader(); - } +// if() +// { +// //TODO: open file and start read +// } +// else +// { +// startReadRequestHeader(); +// } } else if(errorCode == boost::asio::error::eof) { @@ -130,8 +108,6 @@ void Session::handleWriteResponse(const boost::system::error_code& errorCode) //============================================================================== void Session::handleWriteData(const boost::system::error_code& errorCode) { - //DEBUG_STREAM << "Session::handleWriteData()" << endl; - if(!errorCode) { startWriteData(); diff --git a/src/Session.h b/src/Session.h index 5f7b2cc7b9868a204165199087e7b7e2cf957a2a..8ff8cc82be121d2b6a48d3b0eeffcff2f214ad9c 100644 --- a/src/Session.h +++ b/src/Session.h @@ -98,6 +98,7 @@ protected: //Address and port of remote endpoint std::string m_remoteEndpoint; + //TODO: to delete const int BUFFER_SIZE = 1024; std::ifstream m_inputStream;