25 if ((tmp =
object[
"root"]))
27 if ((tmp =
object[
"return"]))
29 if ((tmp =
object[
"autoindex"]))
31 if ((tmp =
object[
"indexs"])) {
33 for (JSONList::iterator it = indexs.begin(); it < indexs.end(); it++)
34 _indexs.push_back((*it)->str());
36 if ((tmp =
object[
"allowed_methods"])) {
38 for (JSONList::iterator it = headers.begin(); it < headers.end(); it++)
41 if ((tmp =
object[
"cgi"])) {
43 for (JSONObject::iterator it = cgis.begin(); it != cgis.end(); it++)
44 _cgi[(*it).first] = (*it).second->str();
46 if ((tmp =
object[
"client_max_body_size"]))
67 std::stringstream body, ret;
71 vec_string::iterator it;
73 if ((dir = opendir(path.c_str()))) {
75 cout <<
"get index(): path=" << path <<
"\n";
76 body <<
"<h3 style=\"text-align: center;\">" << path <<
" files :</h3>\n<ul>\n";
77 while ((entry = readdir(dir)) != NULL) {
78 if (entry->d_name[0] ==
'.')
81 if (entry->d_name == *it)
84 body <<
"<li><a href=\"" << uri +
"/" + entry->d_name <<
"\">" << entry->d_name <<
"</a></li>\n";
85 if (stat(path.c_str(), &info) != 0)
86 std::cerr <<
"stat() error on " << path <<
": " << strerror(errno) <<
"\n";
94 cout <<
"Getting autoindex\n";
95 ret <<
"Content-type: text/html \r\n";
96 ret <<
"Content-length: " << body.str().length() <<
"\r\n";
97 ret <<
"\r\n" << body.str();
116 std::stringstream ret;
117 vec_string::iterator loc_word, uri_word;
121 uri_word = uri_words.begin();
122 for (loc_word = loc_words.begin(); loc_word < loc_words.end(); loc_word++) {
123 while (uri_word < uri_words.end() && *uri_word ==
"")
125 while (loc_word < loc_words.end() && *loc_word ==
"")
127 if (loc_word != loc_words.end())
130 ret <<
"./" <<
_root;
131 while (uri_word < uri_words.end())
132 ret <<
"/" << *(uri_word++);
std::map< string, string > _cgi
vec_string _allowed_methods
Route(Server *server, string location, JSONNode *datas)
Constructor.
int _client_max_body_size
string correctUri(string uri)
Find the local path corresponding to the uri asked by te client.
string getIndex(string uri, string path)
Search for an index while generating autoindex.
std::vector< JSONNode * > JSONList
std::vector< string > vec_string
std::map< string, JSONNode * > JSONObject