[DEV] continue removing stl

This commit is contained in:
Edouard DUPIN 2017-08-28 00:04:49 +02:00
parent 54a5b66436
commit 29607a6d46
17 changed files with 194 additions and 194 deletions

View File

@ -6,19 +6,19 @@
#include <enet/debug.hpp> #include <enet/debug.hpp>
#include <enet/Http.hpp> #include <enet/Http.hpp>
#include <map> #include <etk/Map.hpp>
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <cstring> #include <cstring>
static std::string escapeChar(const std::string& _value) { static etk::String escapeChar(const etk::String& _value) {
return _value; return _value;
} }
static std::string unEscapeChar(const std::string& _value) { static etk::String unEscapeChar(const etk::String& _value) {
return _value; return _value;
} }
static std::string removeStartAndStopSpace(const std::string& _value) { static etk::String removeStartAndStopSpace(const etk::String& _value) {
std::string out; etk::String out;
out.reserve(_value.size()); out.reserve(_value.size());
bool findSpace = false; bool findSpace = false;
for (auto &it : _value) { for (auto &it : _value) {
@ -36,7 +36,7 @@ static std::string removeStartAndStopSpace(const std::string& _value) {
return out; return out;
} }
static std::map<enet::HTTPAnswerCode, std::string> protocolName = { static etk::Map<enet::HTTPAnswerCode, etk::String> protocolName = {
{enet::HTTPAnswerCode::c100_continue, "Continue"}, {enet::HTTPAnswerCode::c100_continue, "Continue"},
{enet::HTTPAnswerCode::c101_switchingProtocols, "Switching Protocols"}, {enet::HTTPAnswerCode::c101_switchingProtocols, "Switching Protocols"},
{enet::HTTPAnswerCode::c103_checkpoint, "Checkpoint"}, {enet::HTTPAnswerCode::c103_checkpoint, "Checkpoint"},
@ -84,14 +84,14 @@ static std::map<enet::HTTPAnswerCode, std::string> protocolName = {
static std::map<int32_t, std::string> getErrorList() { static etk::Map<int32_t, etk::String> getErrorList() {
static std::map<int32_t, std::string> g_list; static etk::Map<int32_t, etk::String> g_list;
return g_list; return g_list;
} }
enet::Http::Http(enet::Tcp _connection, bool _isServer) : enet::Http::Http(enet::Tcp _connection, bool _isServer) :
m_isServer(_isServer), m_isServer(_isServer),
m_connection(std::move(_connection)), m_connection(etk::move(_connection)),
m_headerIsSend(false), m_headerIsSend(false),
m_thread(nullptr), m_thread(nullptr),
m_threadRunning(false) { m_threadRunning(false) {
@ -178,9 +178,9 @@ void enet::Http::stop(bool _inThreadStop){
} }
/* /*
void enet::Http::writeAnswerHeader(enum enet::HTTPAnswerCode _value) { void enet::Http::writeAnswerHeader(enum enet::HTTPAnswerCode _value) {
std::string out; etk::String out;
out = "HTTP/1.1 "; out = "HTTP/1.1 ";
out += etk::to_string(int32_t(_value)); out += etk::toString(int32_t(_value));
auto it = protocolName.find(_value); auto it = protocolName.find(_value);
if (it == protocolName.end() ) { if (it == protocolName.end() ) {
out += " ???"; out += " ???";
@ -194,10 +194,10 @@ void enet::Http::writeAnswerHeader(enum enet::HTTPAnswerCode _value) {
*/ */
namespace etk { namespace etk {
template <> template <>
bool from_string<enum enet::HTTPAnswerCode>(enum enet::HTTPAnswerCode& _variableRet, const std::string& _value) { bool from_string<enum enet::HTTPAnswerCode>(enum enet::HTTPAnswerCode& _variableRet, const etk::String& _value) {
_variableRet = enet::HTTPAnswerCode::c000_unknow; _variableRet = enet::HTTPAnswerCode::c000_unknow;
for (auto &it : protocolName) { for (auto &it : protocolName) {
if (etk::to_string(int32_t(it.first)) == _value) { if (etk::toString(int32_t(it.first)) == _value) {
_variableRet = it.first; _variableRet = it.first;
return true; return true;
} }
@ -205,11 +205,11 @@ namespace etk {
return false; return false;
} }
template <> template <>
std::string to_string<enum enet::HTTPAnswerCode>(const enum enet::HTTPAnswerCode& _value) { etk::String toString<enum enet::HTTPAnswerCode>(const enum enet::HTTPAnswerCode& _value) {
return etk::to_string(int32_t(_value)); return etk::toString(int32_t(_value));
} }
template <> template <>
bool from_string<enum enet::HTTPReqType>(enum enet::HTTPReqType& _variableRet, const std::string& _value) { bool from_string<enum enet::HTTPReqType>(enum enet::HTTPReqType& _variableRet, const etk::String& _value) {
_variableRet = enet::HTTPReqType::HTTP_GET; _variableRet = enet::HTTPReqType::HTTP_GET;
if (_value == "GET") { if (_value == "GET") {
_variableRet = enet::HTTPReqType::HTTP_GET; _variableRet = enet::HTTPReqType::HTTP_GET;
@ -230,7 +230,7 @@ namespace etk {
return false; return false;
} }
template <> template <>
std::string to_string<enum enet::HTTPReqType>(const enum enet::HTTPReqType& _value) { etk::String toString<enum enet::HTTPReqType>(const enum enet::HTTPReqType& _value) {
switch (_value) { switch (_value) {
case enet::HTTPReqType::HTTP_GET: return "GET"; case enet::HTTPReqType::HTTP_GET: return "GET";
case enet::HTTPReqType::HTTP_HEAD: return "HEAD"; case enet::HTTPReqType::HTTP_HEAD: return "HEAD";
@ -241,7 +241,7 @@ namespace etk {
return "UNKNOW"; return "UNKNOW";
} }
template <> template <>
bool from_string<enum enet::HTTPProtocol>(enum enet::HTTPProtocol& _variableRet, const std::string& _value) { bool from_string<enum enet::HTTPProtocol>(enum enet::HTTPProtocol& _variableRet, const etk::String& _value) {
_variableRet = enet::HTTPProtocol::http_0_1; _variableRet = enet::HTTPProtocol::http_0_1;
if (_value == "HTTP/0.1") { _variableRet = enet::HTTPProtocol::http_0_1; return true; } if (_value == "HTTP/0.1") { _variableRet = enet::HTTPProtocol::http_0_1; return true; }
if (_value == "HTTP/0.2") { _variableRet = enet::HTTPProtocol::http_0_2; return true; } if (_value == "HTTP/0.2") { _variableRet = enet::HTTPProtocol::http_0_2; return true; }
@ -289,7 +289,7 @@ namespace etk {
return false; return false;
} }
template <> template <>
std::string to_string<enum enet::HTTPProtocol>(const enum enet::HTTPProtocol& _value) { etk::String toString<enum enet::HTTPProtocol>(const enum enet::HTTPProtocol& _value) {
switch (_value) { switch (_value) {
case enet::HTTPProtocol::http_0_1: return "HTTP/0.1"; case enet::HTTPProtocol::http_0_1: return "HTTP/0.1";
case enet::HTTPProtocol::http_0_2: return "HTTP/0.2"; case enet::HTTPProtocol::http_0_2: return "HTTP/0.2";
@ -345,7 +345,7 @@ void enet::Http::setRequestHeader(const enet::HttpRequest& _req) {
if (m_requestHeader.getKey("User-Agent") == "") { if (m_requestHeader.getKey("User-Agent") == "") {
m_requestHeader.setKey("User-Agent", "e-net (ewol network interface)"); m_requestHeader.setKey("User-Agent", "e-net (ewol network interface)");
} }
std::string value = m_requestHeader.generate(); etk::String value = m_requestHeader.generate();
write(value, false); write(value, false);
} }
@ -354,14 +354,14 @@ void enet::Http::setAnswerHeader(const enet::HttpAnswer& _req) {
if (m_requestHeader.getKey("User-Agent") == "") { if (m_requestHeader.getKey("User-Agent") == "") {
m_requestHeader.setKey("User-Agent", "e-net (ewol network interface)"); m_requestHeader.setKey("User-Agent", "e-net (ewol network interface)");
} }
std::string value = m_answerHeader.generate(); etk::String value = m_answerHeader.generate();
write(value, false); write(value, false);
} }
void enet::Http::getHeader() { void enet::Http::getHeader() {
ENET_VERBOSE("Read HTTP Header [START]"); ENET_VERBOSE("Read HTTP Header [START]");
bool headerEnded = false; bool headerEnded = false;
std::string header; etk::String header;
while (m_connection.getConnectionStatus() == enet::Tcp::status::link) { while (m_connection.getConnectionStatus() == enet::Tcp::status::link) {
char type = '?'; char type = '?';
int32_t len = m_connection.read(&type, 1); int32_t len = m_connection.read(&type, 1);
@ -396,7 +396,7 @@ void enet::Http::getHeader() {
ENET_VERBOSE("Read HTTP Header [STOP] : '" << header << "'"); ENET_VERBOSE("Read HTTP Header [STOP] : '" << header << "'");
m_headerIsSend = true; m_headerIsSend = true;
// parse header : // parse header :
std::vector<std::string> list = etk::split(header, '\n'); etk::Vector<etk::String> list = etk::split(header, '\n');
for (auto &it : list) { for (auto &it : list) {
if ( it.size()>0 if ( it.size()>0
&& it[it.size()-1] == '\r') { && it[it.size()-1] == '\r') {
@ -404,7 +404,7 @@ void enet::Http::getHeader() {
} }
} }
//parse first element: //parse first element:
std::vector<std::string> listLineOne = etk::split(list[0], ' '); etk::Vector<etk::String> listLineOne = etk::split(list[0], ' ');
if (listLineOne.size() < 2) { if (listLineOne.size() < 2) {
ENET_ERROR("can not parse answear : " << listLineOne); ENET_ERROR("can not parse answear : " << listLineOne);
// answer bad request and close connection ... // answer bad request and close connection ...
@ -459,7 +459,7 @@ void enet::Http::getHeader() {
m_answerHeader.setErrorCode(valueErrorCode); m_answerHeader.setErrorCode(valueErrorCode);
// get comment: // get comment:
std::string comment; etk::String comment;
for (size_t iii=2; iii<listLineOne.size(); ++iii) { for (size_t iii=2; iii<listLineOne.size(); ++iii) {
if (comment.size() != 0) { if (comment.size() != 0) {
comment += " "; comment += " ";
@ -478,13 +478,13 @@ void enet::Http::getHeader() {
} }
for (size_t iii=1; iii<list.size(); ++iii) { for (size_t iii=1; iii<list.size(); ++iii) {
size_t found = list[iii].find(":"); size_t found = list[iii].find(":");
if (found == std::string::npos) { if (found == etk::String::npos) {
// nothing // nothing
continue; continue;
} }
std::string key = unEscapeChar(std::string(list[iii], 0, found)); etk::String key = unEscapeChar(etk::String(list[iii], 0, found));
key = removeStartAndStopSpace(key); key = removeStartAndStopSpace(key);
std::string value = unEscapeChar(std::string(list[iii], found+2)); etk::String value = unEscapeChar(etk::String(list[iii], found+2));
value = removeStartAndStopSpace(value); value = removeStartAndStopSpace(value);
ENET_VERBOSE("header : key='" << key << "' value='" << value << "'"); ENET_VERBOSE("header : key='" << key << "' value='" << value << "'");
if (m_isServer == false) { if (m_isServer == false) {
@ -511,9 +511,9 @@ void enet::Http::getHeader() {
/* /*
bool enet::Http::get(const std::string& _address) { bool enet::Http::get(const etk::String& _address) {
m_header.m_map.clear(); m_header.m_map.clear();
std::string req = "GET http://" + m_connection.getName(); etk::String req = "GET http://" + m_connection.getName();
if (_address != "") { if (_address != "") {
req += "/"; req += "/";
req += _address; req += _address;
@ -538,10 +538,10 @@ bool enet::Http::get(const std::string& _address) {
return false; return false;
} }
bool enet::Http::post(const std::string& _address, const std::map<std::string, std::string>& _values) { bool enet::Http::post(const etk::String& _address, const etk::Map<etk::String, etk::String>& _values) {
m_header.m_map.clear(); m_header.m_map.clear();
// First create body : // First create body :
std::string body; etk::String body;
for (auto &it : _values) { for (auto &it : _values) {
if (body.size() > 0) { if (body.size() > 0) {
body += "&"; body += "&";
@ -551,16 +551,16 @@ bool enet::Http::post(const std::string& _address, const std::map<std::string, s
return post(_address, "application/x-www-form-urlencoded", body); return post(_address, "application/x-www-form-urlencoded", body);
} }
bool enet::Http::post(const std::string& _address, const std::string& _contentType, const std::string& _data) { bool enet::Http::post(const etk::String& _address, const etk::String& _contentType, const etk::String& _data) {
m_header.m_map.clear(); m_header.m_map.clear();
std::string req = "POST http://" + m_connection.getName(); etk::String req = "POST http://" + m_connection.getName();
if (_address != "") { if (_address != "") {
req += "/"; req += "/";
req += _address; req += _address;
} }
req += " HTTP/1.0\n"; req += " HTTP/1.0\n";
setSendHeaderProperties("Content-Type", _contentType); setSendHeaderProperties("Content-Type", _contentType);
setSendHeaderProperties("Content-Length", etk::to_string(_data.size())); setSendHeaderProperties("Content-Length", etk::toString(_data.size()));
// add header properties : // add header properties :
for (auto &it : m_header.m_map) { for (auto &it : m_header.m_map) {
req += escapeChar(it.first) + ": " + escapeChar(it.second) + "\r\n"; req += escapeChar(it.first) + ": " + escapeChar(it.second) + "\r\n";
@ -585,7 +585,7 @@ int32_t enet::Http::write(const void* _data, int32_t _len) {
} }
void enet::HttpHeader::setKey(const std::string& _key, const std::string& _value) { void enet::HttpHeader::setKey(const etk::String& _key, const etk::String& _value) {
auto it = m_map.find(_key); auto it = m_map.find(_key);
if (it == m_map.end()) { if (it == m_map.end()) {
m_map.insert(make_pair(_key, _value)); m_map.insert(make_pair(_key, _value));
@ -594,14 +594,14 @@ void enet::HttpHeader::setKey(const std::string& _key, const std::string& _value
} }
} }
void enet::HttpHeader::rmKey(const std::string& _key) { void enet::HttpHeader::rmKey(const etk::String& _key) {
auto it = m_map.find(_key); auto it = m_map.find(_key);
if (it != m_map.end()) { if (it != m_map.end()) {
m_map.erase(it); m_map.erase(it);
} }
} }
std::string enet::HttpHeader::getKey(const std::string& _key) const { etk::String enet::HttpHeader::getKey(const etk::String& _key) const {
auto it = m_map.find(_key); auto it = m_map.find(_key);
if (it != m_map.end()) { if (it != m_map.end()) {
return it->second; return it->second;
@ -609,8 +609,8 @@ std::string enet::HttpHeader::getKey(const std::string& _key) const {
return ""; return "";
} }
std::string enet::HttpHeader::generateKeys() const { etk::String enet::HttpHeader::generateKeys() const {
std::string out; etk::String out;
for (auto &it : m_map) { for (auto &it : m_map) {
if ( it.first != "" if ( it.first != ""
&& it.second != "") { && it.second != "") {
@ -629,7 +629,7 @@ enet::HttpHeader::HttpHeader():
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
enet::HttpAnswer::HttpAnswer(enum HTTPAnswerCode _code, const std::string& _help): enet::HttpAnswer::HttpAnswer(enum HTTPAnswerCode _code, const etk::String& _help):
m_what(_code), m_what(_code),
m_helpMessage(_help) { m_helpMessage(_help) {
@ -649,11 +649,11 @@ void enet::HttpAnswer::display() const {
} }
} }
std::string enet::HttpAnswer::generate() const { etk::String enet::HttpAnswer::generate() const {
std::string out; etk::String out;
out += etk::to_string(m_protocol); out += etk::toString(m_protocol);
out += " "; out += " ";
out += etk::to_string(int32_t(m_what)); out += etk::toString(int32_t(m_what));
out += " "; out += " ";
if (m_helpMessage != "") { if (m_helpMessage != "") {
out += escapeChar(m_helpMessage); out += escapeChar(m_helpMessage);
@ -671,12 +671,12 @@ std::string enet::HttpAnswer::generate() const {
return out; return out;
} }
enet::HttpServer::HttpServer(enet::Tcp _connection) : enet::HttpServer::HttpServer(enet::Tcp _connection) :
enet::Http(std::move(_connection), true) { enet::Http(etk::move(_connection), true) {
} }
enet::HttpClient::HttpClient(enet::Tcp _connection) : enet::HttpClient::HttpClient(enet::Tcp _connection) :
enet::Http(std::move(_connection), false) { enet::Http(etk::move(_connection), false) {
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
@ -701,13 +701,13 @@ void enet::HttpRequest::display() const {
} }
} }
std::string enet::HttpRequest::generate() const { etk::String enet::HttpRequest::generate() const {
std::string out; etk::String out;
out += etk::to_string(m_req); out += etk::toString(m_req);
out += " "; out += " ";
out += m_uri; out += m_uri;
out += " "; out += " ";
out += etk::to_string(m_protocol); out += etk::toString(m_protocol);
out += "\r\n"; out += "\r\n";
out += generateKeys(); out += generateKeys();
out += "\r\n"; out += "\r\n";
@ -715,17 +715,17 @@ std::string enet::HttpRequest::generate() const {
} }
std::ostream& enet::operator <<(std::ostream& _os, enum enet::HTTPProtocol _obj) { etk::Stream& enet::operator <<(etk::Stream& _os, enum enet::HTTPProtocol _obj) {
_os << "enet::HTTPProtocol::" <<etk::to_string(_obj); _os << "enet::HTTPProtocol::" <<etk::toString(_obj);
return _os; return _os;
} }
std::ostream& enet::operator <<(std::ostream& _os, enum enet::HTTPAnswerCode _obj) { etk::Stream& enet::operator <<(etk::Stream& _os, enum enet::HTTPAnswerCode _obj) {
_os << "enet::HTTPAnswerCode::" << etk::to_string(_obj); _os << "enet::HTTPAnswerCode::" << etk::toString(_obj);
return _os; return _os;
} }
std::ostream& enet::operator <<(std::ostream& _os, enum enet::HTTPReqType _obj) { etk::Stream& enet::operator <<(etk::Stream& _os, enum enet::HTTPReqType _obj) {
_os << "enet::HTTPReqType::" << etk::to_string(_obj); _os << "enet::HTTPReqType::" << etk::toString(_obj);
return _os; return _os;
} }

View File

@ -6,8 +6,8 @@
#pragma once #pragma once
#include <enet/Tcp.hpp> #include <enet/Tcp.hpp>
#include <vector> #include <etk/Vector.hpp>
#include <map> #include <etk/Map.hpp>
#include <thread> #include <thread>
#include <ethread/tools.hpp> #include <ethread/tools.hpp>
#include <functional> #include <functional>
@ -64,7 +64,7 @@ namespace enet {
c505_httpVersionNotSupported, //!< The server does not support the HTTP protocol version used in the request c505_httpVersionNotSupported, //!< The server does not support the HTTP protocol version used in the request
c511_networkAuthenticationRequired, //!< The client needs to authenticate to gain network access c511_networkAuthenticationRequired, //!< The client needs to authenticate to gain network access
}; };
std::ostream& operator <<(std::ostream& _os, enum enet::HTTPAnswerCode _obj); etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPAnswerCode _obj);
enum class HTTPProtocol { enum class HTTPProtocol {
http_0_1, http_0_1,
@ -111,18 +111,18 @@ namespace enet {
http_3_9, http_3_9,
http_3_10, http_3_10,
}; };
std::ostream& operator <<(std::ostream& _os, enum enet::HTTPProtocol _obj); etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPProtocol _obj);
class HttpHeader { class HttpHeader {
protected: protected:
// key, val // key, val
std::map<std::string, std::string> m_map; etk::Map<etk::String, etk::String> m_map;
enum HTTPProtocol m_protocol; enum HTTPProtocol m_protocol;
public: public:
void setKey(const std::string& _key, const std::string& _value); void setKey(const etk::String& _key, const etk::String& _value);
void rmKey(const std::string& _key); void rmKey(const etk::String& _key);
std::string getKey(const std::string& _key) const; etk::String getKey(const etk::String& _key) const;
protected: protected:
std::string generateKeys() const; etk::String generateKeys() const;
public: public:
enum HTTPProtocol getProtocol() const { enum HTTPProtocol getProtocol() const {
return m_protocol; return m_protocol;
@ -132,27 +132,27 @@ namespace enet {
} }
HttpHeader(); HttpHeader();
virtual ~HttpHeader() = default; virtual ~HttpHeader() = default;
virtual std::string generate() const = 0; virtual etk::String generate() const = 0;
}; };
class HttpAnswer : public HttpHeader { class HttpAnswer : public HttpHeader {
private: private:
enet::HTTPAnswerCode m_what; enet::HTTPAnswerCode m_what;
std::string m_helpMessage; etk::String m_helpMessage;
public: public:
HttpAnswer(enum HTTPAnswerCode _code = enet::HTTPAnswerCode::c400_badRequest, const std::string& _help=""); HttpAnswer(enum HTTPAnswerCode _code = enet::HTTPAnswerCode::c400_badRequest, const etk::String& _help="");
void display() const; void display() const;
std::string generate() const; etk::String generate() const;
void setErrorCode(enum HTTPAnswerCode _value) { void setErrorCode(enum HTTPAnswerCode _value) {
m_what = _value; m_what = _value;
} }
enum HTTPAnswerCode getErrorCode() const { enum HTTPAnswerCode getErrorCode() const {
return m_what; return m_what;
} }
void setHelp(const std::string& _value) { void setHelp(const etk::String& _value) {
m_helpMessage = _value; m_helpMessage = _value;
} }
const std::string& getHelp() const { const etk::String& getHelp() const {
return m_helpMessage; return m_helpMessage;
} }
}; };
@ -163,26 +163,26 @@ namespace enet {
HTTP_PUT, HTTP_PUT,
HTTP_DELETE, HTTP_DELETE,
}; };
std::ostream& operator <<(std::ostream& _os, enum enet::HTTPReqType _obj); etk::Stream& operator <<(etk::Stream& _os, enum enet::HTTPReqType _obj);
class HttpRequest : public HttpHeader { class HttpRequest : public HttpHeader {
private: private:
// key, val // key, val
enum HTTPReqType m_req; enum HTTPReqType m_req;
std::string m_uri; etk::String m_uri;
public: public:
HttpRequest(enum enet::HTTPReqType _type=enet::HTTPReqType::HTTP_GET); HttpRequest(enum enet::HTTPReqType _type=enet::HTTPReqType::HTTP_GET);
void display() const; void display() const;
std::string generate() const; etk::String generate() const;
void setType(enum enet::HTTPReqType _value) { void setType(enum enet::HTTPReqType _value) {
m_req = _value; m_req = _value;
} }
enum enet::HTTPReqType getType() const{ enum enet::HTTPReqType getType() const{
return m_req; return m_req;
} }
void setUri(const std::string& _value) { void setUri(const etk::String& _value) {
m_uri = _value; m_uri = _value;
} }
const std::string& getUri() const { const etk::String& getUri() const {
return m_uri; return m_uri;
} }
}; };
@ -218,7 +218,7 @@ namespace enet {
bool m_headerIsSend; bool m_headerIsSend;
std::thread* m_thread; std::thread* m_thread;
bool m_threadRunning; bool m_threadRunning;
std::vector<uint8_t> m_temporaryBuffer; etk::Vector<uint8_t> m_temporaryBuffer;
private: private:
void threadCallback(); void threadCallback();
private: private:
@ -230,7 +230,7 @@ namespace enet {
return m_connection.getConnectionStatus() == enet::Tcp::status::link; return m_connection.getConnectionStatus() == enet::Tcp::status::link;
} }
public: public:
using Observer = std::function<void(std::vector<uint8_t>&)>; //!< Define an Observer: function pointer using Observer = std::function<void(etk::Vector<uint8_t>&)>; //!< Define an Observer: function pointer
Observer m_observer; Observer m_observer;
/** /**
* @brief Connect an function member on the signal with the shared_ptr object. * @brief Connect an function member on the signal with the shared_ptr object.
@ -239,8 +239,8 @@ namespace enet {
* @param[in] _args Argument optinnal the user want to add. * @param[in] _args Argument optinnal the user want to add.
*/ */
template<class CLASS_TYPE> template<class CLASS_TYPE>
void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(std::vector<uint8_t>&)) { void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(etk::Vector<uint8_t>&)) {
m_observer = [=](std::vector<uint8_t>& _value){ m_observer = [=](etk::Vector<uint8_t>& _value){
(*_class.*_func)(_value); (*_class.*_func)(_value);
}; };
} }
@ -289,7 +289,7 @@ namespace enet {
* @return >0 byte size on the socket write * @return >0 byte size on the socket write
* @return -1 an error occured. * @return -1 an error occured.
*/ */
int32_t write(const std::string& _data, bool _writeBackSlashZero = true) { int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) {
if (_data.size() == 0) { if (_data.size() == 0) {
return 0; return 0;
} }
@ -306,7 +306,7 @@ namespace enet {
* @return -1 an error occured. * @return -1 an error occured.
*/ */
template <class T> template <class T>
int32_t write(const std::vector<T>& _data) { int32_t write(const etk::Vector<T>& _data) {
if (_data.size() == 0) { if (_data.size() == 0) {
return 0; return 0;
} }
@ -326,9 +326,9 @@ namespace enet {
setRequestHeader(_header); setRequestHeader(_header);
} }
public: public:
//bool get(const std::string& _address); //bool get(const etk::String& _address);
//bool post(const std::string& _address, const std::map<std::string, std::string>& _values); //bool post(const etk::String& _address, const etk::Map<etk::String, etk::String>& _values);
//bool post(const std::string& _address, const std::string& _contentType, const std::string& _data); //bool post(const etk::String& _address, const etk::String& _contentType, const etk::String& _data);
public: public:
/** /**
* @brief Connect an function member on the signal with the shared_ptr object. * @brief Connect an function member on the signal with the shared_ptr object.

View File

@ -51,15 +51,15 @@ enet::Tcp::Tcp() :
} }
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
enet::Tcp::Tcp(SOCKET _idSocket, const std::string& _name) : enet::Tcp::Tcp(SOCKET _idSocket, const etk::String& _name) :
#else #else
enet::Tcp::Tcp(int32_t _idSocket, const std::string& _name) : enet::Tcp::Tcp(int32_t _idSocket, const etk::String& _name) :
#endif #endif
m_socketId(_idSocket), m_socketId(_idSocket),
m_name(_name), m_name(_name),
m_status(status::link) { m_status(status::link) {
#ifdef ENET_STORE_INPUT #ifdef ENET_STORE_INPUT
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp"); m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp");
m_nodeStoreInput.fileOpenWrite(); m_nodeStoreInput.fileOpenWrite();
#endif #endif
} }
@ -69,7 +69,7 @@ enet::Tcp::Tcp(Tcp&& _obj) :
m_name(_obj.m_name), m_name(_obj.m_name),
m_status(_obj.m_status) { m_status(_obj.m_status) {
#ifdef ENET_STORE_INPUT #ifdef ENET_STORE_INPUT
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp"); m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp");
m_nodeStoreInput.fileOpenWrite(); m_nodeStoreInput.fileOpenWrite();
#endif #endif
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
@ -88,7 +88,7 @@ enet::Tcp::~Tcp() {
enet::Tcp& enet::Tcp::operator = (enet::Tcp&& _obj) { enet::Tcp& enet::Tcp::operator = (enet::Tcp&& _obj) {
unlink(); unlink();
#ifdef ENET_STORE_INPUT #ifdef ENET_STORE_INPUT
m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::to_string(baseID++) + ".tcp"); m_nodeStoreInput = etk::FSNode("CACHE:StoreTCPdata_" + etk::toString(baseID++) + ".tcp");
m_nodeStoreInput.fileOpenWrite(); m_nodeStoreInput.fileOpenWrite();
#endif #endif
m_socketId = _obj.m_socketId; m_socketId = _obj.m_socketId;

View File

@ -34,9 +34,9 @@ namespace enet {
public: public:
Tcp(); Tcp();
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
Tcp(SOCKET _idSocket, const std::string& _name); Tcp(SOCKET _idSocket, const etk::String& _name);
#else #else
Tcp(int32_t _idSocket, const std::string& _name); Tcp(int32_t _idSocket, const etk::String& _name);
#endif #endif
// move constructor // move constructor
Tcp(Tcp&& _obj); Tcp(Tcp&& _obj);
@ -46,13 +46,13 @@ namespace enet {
Tcp& operator= (Tcp& _obj) = delete; Tcp& operator= (Tcp& _obj) = delete;
virtual ~Tcp(); virtual ~Tcp();
private: private:
std::string m_name; //!< hostname/IP:port. etk::String m_name; //!< hostname/IP:port.
public: public:
/** /**
* @brief Get the decriptive name hot the host:port * @brief Get the decriptive name hot the host:port
* @return the string requested * @return the string requested
*/ */
const std::string& getName() { const etk::String& getName() {
return m_name; return m_name;
} }
public: public:
@ -102,7 +102,7 @@ namespace enet {
* @return >0 byte size on the socket write * @return >0 byte size on the socket write
* @return -1 an error occured. * @return -1 an error occured.
*/ */
int32_t write(const std::string& _data, bool _writeBackSlashZero = true) { int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) {
if (_data.size() == 0) { if (_data.size() == 0) {
return 0; return 0;
} }
@ -119,7 +119,7 @@ namespace enet {
* @return -1 an error occured. * @return -1 an error occured.
*/ */
template <class T> template <class T>
int32_t write(const std::vector<T>& _data) { int32_t write(const etk::Vector<T>& _data) {
if (_data.size() == 0) { if (_data.size() == 0) {
return 0; return 0;
} }

View File

@ -24,26 +24,26 @@
#endif #endif
enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) { enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) {
std::string tmpname; etk::String tmpname;
tmpname = etk::to_string(_ip1); tmpname = etk::toString(_ip1);
tmpname += "."; tmpname += ".";
tmpname += etk::to_string(_ip2); tmpname += etk::toString(_ip2);
tmpname += "."; tmpname += ".";
tmpname += etk::to_string(_ip3); tmpname += etk::toString(_ip3);
tmpname += "."; tmpname += ".";
tmpname += etk::to_string(_ip4); tmpname += etk::toString(_ip4);
return std::move(enet::connectTcpClient(tmpname, _port, _numberRetry, _timeOut)); return etk::move(enet::connectTcpClient(tmpname, _port, _numberRetry, _timeOut));
} }
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
enet::Tcp enet::connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) { enet::Tcp enet::connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) {
if (enet::isInit() == false) { if (enet::isInit() == false) {
ENET_ERROR("Need call enet::init(...) before accessing to the socket"); ENET_ERROR("Need call enet::init(...) before accessing to the socket");
return std::move(enet::Tcp()); return etk::move(enet::Tcp());
} }
if (_hostname == "") { if (_hostname == "") {
ENET_ERROR("get connection wihtout hostname"); ENET_ERROR("get connection wihtout hostname");
return std::move(enet::Tcp()); return etk::move(enet::Tcp());
} }
SOCKET socketId = INVALID_SOCKET; SOCKET socketId = INVALID_SOCKET;
ENET_INFO("Start connection on " << _hostname << ":" << _port); ENET_INFO("Start connection on " << _hostname << ":" << _port);
@ -67,7 +67,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
// Resolve the server address and port // Resolve the server address and port
struct addrinfo* result = nullptr; struct addrinfo* result = nullptr;
std::string portValue = etk::to_string(_port); etk::String portValue = etk::toString(_port);
int iResult = getaddrinfo(_hostname.c_str(), portValue.c_str(), &hints, &result); int iResult = getaddrinfo(_hostname.c_str(), portValue.c_str(), &hints, &result);
if (iResult != 0) { if (iResult != 0) {
ENET_ERROR("getaddrinfo failed with error: " << iResult); ENET_ERROR("getaddrinfo failed with error: " << iResult);
@ -106,21 +106,21 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
} }
if (socketId == INVALID_SOCKET) { if (socketId == INVALID_SOCKET) {
ENET_ERROR("ERROR connecting ... (after all try)"); ENET_ERROR("ERROR connecting ... (after all try)");
return std::move(enet::Tcp()); return etk::move(enet::Tcp());
} }
ENET_DEBUG("Connection done"); ENET_DEBUG("Connection done");
return std::move(enet::Tcp(socketId, _hostname + ":" + etk::to_string(_port))); return etk::move(enet::Tcp(socketId, _hostname + ":" + etk::toString(_port)));
} }
#else #else
#include <sys/socket.h> #include <sys/socket.h>
enet::Tcp enet::connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) { enet::Tcp enet::connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry, echrono::Duration _timeOut) {
if (enet::isInit() == false) { if (enet::isInit() == false) {
ENET_ERROR("Need call enet::init(...) before accessing to the socket"); ENET_ERROR("Need call enet::init(...) before accessing to the socket");
return std::move(enet::Tcp()); return etk::move(enet::Tcp());
} }
if (_hostname == "") { if (_hostname == "") {
ENET_ERROR("get connection wihtout hostname"); ENET_ERROR("get connection wihtout hostname");
return std::move(enet::Tcp()); return etk::move(enet::Tcp());
} }
int32_t socketId = -1; int32_t socketId = -1;
ENET_INFO("Start connection on " << _hostname << ":" << _port); ENET_INFO("Start connection on " << _hostname << ":" << _port);
@ -147,7 +147,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
addr.s_addr = inet_addr(_hostname.c_str()); addr.s_addr = inet_addr(_hostname.c_str());
if (addr.s_addr == INADDR_NONE) { if (addr.s_addr == INADDR_NONE) {
ENET_ERROR("The IPv4 address entered must be a legal address" << _hostname.c_str()); ENET_ERROR("The IPv4 address entered must be a legal address" << _hostname.c_str());
return std::move(enet::Tcp()); return etk::move(enet::Tcp());
} else { } else {
// TODO : This is deprecated use getaddrinfo like windows ... // TODO : This is deprecated use getaddrinfo like windows ...
server = gethostbyaddr((char *) &addr, 4, AF_INET); server = gethostbyaddr((char *) &addr, 4, AF_INET);
@ -183,10 +183,10 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8
} }
if (socketId<0) { if (socketId<0) {
ENET_ERROR("ERROR connecting ... (after all try)"); ENET_ERROR("ERROR connecting ... (after all try)");
return std::move(enet::Tcp()); return etk::move(enet::Tcp());
} }
ENET_INFO("Connection done"); ENET_INFO("Connection done");
return std::move(enet::Tcp(socketId, _hostname + ":" + etk::to_string(_port))); return etk::move(enet::Tcp(socketId, _hostname + ":" + etk::toString(_port)));
} }
#endif #endif

View File

@ -10,5 +10,5 @@
namespace enet { namespace enet {
enet::Tcp connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1)); enet::Tcp connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8_t _ip4, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1));
enet::Tcp connectTcpClient(const std::string& _hostname, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1)); enet::Tcp connectTcpClient(const etk::String& _hostname, uint16_t _port, uint32_t _numberRetry=5, echrono::Duration _timeOut = echrono::seconds(1));
} }

View File

@ -37,18 +37,18 @@ enet::TcpServer::~TcpServer() {
} }
void enet::TcpServer::setIpV4(uint8_t _fist, uint8_t _second, uint8_t _third, uint8_t _quatro) { void enet::TcpServer::setIpV4(uint8_t _fist, uint8_t _second, uint8_t _third, uint8_t _quatro) {
std::string tmpname; etk::String tmpname;
tmpname = etk::to_string(_fist); tmpname = etk::toString(_fist);
tmpname += "."; tmpname += ".";
tmpname += etk::to_string(_second); tmpname += etk::toString(_second);
tmpname += "."; tmpname += ".";
tmpname += etk::to_string(_third); tmpname += etk::toString(_third);
tmpname += "."; tmpname += ".";
tmpname += etk::to_string(_quatro); tmpname += etk::toString(_quatro);
setHostNane(tmpname); setHostNane(tmpname);
} }
void enet::TcpServer::setHostNane(const std::string& _name) { void enet::TcpServer::setHostNane(const etk::String& _name) {
if (_name == m_host) { if (_name == m_host) {
return; return;
} }
@ -79,7 +79,7 @@ void enet::TcpServer::setPort(uint16_t _port) {
hints.ai_flags = AI_PASSIVE; hints.ai_flags = AI_PASSIVE;
// Resolve the server address and port // Resolve the server address and port
std::string portValue = etk::to_string(m_port); etk::String portValue = etk::toString(m_port);
int iResult = getaddrinfo(nullptr, portValue.c_str(), &hints, &result); int iResult = getaddrinfo(nullptr, portValue.c_str(), &hints, &result);
if (iResult != 0) { if (iResult != 0) {
ENET_ERROR("getaddrinfo failed with error: " << iResult); ENET_ERROR("getaddrinfo failed with error: " << iResult);
@ -153,7 +153,7 @@ void enet::TcpServer::setPort(uint16_t _port) {
enet::Tcp enet::TcpServer::waitNext() { enet::Tcp enet::TcpServer::waitNext() {
if (enet::isInit() == false) { if (enet::isInit() == false) {
ENET_ERROR("Need call enet::init(...) before accessing to the socket"); ENET_ERROR("Need call enet::init(...) before accessing to the socket");
return std::move(enet::Tcp()); return etk::move(enet::Tcp());
} }
ENET_INFO("End binding Socket ... (start listen)"); ENET_INFO("End binding Socket ... (start listen)");
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
@ -182,7 +182,7 @@ enet::Tcp enet::TcpServer::waitNext() {
return enet::Tcp(); return enet::Tcp();
} }
ENET_INFO("End configuring Socket ... Find New one"); ENET_INFO("End configuring Socket ... Find New one");
return enet::Tcp(socketIdClient, m_host + ":" + etk::to_string(m_port)); return enet::Tcp(socketIdClient, m_host + ":" + etk::toString(m_port));
} }

View File

@ -26,7 +26,7 @@ namespace enet {
TcpServer(); TcpServer();
virtual ~TcpServer(); virtual ~TcpServer();
private: private:
std::string m_host; //!< hostname/IP to connect with. etk::String m_host; //!< hostname/IP to connect with.
public: public:
/** /**
* @brief Set the connection IP id. * @brief Set the connection IP id.
@ -40,12 +40,12 @@ namespace enet {
* @brief set the Host name is the same things as set an Ip adress, but in test mode "127.0.0.1" or "localhost". * @brief set the Host name is the same things as set an Ip adress, but in test mode "127.0.0.1" or "localhost".
* @param[in] _name Host name to connect. * @param[in] _name Host name to connect.
*/ */
void setHostNane(const std::string& _name); void setHostNane(const etk::String& _name);
/** /**
* @brief Get the decriptive name hot the host * @brief Get the decriptive name hot the host
* @return the string requested * @return the string requested
*/ */
const std::string& getHostName() { const etk::String& getHostName() {
return m_host; return m_host;
} }
private: private:

View File

@ -6,7 +6,7 @@
#include <enet/debug.hpp> #include <enet/debug.hpp>
#include <enet/WebSocket.hpp> #include <enet/WebSocket.hpp>
#include <map> #include <etk/Map.hpp>
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <cstring> #include <cstring>
#include <random> #include <random>
@ -40,19 +40,19 @@ enet::WebSocket::WebSocket(enet::Tcp _connection, bool _isServer) :
m_interface(nullptr), m_interface(nullptr),
m_observer(nullptr), m_observer(nullptr),
m_observerUriCheck(nullptr) { m_observerUriCheck(nullptr) {
setInterface(std::move(_connection), _isServer); setInterface(etk::move(_connection), _isServer);
} }
void enet::WebSocket::setInterface(enet::Tcp _connection, bool _isServer) { void enet::WebSocket::setInterface(enet::Tcp _connection, bool _isServer) {
_connection.setTCPNoDelay(true); _connection.setTCPNoDelay(true);
if (_isServer == true) { if (_isServer == true) {
ememory::SharedPtr<enet::HttpServer> interface = ememory::makeShared<enet::HttpServer>(std::move(_connection)); ememory::SharedPtr<enet::HttpServer> interface = ememory::makeShared<enet::HttpServer>(etk::move(_connection));
m_interface = interface; m_interface = interface;
if (interface != nullptr) { if (interface != nullptr) {
interface->connectHeader(this, &enet::WebSocket::onReceiveRequest); interface->connectHeader(this, &enet::WebSocket::onReceiveRequest);
} }
} else { } else {
ememory::SharedPtr<enet::HttpClient> interface = ememory::makeShared<enet::HttpClient>(std::move(_connection)); ememory::SharedPtr<enet::HttpClient> interface = ememory::makeShared<enet::HttpClient>(etk::move(_connection));
m_interface = interface; m_interface = interface;
if (interface != nullptr) { if (interface != nullptr) {
interface->connectHeader(this, &enet::WebSocket::onReceiveAnswer); interface->connectHeader(this, &enet::WebSocket::onReceiveAnswer);
@ -72,7 +72,7 @@ enet::WebSocket::~WebSocket() {
stop(true); stop(true);
} }
static std::string generateKey() { static etk::String generateKey() {
// create dynamic key: // create dynamic key:
std::random_device rd; std::random_device rd;
std::mt19937 e2(rd()); std::mt19937 e2(rd());
@ -84,13 +84,13 @@ static std::string generateKey() {
return algue::base64::encode(dataKey, 16); return algue::base64::encode(dataKey, 16);
} }
static std::string generateCheckKey(const std::string& _key) { static etk::String generateCheckKey(const etk::String& _key) {
std::string out = _key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; etk::String out = _key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
std::vector<uint8_t> keyData = algue::sha1::encode(out); etk::Vector<uint8_t> keyData = algue::sha1::encode(out);
return algue::base64::encode(keyData); return algue::base64::encode(keyData);
} }
void enet::WebSocket::start(const std::string& _uri, const std::vector<std::string>& _listProtocols) { void enet::WebSocket::start(const etk::String& _uri, const etk::Vector<etk::String>& _listProtocols) {
if (m_interface == nullptr) { if (m_interface == nullptr) {
ENET_ERROR("Nullptr interface ..."); ENET_ERROR("Nullptr interface ...");
return; return;
@ -108,7 +108,7 @@ void enet::WebSocket::start(const std::string& _uri, const std::vector<std::stri
req.setKey("Sec-WebSocket-Version", "13"); req.setKey("Sec-WebSocket-Version", "13");
req.setKey("Pragma", "no-cache"); req.setKey("Pragma", "no-cache");
req.setKey("Cache-Control", "no-cache"); req.setKey("Cache-Control", "no-cache");
std::string protocolList; etk::String protocolList;
for (auto &it : _listProtocols) { for (auto &it : _listProtocols) {
if (it == "") { if (it == "") {
continue; continue;
@ -307,8 +307,8 @@ void enet::WebSocket::onReceiveData(enet::Tcp& _connection) {
ENET_ERROR("ReadRaw [STOP] (no opcode manage ... " << int32_t(opcode & 0x0F)); ENET_ERROR("ReadRaw [STOP] (no opcode manage ... " << int32_t(opcode & 0x0F));
} }
static std::string removeStartAndStopSpace(const std::string& _value) { static etk::String removeStartAndStopSpace(const etk::String& _value) {
std::string out; etk::String out;
out.reserve(_value.size()); out.reserve(_value.size());
bool findSpace = false; bool findSpace = false;
for (auto &it : _value) { for (auto &it : _value) {
@ -366,7 +366,7 @@ void enet::WebSocket::onReceiveRequest(const enet::HttpRequest& _data) {
return; return;
} }
// parse all protocols: // parse all protocols:
std::vector<std::string> listProtocol; etk::Vector<etk::String> listProtocol;
if (_data.getKey("Sec-WebSocket-Protocol") != "") { if (_data.getKey("Sec-WebSocket-Protocol") != "") {
listProtocol = etk::split(_data.getKey("Sec-WebSocket-Protocol"),','); listProtocol = etk::split(_data.getKey("Sec-WebSocket-Protocol"),',');
for (size_t iii=0; iii<listProtocol.size(); ++iii) { for (size_t iii=0; iii<listProtocol.size(); ++iii) {
@ -388,7 +388,7 @@ void enet::WebSocket::onReceiveRequest(const enet::HttpRequest& _data) {
answer.setProtocol(enet::HTTPProtocol::http_1_1); answer.setProtocol(enet::HTTPProtocol::http_1_1);
answer.setKey("Upgrade", "websocket"); answer.setKey("Upgrade", "websocket");
answer.setKey("Connection", "Upgrade"); answer.setKey("Connection", "Upgrade");
std::string answerKey = generateCheckKey(_data.getKey("Sec-WebSocket-Key")); etk::String answerKey = generateCheckKey(_data.getKey("Sec-WebSocket-Key"));
answer.setKey("Sec-WebSocket-Accept", answerKey); answer.setKey("Sec-WebSocket-Accept", answerKey);
if (m_protocol != "") { if (m_protocol != "") {
answer.setKey("Sec-WebSocket-Protocol", m_protocol); answer.setKey("Sec-WebSocket-Protocol", m_protocol);

View File

@ -8,17 +8,17 @@
#include <enet/Http.hpp> #include <enet/Http.hpp>
#include <ememory/memory.hpp> #include <ememory/memory.hpp>
#include <echrono/Steady.hpp> #include <echrono/Steady.hpp>
#include <vector> #include <etk/Vector.hpp>
#include <map> #include <etk/Map.hpp>
namespace enet { namespace enet {
class WebSocket { class WebSocket {
protected: protected:
std::vector<uint8_t> m_sendBuffer; etk::Vector<uint8_t> m_sendBuffer;
bool m_connectionValidate; bool m_connectionValidate;
ememory::SharedPtr<enet::Http> m_interface; ememory::SharedPtr<enet::Http> m_interface;
std::vector<uint8_t> m_buffer; etk::Vector<uint8_t> m_buffer;
std::string m_checkKey; etk::String m_checkKey;
echrono::Steady m_lastReceive; echrono::Steady m_lastReceive;
echrono::Steady m_lastSend; echrono::Steady m_lastSend;
std::mutex m_mutex; std::mutex m_mutex;
@ -34,7 +34,7 @@ namespace enet {
WebSocket(enet::Tcp _connection, bool _isServer=false); WebSocket(enet::Tcp _connection, bool _isServer=false);
void setInterface(enet::Tcp _connection, bool _isServer=false); void setInterface(enet::Tcp _connection, bool _isServer=false);
virtual ~WebSocket(); virtual ~WebSocket();
void start(const std::string& _uri="", const std::vector<std::string>& _listProtocols=std::vector<std::string>()); void start(const etk::String& _uri="", const etk::Vector<etk::String>& _listProtocols=etk::Vector<etk::String>());
void stop(bool _inThread=false); void stop(bool _inThread=false);
bool isAlive() const { bool isAlive() const {
if (m_interface == nullptr) { if (m_interface == nullptr) {
@ -46,13 +46,13 @@ namespace enet {
void onReceiveRequest(const enet::HttpRequest& _data); void onReceiveRequest(const enet::HttpRequest& _data);
void onReceiveAnswer(const enet::HttpAnswer& _data); void onReceiveAnswer(const enet::HttpAnswer& _data);
protected: protected:
std::string m_protocol; etk::String m_protocol;
public: public:
void setProtocol(const std::string& _protocol) { void setProtocol(const etk::String& _protocol) {
m_protocol = _protocol; m_protocol = _protocol;
} }
public: public:
using Observer = std::function<void(std::vector<uint8_t>&, bool)>; //!< Define an Observer: function pointer using Observer = std::function<void(etk::Vector<uint8_t>&, bool)>; //!< Define an Observer: function pointer
protected: protected:
Observer m_observer; Observer m_observer;
public: public:
@ -63,8 +63,8 @@ namespace enet {
* @param[in] _args Argument optinnal the user want to add. * @param[in] _args Argument optinnal the user want to add.
*/ */
template<class CLASS_TYPE> template<class CLASS_TYPE>
void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(std::vector<uint8_t>&, bool)) { void connect(CLASS_TYPE* _class, void (CLASS_TYPE::*_func)(etk::Vector<uint8_t>&, bool)) {
m_observer = [=](std::vector<uint8_t>& _value, bool _isString){ m_observer = [=](etk::Vector<uint8_t>& _value, bool _isString){
(*_class.*_func)(_value, _isString); (*_class.*_func)(_value, _isString);
}; };
} }
@ -73,7 +73,7 @@ namespace enet {
} }
// Only server: // Only server:
public: public:
using ObserverUriCheck = std::function<bool(const std::string&, const std::vector<std::string>&)>; //!< Define an Observer: function pointer using ObserverUriCheck = std::function<bool(const etk::String&, const etk::Vector<etk::String>&)>; //!< Define an Observer: function pointer
protected: protected:
ObserverUriCheck m_observerUriCheck; ObserverUriCheck m_observerUriCheck;
public: public:
@ -84,8 +84,8 @@ namespace enet {
* @param[in] _args Argument optinnal the user want to add. * @param[in] _args Argument optinnal the user want to add.
*/ */
template<class CLASS_TYPE> template<class CLASS_TYPE>
void connectUri(CLASS_TYPE* _class, bool (CLASS_TYPE::*_func)(const std::string&, const std::vector<std::string>&)) { void connectUri(CLASS_TYPE* _class, bool (CLASS_TYPE::*_func)(const etk::String&, const etk::Vector<etk::String>&)) {
m_observerUriCheck = [=](const std::string& _value, const std::vector<std::string>& _protocols){ m_observerUriCheck = [=](const etk::String& _value, const etk::Vector<etk::String>& _protocols){
return (*_class.*_func)(_value, _protocols); return (*_class.*_func)(_value, _protocols);
}; };
} }
@ -98,7 +98,7 @@ namespace enet {
uint8_t m_dataMask[4]; uint8_t m_dataMask[4];
public: public:
std::unique_lock<std::mutex> getScopeLock() { std::unique_lock<std::mutex> getScopeLock() {
return std::move(std::unique_lock<std::mutex>(m_mutex)); return etk::move(std::unique_lock<std::mutex>(m_mutex));
} }
/** /**
* Compose the local header inside a temporary buffer ==> must lock external to prevent multiple simultaneous access * Compose the local header inside a temporary buffer ==> must lock external to prevent multiple simultaneous access
@ -128,7 +128,7 @@ namespace enet {
* @return >0 byte size on the socket write * @return >0 byte size on the socket write
* @return -1 an error occured. * @return -1 an error occured.
*/ */
int32_t write(const std::string& _data, bool _writeBackSlashZero = true) { int32_t write(const etk::String& _data, bool _writeBackSlashZero = true) {
if (_data.size() == 0) { if (_data.size() == 0) {
return 0; return 0;
} }
@ -145,7 +145,7 @@ namespace enet {
* @return -1 an error occured. * @return -1 an error occured.
*/ */
template <class T> template <class T>
int32_t write(const std::vector<T>& _data) { int32_t write(const etk::Vector<T>& _data) {
if (_data.size() == 0) { if (_data.size() == 0) {
return 0; return 0;
} }

View File

@ -19,7 +19,7 @@ static bool& getInitSatatus() {
void enet::init(int _argc, const char** _argv) { void enet::init(int _argc, const char** _argv) {
for (int32_t iii=0; iii<_argc; ++iii) { for (int32_t iii=0; iii<_argc; ++iii) {
std::string value = _argv[iii]; etk::String value = _argv[iii];
if (etk::start_with(value, "--enet") == true) { if (etk::start_with(value, "--enet") == true) {
ENET_ERROR("Unknow parameter type: '" << value << "'"); ENET_ERROR("Unknow parameter type: '" << value << "'");
} }

View File

@ -15,7 +15,7 @@
namespace appl { namespace appl {
void onReceiveData(std::vector<uint8_t>& _data) { void onReceiveData(etk::Vector<uint8_t>& _data) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes"); TEST_INFO("Receive Datas : " << _data.size() << " bytes");
TEST_INFO("data:" << (char*)&_data[0] << ""); TEST_INFO("data:" << (char*)&_data[0] << "");
} }
@ -25,7 +25,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);
enet::init(_argc, _argv); enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii]; etk::String data = _argv[iii];
if ( data == "-h" if ( data == "-h"
|| data == "--help") { || data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : "); TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -38,11 +38,11 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("== Test HTTP client =="); TEST_INFO("== Test HTTP client ==");
TEST_INFO("=================================="); TEST_INFO("==================================");
// connect on TCP server: // connect on TCP server:
enet::Tcp tcpConnection = std::move(enet::connectTcpClient("127.0.0.1", 12345)); enet::Tcp tcpConnection = etk::move(enet::connectTcpClient("127.0.0.1", 12345));
// TODO : Check if connection is valid ... // TODO : Check if connection is valid ...
// Create a HTTP connection in Client mode // Create a HTTP connection in Client mode
enet::HttpClient connection(std::move(tcpConnection)); enet::HttpClient connection(etk::move(tcpConnection));
// Set callbacks: // Set callbacks:
connection.connect(appl::onReceiveData); connection.connect(appl::onReceiveData);

View File

@ -16,7 +16,7 @@
namespace appl { namespace appl {
void onReceiveData(std::vector<uint8_t>& _data, bool _isString) { void onReceiveData(etk::Vector<uint8_t>& _data, bool _isString) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes"); TEST_INFO("Receive Datas : " << _data.size() << " bytes");
if (_isString == true) { if (_isString == true) {
_data.resize(_data.size()+1); _data.resize(_data.size()+1);
@ -32,7 +32,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);
enet::init(_argc, _argv); enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii]; etk::String data = _argv[iii];
if ( data == "-h" if ( data == "-h"
|| data == "--help") { || data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : "); TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -45,19 +45,19 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("== Test WebSocket client =="); TEST_INFO("== Test WebSocket client ==");
TEST_INFO("=================================="); TEST_INFO("==================================");
// connect on TCP server: // connect on TCP server:
enet::Tcp tcpConnection = std::move(enet::connectTcpClient("127.0.0.1", 12345)); enet::Tcp tcpConnection = etk::move(enet::connectTcpClient("127.0.0.1", 12345));
// TODO : Check if connection is valid ... // TODO : Check if connection is valid ...
// Create a HTTP connection in Client mode // Create a HTTP connection in Client mode
enet::WebSocket connection(std::move(tcpConnection), false); enet::WebSocket connection(etk::move(tcpConnection), false);
// Set callbacks: // Set callbacks:
connection.connect(appl::onReceiveData); connection.connect(appl::onReceiveData);
// start http connection (the actual state is just TCP start ...) // start http connection (the actual state is just TCP start ...)
std::vector<std::string> protocols; etk::Vector<etk::String> protocols;
protocols.push_back("test1526/1.0"); protocols.pushBack("test1526/1.0");
protocols.push_back("test1526/1.5"); protocols.pushBack("test1526/1.5");
protocols.push_back("Hello"); protocols.pushBack("Hello");
connection.start("/plop.txt", protocols); connection.start("/plop.txt", protocols);
// send some data to play ... // send some data to play ...

View File

@ -17,7 +17,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);
enet::init(_argc, _argv); enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii]; etk::String data = _argv[iii];
if ( data == "-h" if ( data == "-h"
|| data == "--help") { || data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : "); TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -31,7 +31,7 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("=================================="); TEST_INFO("==================================");
// client mode ... // client mode ...
// connect on TCP server: // connect on TCP server:
enet::Tcp connection = std::move(enet::connectTcpClient("127.0.0.1", 12345)); enet::Tcp connection = etk::move(enet::connectTcpClient("127.0.0.1", 12345));
TEST_INFO("CLIENT connect ..."); TEST_INFO("CLIENT connect ...");
if (connection.getConnectionStatus() != enet::Tcp::status::link) { if (connection.getConnectionStatus() != enet::Tcp::status::link) {
TEST_ERROR("can not link to the socket..."); TEST_ERROR("can not link to the socket...");

View File

@ -14,7 +14,7 @@
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
namespace appl { namespace appl {
void onReceiveData(enet::HttpServer* _interface, std::vector<uint8_t>& _data) { void onReceiveData(enet::HttpServer* _interface, etk::Vector<uint8_t>& _data) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes"); TEST_INFO("Receive Datas : " << _data.size() << " bytes");
} }
void onReceiveHeader(enet::HttpServer* _interface, const enet::HttpRequest& _data) { void onReceiveHeader(enet::HttpServer* _interface, const enet::HttpRequest& _data) {
@ -23,8 +23,8 @@ namespace appl {
if (_data.getType() == enet::HTTPReqType::HTTP_GET) { if (_data.getType() == enet::HTTPReqType::HTTP_GET) {
if (_data.getUri() == "plop.txt") { if (_data.getUri() == "plop.txt") {
enet::HttpAnswer answer(enet::HTTPAnswerCode::c200_ok); enet::HttpAnswer answer(enet::HTTPAnswerCode::c200_ok);
std::string data = "<html><head></head></body>coucou</body></html>"; etk::String data = "<html><head></head></body>coucou</body></html>";
answer.setKey("Content-Length", etk::to_string(data.size())); answer.setKey("Content-Length", etk::toString(data.size()));
_interface->setHeader(answer); _interface->setHeader(answer);
_interface->write(data); _interface->write(data);
_interface->stop(true); _interface->stop(true);
@ -42,7 +42,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);
enet::init(_argc, _argv); enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii]; etk::String data = _argv[iii];
if ( data == "-h" if ( data == "-h"
|| data == "--help") { || data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : "); TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -62,16 +62,16 @@ int main(int _argc, const char *_argv[]) {
// Start listening ... // Start listening ...
interface.link(); interface.link();
// Wait a new connection .. // Wait a new connection ..
enet::Tcp tcpConnection = std::move(interface.waitNext()); enet::Tcp tcpConnection = etk::move(interface.waitNext());
// Free Connected port // Free Connected port
interface.unlink(); interface.unlink();
// TODO : Check if connection is valid ... // TODO : Check if connection is valid ...
// Create a HTTP connection in Server mode // Create a HTTP connection in Server mode
enet::HttpServer connection(std::move(tcpConnection)); enet::HttpServer connection(etk::move(tcpConnection));
enet::HttpServer* tmp = &connection; enet::HttpServer* tmp = &connection;
// Set callbacks: // Set callbacks:
connection.connect([=](std::vector<uint8_t>& _value){ connection.connect([=](etk::Vector<uint8_t>& _value){
appl::onReceiveData(tmp, _value); appl::onReceiveData(tmp, _value);
}); });
connection.connectHeader([=](const enet::HttpRequest& _value){ connection.connectHeader([=](const enet::HttpRequest& _value){
@ -97,8 +97,8 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("----------------------------"); TEST_INFO("----------------------------");
TEST_INFO("POST data : "); TEST_INFO("POST data : ");
std::map<std::string, std::string> values; etk::Map<etk::String, etk::String> values;
values.insert(std::make_pair<std::string, std::string>("plop", "valuePlop")); values.insert(etk::makePair<etk::String, etk::String>("plop", "valuePlop"));
if (connection.post("", values) == false) { if (connection.post("", values) == false) {
TEST_ERROR("can not POST data..."); TEST_ERROR("can not POST data...");
return -1; return -1;
@ -107,7 +107,7 @@ int main(int _argc, const char *_argv[]) {
TEST_INFO("----------------------------"); TEST_INFO("----------------------------");
TEST_INFO("POST xml : "); TEST_INFO("POST xml : ");
if (connection.post("", "text/xml; charset=utf-8", "<plop><string>value1</string></plop>") == false) { if (connection.post("", "text/xml; charset=utf-8", "<plop><etk/String.hpp>value1</string></plop>") == false) {
TEST_ERROR("can not POST XML data..."); TEST_ERROR("can not POST XML data...");
return -1; return -1;
} }

View File

@ -15,7 +15,7 @@
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
namespace appl { namespace appl {
void onReceiveData(enet::WebSocket* _interface, std::vector<uint8_t>& _data, bool _isString) { void onReceiveData(enet::WebSocket* _interface, etk::Vector<uint8_t>& _data, bool _isString) {
TEST_INFO("Receive Datas : " << _data.size() << " bytes"); TEST_INFO("Receive Datas : " << _data.size() << " bytes");
if (_isString == true) { if (_isString == true) {
_data.resize(_data.size()+1); _data.resize(_data.size()+1);
@ -26,7 +26,7 @@ namespace appl {
TEST_INFO("binary data: ... "); TEST_INFO("binary data: ... ");
} }
} }
bool onReceiveUri(enet::WebSocket* _interface, const std::string& _uri, const std::vector<std::string>& _protocols) { bool onReceiveUri(enet::WebSocket* _interface, const etk::String& _uri, const etk::Vector<etk::String>& _protocols) {
TEST_INFO("Receive Header uri: " << _uri); TEST_INFO("Receive Header uri: " << _uri);
for (auto &it : _protocols) { for (auto &it : _protocols) {
if (it == "test1526/1.5") { if (it == "test1526/1.5") {
@ -45,7 +45,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);
enet::init(_argc, _argv); enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii]; etk::String data = _argv[iii];
if ( data == "-h" if ( data == "-h"
|| data == "--help") { || data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : "); TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -65,19 +65,19 @@ int main(int _argc, const char *_argv[]) {
// Start listening ... // Start listening ...
interface.link(); interface.link();
// Wait a new connection .. // Wait a new connection ..
enet::Tcp tcpConnection = std::move(interface.waitNext()); enet::Tcp tcpConnection = etk::move(interface.waitNext());
// Free Connected port // Free Connected port
interface.unlink(); interface.unlink();
// TODO : Check if connection is valid ... // TODO : Check if connection is valid ...
// Create a HTTP connection in Server mode // Create a HTTP connection in Server mode
enet::WebSocket connection(std::move(tcpConnection), true); enet::WebSocket connection(etk::move(tcpConnection), true);
enet::WebSocket* tmp = &connection; enet::WebSocket* tmp = &connection;
// Set callbacks: // Set callbacks:
connection.connect([=](std::vector<uint8_t>& _value, bool _isString){ connection.connect([=](etk::Vector<uint8_t>& _value, bool _isString){
appl::onReceiveData(tmp, _value, _isString); appl::onReceiveData(tmp, _value, _isString);
}); });
connection.connectUri([=](const std::string& _value, const std::vector<std::string>& _protocols){ connection.connectUri([=](const etk::String& _value, const etk::Vector<etk::String>& _protocols){
return appl::onReceiveUri(tmp, _value, _protocols); return appl::onReceiveUri(tmp, _value, _protocols);
}); });

View File

@ -17,7 +17,7 @@ int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv); etk::init(_argc, _argv);
enet::init(_argc, _argv); enet::init(_argc, _argv);
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
std::string data = _argv[iii]; etk::String data = _argv[iii];
if ( data == "-h" if ( data == "-h"
|| data == "--help") { || data == "--help") {
TEST_PRINT(etk::getApplicationName() << " - help : "); TEST_PRINT(etk::getApplicationName() << " - help : ");
@ -37,13 +37,13 @@ int main(int _argc, const char *_argv[]) {
// Start listening ... // Start listening ...
interface.link(); interface.link();
// Wait a new connection .. // Wait a new connection ..
enet::Tcp tcpConnection = std::move(interface.waitNext()); enet::Tcp tcpConnection = etk::move(interface.waitNext());
// Free Connected port // Free Connected port
interface.unlink(); interface.unlink();
int32_t iii = 0; int32_t iii = 0;
while (tcpConnection.getConnectionStatus() == enet::Tcp::status::link) { while (tcpConnection.getConnectionStatus() == enet::Tcp::status::link) {
int32_t len = tcpConnection.write("plop" + etk::to_string(iii)); int32_t len = tcpConnection.write("plop" + etk::toString(iii));
TEST_INFO("write len=" << len); TEST_INFO("write len=" << len);
char data[1024]; char data[1024];
len = tcpConnection.read(data, 1024); len = tcpConnection.read(data, 1024);