]> git.llucax.com Git - z.facultad/75.42/plaqui.git/commitdiff
Se agrega un archivo que falto subir en el ultimo commit XD
authorLeandro Lucarella <llucax@gmail.com>
Fri, 28 Nov 2003 19:46:12 +0000 (19:46 +0000)
committerLeandro Lucarella <llucax@gmail.com>
Fri, 28 Nov 2003 19:46:12 +0000 (19:46 +0000)
Server/src/response_parser.cpp [new file with mode: 0644]
Server/src/server.cpp

diff --git a/Server/src/response_parser.cpp b/Server/src/response_parser.cpp
new file mode 100644 (file)
index 0000000..c34bbfb
--- /dev/null
@@ -0,0 +1,133 @@
+// vim: set noexpandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+//                                  PlaQui
+//----------------------------------------------------------------------------
+// This file is part of PlaQui.
+//
+// PlaQui is free software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the Free Software
+// Foundation; either version 2 of the License, or (at your option) any later
+// version.
+//
+// PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+// details.
+//
+// You should have received a copy of the GNU General Public License along
+// with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA  02111-1307  USA
+//----------------------------------------------------------------------------
+// Creado:  jue nov 27 13:33:22 ART 2003
+// Autores: Leandro Lucarella <llucare@fi.uba.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#include "plaqui/server/response.h"
+#include "plaqui/server/string.h"
+#include <sstream>
+#ifdef DEBUG
+#      include <iostream>
+#endif // DEBUG
+
+using namespace std;
+
+namespace PlaQui {
+
+namespace Server {
+
+Response::Parser::~Parser(void) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": destructor." << endl;
+#endif // DEBUG
+}
+
+Response::Parser::Parser(Response& resp): response(&resp), root(true) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": constructor();" << endl;
+#endif // DEBUG
+}
+
+void Response::Parser::on_start_element(const string& name,
+               const AttributeMap& attrs) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": on_start_element(name = " << name << ", attrs = [";
+       for (AttributeMap::const_iterator i = attrs.begin();
+                       i != attrs.end(); i++) {
+               cerr << i->first << " = " << i->second << ", ";
+       }
+       cerr << "]);" << endl;
+#endif // DEBUG
+       if (root) {
+               // Si es el elemento raíz, debe ser la respuesta.
+               if (name == "plaqui-response") {
+                       AttributeMap::const_iterator i = attrs.find("version");
+                       if (i != attrs.end()) {
+                               response->xml_version = i->second;
+                       }
+                       i = attrs.find("code");
+                       if (i != attrs.end()) {
+                               int c;
+                               to(i->second, c);
+                               response->xml_code = static_cast<Response::Code>(c);
+                       }
+                       i = attrs.find("description");
+                       if (i != attrs.end()) {
+                               response->xml_description = i->second;
+                       }
+                       root = false;
+               }
+       // Si no es el elemento raíz, lo agrego al body.
+       } else {
+               response->xml_body += "<";
+               response->xml_body += name + " ";
+               for (AttributeMap::const_iterator i = attrs.begin();
+                               i != attrs.end(); i++) {
+                       response->xml_body += i->first + " = \"" + i->second + "\" ";
+               }
+               response->xml_body += ">";
+       }
+}
+
+void Response::Parser::on_end_element(const string& name) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": on_end_element(name = " << name << ");" << endl;
+#endif // DEBUG
+       // Si es el fin de la respuesta, volvemos a la raíz.
+       if (name == "plaqui-response") {
+               root = true;
+       // Si no, agrega al cuerpo.
+       } else {
+               response->xml_body += "</";
+               response->xml_body += name + ">";
+       }
+}
+
+void Response::Parser::on_characters(const string& chars) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": on_characters(chars = " << chars << ");" << endl;
+#endif // DEBUG
+       // Sólo nos importa el contenido, lo agregamos.
+       if (!root) {
+               response->xml_body += chars;
+       }
+}
+
+/*void Response::Parser::on_comment(const string& text) {
+#ifdef DEBUG
+       cerr << __FILE__ << "(" << __LINE__ << ")"
+               << ": on_comment(text = " << text << ");" << endl;
+#endif // DEBUG
+}*/
+
+} // namespace Server
+
+} // namespace PlaQui
+
index ca1f763a5883513b275db1a13ba94048c45e80fe..5e7197acd3adcae385a75e83735332b97f2d2d00 100644 (file)
@@ -114,7 +114,6 @@ void Server::on_control_command_received(const Command& command,
                << endl;
 #endif // DEBUG
        Response* response;
-       //bool stop_controlserver = false;
        if (command.get_target() == "server") {
                if (command.get_command() == "info") {
                        response = cmd_server_info();