v2.3.3 Fixed Chinese input and gtk3 issues for linux packagin

This commit is contained in:
杨红岩 2023-01-10 21:15:56 +08:00
parent 851cb82aed
commit bc988d1885
16 changed files with 159 additions and 133 deletions

View File

@ -176,10 +176,9 @@ func (conn *Conn) tryAuth(m Auth, state authState, in *bufio.Reader) (error, boo
return err, false
}
state = waitingForReject
} else {
conn.uuid = string(s[1])
return nil, true
}
conn.uuid = string(s[1])
return nil, true
case state == waitingForData:
err = authWriteLine(conn.transport, []byte("ERROR"))
if err != nil {
@ -192,10 +191,9 @@ func (conn *Conn) tryAuth(m Auth, state authState, in *bufio.Reader) (error, boo
return err, false
}
state = waitingForReject
} else {
conn.uuid = string(s[1])
return nil, true
}
conn.uuid = string(s[1])
return nil, true
case state == waitingForOk && string(s[0]) == "DATA":
err = authWriteLine(conn.transport, []byte("DATA"))
if err != nil {

View File

@ -169,7 +169,7 @@ func Connect(address string, opts ...ConnOption) (*Conn, error) {
// SystemBusPrivate returns a new private connection to the system bus.
// Note: this connection is not ready to use. One must perform Auth and Hello
// on the connection before it is usable.
// on the connection before it is useable.
func SystemBusPrivate(opts ...ConnOption) (*Conn, error) {
return Dial(getSystemBusPlatformAddress(), opts...)
}
@ -284,6 +284,10 @@ func newConn(tr transport, opts ...ConnOption) (*Conn, error) {
conn.ctx = context.Background()
}
conn.ctx, conn.cancelCtx = context.WithCancel(conn.ctx)
go func() {
<-conn.ctx.Done()
conn.Close()
}()
conn.calls = newCallTracker()
if conn.handler == nil {
@ -298,11 +302,6 @@ func newConn(tr transport, opts ...ConnOption) (*Conn, error) {
conn.outHandler = &outputHandler{conn: conn}
conn.names = newNameTracker()
conn.busObj = conn.Object("org.freedesktop.DBus", "/org/freedesktop/DBus")
go func() {
<-conn.ctx.Done()
conn.Close()
}()
return conn, nil
}
@ -551,11 +550,6 @@ func (conn *Conn) send(ctx context.Context, msg *Message, ch chan *Call) *Call {
call.ctx = ctx
call.ctxCanceler = canceler
conn.calls.track(msg.serial, call)
if ctx.Err() != nil {
// short path: don't even send the message if context already cancelled
conn.calls.handleSendError(msg, ctx.Err())
return call
}
go func() {
<-ctx.Done()
conn.calls.handleSendError(msg, ctx.Err())
@ -655,9 +649,7 @@ func (conn *Conn) RemoveMatchSignalContext(ctx context.Context, options ...Match
// Signal registers the given channel to be passed all received signal messages.
//
// Multiple of these channels can be registered at the same time. The channel is
// closed if the Conn is closed; it should not be closed by the caller before
// RemoveSignal was called on it.
// Multiple of these channels can be registered at the same time.
//
// These channels are "overwritten" by Eavesdrop; i.e., if there currently is a
// channel for eavesdropped messages, this channel receives all signals, and
@ -773,12 +765,7 @@ func getKey(s, key string) string {
for _, keyEqualsValue := range strings.Split(s, ",") {
keyValue := strings.SplitN(keyEqualsValue, "=", 2)
if len(keyValue) == 2 && keyValue[0] == key {
val, err := UnescapeBusAddressValue(keyValue[1])
if err != nil {
// No way to return an error.
return ""
}
return val
return keyValue[1]
}
}
return ""

View File

@ -54,7 +54,7 @@ func tryDiscoverDbusSessionBusAddress() string {
if runUserBusFile := path.Join(runtimeDirectory, "bus"); fileExists(runUserBusFile) {
// if /run/user/<uid>/bus exists, that file itself
// *is* the unix socket, so return its path
return fmt.Sprintf("unix:path=%s", EscapeBusAddressValue(runUserBusFile))
return fmt.Sprintf("unix:path=%s", runUserBusFile)
}
if runUserSessionDbusFile := path.Join(runtimeDirectory, "dbus-session"); fileExists(runUserSessionDbusFile) {
// if /run/user/<uid>/dbus-session exists, it's a
@ -85,6 +85,9 @@ func getRuntimeDirectory() (string, error) {
}
func fileExists(filename string) bool {
_, err := os.Stat(filename)
return !os.IsNotExist(err)
if _, err := os.Stat(filename); !os.IsNotExist(err) {
return true
} else {
return false
}
}

View File

@ -122,11 +122,8 @@ func isConvertibleTo(dest, src reflect.Type) bool {
case dest.Kind() == reflect.Slice:
return src.Kind() == reflect.Slice &&
isConvertibleTo(dest.Elem(), src.Elem())
case dest.Kind() == reflect.Ptr:
dest = dest.Elem()
return isConvertibleTo(dest, src)
case dest.Kind() == reflect.Struct:
return src == interfacesType || dest.Kind() == src.Kind()
return src == interfacesType
default:
return src.ConvertibleTo(dest)
}
@ -277,8 +274,13 @@ func storeSliceIntoInterface(dest, src reflect.Value) error {
func storeSliceIntoSlice(dest, src reflect.Value) error {
if dest.IsNil() || dest.Len() < src.Len() {
dest.Set(reflect.MakeSlice(dest.Type(), src.Len(), src.Cap()))
} else if dest.Len() > src.Len() {
dest.Set(dest.Slice(0, src.Len()))
}
if dest.Len() != src.Len() {
return fmt.Errorf(
"dbus.Store: type mismatch: "+
"slices are different lengths "+
"need: %d have: %d",
src.Len(), dest.Len())
}
for i := 0; i < src.Len(); i++ {
err := store(dest.Index(i), getVariantValue(src.Index(i)))

View File

@ -10,10 +10,8 @@ value.
Conversion Rules
For outgoing messages, Go types are automatically converted to the
corresponding D-Bus types. See the official specification at
https://dbus.freedesktop.org/doc/dbus-specification.html#type-system for more
information on the D-Bus type system. The following types are directly encoded
as their respective D-Bus equivalents:
corresponding D-Bus types. The following types are directly encoded as their
respective D-Bus equivalents:
Go type | D-Bus type
------------+-----------
@ -41,8 +39,8 @@ Maps encode as DICTs, provided that their key type can be used as a key for
a DICT.
Structs other than Variant and Signature encode as a STRUCT containing their
exported fields in order. Fields whose tags contain `dbus:"-"` and unexported
fields will be skipped.
exported fields. Fields whose tags contain `dbus:"-"` and unexported fields will
be skipped.
Pointers encode as the value they're pointed to.

View File

@ -3,7 +3,6 @@ package dbus
import (
"errors"
"fmt"
"os"
"reflect"
"strings"
)
@ -210,23 +209,28 @@ func (conn *Conn) handleCall(msg *Message) {
}
reply.Headers[FieldSignature] = MakeVariant(SignatureOf(reply.Body...))
if err := reply.IsValid(); err != nil {
fmt.Fprintf(os.Stderr, "dbus: dropping invalid reply to %s.%s on obj %s: %s\n", ifaceName, name, path, err)
} else {
conn.sendMessageAndIfClosed(reply, nil)
}
conn.sendMessageAndIfClosed(reply, nil)
}
}
// Emit emits the given signal on the message bus. The name parameter must be
// formatted as "interface.member", e.g., "org.freedesktop.DBus.NameLost".
func (conn *Conn) Emit(path ObjectPath, name string, values ...interface{}) error {
if !path.IsValid() {
return errors.New("dbus: invalid object path")
}
i := strings.LastIndex(name, ".")
if i == -1 {
return errors.New("dbus: invalid method name")
}
iface := name[:i]
member := name[i+1:]
if !isValidMember(member) {
return errors.New("dbus: invalid method name")
}
if !isValidInterface(iface) {
return errors.New("dbus: invalid interface name")
}
msg := new(Message)
msg.Type = TypeSignal
msg.Headers = make(map[HeaderField]Variant)
@ -237,9 +241,6 @@ func (conn *Conn) Emit(path ObjectPath, name string, values ...interface{}) erro
if len(values) > 0 {
msg.Headers[FieldSignature] = MakeVariant(SignatureOf(values...))
}
if err := msg.IsValid(); err != nil {
return err
}
var closed bool
conn.sendMessageAndIfClosed(msg, func() {

View File

@ -2,24 +2,27 @@ package dbus
import (
"os"
"os/user"
"sync"
)
var (
homeDir string
homeDirLock sync.Mutex
)
// Get returns the home directory of the current user, which is usually the
// value of HOME environment variable. In case it is not set or empty, os/user
// package is used.
//
// If linking statically with cgo enabled against glibc, make sure the
// osusergo build tag is used.
//
// If needing to do nss lookups, do not disable cgo or set osusergo.
func getHomeDir() string {
homeDir := os.Getenv("HOME")
homeDirLock.Lock()
defer homeDirLock.Unlock()
if homeDir != "" {
return homeDir
}
if u, err := user.Current(); err == nil {
return u.HomeDir
homeDir = os.Getenv("HOME")
if homeDir != "" {
return homeDir
}
return "/"
homeDir = lookupHomeDir()
return homeDir
}

15
vendor/github.com/godbus/dbus/v5/homedir_dynamic.go generated vendored Normal file
View File

@ -0,0 +1,15 @@
// +build !static_build
package dbus
import (
"os/user"
)
func lookupHomeDir() string {
u, err := user.Current()
if err != nil {
return "/"
}
return u.HomeDir
}

45
vendor/github.com/godbus/dbus/v5/homedir_static.go generated vendored Normal file
View File

@ -0,0 +1,45 @@
// +build static_build
package dbus
import (
"bufio"
"os"
"strconv"
"strings"
)
func lookupHomeDir() string {
myUid := os.Getuid()
f, err := os.Open("/etc/passwd")
if err != nil {
return "/"
}
defer f.Close()
s := bufio.NewScanner(f)
for s.Scan() {
if err := s.Err(); err != nil {
break
}
line := strings.TrimSpace(s.Text())
if line == "" {
continue
}
parts := strings.Split(line, ":")
if len(parts) >= 6 {
uid, err := strconv.Atoi(parts[2])
if err == nil && uid == myUid {
return parts[5]
}
}
}
// Default to / if we can't get a better value
return "/"
}

View File

@ -50,7 +50,7 @@ type Interface struct {
Annotations []Annotation `xml:"annotation"`
}
// Method describes a Method on an Interface as returned by an introspection.
// Method describes a Method on an Interface as retured by an introspection.
type Method struct {
Name string `xml:"name,attr"`
Args []Arg `xml:"arg"`

View File

@ -208,7 +208,7 @@ func DecodeMessageWithFDs(rd io.Reader, fds []int) (msg *Message, err error) {
// The possibly returned error can be an error of the underlying reader, an
// InvalidMessageError or a FormatError.
func DecodeMessage(rd io.Reader) (msg *Message, err error) {
return DecodeMessageWithFDs(rd, make([]int, 0))
return DecodeMessageWithFDs(rd, make([]int, 0));
}
type nullwriter struct{}
@ -227,8 +227,8 @@ func (msg *Message) CountFds() (int, error) {
}
func (msg *Message) EncodeToWithFDs(out io.Writer, order binary.ByteOrder) (fds []int, err error) {
if err := msg.validateHeader(); err != nil {
return nil, err
if err := msg.IsValid(); err != nil {
return make([]int, 0), err
}
var vs [7]interface{}
switch order {
@ -237,7 +237,7 @@ func (msg *Message) EncodeToWithFDs(out io.Writer, order binary.ByteOrder) (fds
case binary.BigEndian:
vs[0] = byte('B')
default:
return nil, errors.New("dbus: invalid byte order")
return make([]int, 0), errors.New("dbus: invalid byte order")
}
body := new(bytes.Buffer)
fds = make([]int, 0)
@ -284,13 +284,8 @@ func (msg *Message) EncodeTo(out io.Writer, order binary.ByteOrder) (err error)
}
// IsValid checks whether msg is a valid message and returns an
// InvalidMessageError or FormatError if it is not.
// InvalidMessageError if it is not.
func (msg *Message) IsValid() error {
var b bytes.Buffer
return msg.EncodeTo(&b, nativeEndian)
}
func (msg *Message) validateHeader() error {
if msg.Flags & ^(FlagNoAutoStart|FlagNoReplyExpected|FlagAllowInteractiveAuthorization) != 0 {
return InvalidMessageError("invalid flags")
}
@ -335,7 +330,6 @@ func (msg *Message) validateHeader() error {
return InvalidMessageError("missing signature")
}
}
return nil
}

View File

@ -126,9 +126,7 @@ const IntrospectDataString = `
// Prop represents a single property. It is used for creating a Properties
// value.
type Prop struct {
// Initial value. Must be a DBus-representable type. This is not modified
// after Properties has been initialized; use Get or GetMust to access the
// value.
// Initial value. Must be a DBus-representable type.
Value interface{}
// If true, the value can be modified by calls to Set.
@ -145,24 +143,6 @@ type Prop struct {
Callback func(*Change) *dbus.Error
}
// Introspection returns the introspection data for p.
// The "name" argument is used as the property's name in the resulting data.
func (p *Prop) Introspection(name string) introspect.Property {
var result = introspect.Property{Name: name, Type: dbus.SignatureOf(p.Value).String()}
if p.Writable {
result.Access = "readwrite"
} else {
result.Access = "read"
}
result.Annotations = []introspect.Annotation{
{
Name: "org.freedesktop.DBus.Property.EmitsChangedSignal",
Value: p.Emit.String(),
},
}
return result
}
// Change represents a change of a property by a call to Set.
type Change struct {
Props *Properties
@ -175,7 +155,7 @@ type Change struct {
// using the org.freedesktop.DBus.Properties interface. It is safe for
// concurrent use by multiple goroutines.
type Properties struct {
m Map
m map[string]map[string]*Prop
mut sync.RWMutex
conn *dbus.Conn
path dbus.ObjectPath
@ -185,7 +165,7 @@ type Properties struct {
// swallowing the error, shouldn't be used.
//
// Deprecated: use Export instead.
func New(conn *dbus.Conn, path dbus.ObjectPath, props Map) *Properties {
func New(conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop) *Properties {
p, err := Export(conn, path, props)
if err != nil {
return nil
@ -198,33 +178,15 @@ func New(conn *dbus.Conn, path dbus.ObjectPath, props Map) *Properties {
// second-level key is the name of the property. The returned structure will be
// exported as org.freedesktop.DBus.Properties on path.
func Export(
conn *dbus.Conn, path dbus.ObjectPath, props Map,
conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop,
) (*Properties, error) {
p := &Properties{m: copyProps(props), conn: conn, path: path}
p := &Properties{m: props, conn: conn, path: path}
if err := conn.Export(p, path, "org.freedesktop.DBus.Properties"); err != nil {
return nil, err
}
return p, nil
}
// Map is a helper type for supplying the configuration of properties to be handled.
type Map = map[string]map[string]*Prop
func copyProps(in Map) Map {
out := make(Map, len(in))
for intf, props := range in {
out[intf] = make(map[string]*Prop)
for name, prop := range props {
out[intf][name] = new(Prop)
*out[intf][name] = *prop
val := reflect.New(reflect.TypeOf(prop.Value))
val.Elem().Set(reflect.ValueOf(prop.Value))
out[intf][name].Value = val.Interface()
}
}
return out
}
// Get implements org.freedesktop.DBus.Properties.Get.
func (p *Properties) Get(iface, property string) (dbus.Variant, *dbus.Error) {
p.mut.RLock()
@ -237,7 +199,7 @@ func (p *Properties) Get(iface, property string) (dbus.Variant, *dbus.Error) {
if !ok {
return dbus.Variant{}, ErrPropNotFound
}
return dbus.MakeVariant(reflect.ValueOf(prop.Value).Elem().Interface()), nil
return dbus.MakeVariant(prop.Value), nil
}
// GetAll implements org.freedesktop.DBus.Properties.GetAll.
@ -250,7 +212,7 @@ func (p *Properties) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error)
}
rm := make(map[string]dbus.Variant, len(m))
for k, v := range m {
rm[k] = dbus.MakeVariant(reflect.ValueOf(v.Value).Elem().Interface())
rm[k] = dbus.MakeVariant(v.Value)
}
return rm, nil
}
@ -260,7 +222,7 @@ func (p *Properties) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error)
func (p *Properties) GetMust(iface, property string) interface{} {
p.mut.RLock()
defer p.mut.RUnlock()
return reflect.ValueOf(p.m[iface][property].Value).Elem().Interface()
return p.m[iface][property].Value
}
// Introspection returns the introspection data that represents the properties
@ -270,8 +232,20 @@ func (p *Properties) Introspection(iface string) []introspect.Property {
defer p.mut.RUnlock()
m := p.m[iface]
s := make([]introspect.Property, 0, len(m))
for name, prop := range m {
s = append(s, prop.Introspection(name))
for k, v := range m {
p := introspect.Property{Name: k, Type: dbus.SignatureOf(v.Value).String()}
if v.Writable {
p.Access = "readwrite"
} else {
p.Access = "read"
}
p.Annotations = []introspect.Annotation{
{
Name: "org.freedesktop.DBus.Property.EmitsChangedSignal",
Value: v.Emit.String(),
},
}
s = append(s, p)
}
return s
}
@ -280,6 +254,9 @@ func (p *Properties) Introspection(iface string) []introspect.Property {
// must already be locked.
func (p *Properties) set(iface, property string, v interface{}) error {
prop := p.m[iface][property]
if reflect.ValueOf(prop.Value).Kind() != reflect.Ptr {
prop.Value = reflect.New(reflect.TypeOf(prop.Value)).Interface()
}
err := dbus.Store([]interface{}{v}, prop.Value)
if err != nil {
return err
@ -341,8 +318,9 @@ func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error
func (p *Properties) SetMust(iface, property string, v interface{}) {
p.mut.Lock()
defer p.mut.Unlock() // unlock in case of panic
err := p.set(iface, property, v)
if err != nil {
prop := p.m[iface][property]
prop.Value = v
if err := p.emitChange(iface, property); err != nil {
panic(err)
}
}

View File

@ -63,7 +63,7 @@ type Method interface {
// any other decoding scheme.
type ArgumentDecoder interface {
// To decode the arguments of a method the sender and message are
// provided in case the semantics of the implementer provides access
// provided incase the semantics of the implementer provides access
// to these as part of the method invocation.
DecodeArguments(conn *Conn, sender string, msg *Message, args []interface{}) ([]interface{}, error)
}

View File

@ -102,7 +102,7 @@ func getSignature(t reflect.Type, depth *depthCounter) (sig string) {
}
}
if len(s) == 0 {
panic(InvalidTypeError{t})
panic("empty struct")
}
return "(" + s + ")"
case reflect.Array, reflect.Slice:

View File

@ -154,15 +154,17 @@ func (t *unixTransport) ReadMessage() (*Message, error) {
// substitute the values in the message body (which are indices for the
// array receiver via OOB) with the actual values
for i, v := range msg.Body {
switch index := v.(type) {
switch v.(type) {
case UnixFDIndex:
if uint32(index) >= unixfds {
j := v.(UnixFDIndex)
if uint32(j) >= unixfds {
return nil, InvalidMessageError("invalid index for unix fd")
}
msg.Body[i] = UnixFD(fds[index])
msg.Body[i] = UnixFD(fds[j])
case []UnixFDIndex:
fdArray := make([]UnixFD, len(index))
for k, j := range index {
idxArray := v.([]UnixFDIndex)
fdArray := make([]UnixFD, len(idxArray))
for k, j := range idxArray {
if uint32(j) >= unixfds {
return nil, InvalidMessageError("invalid index for unix fd")
}

View File

@ -49,7 +49,7 @@ func ParseVariant(s string, sig Signature) (Variant, error) {
}
// format returns a formatted version of v and whether this string can be parsed
// unambiguously.
// unambigously.
func (v Variant) format() (string, bool) {
switch v.sig.str[0] {
case 'b', 'i':