X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/acadd90a6debfcf473a2dc813c71e4619c0af11d..b06fafbf627b1c03259828507c17a83d1b722c5c:/src/main/java/org/asamk/textsecure/Main.java?ds=sidebyside diff --git a/src/main/java/org/asamk/textsecure/Main.java b/src/main/java/org/asamk/textsecure/Main.java index 2e694ffd..404a8988 100644 --- a/src/main/java/org/asamk/textsecure/Main.java +++ b/src/main/java/org/asamk/textsecure/Main.java @@ -20,16 +20,18 @@ 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.TextSecure; import org.freedesktop.dbus.DBusConnection; import org.freedesktop.dbus.exceptions.DBusException; -import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException; -import org.whispersystems.textsecure.api.messages.*; -import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage; -import org.whispersystems.textsecure.api.push.exceptions.EncapsulatedExceptions; -import org.whispersystems.textsecure.api.push.exceptions.NetworkFailureException; -import org.whispersystems.textsecure.api.push.exceptions.UnregisteredUserException; -import org.whispersystems.textsecure.api.util.PhoneNumberFormatter; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException; +import org.whispersystems.signalservice.api.messages.*; +import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; +import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions; +import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException; +import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException; +import org.whispersystems.signalservice.api.util.PhoneNumberFormatter; import java.io.File; import java.io.IOException; @@ -78,7 +80,12 @@ public class Main { return; } } else { - m = new Manager(username); + String settingsPath = ns.getString("config"); + if (TextUtils.isEmpty(settingsPath)) { + settingsPath = System.getProperty("user.home") + "/.config/textsecure"; + } + + m = new Manager(username, settingsPath); ts = m; if (m.userExists()) { try { @@ -147,6 +154,8 @@ public class Main { handleEncapsulatedExceptions(e); } catch (AssertionError e) { handleAssertionError(e); + } catch (DBusExecutionException e) { + handleDBusExecutionException(e); } } else { String messageText = ns.getString("message"); @@ -183,6 +192,8 @@ public class Main { System.err.println("Failed to add attachment: " + e.getMessage()); System.err.println("Aborting sending."); System.exit(1); + } catch (DBusExecutionException e) { + handleDBusExecutionException(e); } } @@ -324,6 +335,12 @@ public class Main { System.exit(1); } + private static void handleDBusExecutionException(DBusExecutionException e) { + System.err.println("Cannot connect to dbus: " + e.getMessage()); + System.err.println("Aborting."); + System.exit(1); + } + private static byte[] decodeGroupId(String groupId) { try { return Base64.decode(groupId); @@ -344,6 +361,8 @@ public class Main { parser.addArgument("-v", "--version") .help("Show package version.") .action(Arguments.version()); + parser.addArgument("--config") + .help("Set the path, where to store the config (Default: $HOME/.config/textsecure-cli)."); MutuallyExclusiveGroup mut = parser.addMutuallyExclusiveGroup(); mut.addArgument("-u", "--username") @@ -467,18 +486,18 @@ public class Main { } @Override - public void handleMessage(TextSecureEnvelope envelope, TextSecureContent content, GroupInfo group) { + public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, GroupInfo group) { System.out.println("Envelope from: " + envelope.getSource()); System.out.println("Timestamp: " + envelope.getTimestamp()); if (envelope.isReceipt()) { System.out.println("Got receipt."); - } else if (envelope.isWhisperMessage() | envelope.isPreKeyWhisperMessage()) { + } else if (envelope.isSignalMessage() | envelope.isPreKeySignalMessage()) { if (content == null) { System.out.println("Failed to decrypt message."); } else { if (content.getDataMessage().isPresent()) { - TextSecureDataMessage message = content.getDataMessage().get(); + SignalServiceDataMessage message = content.getDataMessage().get(); System.out.println("Message timestamp: " + message.getTimestamp()); @@ -486,7 +505,7 @@ public class Main { System.out.println("Body: " + message.getBody().get()); } if (message.getGroupInfo().isPresent()) { - TextSecureGroup groupInfo = message.getGroupInfo().get(); + SignalServiceGroup groupInfo = message.getGroupInfo().get(); System.out.println("Group info:"); System.out.println(" Id: " + Base64.encodeBytes(groupInfo.getGroupId())); if (groupInfo.getName().isPresent()) { @@ -513,13 +532,13 @@ public class Main { if (message.getAttachments().isPresent()) { System.out.println("Attachments: "); - for (TextSecureAttachment attachment : message.getAttachments().get()) { + for (SignalServiceAttachment attachment : message.getAttachments().get()) { printAttachment(attachment); } } } if (content.getSyncMessage().isPresent()) { - TextSecureSyncMessage syncMessage = content.getSyncMessage().get(); + SignalServiceSyncMessage syncMessage = content.getSyncMessage().get(); System.out.println("Received sync message"); } } @@ -529,10 +548,10 @@ public class Main { System.out.println(); } - private void printAttachment(TextSecureAttachment attachment) { + private void printAttachment(SignalServiceAttachment attachment) { System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")"); if (attachment.isPointer()) { - final TextSecureAttachmentPointer pointer = attachment.asPointer(); + final SignalServiceAttachmentPointer pointer = attachment.asPointer(); System.out.println(" Id: " + pointer.getId() + " Key length: " + pointer.getKey().length + (pointer.getRelay().isPresent() ? " Relay: " + pointer.getRelay().get() : "")); System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : "")); File file = m.getAttachmentFile(pointer.getId()); @@ -553,18 +572,18 @@ public class Main { } @Override - public void handleMessage(TextSecureEnvelope envelope, TextSecureContent content, GroupInfo group) { + public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, GroupInfo group) { System.out.println("Envelope from: " + envelope.getSource()); System.out.println("Timestamp: " + envelope.getTimestamp()); if (envelope.isReceipt()) { System.out.println("Got receipt."); - } else if (envelope.isWhisperMessage() | envelope.isPreKeyWhisperMessage()) { + } else if (envelope.isSignalMessage() | envelope.isPreKeySignalMessage()) { if (content == null) { System.out.println("Failed to decrypt message."); } else { if (content.getDataMessage().isPresent()) { - TextSecureDataMessage message = content.getDataMessage().get(); + SignalServiceDataMessage message = content.getDataMessage().get(); System.out.println("Message timestamp: " + message.getTimestamp()); @@ -573,7 +592,7 @@ public class Main { } if (message.getGroupInfo().isPresent()) { - TextSecureGroup groupInfo = message.getGroupInfo().get(); + SignalServiceGroup groupInfo = message.getGroupInfo().get(); System.out.println("Group info:"); System.out.println(" Id: " + Base64.encodeBytes(groupInfo.getGroupId())); if (groupInfo.getName().isPresent()) { @@ -601,7 +620,7 @@ public class Main { List attachments = new ArrayList<>(); if (message.getAttachments().isPresent()) { System.out.println("Attachments: "); - for (TextSecureAttachment attachment : message.getAttachments().get()) { + for (SignalServiceAttachment attachment : message.getAttachments().get()) { if (attachment.isPointer()) { attachments.add(m.getAttachmentFile(attachment.asPointer().getId()).getAbsolutePath()); } @@ -609,7 +628,7 @@ public class Main { } } if (!message.isEndSession() && - !(message.getGroupInfo().isPresent() && message.getGroupInfo().get().getType() != TextSecureGroup.Type.DELIVER)) { + !(message.getGroupInfo().isPresent() && message.getGroupInfo().get().getType() != SignalServiceGroup.Type.DELIVER)) { try { conn.sendSignal(new TextSecure.MessageReceived( TEXTSECURE_OBJECTPATH, @@ -623,7 +642,7 @@ public class Main { } } if (content.getSyncMessage().isPresent()) { - TextSecureSyncMessage syncMessage = content.getSyncMessage().get(); + SignalServiceSyncMessage syncMessage = content.getSyncMessage().get(); System.out.println("Received sync message"); } } @@ -633,10 +652,10 @@ public class Main { System.out.println(); } - private void printAttachment(TextSecureAttachment attachment) { + private void printAttachment(SignalServiceAttachment attachment) { System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (attachment.isStream() ? "Stream" : "") + ")"); if (attachment.isPointer()) { - final TextSecureAttachmentPointer pointer = attachment.asPointer(); + final SignalServiceAttachmentPointer pointer = attachment.asPointer(); System.out.println(" Id: " + pointer.getId() + " Key length: " + pointer.getKey().length + (pointer.getRelay().isPresent() ? " Relay: " + pointer.getRelay().get() : "")); System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : "")); File file = m.getAttachmentFile(pointer.getId());