add serviceinfo
[enigma2.git] / lib / network / http_dyn.cpp
index ea47019..c3a4904 100644 (file)
@@ -1,6 +1,7 @@
 #include <lib/network/http_dyn.h>
 
-eHTTPDyn::eHTTPDyn(eHTTPConnection *c, eString result): eHTTPDataSource(c), result(result)
+DEFINE_REF(eHTTPDyn);
+eHTTPDyn::eHTTPDyn(eHTTPConnection *c, std::string result): eHTTPDataSource(c), result(result)
 {
        wptr=0;
        char buffer[10];
@@ -29,38 +30,45 @@ int eHTTPDyn::doWrite(int hm)
        return (size > wptr) ? 1 : -1;
 }
 
+DEFINE_REF(eHTTPDynPathResolver);
+DEFINE_REF(eHTTPDynPathResolver::eHTTPDynEntry);
+
 eHTTPDynPathResolver::eHTTPDynPathResolver()
 {
-       dyn.setAutoDelete(true);
 }
 
-void eHTTPDynPathResolver::addDyn(eString request, eString path, eString (*function)(eString, eString, eString, eHTTPConnection*))
+void eHTTPDynPathResolver::addDyn(std::string request, std::string path, std::string (*function)(std::string, std::string, std::string, eHTTPConnection*))
 {
        dyn.push_back(new eHTTPDynEntry(request, path, function));
 }
 
-eHTTPDataSource *eHTTPDynPathResolver::getDataSource(eString request, eString path, eHTTPConnection *conn)
+RESULT eHTTPDynPathResolver::getDataSource(eHTTPDataSourcePtr &ptr, std::string request, std::string path, eHTTPConnection *conn)
 {
-       eString p, opt;
-       if (path.find('?')!=eString::npos)
+       std::string p, opt;
+       if (path.find('?')!=std::string::npos)
        {
-               p=path.left(path.find('?'));
-               opt=path.mid(path.find('?')+1);
+               p=path.substr(0, path.find('?'));
+               opt=path.substr(path.find('?')+1);
        }       else
        {
                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;
-                       eString s=i->function(request, path, opt, conn);
+                       std::string s=i->function(request, path, opt, conn);
 
-                       if (s)
-                               return new eHTTPDyn(conn, s);
+                       if (!s.empty())
+                       {
+                               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;
 }