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 std::string result = "";
45 int pos = 1; // first avp
46 const char * subscriptionIdPtr;
47 const char * subscriptionIdDataPtr;
49 // Decoded avp information:
53 std::string _dataG /* grouped */, _data;
56 subscriptionIdPtr = diameter::codec::functions::findAVP(avpsDB, AVPID__Subscription_Id, pos);
58 if(!subscriptionIdPtr) return result;
61 diameter::codec::functions::decodeAVP(subscriptionIdPtr, _id, _flags, _length, _dataG);
62 // Data is Fixed Subscription-Id-Type (Enumerated derived from Integer32) and then Fixed Subscription-Id-Data (UTF8String):
63 // No need to find Subscription-Id-Type, it's always the first:
64 diameter::codec::functions::decodeAVP(_dataG.c_str(), _id, _flags, _length, _data);
66 int type = DECODE4BYTES_INDX_VALUETYPE(_data, 0, int);
67 found = (type == subscriptionIdType);
71 // No need to find Subscription-Id-Data within _dataG, it's always the second, and the first takes always 3 words (no vendorID):
72 subscriptionIdDataPtr = _dataG.c_str() + 12;
73 diameter::codec::functions::decodeAVP(subscriptionIdDataPtr, _id, _flags, _length, result);
79 std::string anna::diameter::helpers::dcca::functions::getServiceContextId(const anna::DataBlock & db, ChargingContext::_v &chargingContext) throw(anna::RuntimeException) {
80 if(db.getSize() < Message::HeaderLength)
81 throw anna::RuntimeException("Not enough bytes to cover command header length", ANNA_FILE_LOCATION);
83 anna::DataBlock avpsDB(db.getData() + Message::HeaderLength, db.getSize() - Message::HeaderLength);
84 const char * serviceContextIdPtr = anna::diameter::codec::functions::findAVP(avpsDB, AVPID__Service_Context_Id);
86 if(serviceContextIdPtr == NULL)
87 throw anna::RuntimeException("Service-Context-Id AVP not found in DataBlock provided", ANNA_FILE_LOCATION);
89 // Decoded avp information:
94 anna::diameter::codec::functions::decodeAVP(serviceContextIdPtr, _id, _flags, _length, result /* data-part */);
95 // Charging context detection:
96 chargingContext = ChargingContext::Unknown;
98 if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::Data))
99 chargingContext = ChargingContext::Data;
100 else if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::Voice))
101 chargingContext = ChargingContext::Voice;
102 else if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::Content))
103 chargingContext = ChargingContext::Content;
104 else if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::SMS))
105 chargingContext = ChargingContext::SMS;
106 else if(anna::functions::endsWith(result, ChargingContextAndDomainSuffix::MMS))
107 chargingContext = ChargingContext::MMS;
110 // future kind of traffic