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: lun nov 17 21:02:22 ART 2003
22 // Autores: Leandro Lucarella <llucare@fi.uba.ar>
23 //----------------------------------------------------------------------------
28 #include "plaqui/server/response.h"
29 #include "plaqui/server/string.h"
41 Response::~Response(void) {
43 cerr << __FILE__ << "(" << __LINE__ << ")"
44 << ": destructor." << endl;
48 Response::Response(const Code& code, const string& desc):
49 xml_version("1.0"), xml_code(code), xml_description(desc) {
51 cerr << __FILE__ << "(" << __LINE__ << ")"
52 << ": constructor(code = " << code << ", desc = " << desc << ");"
55 headers["Content-Type"] = "text/xml; charset=iso-8859-1";
56 status_code = HTTPMessage::OK;
59 Response::Response(const string& body, const string& desc, const Code& code):
60 xml_version("1.0"), xml_code(code), xml_description(desc),
63 cerr << __FILE__ << "(" << __LINE__ << ")"
64 << ": constructor(body.length = " << body.length()
65 << ", desc = " << desc << ", code = " << code << ");" << endl;
67 headers["Content-Type"] = "text/xml; charset=iso-8859-1";
68 status_code = HTTPMessage::OK;
71 istream& operator>>(istream& is, Response& resp)
72 /*throw (HTTPResponse::Error, ios::failure, sockerr)*/ {
74 cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator>>()" << endl;
76 is >> static_cast<HTTPResponse&>(resp);
77 if (resp.get_body().length()) {
78 // TODO parseo XML del body para buscar las cosas basicas de la respuesta.
79 Response::Parser parser(resp);
81 parser.parse_memory(resp.get_body());
82 } catch (const xmlpp::parse_error& e) {
83 // TODO - ver gravedad.
85 cerr << __FILE__ << "(" << __LINE__ << ")"
86 << " : operator>>() error de parseo: " << e.what() << endl;
93 /// \todo TODO hacer el metodo build como en command.
94 ostream& operator<<(ostream& os, const Response& resp) {
96 cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator<<()" << endl;
99 b.from(resp.xml_code);
100 b = string("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n"
101 "<plaqui-response code=\"") + b + "\" version=\""
102 + resp.xml_version + "\" ";
103 if (resp.xml_description.length()) {
104 b += "description=\"" + resp.xml_description + "\" ";
106 if (resp.xml_body.length()) {
107 b += ">\n" + resp.xml_body + "\n</plaqui-response>\n";
111 HTTPResponse r(resp);
113 os << static_cast<const HTTPResponse&>(r);
117 } // namespace Server
119 } // namespace PlaQui