dbus

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 18 Imported by: 0

README

tinywasm/dbus

A minimal, zero-dependency Go client for the Linux D-Bus session bus.

Overview

tinywasm/dbus provides lightweight access to the Linux D-Bus session bus. It is specifically designed to support client operations needed for Secret Service interaction without bringing in large general-purpose D-Bus dependencies or external third-party packages.

Scope Boundary

In scope Out of scope
Connect to the session bus over a Unix socket System bus autolaunch, TCP transport
EXTERNAL SASL authentication DBUS_COOKIE_SHA1, ANONYMOUS
Method calls with reply Exporting objects, owning bus names
Receiving signals via AddMatch Introspection, properties beyond Get
Basic type set (byte, bool, uint32, string, ObjectPath, Variant, arrays, structs, dict entries) File descriptor passing, int16, double, unix_fd

Usage Example

package main

import (
	"fmt"
	"log"

	"github.com/tinywasm/dbus"
)

func main() {
	conn, err := dbus.SessionBus()
	if err != nil {
		log.Fatalf("failed to connect to session bus: %v", err)
	}
	defer conn.Close()

	obj := conn.Object("org.freedesktop.DBus", "/org/freedesktop/DBus")
	reply := obj.Call("org.freedesktop.DBus.GetId")
	if reply.Err != nil {
		log.Fatalf("method call failed: %v", reply.Err)
	}

	var id string
	if err := reply.Store(&id); err != nil {
		log.Fatalf("failed to store reply: %v", err)
	}

	fmt.Println("Session Bus ID:", id)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Store added in v0.1.0

func Store(src []any, dest ...any) error

Types

type CallError added in v0.1.0

type CallError struct {
	Name string // e.g. "org.freedesktop.DBus.Error.ServiceUnknown"
	Msg  string
}

func (*CallError) Error added in v0.1.0

func (e *CallError) Error() string

type Conn added in v0.1.0

type Conn struct {
	// contains filtered or unexported fields
}

func SessionBus added in v0.1.0

func SessionBus() (*Conn, error)

func (*Conn) AddMatch added in v0.1.0

func (c *Conn) AddMatch(rule string) error

func (*Conn) Close added in v0.1.0

func (c *Conn) Close() error

func (*Conn) Object added in v0.1.0

func (c *Conn) Object(dest string, path ObjectPath) *Object

func (*Conn) RemoveMatch added in v0.1.0

func (c *Conn) RemoveMatch(rule string) error

func (*Conn) Signals added in v0.1.0

func (c *Conn) Signals(ch chan<- *Signal)

type Error added in v0.1.0

type Error string
const (
	ErrNoSessionBus      Error = "dbus: DBUS_SESSION_BUS_ADDRESS is not set"
	ErrAuthFailed        Error = "dbus: EXTERNAL authentication rejected"
	ErrClosed            Error = "dbus: connection closed"
	ErrCallTimeout       Error = "dbus: call timed out"
	ErrUnsupportedType   Error = "dbus: unsupported type"
	ErrSignatureMismatch Error = "dbus: signature mismatch"
)

func (Error) Error added in v0.1.0

func (e Error) Error() string

type ErrorResponse added in v0.1.0

type ErrorResponse struct {
	Name string
	Body []any
}

func (*ErrorResponse) Error added in v0.1.0

func (e *ErrorResponse) Error() string

type Flags added in v0.1.0

type Flags byte
const (
	FlagNoReplyExpected Flags = 1 << iota
	FlagNoAutoStart
	FlagAllowInteractiveAuthorization
)

type FormatError added in v0.1.0

type FormatError string

func (FormatError) Error added in v0.1.0

func (e FormatError) Error() string

type HeaderField added in v0.1.0

type HeaderField byte
const (
	FieldPath HeaderField = 1 + iota
	FieldInterface
	FieldMember
	FieldErrorName
	FieldReplySerial
	FieldDestination
	FieldSender
	FieldSignature
	FieldUnixFDs
)

type InvalidMessageError added in v0.1.0

type InvalidMessageError string

func (InvalidMessageError) Error added in v0.1.0

func (e InvalidMessageError) Error() string

type InvalidTypeError added in v0.1.0

type InvalidTypeError struct {
	Type fmt.Stringer
}

func (InvalidTypeError) Error added in v0.1.0

func (e InvalidTypeError) Error() string

type Message added in v0.1.0

type Message struct {
	Type    Type
	Flags   Flags
	Headers map[HeaderField]Variant
	Body    []any
	// contains filtered or unexported fields
}

func DecodeMessage added in v0.1.0

func DecodeMessage(rd io.Reader) (msg *Message, err error)

func (*Message) EncodeTo added in v0.1.0

func (msg *Message) EncodeTo(out io.Writer, order binary.ByteOrder) (err error)

func (*Message) IsValid added in v0.1.0

func (msg *Message) IsValid() error

func (*Message) Serial added in v0.1.0

func (msg *Message) Serial() uint32

func (*Message) String added in v0.1.0

func (msg *Message) String() string

type Object added in v0.1.0

type Object struct {
	// contains filtered or unexported fields
}

func (*Object) Call added in v0.1.0

func (o *Object) Call(method string, args ...any) *Reply

func (*Object) GetProperty added in v0.1.0

func (o *Object) GetProperty(iface, name string) (Variant, error)

type ObjectPath added in v0.1.0

type ObjectPath string

ObjectPath is a D-Bus object path, e.g. "/org/freedesktop/secrets".

func (ObjectPath) IsValid added in v0.1.0

func (p ObjectPath) IsValid() bool

IsValid returns whether the object path is valid according to the spec.

type Reply added in v0.1.0

type Reply struct {
	Body []any
	Err  error
}

func (*Reply) Store added in v0.1.0

func (r *Reply) Store(dest ...any) error

type Signal added in v0.1.0

type Signal struct {
	Sender string
	Path   ObjectPath
	Name   string // "interface.Member"
	Body   []any
}

type Signature added in v0.1.0

type Signature struct {
	// contains filtered or unexported fields
}

Signature represents a correct type signature as specified by the D-Bus specification. The zero value represents the empty signature, "".

func ParseSignature added in v0.1.0

func ParseSignature(s string) (sig Signature, err error)

ParseSignature returns the signature represented by this string, or a SignatureError if the string is not a valid signature.

func ParseSignatureMust added in v0.1.0

func ParseSignatureMust(s string) Signature

ParseSignatureMust behaves like ParseSignature, except that it panics if s is not valid.

func SignatureOf added in v0.1.0

func SignatureOf(vs ...any) Signature

SignatureOf returns the concatenation of all the signatures of the given values. It panics if one of them is not representable in D-Bus.

func SignatureOfType added in v0.1.0

func SignatureOfType(t reflect.Type) Signature

SignatureOfType returns the signature of the given type. It panics if the type is not representable in D-Bus.

func (Signature) Empty added in v0.1.0

func (s Signature) Empty() bool

Empty returns whether the signature is the empty signature.

func (Signature) Single added in v0.1.0

func (s Signature) Single() bool

Single returns whether the signature represents a single, complete type.

func (Signature) String added in v0.1.0

func (s Signature) String() string

String returns the signature's string representation.

type SignatureError added in v0.1.0

type SignatureError struct {
	Sig    string
	Reason string
}

A SignatureError indicates that a signature passed to a function or received on a connection is not a valid signature.

func (SignatureError) Error added in v0.1.0

func (e SignatureError) Error() string

type Type added in v0.1.0

type Type byte
const (
	TypeMethodCall Type = 1 + iota
	TypeMethodReply
	TypeError
	TypeSignal
)

func (Type) String added in v0.1.0

func (t Type) String() string

type Variant added in v0.1.0

type Variant struct {
	// contains filtered or unexported fields
}

Variant represents the D-Bus variant type.

func MakeVariant added in v0.1.0

func MakeVariant(v any) Variant

MakeVariant converts the given value to a Variant.

func MakeVariantWithSignature added in v0.1.0

func MakeVariantWithSignature(v any, s Signature) Variant

MakeVariantWithSignature converts the given value to a Variant with specified signature.

func (Variant) Signature added in v0.1.0

func (v Variant) Signature() string

Signature returns the D-Bus signature of the underlying value of v.

func (Variant) String added in v0.1.0

func (v Variant) String() string

func (Variant) Value added in v0.1.0

func (v Variant) Value() any

Value returns the underlying value of v.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL