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

Generated by: LCOV version 2.0-1