Skip to content

Commit

Permalink
Merge pull request #123 from netixx/fix-self-closing-tags-length
Browse files Browse the repository at this point in the history
Call forceselfclosingtags before netconf message framing
  • Loading branch information
carlmontanari authored Mar 11, 2023
2 parents e191a6d + 497ee1e commit 37eba54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 11 additions & 7 deletions driver/netconf/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ type message struct {
Payload interface{} `xml:",innerxml"`
}

func (m *message) serialize(v string) ([]byte, error) {
message, err := xml.Marshal(m)
func (m *message) serialize(v string, forceSelfClosingTags bool) ([]byte, error) {
msg, err := xml.Marshal(m)
if err != nil {
return nil, err
}

message = append([]byte(xmlHeader), message...)
msg = append([]byte(xmlHeader), msg...)

if forceSelfClosingTags {
msg = ForceSelfClosingTags(msg)
}

switch v {
case V1Dot0:
message = append(message, []byte(v1Dot0Delim)...)
msg = append(msg, []byte(v1Dot0Delim)...)
case V1Dot1:
message = append([]byte(fmt.Sprintf("#%d\n", len(message))), message...)
message = append(message, []byte("\n##")...)
msg = append([]byte(fmt.Sprintf("#%d\n", len(msg))), msg...)
msg = append(msg, []byte("\n##")...)
}

return message, nil
return msg, nil
}
10 changes: 4 additions & 6 deletions driver/netconf/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ func (d *Driver) sendRPC(
m *message,
op *OperationOptions,
) (*response.NetconfResponse, error) {
b, err := m.serialize(d.SelectedVersion)
if err != nil {
return nil, err
}

if d.ForceSelfClosingTags {
d.Logger.Debug("ForceSelfClosingTags is true, enforcing...")
}

b = ForceSelfClosingTags(b)
b, err := m.serialize(d.SelectedVersion, d.ForceSelfClosingTags)
if err != nil {
return nil, err
}

d.Logger.Debugf("sending finalized rpc payload:\n%s", string(b))
Expand Down

0 comments on commit 37eba54

Please sign in to comment.