1 // vim: set noexpandtab tabstop=4 shiftwidth=4:
2 //----------------------------------------------------------------------------
4 //----------------------------------------------------------------------------
5 // This file is part of PlaQui.
7 // PlaQui is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the Free Software
9 // Foundation; either version 2 of the License, or (at your option) any later
12 // PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 // You should have received a copy of the GNU General Public License along
18 // with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
19 // Place, Suite 330, Boston, MA 02111-1307 USA
20 //----------------------------------------------------------------------------
21 // Creado: Sat Oct 18 18:18:36 2003
22 // Autores: Leandro Lucarella <llucare@fi.uba.ar>
23 //----------------------------------------------------------------------------
28 #include "plaqui/server/controlserver.h"
29 #include "plaqui/server/request.h"
36 PlaQui::Server::ControlServer::~ControlServer(void) {
38 std::cerr << __FILE__ << ": destructor." << std::endl;
42 PlaQui::Server::ControlServer::ControlServer(const sockbuf::sockdesc& sd):
45 std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl;
49 void PlaQui::Server::ControlServer::real_run(void) {
50 // FIXME se tiene que ir a la clase para poder frenarlo desde afuera.
52 char buf[BUFFER_SIZE];
55 // Primera línea no vacía (que debe ser el request).
57 while (!stop && socket.getline(buf, BUFFER_SIZE)) {
59 std::cerr << "Reciviendo linea: " << buf << std::endl;
61 int len = strlen(buf);
62 // Si tiene un retorno de carro, lo elimina.
63 if (len && (buf[len-1] == '\r')) {
66 // Si tiene contenido, lo agrego a la información del request.
68 // Si es la primera línea, es el request.
70 request.set_request(buf, socket->peerhost(),
74 // TODO request.parse_header(buf);
76 // Si viene la línea vacía
78 // Si no es la primera, terminan las cabeceras HTTP.
80 // Podría ir un break.
84 // Si es la primera, no pasa nada, sigue esperando un request.
87 // TODO: Manda mensaje a la planta.
88 //signal_command_received().emit(request);
89 //dispatch_command(parse_command(sstr.str()));
91 std::cerr << "Request: " << std::endl;
92 for (Request::const_iterator i = request.begin(); i != request.end();
94 std::cerr << " " << i->first << ": " << i->second << std::endl;
97 // FIXME - hacer respuesta XML.
98 stringstream response_xml;
99 socket << "HTTP/1.0 200 OK" << std::endl;
101 Date: Sun, 19 Oct 2003 15:11:14 GMT
102 Server: Apache/1.3.28 (Debian GNU/Linux)
103 Last-Modified: Mon, 28 Apr 2003 07:50:08 GMT
104 ETag: "110f4043-11a1-3eacdd30"
107 socket << "Content-Type: text/html; charset=iso-8859-1" << std::endl;
108 response_xml << "<html>" << std::endl;
109 response_xml << " <head>" << std::endl;
110 response_xml << " <title>PlaQui v0.1</title>" << std::endl;
111 response_xml << " </head>" << std::endl;
112 response_xml << " <body>" << std::endl;
113 response_xml << " <h1>PlaQui</h1>" << std::endl;
114 response_xml << " <p>versión 0.2</p>" << std::endl;
115 response_xml << " <h2>Pedido HTTP</h2>" << std::endl;
116 response_xml << " <ul>" << std::endl;
117 for (Request::const_iterator i = request.begin(); i != request.end();
119 response_xml << " <li><b>" << i->first << ":</b> "
120 << i->second << std::endl;
122 response_xml << " </ul>" << std::endl;
123 response_xml << " <h2>Desarrollado por</h2>" << std::endl;
124 response_xml << " <ul>" << std::endl;
125 response_xml << " <li>Nicolás Dimov.</li>" << std::endl;
126 response_xml << " <li>Leandro Lucarella.</li>" << std::endl;
127 response_xml << " <li>Ricardo Markiewicz.</li>" << std::endl;
128 response_xml << " </ul>" << std::endl;
129 response_xml << " <address>" << std::endl;
130 response_xml << " Copyleft 2003 - bajo los " << std::endl;
131 response_xml << " términos de la licencia GPL" << std::endl;
132 response_xml << " </address>" << std::endl;
133 response_xml << " </body>" << std::endl;
134 response_xml << "</html>" << std::endl;
135 socket << "Content-Length: " << response_xml.str().length() << std::endl;
137 socket << response_xml.str() << std::flush;