From 559752a3b96250571eb9f4ff44d0210bb48d8c9f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 11 Dec 2016 23:00:15 +0100 Subject: [PATCH] [DEV] add sha512 calculation and catche exception std::xxx when have an error on functioncall in RPC --- tools/router/appl/main-router.cpp | 4 ++ .../appl/main-service-picture.cpp | 14 +++++ zeus/AbstractFunctionTypeClass.hpp | 56 ++++++++++++++++++- zeus/AbstractFunctionTypeDirect.hpp | 56 ++++++++++++++++++- zeus/Raw.cpp | 3 +- zeus/message/Parameter_getParameter.cpp | 8 ++- zeus/zeus-File.obj.zeus.idl | 9 +++ 7 files changed, 143 insertions(+), 7 deletions(-) diff --git a/tools/router/appl/main-router.cpp b/tools/router/appl/main-router.cpp index 6a55d26..14ca99f 100644 --- a/tools/router/appl/main-router.cpp +++ b/tools/router/appl/main-router.cpp @@ -11,10 +11,14 @@ #include +#include int main(int _argc, const char *_argv[]) { etk::init(_argc, _argv); zeus::init(_argc, _argv); + //std::string OUT2 = algue::stringConvert(algue::sha512::encode("jkhlkjhlkjhlkjhlkjhlkjhlkjhiugouuyrtfkvjhbnj,owixhuvkfn r;,dcxwjo ppxicodsn,kwp #include +#include #include #include @@ -204,6 +205,9 @@ namespace appl { APPL_ERROR("size : " << futSize.get()); int64_t retSize = futSize.get(); int64_t offset = 0; + algue::Sha512 shaCtx; + etk::FSNode nodeFile(g_basePath + "tmpImport_" + etk::to_string(id)); + nodeFile.fileOpenWrite(); while (retSize > 0) { int32_t nbElement = 1*1024*1024; if (retSize Receive FILE " << _dataFile.getMineType() << " size=" << _dataFile.getData().size()); diff --git a/zeus/AbstractFunctionTypeClass.hpp b/zeus/AbstractFunctionTypeClass.hpp index ce96055..192ed7f 100644 --- a/zeus/AbstractFunctionTypeClass.hpp +++ b/zeus/AbstractFunctionTypeClass.hpp @@ -151,8 +151,60 @@ namespace zeus { return; } } - // execute cmd: - zeus::executeClassCall(_interfaceClient, _obj, tmpClass, m_function); + try { + // execute cmd: + zeus::executeClassCall(_interfaceClient, _obj, tmpClass, m_function); + } catch (const std::logic_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LOGIC-ERROR", eee.what()); + return true; + }); + } catch (const std::invalid_argument& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "INVALID-ARGUMENT", eee.what()); + return true; + }); + } catch (const std::domain_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "DOMAIN-ERROR", eee.what()); + return true; + }); + } catch (const std::length_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LENGTH-ERROR", eee.what()); + return true; + }); + } catch (const std::out_of_range& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OUT-OF-RANGE", eee.what()); + return true; + }); + } catch (const std::runtime_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RUNTIME-ERROR", eee.what()); + return true; + }); + } catch (const std::range_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RANGE-ERROR", eee.what()); + return true; + }); + } catch (const std::overflow_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OVERFLOW-ERROR", eee.what()); + return true; + }); + } catch (const std::underflow_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "UNDERFLOW-ERROR", eee.what()); + return true; + }); + } catch ( ... ) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "?-ERROR", "catch unknow error"); + return true; + }); + } } }; // specialization diff --git a/zeus/AbstractFunctionTypeDirect.hpp b/zeus/AbstractFunctionTypeDirect.hpp index 5d644b4..c72c597 100644 --- a/zeus/AbstractFunctionTypeDirect.hpp +++ b/zeus/AbstractFunctionTypeDirect.hpp @@ -139,8 +139,60 @@ namespace zeus { return; } } - // execute cmd: - zeus::executeCall(_interfaceClient, _obj, m_function); + try { + // execute cmd: + zeus::executeCall(_interfaceClient, _obj, m_function); + } catch (const std::logic_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LOGIC-ERROR", eee.what()); + return true; + }); + } catch (const std::invalid_argument& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "INVALID-ARGUMENT", eee.what()); + return true; + }); + } catch (const std::domain_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "DOMAIN-ERROR", eee.what()); + return true; + }); + } catch (const std::length_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LENGTH-ERROR", eee.what()); + return true; + }); + } catch (const std::out_of_range& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OUT-OF-RANGE", eee.what()); + return true; + }); + } catch (const std::runtime_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RUNTIME-ERROR", eee.what()); + return true; + }); + } catch (const std::range_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RANGE-ERROR", eee.what()); + return true; + }); + } catch (const std::overflow_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OVERFLOW-ERROR", eee.what()); + return true; + }); + } catch (const std::underflow_error& eee) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "UNDERFLOW-ERROR", eee.what()); + return true; + }); + } catch ( ... ) { + _interfaceClient->addAsync([=](WebServer* _interface) { + _interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "?-ERROR", "catch unknow error"); + return true; + }); + } } }; // specialization diff --git a/zeus/Raw.cpp b/zeus/Raw.cpp index 8f1aaae..6943000 100644 --- a/zeus/Raw.cpp +++ b/zeus/Raw.cpp @@ -20,13 +20,14 @@ zeus::Raw::Raw(uint32_t _size) : m_dataExternal(nullptr), m_dataInternal() { m_dataInternal.resize(_size); + ZEUS_ERROR("Create BUFFER 1 : " << m_size); } zeus::Raw::Raw(uint32_t _size, const uint8_t* _data) : m_size(_size), m_dataExternal(_data), m_dataInternal() { - + ZEUS_ERROR("Create BUFFER 2 : " << m_size); } zeus::Raw::~Raw() { diff --git a/zeus/message/Parameter_getParameter.cpp b/zeus/message/Parameter_getParameter.cpp index a549dbf..dc7ece5 100644 --- a/zeus/message/Parameter_getParameter.cpp +++ b/zeus/message/Parameter_getParameter.cpp @@ -1444,8 +1444,12 @@ namespace zeus { // TODO : Check size ... if (createType() == type) { // get size if the file in int32_t - uint32_t size = 0; - memcpy(&size, pointer, sizeof(uint32_t)); + #if 0 + uint32_t size = 0; + memcpy(&size, pointer, sizeof(uint32_t)); + #else + uint32_t size = dataSize; + #endif return zeus::Raw(size, &pointer[sizeof(uint32_t)]); } ZEUS_ERROR("Can not get type from '" << type << "'"); diff --git a/zeus/zeus-File.obj.zeus.idl b/zeus/zeus-File.obj.zeus.idl index b880fbb..0a042d7 100644 --- a/zeus/zeus-File.obj.zeus.idl +++ b/zeus/zeus-File.obj.zeus.idl @@ -3,6 +3,9 @@ #elem-type:FILE #elem-author:Heero Yui +#param:_fileName: Name of the local file to instanciate +//factory obj:zeus-File + #brief:Get size of the file #return:current size of the file uint64 getSize() @@ -20,3 +23,9 @@ string getMineType() #param:_stop:Stop position in the file #return:Buffer with the data raw getPart(uint64, uint64) + + +#brief:Store all the data in a specific file +#param:_file: Handle on the file +#param:_filename:Local filename +//tool void storeInTemporaryFile(obj:zeus-File, string)