commit 1a7284815bb2a63aac6b726e9167baed4813aa95
parent 30f8a148ff551129b3ccc8f52e5dda1ec2104ee3
Author: Bernd Fix <brf@hoi-polloi.org>
Date: Fri, 11 Nov 2022 11:56:38 +0100
Plugin integration (ZoneMaster)
Diffstat:
2 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/src/gnunet/service/gns/rr/coexist.go b/src/gnunet/service/gns/rr/coexist.go
@@ -56,8 +56,13 @@ func CanCoexist(t enums.GNSType, list []*enums.GNSSpec, label string) (ok bool,
Flags: forced,
}
for i, e := range testList {
+ // skip unknown types
+ if rr = NilRR(e.Type); rr == nil {
+ return true, 0
+ }
+ // check replacement
testList[i] = eNew
- ok, forced = NilRR(e.Type).Coexist(testList, label)
+ ok, forced = rr.Coexist(testList, label)
if !ok {
return
}
diff --git a/src/gnunet/service/zonemaster/gui.go b/src/gnunet/service/zonemaster/gui.go
@@ -625,15 +625,23 @@ func (zm *ZoneMaster) editRec(w http.ResponseWriter, r *http.Request, data *NewE
if rec, err = zm.zdb.GetRecord(data.Ref); err != nil {
return
}
+ // default GUI dialog template name
+ dialog := "edit_rec"
+
+ // get possible plugin handler
+ plugin, ok := zm.hdlrs[rec.RType]
+ if ok {
+ // get custom edit dialog
+ _, dialog = plugin.TemplateNames()
+ }
// get prefix used for attributes and fields
pf, ok := dlgPrefix[rec.RType]
if !ok {
// no prefix defined; ask plugin
- inst, ok := zm.hdlrs[rec.RType]
- if !ok {
+ if plugin == nil {
return errors.New("no prefix defined for record type")
}
- pf = inst.Prefix(uint32(rec.RType)) + "_"
+ pf = plugin.Prefix(uint32(rec.RType)) + "_"
}
// save shared attributes
@@ -665,14 +673,22 @@ func (zm *ZoneMaster) editRec(w http.ResponseWriter, r *http.Request, data *NewE
if rec.Flags&enums.GNS_FLAG_CRITICAL != 0 {
data.Params[pf+"critical"] = "on"
}
- // get record instance
- var inst rr.RR
- if inst, err = rr.ParseRR(rec.RType, rec.Data); err == nil {
- // add RR attributes to list
- inst.ToMap(data.Params, pf)
+ // set record attributes
+ if plugin != nil {
+ var params map[string]string
+ params, err = plugin.ToMap(uint32(rec.RType), rec.Data)
+ for k, v := range params {
+ data.Params[k] = v
+ }
+ } else {
+ var inst rr.RR
+ if inst, err = rr.ParseRR(rec.RType, rec.Data); err == nil {
+ // add RR attributes to list
+ inst.ToMap(data.Params, pf)
+ }
}
// show dialog
- renderPage(w, data, "edit_rec")
+ renderPage(w, data, dialog)
return
}