OpenDDS  Snapshot(2023/04/28-20:55)
HandleRegistry.cpp
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #include <DCPS/DdsDcps_pch.h> //Only the _pch include should start with DCPS/
7 
8 #ifdef OPENDDS_SECURITY
9 
10 #include "HandleRegistry.h"
11 
12 #include <dds/DCPS/debug.h>
13 #include <dds/DCPS/GuidConverter.h>
14 
16 
17 namespace OpenDDS {
18 namespace Security {
19 
21 {
30 }
31 
33 {
34  if (DCPS::security_debug.bookkeeping) {
35  ACE_DEBUG((LM_DEBUG, "(%P|%t) {bookkeeping} "
36  "HandleRegistry::~HandleRegistry local datareader %B local datawriter %B "
37  "remote participant %B remote datareader %B remote datawriter %B\n",
43  }
44 }
45 
46 void
50 {
51  if (handle != DDS::HANDLE_NIL) {
53  local_datareader_crypto_handles_[id] = std::make_pair(handle, attributes);
54 
55  if (DCPS::security_debug.bookkeeping) {
56  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
57  ACE_TEXT("HandleRegistry::insert_local_datareader_crypto_handle %C %d (total %B)\n"),
58  DCPS::LogGuid(id).c_str(),
59  handle,
61  }
62  }
63 }
64 
67 {
69  DatareaderCryptoHandleMap::const_iterator pos = local_datareader_crypto_handles_.find(id);
70  if (pos != local_datareader_crypto_handles_.end()) {
71  return pos->second.first;
72  }
73  return DDS::HANDLE_NIL;
74 }
75 
78 {
80  DatareaderCryptoHandleMap::const_iterator pos = local_datareader_crypto_handles_.find(id);
81  if (pos != local_datareader_crypto_handles_.end()) {
82  return pos->second.second;
83  }
85 }
86 
87 void
89 {
92 
93  if (DCPS::security_debug.bookkeeping) {
94  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
95  ACE_TEXT("HandleRegistry::erase_local_datareader_crypto_handle %C (%B)\n"),
96  DCPS::LogGuid(id).c_str(),
98  }
99 }
100 
101 void
105 {
106  if (handle != DDS::HANDLE_NIL) {
108  local_datawriter_crypto_handles_[id] = std::make_pair(handle, attributes);
109 
110  if (DCPS::security_debug.bookkeeping) {
111  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
112  ACE_TEXT("HandleRegistry::insert_local_datawriter_crypto_handle %C %d (total %B)\n"),
113  DCPS::LogGuid(id).c_str(),
114  handle,
116  }
117  }
118 }
119 
122 {
124  DatawriterCryptoHandleMap::const_iterator pos = local_datawriter_crypto_handles_.find(id);
125  if (pos != local_datawriter_crypto_handles_.end()) {
126  return pos->second.first;
127  }
128  return DDS::HANDLE_NIL;
129 }
130 
133 {
135  DatawriterCryptoHandleMap::const_iterator pos = local_datawriter_crypto_handles_.find(id);
136  if (pos != local_datawriter_crypto_handles_.end()) {
137  return pos->second.second;
138  }
140 }
141 
142 void
144 {
147 
148  if (DCPS::security_debug.bookkeeping) {
149  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
150  ACE_TEXT("HandleRegistry::erase_local_datawriter_crypto_handle %C (total %B)\n"),
151  DCPS::LogGuid(id).c_str(),
153  }
154 }
155 
156 void
159 {
160  if (handle != DDS::HANDLE_NIL) {
163 
164  if (DCPS::security_debug.bookkeeping) {
165  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
166  ACE_TEXT("HandleRegistry::insert_remote_participant_crypto_handle %C %d (total %B)\n"),
167  DCPS::LogGuid(id).c_str(),
168  handle,
170  }
171  }
172 }
173 
176 {
178  ParticipantCryptoHandleMap::const_iterator pos = remote_participant_crypto_handles_.find(id);
179  if (pos != remote_participant_crypto_handles_.end()) {
180  return pos->second;
181  }
182  return DDS::HANDLE_NIL;
183 }
184 
185 void
187 {
190 
191  if (DCPS::security_debug.bookkeeping) {
192  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
193  ACE_TEXT("HandleRegistry::erase_remote_participant_crypto_handle %C (total %B)\n"),
194  DCPS::LogGuid(id).c_str(),
196  }
197 }
198 
199 void
202 {
203  if (handle != DDS::HANDLE_NIL) {
206 
207  if (DCPS::security_debug.bookkeeping) {
208  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
209  ACE_TEXT("HandleRegistry::insert_remote_participant_permissions_handle %C %d (total %B)\n"),
210  DCPS::LogGuid(id).c_str(),
211  handle,
213  }
214  }
215 }
216 
219 {
221  PermissionsHandleMap::const_iterator pos = remote_participant_permissions_handles_.find(id);
222  if (pos != remote_participant_permissions_handles_.end()) {
223  return pos->second;
224  }
225  return DDS::HANDLE_NIL;
226 }
227 
228 void
230 {
233 
234  if (DCPS::security_debug.bookkeeping) {
235  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
236  ACE_TEXT("HandleRegistry::erase_remote_participant_permissions_handle %C (total %B)\n"),
237  DCPS::LogGuid(id).c_str(),
239  }
240 }
241 
242 void
246 {
247  if (handle != DDS::HANDLE_NIL) {
249  remote_datareader_crypto_handles_[id] = std::make_pair(handle, attributes);
250  }
251 
252  if (DCPS::security_debug.bookkeeping) {
253  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
254  ACE_TEXT("HandleRegistry::insert_remote_datareader_crypto_handle %C %d (total %B)\n"),
255  DCPS::LogGuid(id).c_str(),
256  handle,
258  }
259 }
260 
263 {
265  DatareaderCryptoHandleMap::const_iterator pos = remote_datareader_crypto_handles_.find(id);
266  if (pos != remote_datareader_crypto_handles_.end()) {
267  return pos->second.first;
268  }
269  return DDS::HANDLE_NIL;
270 }
271 
274 {
276  DatareaderCryptoHandleMap::const_iterator pos = remote_datareader_crypto_handles_.find(id);
277  if (pos != remote_datareader_crypto_handles_.end()) {
278  return pos->second.second;
279  }
281 }
282 
283 HandleRegistry::DatareaderCryptoHandleList
285 {
286  DatareaderCryptoHandleList retval;
287  ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, retval);
288  for (DatareaderCryptoHandleMap::const_iterator pos =
290  limit = remote_datareader_crypto_handles_.end();
291  pos != limit && DCPS::equal_guid_prefixes(pos->first, prefix); ++pos) {
292  retval.push_back(std::make_pair(pos->first, pos->second.first));
293  }
294  return retval;
295 }
296 
297 void
299 {
302 
303  if (DCPS::security_debug.bookkeeping) {
304  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
305  ACE_TEXT("HandleRegistry::erase_remote_datareader_crypto_handle %C (total %B)\n"),
306  DCPS::LogGuid(id).c_str(),
308  }
309 }
310 
311 void
315 {
316  OPENDDS_ASSERT(id.entityId != DCPS::ENTITYID_UNKNOWN);
317  if (handle != DDS::HANDLE_NIL) {
319  remote_datawriter_crypto_handles_[id] = std::make_pair(handle, attributes);
320 
321  if (DCPS::security_debug.bookkeeping) {
322  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
323  ACE_TEXT("HandleRegistry::insert_remote_datawriter_crypto_handle %C %d (total %B)\n"),
324  DCPS::LogGuid(id).c_str(),
325  handle,
327  }
328  }
329 }
330 
333 {
335  DatawriterCryptoHandleMap::const_iterator pos = remote_datawriter_crypto_handles_.find(id);
336  if (pos != remote_datawriter_crypto_handles_.end()) {
337  return pos->second.first;
338  }
339  return DDS::HANDLE_NIL;
340 }
341 
344 {
346  DatawriterCryptoHandleMap::const_iterator pos = remote_datawriter_crypto_handles_.find(id);
347  if (pos != remote_datawriter_crypto_handles_.end()) {
348  return pos->second.second;
349  }
351 }
352 
353 HandleRegistry::DatawriterCryptoHandleList
355 {
356  DatawriterCryptoHandleList retval;
357  ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, mutex_, retval);
358  for (DatawriterCryptoHandleMap::const_iterator pos =
360  limit = remote_datawriter_crypto_handles_.end();
361  pos != limit && DCPS::equal_guid_prefixes(pos->first, prefix); ++pos) {
362  retval.push_back(std::make_pair(pos->first, pos->second.first));
363  }
364  return retval;
365 }
366 
367 void
369 {
372 
373  if (DCPS::security_debug.bookkeeping) {
374  ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) {bookkeeping} ")
375  ACE_TEXT("HandleRegistry::erase_remote_datawriter_crypto_handle %C (total %B)\n"),
376  DCPS::LogGuid(id).c_str(),
378  }
379 }
380 
381 } // Security
382 } // OpenDDS
383 
385 
386 #endif // OPENDDS_SECURITY
#define ACE_DEBUG(X)
void insert_local_datawriter_crypto_handle(const DCPS::GUID_t &id, DDS::Security::DatawriterCryptoHandle handle, const DDS::Security::EndpointSecurityAttributes &attributes)
const DDS::Security::EndpointSecurityAttributes & get_local_datareader_security_attributes(const DCPS::GUID_t &id) const
DDS::Security::EndpointSecurityAttributes default_endpoint_security_attributes_
#define ACE_GUARD(MUTEX, OBJ, LOCK)
void insert_remote_datawriter_crypto_handle(const DCPS::GUID_t &id, DDS::Security::DatawriterCryptoHandle handle, const DDS::Security::EndpointSecurityAttributes &attributes)
void insert_remote_datareader_crypto_handle(const DCPS::GUID_t &id, DDS::Security::DatareaderCryptoHandle handle, const DDS::Security::EndpointSecurityAttributes &attributes)
const InstanceHandle_t HANDLE_NIL
DDS::Security::DatawriterCryptoHandle get_local_datawriter_crypto_handle(const DCPS::GUID_t &id) const
DDS::Security::DatareaderCryptoHandle get_local_datareader_crypto_handle(const DCPS::GUID_t &id) const
PermissionsHandleMap remote_participant_permissions_handles_
const DDS::Security::EndpointSecurityAttributes & get_remote_datareader_security_attributes(const DCPS::GUID_t &id) const
#define OPENDDS_ASSERT(C)
Definition: Definitions.h:72
void insert_remote_participant_crypto_handle(const DCPS::GUID_t &id, DDS::Security::ParticipantCryptoHandle handle)
PluginEndpointSecurityAttributesMask plugin_endpoint_attributes
void erase_remote_participant_permissions_handle(const DCPS::GUID_t &id)
LM_DEBUG
NativeCryptoHandle DatawriterCryptoHandle
const DDS::Security::EndpointSecurityAttributes & get_remote_datawriter_security_attributes(const DCPS::GUID_t &id) const
DatawriterCryptoHandleMap local_datawriter_crypto_handles_
#define ACE_GUARD_RETURN(MUTEX, OBJ, LOCK, RETURN)
NativeCryptoHandle DatareaderCryptoHandle
void insert_local_datareader_crypto_handle(const DCPS::GUID_t &id, DDS::Security::DatareaderCryptoHandle handle, const DDS::Security::EndpointSecurityAttributes &attributes)
void erase_remote_participant_crypto_handle(const DCPS::GUID_t &id)
DDS::Security::ParticipantCryptoHandle get_remote_participant_crypto_handle(const DCPS::GUID_t &id) const
ACE_TEXT("TCP_Factory")
void erase_local_datawriter_crypto_handle(const DCPS::GUID_t &id)
void erase_remote_datawriter_crypto_handle(const DCPS::GUID_t &id)
OpenDDS_Dcps_Export bool equal_guid_prefixes(const GuidPrefix_t &lhs, const GuidPrefix_t &rhs)
Definition: GuidUtils.h:132
DatawriterCryptoHandleMap remote_datawriter_crypto_handles_
DDS::Security::PermissionsHandle get_remote_participant_permissions_handle(const DCPS::GUID_t &id) const
DatareaderCryptoHandleMap remote_datareader_crypto_handles_
DatareaderCryptoHandleList get_all_remote_datareaders(const DCPS::GUID_t &prefix) const
DDS::Security::DatawriterCryptoHandle get_remote_datawriter_crypto_handle(const DCPS::GUID_t &id) const
DDS::Security::DatareaderCryptoHandle get_remote_datareader_crypto_handle(const DCPS::GUID_t &id) const
void insert_remote_participant_permissions_handle(const DCPS::GUID_t &id, DDS::Security::PermissionsHandle handle)
DatareaderCryptoHandleMap local_datareader_crypto_handles_
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
const DDS::Security::EndpointSecurityAttributes & get_local_datawriter_security_attributes(const DCPS::GUID_t &id) const
ParticipantCryptoHandleMap remote_participant_crypto_handles_
GUID_t make_id(const GuidPrefix_t &prefix, const EntityId_t &entity)
Definition: GuidUtils.h:200
DatawriterCryptoHandleList get_all_remote_datawriters(const DCPS::GUID_t &prefix) const
const EntityId_t ENTITYID_UNKNOWN
Definition: GuidUtils.h:36
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
void erase_remote_datareader_crypto_handle(const DCPS::GUID_t &id)
OpenDDS_Dcps_Export SecurityDebug security_debug
Definition: debug.cpp:32
void erase_local_datareader_crypto_handle(const DCPS::GUID_t &id)