]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/command.cpp
Se cuentan la cantidad de lineas tambien
[z.facultad/75.42/plaqui.git] / Server / src / command.cpp
index 084cf796b6acb3bfe1bb21a364aff5b8f9e8d5d2..5aa47001ab0b2ec6c5b6009d346d6afc4d36dab2 100644 (file)
@@ -28,6 +28,7 @@
 #include "plaqui/server/command.h"
 #include "plaqui/server/string.h"
 #include <algorithm>
 #include "plaqui/server/command.h"
 #include "plaqui/server/string.h"
 #include <algorithm>
+//#include <exception>
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
@@ -40,22 +41,32 @@ namespace Server {
 
 Command::~Command(void) {
 #ifdef DEBUG
 
 Command::~Command(void) {
 #ifdef DEBUG
-       cerr << __FILE__ << ": destructor." << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": destructor." << endl;
 #endif // DEBUG
 }
 
 #endif // DEBUG
 }
 
-Command::Command(const string& target, const string& command):
-               target(target), command(command) {
+Command::Command(const string& _target, const string& _command) {
 #ifdef DEBUG
 #ifdef DEBUG
-       cerr << __FILE__ << ": target = " << target << " | "
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": target = " << target << " | "
                        << "command = " << command << endl;
 #endif // DEBUG
                        << "command = " << command << endl;
 #endif // DEBUG
+       set_target(_target);
+       set_command(_command);
 }
 
 void Command::build(void) {
 }
 
 void Command::build(void) {
-       uri = string("/") + target + '/' + command + String::join(args, "/");
+       uri = string("/") + target;
+       if (command.length()) {
+               uri += '/' + command;
+               if (args.size()) {
+                       uri += '/' + String::join(args, "/");
+               }
+       }
 #ifdef DEBUG
 #ifdef DEBUG
-       cerr << __FILE__ << ": build() = " << uri << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": build() = " << uri << endl;
 #endif // DEBUG
 }
 
 #endif // DEBUG
 }
 
@@ -64,7 +75,7 @@ void Command::set_target(const std::string& _target) {
        build();
 }
 
        build();
 }
 
-const std::string& Command::get_target(void) {
+const std::string& Command::get_target(void) const {
        return target;
 }
 
        return target;
 }
 
@@ -73,7 +84,7 @@ void Command::set_command(const std::string& _command) {
        build();
 }
 
        build();
 }
 
-const std::string& Command::get_command(void) {
+const std::string& Command::get_command(void) const {
        return command;
 }
 
        return command;
 }
 
@@ -82,7 +93,7 @@ void Command::set_args(const Command::Arguments& _args) {
        build();
 }
 
        build();
 }
 
-const Command::Arguments& Command::get_args(void) {
+const Command::Arguments& Command::get_args(void) const {
        return args;
 }
 
        return args;
 }
 
@@ -91,9 +102,21 @@ void Command::add_arg(const std::string& arg) {
        build();
 }
 
        build();
 }
 
-istream& operator>>(istream& is, Command& command) {
+void Command::add_arg(const unsigned& arg) {
 #ifdef DEBUG
 #ifdef DEBUG
-       cerr << __FILE__ << ": operator>>()" << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": add_arg(arg = " << arg << ") = "
+               << String().from(arg) << endl;
+#endif // DEBUG
+       args.push_back(String().from(arg));
+       build();
+}
+
+istream& operator>>(istream& is, Command& command)
+               throw(HTTPError, sockerr, ios::failure) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": operator>>()" << endl;
 #endif // DEBUG
        // Obtengo datos del Request HTTP.
        is >> static_cast<HTTPRequest&>(command);
 #endif // DEBUG
        // Obtengo datos del Request HTTP.
        is >> static_cast<HTTPRequest&>(command);
@@ -108,8 +131,8 @@ istream& operator>>(istream& is, Command& command) {
        } else {
                command.target = "";
        }
        } else {
                command.target = "";
        }
-       if (command.args.size() > 1) {
-               command.command = command.args[1];
+       if (command.args.size() > 0) {
+               command.command = command.args[0];
                command.args.erase(command.args.begin());
        } else {
                command.command = "";
                command.args.erase(command.args.begin());
        } else {
                command.command = "";
@@ -117,9 +140,10 @@ istream& operator>>(istream& is, Command& command) {
        return is;
 }
 
        return is;
 }
 
-ostream& operator<<(ostream& os, const Command& command) {
+ostream& operator<<(ostream& os, const Command& command) throw (sockerr) {
 #ifdef DEBUG
 #ifdef DEBUG
-       cerr << __FILE__ << ": operator<<()" << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": operator<<()" << endl;
 #endif // DEBUG
        // Manda el request HTTP con la URI que representa el comando.
        os << static_cast<const HTTPRequest&>(command);
 #endif // DEBUG
        // Manda el request HTTP con la URI que representa el comando.
        os << static_cast<const HTTPRequest&>(command);