LCOV - code coverage report
Current view: top level - stack - Command.cpp (source / functions) Coverage Total Hit
Test: final-coverage.info Lines: 36.7 % 30 11
Test Date: 2026-08-11 23:06:37 Functions: 66.7 % 3 2

            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/Command.hpp>
      42              : #include <ert/tracing/Logger.hpp>
      43              : 
      44              : namespace ert {
      45              : namespace diametercodec {
      46              : namespace stack {
      47              : 
      48        23798 : void Command::addAvpRule(const AvpRule& avpRule) {
      49        23798 :     if (avpRule.isFixed()) {
      50         1168 :         if (!allow_fixed_rule_) {
      51              :             std::string s_ex =
      52              :                 ert::tracing::Logger::asString("Incorrect position for fixed avp rule '<%s>' within command '%s'",
      53            0 :                                                avpRule.getAvpName().c_str(), getName().c_str());
      54            0 :             s_ex += ". Fixed avp rules must be located at the beginning";
      55            0 :             throw std::runtime_error(s_ex);
      56            0 :         }
      57              :     } else
      58        22630 :         allow_fixed_rule_ = false;
      59              : 
      60              :     // Restriction for redefinition (at this same level) of two rules for the same avp:
      61        23798 :     if (isChild(avpRule.getId())) {
      62              :         std::string s_ex =
      63              :             ert::tracing::Logger::asString("Cannot add two rules for avp '%s', at the same level within command '%s'",
      64            0 :                                            avpRule.getAvpName().c_str(), getName().c_str());
      65            0 :         throw std::runtime_error(s_ex);
      66            0 :     }
      67              : 
      68        23798 :     avprules_[avprule_position_++] = avpRule;
      69        23798 : }
      70              : 
      71        23798 : bool Command::isChild(const core::AvpId& avpId) const {
      72       178120 :     for (const auto& it : avprules_)
      73       154322 :         if (avpId == (it.second.getId())) return true;
      74              : 
      75        23798 :     return false;
      76              : }
      77              : 
      78            0 : nlohmann::json Command::asJson(void) const {
      79            0 :     nlohmann::json result;
      80              : 
      81            0 :     result["name"] = name_;
      82            0 :     result["code"] = id_.first;
      83            0 :     if (id_.second) result["r-bit"] = id_.second;
      84            0 :     if (p_bit_) result["p-bit"] = p_bit_;
      85            0 :     if (application_id_ != 0) result["application-id"] = application_id_;
      86              : 
      87              :     // Build avprule array
      88            0 :     nlohmann::json aux;
      89              : 
      90            0 :     for (const auto& it : avprules_) aux.push_back(it.second.asJson());
      91              : 
      92            0 :     result["avprule"] = aux;
      93              : 
      94            0 :     return result;
      95            0 : }
      96              : 
      97              : }  // namespace stack
      98              : }  // namespace diametercodec
      99              : }  // namespace ert
        

Generated by: LCOV version 2.0-1