No longer need to manually handle introspection subpaths

socks-filter
Bruce Leidl 9 years ago
parent 6a5a6f08e7
commit 807d18770a

@ -2,9 +2,7 @@ package main
import ( import (
"errors" "errors"
"fmt"
"path" "path"
"strings"
"github.com/godbus/dbus" "github.com/godbus/dbus"
"github.com/godbus/dbus/introspect" "github.com/godbus/dbus/introspect"
@ -82,44 +80,15 @@ func newDbusServer() (*dbusServer, error) {
if err := conn.Export(ds, objectPath, interfaceName); err != nil { if err := conn.Export(ds, objectPath, interfaceName); err != nil {
return nil, err return nil, err
} }
if err := conn.Export(introspect.Introspectable(introspectXml), objectPath, "org.freedesktop.DBus.Introspectable"); err != nil {
ps := strings.Split(objectPath, "/")
path := "/"
for _, p := range ps {
if len(path) > 1 {
path += "/"
}
path += p
if err := conn.Export(ds, dbus.ObjectPath(path), "org.freedesktop.DBus.Introspectable"); err != nil {
return nil, err return nil, err
} }
}
ds.conn = conn ds.conn = conn
ds.prompter = newPrompter(conn) ds.prompter = newPrompter(conn)
return ds, nil return ds, nil
} }
func (ds *dbusServer) Introspect(msg dbus.Message) (string, *dbus.Error) {
path := string(msg.Headers[dbus.FieldPath].Value().(dbus.ObjectPath))
if path == objectPath {
return introspectXml, nil
}
parts := strings.Split(objectPath, "/")
current := "/"
for i := 0; i < len(parts)-1; i++ {
if len(current) > 1 {
current += "/"
}
current += parts[i]
if path == current {
next := parts[i+1]
return fmt.Sprintf("<node><node name=\"%s\"/></node>", next), nil
}
}
return "", nil
}
func (ds *dbusServer) SetEnabled(flag bool) *dbus.Error { func (ds *dbusServer) SetEnabled(flag bool) *dbus.Error {
log.Debug("SetEnabled(%v) called", flag) log.Debug("SetEnabled(%v) called", flag)
ds.fw.setEnabled(flag) ds.fw.setEnabled(flag)

Loading…
Cancel
Save