X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/1aeefd997cc362c3b37c1587c5f08891b35c3a75..13705824885aa7f8fb779713eab7d0e5874769a4:/lib/network/httpd.cpp diff --git a/lib/network/httpd.cpp b/lib/network/httpd.cpp index acd3ebe6..c89ad7e3 100644 --- a/lib/network/httpd.cpp +++ b/lib/network/httpd.cpp @@ -2,11 +2,16 @@ #include #include +#include +#include #include #include #include #include +#include +#include + eHTTPDataSource::eHTTPDataSource(eHTTPConnection *c): connection(c) { } @@ -24,9 +29,11 @@ int eHTTPDataSource::doWrite(int) return 0; } +DEFINE_REF(eHTTPError); + eHTTPError::eHTTPError(eHTTPConnection *c, int errcode): eHTTPDataSource(c), errcode(errcode) { - eString error="unknown error"; + std::string error="unknown error"; switch (errcode) { case 400: error="Bad Request"; break; @@ -44,9 +51,9 @@ eHTTPError::eHTTPError(eHTTPConnection *c, int errcode): eHTTPDataSource(c), err int eHTTPError::doWrite(int w) { - eString html; - html+="Error "+eString().setNum(connection->code)+""+ - "

Error "+eString().setNum(errcode)+": "+connection->code_descr+"

\n"; + std::string html; + html+="Error " + getNum(connection->code) + ""+ + "

Error " + getNum(errcode) + ": " + connection->code_descr + "

