Skip to content

Commit

Permalink
Add parameter to exclude header for weird server implementations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuska committed Sep 23, 2024
1 parent 7262aad commit bf40d63
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions driver/netconf/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ type Driver struct {
SelectedVersion string

ForceSelfClosingTags bool
ExcludeHeader bool

serverCapabilities []string
sessionID uint64
Expand Down
6 changes: 4 additions & 2 deletions driver/netconf/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ type serializedInput struct {
framedXML []byte
}

func (m *message) serialize(v string, forceSelfClosingTags bool) (*serializedInput, error) {
func (m *message) serialize(v string, forceSelfClosingTags bool, excludeHeader bool) (*serializedInput, error) {

Check failure on line 21 in driver/netconf/message.go

View workflow job for this annotation

GitHub Actions / unit-test (ubuntu-latest, 1.22)

paramTypeCombine: func(v string, forceSelfClosingTags bool, excludeHeader bool) (*serializedInput, error) could be replaced with func(v string, forceSelfClosingTags, excludeHeader bool) (*serializedInput, error) (gocritic)

Check failure on line 21 in driver/netconf/message.go

View workflow job for this annotation

GitHub Actions / unit-test (macos-latest, 1.20)

paramTypeCombine: func(v string, forceSelfClosingTags bool, excludeHeader bool) (*serializedInput, error) could be replaced with func(v string, forceSelfClosingTags, excludeHeader bool) (*serializedInput, error) (gocritic)

Check failure on line 21 in driver/netconf/message.go

View workflow job for this annotation

GitHub Actions / unit-test (macos-latest, 1.22)

paramTypeCombine: func(v string, forceSelfClosingTags bool, excludeHeader bool) (*serializedInput, error) could be replaced with func(v string, forceSelfClosingTags, excludeHeader bool) (*serializedInput, error) (gocritic)
serialized := &serializedInput{}

msg, err := xml.Marshal(m)
if err != nil {
return nil, err
}

msg = append([]byte(xmlHeader), msg...)
if !excludeHeader {
msg = append([]byte(xmlHeader), msg...)
}

if forceSelfClosingTags {
msg = ForceSelfClosingTags(msg)
Expand Down
2 changes: 1 addition & 1 deletion driver/netconf/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (d *Driver) sendRPC(
d.Logger.Debug("ForceSelfClosingTags is true, enforcing...")
}

serialized, err := m.serialize(d.SelectedVersion, d.ForceSelfClosingTags)
serialized, err := m.serialize(d.SelectedVersion, d.ForceSelfClosingTags, d.ExcludeHeader)
if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions driver/options/netconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,19 @@ func WithNetconfForceSelfClosingTags() util.Option {
return nil
}
}

// WithNetconfExcludeHeader excludes the XML header from the NETCONF message.
// This is useful for devices that do not support the XML header.
func WithNetconfExcludeHeader() util.Option {
return func(o interface{}) error {
d, ok := o.(*netconf.Driver)

if !ok {
return util.ErrIgnoredOption
}

d.ExcludeHeader = true

return nil
}
}

0 comments on commit bf40d63

Please sign in to comment.