Browse Source

save 22-11-3

master
nicolas-arnaud 2 years ago
parent
commit
0331ff68af
  1. 155
      srcs/load/Route.cpp
  2. 273
      srcs/load/Socket.cpp
  3. 190
      srcs/tools.cpp

155
srcs/load/Route.cpp

@ -1,27 +1,28 @@
#include "webserv.hpp"
Route::Route(Server *server, string location, JSONNode *datas)
: _server(server), _location(location) {
JSONObject object = datas->obj();
JSONNode *tmp;
if ((tmp = object["root"]))
_root = tmp->str();
if ((tmp = object["return"]))
_ret = tmp->str();
if ((tmp = object["autoindex"]))
_autoindex = tmp->boo();
if ((tmp = object["indexs"])) {
JSONList indexs = tmp->lst();
for (JSONList::iterator it = indexs.begin(); it < indexs.end(); it++) {
_indexs.push_back((*it)->str());
}
}
if ((tmp = object["add_header"])) {
JSONList headers = tmp->lst();
for (JSONList::iterator it = headers.begin(); it < headers.end(); it++) {
_headers.push_back((*it)->str());
}
}
: _server(server), _location(location) {
JSONObject object = datas->obj();
JSONNode *tmp;
if ((tmp = object["root"]))
_root = tmp->str();
if ((tmp = object["return"]))
_ret = tmp->str();
if ((tmp = object["autoindex"]))
_autoindex = tmp->boo();
if ((tmp = object["indexs"])) {
JSONList indexs = tmp->lst();
for (JSONList::iterator it = indexs.begin(); it < indexs.end(); it++) {
_indexs.push_back((*it)->str());
}
}
if ((tmp = object["add_header"])) {
JSONList headers = tmp->lst();
for (JSONList::iterator it = headers.begin(); it < headers.end();
it++) {
_headers.push_back((*it)->str());
}
}
}
Route::~Route(void) {}
@ -31,67 +32,67 @@ string Route::getRoot(void) { return _root; }
string Route::getReturn(void) { return _ret; }
std::vector<string> Route::getIndexsLst(void) { return _indexs; }
std::vector<string> Route::getHeadersLst(void) { return _headers; }
string Route::getIndex(string uri, string path) {
std::stringstream content;
std::stringstream ret;
DIR *dir;
struct dirent *entry;
struct stat info;
std::vector<string> indexs = getIndexsLst();
std::vector<string>::iterator it;
std::stringstream content;
std::stringstream ret;
DIR *dir;
struct dirent *entry;
struct stat info;
std::vector<string> indexs = getIndexsLst();
std::vector<string>::iterator it;
if ((dir = opendir(path.c_str())) == NULL)
return "";
else {
content << "<h3 style=\"text-align: center;\">" << path
<< " files :</h3>\n<ul>\n";
while ((entry = readdir(dir)) != NULL) {
if (entry->d_name[0] == '.')
continue;
for (it = indexs.begin(); it < indexs.end(); it++) {
if (entry->d_name == *it)
return (read_file(path + "/" + *it));
}
content << "<li><a href=\"" << uri + "/" + entry->d_name << "\">"
<< entry->d_name << "</a></li>\n";
if (stat(path.c_str(), &info) != 0)
std::cerr << "stat() error on " << path << ": " << strerror(errno)
<< "\n";
}
content << "<ul>";
closedir(dir);
}
if (!_autoindex)
return "";
ret << "Content-type: text/html \r\n";
ret << "Content-length: " << content.str().length() << "\r\n";
ret << "\r\n" << content.str();
return ret.str();
if ((dir = opendir(path.c_str())) == NULL)
return "";
else {
content << "<h3 style=\"text-align: center;\">" << path
<< " files :</h3>\n<ul>\n";
while ((entry = readdir(dir)) != NULL) {
if (entry->d_name[0] == '.')
continue;
for (it = indexs.begin(); it < indexs.end(); it++) {
if (entry->d_name == *it)
return (read_file(path + "/" + *it));
}
content << "<li><a href=\"" << uri + "/" + entry->d_name << "\">"
<< entry->d_name << "</a></li>\n";
if (stat(path.c_str(), &info) != 0)
std::cerr << "stat() error on " << path << ": "
<< strerror(errno) << "\n";
}
content << "<ul>";
closedir(dir);
}
if (!_autoindex)
return "";
ret << "Content-type: text/html \r\n";
ret << "Content-length: " << content.str().length() << "\r\n";
ret << "\r\n" << content.str();
return ret.str();
}
string Route::correctUri(string uri) {
std::stringstream ret;
std::vector<string>::iterator it;
std::vector<string>::iterator it2;
std::stringstream ret;
std::vector<string>::iterator it;
std::vector<string>::iterator it2;
// cout << "Correcting request: " << uri << " with root: " << _root << "\n";
ret << _root;
std::vector<string> loc_split = split(_location, '/');
std::vector<string> uri_split = split(uri, '/');
it2 = uri_split.begin();
for (it = loc_split.begin(); it < loc_split.end(); it++) {
while (*it2 == "")
it2++;
while (*it == "")
it++;
if (it != loc_split.end())
it2++;
}
// cout << "Correcting request: " << uri << " with root: " << _root << "\n";
ret << _root;
std::vector<string> loc_split = split(_location, '/');
std::vector<string> uri_split = split(uri, '/');
it2 = uri_split.begin();
for (it = loc_split.begin(); it < loc_split.end(); it++) {
while (*it2 == "")
it2++;
while (*it == "")
it++;
if (it != loc_split.end())
it2++;
}
while (it2 < uri_split.end()) {
ret << "/" << *(it2++);
}
// cout << "resutlt: " << ret.str() << "\n";
return ret.str();
while (it2 < uri_split.end()) {
ret << "/" << *(it2++);
}
// cout << "resutlt: " << ret.str() << "\n";
return ret.str();
}

273
srcs/load/Socket.cpp

@ -4,167 +4,174 @@ Socket::Socket(listen_t listen) : _listen(listen) {}
Socket::Socket(int fd, Socket *parent) : _fd(fd), _parent(parent) {}
Socket::~Socket(void) {
close(_fd);
cout << "Socket destroyed!\n";
close(_fd);
cout << "Socket destroyed!\n";
}
int Socket::launch(void) {
int opt = 1;
string ip = _listen.ip;
int port = _listen.port;
int opt = 1;
string ip = _listen.ip;
int port = _listen.port;
_fd = socket(AF_INET, SOCK_STREAM, 0);
if (_fd == 0) {
cout << "Socket creation: " << strerror(errno) << "\n";
return (EXIT_FAILURE);
}
int opt_ret =
setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt));
if (opt_ret < 0) {
cout << "Sockopt: " << strerror(errno) << "\n";
return (EXIT_FAILURE);
}
_fd = socket(AF_INET, SOCK_STREAM, 0);
if (_fd == 0) {
cout << "Socket creation: " << strerror(errno) << "\n";
return (EXIT_FAILURE);
}
int opt_ret =
setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt));
if (opt_ret < 0) {
cout << "Sockopt: " << strerror(errno) << "\n";
return (EXIT_FAILURE);
}
_address.sin_family = AF_INET;
_address.sin_addr.s_addr = inet_addr(ip.c_str());
_address.sin_port = htons(port);
_address.sin_family = AF_INET;
_address.sin_addr.s_addr = inet_addr(ip.c_str());
_address.sin_port = htons(port);
if (bind(_fd, (struct sockaddr *)&_address, sizeof(_address)) < 0) {
cout << "Bind: " << strerror(errno) << "\n";
return (EXIT_FAILURE);
}
cout << "Listener " << ip << " on port " << port << "\n";
if (bind(_fd, (struct sockaddr *)&_address, sizeof(_address)) < 0) {
cout << "Bind: " << strerror(errno) << "\n";
return (EXIT_FAILURE);
}
cout << "Listener " << ip << " on port " << port << "\n";
if (listen(_fd, 3) < 0) {
cout << "Listen: " << strerror(errno) << "\n";
return (EXIT_FAILURE);
}
cout << "Master: " << _fd << "\n";
if (_fd < _min_fd)
_min_fd = _fd;
_amount++;
return (EXIT_SUCCESS);
if (listen(_fd, 3) < 0) {
cout << "Listen: " << strerror(errno) << "\n";
return (EXIT_FAILURE);
}
cout << "Master: " << _fd << "\n";
if (_fd < _min_fd)
_min_fd = _fd;
_amount++;
return (EXIT_SUCCESS);
}
void Socket::set_fds(void) {
int child_fd;
FD_SET(_fd, &_readfds);
for (std::vector<Socket *>::iterator it = _childs.begin(); it < _childs.end();
it++) {
child_fd = (*it)->_fd;
FD_SET(child_fd, &_readfds);
if (child_fd > _max_fd)
_max_fd = child_fd;
}
int child_fd;
FD_SET(_fd, &_readfds);
for (std::vector<Socket *>::iterator it = _childs.begin();
it < _childs.end(); it++) {
child_fd = (*it)->_fd;
FD_SET(child_fd, &_readfds);
if (child_fd > _max_fd)
_max_fd = child_fd;
}
}
void Socket::refresh(Env *env) {
int valread;
int addrlen = sizeof(_address);
char buffer[10000];
if (FD_ISSET(_fd, &_readfds)) {
int new_socket =
accept(_fd, (struct sockaddr *)&_address, (socklen_t *)&addrlen);
if (new_socket < 0) {
cout << "Accept: " << strerror(errno) << "\n";
exit(EXIT_FAILURE);
}
int valread;
int addrlen = sizeof(_address);
char buffer[10000];
if (FD_ISSET(_fd, &_readfds)) {
int new_socket =
accept(_fd, (struct sockaddr *)&_address, (socklen_t *)&addrlen);
if (new_socket < 0) {
cout << "Accept: " << strerror(errno) << "\n";
exit(EXIT_FAILURE);
}
#ifdef __APPLE__
// fcntl(new_socket, F_GETNOSIGPIPE);
fcntl(new_socket, F_SETFL, O_NONBLOCK);
// fcntl(new_socket, F_GETNOSIGPIPE);
fcntl(new_socket, F_SETFL, O_NONBLOCK);
#endif
cout << "New connection, socket fd is " << new_socket
<< ", ip is : " << inet_ntoa(_address.sin_addr)
<< ", port : " << ntohs(_address.sin_port) << "\n";
_childs.push_back(new Socket(new_socket, this));
}
int child_fd;
for (std::vector<Socket *>::iterator it = _childs.begin(); it < _childs.end();
it++) {
child_fd = (*it)->_fd;
if (FD_ISSET(child_fd, &_readfds)) {
valread = read(child_fd, buffer, 10000);
if (valread == 0) {
getpeername(child_fd, (struct sockaddr *)&_address,
(socklen_t *)&addrlen);
cout << "Host disconnected, ip " << inet_ntoa(_address.sin_addr)
<< ", port " << ntohs(_address.sin_port) << "\n";
delete (*it);
_childs.erase(it);
} else {
buffer[valread] = '\0';
(*it)->answer(env, buffer);
}
}
}
cout << "New connection, socket fd is " << new_socket
<< ", ip is : " << inet_ntoa(_address.sin_addr)
<< ", port : " << ntohs(_address.sin_port) << "\n";
_childs.push_back(new Socket(new_socket, this));
}
int child_fd;
for (std::vector<Socket *>::iterator it = _childs.begin();
it < _childs.end(); it++) {
child_fd = (*it)->_fd;
if (FD_ISSET(child_fd, &_readfds)) {
valread = read(child_fd, buffer, 10000);
if (valread == 0) {
getpeername(child_fd, (struct sockaddr *)&_address,
(socklen_t *)&addrlen);
cout << "Host disconnected, ip " << inet_ntoa(_address.sin_addr)
<< ", port " << ntohs(_address.sin_port) << "\n";
delete (*it);
_childs.erase(it);
} else {
buffer[valread] = '\0';
(*it)->answer(env, buffer);
}
}
}
}
bool Socket::waitHeader() {
if (_tmp.length() < 1)
return false;
std::vector<string> lines = split(_tmp, '\n');
bool is_valid = false;
for (std::vector<string>::iterator it = lines.begin(); it < lines.end();
it++) {
if (*it == "\r")
is_valid = true;
}
if (!is_valid)
return false;
_header = _tmp;
_tmp = "";
return true;
if (_tmp.length() < 1)
return false;
std::vector<string> lines = split(_tmp, '\n');
bool is_valid = false;
for (std::vector<string>::iterator it = lines.begin(); it < lines.end();
it++) {
if (*it == "\r")
is_valid = true;
}
if (!is_valid)
return false;
_header = _tmp;
_tmp = "";
return true;
}
int Socket::answer(Env *env, string request) {
_tmp += request;
cout << "|===|request|===>" << _tmp << "|===||\n";
if (_header == "") {
waitHeader();
}
std::vector<string> lines = split(_header, '\n');
std::vector<string> head = split(lines.at(0), ' ');
string uri = head.at(1);
cout << uri << "\n";
string ret;
std::stringstream answer;
answer << "HTTP/1.1";
_tmp += request;
cout << "|===|request|===>" << _tmp << "|===||\n";
if (_header == "") {
waitHeader();
}
std::vector<string> lines = split(_header, '\n');
std::vector<string> head = split(lines.at(0), ' ');
string uri = head.at(1);
cout << uri << "\n";
string ret;
std::stringstream answer;
answer << "HTTP/1.1";
Server *server = env->choose_server(_parent, split(lines.at(1), ' ').at(1));
Route *route = server->get_route(uri);
std::vector<string> headers;
Server *server = env->choose_server(_parent, split(lines.at(1), ' ').at(1));
Route *route = server->get_route(uri);
std::vector<string> headers;
if ((head.at(0) != "GET" && head.at(0) != "POST" && head.at(0) != "DELETE") ||
head.size() < 2)
send_answer("HTTP/1.1 405 Method Not Allowed\r\nContent-length: 0\r\n\r\n");
else if ((headers = route->getHeadersLst()).size() > 0) {
if (std::find(headers.begin(), headers.end(), head.at(0)) == headers.end())
send_answer("HTTP/1.1 405 Method Not Allowed\r\nContent-length: 0\r\n\r\n");
} else if ((headers = server->getHeadersLst()).size() > 0) {
if (std::find(headers.begin(), headers.end(), head.at(0)) == headers.end())
send_answer("HTTP/1.1 405 Method Not Allowed\r\nContent-length: 0\r\n\r\n");
}
if ((head.at(0) != "GET" && head.at(0) != "POST" &&
head.at(0) != "DELETE") ||
head.size() < 2)
send_answer(
"HTTP/1.1 405 Method Not Allowed\r\nContent-length: 0\r\n\r\n");
else if ((headers = route->getHeadersLst()).size() > 0) {
if (std::find(headers.begin(), headers.end(), head.at(0)) ==
headers.end())
send_answer(
"HTTP/1.1 405 Method Not Allowed\r\nContent-length: 0\r\n\r\n");
} else if ((headers = server->getHeadersLst()).size() > 0) {
if (std::find(headers.begin(), headers.end(), head.at(0)) ==
headers.end())
send_answer(
"HTTP/1.1 405 Method Not Allowed\r\nContent-length: 0\r\n\r\n");
}
string path = route->correctUri(uri);
cout << "Path: " << path << "\n";
ret = route->getIndex(uri, path);
if (ret == "") {
cout << "No index: lf file\n";
ret = read_file(path);
}
answer << (ret == "" ? " 404 Not Found\r\nContent-length: 0\r\n\r\n" : " 200 OK\r\n")
<< ret;
cout << "|===|Answer|===>" << answer.str() << "|===||\n";
send_answer(answer.str());
_content = "";
_header = "";
return EXIT_SUCCESS;
string path = route->correctUri(uri);
cout << "Path: " << path << "\n";
ret = route->getIndex(uri, path);
if (ret == "") {
cout << "No index: lf file\n";
ret = read_file(path);
}
answer << (ret == "" ? " 404 Not Found\r\nContent-length: 0\r\n\r\n"
: " 200 OK\r\n")
<< ret;
cout << "|===|Answer|===>" << answer.str() << "|===||\n";
send_answer(answer.str());
_content = "";
_header = "";
return EXIT_SUCCESS;
}
void Socket::send_answer(string msg) {
#ifdef __linux__
send(_fd, msg.c_str(), msg.length(), MSG_NOSIGNAL);
send(_fd, msg.c_str(), msg.length(), MSG_NOSIGNAL);
#elif __APPLE__
send(_fd, msg.c_str(), msg.length(), 0);
send(_fd, msg.c_str(), msg.length(), 0);
#endif
}

