]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blobdiff - Server/src/command.cpp
Se agrega un try para tratar de solucionar situaciones en las que el server
[z.facultad/75.42/plaqui.git] / Server / src / command.cpp
index 08a73c9b36ae4a9bd5cb18bec05325d667acd2ff..5aa47001ab0b2ec6c5b6009d346d6afc4d36dab2 100644 (file)
@@ -28,6 +28,7 @@
 #include "plaqui/server/command.h"
 #include "plaqui/server/string.h"
 #include <algorithm>
+//#include <exception>
 #ifdef DEBUG
 #      include <iostream>
 #endif // DEBUG
@@ -40,13 +41,15 @@ namespace Server {
 
 Command::~Command(void) {
 #ifdef DEBUG
-       cerr << __FILE__ << ": destructor." << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": destructor." << endl;
 #endif // DEBUG
 }
 
 Command::Command(const string& _target, const string& _command) {
 #ifdef DEBUG
-       cerr << __FILE__ << ": target = " << target << " | "
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": target = " << target << " | "
                        << "command = " << command << endl;
 #endif // DEBUG
        set_target(_target);
@@ -54,9 +57,16 @@ Command::Command(const string& _target, const string& _command) {
 }
 
 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
-       cerr << __FILE__ << ": build() = " << uri << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": build() = " << uri << endl;
 #endif // DEBUG
 }
 
@@ -92,9 +102,21 @@ void Command::add_arg(const std::string& arg) {
        build();
 }
 
-istream& operator>>(istream& is, Command& command) {
+void Command::add_arg(const unsigned& arg) {
+#ifdef DEBUG
+       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__ << ": operator>>()" << endl;
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": operator>>()" << endl;
 #endif // DEBUG
        // Obtengo datos del Request HTTP.
        is >> static_cast<HTTPRequest&>(command);
@@ -118,9 +140,10 @@ istream& operator>>(istream& is, Command& command) {
        return is;
 }
 
-ostream& operator<<(ostream& os, const Command& command) {
+ostream& operator<<(ostream& os, const Command& command) throw (sockerr) {
 #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);