#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;
eHTTPFilePathResolver::eHTTPFilePathResolver()
{
-#warning autodelete removed
}
static char _base64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
-static int unbase64(eString &dst, const eString string)
+static int unbase64(std::string &dst, const std::string string)
{
dst="";
char c[4];
return !!strcmp(cres, cpwd);
}
-static int checkAuth(const eString cauth)
+static int checkAuth(const std::string cauth)
{
- eString auth;
- if (cauth.left(6) != "Basic ")
+ std::string auth;
+ if (cauth.substr(0, 6) != "Basic ")
return -1;
- if (unbase64(auth, cauth.mid(6)))
+ if (unbase64(auth, cauth.substr(6)))
return -1;
- eString username=auth.left(auth.find(":"));
- eString password=auth.mid(auth.find(":")+1);
+ std::string username=auth.substr(0, auth.find(":"));
+ std::string password=auth.substr(auth.find(":")+1);
if (CheckUnixPassword(username.c_str(), password.c_str()))
return -1;
return 0;
}
-eHTTPDataSource *eHTTPFilePathResolver::getDataSource(eString request, eString 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());
else if (request == "PUT")
method=eHTTPFile::methodPUT;
else
- return new eHTTPError(conn, 405); // method not allowed
- if (path.find("../")!=eString::npos) // evil hax0r
- return new eHTTPError(conn, 403);
+ {
+ ptr = new eHTTPError(conn, 405); // method not allowed
+ return 0;
+ }
+ if (path.find("../")!=std::string::npos) // evil hax0r
+ {
+ ptr = new eHTTPError(conn, 403);
+ return 0;
+ }
if (path[0] != '/') // prepend '/'
path.insert(0,"/");
if (path[path.length()-1]=='/')
eHTTPDataSource *data=0;
for (ePtrList<eHTTPFilePath>::iterator i(translate); i != translate.end(); ++i)
{
- if (i->root==path.left(i->root.length()))
+ if (i->root==path.substr(0, i->root.length()))
{
- eString newpath=i->path+path.mid(i->root.length());
+ std::string newpath=i->path+path.substr(i->root.length());
if (newpath.find('?'))
- newpath=newpath.left(newpath.find('?'));
+ newpath=newpath.substr(0, newpath.find('?'));
eDebug("translated %s to %s", path.c_str(), newpath.c_str());
if (i->authorized & ((method==eHTTPFile::methodGET)?1:2))
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;
}
}
break;
}
- eString ext=path.mid(path.rfind('.'));
+ std::string ext=path.substr(path.rfind('.'));
const char *mime="text/unknown";
if ((ext==".html") || (ext==".htm"))
mime="text/html";
break;
}
}
- return data;
+ if (!data)
+ return -1;
+ ptr = data;
+ return 0;
}
-void eHTTPFilePathResolver::addTranslation(eString path, eString root, int authorized)
+void eHTTPFilePathResolver::addTranslation(std::string path, std::string root, int authorized)
{
if (path[path.length()-1]!='/')
path+='/';