X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/17ff7531d493266bca9c97fdf61290ead7262227..4608fb433b1af1753bdf73584d5c0f5f9e70f1bf:/src/main/java/org/asamk/signal/Main.java diff --git a/src/main/java/org/asamk/signal/Main.java b/src/main/java/org/asamk/signal/Main.java index a6d36d0f..4b22605c 100644 --- a/src/main/java/org/asamk/signal/Main.java +++ b/src/main/java/org/asamk/signal/Main.java @@ -19,7 +19,6 @@ package org.asamk.signal; import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.impl.Arguments; import net.sourceforge.argparse4j.inf.*; -import org.apache.commons.io.IOUtils; import org.apache.http.util.TextUtils; import org.asamk.Signal; import org.freedesktop.dbus.DBusConnection; @@ -41,8 +40,11 @@ import org.whispersystems.signalservice.api.util.PhoneNumberFormatter; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.Charset; import java.security.Security; import java.util.ArrayList; import java.util.List; @@ -224,6 +226,23 @@ public class Main { System.exit(3); } break; + case "removeDevice": + if (dBusConn != null) { + System.err.println("removeDevice is not yet implemented via dbus"); + System.exit(1); + } + if (!m.isRegistered()) { + System.err.println("User is not registered."); + System.exit(1); + } + try { + int deviceId = ns.getInt("deviceId"); + m.removeLinkedDevices(deviceId); + } catch (IOException e) { + e.printStackTrace(); + System.exit(3); + } + break; case "send": if (dBusConn == null && !m.isRegistered()) { System.err.println("User is not registered."); @@ -253,7 +272,7 @@ public class Main { String messageText = ns.getString("message"); if (messageText == null) { try { - messageText = IOUtils.toString(System.in); + messageText = readAll(System.in); } catch (IOException e) { System.err.println("Failed to read message from stdin: " + e.getMessage()); System.err.println("Aborting sending."); @@ -487,7 +506,7 @@ public class Main { .help("Show package version.") .action(Arguments.version()); parser.addArgument("--config") - .help("Set the path, where to store the config (Default: $HOME/.config/signal-cli)."); + .help("Set the path, where to store the config (Default: $HOME/.config/signal)."); MutuallyExclusiveGroup mut = parser.addMutuallyExclusiveGroup(); mut.addArgument("-u", "--username") @@ -516,6 +535,12 @@ public class Main { Subparser parserDevices = subparsers.addParser("listDevices"); + Subparser parserRemoveDevice = subparsers.addParser("removeDevice"); + parserRemoveDevice.addArgument("-d", "--deviceId") + .type(int.class) + .required(true) + .help("Specify the device you want to remove. Use listDevices to see the deviceIds."); + Subparser parserRegister = subparsers.addParser("register"); parserRegister.addArgument("-v", "--voice") .help("The verification should be done over voice, not sms.") @@ -620,6 +645,18 @@ public class Main { System.err.println("Failed to send message: " + e.getMessage()); } + private static String readAll(InputStream in) throws IOException { + StringWriter output = new StringWriter(); + byte[] buffer = new byte[4096]; + long count = 0; + int n; + while (-1 != (n = System.in.read(buffer))) { + output.write(new String(buffer, 0, n, Charset.defaultCharset())); + count += n; + } + return output.toString(); + } + private static class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { final Manager m;