Loading examples/httpsysinfo.cpp +10 −10 Changes for examples/httpsysinfo.cpp: 10 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -221,7 +221,7 @@ public: } } /*virtual method from event will call for every incomming Request*/ void RequestEvent(std::shared_ptr<libhttppp::HttpRequest> &curreq, const int tid,ULONG_PTR args){ void RequestEvent(std::shared_ptr<libhttppp::HttpRequest> curreq, const int tid,ULONG_PTR args){ try{ /*self implemented controller see above*/ IndexController(curreq); Loading @@ -233,18 +233,18 @@ public: } } void ResponseEvent(std::shared_ptr<libhttppp::HttpRequest> &curreq, const int tid,ULONG_PTR args){ void ResponseEvent(std::shared_ptr<libhttppp::HttpRequest> curreq, const int tid,ULONG_PTR args){ if(curreq->getRequestURL()=="/images/header.png"){ if(curreq->SendData->pos < header_png_size){ size_t si = BLOCKSIZE < (header_png_size-curreq->SendData->pos) ? BLOCKSIZE : (header_png_size-curreq->SendData->pos); curreq->SendData->append((const char*)header_png+curreq->SendData->pos,si); curreq->SendData->pos+=si; if(curreq->SendData.pos < header_png_size){ size_t si = BLOCKSIZE < (header_png_size-curreq->SendData.pos) ? BLOCKSIZE : (header_png_size-curreq->SendData.pos); curreq->SendData.append((const char*)header_png+curreq->SendData.pos,si); curreq->SendData.pos+=si; } }else if(curreq->getRequestURL()=="/favicon.ico "){ if(curreq->SendData->pos < favicon_ico_size){ size_t si = BLOCKSIZE < (favicon_ico_size-curreq->SendData->pos) ? BLOCKSIZE : (favicon_ico_size-curreq->SendData->pos); curreq->SendData->append((const char*)favicon_ico+curreq->SendData->pos,si); curreq->SendData->pos+=si; if(curreq->SendData.pos < favicon_ico_size){ size_t si = BLOCKSIZE < (favicon_ico_size-curreq->SendData.pos) ? BLOCKSIZE : (favicon_ico_size-curreq->SendData.pos); curreq->SendData.append((const char*)favicon_ico+curreq->SendData.pos,si); curreq->SendData.pos+=si; } } } Loading src/http.cpp +13 −14 Changes for src/http.cpp: 13 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -696,7 +696,6 @@ libhttppp::HttpHeader::HeaderData::HeaderData(const char *key){ libhttppp::HttpHeader::HeaderData::~HeaderData(){ _nextHeaderData=nullptr; clear(); } libhttppp::HttpHeader::HeaderData::Values * libhttppp::HttpHeader::HeaderData::getfirstValue(){ Loading Loading @@ -917,10 +916,10 @@ void libhttppp::HttpResponse::send(std::shared_ptr<netplus::con> curconnection,c printHeader(header); curconnection->SendData->append(header.data(),header.size()); curconnection->SendData.append(header.data(),header.size()); if (datalen > 0) std::copy(data.begin(), data.end(), std::back_inserter(*curconnection->SendData)); std::copy(data.begin(), data.end(), std::back_inserter(curconnection->SendData)); } size_t libhttppp::HttpResponse::parse(const char *data,size_t inlen){ Loading Loading @@ -1071,7 +1070,7 @@ libhttppp::HttpRequest::HttpRequest() : HttpHeader(){ _lastHeaderData=nullptr; }; libhttppp::HttpRequest::HttpRequest(std::shared_ptr <netplus::event> evapi) : netplus::con(std::move(evapi)) { libhttppp::HttpRequest::HttpRequest(std::shared_ptr <netplus::event> evapi) : netplus::con(evapi) { _RequestType=PARSEREQUEST; _MaxUploadSize=DEFAULT_UPLOADSIZE; _firstHeaderData=nullptr; Loading @@ -1094,24 +1093,24 @@ size_t libhttppp::HttpRequest::parse(){ try{ size_t startpos=0; if((startpos=RecvData->search("GET"))!=std::string::npos){ if((startpos=RecvData.search("GET"))!=std::string::npos){ _RequestType=GETREQUEST; }else if((startpos=RecvData->search("POST"))!=std::string::npos){ }else if((startpos=RecvData.search("POST"))!=std::string::npos){ _RequestType=POSTREQUEST; }else{ excep[HTTPException::Warning] << "Requesttype not known cleanup"; RecvData->clear(); RecvData.clear(); throw excep; } size_t endpos=RecvData->search("\r\n\r\n"),delimetersize=4; size_t endpos=RecvData.search("\r\n\r\n"),delimetersize=4; if(endpos==std::string::npos){ _RequestType=PARSEREQUEST; return 0; } std::copy(RecvData->begin(),RecvData->begin()+endpos, std::copy(RecvData.begin(),RecvData.begin()+endpos, std::inserter<std::vector<char>>(header,header.begin())); bool found=false; Loading @@ -1119,7 +1118,7 @@ size_t libhttppp::HttpRequest::parse(){ endpos+=delimetersize; RecvData->resize(endpos); RecvData.resize(endpos); for(size_t cpos=pos; cpos< header.size(); ++cpos){ if(header[cpos]==' '){ Loading Loading @@ -1214,7 +1213,7 @@ size_t libhttppp::HttpRequest::parse(){ } }catch(netplus::NetException &e){ if (e.getErrorType() != netplus::NetException::Note) { RecvData->clear(); RecvData.clear(); } excep[HTTPException::Error] << "netplus error: " << e.what(); throw excep; Loading Loading @@ -1370,7 +1369,7 @@ void libhttppp::HttpForm::parse(std::shared_ptr<libhttppp::HttpRequest> request) } for(HttpHeader::HeaderData::Values *cval=ctype->getfirstValue(); cval; cval=cval->nextvalue()){ if(request->getContentLength() <= request->RecvData->size()){ if(request->getContentLength() <= request->RecvData.size()){ if(cval->getvalue().find("multipart/form-data") !=std::string::npos){ for(HttpHeader::HeaderData::Values *cbod=ctype->getfirstValue(); cbod; cbod=cbod->nextvalue()){ size_t fcbod=std::string::npos; Loading @@ -1383,10 +1382,10 @@ void libhttppp::HttpForm::parse(std::shared_ptr<libhttppp::HttpRequest> request) break; } } _parseMulitpart(*request->RecvData); _parseMulitpart(request->RecvData); } if(cval->getvalue().find("application/x-www-form-urlencoded")!=std::string::npos){ _parseUrlDecode(*request->RecvData,request->getContentLength()); _parseUrlDecode(request->RecvData,request->getContentLength()); } } } Loading src/http.h +2 −1 Changes for src/http.h: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <vector> #include <string> #include <memory> #include <netplus/socket.h> #include <netplus/connection.h> Loading Loading @@ -204,7 +205,7 @@ namespace libhttppp { }; class HttpRequest : public HttpHeader, public netplus::con{ class HttpRequest : public HttpHeader, public netplus::con, std::enable_shared_from_this<HttpRequest> { public: HttpRequest(); HttpRequest(std::shared_ptr <netplus::event> evapi); Loading src/httpd.cpp +9 −8 Changes for src/httpd.cpp: 9 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -45,13 +45,12 @@ #define MAXDEFAULTCONN 1024 #define MBEDTLS_PSA_CRYPTO_CONFIG true libhttppp::HttpEvent::HttpEvent(std::shared_ptr<netplus::socket> &ssock, int timeout) : netplus::event(ssock,timeout){ libhttppp::HttpEvent::HttpEvent(std::shared_ptr<netplus::socket> &ssock, int timeout) : event(ssock){ } void libhttppp::HttpEvent::CreateConnetion(std::shared_ptr<netplus::con> &curcon,void *res) { res=new HttpRequest(std::enable_shared_from_this<HttpEvent>::shared_from_this()); curcon=std::shared_ptr<HttpRequest>(reinterpret_cast<HttpRequest*>(res)); void libhttppp::HttpEvent::CreateConnetion(std::shared_ptr <netplus::con> &curcon) { curcon=std::make_shared<HttpRequest>(std::enable_shared_from_this<event>::shared_from_this()); } void libhttppp::HttpEvent::RequestEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args){ Loading Loading @@ -81,9 +80,9 @@ REQUESTHANDLING: cureq->_RequestType=PARSEREQUEST; break; case POSTREQUEST: if(cureq->RecvData->size()>=cureq->getContentLength()){ if(cureq->RecvData.size()>=cureq->getContentLength()){ RequestEvent(cureq,tid,args); cureq->RecvData->resize(cureq->getContentLength()); cureq->RecvData.resize(cureq->getContentLength()); cureq->_RequestType=PARSEREQUEST; } break; Loading @@ -105,8 +104,8 @@ void libhttppp::HttpEvent::ResponseEvent(std::shared_ptr<netplus::con> curcon,co std::shared_ptr <HttpRequest> cureq=std::static_pointer_cast<HttpRequest>(curcon); try{ ResponseEvent(cureq,tid,args); if(cureq->SendData->empty()){ cureq->SendData->pos=0; if(cureq->SendData.empty()){ cureq->SendData.pos=0; cureq->clear(); } }catch(HTTPException &e){ Loading Loading @@ -216,6 +215,8 @@ libhttppp::HttpD::HttpD(int argc, char** argv) { _ServerSocket = std::make_shared<netplus::tcp>(httpaddr, port, maxconnections,-1); #endif } }catch (netplus::NetException &e) { HTTPException ee; ee[HTTPException::Critical] << e.what(); Loading src/httpd.h +5 −5 Changes for src/httpd.h: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -43,12 +43,12 @@ namespace libhttppp { public: HttpEvent(std::shared_ptr<netplus::socket> &ssock,int timeout = -1); void CreateConnetion(std::shared_ptr< netplus::con >& curcon, void* res); void CreateConnetion(std::shared_ptr <netplus::con> &curcon); void RequestEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); void ResponseEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); void ConnectEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); void DisconnectEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); virtual void RequestEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); virtual void ResponseEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); virtual void ConnectEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); virtual void DisconnectEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); private: void RequestEvent(std::shared_ptr <netplus::con> curcon, const int tid, ULONG_PTR args); Loading Loading
examples/httpsysinfo.cpp +10 −10 Changes for examples/httpsysinfo.cpp: 10 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -221,7 +221,7 @@ public: } } /*virtual method from event will call for every incomming Request*/ void RequestEvent(std::shared_ptr<libhttppp::HttpRequest> &curreq, const int tid,ULONG_PTR args){ void RequestEvent(std::shared_ptr<libhttppp::HttpRequest> curreq, const int tid,ULONG_PTR args){ try{ /*self implemented controller see above*/ IndexController(curreq); Loading @@ -233,18 +233,18 @@ public: } } void ResponseEvent(std::shared_ptr<libhttppp::HttpRequest> &curreq, const int tid,ULONG_PTR args){ void ResponseEvent(std::shared_ptr<libhttppp::HttpRequest> curreq, const int tid,ULONG_PTR args){ if(curreq->getRequestURL()=="/images/header.png"){ if(curreq->SendData->pos < header_png_size){ size_t si = BLOCKSIZE < (header_png_size-curreq->SendData->pos) ? BLOCKSIZE : (header_png_size-curreq->SendData->pos); curreq->SendData->append((const char*)header_png+curreq->SendData->pos,si); curreq->SendData->pos+=si; if(curreq->SendData.pos < header_png_size){ size_t si = BLOCKSIZE < (header_png_size-curreq->SendData.pos) ? BLOCKSIZE : (header_png_size-curreq->SendData.pos); curreq->SendData.append((const char*)header_png+curreq->SendData.pos,si); curreq->SendData.pos+=si; } }else if(curreq->getRequestURL()=="/favicon.ico "){ if(curreq->SendData->pos < favicon_ico_size){ size_t si = BLOCKSIZE < (favicon_ico_size-curreq->SendData->pos) ? BLOCKSIZE : (favicon_ico_size-curreq->SendData->pos); curreq->SendData->append((const char*)favicon_ico+curreq->SendData->pos,si); curreq->SendData->pos+=si; if(curreq->SendData.pos < favicon_ico_size){ size_t si = BLOCKSIZE < (favicon_ico_size-curreq->SendData.pos) ? BLOCKSIZE : (favicon_ico_size-curreq->SendData.pos); curreq->SendData.append((const char*)favicon_ico+curreq->SendData.pos,si); curreq->SendData.pos+=si; } } } Loading
src/http.cpp +13 −14 Changes for src/http.cpp: 13 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -696,7 +696,6 @@ libhttppp::HttpHeader::HeaderData::HeaderData(const char *key){ libhttppp::HttpHeader::HeaderData::~HeaderData(){ _nextHeaderData=nullptr; clear(); } libhttppp::HttpHeader::HeaderData::Values * libhttppp::HttpHeader::HeaderData::getfirstValue(){ Loading Loading @@ -917,10 +916,10 @@ void libhttppp::HttpResponse::send(std::shared_ptr<netplus::con> curconnection,c printHeader(header); curconnection->SendData->append(header.data(),header.size()); curconnection->SendData.append(header.data(),header.size()); if (datalen > 0) std::copy(data.begin(), data.end(), std::back_inserter(*curconnection->SendData)); std::copy(data.begin(), data.end(), std::back_inserter(curconnection->SendData)); } size_t libhttppp::HttpResponse::parse(const char *data,size_t inlen){ Loading Loading @@ -1071,7 +1070,7 @@ libhttppp::HttpRequest::HttpRequest() : HttpHeader(){ _lastHeaderData=nullptr; }; libhttppp::HttpRequest::HttpRequest(std::shared_ptr <netplus::event> evapi) : netplus::con(std::move(evapi)) { libhttppp::HttpRequest::HttpRequest(std::shared_ptr <netplus::event> evapi) : netplus::con(evapi) { _RequestType=PARSEREQUEST; _MaxUploadSize=DEFAULT_UPLOADSIZE; _firstHeaderData=nullptr; Loading @@ -1094,24 +1093,24 @@ size_t libhttppp::HttpRequest::parse(){ try{ size_t startpos=0; if((startpos=RecvData->search("GET"))!=std::string::npos){ if((startpos=RecvData.search("GET"))!=std::string::npos){ _RequestType=GETREQUEST; }else if((startpos=RecvData->search("POST"))!=std::string::npos){ }else if((startpos=RecvData.search("POST"))!=std::string::npos){ _RequestType=POSTREQUEST; }else{ excep[HTTPException::Warning] << "Requesttype not known cleanup"; RecvData->clear(); RecvData.clear(); throw excep; } size_t endpos=RecvData->search("\r\n\r\n"),delimetersize=4; size_t endpos=RecvData.search("\r\n\r\n"),delimetersize=4; if(endpos==std::string::npos){ _RequestType=PARSEREQUEST; return 0; } std::copy(RecvData->begin(),RecvData->begin()+endpos, std::copy(RecvData.begin(),RecvData.begin()+endpos, std::inserter<std::vector<char>>(header,header.begin())); bool found=false; Loading @@ -1119,7 +1118,7 @@ size_t libhttppp::HttpRequest::parse(){ endpos+=delimetersize; RecvData->resize(endpos); RecvData.resize(endpos); for(size_t cpos=pos; cpos< header.size(); ++cpos){ if(header[cpos]==' '){ Loading Loading @@ -1214,7 +1213,7 @@ size_t libhttppp::HttpRequest::parse(){ } }catch(netplus::NetException &e){ if (e.getErrorType() != netplus::NetException::Note) { RecvData->clear(); RecvData.clear(); } excep[HTTPException::Error] << "netplus error: " << e.what(); throw excep; Loading Loading @@ -1370,7 +1369,7 @@ void libhttppp::HttpForm::parse(std::shared_ptr<libhttppp::HttpRequest> request) } for(HttpHeader::HeaderData::Values *cval=ctype->getfirstValue(); cval; cval=cval->nextvalue()){ if(request->getContentLength() <= request->RecvData->size()){ if(request->getContentLength() <= request->RecvData.size()){ if(cval->getvalue().find("multipart/form-data") !=std::string::npos){ for(HttpHeader::HeaderData::Values *cbod=ctype->getfirstValue(); cbod; cbod=cbod->nextvalue()){ size_t fcbod=std::string::npos; Loading @@ -1383,10 +1382,10 @@ void libhttppp::HttpForm::parse(std::shared_ptr<libhttppp::HttpRequest> request) break; } } _parseMulitpart(*request->RecvData); _parseMulitpart(request->RecvData); } if(cval->getvalue().find("application/x-www-form-urlencoded")!=std::string::npos){ _parseUrlDecode(*request->RecvData,request->getContentLength()); _parseUrlDecode(request->RecvData,request->getContentLength()); } } } Loading
src/http.h +2 −1 Changes for src/http.h: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <vector> #include <string> #include <memory> #include <netplus/socket.h> #include <netplus/connection.h> Loading Loading @@ -204,7 +205,7 @@ namespace libhttppp { }; class HttpRequest : public HttpHeader, public netplus::con{ class HttpRequest : public HttpHeader, public netplus::con, std::enable_shared_from_this<HttpRequest> { public: HttpRequest(); HttpRequest(std::shared_ptr <netplus::event> evapi); Loading
src/httpd.cpp +9 −8 Changes for src/httpd.cpp: 9 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -45,13 +45,12 @@ #define MAXDEFAULTCONN 1024 #define MBEDTLS_PSA_CRYPTO_CONFIG true libhttppp::HttpEvent::HttpEvent(std::shared_ptr<netplus::socket> &ssock, int timeout) : netplus::event(ssock,timeout){ libhttppp::HttpEvent::HttpEvent(std::shared_ptr<netplus::socket> &ssock, int timeout) : event(ssock){ } void libhttppp::HttpEvent::CreateConnetion(std::shared_ptr<netplus::con> &curcon,void *res) { res=new HttpRequest(std::enable_shared_from_this<HttpEvent>::shared_from_this()); curcon=std::shared_ptr<HttpRequest>(reinterpret_cast<HttpRequest*>(res)); void libhttppp::HttpEvent::CreateConnetion(std::shared_ptr <netplus::con> &curcon) { curcon=std::make_shared<HttpRequest>(std::enable_shared_from_this<event>::shared_from_this()); } void libhttppp::HttpEvent::RequestEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args){ Loading Loading @@ -81,9 +80,9 @@ REQUESTHANDLING: cureq->_RequestType=PARSEREQUEST; break; case POSTREQUEST: if(cureq->RecvData->size()>=cureq->getContentLength()){ if(cureq->RecvData.size()>=cureq->getContentLength()){ RequestEvent(cureq,tid,args); cureq->RecvData->resize(cureq->getContentLength()); cureq->RecvData.resize(cureq->getContentLength()); cureq->_RequestType=PARSEREQUEST; } break; Loading @@ -105,8 +104,8 @@ void libhttppp::HttpEvent::ResponseEvent(std::shared_ptr<netplus::con> curcon,co std::shared_ptr <HttpRequest> cureq=std::static_pointer_cast<HttpRequest>(curcon); try{ ResponseEvent(cureq,tid,args); if(cureq->SendData->empty()){ cureq->SendData->pos=0; if(cureq->SendData.empty()){ cureq->SendData.pos=0; cureq->clear(); } }catch(HTTPException &e){ Loading Loading @@ -216,6 +215,8 @@ libhttppp::HttpD::HttpD(int argc, char** argv) { _ServerSocket = std::make_shared<netplus::tcp>(httpaddr, port, maxconnections,-1); #endif } }catch (netplus::NetException &e) { HTTPException ee; ee[HTTPException::Critical] << e.what(); Loading
src/httpd.h +5 −5 Changes for src/httpd.h: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -43,12 +43,12 @@ namespace libhttppp { public: HttpEvent(std::shared_ptr<netplus::socket> &ssock,int timeout = -1); void CreateConnetion(std::shared_ptr< netplus::con >& curcon, void* res); void CreateConnetion(std::shared_ptr <netplus::con> &curcon); void RequestEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); void ResponseEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); void ConnectEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); void DisconnectEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); virtual void RequestEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); virtual void ResponseEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); virtual void ConnectEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); virtual void DisconnectEvent(std::shared_ptr <HttpRequest> curreq,const int tid,ULONG_PTR args); private: void RequestEvent(std::shared_ptr <netplus::con> curcon, const int tid, ULONG_PTR args); Loading