- DBusConnection.DBusBusType busType;
- if (systemBus) {
- busType = DBusConnection.DBusBusType.SYSTEM;
- } else {
- busType = DBusConnection.DBusBusType.SESSION;
- }
- try (DBusConnection dBusConn = DBusConnection.getConnection(busType)) {
- Signal ts = dBusConn.getRemoteObject(DbusConfig.SIGNAL_BUSNAME,
- DbusConfig.SIGNAL_OBJECTPATH,
- Signal.class);
-
- return handleCommand(command, ns, ts, dBusConn);
- }
- } catch (DBusException | IOException e) {
- logger.error("Dbus client failed", e);
- return 3;
- }
- }
-
- private static Command getCommand(Namespace ns) {
- String commandKey = ns.getString("command");
- final Map<String, Command> commands = Commands.getCommands();
- if (!commands.containsKey(commandKey)) {
- return null;
- }
- return commands.get(commandKey);
- }
-
- private static int handleCommand(Command command, Namespace ns, Signal ts, DBusConnection dBusConn) {
- if (command instanceof ExtendedDbusCommand) {
- return ((ExtendedDbusCommand) command).handleCommand(ns, ts, dBusConn);
- } else if (command instanceof DbusCommand) {
- return ((DbusCommand) command).handleCommand(ns, ts);
- } else {
- System.err.println("Command is not yet implemented via dbus");
- return 1;
- }
- }
-
- private static int handleCommand(Command command, Namespace ns, ProvisioningManager pm) {
- if (command instanceof ProvisioningCommand) {
- return ((ProvisioningCommand) command).handleCommand(ns, pm);
- } else {
- System.err.println("Command only works with a username");
- return 1;
- }
- }
-
- private static int handleCommand(Command command, Namespace ns, RegistrationManager m) {
- if (command instanceof RegistrationCommand) {
- return ((RegistrationCommand) command).handleCommand(ns, m);
- }
- return 1;
- }
-
- private static int handleCommand(Command command, Namespace ns, Manager m) {
- if (command instanceof LocalCommand) {
- return ((LocalCommand) command).handleCommand(ns, m);
- } else if (command instanceof DbusCommand) {
- return ((DbusCommand) command).handleCommand(ns, new DbusSignalImpl(m));
- } else {
- System.err.println("Command only works via dbus");
- return 1;
- }
- }
-
- /**
- * Uses $XDG_DATA_HOME/signal-cli if it exists, or if none of the legacy directories exist:
- * - $HOME/.config/signal
- * - $HOME/.config/textsecure
- *
- * @return the data directory to be used by signal-cli.
- */
- private static File getDefaultDataPath() {
- File dataPath = new File(IOUtils.getDataHomeDir(), "signal-cli");
- if (dataPath.exists()) {
- return dataPath;
- }
-
- File configPath = new File(System.getProperty("user.home"), ".config");
-
- File legacySettingsPath = new File(configPath, "signal");
- if (legacySettingsPath.exists()) {
- return legacySettingsPath;
- }
-
- legacySettingsPath = new File(configPath, "textsecure");
- if (legacySettingsPath.exists()) {
- return legacySettingsPath;