Line data Source code
1 : /*
2 : ________________________________________________________________________
3 : | |
4 : | _ _ _ _ |
5 : | | (_) | | | | |
6 : | __| |_ __ _ _ __ ___ ___| |_ ___ _ __ ___ ___ __| | ___ ___ |
7 : | / _` | |/ _` | '_ ` _ \ / _ \ __/ _ \ '__/ __/ _ \ / _` |/ _ \/ __| |
8 : | | (_| | | (_| | | | | | | __/ || __/ | | (_| (_) | (_| | __/ (__ |
9 : | \__,_|_|\__,_|_| |_| |_|\___|\__\___|_| \___\___/ \__,_|\___|\___| |
10 : | |
11 : |________________________________________________________________________|
12 :
13 : C++ CODEC FOR DIAMETER PROTOCOL (RFC 6733)
14 : Version 0.0.z
15 : https://github.com/testillano/diametercodec
16 :
17 : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
18 : SPDX-License-Identifier: MIT
19 : Copyright (c) 2021 Eduardo Ramos
20 :
21 : Permission is hereby granted, free of charge, to any person obtaining a copy
22 : of this software and associated documentation files (the "Software"), to deal
23 : in the Software without restriction, including without limitation the rights
24 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25 : copies of the Software, and to permit persons to whom the Software is
26 : furnished to do so, subject to the following conditions:
27 :
28 : The above copyright notice and this permission notice shall be included in all
29 : copies or substantial portions of the Software.
30 :
31 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 : SOFTWARE.
38 : */
39 :
40 : // Project
41 : #include <ert/diametercodec/stack/Dictionary.hpp>
42 : #include <ert/diametercodec/stack/Format.hpp>
43 :
44 : namespace ert {
45 : namespace diametercodec {
46 : namespace stack {
47 :
48 : assign_enum(Format::Type) = {
49 : "Unknown", "Any", "OctetString", "Integer32", "Integer64", "Unsigned32", "Unsigned64",
50 : "Float32", "Float64", "Grouped", "Address", "Time", "UTF8String", "DiameterIdentity",
51 : "DiameterURI", "Enumerated", "IPFilterRule", "QoSFilterRule", nullptr /* list end indicator */};
52 :
53 0 : nlohmann::json Format::asJson(void) const {
54 0 : nlohmann::json result;
55 :
56 0 : result["name"] = name_;
57 0 : if (!parent_name_.empty()) result["parent-type"] = parent_name_;
58 :
59 0 : return result;
60 0 : }
61 :
62 0 : Format::Type::_v Format::getBasicType(void) const {
63 0 : if (isDerived()) return dictionary_->getFormat(parent_name_)->getBasicType();
64 0 : if (isReserved()) throw std::runtime_error("Develop error: there is no basic format type for reserved type");
65 :
66 0 : return (Format::Type::asEnum(name_));
67 : }
68 :
69 1168 : void Format::setParentName(const std::string& parentName) {
70 1168 : const Format* parent = dictionary_->getFormat(parentName);
71 1168 : if (parent && !parent->isBasic()) // 'Any' should not be allowed
72 0 : throw std::runtime_error("Only basic diameter format allowed for parent type");
73 :
74 1168 : parent_name_ = parentName;
75 1168 : }
76 :
77 : } // namespace stack
78 : } // namespace diametercodec
79 : } // namespace ert
|