From eedb79dee2f9151e462c4292eea3bc1bf4aa9961 Mon Sep 17 00:00:00 2001 From: Jon Nightingale Date: Sun, 13 Oct 2024 10:52:54 +0100 Subject: [PATCH] fix list keys in xmlstore --- internal/xmlstore/xmlstore.go | 24 ++++++++++++++++++------ netconf_lib.go | 7 ++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/internal/xmlstore/xmlstore.go b/internal/xmlstore/xmlstore.go index 3dca5c1..dc20754 100644 --- a/internal/xmlstore/xmlstore.go +++ b/internal/xmlstore/xmlstore.go @@ -50,7 +50,11 @@ func (el xmlElement) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if err := e.EncodeToken(start); err != nil { return err } - e.EncodeElement(el.Children, start) + if el.Value != "" { + e.EncodeToken(xml.CharData(el.Value)) + } else { + e.EncodeElement(el.Children, start) + } return e.EncodeToken(start.End()) } @@ -66,8 +70,12 @@ func (el *xmlElement) insert(yangMod *yang.Entry, path []string) { } else { // Add new element, then insert into that // fmt.Printf("Adding %v to x%vx\n", ss[0], el.XMLName.Local) + nv := strings.Split(ss[0], "=") if el.XMLName.Local == "" { - el.XMLName.Local = ss[0] + el.XMLName.Local = nv[0] + if len(nv) > 1 { + el.Value = nv[1] + } el.XMLName.Space = yangMod.Namespace().Name el.Children = append(el.Children, &xmlElement{xml.Name{Space: "", Local: ss[1]}, "", []xmlElementInterface{}}) if len(ss) == 2 { @@ -75,11 +83,15 @@ func (el *xmlElement) insert(yangMod *yang.Entry, path []string) { } el.Children[len(el.Children)-1].insert(nil, ss[2:]) } else { - el.Children = append(el.Children, &xmlElement{xml.Name{ - Local: ss[0], + child := xmlElement{xml.Name{ + Local: nv[0], // Space: el.XMLName.Space - }, - "", []xmlElementInterface{}}) + }, "", []xmlElementInterface{}} + if len(nv) > 1 { + child.Value = nv[1] + } + + el.Children = append(el.Children, &child) if len(ss) == 1 { return } diff --git a/netconf_lib.go b/netconf_lib.go index 6fd9e91..90d6e4c 100644 --- a/netconf_lib.go +++ b/netconf_lib.go @@ -497,6 +497,10 @@ func getYangModule(s *netconf.Session, yangMod string) *yang.Module { fmt.Printf("Request reply error1: %v\n", error) return nil } + if reply.Errors != nil && len(reply.Errors) > 0 { + fmt.Printf("Request reply error1: %v\n", reply.Errors[0]) + return nil + } // log.Debugf("Request reply: %v, error: %v\n", reply.Data, error) // re, _ := regexp.Compile("\n#[0-9]+\n") // strs := re.FindAllStringSubmatch(reply.Data, 10) @@ -643,7 +647,8 @@ func sendNetconfRequest(s *netconf.Session, requestLine string, requestType requ } else if requestType == validate { error = s.Validate(context.Background(), netconf.Candidate) log.Debugf("Request reply: %v, error: %v\n", reply, error) - } else if requestType == getConf || requestType == getOper { + // } else if requestType == getConf || requestType == getOper { + } else { rpc := ncRequest reply, error = s.Do(context.Background(), &rpc) if error != nil {