\n"; connection->writeBlock(html.c_str(), html.length()); return -1; } @@ -70,6 +77,7 @@ eHTTPConnection::eHTTPConnection(int socket, int issocket, eHTTPD *parent, int p void eHTTPConnection::destruct() { + eDebug("destruct, this %p!", this); gotHangup(); delete this; } @@ -107,11 +115,7 @@ void eHTTPConnection::gotHangup() { if (data && remotestate == stateData) data->haveData(0, 0); - if (data) - { - delete data; - data=0; - } + data = 0; transferDone(0); localstate=stateWait; @@ -266,7 +270,7 @@ int eHTTPConnection::processLocalState() #ifdef DEBUG_HTTPD eDebug("local request"); #endif - eString req=request+" "+requestpath+" "+httpversion+"\r\n"; + std::string req=request+" "+requestpath+" "+httpversion+"\r\n"; writeBlock(req.c_str(), req.length()); localstate=stateHeader; remotestate=stateResponse; @@ -277,7 +281,7 @@ int eHTTPConnection::processLocalState() #ifdef DEBUG_HTTPD eDebug("local Response"); #endif - writeString( (httpversion + " " + eString().setNum(code)+" " + code_descr + "\r\n").c_str() ); + writeString( (httpversion + " " + getNum(code) + " " + code_descr + "\r\n").c_str() ); localstate=stateHeader; local_header["Connection"]="close"; break; @@ -323,7 +327,7 @@ int eHTTPConnection::processLocalState() // move to stateClose if (remote_header.find("Connection") != remote_header.end()) { - eString &connection=remote_header["Connection"]; + std::string &connection=remote_header["Connection"]; if (connection == "keep-alive") localstate=stateWait; else @@ -344,10 +348,8 @@ int eHTTPConnection::processLocalState() #endif if (persistent) { - if (data) - delete data; - data=0; - localstate=stateWait; + data = 0; + localstate = stateWait; } else close(); // bye, bye, remote return 1; @@ -387,7 +389,7 @@ int eHTTPConnection::processRemoteState() #ifdef DEBUG_HTTPD eDebug("stateRequest"); #endif - eString line; + std::string line; if (!getLine(line)) { done=1; @@ -400,8 +402,7 @@ int eHTTPConnection::processRemoteState() del[1]=line.find(" ", del[0]+1); if (del[0]==-1) { - if (data) - delete data; + data = 0; eDebug("request buggy"); httpversion="HTTP/1.0"; data=new eHTTPError(this, 400); @@ -412,16 +413,16 @@ int eHTTPConnection::processRemoteState() return -1; break; } - request=line.left(del[0]); - requestpath=line.mid(del[0]+1, (del[1]==-1)?-1:(del[1]-del[0]-1)); + request=line.substr(0, del[0]); + requestpath=line.substr(del[0]+1, (del[1]==-1)?-1:(del[1]-del[0]-1)); if (del[1]!=-1) { is09=0; - httpversion=line.mid(del[1]+1); + httpversion=line.substr(del[1]+1); } else is09=1; - if (is09 || (httpversion.left(7) != "HTTP/1.") || httpversion.size()!=8) + if (is09 || (httpversion.substr(0, 7) != "HTTP/1.") || httpversion.size()!=8) { remotestate=stateData; done=0; @@ -437,7 +438,7 @@ int eHTTPConnection::processRemoteState() #ifdef DEBUG_HTTPD eDebug("state response.."); #endif - eString line; + std::string line; if (!getLine(line)) { done=1; @@ -454,10 +455,10 @@ int eHTTPConnection::processRemoteState() code=-1; else { - httpversion=line.left(del[0]); - code=atoi(line.mid(del[0]+1, (del[1]==-1)?-1:(del[1]-del[0]-1)).c_str()); + httpversion=line.substr(0, del[0]); + code=atoi(line.substr(del[0]+1, (del[1]==-1)?-1:(del[1]-del[0]-1)).c_str()); if (del[1] != -1) - code_descr=line.mid(del[1]+1); + code_descr=line.substr(del[1]+1); else code_descr=""; } @@ -470,7 +471,7 @@ int eHTTPConnection::processRemoteState() #ifdef DEBUG_HTTPD eDebug("remote stateHeader"); #endif - eString line; + std::string line; if (!getLine(line)) { done=1; @@ -489,20 +490,17 @@ int eHTTPConnection::processRemoteState() if (parent) { - for (ePtrList::iterator i(parent->resolver); i != parent->resolver.end(); ++i) - { - if ((data=i->getDataSource(request, requestpath, this))) + for (eSmartPtrList::iterator i(parent->resolver); i != parent->resolver.end(); ++i) + if (!(i->getDataSource(data, request, requestpath, this))) break; - } localstate=stateResponse; // can be overridden by dataSource } else data=createDataSource(this); if (!data) { - if (data) - delete data; - data=new eHTTPError(this, 404); + data = 0; + data = new eHTTPError(this, 404); } if (content_length || // if content-length is set, we have content @@ -519,9 +517,9 @@ int eHTTPConnection::processRemoteState() } else { int del=line.find(":"); - eString name=line.left(del), value=line.mid(del+1); + std::string name=line.substr(0, del), value=line.substr(del+1); if (value[0]==' ') - value=value.mid(1); + value=value.substr(1); remote_header[std::string(name)]=std::string(value); } done=1; @@ -583,7 +581,7 @@ void eHTTPConnection::writeString(const char *data) writeBlock(data, strlen(data)); } -int eHTTPConnection::getLine(eString &line) +int eHTTPConnection::getLine(std::string &line) { if (!canReadLine()) return 0; @@ -599,11 +597,7 @@ int eHTTPConnection::getLine(eString &line) void eHTTPConnection::gotError(int err) { - if (data) - { - delete data; - data=0; - } + data = 0; transferDone(err); delete this; } @@ -614,15 +608,13 @@ eHTTPD::eHTTPD(int port, eMainloop *ml): eServerSocket(port, ml), ml(ml) eDebug("[NET] httpd server FAILED on port %d", port); else eDebug("[NET] httpd server started on port %d", port); -#warning resolver autodelete removed } eHTTPConnection::~eHTTPConnection() { + eDebug("HTTP connection destruct"); if ((!persistent) && (state()!=Idle)) eWarning("~eHTTPConnection, status still %d", state()); - if (data) - delete data; } void eHTTPD::newConnection(int socket)