binary_session.cpp
Go to the documentation of this file.
1 
11 #include "binary_serialization.h"
12 
15 #include <opc/ua/protocol/types.h>
17 
18 #include <algorithm>
19 #include <memory>
20 #include <string>
21 
22 namespace OpcUa
23 {
26 {
27 }
28 
31 {
32 }
33 
35 {
37 
38  if (Header.TypeId.FourByteData.Identifier == USER_IdENTIFY_TOKEN_USERNAME)
39  { type = UserTokenType::UserName; }
40 
41  return type;
42 }
43 
44 void UserIdentifyToken::setUser(const std::string & user, const std::string & password)
45 {
46  Header.TypeId.FourByteData.Identifier = USER_IdENTIFY_TOKEN_USERNAME;
47  UserName.UserName = user;
48  UserName.Password = password;
49  //UserName.EncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#rsa-oaep";
50 }
51 
53 {
54  int sz = id.length();
55  PolicyId.resize(sz);
56 
57  for (int i = 0; i < sz; i++)
58  {
59  PolicyId[i] = id[i];
60  }
61 }
62 
65  , DeleteSubscriptions(true)
66 {
67 }
68 
71 {
72 }
73 
74 namespace Binary
75 {
76 //---------------------------------------------------
77 // UserIdentifyToken
78 //---------------------------------------------------
79 
80 template<>
81 std::size_t RawSize<UserIdentifyToken::UserNameStruct>(const UserIdentifyToken::UserNameStruct & uname)
82 {
83  return RawSize(uname.UserName) + RawSize(uname.Password) + RawSize(uname.EncryptionAlgorithm);
84 }
85 
86 template<>
87 void DataSerializer::Serialize<UserIdentifyToken::UserNameStruct>(const UserIdentifyToken::UserNameStruct & uname)
88 {
89  *this << uname.UserName;
90  *this << uname.Password;
91  *this << uname.EncryptionAlgorithm;
92 }
93 
94 template<>
95 void DataDeserializer::Deserialize<UserIdentifyToken::UserNameStruct>(UserIdentifyToken::UserNameStruct & uname)
96 {
97  *this >> uname.UserName;
98  *this >> uname.Password;
99  *this >> uname.EncryptionAlgorithm;
100 }
101 
102 template<>
104 {
105  std::size_t ret = RawSize(token.Header) + RawSize(token.PolicyId) + RawSize((uint32_t)0);
106 
107  if (token.type() == UserTokenType::UserName)
108  { ret += RawSize(token.UserName); }
109 
110  return ret;
111 }
112 
113 template<>
114 void DataSerializer::Serialize<UserIdentifyToken>(const UserIdentifyToken & token)
115 {
116  *this << token.Header;
117  *this << int32_t(RawSize(token) - RawSize(token.Header) - RawSize((uint32_t)0));
118  *this << token.PolicyId;
119 
120  if (token.type() == UserTokenType::UserName)
121  { *this << token.UserName; }
122 }
123 
124 template<>
125 void DataDeserializer::Deserialize<UserIdentifyToken>(UserIdentifyToken & token)
126 {
127  *this >> token.Header;
128  int32_t tmp;
129  *this >> tmp;
130  *this >> token.PolicyId;
131 
132  if (token.type() == UserTokenType::UserName)
133  { *this >> token.UserName; }
134 }
135 
136 //---------------------------------------------------
137 // CloseSessionRequest
138 //---------------------------------------------------
139 
140 template<>
142 {
143  return RawSize(request.TypeId) + RawSize(request.Header) +
144  RawSize(request.DeleteSubscriptions);
145 }
146 
147 template<>
148 void DataSerializer::Serialize<CloseSessionRequest>(const CloseSessionRequest & request)
149 {
150  *this << request.TypeId;
151  *this << request.Header;
152 
153  *this << request.DeleteSubscriptions;
154 }
155 
156 template<>
157 void DataDeserializer::Deserialize<CloseSessionRequest>(CloseSessionRequest & request)
158 {
159  *this >> request.TypeId;
160  *this >> request.Header;
161 
162  *this >> request.DeleteSubscriptions;
163 }
164 
165 //---------------------------------------------------
166 // CloseSessionResponse
167 //---------------------------------------------------
168 
169 template<>
171 {
172  return RawSize(response.TypeId) + RawSize(response.Header);
173 }
174 
175 template<>
176 void DataSerializer::Serialize<CloseSessionResponse>(const CloseSessionResponse & response)
177 {
178  *this << response.TypeId;
179  *this << response.Header;
180 }
181 
182 template<>
183 void DataDeserializer::Deserialize<CloseSessionResponse>(CloseSessionResponse & response)
184 {
185  *this >> response.TypeId;
186  *this >> response.Header;
187 }
188 
189 //---------------------------------------------------
190 // ServiceFaultResponse
191 //---------------------------------------------------
192 
193 template<>
195 {
196  return RawSize(request.TypeId) + RawSize(request.Header);
197 }
198 
199 template<>
200 void DataSerializer::Serialize<ServiceFaultResponse>(const ServiceFaultResponse & request)
201 {
202  *this << request.TypeId;
203  *this << request.Header;
204 }
205 
206 template<>
207 void DataDeserializer::Deserialize<ServiceFaultResponse>(ServiceFaultResponse & request)
208 {
209  *this >> request.TypeId;
210  *this >> request.Header;
211 }
212 
213 
214 } // namespace Binary
215 } // namespace OpcUa
216 
std::size_t RawSize< UserIdentifyToken >(const UserIdentifyToken &token)
void setUser(const std::string &user, const std::string &password)
std::size_t RawSize< ServiceFaultResponse >(const ServiceFaultResponse &request)
std::size_t RawSize< CloseSessionRequest >(const CloseSessionRequest &request)
std::size_t RawSize< CloseSessionResponse >(const CloseSessionResponse &response)
std::vector< uint8_t > PolicyId
Definition: types_manual.h:22
Moved from session.h.
Definition: types_manual.h:19
OPC UA Address space part. GNU LGPL.
const char * Binary(const char *input, short n)
UserTokenType
Definition: enums.h:80
void setPolicyId(const std::string &id)
UserTokenType type() const
struct OpcUa::UserIdentifyToken::UserNameStruct UserName
std::size_t RawSize(const T &obj)


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:04