more bug fixes for the pgp problem
This commit is contained in:
parent
2f2aa7aa21
commit
ba2ad82c7e
|
@ -23,35 +23,51 @@ public class MessageParser {
|
||||||
|
|
||||||
public Message parseChat(MessagePacket packet, Account account) {
|
public Message parseChat(MessagePacket packet, Account account) {
|
||||||
String[] fromParts = packet.getFrom().split("/");
|
String[] fromParts = packet.getFrom().split("/");
|
||||||
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, fromParts[0],false);
|
Conversation conversation = mXmppConnectionService
|
||||||
|
.findOrCreateConversation(account, fromParts[0], false);
|
||||||
String pgpBody = getPgpBody(packet);
|
String pgpBody = getPgpBody(packet);
|
||||||
if (pgpBody!=null) {
|
if (pgpBody != null) {
|
||||||
return new Message(conversation, packet.getFrom(), pgpBody, Message.ENCRYPTION_PGP, Message.STATUS_RECIEVED);
|
return new Message(conversation, packet.getFrom(), pgpBody,
|
||||||
|
Message.ENCRYPTION_PGP, Message.STATUS_RECIEVED);
|
||||||
} else {
|
} else {
|
||||||
return new Message(conversation, packet.getFrom(), packet.getBody(), Message.ENCRYPTION_NONE, Message.STATUS_RECIEVED);
|
return new Message(conversation, packet.getFrom(),
|
||||||
|
packet.getBody(), Message.ENCRYPTION_NONE,
|
||||||
|
Message.STATUS_RECIEVED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message parseOtrChat(MessagePacket packet, Account account) {
|
public Message parseOtrChat(MessagePacket packet, Account account) {
|
||||||
boolean properlyAddressed = (packet.getTo().split("/").length == 2) || (account.countPresences() == 1);
|
boolean properlyAddressed = (packet.getTo().split("/").length == 2)
|
||||||
|
|| (account.countPresences() == 1);
|
||||||
String[] fromParts = packet.getFrom().split("/");
|
String[] fromParts = packet.getFrom().split("/");
|
||||||
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, fromParts[0],false);
|
Conversation conversation = mXmppConnectionService
|
||||||
|
.findOrCreateConversation(account, fromParts[0], false);
|
||||||
String body = packet.getBody();
|
String body = packet.getBody();
|
||||||
if (!conversation.hasValidOtrSession()) {
|
if (!conversation.hasValidOtrSession()) {
|
||||||
if (properlyAddressed) {
|
if (properlyAddressed) {
|
||||||
Log.d("xmppService","starting new otr session with "+packet.getFrom()+" because no valid otr session has been found");
|
Log.d("xmppService",
|
||||||
conversation.startOtrSession(mXmppConnectionService.getApplicationContext(), fromParts[1],false);
|
"starting new otr session with "
|
||||||
|
+ packet.getFrom()
|
||||||
|
+ " because no valid otr session has been found");
|
||||||
|
conversation.startOtrSession(
|
||||||
|
mXmppConnectionService.getApplicationContext(),
|
||||||
|
fromParts[1], false);
|
||||||
} else {
|
} else {
|
||||||
Log.d("xmppService",account.getJid()+": ignoring otr session with "+fromParts[0]);
|
Log.d("xmppService", account.getJid()
|
||||||
|
+ ": ignoring otr session with " + fromParts[0]);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String foreignPresence = conversation.getOtrSession().getSessionID().getUserID();
|
String foreignPresence = conversation.getOtrSession()
|
||||||
|
.getSessionID().getUserID();
|
||||||
if (!foreignPresence.equals(fromParts[1])) {
|
if (!foreignPresence.equals(fromParts[1])) {
|
||||||
conversation.resetOtrSession();
|
conversation.resetOtrSession();
|
||||||
if (properlyAddressed) {
|
if (properlyAddressed) {
|
||||||
Log.d("xmppService","replacing otr session with "+packet.getFrom());
|
Log.d("xmppService",
|
||||||
conversation.startOtrSession(mXmppConnectionService.getApplicationContext(), fromParts[1],false);
|
"replacing otr session with " + packet.getFrom());
|
||||||
|
conversation.startOtrSession(
|
||||||
|
mXmppConnectionService.getApplicationContext(),
|
||||||
|
fromParts[1], false);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -59,23 +75,21 @@ public class MessageParser {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Session otrSession = conversation.getOtrSession();
|
Session otrSession = conversation.getOtrSession();
|
||||||
SessionStatus before = otrSession
|
SessionStatus before = otrSession.getSessionStatus();
|
||||||
.getSessionStatus();
|
|
||||||
body = otrSession.transformReceiving(body);
|
body = otrSession.transformReceiving(body);
|
||||||
SessionStatus after = otrSession.getSessionStatus();
|
SessionStatus after = otrSession.getSessionStatus();
|
||||||
if ((before != after)
|
if ((before != after) && (after == SessionStatus.ENCRYPTED)) {
|
||||||
&& (after == SessionStatus.ENCRYPTED)) {
|
|
||||||
Log.d(LOGTAG, "otr session etablished");
|
Log.d(LOGTAG, "otr session etablished");
|
||||||
List<Message> messages = conversation
|
List<Message> messages = conversation.getMessages();
|
||||||
.getMessages();
|
|
||||||
for (int i = 0; i < messages.size(); ++i) {
|
for (int i = 0; i < messages.size(); ++i) {
|
||||||
Message msg = messages.get(i);
|
Message msg = messages.get(i);
|
||||||
if ((msg.getStatus() == Message.STATUS_UNSEND)
|
if ((msg.getStatus() == Message.STATUS_UNSEND)
|
||||||
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
|
&& (msg.getEncryption() == Message.ENCRYPTION_OTR)) {
|
||||||
MessagePacket outPacket = mXmppConnectionService.prepareMessagePacket(
|
MessagePacket outPacket = mXmppConnectionService
|
||||||
account, msg, otrSession);
|
.prepareMessagePacket(account, msg, otrSession);
|
||||||
msg.setStatus(Message.STATUS_SEND);
|
msg.setStatus(Message.STATUS_SEND);
|
||||||
mXmppConnectionService.databaseBackend.updateMessage(msg);
|
mXmppConnectionService.databaseBackend
|
||||||
|
.updateMessage(msg);
|
||||||
account.getXmppConnection()
|
account.getXmppConnection()
|
||||||
.sendMessagePacket(outPacket);
|
.sendMessagePacket(outPacket);
|
||||||
}
|
}
|
||||||
|
@ -83,13 +97,15 @@ public class MessageParser {
|
||||||
mXmppConnectionService.updateUi(conversation, false);
|
mXmppConnectionService.updateUi(conversation, false);
|
||||||
} else if ((before != after) && (after == SessionStatus.FINISHED)) {
|
} else if ((before != after) && (after == SessionStatus.FINISHED)) {
|
||||||
conversation.resetOtrSession();
|
conversation.resetOtrSession();
|
||||||
Log.d(LOGTAG,"otr session stoped");
|
Log.d(LOGTAG, "otr session stoped");
|
||||||
}
|
}
|
||||||
//isEmpty is a work around for some weird clients which send emtpty strings over otr
|
// isEmpty is a work around for some weird clients which send emtpty
|
||||||
if ((body == null)||(body.isEmpty())) {
|
// strings over otr
|
||||||
|
if ((body == null) || (body.isEmpty())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Message(conversation, packet.getFrom(), body, Message.ENCRYPTION_OTR,Message.STATUS_RECIEVED);
|
return new Message(conversation, packet.getFrom(), body,
|
||||||
|
Message.ENCRYPTION_OTR, Message.STATUS_RECIEVED);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
conversation.resetOtrSession();
|
conversation.resetOtrSession();
|
||||||
return null;
|
return null;
|
||||||
|
@ -99,9 +115,11 @@ public class MessageParser {
|
||||||
public Message parseGroupchat(MessagePacket packet, Account account) {
|
public Message parseGroupchat(MessagePacket packet, Account account) {
|
||||||
int status;
|
int status;
|
||||||
String[] fromParts = packet.getFrom().split("/");
|
String[] fromParts = packet.getFrom().split("/");
|
||||||
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, fromParts[0],true);
|
Conversation conversation = mXmppConnectionService
|
||||||
|
.findOrCreateConversation(account, fromParts[0], true);
|
||||||
if (packet.hasChild("subject")) {
|
if (packet.hasChild("subject")) {
|
||||||
conversation.getMucOptions().setSubject(packet.findChild("subject").getContent());
|
conversation.getMucOptions().setSubject(
|
||||||
|
packet.findChild("subject").getContent());
|
||||||
mXmppConnectionService.updateUi(conversation, false);
|
mXmppConnectionService.updateUi(conversation, false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +128,8 @@ public class MessageParser {
|
||||||
}
|
}
|
||||||
String counterPart = fromParts[1];
|
String counterPart = fromParts[1];
|
||||||
if (counterPart.equals(conversation.getMucOptions().getNick())) {
|
if (counterPart.equals(conversation.getMucOptions().getNick())) {
|
||||||
if (mXmppConnectionService.markMessage(conversation, packet.getId(), Message.STATUS_SEND)) {
|
if (mXmppConnectionService.markMessage(conversation,
|
||||||
|
packet.getId(), Message.STATUS_SEND)) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
status = Message.STATUS_SEND;
|
status = Message.STATUS_SEND;
|
||||||
|
@ -119,29 +138,29 @@ public class MessageParser {
|
||||||
status = Message.STATUS_RECIEVED;
|
status = Message.STATUS_RECIEVED;
|
||||||
}
|
}
|
||||||
String pgpBody = getPgpBody(packet);
|
String pgpBody = getPgpBody(packet);
|
||||||
if (pgpBody==null) {
|
if (pgpBody == null) {
|
||||||
return new Message(conversation, counterPart, packet.getBody(), Message.ENCRYPTION_NONE, status);
|
return new Message(conversation, counterPart, packet.getBody(),
|
||||||
|
Message.ENCRYPTION_NONE, status);
|
||||||
} else {
|
} else {
|
||||||
return new Message(conversation, counterPart, pgpBody, Message.ENCRYPTION_PGP, status);
|
return new Message(conversation, counterPart, pgpBody,
|
||||||
|
Message.ENCRYPTION_PGP, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message parseCarbonMessage(MessagePacket packet,Account account) {
|
public Message parseCarbonMessage(MessagePacket packet, Account account) {
|
||||||
int status;
|
int status;
|
||||||
String fullJid;
|
String fullJid;
|
||||||
Element forwarded;
|
Element forwarded;
|
||||||
if (packet.hasChild("received")) {
|
if (packet.hasChild("received")) {
|
||||||
forwarded = packet.findChild("received").findChild(
|
forwarded = packet.findChild("received").findChild("forwarded");
|
||||||
"forwarded");
|
|
||||||
status = Message.STATUS_RECIEVED;
|
status = Message.STATUS_RECIEVED;
|
||||||
} else if (packet.hasChild("sent")) {
|
} else if (packet.hasChild("sent")) {
|
||||||
forwarded = packet.findChild("sent").findChild(
|
forwarded = packet.findChild("sent").findChild("forwarded");
|
||||||
"forwarded");
|
|
||||||
status = Message.STATUS_SEND;
|
status = Message.STATUS_SEND;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (forwarded==null) {
|
if (forwarded == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Element message = forwarded.findChild("message");
|
Element message = forwarded.findChild("message");
|
||||||
|
@ -153,23 +172,28 @@ public class MessageParser {
|
||||||
fullJid = message.getAttribute("to");
|
fullJid = message.getAttribute("to");
|
||||||
}
|
}
|
||||||
String[] parts = fullJid.split("/");
|
String[] parts = fullJid.split("/");
|
||||||
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, parts[0],false);
|
Conversation conversation = mXmppConnectionService
|
||||||
String pgpBody = getPgpBody(packet);
|
.findOrCreateConversation(account, parts[0], false);
|
||||||
if (pgpBody!=null) {
|
String pgpBody = getPgpBody(message);
|
||||||
return new Message(conversation,fullJid, pgpBody,Message.ENCRYPTION_PGP,status);
|
if (pgpBody != null) {
|
||||||
|
return new Message(conversation, fullJid, pgpBody,
|
||||||
|
Message.ENCRYPTION_PGP, status);
|
||||||
} else {
|
} else {
|
||||||
return new Message(conversation,fullJid,packet.getBody(),Message.ENCRYPTION_NONE,status);
|
String body = message.findChild("body").getContent();
|
||||||
|
return new Message(conversation, fullJid, body,
|
||||||
|
Message.ENCRYPTION_NONE, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parseError(MessagePacket packet, Account account) {
|
public void parseError(MessagePacket packet, Account account) {
|
||||||
String[] fromParts = packet.getFrom().split("/");
|
String[] fromParts = packet.getFrom().split("/");
|
||||||
mXmppConnectionService.markMessage(account, fromParts[0], packet.getId(), Message.STATUS_SEND_FAILED);
|
mXmppConnectionService.markMessage(account, fromParts[0],
|
||||||
|
packet.getId(), Message.STATUS_SEND_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPgpBody(MessagePacket packet) {
|
private String getPgpBody(Element packet) {
|
||||||
Element child = packet.findChild("x", "jabber:x:encrypted");
|
Element child = packet.findChild("x", "jabber:x:encrypted");
|
||||||
if (child==null) {
|
if (child == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return child.getContent();
|
return child.getContent();
|
||||||
|
|
Loading…
Reference in New Issue