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/httprequest.h"
42 ControlServer::~ControlServer(void) {
44 cerr << __FILE__ << ": destructor." << endl;
48 ControlServer::ControlServer(const sockbuf::sockdesc& sd):
49 ServerConnection(sd) {
51 cerr << __FILE__ << ": sd = " << sd.sock << endl;
55 void ControlServer::real_run(void) {
57 cerr << __FILE__ << ": real_run()" << endl;
63 // TODO agregar las verificaciones de abajo a HTTPRequest y padres.
65 // Primera línea no vacía (que debe ser el request).
67 while (!stop && socket.getline(buf, BUFSIZ)) {
69 cerr << __FILE__ << " Recibiendo inea: " << buf << endl;
71 int len = strlen(buf);
72 // Si tiene un retorno de carro, lo elimina.
73 if (len && (buf[len-1] == '\r')) {
76 // Si tiene contenido, lo agrego a la información del request.
78 // Si es la primera línea, es el request.
80 request.set_request(buf, socket->peerhost(),
84 // TODO request.parse_header(buf);
86 // Si viene la línea vacía
88 // Si no es la primera, terminan las cabeceras HTTP.
90 // Podría ir un break.
94 // Si es la primera, no pasa nada, sigue esperando un request.
98 // TODO: Manda el comando.
99 // Command command = parse_command(request.uri);
100 //signal_command_received().emit(command);
102 cerr << "Request: " << endl;
103 for (Request::const_iterator i = request.begin(); i != request.end();
105 cerr << " " << i->first << ": " << i->second << endl;
108 // FIXME - hacer respuesta XML.
109 // La respuesta hay que mandarla asincrónicamente porque no puedo
110 // responder hasta que la planta no se termine de actualizar, por
112 stringstream response_xml;
113 socket << "HTTP/1.0 200 OK" << endl;
115 Date: Sun, 19 Oct 2003 15:11:14 GMT
116 Server: Apache/1.3.28 (Debian GNU/Linux)
117 Last-Modified: Mon, 28 Apr 2003 07:50:08 GMT
120 socket << "Content-Type: text/html; charset=iso-8859-1" << endl;
121 response_xml << "<html>" << endl;
122 response_xml << " <head>" << endl;
123 response_xml << " <title>PlaQui v0.1</title>" << endl;
124 response_xml << " </head>" << endl;
125 response_xml << " <body>" << endl;
126 response_xml << " <h1>PlaQui</h1>" << endl;
127 response_xml << " <p>versión 0.2</p>" << endl;
128 response_xml << " <h2>Pedido HTTP</h2>" << endl;
129 response_xml << " <ul>" << endl;
130 for (Request::const_iterator i = request.begin(); i != request.end();
132 response_xml << " <li><b>" << i->first << ":</b> "
133 << i->second << endl;
135 response_xml << " </ul>" << endl;
136 response_xml << " <h2>Desarrollado por</h2>" << endl;
137 response_xml << " <ul>" << endl;
138 response_xml << " <li>Nicolás Dimov.</li>" << endl;
139 response_xml << " <li>Leandro Lucarella.</li>" << endl;
140 response_xml << " <li>Ricardo Markiewicz.</li>" << endl;
141 response_xml << " </ul>" << endl;
142 response_xml << " <address>" << endl;
143 response_xml << " Copyleft 2003 - bajo los " << endl;
144 response_xml << " términos de la licencia GPL" << endl;
145 response_xml << " </address>" << endl;
146 response_xml << " </body>" << endl;
147 response_xml << "</html>" << endl;
148 socket << "Content-Length: " << response_xml.str().length() << endl;
150 socket << response_xml.str() << flush;
154 } // namespace Server
156 } // namespace PlaQui