190
srcs/tools.cpp

@ -39,167 +39,175 @@ listen_t get_listen_t(string listen) {
return ret;
}
string getMime(string path)
{
string getMime(string path) {
string extension;
size_t pos = path.rfind('.');
extension = (pos == string::npos) ? "txt" : path.substr(pos + 1);
extension = (pos == string::npos) ? "txt" : path.substr(pos + 1);
if ((extension == "html") || (extension == "htm") || (extension == "shtml"))
return("text/html");
return ("text/html");
else if ((extension == "css"))
return("text/css");
return ("text/css");
else if ((extension == "xml"))
return("text/xml");
return ("text/xml");
else if ((extension == "gif"))
return("image/gif");
return ("image/gif");
else if ((extension == "jpeg") || (extension == "jpg"))
return("image/jpeg");
return ("image/jpeg");
else if ((extension == "js"))
return("application/javascript");
return ("application/javascript");
else if ((extension == "atom"))
return("application/atom+xml");
return ("application/atom+xml");
else if ((extension == "rss"))
return("application/rss+xml");
return ("application/rss+xml");
else if ((extension == "mml"))
return("text/mathml");
return ("text/mathml");
else if ((extension == "txt"))
return("text/plain");
return ("text/plain");
else if ((extension == "jad"))
return("text/vnd.sun.j2me.app-descriptor");
return ("text/vnd.sun.j2me.app-descriptor");
else if ((extension == "wml"))
return("text/vnd.wap.wml");
return ("text/vnd.wap.wml");
else if ((extension == "htc"))
return("text/x-component");
return ("text/x-component");
else if ((extension == "avif"))
return("image/avif");
return ("image/avif");
else if ((extension == "png"))
return("image/png");
return ("image/png");
else if ((extension == "svg") || (extension == "svgz"))
return("image/svg+xml");
return ("image/svg+xml");
else if ((extension == "tif") || (extension == "tiff"))
return("image/tiff");
return ("image/tiff");
else if ((extension == "wbmp"))
return("image/vnd.wap.wbmp");
return ("image/vnd.wap.wbmp");
else if ((extension == "webp"))
return("image/webp");
return ("image/webp");
else if ((extension == "ico"))
return("image/x-icon");
return ("image/x-icon");
else if ((extension == "jng"))
return("image/x-jng");
return ("image/x-jng");
else if ((extension == "bmp"))
return("image/x-ms-bmp");
return ("image/x-ms-bmp");
else if ((extension == "woff"))
return("font/woff");
return ("font/woff");
else if ((extension == "woff2"))
return("font/woff2");
else if ((extension == "jar") || (extension == "war") || (extension == "ear"))
return("application/java-archive");
return ("font/woff2");
else if ((extension == "jar") || (extension == "war") ||
(extension == "ear"))
return ("application/java-archive");
else if ((extension == "json"))
return("application/json");
return ("application/json");
else if ((extension == "hqx"))
return("application/mac-binhex40");
return ("application/mac-binhex40");
else if ((extension == "doc"))
return("application/msword");
return ("application/msword");
else if ((extension == "pdf"))
return("application/pdf");
return ("application/pdf");
else if ((extension == "ps") || (extension == "eps") || (extension == "ai"))
return("application/postscript");
return ("application/postscript");
else if ((extension == "rtf"))
return("application/rtf");
return ("application/rtf");
else if ((extension == "m3u8"))
return("application/vnd.apple.mpegurl");
else if ((extension == "xls") || (extension == "xlt") || (extension == "xlm") || (extension == "xld") || (extension == "xla") || (extension == "xlc") || (extension == "xlw") || (extension == "xll"))
return("application/vnd.ms-excel");
return ("application/vnd.apple.mpegurl");
else if ((extension == "xls") || (extension == "xlt") ||
(extension == "xlm") || (extension == "xld") ||
(extension == "xla") || (extension == "xlc") ||
(extension == "xlw") || (extension == "xll"))
return ("application/vnd.ms-excel");
else if ((extension == "ppt") || (extension == "pps"))
return("application/vnd.ms-powerpoint");
return ("application/vnd.ms-powerpoint");
else if ((extension == "wmlc"))
return("application/vnd.wap.wmlc");
return ("application/vnd.wap.wmlc");
else if ((extension == "kml"))
return("application/vnd.google-earth.kml+xml");
return ("application/vnd.google-earth.kml+xml");
else if ((extension == "kmz"))
return("application/vnd.google-earth.kmz");
return ("application/vnd.google-earth.kmz");
else if ((extension == "7z"))
return("application/x-7z-compressed");
return ("application/x-7z-compressed");
else if ((extension == "cco"))
return("application/x-cocoa");
return ("application/x-cocoa");
else if ((extension == "jardiff"))
return("application/x-java-archive-diff");
return ("application/x-java-archive-diff");
else if ((extension == "jnlp"))
return("application/x-java-jnlp-file");
return ("application/x-java-jnlp-file");
else if ((extension == "run"))
return("application/x-makeself");
return ("application/x-makeself");
else if ((extension == "pl") || (extension == "pm"))
return("application/x-perl");
else if ((extension == "pdb") || (extension == "pqr") || (extension == "prc") || (extension == "pde"))
return("application/x-pilot");
return ("application/x-perl");
else if ((extension == "pdb") || (extension == "pqr") ||
(extension == "prc") || (extension == "pde"))
return ("application/x-pilot");
else if ((extension == "rar"))
return("application/x-rar-compressed");
return ("application/x-rar-compressed");
else if ((extension == "rpm"))
return("application/x-redhat-package-manager");
return ("application/x-redhat-package-manager");
else if ((extension == "sea"))
return("application/x-sea");
return ("application/x-sea");
else if ((extension == "swf"))
return("application/x-shockwave-flash");
return ("application/x-shockwave-flash");
else if ((extension == "sit"))
return("application/x-stuffit");
return ("application/x-stuffit");
else if ((extension == "tcl") || (extension == "tk"))
return("application/x-tcl");
else if ((extension == "der") || (extension == "pem") || (extension == "crt"))
return("application/x-x509-ca-cert");
return ("application/x-tcl");
else if ((extension == "der") || (extension == "pem") ||
(extension == "crt"))
return ("application/x-x509-ca-cert");
else if ((extension == "xpi"))
return("application/x-xpinstall");
return ("application/x-xpinstall");
else if ((extension == "xhtml") || (extension == "xht"))
return("application/xhtml+xml");
return ("application/xhtml+xml");
else if ((extension == "zip"))
return("application/zip");
else if ((extension == "bin") || (extension == "exe") || (extension == "dll"))
return("application/octet-stream");
return ("application/zip");
else if ((extension == "bin") || (extension == "exe") ||
(extension == "dll"))
return ("application/octet-stream");
else if ((extension == "deb"))
return("application/octet-stream");
return ("application/octet-stream");
else if ((extension == "dmg"))
return("application/octet-stream");
return ("application/octet-stream");
else if ((extension == "eot"))
return("application/octet-stream");
return ("application/octet-stream");
else if ((extension == "img") || (extension == "iso"))
return("application/octet-stream");
else if ((extension == "msi") || (extension == "msp") || (extension == "msm"))
return("application/octet-stream");
else if ((extension == "mid") || (extension == "midi") || (extension == "kar"))
return("audio/midi");
return ("application/octet-stream");
else if ((extension == "msi") || (extension == "msp") ||
(extension == "msm"))
return ("application/octet-stream");
else if ((extension == "mid") || (extension == "midi") ||
(extension == "kar"))
return ("audio/midi");
else if ((extension == "mp3"))
return("audio/mpeg");
return ("audio/mpeg");
else if ((extension == "ogg"))
return("audio/ogg");
return ("audio/ogg");
else if ((extension == "m4a"))
return("audio/x-m4a");
return ("audio/x-m4a");
else if ((extension == "ra"))
return("audio/x-realaudio");
return ("audio/x-realaudio");
else if ((extension == "3gpp") || (extension == "3gp"))
return("video/3gpp");
return ("video/3gpp");
else if ((extension == "ts"))
return("video/mp2t");
return ("video/mp2t");
else if ((extension == "mp4"))
return("video/mp4");
return ("video/mp4");
else if ((extension == "mpeg") || (extension == "mpg"))
return("video/mpeg");
return ("video/mpeg");
else if ((extension == "mov"))
return("video/quicktime");
return ("video/quicktime");
else if ((extension == "webm"))
return("video/webm");
return ("video/webm");
else if ((extension == "flv"))
return("video/x-flv");
return ("video/x-flv");
else if ((extension == "m4v"))
return("video/x-m4v");
return ("video/x-m4v");
else if ((extension == "mng"))
return("video/x-mng");
return ("video/x-mng");
else if ((extension == "asx") || (extension == "asf"))
return("video/x-ms-asf");
return ("video/x-ms-asf");
else if ((extension == "wmv"))
return("video/x-ms-wmv");
return ("video/x-ms-wmv");
else if ((extension == "avi"))
return("video/x-msvideo");
return ("video/x-msvideo");
else
return("text/plain");
return ("text/plain");
}
string read_file(string path) {
@ -208,12 +216,12 @@ string read_file(string path) {
std::stringstream ret;
struct stat info;
if (stat(path.c_str(), &info) != 0 || S_ISDIR(info.st_mode)) {
std::cerr << "stat() error on " << path << ": "
<< strerror(errno) << "\n";
std::cerr << "stat() error on " << path << ": " << strerror(errno)
<< "\n";
return "";
}
std::ifstream file(path.c_str());
//if (!file.good())
// if (!file.good())
// return "";
while (file) {
std::getline(file, str);

Loading…
Cancel
Save