2014-01-26 13:02:12 +01:00
|
|
|
#include "StaticFileHandler.H"
|
|
|
|
|
2014-05-05 00:45:39 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
std::string
|
2014-01-26 13:02:12 +01:00
|
|
|
StaticFileHandler::_cleanpath (const char * const path)
|
|
|
|
{
|
2014-05-05 00:45:39 +02:00
|
|
|
//adds no security at all
|
|
|
|
return "static/"+std::string(path);
|
2014-01-26 13:02:12 +01:00
|
|
|
}
|
|
|
|
|
2014-05-05 00:45:39 +02:00
|
|
|
int
|
2014-01-26 13:02:12 +01:00
|
|
|
StaticFileHandler::answer_pathreq(const char * const path,
|
2014-05-05 00:45:39 +02:00
|
|
|
struct mg_connection *conn)
|
2014-01-26 13:02:12 +01:00
|
|
|
{
|
2014-05-05 00:45:39 +02:00
|
|
|
FILE *fp ;
|
|
|
|
char buf[1024];
|
|
|
|
size_t n = 0;
|
|
|
|
|
|
|
|
fp = fopen(_cleanpath(path).c_str(), "r");
|
|
|
|
|
|
|
|
if (fp != NULL) {
|
|
|
|
std::cerr << "outfile" << std::endl;
|
|
|
|
while ((n =fread(buf,1,sizeof(buf),fp)) > 0){
|
|
|
|
mg_send_data(conn,buf,n);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
return MG_TRUE;
|
|
|
|
}
|
|
|
|
return MG_FALSE;
|
2014-01-26 13:02:12 +01:00
|
|
|
}
|
2014-05-05 00:45:39 +02:00
|
|
|
|