Merge pull request #1099 from BrianBlade/fix_otr_error_msgs

Fix OTR-Error messages (#1021)
This commit is contained in:
Daniel Gultsch 2015-04-02 11:11:22 +02:00
commit 59ea143147
2 changed files with 24 additions and 18 deletions

View File

@ -202,20 +202,7 @@ public class OtrEngine extends OtrCryptoEngineImpl implements OtrEngineHost {
@Override
public void messageFromAnotherInstanceReceived(SessionID session) {
try {
Jid jid = Jid.fromSessionID(session);
Conversation conversation = mXmppConnectionService.find(account, jid);
String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
if (id != null) {
MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateOtrError(jid,id);
packet.setFrom(account.getJid());
mXmppConnectionService.sendMessagePacket(account,packet);
Log.d(Config.LOGTAG,packet.toString());
Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": unreadable OTR message in "+conversation.getName());
}
} catch (InvalidJidException e) {
return;
}
sendOtrErrorMessage(session, "Message from another OTR-instance received");
}
@Override
@ -267,9 +254,28 @@ public class OtrEngine extends OtrCryptoEngineImpl implements OtrEngineHost {
}
@Override
public void unreadableMessageReceived(SessionID arg0) throws OtrException {
public void unreadableMessageReceived(SessionID session) throws OtrException {
Log.d(Config.LOGTAG,"unreadable message received");
throw new OtrException(new Exception("unreadable message received"));
sendOtrErrorMessage(session, "You sent me an unreadable OTR-encrypted message");
}
public void sendOtrErrorMessage(SessionID session, String errorText) {
try {
Jid jid = Jid.fromSessionID(session);
Conversation conversation = mXmppConnectionService.find(account, jid);
String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
if (id != null) {
MessagePacket packet = mXmppConnectionService.getMessageGenerator()
.generateOtrError(jid, id, errorText);
packet.setFrom(account.getJid());
mXmppConnectionService.sendMessagePacket(account,packet);
Log.d(Config.LOGTAG,packet.toString());
Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()
+": unreadable OTR message in "+conversation.getName());
}
} catch (InvalidJidException e) {
return;
}
}
@Override

View File

@ -172,7 +172,7 @@ public class MessageGenerator extends AbstractGenerator {
return receivedPacket;
}
public MessagePacket generateOtrError(Jid to, String id) {
public MessagePacket generateOtrError(Jid to, String id, String errorText) {
MessagePacket packet = new MessagePacket();
packet.setType(MessagePacket.TYPE_ERROR);
packet.setAttribute("id",id);
@ -181,7 +181,7 @@ public class MessageGenerator extends AbstractGenerator {
error.setAttribute("code","406");
error.setAttribute("type","modify");
error.addChild("not-acceptable","urn:ietf:params:xml:ns:xmpp-stanzas");
error.addChild("text").setContent("unreadable OTR message received");
error.addChild("text").setContent("?OTR Error:" + errorText);
return packet;
}
}