X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Fhttp%2Fpages%2Fshowimagepage.cpp;fp=src%2Fhttp%2Fpages%2Fshowimagepage.cpp;h=8b653ee04bf457801c1d1dca3e0d309930932abd;hp=0000000000000000000000000000000000000000;hb=221236a4d3aac4144529d418ce368db5c98facb0;hpb=d5c9f7e6c1dd263dfc85a3cb5941a378a5ddd923 diff --git a/src/http/pages/showimagepage.cpp b/src/http/pages/showimagepage.cpp new file mode 100644 index 0000000..8b653ee --- /dev/null +++ b/src/http/pages/showimagepage.cpp @@ -0,0 +1,64 @@ +#include "../../../include/http/pages/showimagepage.h" + +#ifdef XMEM + #include +#endif + +std::map > ShowImagePage::m_imagecache; + +void ShowImagePage::handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response) +{ + m_log->trace("ShowImagePage::handleRequest from "+request.clientAddress().toString()); + + std::map queryvars; + CreateQueryVarMap(request,queryvars); + + if(request.getVersion()==Poco::Net::HTTPRequest::HTTP_1_1) + { + response.setChunkedTransferEncoding(true); + } + + std::string content=""; + if(queryvars.find("image")!=queryvars.end()) + { + if(m_imagecache.find((*queryvars.find("image")).second)!=m_imagecache.end()) + { + content+=std::string(m_imagecache[(*queryvars.find("image")).second].begin(),m_imagecache[(*queryvars.find("image")).second].end()); + } + else + { + FILE *infile=fopen((*queryvars.find("image")).second.c_str(),"rb"); + if(infile) + { + fseek(infile,0,SEEK_END); + long filelen=ftell(infile); + fseek(infile,0,SEEK_SET); + + if(filelen>0) + { + std::vector data(filelen,0); + fread(&data[0],1,data.size(),infile); + content+=std::string(data.begin(),data.end()); + m_imagecache[(*queryvars.find("image")).second]=data; + } + + fclose(infile); + } + } + } + + std::ostream &ostr = response.send(); + ostr << content; +} + +const bool ShowImagePage::WillHandleURI(const std::string &uri) +{ + if(uri.find("showimage.htm")!=std::string::npos) + { + return true; + } + else + { + return false; + } +}