Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/client/binary_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class BinaryClient
{
for (ReadValueId attr : params.AttributesToRead)
{
Logger->trace("binary_client | Read: node id: {} attr id: {}", attr.NodeId, ToString(attr.AttributeId));
Logger->trace("binary_client | Read: node id: {} attr id: {}", ToString(attr.NodeId), ToString(attr.AttributeId));
}
}

Expand Down Expand Up @@ -558,7 +558,7 @@ class BinaryClient
virtual std::vector<MonitoredItemCreateResult> CreateMonitoredItems(const MonitoredItemsParameters & parameters) override
{
LOG_DEBUG(Logger, "binary_client | CreateMonitoredItems -->");
LOG_TRACE(Logger, "binary_client | {}", parameters);
LOG_TRACE(Logger, "binary_client | {}", ToString(parameters));

CreateMonitoredItemsRequest request;
request.Parameters = parameters;
Expand Down Expand Up @@ -700,7 +700,7 @@ class BinaryClient
{
for (BrowseDescription desc : query.NodesToBrowse)
{
Logger->trace("Node: {}", desc.NodeToBrowse);
Logger->trace("Node: {}", ToString(desc.NodeToBrowse));
}
}

Expand Down Expand Up @@ -763,7 +763,7 @@ class BinaryClient

for (auto & param : params)
{
Logger->trace(" {}", param);
Logger->trace(" {}", ToString(param));
}
}

Expand All @@ -778,7 +778,7 @@ class BinaryClient

for (auto & id : response.Result)
{
Logger->trace(" {}", id);
Logger->trace(" {}", ToString(id));
}
}
LOG_DEBUG(Logger, "binary_client | RegisterNodes <--");
Expand All @@ -794,7 +794,7 @@ class BinaryClient

for (auto & id : params)
{
Logger->trace(" {}", id);
Logger->trace(" {}", ToString(id));
}
}

Expand Down Expand Up @@ -879,7 +879,7 @@ class BinaryClient
Callbacks.insert(std::make_pair(request.Header.RequestHandle, responseCallback));
lock.unlock();

LOG_DEBUG(Logger, "binary_client | send: id: {} handle: {}, UtcTime: {}", ToString(request.TypeId, true), request.Header.RequestHandle, request.Header.UtcTime);
LOG_DEBUG(Logger, "binary_client | send: id: {} handle: {}, UtcTime: {}", ToString(request.TypeId, true), request.Header.RequestHandle, ToString(request.Header.UtcTime));

Send(request);

