X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/d3ea2ff01c51df0df95cd23157267048e2c2fdcd..2f5c973fdf3f7fb25b13996b66d566c58066f6a0:/Server/src/controlserver.cpp?ds=inline diff --git a/Server/src/controlserver.cpp b/Server/src/controlserver.cpp index 144d236..c5e163f 100644 --- a/Server/src/controlserver.cpp +++ b/Server/src/controlserver.cpp @@ -26,7 +26,8 @@ // #include "plaqui/server/controlserver.h" -#include "plaqui/server/httprequest.h" +#include "plaqui/server/command.h" +#include "plaqui/server/string.h" #include #include #ifdef DEBUG @@ -46,7 +47,7 @@ ControlServer::~ControlServer(void) { } ControlServer::ControlServer(const sockbuf::sockdesc& sd): - ServerConnection(sd) { + Connection(sd) { #ifdef DEBUG cerr << __FILE__ << ": sd = " << sd.sock << endl; #endif // DEBUG @@ -58,8 +59,22 @@ void ControlServer::real_run(void) { #endif // DEBUG //char buf[BUFSIZ]; while (!stop) { - HTTPRequest request; - socket >> request; + Command command; + try { + socket >> command; + } catch (const char* e) { + cerr << " (" << __LINE__ << ") Error: " << e << endl; + stop = true; + continue; + } catch (string e) { + cerr << " (" << __LINE__ << ") Error: " << e << endl; + stop = true; + continue; + } catch (...) { + cerr << " (" << __LINE__ << ") Error desconocido!" << endl; + stop = true; + continue; + } // TODO agregar las verificaciones de abajo a HTTPRequest y padres. /* // Primera línea no vacía (que debe ser el request). @@ -95,15 +110,13 @@ void ControlServer::real_run(void) { } } */ - // TODO: Manda el comando. - // Command command = parse_command(request.uri); - //signal_command_received().emit(command); + // Manda el comando. + command_received.emit(command); #ifdef DEBUG - cerr << "Request: " << request << endl; - //for (HTTPRequest::const_iterator i = request.begin(); - // i != request.end(); i++) { - // cerr << " " << i->first << ": " << i->second << endl; - //} + cerr << "Comando: target = " << command.get_target() + << " | command = " << command.get_command() + << " | args = [" << String::join(command.get_args(), ", ") << "]" + << endl; #endif // DEBUG // FIXME - hacer respuesta XML. // La respuesta hay que mandarla asincrónicamente porque no puedo @@ -120,18 +133,31 @@ Accept-Ranges: bytes socket << "Content-Type: text/html; charset=iso-8859-1" << endl; response_xml << "" << endl; response_xml << " " << endl; - response_xml << " PlaQui v0.1" << endl; + response_xml << " PlaQui v0.4" << endl; response_xml << " " << endl; response_xml << " " << endl; response_xml << "

PlaQui

" << endl; - response_xml << "

versión 0.2

" << endl; - response_xml << "

Pedido HTTP

" << endl; + response_xml << "

versión 0.4

" << endl; + response_xml << "

Comando

" << endl; response_xml << " " << endl; response_xml << "

Desarrollado por

" << endl; response_xml << "