1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
10 #include <anna/diameter.comm/Message.hpp>
11 #include <anna/diameter.comm/ClientSession.hpp>
12 #include <anna/diameter.comm/ServerSession.hpp>
13 #include <anna/diameter/codec/functions.hpp>
14 #include <anna/diameter/defines.hpp>
16 #include <anna/xml/Node.hpp>
17 #include <anna/core/functions.hpp>
18 #include <anna/core/RuntimeException.hpp>
19 #include <anna/comm/ClientSocket.hpp>
20 #include <anna/core/tracing/Logger.hpp>
23 using namespace anna::diameter;
24 using namespace anna::diameter::comm;
28 const char* Message::asText(const OnExpiry::_v rc)
30 static const char* text [] = { "Abandon", "Ignore" };
34 string Message::asString() const
36 string result("diameter::comm::Message { ");
37 result += "ClassCode: ";
38 result += ClassCode::asText(a_classCode);
39 result += " | OnExpiry: ";
40 result += asText(a_onExpiry);
41 result += " | Retries: ";
42 result += anna::functions::asString(a_retries);
43 return result += " }";
46 anna::xml::Node* Message::asXML(anna::xml::Node* parent) const
48 anna::xml::Node* result = parent->createChild("diameter.comm.Message");
49 result->createAttribute("ClassCode", ClassCode::asText(a_classCode));
50 result->createAttribute("OnExpiry", asText(a_onExpiry));
51 result->createAttribute("Retries", anna::functions::asString(a_retries));
56 //void Message::clear ()
60 //// a_classCode = ClassCode::Undefined;
61 //// a_onExpiry = OnExpiry::Ignore;
64 bool Message::fixRequestSequence(HopByHop hbh, EndToEnd ete) throw() {
65 setRequestHopByHop(getHopByHop()); // original request hop-by-hop (backup)
66 setRequestEndToEnd(getEndToEnd()); // original request end-to-end (backup)
69 if(hbh != getRequestHopByHop()) {
70 codec::functions::setHopByHop((anna::DataBlock&)getBody(), hbh);
74 if(a_updateEndToEnd) {
75 if(ete != getRequestEndToEnd()) {
76 codec::functions::setEndToEnd((anna::DataBlock&)getBody(), ete);
82 string msg("diameter::comm::fixRequestSequence { ");
83 msg += "Hop by hop: ";
84 msg += anna::functions::asString(getRequestHopByHop());
85 msg += " (original) -> ";
86 msg += anna::functions::asString(hbh);
88 msg += a_updateEndToEnd ? " | End to end: " : " | End to end [end-to-end unchanged]: ";
89 msg += anna::functions::asString(getRequestEndToEnd());
90 msg += " (original) -> ";
91 msg += anna::functions::asString(ete);
93 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
100 void Message::restoreSequencesAfterFix() throw() {
102 string msg("diameter::comm::restoreSequencesAfterFix { ");
103 msg += "Hop by hop: ";
104 msg += anna::functions::asString(getHopByHop());
105 msg += " (session) -> ";
106 msg += anna::functions::asString(getRequestHopByHop());
107 msg += " (original)";
108 msg += " | End to end: ";
109 msg += anna::functions::asString(getEndToEnd());
110 msg += " (session) -> ";
111 msg += anna::functions::asString(getRequestEndToEnd());
112 msg += " (original)";
113 anna::Logger::debug(msg, ANNA_FILE_LOCATION);
115 diameter::codec::functions::setHopByHop((anna::DataBlock&)getBody(), a_requestHopByHop);
116 diameter::codec::functions::setEndToEnd((anna::DataBlock&)getBody(), a_requestEndToEnd);
120 void Message::send(ClientSession& clientSession) const
121 throw(anna::RuntimeException) {
123 clientSession.getServer()->send((Message *)this);
124 } catch(anna::RuntimeException&) {
129 void Message::send(ServerSession& serverSession) const
130 throw(anna::RuntimeException) {
132 serverSession.getClientSocket()->send((Message *)this);
133 } catch(anna::RuntimeException&) {
140 anna::diameter::CommandId Message::getCommandId(bool &isRequest) const throw() {
141 diameter::CommandId result = diameter::codec::functions::getCommandId(getBody());
142 isRequest = result.second; // diameter::codec::functions::isRequest(result);
146 anna::diameter::ApplicationId Message::getApplicationId() const throw() {
147 diameter::ApplicationId result = diameter::codec::functions::getApplicationId(getBody());
151 HopByHop Message::getHopByHop() const throw() {
152 return (diameter::codec::functions::getHopByHop(getBody()));
155 EndToEnd Message::getEndToEnd() const throw() {
156 return (diameter::codec::functions::getEndToEnd(getBody()));