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,
75 cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator>>()" << endl;
77 is >> static_cast<HTTPResponse&>(resp);
78 if (resp.get_body().length()) {
79 Response::Parser(resp).parse_memory(resp.get_body());
84 /// \todo TODO hacer el metodo build como en command.
85 ostream& operator<<(ostream& os, const Response& resp) {
87 cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator<<()" << endl;
90 b.from(resp.xml_code);
91 b = string("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n"
92 "<plaqui-response code=\"") + b + "\" version=\""
93 + resp.xml_version + "\" ";
94 if (resp.xml_description.length()) {
95 b += "description=\"" + resp.xml_description + "\" ";
97 if (resp.xml_body.length()) {
98 b += ">\n" + resp.xml_body + "\n</plaqui-response>\n";
102 HTTPResponse r(resp);
104 os << static_cast<const HTTPResponse&>(r);
108 } // namespace Server
110 } // namespace PlaQui