OpenDDS  Snapshot(2023/04/28-20:55)
debug.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 #include "debug.h"
9 #include "Util.h"
10 
11 #ifdef OPENDDS_SECURITY
12 #include "PoolAllocator.h"
13 #endif
14 
15 #include <ace/Log_Msg.h>
16 
17 #include <cstring>
18 
20 
21 namespace OpenDDS {
22 namespace DCPS {
23 
24 #ifndef OPENDDS_UTIL_BUILD
27 #endif
28 
31 #ifdef OPENDDS_SECURITY
33 #endif
34 
36 {
37  level_ = value;
38 #ifdef OPENDDS_SECURITY
39  if (level_ >= Notice) {
40  security_debug.set_debug_level(1);
41  } else {
42  security_debug.set_all_flags_to(false);
43  }
44 #endif
45  if (level_ >= Debug) {
46  if (DCPS_debug_level == 0) {
47  DCPS_debug_level = 1;
48  }
49  } else {
50  DCPS_debug_level = 0;
51 #ifndef OPENDDS_UTIL_BUILD
52  Transport_debug_level = 0;
53  transport_debug = TransportDebug();
54 #endif
55  }
56 }
57 
58 namespace {
59  struct LogLevelNameValue {
60  const char* const name;
62  };
63  static const LogLevelNameValue log_levels[] = {
64  {"none", LogLevel::None},
65  {"error", LogLevel::Error},
66  {"warning", LogLevel::Warning},
67  {"notice", LogLevel::Notice},
68  {"info", LogLevel::Info},
69  {"debug", LogLevel::Debug}
70  };
71 };
72 
74 {
75  for (size_t i = 0; i < array_count(log_levels); ++i) {
76  if (!std::strcmp(log_levels[i].name, name)) {
77  set(log_levels[i].value);
78  return;
79  }
80  }
81  if (log_level >= Warning) {
82  ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: LogLevel::set_from_string: "
83  "Invalid log level name: %C\n", name));
84  }
85 }
86 
87 const char* LogLevel::get_as_string() const
88 {
89  const unsigned index = static_cast<unsigned>(get());
90  if (index >= array_count(log_levels)) {
91  ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: LogLevel::get_as_string: "
92  "Invalid log level value: %u\n", index));
93  return "invalid";
94  }
95  return log_levels[index].name;
96 }
97 
99 {
100  if (log_level.get() < LogLevel::Debug) {
102  }
103  if (log_level >= LogLevel::Info) {
104  ACE_DEBUG((LM_INFO, "(%P|%t) INFO: set_DCPS_debug_level: set to %u\n", lvl));
105  }
106  DCPS_debug_level = lvl;
107 }
108 
109 #ifdef OPENDDS_SECURITY
111  : fake_encryption(false)
112  , force_auth_role(FORCE_AUTH_ROLE_NORMAL)
113 {
114  set_all_flags_to(false);
115 }
116 
118 {
120  encdec_warn = value;
122  auth_debug = value;
123  auth_warn = value;
128  access_warn = value;
129  bookkeeping = value;
130  showkeys = value;
131  chlookup = value;
132 }
133 
135 {
136  String s(ACE_TEXT_ALWAYS_CHAR(flags));
137  const String delim(",");
138  while (true) {
139  const size_t pos = s.find(delim);
140  const String flag = s.substr(0, pos);
141  if (flag.length()) {
142  if (flag == "all") {
143  set_all_flags_to(true);
144  } else if (flag == "encdec_error") {
145  encdec_error = true;
146  } else if (flag == "encdec_warn") {
147  encdec_warn = true;
148  } else if (flag == "encdec_debug") {
149  encdec_debug = true;
150  } else if (flag == "auth_debug") {
151  auth_debug = true;
152  } else if (flag == "auth_warn") {
153  auth_warn = true;
154  } else if (flag == "new_entity_error") {
155  new_entity_error = true;
156  } else if (flag == "new_entity_warn") {
157  new_entity_warn = true;
158  } else if (flag == "cleanup_error") {
159  cleanup_error = true;
160  } else if (flag == "access_error") {
161  access_error = true;
162  } else if (flag == "access_warn") {
163  access_warn = true;
164  } else if (flag == "bookkeeping") {
165  bookkeeping = true;
166  } else if (flag == "showkeys") {
167  showkeys = true;
168  } else if (flag == "chlookup") {
169  chlookup = true;
170  } else if (log_level >= LogLevel::Warning) {
171  ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: SecurityDebug::parse_flags: "
172  "Unknown Security Debug Category: \"%C\"\n", flag.c_str()));
173  }
174  }
175  if (pos == String::npos) {
176  break;
177  }
178  s.erase(0, pos + delim.length());
179  }
180 }
181 
182 void SecurityDebug::set_debug_level(unsigned level)
183 {
185  access_warn = level >= 2;
186  auth_warn = encdec_error = level >= 3;
187  new_entity_warn = level >= 3;
188  auth_debug = encdec_warn = bookkeeping = level >= 4;
189  encdec_debug = level >= 8;
190  showkeys = level >= 9;
191  chlookup = level >= 10;
192 }
193 #endif
194 
195 } // namespace DCPS
196 } // namespace OpenDDS
197 
#define ACE_DEBUG(X)
void set_all_flags_to(bool value)
Set all security debug message flags to this value.
Definition: debug.cpp:117
void set_from_string(const char *name)
Definition: debug.cpp:73
#define ACE_ERROR(X)
const LogLevel::Value value
Definition: debug.cpp:61
std::string String
bool chlookup
Print Verbose Search Info About Getting the Crypto Handle from a Key id.
Definition: debug.h:142
LM_INFO
OpenDDS_Dcps_Export TransportDebug transport_debug
Definition: debug.cpp:26
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
size_t array_count(Type(&)[count])
Definition: Util.h:221
#define ACE_TEXT_ALWAYS_CHAR(STRING)
bool auth_debug
Authentication and Handshake.
Definition: debug.h:121
bool cleanup_error
Cleanup.
Definition: debug.h:129
Value get() const
Definition: debug.h:50
bool access_error
Permissions and Governance.
Definition: debug.h:132
OpenDDS_Dcps_Export unsigned int Transport_debug_level
Transport Logging verbosity level.
Definition: debug.cpp:25
OpenDDS_Dcps_Export void set_DCPS_debug_level(unsigned int lvl)
Definition: debug.cpp:98
char ACE_TCHAR
void parse_flags(const ACE_TCHAR *flags)
Definition: debug.cpp:134
bool bookkeeping
Generation and Tracking of Crypto Handles and Keys.
Definition: debug.h:136
LM_WARNING
const char *const name
Definition: debug.cpp:60
OpenDDS_Dcps_Export unsigned int DCPS_debug_level
Definition: debug.cpp:30
OpenDDS_Dcps_Export LogLevel log_level
void set_debug_level(unsigned level)
Definition: debug.cpp:182
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
bool showkeys
Print the Key when Generating it or Using It.
Definition: debug.h:139
bool new_entity_error
New entity creating.
Definition: debug.h:125
const char * get_as_string() const
Definition: debug.cpp:87
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
void set(Value value)
Definition: debug.cpp:35
OpenDDS_Dcps_Export SecurityDebug security_debug
Definition: debug.cpp:32