X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/d61490999af17b602d7208ada92840cddc4eff6a..9322e49b932d824e5664aa8c0e0f9a41464537b1:/Server/src/response.cpp?ds=inline
diff --git a/Server/src/response.cpp b/Server/src/response.cpp
index 91b44af..3a3f4bf 100644
--- a/Server/src/response.cpp
+++ b/Server/src/response.cpp
@@ -53,19 +53,103 @@ Response::Response(const Code& code, const string& desc):
<< endl;
#endif // DEBUG
headers["Content-Type"] = "text/xml; charset=iso-8859-1";
- status_code = HTTPMessage::OK;
+ build();
}
-Response::Response(const string& body, const string& desc, const Code& code):
+Response::Response(const string& contents, const string& desc, const Code& code):
xml_version("1.0"), xml_code(code), xml_description(desc),
- xml_body(body) {
+ xml_contents(contents) {
#ifdef DEBUG
cerr << __FILE__ << "(" << __LINE__ << ")"
- << ": constructor(body.length = " << body.length()
+ << ": constructor(body.length = " << contents.length()
<< ", desc = " << desc << ", code = " << code << ");" << endl;
#endif // DEBUG
headers["Content-Type"] = "text/xml; charset=iso-8859-1";
- status_code = HTTPMessage::OK;
+ build();
+}
+
+void Response::build(void) {
+ String b;
+ b.from(xml_code);
+ b = string("\n"
+ "\n" + xml_contents + "\n\n";
+ } else {
+ b += "/>\n";
+ }
+ set_body(b);
+ switch (xml_code) {
+ case OK:
+ status_code = HTTPMessage::OK;
+ break;
+ case INVALID_TARGET:
+ case INVALID_COMMAND:
+ case CONNECTION_NOT_FOUND:
+ case TRANSMISSION_NOT_FOUND:
+ case PLANT_NOT_FOUND:
+ case ELEMENT_NOT_FOUND:
+ case ELEMENT_INPUT_NOT_FOUND:
+ status_code = HTTPMessage::INTERNAL_SERVER_ERROR;
+ break;
+ case ALLREADY_EXISTS:
+ case ARGUMENT_MISSING:
+ status_code = HTTPMessage::CONFLICT;
+ break;
+ case UNKNOWN_ERROR:
+ case ERROR_STARTING_TRANSMISSION:
+ case ERROR_GETING_PLANT_XML:
+ case ERROR_CHANGING_ELEMENT_INPUT:
+ status_code = HTTPMessage::INTERNAL_SERVER_ERROR;
+ break;
+ default:
+ status_code = HTTPMessage::INTERNAL_SERVER_ERROR;
+ break;
+ }
+}
+
+const string& Response::get_version(void) const {
+ return xml_version;
+}
+
+const string& Response::set_version(const string& version_) {
+ xml_version = version_;
+ build();
+ return version_;
+}
+
+const Response::Code& Response::get_code(void) const {
+ return xml_code;
+}
+
+const Response::Code& Response::set_code(const Response::Code& code_) {
+ xml_code = code_;
+ build();
+ return code_;
+}
+
+const string& Response::get_description(void) const {
+ return xml_description;
+}
+
+const string& Response::set_description(const string& description_) {
+ xml_description = description_;
+ build();
+ return description_;
+}
+
+const string& Response::get_contents(void) const {
+ return xml_contents;
+}
+
+const string& Response::set_contents(const string& contents_) {
+ xml_contents = contents_;
+ build();
+ return contents_;
}
istream& operator>>(istream& is, Response& resp)
@@ -78,30 +162,15 @@ istream& operator>>(istream& is, Response& resp)
if (resp.get_body().length()) {
Response::Parser(resp).parse_memory(resp.get_body());
}
+ resp.build();
return is;
}
-/// \todo TODO hacer el metodo build como en command.
ostream& operator<<(ostream& os, const Response& resp) {
#ifdef DEBUG
cerr << __FILE__ << "(" << __LINE__ << ")" << ": operator<<()" << endl;
#endif // DEBUG
- String b;
- b.from(resp.xml_code);
- b = string("\n"
- "\n" + resp.xml_body + "\n\n";
- } else {
- b += "/>\n";
- }
- HTTPResponse r(resp);
- r.set_body(b);
- os << static_cast(r);
+ os << static_cast(resp);
return os;
}