LCOV - code coverage report
Current view: top level - DCPS/security - TokenReader.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 23 95.7 %
Date: 2023-04-30 01:32:43 Functions: 8 9 88.9 %

          Line data    Source code
       1             : /*
       2             : *
       3             : *
       4             : * Distributed under the OpenDDS License.
       5             : * See: http://www.OpenDDS.org/license.html
       6             : */
       7             : 
       8             : #include "TokenReader.h"
       9             : #include "dds/DCPS/SequenceIterator.h"
      10             : #include <algorithm>
      11             : 
      12             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      13             : using namespace OpenDDS::DCPS;
      14             : 
      15             : namespace OpenDDS {
      16             : namespace Security {
      17             : 
      18             : template<typename PropType>
      19             : struct has_property
      20             : {
      21         191 :   has_property(const std::string& name) : name_(name) {}
      22             : 
      23         665 :   bool operator() (const PropType& property)
      24             :   {
      25         665 :     return (0 == name_.compare(property.name));
      26             :   }
      27             : 
      28             : private:
      29             :   const std::string& name_;
      30             : };
      31             : 
      32         275 : TokenReader::TokenReader(const DDS::Security::Token& token_ref)
      33         275 : : token_ref_(token_ref)
      34         275 : , _empty_seq_()
      35             : {
      36         275 : }
      37             : 
      38         275 : TokenReader::~TokenReader()
      39             : {
      40         275 : }
      41             : 
      42          24 : const char* TokenReader::get_property_value(const std::string& property_name) const
      43             : {
      44             :   typedef ConstSequenceIterator<const DDS::PropertySeq> iter_t;
      45             :   typedef has_property<const DDS::Property_t> has_property;
      46             : 
      47          24 :   iter_t begin = const_sequence_begin(token_ref_.properties),
      48          24 :          end = const_sequence_end(token_ref_.properties);
      49             : 
      50          24 :   iter_t result = std::find_if(begin, end, has_property(property_name));
      51             : 
      52          24 :   if (result != end) {
      53          24 :     return result->value;
      54             :   }
      55             : 
      56           0 :   return 0;
      57             : }
      58             : 
      59         167 : const DDS::OctetSeq& TokenReader::get_bin_property_value(const std::string& property_name) const
      60             : {
      61             :   typedef ConstSequenceIterator<const DDS::BinaryPropertySeq> iter_t;
      62             :   typedef has_property<const DDS::BinaryProperty_t> has_property;
      63             : 
      64         167 :   iter_t begin = const_sequence_begin(token_ref_.binary_properties),
      65         167 :          end = const_sequence_end(token_ref_.binary_properties);
      66             : 
      67         167 :   iter_t result = std::find_if(begin, end, has_property(property_name));
      68             : 
      69         167 :   if (result != end) {
      70         166 :     return result->value;
      71             :   }
      72             : 
      73           1 :   return _empty_seq_;
      74             : }
      75             : 
      76             : } // namespace Security
      77             : } // namespace OpenDDS
      78             : 
      79             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16