mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Separate DbusSignal implementation from Manager
This commit is contained in:
parent
d08508e6ef
commit
1e0aa8929d
8 changed files with 332 additions and 182 deletions
|
@ -1,33 +1,33 @@
|
||||||
package org.asamk;
|
package org.asamk;
|
||||||
|
|
||||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
|
||||||
import org.asamk.signal.manager.GroupNotFoundException;
|
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.freedesktop.dbus.interfaces.DBusInterface;
|
import org.freedesktop.dbus.interfaces.DBusInterface;
|
||||||
import org.freedesktop.dbus.messages.DBusSignal;
|
import org.freedesktop.dbus.messages.DBusSignal;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DBus interface for the org.asamk.Signal service.
|
||||||
|
* Including emitted Signals and returned Errors.
|
||||||
|
*/
|
||||||
public interface Signal extends DBusInterface {
|
public interface Signal extends DBusInterface {
|
||||||
|
|
||||||
long sendMessage(String message, List<String> attachments, String recipient) throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException;
|
long sendMessage(String message, List<String> attachments, String recipient) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber;
|
||||||
|
|
||||||
long sendMessage(String message, List<String> attachments, List<String> recipients) throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException;
|
long sendMessage(String message, List<String> attachments, List<String> recipients) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.UnregisteredUser, Error.UntrustedIdentity;
|
||||||
|
|
||||||
void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, InvalidNumberException;
|
void sendEndSessionMessage(List<String> recipients) throws Error.Failure, Error.InvalidNumber, Error.UnregisteredUser, Error.UntrustedIdentity;
|
||||||
|
|
||||||
long sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, IOException;
|
long sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws Error.GroupNotFound, Error.Failure, Error.AttachmentInvalid, Error.UnregisteredUser, Error.UntrustedIdentity;
|
||||||
|
|
||||||
String getContactName(String number) throws InvalidNumberException;
|
String getContactName(String number) throws Error.InvalidNumber;
|
||||||
|
|
||||||
void setContactName(String number, String name) throws InvalidNumberException;
|
void setContactName(String number, String name) throws Error.InvalidNumber;
|
||||||
|
|
||||||
void setContactBlocked(String number, boolean blocked) throws InvalidNumberException;
|
void setContactBlocked(String number, boolean blocked) throws Error.InvalidNumber;
|
||||||
|
|
||||||
void setGroupBlocked(byte[] groupId, boolean blocked) throws GroupNotFoundException;
|
void setGroupBlocked(byte[] groupId, boolean blocked) throws Error.GroupNotFound;
|
||||||
|
|
||||||
List<byte[]> getGroupIds();
|
List<byte[]> getGroupIds();
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public interface Signal extends DBusInterface {
|
||||||
|
|
||||||
List<String> getGroupMembers(byte[] groupId);
|
List<String> getGroupMembers(byte[] groupId);
|
||||||
|
|
||||||
byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException;
|
byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound, Error.UnregisteredUser, Error.UntrustedIdentity;
|
||||||
|
|
||||||
boolean isRegistered();
|
boolean isRegistered();
|
||||||
|
|
||||||
|
@ -140,4 +140,49 @@ public interface Signal extends DBusInterface {
|
||||||
return attachments;
|
return attachments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Error {
|
||||||
|
|
||||||
|
class AttachmentInvalid extends DBusExecutionException {
|
||||||
|
|
||||||
|
public AttachmentInvalid(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Failure extends DBusExecutionException {
|
||||||
|
|
||||||
|
public Failure(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GroupNotFound extends DBusExecutionException {
|
||||||
|
|
||||||
|
public GroupNotFound(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InvalidNumber extends DBusExecutionException {
|
||||||
|
|
||||||
|
public InvalidNumber(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnregisteredUser extends DBusExecutionException {
|
||||||
|
|
||||||
|
public UnregisteredUser(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UntrustedIdentity extends DBusExecutionException {
|
||||||
|
|
||||||
|
public UntrustedIdentity(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.asamk.signal.commands.DbusCommand;
|
||||||
import org.asamk.signal.commands.ExtendedDbusCommand;
|
import org.asamk.signal.commands.ExtendedDbusCommand;
|
||||||
import org.asamk.signal.commands.LocalCommand;
|
import org.asamk.signal.commands.LocalCommand;
|
||||||
import org.asamk.signal.commands.ProvisioningCommand;
|
import org.asamk.signal.commands.ProvisioningCommand;
|
||||||
|
import org.asamk.signal.dbus.DbusSignalImpl;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.asamk.signal.manager.ProvisioningManager;
|
import org.asamk.signal.manager.ProvisioningManager;
|
||||||
import org.asamk.signal.manager.ServiceConfig;
|
import org.asamk.signal.manager.ServiceConfig;
|
||||||
|
@ -179,7 +180,7 @@ public class Main {
|
||||||
if (command instanceof LocalCommand) {
|
if (command instanceof LocalCommand) {
|
||||||
return ((LocalCommand) command).handleCommand(ns, m);
|
return ((LocalCommand) command).handleCommand(ns, m);
|
||||||
} else if (command instanceof DbusCommand) {
|
} else if (command instanceof DbusCommand) {
|
||||||
return ((DbusCommand) command).handleCommand(ns, m);
|
return ((DbusCommand) command).handleCommand(ns, new DbusSignalImpl(m));
|
||||||
} else if (command instanceof ExtendedDbusCommand) {
|
} else if (command instanceof ExtendedDbusCommand) {
|
||||||
System.err.println(commandKey + " only works via dbus");
|
System.err.println(commandKey + " only works via dbus");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
import org.asamk.signal.DbusReceiveMessageHandler;
|
import org.asamk.signal.DbusReceiveMessageHandler;
|
||||||
import org.asamk.signal.JsonDbusReceiveMessageHandler;
|
import org.asamk.signal.JsonDbusReceiveMessageHandler;
|
||||||
|
import org.asamk.signal.dbus.DbusSignalImpl;
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
import org.freedesktop.dbus.connections.impl.DBusConnection;
|
||||||
import org.freedesktop.dbus.exceptions.DBusException;
|
import org.freedesktop.dbus.exceptions.DBusException;
|
||||||
|
@ -48,7 +49,7 @@ public class DaemonCommand implements LocalCommand {
|
||||||
busType = DBusConnection.DBusBusType.SESSION;
|
busType = DBusConnection.DBusBusType.SESSION;
|
||||||
}
|
}
|
||||||
conn = DBusConnection.getConnection(busType);
|
conn = DBusConnection.getConnection(busType);
|
||||||
conn.exportObject(SIGNAL_OBJECTPATH, m);
|
conn.exportObject(SIGNAL_OBJECTPATH, new DbusSignalImpl(m));
|
||||||
conn.requestBusName(SIGNAL_BUSNAME);
|
conn.requestBusName(SIGNAL_BUSNAME);
|
||||||
} catch (UnsatisfiedLinkError e) {
|
} catch (UnsatisfiedLinkError e) {
|
||||||
System.err.println("Missing native library dependency for dbus service: " + e.getMessage());
|
System.err.println("Missing native library dependency for dbus service: " + e.getMessage());
|
||||||
|
|
|
@ -5,15 +5,10 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
|
||||||
import org.asamk.signal.manager.GroupNotFoundException;
|
|
||||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
|
||||||
import org.asamk.signal.util.GroupIdFormatException;
|
import org.asamk.signal.util.GroupIdFormatException;
|
||||||
import org.asamk.signal.util.IOUtils;
|
import org.asamk.signal.util.IOUtils;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
@ -21,13 +16,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleDBusExecutionException;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleEncapsulatedExceptions;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleGroupNotFoundException;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleIOException;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleInvalidNumberException;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleNotAGroupMemberException;
|
|
||||||
|
|
||||||
public class SendCommand implements DbusCommand {
|
public class SendCommand implements DbusCommand {
|
||||||
|
|
||||||
|
@ -65,20 +54,11 @@ public class SendCommand implements DbusCommand {
|
||||||
try {
|
try {
|
||||||
signal.sendEndSessionMessage(ns.getList("recipient"));
|
signal.sendEndSessionMessage(ns.getList("recipient"));
|
||||||
return 0;
|
return 0;
|
||||||
} catch (IOException e) {
|
|
||||||
handleIOException(e);
|
|
||||||
return 3;
|
|
||||||
} catch (EncapsulatedExceptions e) {
|
|
||||||
handleEncapsulatedExceptions(e);
|
|
||||||
return 3;
|
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
handleAssertionError(e);
|
handleAssertionError(e);
|
||||||
return 1;
|
return 1;
|
||||||
} catch (DBusExecutionException e) {
|
} catch (DBusExecutionException e) {
|
||||||
handleDBusExecutionException(e);
|
System.err.println("Failed to send message: " + e.getMessage());
|
||||||
return 1;
|
|
||||||
} catch (InvalidNumberException e) {
|
|
||||||
handleInvalidNumberException(e);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,47 +74,42 @@ public class SendCommand implements DbusCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> attachments = ns.getList("attachment");
|
||||||
|
if (attachments == null) {
|
||||||
|
attachments = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<String> attachments = ns.getList("attachment");
|
|
||||||
if (attachments == null) {
|
|
||||||
attachments = new ArrayList<>();
|
|
||||||
}
|
|
||||||
long timestamp;
|
|
||||||
if (ns.getString("group") != null) {
|
if (ns.getString("group") != null) {
|
||||||
byte[] groupId = Util.decodeGroupId(ns.getString("group"));
|
byte[] groupId;
|
||||||
timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
|
try {
|
||||||
} else {
|
groupId = Util.decodeGroupId(ns.getString("group"));
|
||||||
timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
|
} catch (GroupIdFormatException e) {
|
||||||
|
handleGroupIdFormatException(e);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
long timestamp = signal.sendGroupMessage(messageText, attachments, groupId);
|
||||||
|
System.out.println(timestamp);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
System.out.println(timestamp);
|
|
||||||
return 0;
|
|
||||||
} catch (IOException e) {
|
|
||||||
handleIOException(e);
|
|
||||||
return 3;
|
|
||||||
} catch (EncapsulatedExceptions e) {
|
|
||||||
handleEncapsulatedExceptions(e);
|
|
||||||
return 3;
|
|
||||||
} catch (AssertionError e) {
|
} catch (AssertionError e) {
|
||||||
handleAssertionError(e);
|
handleAssertionError(e);
|
||||||
return 1;
|
return 1;
|
||||||
} catch (GroupNotFoundException e) {
|
} catch (DBusExecutionException e) {
|
||||||
handleGroupNotFoundException(e);
|
System.err.println("Failed to send message: " + e.getMessage());
|
||||||
return 1;
|
return 1;
|
||||||
} catch (NotAGroupMemberException e) {
|
}
|
||||||
handleNotAGroupMemberException(e);
|
|
||||||
return 1;
|
try {
|
||||||
} catch (AttachmentInvalidException e) {
|
long timestamp = signal.sendMessage(messageText, attachments, ns.getList("recipient"));
|
||||||
System.err.println("Failed to add attachment: " + e.getMessage());
|
System.out.println(timestamp);
|
||||||
System.err.println("Aborting sending.");
|
return 0;
|
||||||
|
} catch (AssertionError e) {
|
||||||
|
handleAssertionError(e);
|
||||||
return 1;
|
return 1;
|
||||||
} catch (DBusExecutionException e) {
|
} catch (DBusExecutionException e) {
|
||||||
handleDBusExecutionException(e);
|
System.err.println("Failed to send message: " + e.getMessage());
|
||||||
return 1;
|
|
||||||
} catch (GroupIdFormatException e) {
|
|
||||||
handleGroupIdFormatException(e);
|
|
||||||
return 1;
|
|
||||||
} catch (InvalidNumberException e) {
|
|
||||||
handleInvalidNumberException(e);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,25 +4,16 @@ import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
import org.asamk.Signal;
|
||||||
import org.asamk.signal.manager.AttachmentInvalidException;
|
|
||||||
import org.asamk.signal.manager.GroupNotFoundException;
|
|
||||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
|
||||||
import org.asamk.signal.util.GroupIdFormatException;
|
import org.asamk.signal.util.GroupIdFormatException;
|
||||||
import org.asamk.signal.util.Util;
|
import org.asamk.signal.util.Util;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
|
||||||
import org.whispersystems.util.Base64;
|
import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleEncapsulatedExceptions;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
import static org.asamk.signal.util.ErrorUtils.handleGroupIdFormatException;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleGroupNotFoundException;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleIOException;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleInvalidNumberException;
|
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleNotAGroupMemberException;
|
|
||||||
|
|
||||||
public class UpdateGroupCommand implements DbusCommand {
|
public class UpdateGroupCommand implements DbusCommand {
|
||||||
|
|
||||||
|
@ -46,52 +37,48 @@ public class UpdateGroupCommand implements DbusCommand {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
byte[] groupId = null;
|
||||||
byte[] groupId = null;
|
if (ns.getString("group") != null) {
|
||||||
if (ns.getString("group") != null) {
|
try {
|
||||||
groupId = Util.decodeGroupId(ns.getString("group"));
|
groupId = Util.decodeGroupId(ns.getString("group"));
|
||||||
|
} catch (GroupIdFormatException e) {
|
||||||
|
handleGroupIdFormatException(e);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (groupId == null) {
|
}
|
||||||
groupId = new byte[0];
|
if (groupId == null) {
|
||||||
}
|
groupId = new byte[0];
|
||||||
String groupName = ns.getString("name");
|
}
|
||||||
if (groupName == null) {
|
|
||||||
groupName = "";
|
String groupName = ns.getString("name");
|
||||||
}
|
if (groupName == null) {
|
||||||
List<String> groupMembers = ns.getList("member");
|
groupName = "";
|
||||||
if (groupMembers == null) {
|
}
|
||||||
groupMembers = new ArrayList<>();
|
|
||||||
}
|
List<String> groupMembers = ns.getList("member");
|
||||||
String groupAvatar = ns.getString("avatar");
|
if (groupMembers == null) {
|
||||||
if (groupAvatar == null) {
|
groupMembers = new ArrayList<>();
|
||||||
groupAvatar = "";
|
}
|
||||||
}
|
|
||||||
|
String groupAvatar = ns.getString("avatar");
|
||||||
|
if (groupAvatar == null) {
|
||||||
|
groupAvatar = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
byte[] newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar);
|
byte[] newGroupId = signal.updateGroup(groupId, groupName, groupMembers, groupAvatar);
|
||||||
if (groupId.length != newGroupId.length) {
|
if (groupId.length != newGroupId.length) {
|
||||||
System.out.println("Creating new group \"" + Base64.encodeBytes(newGroupId) + "\" …");
|
System.out.println("Creating new group \"" + Base64.encodeBytes(newGroupId) + "\" …");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} catch (IOException e) {
|
} catch (AssertionError e) {
|
||||||
handleIOException(e);
|
handleAssertionError(e);
|
||||||
return 3;
|
return 1;
|
||||||
} catch (AttachmentInvalidException e) {
|
} catch (Signal.Error.AttachmentInvalid e) {
|
||||||
System.err.println("Failed to add avatar attachment for group\": " + e.getMessage());
|
System.err.println("Failed to add avatar attachment for group\": " + e.getMessage());
|
||||||
System.err.println("Aborting sending.");
|
|
||||||
return 1;
|
return 1;
|
||||||
} catch (GroupNotFoundException e) {
|
} catch (DBusExecutionException e) {
|
||||||
handleGroupNotFoundException(e);
|
System.err.println("Failed to send message: " + e.getMessage());
|
||||||
return 1;
|
|
||||||
} catch (NotAGroupMemberException e) {
|
|
||||||
handleNotAGroupMemberException(e);
|
|
||||||
return 1;
|
|
||||||
} catch (EncapsulatedExceptions e) {
|
|
||||||
handleEncapsulatedExceptions(e);
|
|
||||||
return 3;
|
|
||||||
} catch (GroupIdFormatException e) {
|
|
||||||
handleGroupIdFormatException(e);
|
|
||||||
return 1;
|
|
||||||
} catch (InvalidNumberException e) {
|
|
||||||
handleInvalidNumberException(e);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
205
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java
Normal file
205
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java
Normal file
|
@ -0,0 +1,205 @@
|
||||||
|
package org.asamk.signal.dbus;
|
||||||
|
|
||||||
|
import org.asamk.Signal;
|
||||||
|
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||||
|
import org.asamk.signal.manager.GroupNotFoundException;
|
||||||
|
import org.asamk.signal.manager.Manager;
|
||||||
|
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||||
|
import org.asamk.signal.storage.groups.GroupInfo;
|
||||||
|
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||||
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
|
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.InvalidNumberException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DbusSignalImpl implements Signal {
|
||||||
|
|
||||||
|
private final Manager m;
|
||||||
|
|
||||||
|
public DbusSignalImpl(final Manager m) {
|
||||||
|
this.m = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRemote() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getObjectPath() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long sendMessage(final String message, final List<String> attachments, final String recipient) {
|
||||||
|
List<String> recipients = new ArrayList<>(1);
|
||||||
|
recipients.add(recipient);
|
||||||
|
return sendMessage(message, attachments, recipients);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DBusExecutionException convertEncapsulatedExceptions(EncapsulatedExceptions e) {
|
||||||
|
if (e.getNetworkExceptions().size() + e.getUnregisteredUserExceptions().size() + e.getUntrustedIdentityExceptions().size() == 1) {
|
||||||
|
if (e.getNetworkExceptions().size() == 1) {
|
||||||
|
NetworkFailureException n = e.getNetworkExceptions().get(0);
|
||||||
|
return new Error.Failure("Network failure for \"" + n.getE164number() + "\": " + n.getMessage());
|
||||||
|
} else if (e.getUnregisteredUserExceptions().size() == 1) {
|
||||||
|
UnregisteredUserException n = e.getUnregisteredUserExceptions().get(0);
|
||||||
|
return new Error.UnregisteredUser("Unregistered user \"" + n.getE164Number() + "\": " + n.getMessage());
|
||||||
|
} else if (e.getUntrustedIdentityExceptions().size() == 1) {
|
||||||
|
UntrustedIdentityException n = e.getUntrustedIdentityExceptions().get(0);
|
||||||
|
return new Error.UntrustedIdentity("Untrusted Identity for \"" + n.getIdentifier() + "\": " + n.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
message.append("Failed to send (some) messages:").append('\n');
|
||||||
|
for (NetworkFailureException n : e.getNetworkExceptions()) {
|
||||||
|
message.append("Network failure for \"").append(n.getE164number()).append("\": ").append(n.getMessage()).append('\n');
|
||||||
|
}
|
||||||
|
for (UnregisteredUserException n : e.getUnregisteredUserExceptions()) {
|
||||||
|
message.append("Unregistered user \"").append(n.getE164Number()).append("\": ").append(n.getMessage()).append('\n');
|
||||||
|
}
|
||||||
|
for (UntrustedIdentityException n : e.getUntrustedIdentityExceptions()) {
|
||||||
|
message.append("Untrusted Identity for \"").append(n.getIdentifier()).append("\": ").append(n.getMessage()).append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Error.Failure(message.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
||||||
|
try {
|
||||||
|
return m.sendMessage(message, attachments, recipients);
|
||||||
|
} catch (EncapsulatedExceptions e) {
|
||||||
|
throw convertEncapsulatedExceptions(e);
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
|
} catch (AttachmentInvalidException e) {
|
||||||
|
throw new Error.AttachmentInvalid(e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Error.Failure(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEndSessionMessage(final List<String> recipients) {
|
||||||
|
try {
|
||||||
|
m.sendEndSessionMessage(recipients);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Error.Failure(e.getMessage());
|
||||||
|
} catch (EncapsulatedExceptions e) {
|
||||||
|
throw convertEncapsulatedExceptions(e);
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long sendGroupMessage(final String message, final List<String> attachments, final byte[] groupId) {
|
||||||
|
try {
|
||||||
|
return m.sendGroupMessage(message, attachments, groupId);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Error.Failure(e.getMessage());
|
||||||
|
} catch (EncapsulatedExceptions e) {
|
||||||
|
throw convertEncapsulatedExceptions(e);
|
||||||
|
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||||
|
throw new Error.GroupNotFound(e.getMessage());
|
||||||
|
} catch (AttachmentInvalidException e) {
|
||||||
|
throw new Error.AttachmentInvalid(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContactName(final String number) {
|
||||||
|
try {
|
||||||
|
return m.getContactName(number);
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setContactName(final String number, final String name) {
|
||||||
|
try {
|
||||||
|
m.setContactName(number, name);
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setContactBlocked(final String number, final boolean blocked) {
|
||||||
|
try {
|
||||||
|
m.setContactBlocked(number, blocked);
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGroupBlocked(final byte[] groupId, final boolean blocked) {
|
||||||
|
try {
|
||||||
|
m.setGroupBlocked(groupId, blocked);
|
||||||
|
} catch (GroupNotFoundException e) {
|
||||||
|
throw new Error.GroupNotFound(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<byte[]> getGroupIds() {
|
||||||
|
List<GroupInfo> groups = m.getGroups();
|
||||||
|
List<byte[]> ids = new ArrayList<>(groups.size());
|
||||||
|
for (GroupInfo group : groups) {
|
||||||
|
ids.add(group.groupId);
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGroupName(final byte[] groupId) {
|
||||||
|
GroupInfo group = m.getGroup(groupId);
|
||||||
|
if (group == null) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return group.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getGroupMembers(final byte[] groupId) {
|
||||||
|
GroupInfo group = m.getGroup(groupId);
|
||||||
|
if (group == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
} else {
|
||||||
|
return new ArrayList<>(group.getMembersE164());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] updateGroup(final byte[] groupId, final String name, final List<String> members, final String avatar) {
|
||||||
|
try {
|
||||||
|
return m.updateGroup(groupId, name, members, avatar);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Error.Failure(e.getMessage());
|
||||||
|
} catch (EncapsulatedExceptions e) {
|
||||||
|
throw convertEncapsulatedExceptions(e);
|
||||||
|
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||||
|
throw new Error.GroupNotFound(e.getMessage());
|
||||||
|
} catch (InvalidNumberException e) {
|
||||||
|
throw new Error.InvalidNumber(e.getMessage());
|
||||||
|
} catch (AttachmentInvalidException e) {
|
||||||
|
throw new Error.AttachmentInvalid(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRegistered() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,6 @@ package org.asamk.signal.manager;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.asamk.Signal;
|
|
||||||
import org.asamk.signal.storage.SignalAccount;
|
import org.asamk.signal.storage.SignalAccount;
|
||||||
import org.asamk.signal.storage.contacts.ContactInfo;
|
import org.asamk.signal.storage.contacts.ContactInfo;
|
||||||
import org.asamk.signal.storage.groups.GroupInfo;
|
import org.asamk.signal.storage.groups.GroupInfo;
|
||||||
|
@ -142,7 +141,7 @@ import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
public class Manager implements Signal, Closeable {
|
public class Manager implements Closeable {
|
||||||
|
|
||||||
private final SleepTimer timer = new UptimeSleepTimer();
|
private final SleepTimer timer = new UptimeSleepTimer();
|
||||||
private final SignalServiceConfiguration serviceConfiguration;
|
private final SignalServiceConfiguration serviceConfiguration;
|
||||||
|
@ -478,7 +477,6 @@ public class Manager implements Signal, Closeable {
|
||||||
return account.getGroupStore().getGroups();
|
return account.getGroupStore().getGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long sendGroupMessage(String messageText, List<String> attachments,
|
public long sendGroupMessage(String messageText, List<String> attachments,
|
||||||
byte[] groupId)
|
byte[] groupId)
|
||||||
throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException {
|
||||||
|
@ -641,15 +639,6 @@ public class Manager implements Signal, Closeable {
|
||||||
getMessageSender().sendReceipt(remoteAddress, getAccessFor(remoteAddress), receiptMessage);
|
getMessageSender().sendReceipt(remoteAddress, getAccessFor(remoteAddress), receiptMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long sendMessage(String message, List<String> attachments, String recipient)
|
|
||||||
throws EncapsulatedExceptions, AttachmentInvalidException, IOException, InvalidNumberException {
|
|
||||||
List<String> recipients = new ArrayList<>(1);
|
|
||||||
recipients.add(recipient);
|
|
||||||
return sendMessage(message, attachments, recipients);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long sendMessage(String messageText, List<String> attachments,
|
public long sendMessage(String messageText, List<String> attachments,
|
||||||
List<String> recipients)
|
List<String> recipients)
|
||||||
throws IOException, EncapsulatedExceptions, AttachmentInvalidException, InvalidNumberException {
|
throws IOException, EncapsulatedExceptions, AttachmentInvalidException, InvalidNumberException {
|
||||||
|
@ -682,7 +671,6 @@ public class Manager implements Signal, Closeable {
|
||||||
sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients));
|
sendMessageLegacy(messageBuilder, getSignalServiceAddresses(recipients));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, InvalidNumberException {
|
public void sendEndSessionMessage(List<String> recipients) throws IOException, EncapsulatedExceptions, InvalidNumberException {
|
||||||
SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder()
|
||||||
.asEndSessionMessage();
|
.asEndSessionMessage();
|
||||||
|
@ -699,7 +687,6 @@ public class Manager implements Signal, Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getContactName(String number) throws InvalidNumberException {
|
public String getContactName(String number) throws InvalidNumberException {
|
||||||
ContactInfo contact = account.getContactStore().getContact(canonicalizeAndResolveSignalServiceAddress(number));
|
ContactInfo contact = account.getContactStore().getContact(canonicalizeAndResolveSignalServiceAddress(number));
|
||||||
if (contact == null) {
|
if (contact == null) {
|
||||||
|
@ -709,7 +696,6 @@ public class Manager implements Signal, Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContactName(String number, String name) throws InvalidNumberException {
|
public void setContactName(String number, String name) throws InvalidNumberException {
|
||||||
final SignalServiceAddress address = canonicalizeAndResolveSignalServiceAddress(number);
|
final SignalServiceAddress address = canonicalizeAndResolveSignalServiceAddress(number);
|
||||||
ContactInfo contact = account.getContactStore().getContact(address);
|
ContactInfo contact = account.getContactStore().getContact(address);
|
||||||
|
@ -724,7 +710,6 @@ public class Manager implements Signal, Closeable {
|
||||||
account.save();
|
account.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContactBlocked(String number, boolean blocked) throws InvalidNumberException {
|
public void setContactBlocked(String number, boolean blocked) throws InvalidNumberException {
|
||||||
setContactBlocked(canonicalizeAndResolveSignalServiceAddress(number), blocked);
|
setContactBlocked(canonicalizeAndResolveSignalServiceAddress(number), blocked);
|
||||||
}
|
}
|
||||||
|
@ -742,7 +727,6 @@ public class Manager implements Signal, Closeable {
|
||||||
account.save();
|
account.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setGroupBlocked(final byte[] groupId, final boolean blocked) throws GroupNotFoundException {
|
public void setGroupBlocked(final byte[] groupId, final boolean blocked) throws GroupNotFoundException {
|
||||||
GroupInfo group = getGroup(groupId);
|
GroupInfo group = getGroup(groupId);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
|
@ -755,37 +739,6 @@ public class Manager implements Signal, Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<byte[]> getGroupIds() {
|
|
||||||
List<GroupInfo> groups = getGroups();
|
|
||||||
List<byte[]> ids = new ArrayList<>(groups.size());
|
|
||||||
for (GroupInfo group : groups) {
|
|
||||||
ids.add(group.groupId);
|
|
||||||
}
|
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getGroupName(byte[] groupId) {
|
|
||||||
GroupInfo group = getGroup(groupId);
|
|
||||||
if (group == null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return group.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getGroupMembers(byte[] groupId) {
|
|
||||||
GroupInfo group = getGroup(groupId);
|
|
||||||
if (group == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
} else {
|
|
||||||
return new ArrayList<>(group.getMembersE164());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
public byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, InvalidNumberException, NotAGroupMemberException {
|
||||||
if (groupId.length == 0) {
|
if (groupId.length == 0) {
|
||||||
groupId = null;
|
groupId = null;
|
||||||
|
@ -1764,16 +1717,6 @@ public class Manager implements Signal, Closeable {
|
||||||
return messageReceiver.retrieveAttachment(pointer, tmpFile, ServiceConfig.MAX_ATTACHMENT_SIZE);
|
return messageReceiver.retrieveAttachment(pointer, tmpFile, ServiceConfig.MAX_ATTACHMENT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isRemote() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getObjectPath() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendGroups() throws IOException, UntrustedIdentityException {
|
private void sendGroups() throws IOException, UntrustedIdentityException {
|
||||||
File groupsFile = IOUtils.createTempFile();
|
File groupsFile = IOUtils.createTempFile();
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.asamk.signal.util;
|
||||||
|
|
||||||
import org.asamk.signal.manager.GroupNotFoundException;
|
import org.asamk.signal.manager.GroupNotFoundException;
|
||||||
import org.asamk.signal.manager.NotAGroupMemberException;
|
import org.asamk.signal.manager.NotAGroupMemberException;
|
||||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
|
||||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
import org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException;
|
||||||
|
@ -50,11 +49,6 @@ public class ErrorUtils {
|
||||||
System.err.println("Aborting sending.");
|
System.err.println("Aborting sending.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleDBusExecutionException(DBusExecutionException e) {
|
|
||||||
System.err.println("Cannot connect to dbus: " + e.getMessage());
|
|
||||||
System.err.println("Aborting.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void handleGroupIdFormatException(GroupIdFormatException e) {
|
public static void handleGroupIdFormatException(GroupIdFormatException e) {
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
System.err.println("Aborting sending.");
|
System.err.println("Aborting sending.");
|
||||||
|
@ -62,7 +56,6 @@ public class ErrorUtils {
|
||||||
|
|
||||||
public static void handleInvalidNumberException(InvalidNumberException e) {
|
public static void handleInvalidNumberException(InvalidNumberException e) {
|
||||||
System.err.println("Failed to parse recipient: " + e.getMessage());
|
System.err.println("Failed to parse recipient: " + e.getMessage());
|
||||||
System.err.println(e.getMessage());
|
|
||||||
System.err.println("Aborting sending.");
|
System.err.println("Aborting sending.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue