]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/request.cpp
Se termina de migrar lo que habia hecho al nuevo modelo cliente-servidor, pero
[z.facultad/75.42/plaqui.git] / Server / src / request.cpp
index 92bb7e1d7c7fc9386318e0122f225ea4db77ac65..d17ca72bbed0757d73c5244bef7273a5a6124647 100644 (file)
 #      include <iostream>
 #endif // DEBUG
 
-using namespace PlaQui::Server;
+const std::string
+PlaQui::Server::Request::CHARS_DIGIT = "0123456789";
 
-const std::string Request::CHARS_DIGIT = "0123456789";
+const std::string
+PlaQui::Server::Request::CHARS_LOWALPHA = "abcdefghijklmnopqrstuvwxyz";
 
-const std::string Request::CHARS_LOWALPHA = "abcdefghijklmnopqrstuvwxyz";
+const std::string
+PlaQui::Server::Request::CHARS_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
-const std::string Request::CHARS_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+const std::string
+PlaQui::Server::Request::CHARS_ALPHA = CHARS_LOWALPHA + CHARS_UPALPHA;
 
-const std::string Request::CHARS_ALPHA = CHARS_LOWALPHA + CHARS_UPALPHA;
+const std::string
+PlaQui::Server::Request::CHARS_ALPHANUM = CHARS_DIGIT + CHARS_ALPHA;
 
-const std::string Request::CHARS_ALPHANUM = CHARS_DIGIT + CHARS_ALPHA;
+const std::string
+PlaQui::Server::Request::CHARS_RESERVED = ";/?:@&=+$,";
 
-const std::string Request::CHARS_RESERVED = ";/?:@&=+$,";
+const std::string
+PlaQui::Server::Request::CHARS_MARK = "-_.!~*'()";
 
-const std::string Request::CHARS_MARK = "-_.!~*'()";
+const std::string
+PlaQui::Server::Request::CHARS_UNRESERVED = CHARS_ALPHANUM + CHARS_MARK;
 
-const std::string Request::CHARS_UNRESERVED = CHARS_ALPHANUM + CHARS_MARK;
+const std::string
+PlaQui::Server::Request::CHARS_HEX = CHARS_DIGIT + std::string("abcdefABCDEF");
 
-const std::string Request::CHARS_HEX = CHARS_DIGIT + std::string("abcdefABCDEF");
-
-void Request::set_request(const std::string& req, const std::string& host,
-               unsigned port) {
+void PlaQui::Server::Request::set_request(const std::string& req,
+               const std::string& host, unsigned port) {
 #ifdef DEBUG
        std::cerr << __FILE__ << ": req = " << req << " | host = " << host
                << " | port = " << port << std::endl;
 #endif // DEBUG
-       String request(req);
+       PlaQui::Server::String request(req);
        (*this)["REMOTE_HOST"] = host;
        std::stringstream ss;
        ss << port;
@@ -71,8 +78,9 @@ void Request::set_request(const std::string& req, const std::string& host,
                throw "HTTP/1.1 501 Method Not Implemented";
        }
        // Averiguo método.
-       std::string::size_type pos = request.find_first_of(String::SPACE_CHARS);
-       String method = request.substr(0, pos); 
+       std::string::size_type pos = request.find_first_of(
+                       PlaQui::Server::String::SPACE_CHARS);
+       PlaQui::Server::String method = request.substr(0, pos); 
        if ((method.to_upper() == "GET") || (method.to_upper() == "POST")) {
                (*this)["REQUEST_METHOD"] = method;
        } else {
@@ -87,13 +95,13 @@ void Request::set_request(const std::string& req, const std::string& host,
                throw "HTTP/1.1 400 Bad Request";
        }
        // Si tiene más espacios, tengo la URI y el protocolo (o un error).
-       pos = request.find_first_of(String::SPACE_CHARS);
+       pos = request.find_first_of(PlaQui::Server::String::SPACE_CHARS);
        if (pos != std::string::npos) {
                // Si el resto es un protocolo válido, agrego más variables.
-               String protocol = request.substr(pos + 1);
+               PlaQui::Server::String protocol = request.substr(pos + 1);
                protocol = protocol.trim();
-               if ((String(protocol).to_upper() == "HTTP/1.0")
-                               || (String(protocol).to_upper() == "HTTP/1.1")) {
+               if ((PlaQui::Server::String(protocol).to_upper() == "HTTP/1.0")
+                               || (PlaQui::Server::String(protocol).to_upper() == "HTTP/1.1")) {
                        (*this)["SERVER_PROTOCOL"] = protocol;
                // Si no es un error.
                } else {
@@ -120,7 +128,7 @@ void Request::set_request(const std::string& req, const std::string& host,
        (*this)["SCRIPT_NAME"] = request.substr(0, pos);
 }
 
-void Request::parse_header(const std::string& header) {
+void PlaQui::Server::Request::parse_header(const std::string& header) {
 #ifdef DEBUG
        std::cerr << __FILE__ << ": header = " << header << std::endl;
 #endif // DEBUG