Documentation ¶
Overview ¶
Package schema provides the NETCONF XML schema object and corresponding parser.
Schema objects are constructed in terms of received XML tokens. The first XML token read from the input causes the schema's root node children to be scanned for a child schema node matching the received XML token. Matches can be simple or more elaborate.
There exist different schema objects for parsing NETCONF client sessions versus server sessions. A NETCONF parser is constructed with a schema object and a standard-library XML decoder to read tokens from.
The parser allows registration of callbacks for parser events which facilitate processing of a NETCONF XML session, as triggered by schema node events upon the client or server session schema object.
Schema processing ¶
Each call to the ParseSchemaXML function made by the state machine will consume a single XML token from the input reader. If an error occurs reading the token, the state machine will exit and errors other than EOF will be set on the Error struct field of the parser state machine.
If there is no error, depending on the XML token type received the following occurs;
xml.StartElement If a matching child node is found by XML name, the tokenize callback is run. The parser will change the context node to the matched node and the next state will consume another token. xml.CharData If a matching child node is found by type (NodeTypeText), its callback is run. The parser will not change the context node (as CharData tokens have no element children), the will next consume another token. xml.EndElement If a matching child node is found by XML name, the end-element callback is run. The parser will change the context node to the parent element schema node and will next consume another token.
NETCONF Session Callbacks ¶
Parser callbacks (described above) are registered using ParserOption, including WithRemoteCapabilities.
Index ¶
- func ParseSchemaXML(n *xmlstream.Node, d *xml.Decoder, es EventSender) xmlstream.StateFn
- func ValidateSchema(ctx context.Context, n *xmlstream.Node, es EventSender)
- type ConstraintError
- type EventReceiver
- type EventSendReceiver
- type EventSender
- type NETCONFSchema
- type Option
- type Parser
- type ParserEvent
- type ParserOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSchemaXML ¶
ParseSchemaXML returns a state machine function which consumes the next XML token from d given the context schema node n. events is the channel to receive events such as parsing errors and must be consumed concurrently.
func ValidateSchema ¶
func ValidateSchema(ctx context.Context, n *xmlstream.Node, es EventSender)
Types ¶
type ConstraintError ¶
type ConstraintError struct { Node *xmlstream.Node // Node is the schema node the constraint failed upon Name string // Name is the constraint which failed Message string Args interface{} Token xml.Token }
func IsConstraintError ¶
func IsConstraintError(err error) (ConstraintError, bool)
func (ConstraintError) Error ¶
func (e ConstraintError) Error() string
type EventReceiver ¶
type EventReceiver interface { Init(context.Context) error RemoteCapabilities(context.Context, []string) RemoteSessionID(context.Context, string) HelloReceived(context.Context) RPC(context.Context, xml.StartElement) RPCError(context.Context, xml.StartElement) RPCReply(context.Context, xml.StartElement) Notification(context.Context, xml.StartElement) Finished(context.Context, error) }
EventReceiver is the interface for handlers of NETCONF Schema events.
type EventSendReceiver ¶
type EventSendReceiver interface { EventSender EventReceiver }
EventSendReceiver is the combined event sender/receiver interface, used by parsers
type EventSender ¶
EventSender is the interface for sending errors and other events to the (running) schema parser.
type NETCONFSchema ¶
type NETCONFSchema struct {
// contains filtered or unexported fields
}
func NewClientSchema ¶
func NewClientSchema(opts ...Option) *NETCONFSchema
func NewServerSchema ¶
func NewServerSchema(opts ...Option) *NETCONFSchema
func (*NETCONFSchema) Bind ¶
func (s *NETCONFSchema) Bind(ev EventSendReceiver) *xmlstream.Node
type Option ¶
type Option func(*NETCONFSchema)
type Parser ¶
type Parser struct { Schema *NETCONFSchema EV EventSendReceiver Cancel context.CancelFunc SM *xmlstream.StateMachine // contains filtered or unexported fields }
Parser is a NETCONF stream parser conforming to a schema.
Schema must be a non-nil client or server schema object.
func (*Parser) Run ¶
Run the parser using the provided context and the XML decoder. Events will be sent concurrently to the events channel, which must not be nil.
If there is no initialization error, will return nil after starting the parser in a goroutine. Once running, call Wait() to determine when the parser has completed processing input. Schema validation will be performed by the parser after processing completes.
type ParserEvent ¶
type ParserEvent struct { Callback func() Err error }
ParserEvent is a schema parsing event
type ParserOption ¶
type ParserOption func(*Parser)
ParserOption is a NETCONF parser constructor option.