]> git.llucax.com Git - z.facultad/75.42/plaqui.git/blob - Server/src/response.cpp
Se corrige el bug al parsear el xml.
[z.facultad/75.42/plaqui.git] / Server / src / response.cpp
1 // vim: set noexpandtab tabstop=4 shiftwidth=4:
2 //----------------------------------------------------------------------------
3 //                                  PlaQui
4 //----------------------------------------------------------------------------
5 // This file is part of PlaQui.
6 //
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
10 // version.
11 //
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
15 // details.
16 //
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 //----------------------------------------------------------------------------
24 //
25 // $Id$
26 //
27
28 #include "plaqui/server/response.h"
29 #include "plaqui/server/string.h"
30 #include <sstream>
31 #ifdef DEBUG
32 #       include <iostream>
33 #endif // DEBUG
34
35 using namespace std;
36
37 namespace PlaQui {
38
39 namespace Server {
40
41 Response::~Response(void) {
42 #ifdef DEBUG
43         cerr << __FILE__ << "(" << __LINE__ << ")"
44                 << ": destructor." << endl;
45 #endif // DEBUG
46 }
47
48 Response::Response(const Code& code, const string& desc):
49                 xml_version("1.0"), xml_code(code), xml_description(desc) {
50 #ifdef DEBUG
51         cerr << __FILE__ << "(" << __LINE__ << ")"
52                 << ": constructor(code = " << code << ", desc = " << desc << ");"
53                 << endl;
54 #endif // DEBUG
55         headers["Content-Type"] = "text/xml; charset=iso-8859-1";
56         status_code = HTTPMessage::OK;
57 }
58
59 Response::Response(const string& body, const string& desc, const Code& code):
60                 xml_version("1.0"), xml_code(code), xml_description(desc),
61                 xml_body(body) {
62 #ifdef DEBUG
63         cerr << __FILE__ << "(" << __LINE__ << ")"
64                 << ": constructor(body.length = " << body.length()
65                 << ", desc = " << desc << ", code = " << code << ");" << endl;
66 #endif // DEBUG
67         headers["Content-Type"] = "text/xml; charset=iso-8859-1";
68         status_code = HTTPMessage::OK;
69 }
70
71 istream& operator>>(istream& is, Response& resp)
72                 throw (HTTPResponse::Error, ios::failure, sockerr,
73                                 xmlpp::parse_error) {
74 #ifdef DEBUG
75         cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator>>()" << endl;
76 #endif // DEBUG
77         is >> static_cast<HTTPResponse&>(resp);
78         if (resp.get_body().length()) {
79                 Response::Parser(resp).parse_memory(resp.get_body());
80         }
81         return is;
82 }
83
84 /// \todo TODO hacer el metodo build como en command.
85 ostream& operator<<(ostream& os, const Response& resp) {
86 #ifdef DEBUG
87         cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator<<()" << endl;
88 #endif // DEBUG
89         String b;
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 + "\" ";
96         }
97         if (resp.xml_body.length()) {
98                 b += ">\n" + resp.xml_body + "\n</plaqui-response>\n";
99         } else {
100                 b += "/>\n";
101         }
102         HTTPResponse r(resp);
103         r.set_body(b);
104         os << static_cast<const HTTPResponse&>(r);
105         return os;
106 }
107
108 } // namespace Server
109
110 } // namespace PlaQui
111