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;
23 //------------------------------------------------------------------------------
24 //------------------------------------------------------------------ Avp::~Avp()
25 //------------------------------------------------------------------------------
31 ////------------------------------------------------------------------------------
32 ////------------------------------------------------------------- Avp::getEngine()
33 ////------------------------------------------------------------------------------
34 //anna::diameter::codec::Engine * Avp::getEngine() const throw(anna::RuntimeException) {
36 // throw anna::RuntimeException("Invalid codec engine reference (NULL)", ANNA_FILE_LOCATION);
42 //------------------------------------------------------------------------------
43 //---------------------------------------------------- Avp::initializeByFormat()
44 //------------------------------------------------------------------------------
45 void Avp::initializeByFormat() throw() {
52 //------------------------------------------------------------------------------
53 //--------------------------------------------------------- Avp::clearByFormat()
54 //------------------------------------------------------------------------------
55 void Avp::clearByFormat() throw() {
62 //------------------------------------------------------------------------------
63 //---------------------------------------------------- Avp::allocationByFormat()
64 //------------------------------------------------------------------------------
65 void Avp::allocationByFormat(const stack::Format *stackFormat) throw() {
66 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber = new ISDNNumber();
67 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress = new ISDNAddress();
68 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16 = new Unsigned16();
72 //------------------------------------------------------------------------------
73 //----------------------------------------------------- Avp::getLengthByFormat()
74 //------------------------------------------------------------------------------
75 U24 Avp::getLengthByFormat(const stack::Format *stackFormat) const throw() {
78 if(stackFormat->getName() == "ISDNNumber") result += a_ISDNNumber->getSize();
79 else if(stackFormat->getName() == "ISDNAddress") result += a_ISDNAddress->getSize();
80 else if(stackFormat->getName() == "Unsigned16") result += a_Unsigned16->getSize();
86 //------------------------------------------------------------------------------
87 //------------------------------------------------ Avp::decodeDataPartByFormat()
88 //------------------------------------------------------------------------------
89 void Avp::decodeDataPartByFormat(const char * buffer, int size, const stack::Format *stackFormat) throw(anna::RuntimeException) {
90 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->decode(buffer, size);
91 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->decode(buffer, size);
92 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->decode(buffer, size);
96 //------------------------------------------------------------------------------
97 //---------------------------------------------------------- Avp::codeByFormat()
98 //------------------------------------------------------------------------------
99 void Avp::codeByFormat(char* dataPart, const stack::Format *stackFormat) const throw(anna::RuntimeException) {
102 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->code(dataPart, dataBytes);
103 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->code(dataPart, dataBytes);
104 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->code(dataPart, dataBytes);
108 //------------------------------------------------------------------------------
109 //---------------------------------------------------- Avp::getXMLdataByFormat()
110 //------------------------------------------------------------------------------
111 std::string Avp::getXMLdataByFormat(bool & isHex, const stack::Format *stackFormat) const throw() {
114 if(stackFormat->getName() == "ISDNNumber") {
116 return a_ISDNNumber->asHexString();
117 } else if(stackFormat->getName() == "ISDNAddress") {
119 return a_ISDNAddress->asHexString();
120 } else if(stackFormat->getName() == "Unsigned16") return a_Unsigned16->asPrintableString();
126 //------------------------------------------------------------------------------
127 //------------------------------------------------------- Avp::fromXMLByFormat()
128 //------------------------------------------------------------------------------
129 void Avp::fromXMLByFormat(const anna::xml::Attribute* data, const anna::xml::Attribute* hexData, const stack::Format *stackFormat) throw(anna::RuntimeException) {
130 if(stackFormat->getName() == "ISDNNumber") {
131 if(data) a_ISDNNumber->fromPrintableString(data->getValue().c_str());
132 else if(hexData) a_ISDNNumber->fromHexString(hexData->getValue());
133 } else if(stackFormat->getName() == "ISDNAddress") {
134 if(data) a_ISDNAddress->fromPrintableString(data->getValue().c_str());
135 else if(hexData) a_ISDNAddress->fromHexString(hexData->getValue());
136 } else if(stackFormat->getName() == "Unsigned16") {
137 if(data) a_Unsigned16->fromPrintableString(data->getValue().c_str());
138 else if(hexData) a_Unsigned16->fromHexString(hexData->getValue());