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) {
54 throw anna::RuntimeException("Invalid codec engine reference (NULL)", ANNA_FILE_LOCATION);
60 //------------------------------------------------------------------------------
61 //---------------------------------------------------- Avp::initializeByFormat()
62 //------------------------------------------------------------------------------
63 void Avp::initializeByFormat() throw() {
70 //------------------------------------------------------------------------------
71 //--------------------------------------------------------- Avp::clearByFormat()
72 //------------------------------------------------------------------------------
73 void Avp::clearByFormat() throw() {
80 //------------------------------------------------------------------------------
81 //---------------------------------------------------- Avp::allocationByFormat()
82 //------------------------------------------------------------------------------
83 void Avp::allocationByFormat(const stack::Format *stackFormat) throw() {
84 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber = new ISDNNumber();
85 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress = new ISDNAddress();
86 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16 = new Unsigned16();
90 //------------------------------------------------------------------------------
91 //----------------------------------------------------- Avp::getLengthByFormat()
92 //------------------------------------------------------------------------------
93 U24 Avp::getLengthByFormat(const stack::Format *stackFormat) const throw() {
96 if(stackFormat->getName() == "ISDNNumber") result += a_ISDNNumber->getSize();
97 else if(stackFormat->getName() == "ISDNAddress") result += a_ISDNAddress->getSize();
98 else if(stackFormat->getName() == "Unsigned16") result += a_Unsigned16->getSize();
104 //------------------------------------------------------------------------------
105 //------------------------------------------------ Avp::decodeDataPartByFormat()
106 //------------------------------------------------------------------------------
107 void Avp::decodeDataPartByFormat(const char * buffer, int size, const stack::Format *stackFormat) throw(anna::RuntimeException) {
108 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->decode(buffer, size);
109 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->decode(buffer, size);
110 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->decode(buffer, size);
114 //------------------------------------------------------------------------------
115 //---------------------------------------------------------- Avp::codeByFormat()
116 //------------------------------------------------------------------------------
117 void Avp::codeByFormat(char* dataPart, const stack::Format *stackFormat) const throw(anna::RuntimeException) {
120 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->code(dataPart, dataBytes);
121 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->code(dataPart, dataBytes);
122 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->code(dataPart, dataBytes);
126 //------------------------------------------------------------------------------
127 //---------------------------------------------------- Avp::getXMLdataByFormat()
128 //------------------------------------------------------------------------------
129 std::string Avp::getXMLdataByFormat(bool & isHex, const stack::Format *stackFormat) const throw() {
132 if(stackFormat->getName() == "ISDNNumber") {
134 return a_ISDNNumber->asHexString();
135 } else if(stackFormat->getName() == "ISDNAddress") {
137 return a_ISDNAddress->asHexString();
138 } else if(stackFormat->getName() == "Unsigned16") return a_Unsigned16->asPrintableString();
144 //------------------------------------------------------------------------------
145 //------------------------------------------------------- Avp::fromXMLByFormat()
146 //------------------------------------------------------------------------------
147 void Avp::fromXMLByFormat(const anna::xml::Attribute* data, const anna::xml::Attribute* hexData, const stack::Format *stackFormat) throw(anna::RuntimeException) {
148 if(stackFormat->getName() == "ISDNNumber") {
149 if(data) a_ISDNNumber->fromPrintableString(data->getValue().c_str());
150 else if(hexData) a_ISDNNumber->fromHexString(hexData->getValue());
151 } else if(stackFormat->getName() == "ISDNAddress") {
152 if(data) a_ISDNAddress->fromPrintableString(data->getValue().c_str());
153 else if(hexData) a_ISDNAddress->fromHexString(hexData->getValue());
154 } else if(stackFormat->getName() == "Unsigned16") {
155 if(data) a_Unsigned16->fromPrintableString(data->getValue().c_str());
156 else if(hexData) a_Unsigned16->fromHexString(hexData->getValue());