diff --git a/sources/main.cpp b/sources/main.cpp index 0e6b513..dbc1040 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -17,7 +17,7 @@ int main(int argc, char **argv) { vector configs = parser.parse(); // configs[0].print(); Server &webserv = Server::get_instance(configs[0], 10); - webserv.start(SELECT); + webserv.start(KQUEUE); } catch (std::exception &error) { diff --git a/sources/parser/ConfigParser.cpp b/sources/parser/ConfigParser.cpp index 6e8c34a..c7b1f24 100644 --- a/sources/parser/ConfigParser.cpp +++ b/sources/parser/ConfigParser.cpp @@ -141,17 +141,24 @@ Location ConfigParser::_parse_location_context(void) THROW_EXCEPTION_WITH_INFO(ERR_INVALID_LOCATION); ++_itr; // move to location content + set parsedLocationDirectives; while (*_itr != "}") { - if (*_itr == "root") + if (*_itr == "root") { location.root = _parse_root(); - else if (*_itr == "autoindex") + check_duplicate_directive(parsedLocationDirectives, "root"); + } + else if (*_itr == "autoindex") { location.autoindex = _parse_autoindex(); + check_duplicate_directive(parsedLocationDirectives, "autoindex"); + } else if (*_itr == "index") location.indexFiles = _parse_index(location.root); - else { - cout << *_itr << endl; - THROW_EXCEPTION_WITH_INFO(ERR_UNEXPECTED_TOKENS_IN_LOCATION); + else if (*_itr == "client_max_body_size") { + location.maxBodySize = _parse_client_max_body_size(); + check_duplicate_directive(parsedLocationDirectives, "client_max_body_size"); } + else + THROW_EXCEPTION_WITH_INFO(ERR_UNEXPECTED_TOKENS_IN_LOCATION); ++_itr; } ++_itr; // move to next directive @@ -308,16 +315,33 @@ vector ConfigParser::_parse_HTTP_context(void) THROW_EXCEPTION_WITH_INFO(ERR_OPENINING_BRACE); ++_itr; // move to first directive + set parsedHTTPDirectives; vector serverConfigs; while (*_itr != "}") { if (*_itr == "server") serverConfigs.push_back(_parse_server_context()); + else if (*_itr == "root") { + // _serverConfig.serverRoot = _parse_root(); + check_duplicate_directive(parsedHTTPDirectives, "root"); + } + else if (*_itr == "index") + ; // index here will be default index for all servers + else if (*_itr == "error_page") + ; // error_page here will be default error_page for all servers + else if (*_itr == "client_max_body_size") { + // _serverConfig.maxBodySize = _parse_client_max_body_size(); + check_duplicate_directive(parsedHTTPDirectives, "client_max_body_size"); + } + else if (*_itr == "autoindex") { + // _serverConfig.autoindex = _parse_autoindex(); + check_duplicate_directive(parsedHTTPDirectives, "autoindex"); + } else THROW_EXCEPTION_WITH_INFO(ERR_UNEXPECTED_TOKENS_IN); ++_itr; } - if ((_itr + 1) != _tokens.end()) + if ((_itr + 1) != _tokens.end()) // after http context no more tokens should be present THROW_EXCEPTION_WITH_INFO(ERR_UNEXPECTED_TOKENS_OUT); return serverConfigs; diff --git a/sources/server/Server.cpp b/sources/server/Server.cpp index 945277c..faec0f8 100644 --- a/sources/server/Server.cpp +++ b/sources/server/Server.cpp @@ -190,18 +190,21 @@ void Server::kqueue_strat() THROW_EXCEPTION_WITH_INFO(strerror(errno)); } } - else + else if (eventList[i].flags & EV_EOF) { - DEBUG_MSG("reading from connection", M); - if (handle_connection(eventList[i].ident) == CLOSE_CONNECTION) - { - // remove connection from kqueue - EV_SET(&changeList, eventList[i].ident, EVFILT_READ, EV_DELETE, 0, 0, 0); - if (kevent(kq, &changeList, 1, NULL, 0, NULL) == -1) { - close(kq); - THROW_EXCEPTION_WITH_INFO(strerror(errno)); - } + // remove connection from kqueue + EV_SET(&changeList, eventList[i].ident, EVFILT_READ, EV_DELETE, 0, 0, 0); + if (kevent(kq, &changeList, 1, NULL, 0, NULL) == -1) { + close(kq); + THROW_EXCEPTION_WITH_INFO(strerror(errno)); } + close(eventList[i].ident); + // this should be done in handle_connection + } + else if (eventList[i].flags & EVFILT_READ) + { + DEBUG_MSG("reading from connection", M); + //TODO HANDLE READ } } } diff --git a/sources/server/ServerConfig.hpp b/sources/server/ServerConfig.hpp index fd016b2..41bd575 100644 --- a/sources/server/ServerConfig.hpp +++ b/sources/server/ServerConfig.hpp @@ -10,7 +10,8 @@ struct Location { string root; vector indexFiles; bool autoindex; - Location() : autoindex(false) {} + size_t maxBodySize; + Location() : autoindex(false), maxBodySize(1000000) {} }; struct ServerConfig { @@ -22,6 +23,7 @@ struct ServerConfig { vector locations; map errorPages; bool autoindex; + in_addr_t serverAddr; ServerConfig() : listenerPort(8080), maxBodySize(1000000), autoindex(false) {}