[DEV] add sha512 calculation and catche exception std::xxx when have an error on functioncall in RPC
This commit is contained in:
parent
d439fb5bc2
commit
559752a3b9
@ -11,10 +11,14 @@
|
||||
|
||||
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <algue/sha512.hpp>
|
||||
|
||||
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<uivfknejc<wxphogkbezdsj<cxhwdséznreS<WJCXHKJ"));
|
||||
//APPL_PRINT("2: " << OUT2);
|
||||
//return 0;
|
||||
appl::Router basicRouter;
|
||||
for (int32_t iii=0; iii<_argc ; ++iii) {
|
||||
std::string data = _argv[iii];
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include <etk/stdTools.hpp>
|
||||
#include <algue/sha512.hpp>
|
||||
|
||||
#include <zeus/service/Picture.hpp>
|
||||
#include <zeus/service/registerPicture.hpp>
|
||||
@ -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<nbElement) {
|
||||
@ -211,9 +215,19 @@ namespace appl {
|
||||
}
|
||||
auto futData = _dataFile.getPart(offset, offset + nbElement);
|
||||
futData.wait();
|
||||
if (futData.hasError() == true) {
|
||||
throw std::runtime_error("ErrorWhen loading data");
|
||||
}
|
||||
zeus::Raw buffer = futData.get();
|
||||
APPL_ERROR(" get size ... : " << buffer.size() << " " << nbElement);
|
||||
shaCtx.update(buffer.data(), buffer.size());
|
||||
nodeFile.fileWrite(buffer.data(), 1, buffer.size());
|
||||
offset += nbElement;
|
||||
retSize -= nbElement;
|
||||
}
|
||||
std::string sha256String = algue::stringConvert(shaCtx.finalize());
|
||||
APPL_ERROR(" filename : " << sha256String);
|
||||
return sha256String;
|
||||
|
||||
/*
|
||||
APPL_ERROR(" ==> Receive FILE " << _dataFile.getMineType() << " size=" << _dataFile.getData().size());
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
@ -1444,8 +1444,12 @@ namespace zeus {
|
||||
// TODO : Check size ...
|
||||
if (createType<zeus::Raw>() == 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 << "'");
|
||||
|
@ -3,6 +3,9 @@
|
||||
#elem-type:FILE
|
||||
#elem-author:Heero Yui<yui.heero@gmail.com>
|
||||
|
||||
#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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user