Reply
deferred Body parsing doesn't work with multiple elements under the root.
#62
Labels
bug
Something isn't working
help wanted
Extra attention is needed
investigation
Needs some time to invesigate an isssue
The
<rpc-reply>
element defined in RFC6241 has really two uses.message-id
)So far this has been done with the
Reply
object by added aBody []byte
xml:,innerxmlto capture the remaining nodes to allowed for deferred xml deoding. Even the
Replystruct has a method called
Decodeused to decode the
Bodyinto a Go struct. This was very much modeled after jsons
json.RawMessage` API and assumed to work similarly.This works 90% of the time as the reply message is a single element and a single element looks like document to XML. This, however, breaks when there are multiple elements.
Multiple nodes
For example the following doesn't work: Assume the netconf server replies with the message
Because
encoding/xml
expects a document (i.e a single root element)Decode
method onReply
doesn't DO ANYTHING and just silently fails. The fields insideresp
are of the zero type and nothing happens.The RFC explicitly allows for this behavior:
https://www.rfc-editor.org/rfc/rfc6241#section-4.2 (emphasis mine):
This also comes up in a lot of
Junos
RPCs that may return a<ok/>
along with data elements (even though it's a bit redundant and against the RFSingle nodes as well
This also just breaks with a single element. We have defined in the library the following
If passed the same way into
reply.Decode()
(orsession.Call()
) the<ok/>
is never parsed and is always false. This only really works if the resp structure has aXMLNode
defined or the name of the struct itself is the single xml node.Potential fixes
The easy solution is to allow the user to re-decode the entire
rpc-reply
message. Elements<rpc-error>
can be omitted if the user doesn't want to parse it. This is probably the direction to go in and gives the most flexibility while fitting the original goals of this library.some sort of fancy "rewrapping" of objects to make them documents to allow for parsing (i.e adding a fake root node) to the input data and the parsing data to appease the decoder. This is probably doable but also needs a lot of testing around corner cases to work properly and is a bit too "weird"
Nothing. We return the bytes up to the caller to handle parsing (i.e parsing multiple "documents"). This seems the least useful and more hostile to the users of the library..
Either way I am glad I ran into this issue now as it will be a breaking API change to solve it.
The text was updated successfully, but these errors were encountered: