|
@@ -169,22 +169,6 @@ static void init_response_header(const UA_RequestHeader *p, UA_ResponseHeader *r
|
|
|
responseType = requestType.nodeId.identifier.numeric + 3; \
|
|
|
} while(0)
|
|
|
|
|
|
-#ifdef EXTENSION_STATELESS
|
|
|
-#define INVOKE_STATELESS_SERVICE(TYPE) do { \
|
|
|
- UA_##TYPE##Request p; \
|
|
|
- UA_##TYPE##Response r; \
|
|
|
- CHECK_PROCESS(UA_##TYPE##Request_decodeBinary(msg, pos, &p),; ); \
|
|
|
- UA_##TYPE##Response_init(&r); \
|
|
|
- init_response_header(&p.requestHeader, &r.responseHeader); \
|
|
|
- Service_##TYPE(server, &anonymousSession, &p, &r); \
|
|
|
- UA_ByteString_newMembers(message, UA_##TYPE##Response_calcSizeBinary(&r)); \
|
|
|
- UA_##TYPE##Response_encodeBinary(&r, message, &sendOffset); \
|
|
|
- UA_##TYPE##Request_deleteMembers(&p); \
|
|
|
- UA_##TYPE##Response_deleteMembers(&r); \
|
|
|
- responseType = requestType.nodeId.identifier.numeric + 3; \
|
|
|
-} while(0)
|
|
|
-#endif
|
|
|
-
|
|
|
static void processMessage(UA_Connection *connection, UA_Server *server, const UA_ByteString *msg, UA_UInt32 *pos) {
|
|
|
// 1) Read in the securechannel
|
|
|
UA_UInt32 secureChannelId;
|
|
@@ -194,28 +178,29 @@ static void processMessage(UA_Connection *connection, UA_Server *server, const U
|
|
|
#ifdef EXTENSION_STATELESS
|
|
|
if(connection->channel != UA_NULL && secureChannelId != 0){
|
|
|
#endif
|
|
|
- channel = UA_SecureChannelManager_get(&server->secureChannelManager, secureChannelId);
|
|
|
+ channel = UA_SecureChannelManager_get(&server->secureChannelManager, secureChannelId);
|
|
|
#ifdef EXTENSION_STATELESS
|
|
|
+ }else{
|
|
|
+ //a call of a stateless service is coming - replace the session by the anonymous one
|
|
|
+ UA_SecureChannel dummyChannel;
|
|
|
+ UA_SecureChannel_init(&dummyChannel);
|
|
|
+ channel = &dummyChannel;
|
|
|
+ channel->session = &anonymousSession;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
+
|
|
|
// 2) Read the security header
|
|
|
UA_UInt32 tokenId;
|
|
|
UA_UInt32_decodeBinary(msg, pos, &tokenId);
|
|
|
UA_SequenceHeader sequenceHeader;
|
|
|
CHECK_PROCESS(UA_SequenceHeader_decodeBinary(msg, pos, &sequenceHeader),; );
|
|
|
|
|
|
-#ifdef EXTENSION_STATELESS
|
|
|
- if(connection->channel != UA_NULL && secureChannelId != 0) {
|
|
|
-#endif
|
|
|
channel->sequenceNumber = sequenceHeader.sequenceNumber;
|
|
|
channel->requestId = sequenceHeader.requestId;
|
|
|
// todo
|
|
|
//UA_SecureChannel_checkSequenceNumber(channel,sequenceHeader.sequenceNumber);
|
|
|
//UA_SecureChannel_checkRequestId(channel,sequenceHeader.requestId);
|
|
|
-#ifdef EXTENSION_STATELESS
|
|
|
- }
|
|
|
-#endif
|
|
|
|
|
|
// 3) Read the nodeid of the request
|
|
|
UA_ExpandedNodeId requestType;
|
|
@@ -235,25 +220,6 @@ static void processMessage(UA_Connection *connection, UA_Server *server, const U
|
|
|
|
|
|
UA_UInt32 sendOffset = 0;
|
|
|
|
|
|
-#ifdef EXTENSION_STATELESS
|
|
|
- if(connection->channel == UA_NULL && secureChannelId == 0) {
|
|
|
- //stateless service calls - will pass UA_NULL as session
|
|
|
- //fixme: maybe we need to pass a magic number instead of UA_NULL e.g. just a 42
|
|
|
- switch(requestType.nodeId.identifier.numeric - 2) {
|
|
|
- case UA_READREQUEST_NS0:
|
|
|
- INVOKE_STATELESS_SERVICE(Read);
|
|
|
- break;
|
|
|
- case UA_WRITEREQUEST_NS0:
|
|
|
- INVOKE_STATELESS_SERVICE(Write);
|
|
|
- break;
|
|
|
- case UA_BROWSEREQUEST_NS0:
|
|
|
- INVOKE_STATELESS_SERVICE(Browse);
|
|
|
- break;
|
|
|
-}
|
|
|
- //FIXME: a copy-pasted default case, but I did not want any duplications
|
|
|
-}else{
|
|
|
-#endif
|
|
|
-
|
|
|
//subtract UA_ENCODINGOFFSET_BINARY for binary encoding
|
|
|
switch(requestType.nodeId.identifier.numeric - UA_ENCODINGOFFSET_BINARY) {
|
|
|
case UA_GETENDPOINTSREQUEST_NS0: {
|
|
@@ -329,6 +295,7 @@ static void processMessage(UA_Connection *connection, UA_Server *server, const U
|
|
|
case UA_BROWSEREQUEST_NS0:
|
|
|
INVOKE_SERVICE(Browse);
|
|
|
break;
|
|
|
+
|
|
|
case UA_ADDREFERENCESREQUEST_NS0:
|
|
|
INVOKE_SERVICE(AddReferences);
|
|
|
break;
|
|
@@ -369,9 +336,6 @@ static void processMessage(UA_Connection *connection, UA_Server *server, const U
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
-#ifdef EXTENSION_STATELESS
|
|
|
-}
|
|
|
-#endif
|
|
|
// 5) Build the header
|
|
|
UA_NodeId response_nodeid = { .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
|
|
|
.identifier.numeric = responseType }; // add 2 for binary encoding
|
|
@@ -389,23 +353,11 @@ static void processMessage(UA_Connection *connection, UA_Server *server, const U
|
|
|
UA_UInt32 rpos = 0;
|
|
|
UA_TcpMessageHeader_encodeBinary(&respHeader, header, &rpos);
|
|
|
|
|
|
-#ifdef EXTENSION_STATELESS
|
|
|
- if(connection->channel != UA_NULL && secureChannelId != 0){
|
|
|
-#endif
|
|
|
UA_UInt32_encodeBinary(&channel->securityToken.channelId, header, &rpos); // channel id
|
|
|
UA_UInt32_encodeBinary(&channel->securityToken.tokenId, header, &rpos); // algorithm security header
|
|
|
UA_UInt32_encodeBinary(&channel->sequenceNumber, header, &rpos); // encode sequence header
|
|
|
UA_UInt32_encodeBinary(&channel->requestId, header, &rpos); // request id
|
|
|
UA_NodeId_encodeBinary(&response_nodeid, header, &rpos); // add payload type
|
|
|
-#ifdef EXTENSION_STATELESS
|
|
|
- }else{
|
|
|
- UA_UInt32 zeroInt = 0;
|
|
|
- UA_UInt32_encodeBinary(&zeroInt, header, &rpos);
|
|
|
- UA_UInt32_encodeBinary(&zeroInt, header, &rpos);
|
|
|
- UA_UInt32_encodeBinary(&zeroInt, header, &rpos);
|
|
|
- UA_UInt32_encodeBinary(&zeroInt, header, &rpos);
|
|
|
- }
|
|
|
-#endif
|
|
|
// sign data
|
|
|
|
|
|
// encrypt data
|