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/helpers/dcca/defines.hpp>
11 #include <anna/diameter/helpers/dcca/functions.hpp>
12 #include <anna/diameter/codec/Message.hpp>
13 #include <anna/diameter/codec/functions.hpp>
14 #include <anna/config/defines.hpp> // general types, decoding helpers (DECODE[2/3/4]BYTES_INDX_VALUETYPE), etc.
15 #include <anna/core/functions.hpp>
17 #include <anna/core/functions.hpp>
18 #include <anna/core/DataBlock.hpp>
24 using namespace anna::diameter::codec;
25 using namespace anna::diameter::helpers::dcca;
30 const char anna::diameter::helpers::dcca::ChargingContextAndDomainSuffix::Data[] = "32251@3gpp.org";
31 const char anna::diameter::helpers::dcca::ChargingContextAndDomainSuffix::Voice[] = "OCS-CS@telefonica.com";
32 const char anna::diameter::helpers::dcca::ChargingContextAndDomainSuffix::Content[] = "OCS-Generic-Services@telefonica.com";
33 const char anna::diameter::helpers::dcca::ChargingContextAndDomainSuffix::SMS[] = "32274@3gpp.org";
34 const char anna::diameter::helpers::dcca::ChargingContextAndDomainSuffix::MMS[] = "32270@3gpp.org";
38 std::string anna::diameter::helpers::dcca::functions::getSubscriptionIdData(const anna::DataBlock & db, int subscriptionIdType) throw(anna::RuntimeException) {
39 if(db.getSize() < Message::HeaderLength)
40 throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
42 //anna::DataBlock avpsDB(db.getData() + Message::HeaderLength, db.getSize() - Message::HeaderLength);
43 const char *avpsDB = db.getData() + Message::HeaderLength;
44 int avpsLen = db.getSize() - Message::HeaderLength;
45 std::string result = "";
47 int pos = 1; // first avp
48 const char * subscriptionIdPtr;
49 const char * subscriptionIdDataPtr;
51 // Decoded avp information:
55 std::string _dataG /* grouped */, _data;
58 //subscriptionIdPtr = diameter::codec::functions::findAVP(avpsDB, AVPID__Subscription_Id, pos);
59 subscriptionIdPtr = diameter::codec::functions::findAVP(avpsDB, avpsLen, AVPID__Subscription_Id, pos);
61 if(!subscriptionIdPtr) return result;
64 diameter::codec::functions::decodeAVP(subscriptionIdPtr, _id, _flags, _length, _dataG);
65 // Data is Fixed Subscription-Id-Type (Enumerated derived from Integer32) and then Fixed Subscription-Id-Data (UTF8String):
66 // No need to find Subscription-Id-Type, it's always the first:
67 diameter::codec::functions::decodeAVP(_dataG.c_str(), _id, _flags, _length, _data);
69 int type = DECODE4BYTES_INDX_VALUETYPE(_data, 0, int);
70 found = (type == subscriptionIdType);
74 // No need to find Subscription-Id-Data within _dataG, it's always the second, and the first takes always 3 words (no vendorID):
75 subscriptionIdDataPtr = _dataG.c_str() + 12;
76 diameter::codec::functions::decodeAVP(subscriptionIdDataPtr, _id, _flags, _length, result);
82 std::string anna::diameter::helpers::dcca::functions::getServiceContextId(const anna::DataBlock & db, ChargingContext::_v &chargingContext) throw(anna::RuntimeException) {
83 if(db.getSize() < Message::HeaderLength)
84 throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
86 //anna::DataBlock avpsDB(db.getData() + Message::HeaderLength, db.getSize() - Message::HeaderLength);
87 //const char * serviceContextIdPtr = anna::diameter::codec::functions::findAVP(avpsDB, AVPID__Service_Context_Id);
89 const char *avpsDB = db.getData() + Message::HeaderLength;
90 int avpsLen = db.getSize() - Message::HeaderLength;
91 const char * serviceContextIdPtr = anna::diameter::codec::functions::findAVP(avpsDB, avpsLen, AVPID__Service_Context_Id);
93 if(serviceContextIdPtr == NULL)
94 throw anna::RuntimeException("Service-Context-Id AVP not found in DataBlock provided", ANNA_FILE_LOCATION);
96 // Decoded avp information:
101 anna::diameter::codec::functions::decodeAVP(serviceContextIdPtr, _id, _flags, _length, result /* data-part */);
102 // Charging context detection:
103 chargingContext = ChargingContext::Unknown;
105 if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::Data))
106 chargingContext = ChargingContext::Data;
107 else if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::Voice))
108 chargingContext = ChargingContext::Voice;
109 else if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::Content))
110 chargingContext = ChargingContext::Content;
111 else if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::SMS))
112 chargingContext = ChargingContext::SMS;
113 else if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::MMS))
114 chargingContext = ChargingContext::MMS;
117 // future kind of traffic