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 ////------------------------------------------------------------------------------
27 //Avp::Avp(Engine *engine) : anna::diameter::codec::Avp(engine) {
31 ////------------------------------------------------------------------------------
32 ////------------------------------------------------------------------- Avp::Avp()
33 ////------------------------------------------------------------------------------
34 //Avp::Avp(AvpId id, Engine *engine)/* : anna::diameter::codec::Avp(id, engine)*/ {
39 //------------------------------------------------------------------------------
40 //------------------------------------------------------------------ Avp::~Avp()
41 //------------------------------------------------------------------------------
47 ////------------------------------------------------------------------------------
48 ////------------------------------------------------------------- Avp::getEngine()
49 ////------------------------------------------------------------------------------
50 //anna::diameter::codec::Engine * Avp::getEngine() const throw(anna::RuntimeException) {
52 // throw anna::RuntimeException("Invalid codec engine reference (NULL)", ANNA_FILE_LOCATION);
58 //------------------------------------------------------------------------------
59 //---------------------------------------------------- Avp::initializeByFormat()
60 //------------------------------------------------------------------------------
61 void Avp::initializeByFormat() throw() {
68 //------------------------------------------------------------------------------
69 //--------------------------------------------------------- Avp::clearByFormat()
70 //------------------------------------------------------------------------------
71 void Avp::clearByFormat() throw() {
78 //------------------------------------------------------------------------------
79 //---------------------------------------------------- Avp::allocationByFormat()
80 //------------------------------------------------------------------------------
81 void Avp::allocationByFormat(const stack::Format *stackFormat) throw() {
82 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber = new ISDNNumber();
83 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress = new ISDNAddress();
84 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16 = new Unsigned16();
88 //------------------------------------------------------------------------------
89 //----------------------------------------------------- Avp::getLengthByFormat()
90 //------------------------------------------------------------------------------
91 U24 Avp::getLengthByFormat(const stack::Format *stackFormat) const throw() {
94 if(stackFormat->getName() == "ISDNNumber") result += a_ISDNNumber->getSize();
95 else if(stackFormat->getName() == "ISDNAddress") result += a_ISDNAddress->getSize();
96 else if(stackFormat->getName() == "Unsigned16") result += a_Unsigned16->getSize();
102 //------------------------------------------------------------------------------
103 //------------------------------------------------ Avp::decodeDataPartByFormat()
104 //------------------------------------------------------------------------------
105 void Avp::decodeDataPartByFormat(const char * buffer, int size, const stack::Format *stackFormat) throw(anna::RuntimeException) {
106 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->decode(buffer, size);
107 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->decode(buffer, size);
108 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->decode(buffer, size);
112 //------------------------------------------------------------------------------
113 //---------------------------------------------------------- Avp::codeByFormat()
114 //------------------------------------------------------------------------------
115 void Avp::codeByFormat(char* dataPart, const stack::Format *stackFormat) const throw(anna::RuntimeException) {
118 if(stackFormat->getName() == "ISDNNumber") a_ISDNNumber->code(dataPart, dataBytes);
119 else if(stackFormat->getName() == "ISDNAddress") a_ISDNAddress->code(dataPart, dataBytes);
120 else if(stackFormat->getName() == "Unsigned16") a_Unsigned16->code(dataPart, dataBytes);
124 //------------------------------------------------------------------------------
125 //---------------------------------------------------- Avp::getXMLdataByFormat()
126 //------------------------------------------------------------------------------
127 std::string Avp::getXMLdataByFormat(bool & isHex, const stack::Format *stackFormat) const throw() {
130 if(stackFormat->getName() == "ISDNNumber") {
132 return a_ISDNNumber->asHexString();
133 } else if(stackFormat->getName() == "ISDNAddress") {
135 return a_ISDNAddress->asHexString();
136 } else if(stackFormat->getName() == "Unsigned16") return a_Unsigned16->asPrintableString();
142 //------------------------------------------------------------------------------
143 //------------------------------------------------------- Avp::fromXMLByFormat()
144 //------------------------------------------------------------------------------
145 void Avp::fromXMLByFormat(const anna::xml::Attribute* data, const anna::xml::Attribute* hexData, const stack::Format *stackFormat) throw(anna::RuntimeException) {
146 if(stackFormat->getName() == "ISDNNumber") {
147 if(data) a_ISDNNumber->fromPrintableString(data->getValue().c_str());
148 else if(hexData) a_ISDNNumber->fromHexString(hexData->getValue());
149 } else if(stackFormat->getName() == "ISDNAddress") {
150 if(data) a_ISDNAddress->fromPrintableString(data->getValue().c_str());
151 else if(hexData) a_ISDNAddress->fromHexString(hexData->getValue());
152 } else if(stackFormat->getName() == "Unsigned16") {
153 if(data) a_Unsigned16->fromPrintableString(data->getValue().c_str());
154 else if(hexData) a_Unsigned16->fromHexString(hexData->getValue());