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"
33 using namespace PlaQui::Server;
35 ControlServer::ControlServer(const sockbuf::sockdesc& sd):
38 std::cerr << "Compilado el " << __DATE__ << std::endl;
39 std::cerr << __FILE__ << ": sd = " << sd.sock << std::endl;
43 void ControlServer::real_run(void) {
44 // FIXME se tiene que ir a la clase para poder frenarlo desde afuera.
46 char buf[BUFFER_SIZE];
49 // Primera línea no vacía (que debe ser el request).
51 while (!stop && socket.getline(buf, BUFFER_SIZE)) {
53 std::cerr << "Reciviendo linea: " << buf << std::endl;
55 int len = strlen(buf);
56 // Si tiene un retorno de carro, lo elimina.
57 if (len && (buf[len-1] == '\r')) {
60 // Si tiene contenido, lo agrego a la información del request.
62 // Si es la primera línea, es el request.
64 request.set_request(buf, socket->peerhost(),
68 // TODO request.parse_header(buf);
70 // Si viene la línea vacía
72 // Si no es la primera, terminan las cabeceras HTTP.
74 // Podría ir un break.
78 // Si es la primera, no pasa nada, sigue esperando un request.
81 // Manda mensaje a la planta.
82 //dispatch_command(parse_command(sstr.str()));
84 std::cerr << "Request: " << std::endl;
85 for (Request::const_iterator i = request.begin(); i != request.end();
87 std::cerr << " " << i->first << ": " << i->second << std::endl;
90 // FIXME - hacer respuesta XML.
91 stringstream response_xml;
92 socket << "HTTP/1.0 200 OK" << std::endl;
94 Date: Sun, 19 Oct 2003 15:11:14 GMT
95 Server: Apache/1.3.28 (Debian GNU/Linux)
96 Last-Modified: Mon, 28 Apr 2003 07:50:08 GMT
97 ETag: "110f4043-11a1-3eacdd30"
100 socket << "Content-Type: text/html; charset=iso-8859-1" << std::endl;
101 response_xml << "<html>" << std::endl;
102 response_xml << " <head>" << std::endl;
103 response_xml << " <title>PlaQui v0.1</title>" << std::endl;
104 response_xml << " </head>" << std::endl;
105 response_xml << " <body>" << std::endl;
106 response_xml << " <h1>PlaQui</h1>" << std::endl;
107 response_xml << " <p>versión 0.2</p>" << std::endl;
108 response_xml << " <h2>Pedido HTTP</h2>" << std::endl;
109 response_xml << " <ul>" << std::endl;
110 for (Request::const_iterator i = request.begin(); i != request.end();
112 response_xml << " <li><b>" << i->first << ":</b> "
113 << i->second << std::endl;
115 response_xml << " </ul>" << std::endl;
116 response_xml << " <h2>Desarrollado por</h2>" << std::endl;
117 response_xml << " <ul>" << std::endl;
118 response_xml << " <li>Nicolás Dimov.</li>" << std::endl;
119 response_xml << " <li>Leandro Lucarella.</li>" << std::endl;
120 response_xml << " <li>Ricardo Markiewicz.</li>" << std::endl;
121 response_xml << " </ul>" << std::endl;
122 response_xml << " <address>" << std::endl;
123 response_xml << " Copyleft 2003 - bajo los " << std::endl;
124 response_xml << " términos de la licencia GPL" << std::endl;
125 response_xml << " </address>" << std::endl;
126 response_xml << " </body>" << std::endl;
127 response_xml << "</html>" << std::endl;
128 socket << "Content-Length: " << response_xml.str().length() << std::endl;
130 socket << response_xml.str() << std::flush;