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/codec/tme/Avp.hpp>
11 #include <anna/diameter/codec/tme/Engine.hpp>
13 #include <anna/diameter/helpers/defines.hpp>
14 #include <anna/diameter/stack/Format.hpp>
15 #include <anna/core/functions.hpp>
17 #include <anna/xml/xml.hpp>
20 using namespace anna::diameter::codec::tme;
24 //------------------------------------------------------------------------------
25 //------------------------------------------------------------------- Avp::Avp()
26 //------------------------------------------------------------------------------
32 //------------------------------------------------------------------------------
33 //------------------------------------------------------------------- Avp::Avp()
34 //------------------------------------------------------------------------------
41 //------------------------------------------------------------------------------
42 //------------------------------------------------------------------ Avp::~Avp()
43 //------------------------------------------------------------------------------
49 //------------------------------------------------------------------------------
50 //------------------------------------------------------------- Avp::getEngine()
51 //------------------------------------------------------------------------------
52 anna::diameter::codec::Engine * Avp::getEngine() const throw(anna::RuntimeException) {
53 return a_engine ? a_engine : (a_engine = (anna::diameter::codec::Engine *)anna::functions::component <Engine> (ANNA_FILE_LOCATION));
57 //------------------------------------------------------------------------------
58 //---------------------------------------------------- Avp::initializeByFormat()
59 //------------------------------------------------------------------------------
60 void Avp::initializeByFormat() throw() {
67 //------------------------------------------------------------------------------
68 //--------------------------------------------------------- Avp::clearByFormat()
69 //------------------------------------------------------------------------------
70 void Avp::clearByFormat() throw() {
77 //------------------------------------------------------------------------------
78 //---------------------------------------------------- Avp::allocationByFormat()
79 //------------------------------------------------------------------------------
80 void Avp::allocationByFormat(const stack::Format *stackFormat) throw() {
81 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber = new ISDNNumber();
82 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress = new ISDNAddress();
83 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16 = new Unsigned16();
87 //------------------------------------------------------------------------------
88 //----------------------------------------------------- Avp::getLengthByFormat()
89 //------------------------------------------------------------------------------
90 U24 Avp::getLengthByFormat(const stack::Format *stackFormat) const throw() {
93 if(stackFormat->getName() == "ISDNNumber") result += a_ISDNNumber->getSize();
94 else if(stackFormat->getName() == "ISDNAddress") result += a_ISDNAddress->getSize();
95 else if(stackFormat->getName() == "Unsigned16") result += a_Unsigned16->getSize();
101 //------------------------------------------------------------------------------
102 //------------------------------------------------ Avp::decodeDataPartByFormat()
103 //------------------------------------------------------------------------------
104 void Avp::decodeDataPartByFormat(const char * buffer, int size, const stack::Format *stackFormat) throw(anna::RuntimeException) {
105 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->decode(buffer, size);
106 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->decode(buffer, size);
107 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->decode(buffer, size);
111 //------------------------------------------------------------------------------
112 //---------------------------------------------------------- Avp::codeByFormat()
113 //------------------------------------------------------------------------------
114 void Avp::codeByFormat(char* dataPart, const stack::Format *stackFormat) const throw(anna::RuntimeException) {
117 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->code(dataPart, dataBytes);
118 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->code(dataPart, dataBytes);
119 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->code(dataPart, dataBytes);
123 //------------------------------------------------------------------------------
124 //---------------------------------------------------- Avp::getXMLdataByFormat()
125 //------------------------------------------------------------------------------
126 std::string Avp::getXMLdataByFormat(bool & isHex, const stack::Format *stackFormat) const throw() {
129 if(stackFormat->getName() == "ISDNNumber") {
131 return a_ISDNNumber->asHexString();
132 } else if(stackFormat->getName() == "ISDNAddress") {
134 return a_ISDNAddress->asHexString();
135 } else if(stackFormat->getName() == "Unsigned16") return a_Unsigned16->asPrintableString();
141 //------------------------------------------------------------------------------
142 //------------------------------------------------------- Avp::fromXMLByFormat()
143 //------------------------------------------------------------------------------
144 void Avp::fromXMLByFormat(const anna::xml::Attribute* data, const anna::xml::Attribute* hexData, const stack::Format *stackFormat) throw(anna::RuntimeException) {
145 if(stackFormat->getName() == "ISDNNumber") {
146 if(data) a_ISDNNumber->fromPrintableString(data->getValue().c_str());
147 else if(hexData) a_ISDNNumber->fromHexString(hexData->getValue());
148 } else if(stackFormat->getName() == "ISDNAddress") {
149 if(data) a_ISDNAddress->fromPrintableString(data->getValue().c_str());
150 else if(hexData) a_ISDNAddress->fromHexString(hexData->getValue());
151 } else if(stackFormat->getName() == "Unsigned16") {
152 if(data) a_Unsigned16->fromPrintableString(data->getValue().c_str());
153 else if(hexData) a_Unsigned16->fromHexString(hexData->getValue());