Sending to the self number (+XXXX) now behaves the same as the `--note-to-self` parameter. To get the previous
behavior, the `--notify-self` parameter can be added
- New `--unrestricted-unidentified-sender` parameter for `updateAccount command`
+- New `--bus-name` parameter for `daemon` command to use another D-Bus bus name
### Improved
## [0.12.8] - 2024-02-06
### Fixes
+
- Update user agent
## [0.12.7] - 2023-12-15
*--dbus-system*::
Make request via system dbus.
+*--bus-name*::
+Connect to another D-Bus bus name than the default.
+
*-o* OUTPUT-MODE, *--output* OUTPUT-MODE::
Specify if you want commands to output in either "plain-text" mode or in "json".
Defaults to "plain-text"
Export DBus interface on system bus. +
See **signal-cli-dbus**(5) for info on the dbus interface.
+*--bus-name*::
+Claim another D-Bus bus name than the default.
+
*--ignore-attachments*::
Don’t download attachments of received messages.
.dest("global-dbus-system")
.help("Make request via system dbus.")
.action(Arguments.storeTrue());
+ parser.addArgument("--bus-name")
+ .dest("global-bus-name")
+ .setDefault(DbusConfig.getBusname())
+ .help("Specify the D-Bus bus name to connect to.");
parser.addArgument("-o", "--output")
.help("Choose to output in plain text or JSON")
final var useDbus = Boolean.TRUE.equals(ns.getBoolean("global-dbus"));
final var useDbusSystem = Boolean.TRUE.equals(ns.getBoolean("global-dbus-system"));
if (useDbus || useDbusSystem) {
+ final var busName = ns.getString("global-bus-name");
// If account is null, it will connect to the default object path
- initDbusClient(command, account, useDbusSystem, commandHandler);
+ initDbusClient(command, account, useDbusSystem, busName, commandHandler);
return;
}
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
+import org.asamk.signal.DbusConfig;
import org.asamk.signal.OutputType;
import org.asamk.signal.ReceiveMessageHandler;
import org.asamk.signal.Shutdown;
subparser.addArgument("--dbus-system", "--system")
.action(Arguments.storeTrue())
.help("Expose a DBus interface on the system bus.");
+ subparser.addArgument("--bus-name")
+ .setDefault(DbusConfig.getBusname())
+ .help("Specify the D-Bus bus name to connect to.");
subparser.addArgument("--socket")
.nargs("?")
.type(File.class)
final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));
if (isDbusSystem) {
- daemonHandler.runDbus(true);
+ final var busName = ns.getString("bus-name");
+ daemonHandler.runDbus(true, busName);
}
final var isDbusSession = Boolean.TRUE.equals(ns.getBoolean("dbus"));
- if (isDbusSession || (
- !isDbusSystem
- && socketFile == null
- && tcpAddress == null
- && httpAddress == null
- && inheritedChannel == null
- )) {
+ if (isDbusSession) {
+ final var busName = ns.getString("bus-name");
+ daemonHandler.runDbus(false, busName);
+ }
+
+ if (!isDbusSystem
+ && !isDbusSession
+ && socketFile == null
+ && tcpAddress == null
+ && httpAddress == null
+ && inheritedChannel == null) {
logger.warn(
"Running daemon command without explicit mode is deprecated. Use --dbus to use the dbus interface.");
- daemonHandler.runDbus(false);
+ daemonHandler.runDbus(false, DbusConfig.getBusname());
}
}
public abstract void runSocket(ServerSocketChannel serverChannel) throws CommandException;
- public abstract void runDbus(boolean isDbusSystem) throws CommandException;
+ public abstract void runDbus(boolean isDbusSystem, final String busname) throws CommandException;
public abstract void runHttp(InetSocketAddress address) throws CommandException;
}
@Override
- public void runDbus(final boolean isDbusSystem) throws CommandException {
- runDbus(new DbusHandler(isDbusSystem, m, receiveMode != ReceiveMode.ON_START));
+ public void runDbus(final boolean isDbusSystem, final String busname) throws CommandException {
+ runDbus(new DbusHandler(isDbusSystem, busname, m, receiveMode != ReceiveMode.ON_START));
}
@Override
}
@Override
- public void runDbus(final boolean isDbusSystem) throws CommandException {
- runDbus(new DbusHandler(isDbusSystem, c, receiveMode != ReceiveMode.ON_START));
+ public void runDbus(final boolean isDbusSystem, final String busname) throws CommandException {
+ runDbus(new DbusHandler(isDbusSystem, busname, c, receiveMode != ReceiveMode.ON_START));
}
@Override
public class DbusCommandHandler {
public static void initDbusClient(
- final Command command, final String account, final boolean systemBus, final CommandHandler commandHandler
+ final Command command,
+ final String account,
+ final boolean systemBus,
+ final String busname,
+ final CommandHandler commandHandler
) throws CommandException {
try {
final var busType = systemBus ? DBusConnection.DBusBusType.SYSTEM : DBusConnection.DBusBusType.SESSION;
try (var dBusConn = DBusConnectionBuilder.forType(busType).build()) {
- handleCommand(command, account, dBusConn, commandHandler);
+ handleCommand(command, account, dBusConn, busname, commandHandler);
}
} catch (ServiceUnknown e) {
throw new UserErrorException("signal-cli DBus daemon not running on "
final Command command,
final String account,
final DBusConnection dBusConn,
+ final String busname,
final CommandHandler commandHandler
) throws CommandException, DBusException {
try {
throw new UserErrorException("You cannot specify a account (phone number) when linking");
}
- handleProvisioningCommand(c, dBusConn, commandHandler);
+ handleProvisioningCommand(c, dBusConn, busname, commandHandler);
return;
}
if (account == null && command instanceof MultiLocalCommand c) {
- handleMultiLocalCommand(c, dBusConn, commandHandler);
+ handleMultiLocalCommand(c, dBusConn, busname, commandHandler);
return;
}
if (account != null && command instanceof RegistrationCommand c) {
- handleRegistrationCommand(c, account, dBusConn, commandHandler);
+ handleRegistrationCommand(c, account, dBusConn, busname, commandHandler);
return;
}
if (!(command instanceof LocalCommand localCommand)) {
throw new UserErrorException("Command only works in multi-account mode");
}
- var accountObjectPath = account == null ? tryGetSingleAccountObjectPath(dBusConn) : null;
+ var accountObjectPath = account == null ? tryGetSingleAccountObjectPath(dBusConn, busname) : null;
if (accountObjectPath == null) {
accountObjectPath = DbusConfig.getObjectPath(account);
}
- handleLocalCommand(localCommand, accountObjectPath, dBusConn, commandHandler);
+ handleLocalCommand(localCommand, accountObjectPath, dBusConn, busname, commandHandler);
} catch (UnsupportedOperationException e) {
throw new UserErrorException("Command is not yet implemented via dbus", e);
} catch (DBusExecutionException e) {
}
}
- private static String tryGetSingleAccountObjectPath(final DBusConnection dBusConn) throws DBusException, CommandException {
- var control = dBusConn.getRemoteObject(DbusConfig.getBusname(),
- DbusConfig.getObjectPath(),
- SignalControl.class);
+ private static String tryGetSingleAccountObjectPath(
+ final DBusConnection dBusConn, final String busname
+ ) throws DBusException, CommandException {
+ var control = dBusConn.getRemoteObject(busname, DbusConfig.getObjectPath(), SignalControl.class);
try {
final var accounts = control.listAccounts();
if (accounts.isEmpty()) {
}
private static void handleMultiLocalCommand(
- final MultiLocalCommand c, final DBusConnection dBusConn, final CommandHandler commandHandler
+ final MultiLocalCommand c,
+ final DBusConnection dBusConn,
+ final String busname,
+ final CommandHandler commandHandler
) throws CommandException, DBusException {
- final var signalControl = dBusConn.getRemoteObject(DbusConfig.getBusname(),
- DbusConfig.getObjectPath(),
- SignalControl.class);
- try (final var multiAccountManager = new DbusMultiAccountManagerImpl(signalControl, dBusConn)) {
+ final var signalControl = dBusConn.getRemoteObject(busname, DbusConfig.getObjectPath(), SignalControl.class);
+ try (final var multiAccountManager = new DbusMultiAccountManagerImpl(signalControl, dBusConn, busname)) {
commandHandler.handleMultiLocalCommand(c, multiAccountManager);
}
}
final LocalCommand c,
String accountObjectPath,
final DBusConnection dBusConn,
+ final String busname,
final CommandHandler commandHandler
) throws CommandException, DBusException {
- var signal = dBusConn.getRemoteObject(DbusConfig.getBusname(), accountObjectPath, Signal.class);
- try (final var manager = new DbusManagerImpl(signal, dBusConn)) {
+ var signal = dBusConn.getRemoteObject(busname, accountObjectPath, Signal.class);
+ try (final var manager = new DbusManagerImpl(signal, dBusConn, busname)) {
commandHandler.handleLocalCommand(c, manager);
}
}
final RegistrationCommand c,
String account,
final DBusConnection dBusConn,
+ final String busname,
final CommandHandler commandHandler
) throws CommandException, DBusException {
- final var signalControl = dBusConn.getRemoteObject(DbusConfig.getBusname(),
- DbusConfig.getObjectPath(),
- SignalControl.class);
+ final var signalControl = dBusConn.getRemoteObject(busname, DbusConfig.getObjectPath(), SignalControl.class);
try (final var registrationManager = new DbusRegistrationManagerImpl(account, signalControl, dBusConn)) {
commandHandler.handleRegistrationCommand(c, registrationManager);
}
}
private static void handleProvisioningCommand(
- final ProvisioningCommand c, final DBusConnection dBusConn, final CommandHandler commandHandler
+ final ProvisioningCommand c,
+ final DBusConnection dBusConn,
+ final String busname,
+ final CommandHandler commandHandler
) throws CommandException, DBusException {
- final var signalControl = dBusConn.getRemoteObject(DbusConfig.getBusname(),
- DbusConfig.getObjectPath(),
- SignalControl.class);
+ final var signalControl = dBusConn.getRemoteObject(busname, DbusConfig.getObjectPath(), SignalControl.class);
final var provisioningManager = new DbusProvisioningManagerImpl(signalControl, dBusConn);
commandHandler.handleProvisioningCommand(c, provisioningManager);
}
private final boolean isDbusSystem;
private DBusConnection dBusConnection;
+ private final String busname;
private final List<AutoCloseable> closeables = new ArrayList<>();
private final DbusRunner dbusRunner;
private final boolean noReceiveOnStart;
- public DbusHandler(final boolean isDbusSystem, final Manager m, final boolean noReceiveOnStart) {
+ public DbusHandler(
+ final boolean isDbusSystem, final String busname, final Manager m, final boolean noReceiveOnStart
+ ) {
this.isDbusSystem = isDbusSystem;
this.dbusRunner = (connection) -> {
try {
}
};
this.noReceiveOnStart = noReceiveOnStart;
+ this.busname = busname;
}
- public DbusHandler(final boolean isDbusSystem, final MultiAccountManager c, final boolean noReceiveOnStart) {
+ public DbusHandler(
+ final boolean isDbusSystem,
+ final String busname,
+ final MultiAccountManager c,
+ final boolean noReceiveOnStart
+ ) {
this.isDbusSystem = isDbusSystem;
this.dbusRunner = (connection) -> {
final var signalControl = new DbusSignalControlImpl(c, DbusConfig.getObjectPath());
}
};
this.noReceiveOnStart = noReceiveOnStart;
+ this.busname = busname;
}
public void init() throws CommandException {
throw new AssertionError("DbusHandler already initialized");
}
final var busType = isDbusSystem ? DBusConnection.DBusBusType.SYSTEM : DBusConnection.DBusBusType.SESSION;
- logger.debug("Starting DBus server on {} bus: {}", busType, DbusConfig.getBusname());
+ logger.debug("Starting DBus server on {} bus: {}", busType, busname);
try {
dBusConnection = DBusConnectionBuilder.forType(busType).build();
dbusRunner.run(dBusConnection);
}
try {
- dBusConnection.requestBusName(DbusConfig.getBusname());
+ dBusConnection.requestBusName(busname);
} catch (DBusException e) {
throw new UnexpectedErrorException("Dbus command failed, maybe signal-cli dbus daemon is already running: "
+ e.getMessage(), e);
}
- logger.info("Started DBus server on {} bus: {}", busType, DbusConfig.getBusname());
+ logger.info("Started DBus server on {} bus: {}", busType, busname);
}
@Override
package org.asamk.signal.dbus;
import org.asamk.Signal;
-import org.asamk.signal.DbusConfig;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.AlreadyReceivingException;
import org.asamk.signal.manager.api.AttachmentInvalidException;
private final Set<ReceiveMessageHandler> weakHandlers = new HashSet<>();
private final Set<ReceiveMessageHandler> messageHandlers = new HashSet<>();
private final List<Runnable> closedListeners = new ArrayList<>();
+ private final String busname;
private DBusSigHandler<Signal.MessageReceivedV2> dbusMsgHandler;
private DBusSigHandler<Signal.EditMessageReceived> dbusEditMsgHandler;
private DBusSigHandler<Signal.ReceiptReceivedV2> dbusRcptHandler;
private DBusSigHandler<Signal.SyncMessageReceivedV2> dbusSyncHandler;
- public DbusManagerImpl(final Signal signal, DBusConnection connection) {
+ public DbusManagerImpl(final Signal signal, DBusConnection connection, final String busname) {
this.signal = signal;
this.connection = connection;
+ this.busname = busname;
}
@Override
private <T extends DBusInterface> T getRemoteObject(final DBusPath path, final Class<T> type) {
try {
- return connection.getRemoteObject(DbusConfig.getBusname(), path.getPath(), type);
+ return connection.getRemoteObject(busname, path.getPath(), type);
} catch (DBusException e) {
throw new AssertionError(e);
}
import org.asamk.Signal;
import org.asamk.SignalControl;
-import org.asamk.signal.DbusConfig;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.MultiAccountManager;
import org.asamk.signal.manager.ProvisioningManager;
// TODO add listeners for added/removed accounts
private final Set<Consumer<Manager>> onManagerAddedHandlers = new HashSet<>();
private final Set<Consumer<Manager>> onManagerRemovedHandlers = new HashSet<>();
+ private final String busname;
- public DbusMultiAccountManagerImpl(final SignalControl signalControl, DBusConnection connection) {
+ public DbusMultiAccountManagerImpl(
+ final SignalControl signalControl, DBusConnection connection, final String busname
+ ) {
this.signalControl = signalControl;
this.connection = connection;
+ this.busname = busname;
}
@Override
public List<Manager> getManagers() {
return signalControl.listAccounts()
.stream()
- .map(a -> (Manager) new DbusManagerImpl(getRemoteObject(a, Signal.class), connection))
+ .map(a -> (Manager) new DbusManagerImpl(getRemoteObject(a, Signal.class), connection, busname))
.toList();
}
@Override
public Manager getManager(final String phoneNumber) {
- return new DbusManagerImpl(getRemoteObject(signalControl.getAccount(phoneNumber), Signal.class), connection);
+ return new DbusManagerImpl(getRemoteObject(signalControl.getAccount(phoneNumber), Signal.class),
+ connection,
+ busname);
}
@Override
private <T extends DBusInterface> T getRemoteObject(final DBusPath path, final Class<T> type) {
try {
- return connection.getRemoteObject(DbusConfig.getBusname(), path.getPath(), type);
+ return connection.getRemoteObject(busname, path.getPath(), type);
} catch (DBusException e) {
throw new AssertionError(e);
}