Expand Down Expand Up @@ -928,7 +928,7 @@ class BinaryClient
{
Binary::SecureHeader responseHeader;
Stream >> responseHeader;
LOG_DEBUG(Logger, "binary_client | received message: Type: {}, ChunkType: {}, Size: {}, ChannelId: {}", responseHeader.Type, responseHeader.Chunk, responseHeader.Size, responseHeader.ChannelId);
LOG_DEBUG(Logger, "binary_client | received message: Type: {}, ChunkType: {}, Size: {}, ChannelId: {}", (uint32_t)responseHeader.Type, (uint32_t)responseHeader.Chunk, responseHeader.Size, responseHeader.ChannelId);

size_t algo_size;

Expand Down Expand Up @@ -982,7 +982,7 @@ class BinaryClient

if (callbackIt == Callbacks.end())
{
LOG_WARN(Logger, "binary_client | no callback found for message id: {}, handle: {}", id, header.RequestHandle);
LOG_WARN(Logger, "binary_client | no callback found for message id: {}, handle: {}", ToString(id), header.RequestHandle);
messageBuffer.clear();
return;
}
Expand Down Expand Up @@ -1017,11 +1017,11 @@ class BinaryClient

if (id == SERVICE_FAULT)
{
LOG_WARN(Logger, "binary_client | receive ServiceFault from Server with StatusCode: {}", header.ServiceResult);
LOG_WARN(Logger, "binary_client | receive ServiceFault from Server with StatusCode: {}", ToString(header.ServiceResult));
}
else if (header.ServiceResult != StatusCode::Good)
{
LOG_WARN(Logger, "binary_client | received a response from server with error status: {}", header.ServiceResult);
LOG_WARN(Logger, "binary_client | received a response from server with error status: {}", ToString(header.ServiceResult));
}

messageBuffer.insert(messageBuffer.end(), buffer.begin(), buffer.end());
Expand Down
7 changes: 3 additions & 4 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,11 @@ void UaClient::EncryptPassword(OpcUa::UserIdentifyToken &identity, const CreateS
}
{
mbedtls_rsa_context *rsa = mbedtls_pk_rsa(x509.pk);
rsa->padding = MBEDTLS_RSA_PKCS_V21;
rsa->hash_id = MBEDTLS_MD_SHA1;
mbedtls_rsa_set_padding(rsa,MBEDTLS_RSA_PKCS_V21,MBEDTLS_MD_SHA1);

LOG_DEBUG(Logger, "ua_client | generating the RSA encrypted value...");

unsigned char buff[rsa->len];
unsigned char buff[mbedtls_rsa_get_len(rsa)];
std::string input = identity.UserName.Password;
input += std::string(response.Parameters.ServerNonce.Data.begin(), response.Parameters.ServerNonce.Data.end());
{
Expand All @@ -571,7 +570,7 @@ void UaClient::EncryptPassword(OpcUa::UserIdentifyToken &identity, const CreateS
}
LOG_DEBUG(Logger, "ua_client | encrypted password: {}", hex(std::vector<unsigned char>(buff, buff + sizeof(buff))));

identity.UserName.Password = std::string((const char*)buff, rsa->len);
identity.UserName.Password = std::string((const char*)buff, mbedtls_rsa_get_len(rsa));
identity.UserName.EncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#rsa-oaep";
}
exit2:
Expand Down
12 changes: 6 additions & 6 deletions src/core/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
******************************************************************************/


#include <opc/ua/subscription.h>
#include <opc/ua/protocol/string_utils.h>

#include <boost/asio.hpp>
#include <iostream>


namespace OpcUa
{
Subscription::Subscription(Services::SharedPtr server, const CreateSubscriptionParameters & params, SubscriptionHandler & callback, const Common::Logger::SharedPtr & logger)
Expand Down Expand Up @@ -78,7 +78,7 @@ void Subscription::PublishCallback(Services::SharedPtr server, const PublishResu

else
{
LOG_WARN(Logger, "subscription | unknown notficiation type received: {}", data.Header.TypeId);
LOG_WARN(Logger, "subscription | unknown notficiation type received: {}", ToString(data.Header.TypeId));
}
}

Expand All @@ -100,7 +100,7 @@ void Subscription::CallDataChangeCallback(const NotificationData & data)

if (mapit == AttributeValueMap.end())
{
LOG_WARN(Logger, "subscription | got PublishResult for an unknown monitoreditem id: {}", item.ClientHandle);
LOG_WARN(Logger, "subscription | got PublishResult for an unknown monitoreditem id: {}", (unsigned)item.ClientHandle);
}

else
Expand All @@ -109,7 +109,7 @@ void Subscription::CallDataChangeCallback(const NotificationData & data)
Node node = mapit->second.TargetNode;
lock.unlock(); //unlock before calling client cades, you never know what they may do

LOG_DEBUG(Logger, "subscription | calling DataChange user callback: {} and node: {}", item.ClientHandle, mapit->second.TargetNode);
LOG_DEBUG(Logger, "subscription | calling DataChange user callback: {} and node: {}", (unsigned)item.ClientHandle, ToString(mapit->second.TargetNode));

Client.DataValueChange(mapit->second.MonitoredItemId, node, item.Value, attr);
Client.DataChange(mapit->second.MonitoredItemId, node, item.Value.Value, attr);
Expand All @@ -132,7 +132,7 @@ void Subscription::CallEventCallback(const NotificationData & data)

if (mapit == AttributeValueMap.end())
{
LOG_WARN(Logger, "subscription | got PublishResult for an unknown MonitoredItem id: {}", ef.ClientHandle);
LOG_WARN(Logger, "subscription | got PublishResult for an unknown MonitoredItem id: {}", (unsigned)ef.ClientHandle);
}

else
Expand Down Expand Up @@ -370,7 +370,7 @@ uint32_t Subscription::SubscribeEvents(const Node & node, const Node & eventtype
for (Node & child : eventtype.GetProperties())
{
auto propertyName = child.GetBrowseName();
LOG_DEBUG(Logger, " property: {}", propertyName);
LOG_DEBUG(Logger, " property: {}", propertyName.Name);

SimpleAttributeOperand op;
op.TypeId = eventtype.GetId();
Expand Down
6 changes: 3 additions & 3 deletions src/examples/example_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ int main(int argc, char ** argv)

//get Root node on server
OpcUa::Node root = client.GetRootNode();
logger->info("Root node is: {}", root);
logger->info("Root node is: {}", ToString(root));

//get and browse Objects node
logger->info("Child of objects node are:");
Node objects = client.GetObjectsNode();

for (OpcUa::Node node : objects.GetChildren())
{ logger->info(" {}", node); }
{ logger->info(" {}", ToString(node)); }

//get a node from standard namespace using objectId
logger->info("NamespaceArray is:");
Expand Down Expand Up @@ -96,7 +96,7 @@ int main(int argc, char ** argv)
std::vector<std::string> varpath{ "Objects", "Server", "ServerStatus", "CurrentTime" };
myvar = root.GetChild(varpath);

logger->info("got node: {}", myvar);
logger->info("got node: {}", ToString(myvar));

//Subscription
SubClient sclt;
Expand Down
4 changes: 2 additions & 2 deletions src/examples/example_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ void RunServer()

//browse root node on server side
Node root = server.GetRootNode();
logger->info("Root node is: {}", root);
logger->info("Root node is: {}", ToString(root));
logger->info("Children are:");

for (Node node : root.GetChildren())
{
logger->info(" {}", node);
logger->info(" {}", ToString(node));
}


Expand Down
2 changes: 1 addition & 1 deletion src/protocol/binary_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ time_t DateTime::ToTimeT(DateTime dateTime)
if (dateTime.Value < secsFrom1601To1970)
{
std::stringstream stream;
stream << "OpcUa date time cannot be less than " << secsFrom1601To1970;
stream << "OpcUa date time cannot be less than " << secsFrom1601To1970 << ". Current value: " << dateTime.Value;
throw std::invalid_argument(stream.str());
}

Expand Down
10 changes: 9 additions & 1 deletion src/protocol/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,15 @@ std::ostream & OpcUa::ToStream(std::ostream & os, const OpcUa::Event & value, in
ToStream(os, value.EventType, true);

indent(os, subIndentLevel);
os << "Time: " << value.Time;

try
{
os << "Time: " << value.Time;
}
catch(const std::invalid_argument& e)
{
os << "Time: INVALID";
}

if (showAll)
{
Expand Down
20 changes: 10 additions & 10 deletions src/server/address_space_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ std::vector<BrowseResult> AddressSpaceInMemory::Browse(const OpcUa::NodesQuery &
if (Logger && Logger->should_log(spdlog::level::trace))
{
Logger->trace("address_space_internal| browsing");
Logger->trace(" NodeId: '{}'", browseDescription.NodeToBrowse);
Logger->trace(" ReferenceId: '{}'", browseDescription.ReferenceTypeId);
Logger->trace(" Direction: {}", browseDescription.Direction);
Logger->trace(" NodeId: '{}'", ToString(browseDescription.NodeToBrowse));
Logger->trace(" ReferenceId: '{}'", ToString(browseDescription.ReferenceTypeId));
Logger->trace(" Direction: {}", (unsigned)browseDescription.Direction);
Logger->trace(" NodeClasses: {:#x}", (unsigned)browseDescription.NodeClasses);
Logger->trace(" ResultMask: {:#x}", (unsigned)browseDescription.ResultMask);
}
Expand Down Expand Up @@ -276,21 +276,21 @@ uint32_t AddressSpaceInMemory::AddDataChangeCallback(const NodeId & node, Attrib
{
boost::unique_lock<boost::shared_mutex> lock(DbMutex);

LOG_DEBUG(Logger, "address_space_internal| set data changes callback for node {} and attribute {}", node, (unsigned)attribute);
LOG_DEBUG(Logger, "address_space_internal| set data changes callback for node {} and attribute {}", ToString(node), (unsigned)attribute);

NodesMap::iterator it = Nodes.find(node);

if (it == Nodes.end())
{
LOG_ERROR(Logger, "address_space_internal| Node: '{}' not found", node);
LOG_ERROR(Logger, "address_space_internal| Node: '{}' not found", ToString(node));
throw std::runtime_error("address_space_internal| NodeId not found");
}

AttributesMap::iterator ait = it->second.Attributes.find(attribute);

if (ait == it->second.Attributes.end())
{
LOG_ERROR(Logger, "address_space_internal| Attribute: {} of node: ‘{}‘ not found", (unsigned)attribute, node);
LOG_ERROR(Logger, "address_space_internal| Attribute: {} of node: ‘{}‘ not found", (unsigned)attribute, ToString(node));
throw std::runtime_error("Attribute not found");
}

Expand Down Expand Up @@ -420,7 +420,7 @@ CallMethodResult AddressSpaceInMemory::CallMethod(CallMethodRequest request)

catch (std::exception & ex)
{
LOG_ERROR(Logger, "address_space_internal| exception while calling method: {}: {}", request.MethodId, ex.what());
LOG_ERROR(Logger, "address_space_internal| exception while calling method: {}: {}", ToString(request.MethodId), ex.what());
result.Status = StatusCode::BadUnexpectedError;
return result;
}
Expand Down Expand Up @@ -534,13 +534,13 @@ AddNodesResult AddressSpaceInMemory::AddNode(const AddNodesItem & item)
{
AddNodesResult result;

LOG_TRACE(Logger, "address_space_internal| adding new node id: '{}' name: '{}'", item.RequestedNewNodeId, item.BrowseName.Name);
LOG_TRACE(Logger, "address_space_internal| adding new node id: '{}' name: '{}'", ToString(item.RequestedNewNodeId), item.BrowseName.Name);

const NodeId resultId = GetNewNodeId(item.RequestedNewNodeId);

if (!Nodes.empty() && resultId != ObjectId::Null && Nodes.find(resultId) != Nodes.end())
{
LOG_ERROR(Logger, "address_space_internal| NodeId: '{}' already exists", resultId);
LOG_ERROR(Logger, "address_space_internal| NodeId: '{}' already exists", ToString(resultId));
result.Status = StatusCode::BadNodeIdExists;
return result;
}
Expand All @@ -553,7 +553,7 @@ AddNodesResult AddressSpaceInMemory::AddNode(const AddNodesItem & item)

if (parent_node_it == Nodes.end())
{
LOG_ERROR(Logger, "address_space_internal| parent node '{}' does not exists", item.ParentNodeId);
LOG_ERROR(Logger, "address_space_internal| parent node '{}' does not exists", ToString(item.ParentNodeId));
result.Status = StatusCode::BadParentNodeIdInvalid;
return result;
}
Expand Down
12 changes: 6 additions & 6 deletions src/server/internal_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ MonitoredItemCreateResult InternalSubscription::CreateMonitoredItem(const Monito
if (request.ItemToMonitor.AttributeId == AttributeId::EventNotifier)
{
LOG_DEBUG(Logger, "internal_subscription | id: {}, subscribe to event notifier", Data.SubscriptionId);
LOG_TRACE(Logger, "internal_subscription | id: {}, {}", Data.SubscriptionId, result.FilterResult);
LOG_TRACE(Logger, "internal_subscription | id: {}, {}", Data.SubscriptionId, ToString(result.FilterResult));

// Client wants to subscribe to events
// FIXME: check attribute EVENT notifier is set for the node
Expand Down Expand Up @@ -484,7 +484,7 @@ void InternalSubscription::DataChangeCallback(const uint32_t & m_id, const DataV
event.Data.ClientHandle = monitoredDataChange.ClientHandle;
event.Data.Value = value;

LOG_DEBUG(Logger, "internal_subscription | id: {}, enqueue TriggeredDataChange event: ClientHandle: {}", Data.SubscriptionId, event.Data.ClientHandle);
LOG_DEBUG(Logger, "internal_subscription | id: {}, enqueue TriggeredDataChange event: ClientHandle: {}", Data.SubscriptionId, (unsigned)event.Data.ClientHandle);

++monitoredDataChange.TriggerCount;
TriggeredDataChangeEvents.push_back(event);
Expand All @@ -498,7 +498,7 @@ void InternalSubscription::TriggerEvent(NodeId node, Event event)

if (it == MonitoredEvents.end())
{
LOG_DEBUG(Logger, "internal_subscription | id: {} does not monitor NodeId: {}", Data.SubscriptionId, node);
LOG_DEBUG(Logger, "internal_subscription | id: {} does not monitor NodeId: {}", Data.SubscriptionId, ToString(node));

return;
}
Expand All @@ -509,7 +509,7 @@ void InternalSubscription::TriggerEvent(NodeId node, Event event)

bool InternalSubscription::EnqueueEvent(uint32_t monitoredItemId, const Event & event)
{
LOG_DEBUG(Logger, "internal_subscription | id: {}, EnqueEvent: {}", Data.SubscriptionId, event);
LOG_DEBUG(Logger, "internal_subscription | id: {}, EnqueEvent: {}", Data.SubscriptionId, ToString(event));

boost::unique_lock<boost::shared_mutex> lock(DbMutex);

Expand Down Expand Up @@ -553,7 +553,7 @@ std::vector<Variant> InternalSubscription::GetEventFields(const EventFilter & fi

else
{
LOG_DEBUG(Logger, "internal_subscription | id: {}, send value for: {}", Data.SubscriptionId, sattr.BrowsePath[0]);
LOG_DEBUG(Logger, "internal_subscription | id: {}, send value for: {}", Data.SubscriptionId, sattr.BrowsePath[0].Name);

if (sattr.BrowsePath[0] == QualifiedName("EventId", 0))
{
Expand All @@ -577,7 +577,7 @@ std::vector<Variant> InternalSubscription::GetEventFields(const EventFilter & fi

else if (sattr.BrowsePath[0] == QualifiedName("Message", 0))
{
LOG_DEBUG(Logger, "internal_subscription | message is: {}", event.Message);
LOG_DEBUG(Logger, "internal_subscription | message is: {}", ToString(event.Message));

fields.push_back(event.Message);
}
Expand Down
6 changes: 3 additions & 3 deletions src/server/opc_tcp_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <opc/ua/server/opc_tcp_async.h>

#include <opc/ua/protocol/utils.h>
#include <opc/ua/protocol/string_utils.h>
#include <opc/ua/protocol/binary/common.h>
#include <opc/ua/protocol/binary/stream.h>
#include <opc/ua/protocol/channel.h>
Expand Down Expand Up @@ -209,7 +210,7 @@ void OpcTcpConnection::ProcessHeader(const boost::system::error_code & error, st

const std::size_t messageSize = header.Size - GetHeaderSize();

LOG_DEBUG(Logger, "opc_tcp_async | received message: Type: {}, ChunkType: {}, Size: {}: DataSize: {}", header.Type, header.Chunk, header.Size, messageSize);
LOG_DEBUG(Logger, "opc_tcp_async | received message: Type: {}, ChunkType: {}, Size: {}: DataSize: {}", (unsigned)header.Type, (unsigned)header.Chunk, header.Size, messageSize);

// do not lose reference to shared instance even if another
// async operation decides to call GoodBye()
Expand Down Expand Up @@ -329,8 +330,7 @@ OpcTcpServer::OpcTcpServer(const AsyncOpcTcp::Parameters & params, Services::Sha
void OpcTcpServer::Listen()
{
LOG_DEBUG(Logger, "opc_tcp_async | running server");

LOG_DEBUG(Logger, "opc_tcp_async | waiting for client connection at: {}:{}", acceptor.local_endpoint().address(), acceptor.local_endpoint().port());
LOG_DEBUG(Logger, "opc_tcp_async | waiting for client connection at: {}:{}", acceptor.local_endpoint().address().to_string(), acceptor.local_endpoint().port());
acceptor.listen();

Accept();
Expand Down
Loading