#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()); } } if ((tmp = object["cgi"])) { JSONObject cgis = tmp->obj(); for (JSONObject::iterator it = cgis.begin(); it != cgis.end(); it++) { _cgi[(*it).first] = (*it).second->str(); } } } Route::~Route(void) {} string Route::getLocation(void) { return _location; } 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; if ((dir = opendir(path.c_str())) == NULL) return ""; else { content << "