aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/parser
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-05-26 17:46:58 +0200
committerlookshe <github@lookshe.org>2016-05-26 17:46:58 +0200
commit327cfb8ae52443c3cb7ff7f09a753300365a306c (patch)
tree02ed62c978685ce7f481d98ed4d2bd3c508587a6 /src/main/java/eu/siacs/conversations/parser
parent2860088f0ea1cd5753756861c71cc7c118094f32 (diff)
parent33218ec32a47292a46d574e5107164b8e8a72e40 (diff)
Merge tag '1.12.4' into trz/merge_1.12.4 (not tested yet)trz/merge_1.12.4
Conflicts: README.md art/render.rb build.gradle src/main/java/eu/siacs/conversations/Config.java src/main/java/eu/siacs/conversations/crypto/PgpEngine.java src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java src/main/java/eu/siacs/conversations/crypto/axolotl/SQLiteAxolotlStore.java src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlSession.java src/main/java/eu/siacs/conversations/entities/Bookmark.java src/main/java/eu/siacs/conversations/entities/Contact.java src/main/java/eu/siacs/conversations/entities/ListItem.java src/main/java/eu/siacs/conversations/entities/Message.java src/main/java/eu/siacs/conversations/parser/IqParser.java src/main/java/eu/siacs/conversations/parser/PresenceParser.java src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java src/main/java/eu/siacs/conversations/persistance/FileBackend.java src/main/java/eu/siacs/conversations/services/XmppConnectionService.java src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java src/main/java/eu/siacs/conversations/ui/SettingsActivity.java src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java src/main/java/eu/siacs/conversations/ui/XmppActivity.java src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java src/main/java/eu/siacs/conversations/utils/DNSHelper.java src/main/java/eu/siacs/conversations/utils/UIHelper.java src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java src/main/res/layout/activity_contact_details.xml src/main/res/layout/message_received.xml src/main/res/layout/message_sent.xml src/main/res/values-bg/strings.xml src/main/res/values-de/strings.xml src/main/res/values-es/strings.xml src/main/res/values-eu/strings.xml src/main/res/values-fr/strings.xml src/main/res/values-ja/strings.xml src/main/res/values-nl/strings.xml src/main/res/values-pt-rBR/strings.xml src/main/res/values-pt/strings.xml src/main/res/values-ro-rRO/strings.xml src/main/res/values-sr/strings.xml src/main/res/values-sv/strings.xml src/main/res/values-tr-rTR/strings.xml
Diffstat (limited to 'src/main/java/eu/siacs/conversations/parser')
-rw-r--r--src/main/java/eu/siacs/conversations/parser/AbstractParser.java31
-rw-r--r--src/main/java/eu/siacs/conversations/parser/IqParser.java14
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java81
-rw-r--r--src/main/java/eu/siacs/conversations/parser/PresenceParser.java13
4 files changed, 112 insertions, 27 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
index ad368f11..bdd13932 100644
--- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java
@@ -7,8 +7,11 @@ import java.util.Locale;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
+import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
@@ -71,16 +74,12 @@ public abstract class AbstractParser {
return dateFormat.parse(timestamp);
}
- protected void updateLastseen(final AbstractStanza packet, final Account account, final boolean presenceOverwrite) {
- updateLastseen(getTimestamp(packet), account, packet.getFrom(), presenceOverwrite);
- }
-
- protected void updateLastseen(long timestamp, final Account account, final Jid from, final boolean presenceOverwrite) {
+ protected void updateLastseen(long timestamp, final Account account, final Jid from) {
final String presence = from == null || from.isBareJid() ? "" : from.getResourcepart();
final Contact contact = account.getRoster().getContact(from);
if (timestamp >= contact.lastseen.time) {
contact.lastseen.time = timestamp;
- if (!presence.isEmpty() && presenceOverwrite) {
+ if (!presence.isEmpty()) {
contact.lastseen.presence = presence;
}
}
@@ -93,4 +92,24 @@ public abstract class AbstractParser {
}
return item.findChildContent("data", "urn:xmpp:avatar:data");
}
+
+ public static MucOptions.User parseItem(Conversation conference, Element item) {
+ final String local = conference.getJid().getLocalpart();
+ final String domain = conference.getJid().getDomainpart();
+ String affiliation = item.getAttribute("affiliation");
+ String role = item.getAttribute("role");
+ String nick = item.getAttribute("nick");
+ Jid fullJid;
+ try {
+ fullJid = nick != null ? Jid.fromParts(local, domain, nick) : null;
+ } catch (InvalidJidException e) {
+ fullJid = null;
+ }
+ Jid realJid = item.getAttributeAsJid("jid");
+ MucOptions.User user = new MucOptions.User(conference.getMucOptions(), nick == null ? null : fullJid);
+ user.setRealJid(realJid);
+ user.setAffiliation(affiliation);
+ user.setRole(role);
+ return user;
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/parser/IqParser.java b/src/main/java/eu/siacs/conversations/parser/IqParser.java
index c03ed42f..365c9e5e 100644
--- a/src/main/java/eu/siacs/conversations/parser/IqParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/IqParser.java
@@ -56,6 +56,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
final String name = item.getAttribute("name");
final String subscription = item.getAttribute("subscription");
final Contact contact = account.getRoster().getContact(jid);
+ boolean bothPre = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
contact.setServerName(name);
contact.parseGroupsFromElement(item);
@@ -71,6 +72,14 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
contact.parseSubscriptionFromElement(item);
}
}
+ boolean both = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
+ if ((both != bothPre) && both) {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": gained mutual presence subscription with "+contact.getJid());
+ AxolotlService axolotlService = account.getAxolotlService();
+ if (axolotlService != null) {
+ axolotlService.clearErrorsInFetchStatusMap(contact.getJid());
+ }
+ }
AvatarService.getInstance().clear(contact);
}
}
@@ -270,6 +279,11 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
@Override
public void onIqPacketReceived(final Account account, final IqPacket packet) {
+ if (Config.BACKGROUND_STANZA_LOGGING && (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET)) {
+ Element first = packet.getChildren().size() > 0 ? packet.getChildren().get(0) : null;
+ Logging.d(Config.LOGTAG,account.getJid().toBareJid()+": IQ request from "+packet.getFrom()+(first == null ? "" : " "+first));
+ }
+
if (packet.getType() == IqPacket.TYPE.ERROR || packet.getType() == IqPacket.TYPE.TIMEOUT) {
return;
} else if (packet.hasChild("query", Xmlns.ROSTER) && packet.fromServer(account)) {
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index c79110c9..57a737ef 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -1,5 +1,6 @@
package eu.siacs.conversations.parser;
+import android.text.Html;
import android.util.Log;
import android.util.Pair;
@@ -12,6 +13,9 @@ import net.java.otr4j.session.SessionStatus;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
import java.util.Set;
import de.thedevstack.android.logcat.Logging;
@@ -29,6 +33,8 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions;
+import eu.siacs.conversations.entities.Presence;
+import eu.siacs.conversations.entities.ServiceDiscoveryResult;
import eu.siacs.conversations.http.HttpConnectionManager;
import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.services.MessageArchiveService;
@@ -41,8 +47,10 @@ import eu.siacs.conversations.xmpp.jid.Jid;
import eu.siacs.conversations.xmpp.pep.Avatar;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
-public class MessageParser extends AbstractParser implements
- OnMessagePacketReceived {
+public class MessageParser extends AbstractParser implements OnMessagePacketReceived {
+
+ private static final List<String> CLIENTS_SENDING_HTML_IN_OTR = Arrays.asList(new String[]{"Pidgin","Adium"});
+
public MessageParser(XmppConnectionService service) {
super(service);
}
@@ -106,6 +114,11 @@ public class MessageParser extends AbstractParser implements
conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
return null;
}
+ if (clientMightSendHtml(conversation.getAccount(), from)) {
+ Log.d(Config.LOGTAG,conversation.getAccount().getJid().toBareJid()+": received OTR message from bad behaving client. escaping HTML…");
+ body = Html.fromHtml(body).toString();
+ }
+
final OtrService otrService = conversation.getAccount().getOtrService();
Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED);
finishedMessage.setFingerprint(otrService.getFingerprint(otrSession.getRemotePublicKey()));
@@ -118,6 +131,30 @@ public class MessageParser extends AbstractParser implements
}
}
+ private static boolean clientMightSendHtml(Account account, Jid from) {
+ String resource = from.getResourcepart();
+ if (resource == null) {
+ return false;
+ }
+ Presence presence = account.getRoster().getContact(from).getPresences().getPresences().get(resource);
+ ServiceDiscoveryResult disco = presence == null ? null : presence.getServiceDiscoveryResult();
+ if (disco == null) {
+ return false;
+ }
+ return hasIdentityKnowForSendingHtml(disco.getIdentities());
+ }
+
+ private static boolean hasIdentityKnowForSendingHtml(List<ServiceDiscoveryResult.Identity> identities) {
+ for(ServiceDiscoveryResult.Identity identity : identities) {
+ if (identity.getName() != null) {
+ if (CLIENTS_SENDING_HTML_IN_OTR.contains(identity.getName())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status) {
Message finishedMessage = null;
AxolotlService service = conversation.getAccount().getAxolotlService();
@@ -320,7 +357,7 @@ public class MessageParser extends AbstractParser implements
}
boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT;
- boolean isProperlyAddressed = (to != null ) && (!to.isBareJid() || account.countPresences() <= 1);
+ boolean isProperlyAddressed = (to != null ) && (!to.isBareJid() || account.countPresences() == 0);
boolean isMucStatusMessage = from.isBareJid() && mucUserElement != null && mucUserElement.hasChild("status");
if (packet.fromAccount(account)) {
status = Message.STATUS_SEND;
@@ -374,7 +411,7 @@ public class MessageParser extends AbstractParser implements
} else if (axolotlEncrypted != null && Config.supportOmemo()) {
Jid origin;
if (conversation.getMode() == Conversation.MODE_MULTI) {
- origin = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());
+ origin = conversation.getMucOptions().getTrueCounterpart(counterpart);
if (origin == null) {
Log.d(Config.LOGTAG,"axolotl message in non anonymous conference received");
return;
@@ -406,16 +443,13 @@ public class MessageParser extends AbstractParser implements
message.setOob(isOob);
message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
if (conversation.getMode() == Conversation.MODE_MULTI) {
- Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());
+ Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart);
message.setTrueCounterpart(trueCounterpart);
- if (trueCounterpart != null) {
- updateLastseen(timestamp, account, trueCounterpart, false);
- }
if (!isTypeGroupChat) {
message.setType(Message.TYPE_PRIVATE);
}
} else {
- updateLastseen(timestamp, account, packet.getFrom(), true);
+ updateLastseen(timestamp, account, from);
}
boolean checkForDuplicates = query != null
@@ -486,8 +520,11 @@ public class MessageParser extends AbstractParser implements
}
}
} else if (!packet.hasChild("body")){ //no body
+ if (Config.BACKGROUND_STANZA_LOGGING && !mXmppConnectionService.checkListeners()) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": " + original);
+ }
+ Conversation conversation = mXmppConnectionService.find(account, from.toBareJid());
if (isTypeGroupChat) {
- Conversation conversation = mXmppConnectionService.find(account, from.toBareJid());
if (packet.hasChild("subject")) {
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0);
@@ -503,18 +540,36 @@ public class MessageParser extends AbstractParser implements
return;
}
}
-
- if (conversation != null && isMucStatusMessage) {
+ }
+ if (conversation != null && mucUserElement != null && from.isBareJid()) {
+ if (mucUserElement.hasChild("status")) {
for (Element child : mucUserElement.getChildren()) {
if (child.getName().equals("status")
&& MucOptions.STATUS_CODE_ROOM_CONFIG_CHANGED.equals(child.getAttribute("code"))) {
mXmppConnectionService.fetchConferenceConfiguration(conversation);
}
}
+ } else if (mucUserElement.hasChild("item")) {
+ for(Element child : mucUserElement.getChildren()) {
+ if ("item".equals(child.getName())) {
+ MucOptions.User user = AbstractParser.parseItem(conversation,child);
+ Log.d(Config.LOGTAG,account.getJid()+": changing affiliation for "
+ +user.getRealJid()+" to "+user.getAffiliation()+" in "
+ +conversation.getJid().toBareJid());
+ if (!user.realJidMatchesAccount()) {
+ conversation.getMucOptions().addUser(user);
+ mXmppConnectionService.getAvatarService().clear(conversation);
+ mXmppConnectionService.updateMucRosterUi();
+ mXmppConnectionService.updateConversationUi();
+ }
+ }
+ }
}
}
}
+
+
Element received = packet.findChild("received", "urn:xmpp:chat-markers:0");
if (received == null) {
received = packet.findChild("received", "urn:xmpp:receipts");
@@ -531,7 +586,7 @@ public class MessageParser extends AbstractParser implements
mXmppConnectionService.markRead(conversation);
}
} else {
- updateLastseen(timestamp, account, packet.getFrom(), true);
+ updateLastseen(timestamp, account, from);
final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), displayed.getAttribute("id"), Message.STATUS_SEND_DISPLAYED);
Message message = displayedMessage == null ? null : displayedMessage.prev();
while (message != null
diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java
index 76da5a31..a06e0d49 100644
--- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java
@@ -73,11 +73,7 @@ public class PresenceParser extends AbstractParser implements
MucOptions.User user = new MucOptions.User(mucOptions, from);
user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role"));
- Jid real = item.getAttributeAsJid("jid");
- if (real != null) {
- user.setJid(real);
- mucOptions.putMember(real.toBareJid());
- }
+ user.setRealJid(item.getAttributeAsJid("jid"));
if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || packet.getFrom().equals(mucOptions.getConversation().getJid())) {
mucOptions.setOnline();
mucOptions.setSelf(user);
@@ -153,7 +149,7 @@ public class PresenceParser extends AbstractParser implements
} else if (error != null && error.hasChild("forbidden")) {
mucOptions.setError(MucOptions.Error.BANNED);
} else if (error != null && error.hasChild("registration-required")) {
- mucOptions.setError(MucOptions.Error.BANNED);
+ mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
}
}
}
@@ -177,7 +173,7 @@ public class PresenceParser extends AbstractParser implements
public void parseContactPresence(final PresencePacket packet, final Account account) {
final PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator();
final Jid from = packet.getFrom();
- if (from == null) {
+ if (from == null || from.equals(account.getJid())) {
return;
}
final String type = packet.getAttribute("type");
@@ -202,7 +198,8 @@ public class PresenceParser extends AbstractParser implements
final String show = packet.findChildContent("show");
final Element caps = packet.findChild("c", "http://jabber.org/protocol/caps");
- final Presence presence = Presence.parse(show, caps);
+ final String message = packet.findChildContent("status");
+ final Presence presence = Presence.parse(show, caps, message);
contact.updatePresence(resource, presence);
if (presence.hasCaps() && Config.REQUEST_DISCO) {
mXmppConnectionService.fetchCaps(account, from, presence);