/* * This static method is used to load catalog config info and return the * error status (0 is OK, 1 for error). * * The argument should be a catalog entry of type "directory", where the * URL points to the catalog config file. There may be multiple such * entries in the form of a catalog server tree. */ int CatalogInfo::load(CatalogInfoEntry* e) { // loop through the url list until success HTTP http; int nlines = 0; char * s = http.get(e->url(), nlines); if (!s) return 1; // http error char* ctype = (http.content_type() ? http.content_type() : (char*)""); if (strcmp(ctype, "text/html") == 0) { // most likely an error message return http.html_error(s); } istringstream is(s); e->link(load(is, e->url())); if (! e->link()) return 1; // input error // if it is a local config file, allow URL commands if (strncmp(e->url(), "file:", 5) == 0) HTTP::allowUrlExec(1); return 0; // normal return }
void Client::start (System::Socket* socket) { HTTP* request = new HTTP; while (!request->done()) { std::string string = socket->readLine().toString(); request->request(string); } HTTP* response = new HTTP; if (request->isOk()) { try { response->setData(System::readFile( Config::get("directories->document[path]")+System::normalizePath(request->getUri()) )); response->setStatus(200); response->setVersion(request->getVersion()); response->setHeader("Connection", "close"); response->setHeader("Content-Type", Mime::getType(request->getUri())); response->setHeader("Content-Length", response->getData().length()); response->setHeader("Server", "lulzHTTPd/0.1"); socket->send(response->get()); } catch (Exception e) { std::stringstream resp; resp << "WUT, ARE YOU BLIND? :O" << std::endl; response->setStatus(404); response->setVersion(request->getVersion()); response->setHeader("Connection", "close"); response->setHeader("Content-Type", "text/plain"); response->setHeader("Content-Length", resp.str().length()); response->setHeader("Server", "lulzHTTPd/0.1"); response->setData(resp.str()); socket->send(response->get()); } } else { std::stringstream resp; resp << "F****T IT'S A BAD REQUEST" << std::endl; response->setStatus(request->getStatus()); response->setVersion(request->getVersion() ? request->getVersion() : 1.0); response->setHeader("Connection", "close"); response->setHeader("Content-Type", "text/plain"); response->setHeader("Content-Length", resp.str().length()); response->setHeader("Server", "lulzHTTPd/0.1"); response->setData(resp.str()); socket->send(response->get()); } delete request; delete response; delete socket; }