Skip to content

Commit

Permalink
fix(plc4go/opcua): Fix compile errors in golang opcua driver.
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Dywicki <[email protected]>
  • Loading branch information
splatch committed Nov 6, 2024
1 parent a132fa0 commit cf95a8c
Show file tree
Hide file tree
Showing 2,153 changed files with 4,344 additions and 2,347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ func (m *_${type.name}) GetTypeName() string {
<#if !type.isDiscriminatedParentTypeDefinition()>
func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
<#if type.isDiscriminatedChildTypeDefinition()>
lengthInBits := uint16(m.${type.getParentType().orElseThrow().name}Contract.(*_${type.getParentType().orElseThrow().name}).GetLengthInBits(ctx))
lengthInBits := uint16(m.${type.getParentType().orElseThrow().name}Contract.(*_${type.getParentType().orElseThrow().name}).getLengthInBits(ctx))
<#else>
lengthInBits := uint16(0)
</#if>
Expand Down Expand Up @@ -770,7 +770,7 @@ func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
<#elseif helper.isEnumField(discriminatorField)>
lengthInBits += ${helper.getEnumBaseTypeReference(discriminatorField.type).sizeInBits};
<#else>
lengthInBits += ${discriminatorField.name}.GetLengthInBits();
lengthInBits += ${discriminatorField.name}.getLengthInBits();
</#if>
<#break>
<#case "enum">
Expand Down Expand Up @@ -880,7 +880,7 @@ func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
</#if>

<#if type.isDiscriminatedParentTypeDefinition()>
func (m *_${type.name}) GetLengthInBits(ctx context.Context) uint16 {
func (m *_${type.name}) getLengthInBits(ctx context.Context) uint16 {
lengthInBits := uint16(0)
<#list type.fields as field>
<#switch field.typeName>
Expand Down
12 changes: 12 additions & 0 deletions plc4go/assets/testing/protocols/ads/DriverTestsuite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,18 @@
</PlcResponseItem>
</hurz>
</values>
<metadata isList="true">
<hurz>
<entry>
<key dataType="string" bitLength="17" encoding="UTF-8">receive_timestamp</key>
<value dataType="string" bitLength="13" encoding="UTF-8" plc4x-skip-comparison="true">0</value>
</entry>
<entry>
<key dataType="string" bitLength="16" encoding="UTF-8">timestamp_source</key>
<value dataType="string" bitLength="10" encoding="UTF-8">ASSUMPTION</value>
</entry>
</hurz>
</metadata>
</PlcReadResponse>
</api-response>
</steps>
Expand Down
2,081 changes: 2,014 additions & 67 deletions plc4go/assets/testing/protocols/opcua/DriverTestsuite.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plc4go/internal/opcua/EncryptionHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (h *EncryptionHandler) encodeMessage(ctx context.Context, pdu readWriteMode
numberOfBlocks := preEncryptedLength / PREENCRYPTED_BLOCK_LENGTH
encryptedLength := numberOfBlocks*256 + positionFirstBlock
buf := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.LittleEndian))
if err := readWriteModel.NewOpcuaAPU(pdu, false).SerializeWithWriteBuffer(ctx, buf); err != nil {
if err := readWriteModel.NewOpcuaAPU(pdu, false, true).SerializeWithWriteBuffer(ctx, buf); err != nil {
return nil, errors.Wrap(err, "error serializing")
}
paddingByte := byte(paddingSize)
Expand Down Expand Up @@ -168,7 +168,7 @@ func (h *EncryptionHandler) decodeMessage(ctx context.Context, pdu readWriteMode
}

readBuffer := utils.NewReadBufferByteBased(buf.GetBytes(), utils.WithByteOrderForReadBufferByteBased(binary.LittleEndian))
return readWriteModel.OpcuaAPUParseWithBuffer(ctx, readBuffer, true)
return readWriteModel.OpcuaAPUParseWithBuffer(ctx, readBuffer, true, true)
default:
h.log.Trace().Msg("unmapped security policy")
return pdu, nil
Expand Down
4 changes: 2 additions & 2 deletions plc4go/internal/opcua/MessageCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (m *MessageCodec) Send(message spi.Message) error {
opcuaApu, ok := message.(readWriteModel.OpcuaAPU)
if !ok {
if message, ok := message.(readWriteModel.MessagePDU); ok {
opcuaApu = readWriteModel.NewOpcuaAPU(message, false)
opcuaApu = readWriteModel.NewOpcuaAPU(message, false, true)
} else {
return errors.Errorf("Invalid message type %T", message)
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (m *MessageCodec) Receive() (spi.Message, error) {
}
ctxForModel := options.GetLoggerContextForModel(context.Background(), m.log, options.WithPassLoggerToModel(m.passLogToModel))
rbbb := utils.NewReadBufferByteBased(readBytes, utils.WithByteOrderForReadBufferByteBased(binary.LittleEndian))
opcuaAPU, err := readWriteModel.OpcuaAPUParseWithBuffer(ctxForModel, rbbb, true)
opcuaAPU, err := readWriteModel.OpcuaAPUParseWithBuffer(ctxForModel, rbbb, true, true)
if err != nil {
return nil, errors.New("Could not parse pdu")
}
Expand Down
46 changes: 25 additions & 21 deletions plc4go/internal/opcua/SecureChannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ var (
nil,
nil,
)
BINARY_ENCODING_MASK = readWriteModel.NewExtensionObjectEncodingMask(false, false, true)
NULL_EXTENSION_OBJECT = readWriteModel.NewNullExtensionObjectWithMask(NULL_EXPANDED_NODEID,
readWriteModel.NewExtensionObjectEncodingMask(false, false, false),
0,
Expand Down Expand Up @@ -197,6 +196,7 @@ func (s *SecureChannel) submit(ctx context.Context, codec *MessageCodec, errorDi
uint32(len(buffer.GetBytes())),
),
uint32(len(buffer.GetBytes())),
true,
)

var apu readWriteModel.OpcuaAPU
Expand All @@ -206,13 +206,13 @@ func (s *SecureChannel) submit(ctx context.Context, codec *MessageCodec, errorDi
errorDispatcher(err)
return
}
apu, err = readWriteModel.OpcuaAPUParse(ctx, message, false)
apu, err = readWriteModel.OpcuaAPUParse(ctx, message, false, true)
if err != nil {
errorDispatcher(err)
return
}
} else {
apu = readWriteModel.NewOpcuaAPU(messageRequest, false)
apu = readWriteModel.NewOpcuaAPU(messageRequest, false, true)
}

requestConsumer := func(transactionId int32) {
Expand Down Expand Up @@ -299,6 +299,7 @@ func (s *SecureChannel) onConnect(ctx context.Context, connection *Connection, c
DEFAULT_MAX_CHUNK_COUNT,
),
s.endpoint,
true,
)

requestConsumer := func(transactionId int32) {
Expand Down Expand Up @@ -407,6 +408,7 @@ func (s *SecureChannel) onConnectOpenSecureChannel(ctx context.Context, connecti
uint32(len(buffer.GetBytes())),
),
uint32(len(buffer.GetBytes())),
true,
)

var apu readWriteModel.OpcuaAPU
Expand All @@ -418,14 +420,14 @@ func (s *SecureChannel) onConnectOpenSecureChannel(ctx context.Context, connecti
connection.fireConnectionError(err, ch)
return
}
apu, err = readWriteModel.OpcuaAPUParse(ctx, message, false)
apu, err = readWriteModel.OpcuaAPUParse(ctx, message, false, true)
if err != nil {
s.log.Debug().Err(err).Msg("error parsing")
connection.fireConnectionError(err, ch)
return
}
} else {
apu = readWriteModel.NewOpcuaAPU(openRequest, false)
apu = readWriteModel.NewOpcuaAPU(openRequest, false, true)
}

requestConsumer := func(transactionId int32) {
Expand Down Expand Up @@ -839,9 +841,10 @@ func (s *SecureChannel) onDisconnectCloseSecureChannel(ctx context.Context, conn
),
0,
),
true,
)

apu := readWriteModel.NewOpcuaAPU(closeRequest, false)
apu := readWriteModel.NewOpcuaAPU(closeRequest, false, true)

requestConsumer := func(transactionId int32) {
if err := connection.messageCodec.SendRequest(
Expand Down Expand Up @@ -898,9 +901,10 @@ func (s *SecureChannel) onDiscover(ctx context.Context, codec *MessageCodec) {
DEFAULT_MAX_CHUNK_COUNT,
),
s.endpoint,
true,
)

apu := readWriteModel.NewOpcuaAPU(hello, false)
apu := readWriteModel.NewOpcuaAPU(hello, false, true)

requestConsumer := func(transactionId int32) {
if err := codec.SendRequest(
Expand Down Expand Up @@ -999,9 +1003,10 @@ func (s *SecureChannel) onDiscoverOpenSecureChannel(ctx context.Context, codec *
uint32(len(buffer.GetBytes())),
),
uint32(len(buffer.GetBytes())),
true,
)

apu := readWriteModel.NewOpcuaAPU(openRequest, false)
apu := readWriteModel.NewOpcuaAPU(openRequest, false, true)

requestConsumer := func(transactionId int32) {
if err := codec.SendRequest(
Expand Down Expand Up @@ -1125,9 +1130,10 @@ func (s *SecureChannel) onDiscoverGetEndpointsRequest(ctx context.Context, codec
uint32(len(buffer.GetBytes())),
),
uint32(len(buffer.GetBytes())),
true,
)

apu := readWriteModel.NewOpcuaAPU(messageRequest, false)
apu := readWriteModel.NewOpcuaAPU(messageRequest, false, true)

requestConsumer := func(transactionId int32) {
if err := codec.SendRequest(
Expand Down Expand Up @@ -1237,9 +1243,10 @@ func (s *SecureChannel) onDiscoverCloseSecureChannel(ctx context.Context, codec
),
uint32(0),
),
true,
)

apu := readWriteModel.NewOpcuaAPU(closeRequest, false)
apu := readWriteModel.NewOpcuaAPU(closeRequest, false, true)

requestConsumer := func(transactionId int32) {
if err := codec.SendRequest(
Expand Down Expand Up @@ -1362,6 +1369,7 @@ func (s *SecureChannel) keepAlive() {
uint32(len(buffer.GetBytes())),
),
uint32(len(buffer.GetBytes())),
true,
)

var apu readWriteModel.OpcuaAPU
Expand All @@ -1372,13 +1380,13 @@ func (s *SecureChannel) keepAlive() {
s.log.Error().Err(err).Msg("error encoding")
return
}
apu, err = readWriteModel.OpcuaAPUParse(ctx, message, false)
apu, err = readWriteModel.OpcuaAPUParse(ctx, message, false, true)
if err != nil {
s.log.Error().Err(err).Msg("error parsing")
return
}
} else {
apu = readWriteModel.NewOpcuaAPU(openRequest, false)
apu = readWriteModel.NewOpcuaAPU(openRequest, false, true)
}

requestConsumer := func(transactionId int32) {
Expand Down Expand Up @@ -1561,21 +1569,17 @@ func (s *SecureChannel) getIdentityToken(tokenType readWriteModel.UserTokenType,
switch tokenType {
case readWriteModel.UserTokenType_userTokenTypeAnonymous:
//If we aren't using authentication tell the server we would like to log in anonymously
anonymousIdentityToken, err := readWriteModel.NewAnonymousIdentityTokenBuilder().WithPolicyId(readWriteModel.NewPascalString(policyId)).Build()
if err != nil {
s.log.Error().Err(err).Msg("error creating anonymous authentication token")
return nil
}
anonymousIdentityToken := readWriteModel.NewAnonymousIdentityToken(readWriteModel.NewPascalString(policyId))
extExpandedNodeId := readWriteModel.NewExpandedNodeId(
false, //Namespace Uri Specified
false, //Server Index Specified
readWriteModel.NewNodeIdFourByte(0, uint16(anonymousIdentityToken.GetExtensionId())),
readWriteModel.NewNodeIdFourByte(0, 321 /* TODO: disabled till we have greater segmentation: uint16(readWriteModel.OpcuaNodeIdServices_AnonymousIdentityToken_Encoding_DefaultBinary)*/),
nil,
nil,
)
return readWriteModel.NewBinaryExtensionObjectWithMask(
extExpandedNodeId,
BINARY_ENCODING_MASK,
readWriteModel.NewExtensionObjectEncodingMask(false, false, true),
anonymousIdentityToken,
anonymousIdentityToken.GetExtensionId(),
false,
Expand Down Expand Up @@ -1608,12 +1612,12 @@ func (s *SecureChannel) getIdentityToken(tokenType readWriteModel.UserTokenType,
extExpandedNodeId := readWriteModel.NewExpandedNodeId(
false, //Namespace Uri Specified
false, //Server Index Specified
readWriteModel.NewNodeIdFourByte(0, uint16(userNameIdentityToken.GetExtensionId())),
readWriteModel.NewNodeIdFourByte(0, 324 /*TODO: disabled till we have greater segmentation: uint16(readWriteModel.OpcuaNodeIdServices_UserNameIdentityToken_Encoding_DefaultBinary)*/),
nil,
nil)
return readWriteModel.NewBinaryExtensionObjectWithMask(
extExpandedNodeId,
BINARY_ENCODING_MASK,
readWriteModel.NewExtensionObjectEncodingMask(false, false, true),
userNameIdentityToken,
userNameIdentityToken.GetExtensionId(),
false,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cf95a8c

Please sign in to comment.