56 lines
878 B
C++
56 lines
878 B
C++
|
|
# include "cgi_utils.hpp"
|
|
|
|
int main (int ac, char **av, char ** env)
|
|
{
|
|
std::string http_header;
|
|
std::string http_body;
|
|
std::string rq_body;
|
|
std::string form_infos;
|
|
std::string path;
|
|
std::ifstream ifd;
|
|
std::stringstream buf;
|
|
size_t status;
|
|
|
|
std::cin >> rq_body;
|
|
|
|
(void)ac;
|
|
(void)av;
|
|
(void)env;
|
|
|
|
http_header = "Content-Type: image/jpeg" CRLF;
|
|
|
|
form_infos = get_form_infos(rq_body);
|
|
path = get_value("file", rq_body);
|
|
path = "./www/" + path;
|
|
|
|
status = ::eval_file_read(path);
|
|
if (status)
|
|
{
|
|
std::cout << "Status: " << status << CRLF CRLF;
|
|
return 0;
|
|
}
|
|
|
|
ifd.open(path.c_str());
|
|
if (!ifd)
|
|
{
|
|
std::cout << "Status: " << 500 << CRLF CRLF;
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
buf << ifd.rdbuf();
|
|
if (!ifd || !buf)
|
|
{
|
|
std::cout << "Status: " << 500 << CRLF CRLF;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
std::cout << http_header << CRLF << buf.str();
|
|
|
|
return 0;
|
|
}
|
|
|
|
|