fixed a couple of muc issues. added jingle listener (which doesn't do anything for now)

This commit is contained in:
Daniel Gultsch 2014-03-27 02:02:59 +01:00
parent f4c9c19ec0
commit 4864f7200b
10 changed files with 173 additions and 32 deletions

View File

@ -293,7 +293,7 @@ public class Conversation extends AbstractEntity {
return this.otrFingerprint; return this.otrFingerprint;
} }
public MucOptions getMucOptions() { public synchronized MucOptions getMucOptions() {
if (this.mucOptions == null) { if (this.mucOptions == null) {
this.mucOptions = new MucOptions(); this.mucOptions = new MucOptions();
} }

View File

@ -107,7 +107,7 @@ public class MucOptions {
String type = packet.getAttribute("type"); String type = packet.getAttribute("type");
if (type==null) { if (type==null) {
User user = new User(); User user = new User();
Element item = packet.findChild("x").findChild("item"); Element item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item");
user.setName(name); user.setName(name);
user.setAffiliation(item.getAttribute("affiliation")); user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role")); user.setRole(item.getAttribute("role"));
@ -121,7 +121,7 @@ public class MucOptions {
} }
} else if (type.equals("unavailable")) { } else if (type.equals("unavailable")) {
if (name.equals(getNick())) { if (name.equals(getNick())) {
Element item = packet.findChild("x").findChild("item"); Element item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item");
String nick = item.getAttribute("nick"); String nick = item.getAttribute("nick");
if (nick!=null) { if (nick!=null) {
aboutToRename = false; aboutToRename = false;

View File

@ -39,6 +39,7 @@ import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnBindListener; import eu.siacs.conversations.xmpp.OnBindListener;
import eu.siacs.conversations.xmpp.OnIqPacketReceived; import eu.siacs.conversations.xmpp.OnIqPacketReceived;
import eu.siacs.conversations.xmpp.OnJinglePacketReceived;
import eu.siacs.conversations.xmpp.OnMessagePacketReceived; import eu.siacs.conversations.xmpp.OnMessagePacketReceived;
import eu.siacs.conversations.xmpp.OnPresencePacketReceived; import eu.siacs.conversations.xmpp.OnPresencePacketReceived;
import eu.siacs.conversations.xmpp.OnStatusChanged; import eu.siacs.conversations.xmpp.OnStatusChanged;
@ -47,6 +48,7 @@ import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.stanzas.IqPacket; import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket; import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket; import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
import eu.siacs.conversations.xmpp.stanzas.jingle.JinglePacket;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
@ -230,12 +232,18 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onPresencePacketReceived(Account account, public void onPresencePacketReceived(Account account,
PresencePacket packet) { PresencePacket packet) {
if (packet.hasChild("x") if (packet.hasChild("x","http://jabber.org/protocol/muc#user")) {
&& (packet.findChild("x").getAttribute("xmlns")
.startsWith("http://jabber.org/protocol/muc"))) {
Conversation muc = findMuc( Conversation muc = findMuc(
packet.getAttribute("from").split("/")[0], account); packet.getAttribute("from").split("/")[0], account);
if (muc != null) { if (muc != null) {
muc.getMucOptions().processPacket(packet);
} else {
Log.d(LOGTAG,account.getJid()+": could not find muc for received muc package "+packet.toString());
}
} else if (packet.hasChild("x","http://jabber.org/protocol/muc")) {
Conversation muc = findMuc(packet.getAttribute("from").split("/")[0], account);
if (muc != null) {
Log.d(LOGTAG,account.getJid()+": reading muc status packet "+packet.toString());
int error = muc.getMucOptions().getError(); int error = muc.getMucOptions().getError();
muc.getMucOptions().processPacket(packet); muc.getMucOptions().processPacket(packet);
if ((muc.getMucOptions().getError() != error) if ((muc.getMucOptions().getError() != error)
@ -267,10 +275,8 @@ public class XmppConnectionService extends Service {
contact.updatePresence(fromParts[1], Presences.parseShow(packet.findChild("show"))); contact.updatePresence(fromParts[1], Presences.parseShow(packet.findChild("show")));
PgpEngine pgp = getPgpEngine(); PgpEngine pgp = getPgpEngine();
if (pgp != null) { if (pgp != null) {
Element x = packet.findChild("x"); Element x = packet.findChild("x","jabber:x:signed");
if ((x != null) if (x != null) {
&& (x.getAttribute("xmlns")
.equals("jabber:x:signed"))) {
try { try {
contact.setPgpKeyId(pgp.fetchKeyId( contact.setPgpKeyId(pgp.fetchKeyId(
packet.findChild("status") packet.findChild("status")
@ -311,7 +317,7 @@ public class XmppConnectionService extends Service {
// TODO: ask user to handle it maybe // TODO: ask user to handle it maybe
} }
} else { } else {
// Log.d(LOGTAG, packet.toString()); //Log.d(LOGTAG, packet.toString());
} }
replaceContactInConversation(contact.getJid(), contact); replaceContactInConversation(contact.getJid(), contact);
} }
@ -334,6 +340,14 @@ public class XmppConnectionService extends Service {
} }
}; };
private OnJinglePacketReceived jingleListener = new OnJinglePacketReceived() {
@Override
public void onJinglePacketReceived(Account account, JinglePacket packet) {
Log.d(LOGTAG,account.getJid()+": jingle packet received"+packet.toString());
}
};
private OpenPgpServiceConnection pgpServiceConnection; private OpenPgpServiceConnection pgpServiceConnection;
private PgpEngine mPgpEngine = null; private PgpEngine mPgpEngine = null;
private Intent pingIntent; private Intent pingIntent;
@ -498,6 +512,8 @@ public class XmppConnectionService extends Service {
databaseBackend = DatabaseBackend.getInstance(getApplicationContext()); databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
this.accounts = databaseBackend.getAccounts(); this.accounts = databaseBackend.getAccounts();
this.getConversations();
getContentResolver().registerContentObserver( getContentResolver().registerContentObserver(
ContactsContract.Contacts.CONTENT_URI, true, contactObserver); ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
this.pgpServiceConnection = new OpenPgpServiceConnection( this.pgpServiceConnection = new OpenPgpServiceConnection(
@ -569,6 +585,7 @@ public class XmppConnectionService extends Service {
connection.setOnPresencePacketReceivedListener(this.presenceListener); connection.setOnPresencePacketReceivedListener(this.presenceListener);
connection connection
.setOnUnregisteredIqPacketReceivedListener(this.unknownIqListener); .setOnUnregisteredIqPacketReceivedListener(this.unknownIqListener);
connection.setOnJinglePacketReceivedListener(this.jingleListener);
connection connection
.setOnTLSExceptionReceivedListener(new OnTLSExceptionReceived() { .setOnTLSExceptionReceivedListener(new OnTLSExceptionReceived() {
@ -897,9 +914,6 @@ public class XmppConnectionService extends Service {
conversation.setAccount(account); conversation.setAccount(account);
if (muc) { if (muc) {
conversation.setMode(Conversation.MODE_MULTI); conversation.setMode(Conversation.MODE_MULTI);
if (account.getStatus() == Account.STATUS_ONLINE) {
joinMuc(conversation);
}
} else { } else {
conversation.setMode(Conversation.MODE_SINGLE); conversation.setMode(Conversation.MODE_SINGLE);
} }
@ -919,9 +933,6 @@ public class XmppConnectionService extends Service {
if (muc) { if (muc) {
conversation = new Conversation(conversationName, account, jid, conversation = new Conversation(conversationName, account, jid,
Conversation.MODE_MULTI); Conversation.MODE_MULTI);
if (account.getStatus() == Account.STATUS_ONLINE) {
joinMuc(conversation);
}
} else { } else {
conversation = new Conversation(conversationName, account, jid, conversation = new Conversation(conversationName, account, jid,
Conversation.MODE_SINGLE); Conversation.MODE_SINGLE);
@ -930,6 +941,9 @@ public class XmppConnectionService extends Service {
this.databaseBackend.createConversation(conversation); this.databaseBackend.createConversation(conversation);
} }
this.conversations.add(conversation); this.conversations.add(conversation);
if ((account.getStatus() == Account.STATUS_ONLINE)&&(conversation.getMode() == Conversation.MODE_MULTI)) {
joinMuc(conversation);
}
if (this.convChangedListener != null) { if (this.convChangedListener != null) {
this.convChangedListener.onConversationListChanged(); this.convChangedListener.onConversationListChanged();
} }
@ -1037,6 +1051,7 @@ public class XmppConnectionService extends Service {
x.addChild("history").setAttribute("seconds", diff + ""); x.addChild("history").setAttribute("seconds", diff + "");
} }
packet.addChild(x); packet.addChild(x);
Log.d(LOGTAG,conversation.getAccount().getJid()+": joining muc "+packet.toString());
conversation.getAccount().getXmppConnection() conversation.getAccount().getXmppConnection()
.sendPresencePacket(packet); .sendPresencePacket(packet);
} }

View File

@ -82,9 +82,6 @@ public class MucDetailsActivity extends XmppActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
this.uuid = getIntent().getExtras().getString("uuid");
}
setContentView(R.layout.activity_muc_details); setContentView(R.layout.activity_muc_details);
mYourNick = (EditText) findViewById(R.id.muc_your_nick); mYourNick = (EditText) findViewById(R.id.muc_your_nick);
mFullJid = (TextView) findViewById(R.id.muc_jabberid); mFullJid = (TextView) findViewById(R.id.muc_jabberid);
@ -135,6 +132,9 @@ public class MucDetailsActivity extends XmppActivity {
void onBackendConnected() { void onBackendConnected() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean useSubject = preferences.getBoolean("use_subject_in_muc", true); boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
if (getIntent().getAction().equals(ACTION_VIEW_MUC)) {
this.uuid = getIntent().getExtras().getString("uuid");
}
if (uuid != null) { if (uuid != null) {
for (Conversation mConv : xmppConnectionService.getConversations()) { for (Conversation mConv : xmppConnectionService.getConversations()) {
if (mConv.getUuid().equals(uuid)) { if (mConv.getUuid().equals(uuid)) {
@ -183,6 +183,8 @@ public class MucDetailsActivity extends XmppActivity {
membersView.addView(view); membersView.addView(view);
} }
} }
} else {
Log.d("xmppService","uuid in muc details was null");
} }
} }
} }

View File

@ -50,19 +50,34 @@ public class Element {
return null; return null;
} }
public boolean hasChild(String name) { public Element findChild(String name, String xmlns) {
for(Element child : this.children) { for(Element child : this.children) {
if (child.getName().equals(name)) { if (child.getName().equals(name)&&(child.getAttribute("xmlns").equals(xmlns))) {
return true; return child;
} }
} }
return false; return null;
} }
public boolean hasChild(String name) {
return findChild(name) != null;
}
public boolean hasChild(String name, String xmlns) {
return findChild(name, xmlns) != null;
}
public List<Element> getChildren() { public List<Element> getChildren() {
return this.children; return this.children;
} }
public Element setChildren(List<Element> children) {
this.children = children;
return this;
}
public String getContent() { public String getContent() {
return content; return content;
} }
@ -85,6 +100,10 @@ public class Element {
} }
} }
public Hashtable<String, String> getAttributes() {
return this.attributes;
}
public String toString() { public String toString() {
StringBuilder elementOutput = new StringBuilder(); StringBuilder elementOutput = new StringBuilder();
if ((content==null)&&(children.size() == 0)) { if ((content==null)&&(children.size() == 0)) {

View File

@ -0,0 +1,8 @@
package eu.siacs.conversations.xmpp;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.xmpp.stanzas.jingle.JinglePacket;
public interface OnJinglePacketReceived extends PacketReceived {
public void onJinglePacketReceived(Account account, JinglePacket packet);
}

View File

@ -46,6 +46,7 @@ import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
import eu.siacs.conversations.xmpp.stanzas.IqPacket; import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket; import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
import eu.siacs.conversations.xmpp.stanzas.PresencePacket; import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
import eu.siacs.conversations.xmpp.stanzas.jingle.JinglePacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.AckPacket; import eu.siacs.conversations.xmpp.stanzas.streammgmt.AckPacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket; import eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket;
import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket; import eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket;
@ -86,6 +87,7 @@ public class XmppConnection implements Runnable {
private Hashtable<String, PacketReceived> packetCallbacks = new Hashtable<String, PacketReceived>(); private Hashtable<String, PacketReceived> packetCallbacks = new Hashtable<String, PacketReceived>();
private OnPresencePacketReceived presenceListener = null; private OnPresencePacketReceived presenceListener = null;
private OnJinglePacketReceived jingleListener = null;
private OnIqPacketReceived unregisteredIqListener = null; private OnIqPacketReceived unregisteredIqListener = null;
private OnMessagePacketReceived messageListener = null; private OnMessagePacketReceived messageListener = null;
private OnStatusChanged statusListener = null; private OnStatusChanged statusListener = null;
@ -284,6 +286,10 @@ public class XmppConnection implements Runnable {
while (!nextTag.isEnd(element.getName())) { while (!nextTag.isEnd(element.getName())) {
if (!nextTag.isNo()) { if (!nextTag.isNo()) {
Element child = tagReader.readElement(nextTag); Element child = tagReader.readElement(nextTag);
if ((packetType == PACKET_IQ)&&("jingle".equals(child.getName()))) {
element = new JinglePacket();
element.setAttributes(currentTag.getAttributes());
}
element.addChild(child); element.addChild(child);
} }
nextTag = tagReader.readTag(); nextTag = tagReader.readTag();
@ -296,15 +302,22 @@ public class XmppConnection implements Runnable {
private void processIq(Tag currentTag) throws XmlPullParserException, private void processIq(Tag currentTag) throws XmlPullParserException,
IOException { IOException {
IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ); IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
if (packetCallbacks.containsKey(packet.getId())) {
if (packetCallbacks.get(packet.getId()) instanceof OnIqPacketReceived) {
((OnIqPacketReceived) packetCallbacks.get(packet.getId()))
.onIqPacketReceived(account, packet);
}
packetCallbacks.remove(packet.getId()); if (packet instanceof JinglePacket) {
} else if (this.unregisteredIqListener != null) { if (this.jingleListener !=null) {
this.unregisteredIqListener.onIqPacketReceived(account, packet); this.jingleListener.onJinglePacketReceived(account, (JinglePacket) packet);
}
} else {
if (packetCallbacks.containsKey(packet.getId())) {
if (packetCallbacks.get(packet.getId()) instanceof OnIqPacketReceived) {
((OnIqPacketReceived) packetCallbacks.get(packet.getId()))
.onIqPacketReceived(account, packet);
}
packetCallbacks.remove(packet.getId());
} else if (this.unregisteredIqListener != null) {
this.unregisteredIqListener.onIqPacketReceived(account, packet);
}
} }
} }
@ -685,6 +698,10 @@ public class XmppConnection implements Runnable {
this.presenceListener = listener; this.presenceListener = listener;
} }
public void setOnJinglePacketReceivedListener(OnJinglePacketReceived listener) {
this.jingleListener = listener;
}
public void setOnStatusChangedListener(OnStatusChanged listener) { public void setOnStatusChangedListener(OnStatusChanged listener) {
this.statusListener = listener; this.statusListener = listener;
} }

View File

@ -0,0 +1,13 @@
package eu.siacs.conversations.xmpp.stanzas.jingle;
import eu.siacs.conversations.xml.Element;
public class Content extends Element {
private Content(String name) {
super(name);
}
public Content() {
super("content");
}
}

View File

@ -0,0 +1,54 @@
package eu.siacs.conversations.xmpp.stanzas.jingle;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JinglePacket extends IqPacket {
Content content = null;
Reason reason = null;
@Override
public Element addChild(Element child) {
if ("jingle".equals(child.getName())) {
Element contentElement = child.findChild("content");
if (contentElement!=null) {
this.content = new Content();
this.content.setChildren(contentElement.getChildren());
this.content.setAttributes(contentElement.getAttributes());
}
Element reasonElement = child.findChild("reason");
if (reasonElement!=null) {
this.reason = new Reason();
this.reason.setChildren(reasonElement.getChildren());
this.reason.setAttributes(reasonElement.getAttributes());
}
this.build();
this.findChild("jingle").setAttributes(child.getAttributes());
}
return child;
}
public JinglePacket setContent(Content content) {
this.content = content;
this.build();
return this;
}
public JinglePacket setReason(Reason reason) {
this.reason = reason;
this.build();
return this;
}
private void build() {
this.children.clear();
Element jingle = addChild("jingle", "urn:xmpp:jingle:1");
if (this.content!=null) {
jingle.addChild(this.content);
}
if (this.reason != null) {
jingle.addChild(this.reason);
}
this.children.add(jingle);
}
}

View File

@ -0,0 +1,13 @@
package eu.siacs.conversations.xmpp.stanzas.jingle;
import eu.siacs.conversations.xml.Element;
public class Reason extends Element {
private Reason(String name) {
super(name);
}
public Reason() {
super("reason");
}
}