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";
59 Response::Response(const string& contents, const string& desc, const Code& code):
60 xml_version("1.0"), xml_code(code), xml_description(desc),
61 xml_contents(contents) {
63 cerr << __FILE__ << "(" << __LINE__ << ")"
64 << ": constructor(body.length = " << contents.length()
65 << ", desc = " << desc << ", code = " << code << ");" << endl;
67 headers["Content-Type"] = "text/xml; charset=iso-8859-1";
71 void Response::build(void) {
74 b = string("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\n"
75 "<plaqui-response code=\"") + b + "\" version=\""
76 + xml_version + "\" ";
77 if (xml_description.length()) {
78 b += "description=\"" + xml_description + "\" ";
80 if (xml_contents.length()) {
81 b += ">\n" + xml_contents + "\n</plaqui-response>\n";
88 status_code = HTTPMessage::OK;
92 case CONNECTION_NOT_FOUND:
93 case TRANSMISSION_NOT_FOUND:
95 case ELEMENT_NOT_FOUND:
96 case ELEMENT_INPUT_NOT_FOUND:
97 status_code = HTTPMessage::INTERNAL_SERVER_ERROR;
100 case ARGUMENT_MISSING:
101 status_code = HTTPMessage::CONFLICT;
104 case ERROR_STARTING_TRANSMISSION:
105 case ERROR_GETING_PLANT_XML:
106 case ERROR_CHANGING_ELEMENT_INPUT:
107 status_code = HTTPMessage::INTERNAL_SERVER_ERROR;
110 status_code = HTTPMessage::INTERNAL_SERVER_ERROR;
115 const string& Response::get_version(void) const {
119 const string& Response::set_version(const string& version_) {
120 xml_version = version_;
125 const Response::Code& Response::get_code(void) const {
129 const Response::Code& Response::set_code(const Response::Code& code_) {
135 const string& Response::get_description(void) const {
136 return xml_description;
139 const string& Response::set_description(const string& description_) {
140 xml_description = description_;
145 const string& Response::get_contents(void) const {
149 const string& Response::set_contents(const string& contents_) {
150 xml_contents = contents_;
155 istream& operator>>(istream& is, Response& resp)
156 throw (HTTPResponse::Error, ios::failure, sockerr,
157 xmlpp::parse_error) {
159 cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator>>()" << endl;
161 is >> static_cast<HTTPResponse&>(resp);
162 if (resp.get_body().length()) {
163 Response::Parser(resp).parse_memory(resp.get_body());
169 ostream& operator<<(ostream& os, const Response& resp) {
171 cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator<<()" << endl;
173 os << static_cast<const HTTPResponse&>(resp);
177 } // namespace Server
179 } // namespace PlaQui