aboutsummaryrefslogtreecommitdiff
path: root/lib/network
diff options
context:
space:
mode:
authorFelix Domke <tmbinc@elitedvb.net>2005-01-09 16:29:34 +0000
committerFelix Domke <tmbinc@elitedvb.net>2005-01-09 16:29:34 +0000
commitba02fb4aced5868d047a5bffbd2ed87583daee4d (patch)
treebcfea66b1f7fd2212539a99abc074de1424ac9a0 /lib/network
parent2494509cd031727d92c6556089c99711d16d8af9 (diff)
downloadenigma2-ba02fb4aced5868d047a5bffbd2ed87583daee4d.tar.gz
enigma2-ba02fb4aced5868d047a5bffbd2ed87583daee4d.zip
- add more python stuff
- fix some gui/gdi - add eslider - improve windowstyle
Diffstat (limited to 'lib/network')
-rw-r--r--lib/network/Makefile.am2
-rw-r--r--lib/network/http.cpp33
-rw-r--r--lib/network/http.h28
-rw-r--r--lib/network/http_dyn.cpp20
-rw-r--r--lib/network/http_dyn.h12
-rw-r--r--lib/network/http_file.cpp25
-rw-r--r--lib/network/http_file.h8
-rw-r--r--lib/network/httpd.cpp43
-rw-r--r--lib/network/httpd.h24
-rw-r--r--lib/network/socket.cpp1
-rw-r--r--lib/network/xmlrpc.h3
11 files changed, 146 insertions, 53 deletions
diff --git a/lib/network/Makefile.am b/lib/network/Makefile.am
index f5efef9a..f9677a10 100644
--- a/lib/network/Makefile.am
+++ b/lib/network/Makefile.am
@@ -4,6 +4,6 @@ INCLUDES = \
noinst_LIBRARIES = libenigma_network.a
libenigma_network_a_SOURCES = \
- http_dyn.cpp http_file.cpp httpd.cpp serversocket.cpp socket.cpp
+ httpd.cpp http_dyn.cpp http_file.cpp http.cpp serversocket.cpp socket.cpp
# xmlrpc.cpp
diff --git a/lib/network/http.cpp b/lib/network/http.cpp
new file mode 100644
index 00000000..dc98a0bd
--- /dev/null
+++ b/lib/network/http.cpp
@@ -0,0 +1,33 @@
+#include <lib/base/init_num.h>
+#include <lib/base/init.h>
+#include <lib/network/http.h>
+
+eHTTPServer *eHTTPServer::m_instance;
+
+RESULT eHTTPServer::getDynResolver(eHTTPDynPathResolverPtr &ptr)
+{
+ ptr = m_dyn;
+ if (!m_dyn)
+ return -1;
+ return 0;
+}
+
+RESULT eHTTPServer::getFileResolver(eHTTPFilePathResolverPtr &ptr)
+{
+ ptr = m_file;
+ if (!m_file)
+ return -1;
+ return 0;
+}
+
+eHTTPServer::eHTTPServer(): m_httpd(8080, eApp)
+{
+ m_instance = this;
+ m_dyn = new eHTTPDynPathResolver();
+ m_file = new eHTTPFilePathResolver();
+
+ m_httpd.addResolver(m_dyn);
+ m_httpd.addResolver(m_file);
+}
+
+eAutoInitP0<eHTTPServer> init_eHTTPServer(eAutoInitNumbers::network, "main http server");
diff --git a/lib/network/http.h b/lib/network/http.h
new file mode 100644
index 00000000..fa2a4fba
--- /dev/null
+++ b/lib/network/http.h
@@ -0,0 +1,28 @@
+#ifndef __http_h
+#define __http_h
+
+#include <lib/network/httpd.h>
+#include <lib/network/http_file.h>
+#include <lib/network/http_dyn.h>
+
+class eHTTPDynPathResolver;
+class eHTTPFilePathResolver;
+
+typedef ePtr<eHTTPDynPathResolver> eHTTPDynPathResolverPtr;
+typedef ePtr<eHTTPFilePathResolver> eHTTPFilePathResolverPtr;
+
+class eHTTPServer
+{
+ eHTTPD m_httpd;
+ static eHTTPServer *m_instance;
+ eHTTPDynPathResolverPtr m_dyn;
+ eHTTPFilePathResolverPtr m_file;
+public:
+ RESULT getDynResolver(eHTTPDynPathResolverPtr &ptr);
+ RESULT getFileResolver(eHTTPFilePathResolverPtr &ptr);
+
+ eHTTPServer();
+ static eHTTPServer *getInstance() { return m_instance; }
+};
+
+#endif
diff --git a/lib/network/http_dyn.cpp b/lib/network/http_dyn.cpp
index eb94d462..c3a49048 100644
--- a/lib/network/http_dyn.cpp
+++ b/lib/network/http_dyn.cpp
@@ -1,5 +1,6 @@
#include <lib/network/http_dyn.h>
+DEFINE_REF(eHTTPDyn);
eHTTPDyn::eHTTPDyn(eHTTPConnection *c, std::string result): eHTTPDataSource(c), result(result)
{
wptr=0;
@@ -29,9 +30,11 @@ int eHTTPDyn::doWrite(int hm)
return (size > wptr) ? 1 : -1;
}
+DEFINE_REF(eHTTPDynPathResolver);
+DEFINE_REF(eHTTPDynPathResolver::eHTTPDynEntry);
+
eHTTPDynPathResolver::eHTTPDynPathResolver()
{
-#warning autodelete removed
}
void eHTTPDynPathResolver::addDyn(std::string request, std::string path, std::string (*function)(std::string, std::string, std::string, eHTTPConnection*))
@@ -39,7 +42,7 @@ void eHTTPDynPathResolver::addDyn(std::string request, std::string path, std::st
dyn.push_back(new eHTTPDynEntry(request, path, function));
}
-eHTTPDataSource *eHTTPDynPathResolver::getDataSource(std::string request, std::string path, eHTTPConnection *conn)
+RESULT eHTTPDynPathResolver::getDataSource(eHTTPDataSourcePtr &ptr, std::string request, std::string path, eHTTPConnection *conn)
{
std::string p, opt;
if (path.find('?')!=std::string::npos)
@@ -51,16 +54,21 @@ eHTTPDataSource *eHTTPDynPathResolver::getDataSource(std::string request, std::s
p=path;
opt="";
}
- for (ePtrList<eHTTPDynEntry>::iterator i(dyn); i != dyn.end(); ++i)
+ for (eSmartPtrList<eHTTPDynEntry>::iterator i(dyn); i != dyn.end(); ++i)
if ((i->path==p) && (i->request==request))
{
conn->code=-1;
std::string s=i->function(request, path, opt, conn);
if (!s.empty())
- return new eHTTPDyn(conn, s);
+ {
+ ptr = new eHTTPDyn(conn, s);
+ return 0;
+ }
- return new eHTTPError(conn, 500);
+ ptr = new eHTTPError(conn, 500);
+ return 0;
}
- return 0;
+ ptr = 0;
+ return -1;
}
diff --git a/lib/network/http_dyn.h b/lib/network/http_dyn.h
index d714403b..61116409 100644
--- a/lib/network/http_dyn.h
+++ b/lib/network/http_dyn.h
@@ -5,6 +5,8 @@
class eHTTPDyn: public eHTTPDataSource
{
+ DECLARE_REF;
+private:
std::string result;
int wptr, size;
public:
@@ -13,10 +15,14 @@ public:
int doWrite(int);
};
-class eHTTPDynPathResolver: public eHTTPPathResolver
+class eHTTPDynPathResolver: public iHTTPPathResolver
{
+ DECLARE_REF;
+private:
struct eHTTPDynEntry
{
+ DECLARE_REF;
+ public:
std::string request, path;
std::string (*function)(std::string request, std::string path, std::string opt, eHTTPConnection *content);
@@ -24,11 +30,11 @@ class eHTTPDynPathResolver: public eHTTPPathResolver
{
}
};
- ePtrList<eHTTPDynEntry> dyn;
+ eSmartPtrList<eHTTPDynEntry> dyn;
public:
void addDyn(std::string request, std::string path, std::string (*function)(std::string, std::string, std::string, eHTTPConnection *conn));
eHTTPDynPathResolver();
- eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn);
+ RESULT getDataSource(eHTTPDataSourcePtr &ptr, std::string request, std::string path, eHTTPConnection *conn);
};
#endif
diff --git a/lib/network/http_file.cpp b/lib/network/http_file.cpp
index 2b47d63c..6c6abc83 100644
--- a/lib/network/http_file.cpp
+++ b/lib/network/http_file.cpp
@@ -6,6 +6,8 @@
#include <shadow.h>
#include <pwd.h>
+DEFINE_REF(eHTTPFile);
+
eHTTPFile::eHTTPFile(eHTTPConnection *c, int _fd, int method, const char *mime): eHTTPDataSource(c), method(method)
{
fd=_fd;
@@ -58,7 +60,6 @@ eHTTPFile::~eHTTPFile()
eHTTPFilePathResolver::eHTTPFilePathResolver()
{
-#warning autodelete removed
}
@@ -138,7 +139,9 @@ static int checkAuth(const std::string cauth)
return 0;
}
-eHTTPDataSource *eHTTPFilePathResolver::getDataSource(std::string request, std::string path, eHTTPConnection *conn)
+DEFINE_REF(eHTTPFilePathResolver);
+
+RESULT eHTTPFilePathResolver::getDataSource(eHTTPDataSourcePtr &ptr, std::string request, std::string path, eHTTPConnection *conn)
{
int method;
eDebug("request = %s, path = %s", request.c_str(), path.c_str());
@@ -147,9 +150,15 @@ eHTTPDataSource *eHTTPFilePathResolver::getDataSource(std::string request, std::
else if (request == "PUT")
method=eHTTPFile::methodPUT;
else
- return new eHTTPError(conn, 405); // method not allowed
+ {
+ ptr = new eHTTPError(conn, 405); // method not allowed
+ return 0;
+ }
if (path.find("../")!=std::string::npos) // evil hax0r
- return new eHTTPError(conn, 403);
+ {
+ ptr = new eHTTPError(conn, 403);
+ return 0;
+ }
if (path[0] != '/') // prepend '/'
path.insert(0,"/");
if (path[path.length()-1]=='/')
@@ -171,7 +180,8 @@ eHTTPDataSource *eHTTPFilePathResolver::getDataSource(std::string request, std::
if ((i == conn->remote_header.end()) || checkAuth(i->second))
{
conn->local_header["WWW-Authenticate"]="Basic realm=\"dreambox\"";
- return new eHTTPError(conn, 401); // auth req'ed
+ ptr = new eHTTPError(conn, 401); // auth req'ed
+ return 0;
}
}
@@ -215,7 +225,10 @@ eHTTPDataSource *eHTTPFilePathResolver::getDataSource(std::string request, std::
break;
}
}
- return data;
+ if (!data)
+ return -1;
+ ptr = data;
+ return 0;
}
void eHTTPFilePathResolver::addTranslation(std::string path, std::string root, int authorized)
diff --git a/lib/network/http_file.h b/lib/network/http_file.h
index 109dc07e..6feb562d 100644
--- a/lib/network/http_file.h
+++ b/lib/network/http_file.h
@@ -5,6 +5,8 @@
class eHTTPFile: public eHTTPDataSource
{
+ DECLARE_REF;
+private:
int fd, size;
const char *mime;
int method;
@@ -16,8 +18,10 @@ public:
void haveData(void *data, int len);
};
-class eHTTPFilePathResolver: public eHTTPPathResolver
+class eHTTPFilePathResolver: public iHTTPPathResolver
{
+ DECLARE_REF;
+public:
struct eHTTPFilePath
{
std::string path;
@@ -30,7 +34,7 @@ class eHTTPFilePathResolver: public eHTTPPathResolver
ePtrList<eHTTPFilePath> translate;
public:
eHTTPFilePathResolver();
- eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn);
+ RESULT getDataSource(eHTTPDataSourcePtr &ptr, std::string request, std::string path, eHTTPConnection *conn);
void addTranslation(std::string path, std::string root, int auth);
};
diff --git a/lib/network/httpd.cpp b/lib/network/httpd.cpp
index f706ccf8..c89ad7e3 100644
--- a/lib/network/httpd.cpp
+++ b/lib/network/httpd.cpp
@@ -2,12 +2,16 @@
#include <lib/network/httpd.h>
#include <sys/socket.h>
+#include <lib/base/smartptr.h>
#include <lib/base/estring.h>
#include <error.h>
#include <errno.h>
#include <time.h>
#include <ctype.h>
+#include <lib/network/http_dyn.h>
+#include <lib/network/http_file.h>
+
eHTTPDataSource::eHTTPDataSource(eHTTPConnection *c): connection(c)
{
}
@@ -25,6 +29,8 @@ int eHTTPDataSource::doWrite(int)
return 0;
}
+DEFINE_REF(eHTTPError);
+
eHTTPError::eHTTPError(eHTTPConnection *c, int errcode): eHTTPDataSource(c), errcode(errcode)
{
std::string error="unknown error";
@@ -71,6 +77,7 @@ eHTTPConnection::eHTTPConnection(int socket, int issocket, eHTTPD *parent, int p
void eHTTPConnection::destruct()
{
+ eDebug("destruct, this %p!", this);
gotHangup();
delete this;
}
@@ -108,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;
@@ -345,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;
@@ -401,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);
@@ -490,20 +490,17 @@ int eHTTPConnection::processRemoteState()
if (parent)
{
- for (ePtrList<eHTTPPathResolver>::iterator i(parent->resolver); i != parent->resolver.end(); ++i)
- {
- if ((data=i->getDataSource(request, requestpath, this)))
+ for (eSmartPtrList<iHTTPPathResolver>::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
@@ -600,11 +597,7 @@ int eHTTPConnection::getLine(std::string &line)
void eHTTPConnection::gotError(int err)
{
- if (data)
- {
- delete data;
- data=0;
- }
+ data = 0;
transferDone(err);
delete this;
}
@@ -615,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)
diff --git a/lib/network/httpd.h b/lib/network/httpd.h
index 61fe2c75..30c3c032 100644
--- a/lib/network/httpd.h
+++ b/lib/network/httpd.h
@@ -4,6 +4,7 @@
#include <asm/types.h>
#include <map>
+#include <lib/base/object.h>
#include <lib/base/eptrlist.h>
#include <lib/base/ebase.h>
#include <string>
@@ -15,14 +16,17 @@ class eHTTPConnection;
class eHTTPDataSource;
class eHTTPD;
-class eHTTPPathResolver
+class eHTTPDataSource;
+typedef ePtr<eHTTPDataSource> eHTTPDataSourcePtr;
+
+class iHTTPPathResolver: public iObject
{
public:
- virtual ~eHTTPPathResolver() {};
- virtual eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn)=0;
+ virtual ~iHTTPPathResolver() {};
+ virtual RESULT getDataSource(eHTTPDataSourcePtr &source, std::string request, std::string path, eHTTPConnection *conn)=0;
};
-class eHTTPDataSource
+class eHTTPDataSource: public iObject
{
protected:
eHTTPConnection *connection;
@@ -33,8 +37,12 @@ public:
virtual int doWrite(int bytes); // number of written bytes, -1 for "no more"
};
+typedef ePtr<eHTTPDataSource> eHTTPDataSourcePtr;
+
class eHTTPError: public eHTTPDataSource
{
+ DECLARE_REF;
+private:
int errcode;
public:
eHTTPError(eHTTPConnection *c, int errcode);
@@ -53,7 +61,7 @@ class eHTTPConnection: public eSocket
int processRemoteState();
void writeString(const char *data);
- eHTTPDataSource *data;
+ eHTTPDataSourcePtr data;
eHTTPD *parent;
int buffersize;
@@ -110,14 +118,14 @@ public:
class eHTTPD: public eServerSocket
{
friend class eHTTPConnection;
- ePtrList<eHTTPPathResolver> resolver;
+ eSmartPtrList<iHTTPPathResolver> resolver;
eMainloop *ml;
public:
eHTTPD(int port, eMainloop *ml);
void newConnection(int socket);
- void addResolver(eHTTPPathResolver *r) { resolver.push_back(r); }
- void removeResolver(eHTTPPathResolver *r) { resolver.remove(r); }
+ void addResolver(iHTTPPathResolver *r) { resolver.push_back(r); }
+ void removeResolver(iHTTPPathResolver *r) { resolver.remove(r); }
};
#endif
diff --git a/lib/network/socket.cpp b/lib/network/socket.cpp
index 628a128b..b2ab7437 100644
--- a/lib/network/socket.cpp
+++ b/lib/network/socket.cpp
@@ -269,6 +269,7 @@ int eSocket::connectToHost(std::string hostname, int port)
eSocket::eSocket(eMainloop *ml): readbuffer(32768), writebuffer(32768), rsn(0)
{
+ ASSERT(ml);
int s=socket(AF_INET, SOCK_STREAM, 0);
#if 0
eDebug("[SOCKET]: initalized socket %d", socketdesc);
diff --git a/lib/network/xmlrpc.h b/lib/network/xmlrpc.h
index 5347dbfe..05fd3cca 100644
--- a/lib/network/xmlrpc.h
+++ b/lib/network/xmlrpc.h
@@ -69,8 +69,9 @@ void xmlrpc_addMethod(std::string methodName, int (*)(std::vector<eXMLRPCVariant
void xmlrpc_fault(ePtrList<eXMLRPCVariant> &res, int faultCode, std::string faultString);
int xmlrpc_checkArgs(std::string args, std::vector<eXMLRPCVariant>&, ePtrList<eXMLRPCVariant> &res);
-class eHTTPXMLRPCResolver: public eHTTPPathResolver
+class eHTTPXMLRPCResolver: public iHTTPPathResolver
{
+ DECLARE_REF;
public:
eHTTPXMLRPCResolver();
eHTTPDataSource *getDataSource(std::string request, std::string path, eHTTPConnection *conn);