1 #include <lib/network/http_dyn.h>
4 eHTTPDyn::eHTTPDyn(eHTTPConnection *c, std::string result): eHTTPDataSource(c), result(result)
8 snprintf(buffer, 10, "%d", size=result.length());
9 c->local_header["Content-Length"]=std::string(buffer);
21 int eHTTPDyn::doWrite(int hm)
28 connection->writeBlock(result.c_str()+wptr, tw);
30 return (size > wptr) ? 1 : -1;
33 DEFINE_REF(eHTTPDynPathResolver);
34 DEFINE_REF(eHTTPDynPathResolver::eHTTPDynEntry);
36 eHTTPDynPathResolver::eHTTPDynPathResolver()
40 void eHTTPDynPathResolver::addDyn(std::string request, std::string path, std::string (*function)(std::string, std::string, std::string, eHTTPConnection*))
42 dyn.push_back(new eHTTPDynEntry(request, path, function));
45 RESULT eHTTPDynPathResolver::getDataSource(eHTTPDataSourcePtr &ptr, std::string request, std::string path, eHTTPConnection *conn)
48 if (path.find('?')!=std::string::npos)
50 p=path.substr(0, path.find('?'));
51 opt=path.substr(path.find('?')+1);
57 for (eSmartPtrList<eHTTPDynEntry>::iterator i(dyn); i != dyn.end(); ++i)
58 if ((i->path==p) && (i->request==request))
61 std::string s=i->function(request, path, opt, conn);
65 ptr = new eHTTPDyn(conn, s);
69 ptr = new eHTTPError(conn, 500);