1
0
mirror of https://github.com/FreeOpcUa/freeopcua synced 2025-10-26 19:56:54 +08:00

Modified to compile against spdlog-1.15.2 and mbedtls-3.6.3 on gcc version 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC)

This commit is contained in:
Vic Simkus 2025-05-02 13:38:39 -05:00
parent 6eac097563
commit 640c61befe
10 changed files with 55 additions and 56 deletions

View File

@ -371,7 +371,7 @@ public:
{
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));
}
}
@ -558,7 +558,7 @@ public:
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;
@ -700,7 +700,7 @@ public:
{
for (BrowseDescription desc : query.NodesToBrowse)
{
Logger->trace("Node: {}", desc.NodeToBrowse);
Logger->trace("Node: {}", ToString(desc.NodeToBrowse));
}
}
@ -763,7 +763,7 @@ public:
for (auto & param : params)
{
Logger->trace(" {}", param);
Logger->trace(" {}", ToString(param));
}
}
@ -778,7 +778,7 @@ public:
for (auto & id : response.Result)
{
Logger->trace(" {}", id);
Logger->trace(" {}", ToString(id));
}
}
LOG_DEBUG(Logger, "binary_client | RegisterNodes <--");
@ -794,7 +794,7 @@ public:
for (auto & id : params)
{
Logger->trace(" {}", id);
Logger->trace(" {}", ToString(id));
}
}
@ -879,7 +879,7 @@ private:
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);
@ -928,7 +928,7 @@ private:
{
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;
@ -982,7 +982,7 @@ private:
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;
}
@ -1017,11 +1017,11 @@ private:
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());

View File

@ -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());
{
@ -564,14 +563,14 @@ void UaClient::EncryptPassword(OpcUa::UserIdentifyToken &identity, const CreateS
input = sn + input;
}
ret = mbedtls_rsa_pkcs1_encrypt( rsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PUBLIC, input.size(), (const unsigned char*)input.data(), buff );
ret = mbedtls_rsa_pkcs1_encrypt( rsa, mbedtls_ctr_drbg_random, &ctr_drbg,input.size(), (const unsigned char*)input.data(), buff );
if( ret != 0 ) {
LOG_ERROR(Logger, "ua_client | error RSA encryption {}", error2string(ret) );
goto exit2;
}
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:

View File

@ -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)
@ -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));
}
}
@ -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
@ -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);
@ -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
@ -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();

View File

@ -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:");
@ -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;

View File

@ -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));
}

View File

@ -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);
}
@ -276,13 +276,13 @@ 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");
}
@ -290,7 +290,7 @@ uint32_t AddressSpaceInMemory::AddDataChangeCallback(const NodeId & node, Attrib
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");
}
@ -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;
}
@ -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;
}
@ -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;
}

View File

@ -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
@ -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);
@ -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;
}
@ -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);
@ -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))
{
@ -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);
}

View File

@ -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>
@ -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()
@ -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();

View File

@ -58,7 +58,7 @@ OpcTcpMessages::OpcTcpMessages(OpcUa::Services::SharedPtr server, OpcUa::OutputC
, SequenceNb(0)
{
//LOG_INFO(Logger, "opc_tcp_processor | log level: {}", Logger->level());
LOG_INFO(Logger, "opc_tcp_processor | SessionId; {}", SessionId);
LOG_INFO(Logger, "opc_tcp_processor | SessionId; {}", ToString(SessionId));
}
@ -131,7 +131,7 @@ bool OpcTcpMessages::ProcessMessage(MessageType msgType, IStreamBinary & iStream
default:
{
LOG_ERROR(Logger, "opc_tcp_processor | unknown message type '{}' received", msgType);
LOG_ERROR(Logger, "opc_tcp_processor | unknown message type '{}' received", (unsigned)msgType);
throw std::logic_error("unknown message type received.");
}
@ -368,7 +368,7 @@ void OpcTcpMessages::ProcessRequest(IStreamBinary & istream, OStreamBinary & ost
Node node(Server, id.NodeId);
name = node.GetBrowseName().Name;
}
Logger->debug("opc_tcp_processor | {} ({})", id.NodeId, name);
Logger->debug("opc_tcp_processor | {} ({})", ToString(id.NodeId), name);
}
}
@ -466,7 +466,7 @@ void OpcTcpMessages::ProcessRequest(IStreamBinary & istream, OStreamBinary & ost
{
target << path.Node ;
}
Logger->debug("opc_tcp_processor | result of browsePath is: {}, target is: {}", (uint32_t)res.Status, target.str());
Logger->debug("opc_tcp_processor | result of browsePath is: {}, target is: {}", (unsigned)res.Status, target.str());
}
}
@ -892,7 +892,7 @@ void OpcTcpMessages::ProcessRequest(IStreamBinary & istream, OStreamBinary & ost
secureHeader.AddSize(RawSize(sequence));
secureHeader.AddSize(RawSize(response));
LOG_WARN(Logger, "opc_tcp_processor | sending 'ServiceFaultResponse' to unsupported request of id: {}", message);
LOG_WARN(Logger, "opc_tcp_processor | sending 'ServiceFaultResponse' to unsupported request of id: {}", (unsigned)message);
ostream << secureHeader << algorithmHeader << sequence << response << flush;
return;

View File

@ -197,7 +197,7 @@ void SubscriptionServiceInternal::Publish(const PublishRequest & request)
if (PublishRequestQueues[session] < 100)
{
PublishRequestQueues[session] += 1;
LOG_DEBUG(Logger, "subscription_service | push PublishRequest for session: {}: available requests: {}", session, PublishRequestQueues[session]);
LOG_DEBUG(Logger, "subscription_service | push PublishRequest for session: {}: available requests: {}", ToString(session), PublishRequestQueues[session]);
}
//FIXME: else spec says we should return error to warn client
@ -236,13 +236,13 @@ bool SubscriptionServiceInternal::PopPublishRequest(NodeId node)
if (queue_it == PublishRequestQueues.end())
{
LOG_ERROR(Logger, "subscription_service | attempt to pop publish request for unknown session: {}", node);
LOG_ERROR(Logger, "subscription_service | attempt to pop publish request for unknown session: {}", ToString(node));
if (Logger && Logger->should_log(spdlog::level::debug))
{
for (auto i : PublishRequestQueues)
{
Logger->debug("subscription_service | available session: {}", i.first);
Logger->debug("subscription_service | available session: {}",ToString( i.first));
}
}
return false;
@ -252,13 +252,13 @@ bool SubscriptionServiceInternal::PopPublishRequest(NodeId node)
{
if (queue_it->second == 0)
{
LOG_ERROR(Logger, "subscription_service | unable to send response: no publish request for session: {}", node);
LOG_ERROR(Logger, "subscription_service | unable to send response: no publish request for session: {}", ToString(node));
return false;
}
else
{
LOG_DEBUG(Logger, "subscription_service | pop PublishRequest for session: {}: available requests: {}", node, queue_it->second);
LOG_DEBUG(Logger, "subscription_service | pop PublishRequest for session: {}: available requests: {}", ToString(node), queue_it->second);
--queue_it->second;
return true;
}