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 //
12 #include <anna/xml/Node.hpp>
13 #include <anna/xml/Compiler.hpp>
14 #include <anna/diameter/defines.hpp>
15 #include <anna/diameter/codec/functions.hpp>
16 #include <anna/diameter/helpers/base/functions.hpp>
18 #include <anna/diameter/helpers/dcca/defines.hpp>
19 #include <anna/diameter/helpers/dcca/functions.hpp>
20 #include <anna/core/util/defines.hpp>
23 #include <TestCondition.hpp>
24 #include <Launcher.hpp>
27 const char* TestCondition::asText(const Type::_v type)
29 static const char* text [] = { "Generic", "Basic" };
33 bool TestCondition::exists() const throw() {
34 if (a_type == Type::Generic)
35 return (a_regexp != "");
37 return (a_code != "" || a_bitR != "" || a_resultCode != "" || a_sessionId != "" || a_hopByHop != "" || a_msisdn != "" || a_imsi != "" || a_serviceContextId != "");
40 bool operator==(const TestCondition &c1, const TestCondition &c2) throw() {
42 if (c1.a_type != c2.a_type) return false;
44 if (c1.a_type == TestCondition::Type::Generic) {
45 if (c1.a_regexp != c2.a_regexp) return false;
48 if (c1.a_code != c2.a_code) return false;
49 if (c1.a_bitR != c2.a_bitR) return false;
50 if (c1.a_resultCode != c2.a_resultCode) return false;
51 if (c1.a_sessionId != c2.a_sessionId) return false;
52 if (c1.a_hopByHop != c2.a_hopByHop) return false;
53 if (c1.a_msisdn != c2.a_msisdn) return false;
54 if (c1.a_imsi != c2.a_imsi) return false;
55 if (c1.a_serviceContextId != c2.a_serviceContextId) return false;
61 bool TestCondition::comply(const anna::DataBlock &message/*, bool matchSessionId*/) const throw() {
63 if (a_type == Type::Generic) {
64 Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
65 static anna::diameter::codec::Message codecMsg(my_app.getCodecEngine());
67 codecMsg.decode(message);
69 catch (anna::RuntimeException &ex) {
73 return codecMsg.isLike(a_regexp);
78 anna::diameter::CommandId cid;
80 if (a_code != "" || a_bitR != "") {
82 cid = anna::diameter::codec::functions::getCommandId(message);
84 catch (anna::RuntimeException &) { return false; }
88 compare = anna::functions::asString(cid.first);
89 if (a_code != compare) return false;
93 compare = (cid.first ? "1":"0");
94 if (a_bitR != compare) return false;
97 if (a_resultCode != "") {
99 anna::U32 rc = anna::diameter::helpers::base::functions::getResultCode(message);
100 compare = anna::functions::asString(rc);
102 catch (anna::RuntimeException &) { return false; }
103 if (a_resultCode != compare) return false;
106 //if (matchSessionId) {
107 if (a_sessionId != "") {
109 compare = anna::diameter::helpers::base::functions::getSessionId(message);
111 catch (anna::RuntimeException &) { return false; }
112 if (a_sessionId != compare) return false;
116 if (a_hopByHop != "") {
118 anna::diameter::HopByHop h = anna::diameter::codec::functions::getHopByHop(message);
119 compare = anna::functions::asString(h);
121 catch (anna::RuntimeException &) { return false; }
122 if (a_hopByHop != compare) return false;
125 if (a_msisdn != "") {
127 compare = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(message, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164);
129 catch (anna::RuntimeException &) { return false; }
130 if (a_msisdn != compare) return false;
135 compare = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(message, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI);
137 catch (anna::RuntimeException &) { return false; }
138 if (a_imsi != compare) return false;
141 if (a_serviceContextId != "") {
143 compare = anna::diameter::helpers::dcca::functions::getServiceContextId(message);
145 catch (anna::RuntimeException &) { return false; }
146 if (a_serviceContextId != compare) return false;
152 anna::xml::Node* TestCondition::asXML(anna::xml::Node* parent) const
154 anna::xml::Node* result = parent->createChild("TestCondition");
155 if (!exists()) return result;
157 if (a_type == Type::Generic) {
158 if (a_regexp != "") result->createAttribute("Regexp", a_regexp);
161 if (a_code != "") result->createAttribute("Code", atoi(a_code.c_str()));
162 if (a_bitR != "") result->createAttribute("BitR", ((a_bitR == "1") ? "yes":"no"));
163 if (a_sessionId != "") result->createAttribute("SessionId", a_sessionId);
164 if (a_resultCode != "") result->createAttribute("ResultCode", atoi(a_resultCode.c_str()));
165 if (a_hopByHop != "") result->createAttribute("HopByHop", atoll(a_hopByHop.c_str()));
166 if (a_msisdn != "") result->createAttribute("Msisdn", a_msisdn);
167 if (a_imsi != "") result->createAttribute("Imsi", a_imsi);
168 if (a_serviceContextId != "") result->createAttribute("ServiceContextId", a_serviceContextId);
171 result->createAttribute("ExpectedSource", a_rcvFromEntity ? "entity":"client");