avoided some null pointers

This commit is contained in:
iNPUTmice 2014-11-17 20:45:00 +01:00
parent f41c3eee04
commit abbadcb58b
3 changed files with 35 additions and 24 deletions

View File

@ -20,7 +20,7 @@ public abstract class AbstractGenerator {
"http://jabber.org/protocol/disco#info", "http://jabber.org/protocol/disco#info",
"urn:xmpp:avatar:metadata+notify", "urn:xmpp:avatar:metadata+notify",
"urn:xmpp:ping"}; "urn:xmpp:ping"};
public final String IDENTITY_NAME = "Conversations 0.8.3"; public final String IDENTITY_NAME = "Conversations 0.9-alpha";
public final String IDENTITY_TYPE = "phone"; public final String IDENTITY_TYPE = "phone";
protected XmppConnectionService mXmppConnectionService; protected XmppConnectionService mXmppConnectionService;

View File

@ -1,5 +1,8 @@
package eu.siacs.conversations.parser; package eu.siacs.conversations.parser;
import android.util.Log;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
@ -68,32 +71,36 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
if (packet.hasChild("query", "jabber:iq:roster")) { if (packet.hasChild("query", "jabber:iq:roster")) {
final Jid from = packet.getFrom(); final Jid from = packet.getFrom();
if ((from == null) || (from.equals(account.getJid().toBareJid()))) { if ((from == null) || (from.equals(account.getJid().toBareJid()))) {
Element query = packet.findChild("query"); Element query = packet.findChild("query");
this.rosterItems(account, query); this.rosterItems(account, query);
} }
} else if (packet.hasChild("open", "http://jabber.org/protocol/ibb")
|| packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
mXmppConnectionService.getJingleConnectionManager()
.deliverIbbPacket(account, packet);
} else if (packet.hasChild("query",
"http://jabber.org/protocol/disco#info")) {
IqPacket response = mXmppConnectionService.getIqGenerator()
.discoResponse(packet);
account.getXmppConnection().sendIqPacket(response, null);
} else if (packet.hasChild("ping", "urn:xmpp:ping")) {
IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT);
mXmppConnectionService.sendIqPacket(account, response, null);
} else { } else {
if ((packet.getType() == IqPacket.TYPE_GET) if (packet.getFrom() == null) {
|| (packet.getType() == IqPacket.TYPE_SET)) { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": received iq with invalid from "+packet.toString());
IqPacket response = packet.generateRespone(IqPacket.TYPE_ERROR); return;
Element error = response.addChild("error"); } else if (packet.hasChild("open", "http://jabber.org/protocol/ibb")
error.setAttribute("type", "cancel"); || packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
error.addChild("feature-not-implemented", mXmppConnectionService.getJingleConnectionManager()
"urn:ietf:params:xml:ns:xmpp-stanzas"); .deliverIbbPacket(account, packet);
} else if (packet.hasChild("query", "http://jabber.org/protocol/disco#info")) {
IqPacket response = mXmppConnectionService.getIqGenerator()
.discoResponse(packet);
account.getXmppConnection().sendIqPacket(response, null); account.getXmppConnection().sendIqPacket(response, null);
} else if (packet.hasChild("ping", "urn:xmpp:ping")) {
IqPacket response = packet.generateRespone(IqPacket.TYPE_RESULT);
mXmppConnectionService.sendIqPacket(account, response, null);
} else {
if ((packet.getType() == IqPacket.TYPE_GET)
|| (packet.getType() == IqPacket.TYPE_SET)) {
IqPacket response = packet.generateRespone(IqPacket.TYPE_ERROR);
Element error = response.addChild("error");
error.setAttribute("type", "cancel");
error.addChild("feature-not-implemented",
"urn:ietf:params:xml:ns:xmpp-stanzas");
account.getXmppConnection().sendIqPacket(response, null);
}
} }
} }
} }

View File

@ -36,11 +36,15 @@ public class AbstractStanza extends Element {
} }
public void setTo(final Jid to) { public void setTo(final Jid to) {
setAttribute("to", to.toString()); if (to != null) {
setAttribute("to", to.toString());
}
} }
public void setFrom(final Jid from) { public void setFrom(final Jid from) {
setAttribute("from", from.toString()); if (from != null) {
setAttribute("from", from.toString());
}
} }
public void setId(final String id) { public void setId(final String id) {