TokenReader.cpp

Go to the documentation of this file.
00001 /*
00002 *
00003 *
00004 * Distributed under the OpenDDS License.
00005 * See: http://www.OpenDDS.org/license.html
00006 */
00007 
00008 #include "dds/DCPS/security/TokenReader.h"
00009 #include "dds/DCPS/SequenceIterator.h"
00010 #include <algorithm>
00011 
00012 using namespace OpenDDS::DCPS;
00013 
00014 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 namespace OpenDDS {
00017 namespace Security {
00018 
00019 template<typename PropType>
00020 struct has_property
00021 {
00022   has_property(const std::string& name) : name_(name) {}
00023 
00024   bool operator() (const PropType& property)
00025   {
00026     return (0 == name_.compare(property.name));
00027   }
00028 
00029 private:
00030   const std::string& name_;
00031 };
00032 
00033 TokenReader::TokenReader(const DDS::Security::Token& token_ref)
00034 : token_ref_(token_ref)
00035 , _empty_seq_()
00036 {
00037 }
00038 
00039 TokenReader::~TokenReader()
00040 {
00041 }
00042 
00043 const char* TokenReader::get_property_value(const std::string& property_name) const
00044 {
00045   typedef ConstSequenceIterator<const DDS::PropertySeq> iter_t;
00046   typedef has_property<const DDS::Property_t> has_property;
00047 
00048   iter_t begin = const_sequence_begin(token_ref_.properties),
00049          end = const_sequence_end(token_ref_.properties);
00050 
00051   iter_t result = std::find_if(begin, end, has_property(property_name));
00052 
00053   if (result != end) {
00054     return result->value;
00055   }
00056 
00057   return 0;
00058 }
00059 
00060 const DDS::OctetSeq& TokenReader::get_bin_property_value(const std::string& property_name) const
00061 {
00062   typedef ConstSequenceIterator<const DDS::BinaryPropertySeq> iter_t;
00063   typedef has_property<const DDS::BinaryProperty_t> has_property;
00064 
00065   iter_t begin = const_sequence_begin(token_ref_.binary_properties),
00066          end = const_sequence_end(token_ref_.binary_properties);
00067 
00068   iter_t result = std::find_if(begin, end, has_property(property_name));
00069 
00070   if (result != end) {
00071     return result->value;
00072   }
00073 
00074   return _empty_seq_;
00075 }
00076 
00077 } // namespace Security
00078 } // namespace OpenDDS
00079 
00080 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1