TokenWriter.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "dds/DCPS/security/TokenWriter.h"
00008 #include <cstring>
00009 #include <sstream>
00010
00011 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00012
00013 namespace OpenDDS {
00014 namespace Security {
00015
00016 TokenWriter::TokenWriter(DDS::Security::Token& token_ref)
00017 : binary_property_inserter_(token_ref.binary_properties)
00018 , property_inserter_(token_ref.properties)
00019 , token_ref_(token_ref)
00020 , reader_(token_ref)
00021 {
00022
00023 }
00024
00025 TokenWriter::TokenWriter(DDS::Security::Token& token_ref, const std::string& class_id)
00026 : binary_property_inserter_(token_ref.binary_properties)
00027 , property_inserter_(token_ref.properties)
00028 , token_ref_(token_ref)
00029 , reader_(token_ref)
00030 {
00031 token_ref.class_id = class_id.c_str();
00032 }
00033
00034 TokenWriter::~TokenWriter()
00035 {
00036 }
00037
00038 void TokenWriter::add_property(const char* prop_name, const char* prop_value, bool propagate)
00039 {
00040 DDS::Property_t p;
00041 p.name = prop_name;
00042 p.value = prop_value;
00043 p.propagate = propagate;
00044 *property_inserter_ = p;
00045 }
00046
00047 void TokenWriter::add_property(const char* prop_name, const DDS::OctetSeq& prop_value, bool propagate)
00048 {
00049 std::ostringstream out;
00050 out.write(reinterpret_cast<const char*>(prop_value.get_buffer()), prop_value.length());
00051
00052 DDS::Property_t p;
00053 p.name = prop_name;
00054 p.value = out.str().c_str();
00055 p.propagate = propagate;
00056 *property_inserter_ = p;
00057 }
00058
00059 void TokenWriter::add_bin_property(const char* prop_name, const DDS::OctetSeq& prop_value, bool propagate)
00060 {
00061 DDS::BinaryProperty_t p;
00062 p.name = prop_name;
00063 p.value = prop_value;
00064 p.propagate = propagate;
00065 *binary_property_inserter_ = p;
00066 }
00067
00068 void TokenWriter::add_bin_property(const char* prop_name, const std::string& prop_value, bool propagate)
00069 {
00070 DDS::BinaryProperty_t p;
00071 p.name = prop_name;
00072 p.propagate = propagate;
00073 p.value.length(prop_value.length() + 1 );
00074 std::memcpy(p.value.get_buffer(),
00075 prop_value.c_str(),
00076 p.value.length());
00077 *binary_property_inserter_ = p;
00078 }
00079
00080 }
00081 }
00082
00083 OPENDDS_END_VERSIONED_NAMESPACE_DECL