aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/xmpp')
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java56
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java34
2 files changed, 87 insertions, 3 deletions
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index d653e06a..5a29ad62 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -98,6 +98,9 @@ public class XmppConnection implements Runnable {
protected void changeStatus(int nextStatus) {
if (account.getStatus() != nextStatus) {
+ if ((nextStatus == Account.STATUS_OFFLINE)&&(account.getStatus() != Account.STATUS_CONNECTING)&&(account.getStatus() != Account.STATUS_ONLINE)) {
+ return;
+ }
account.setStatus(nextStatus);
if (statusListener != null) {
statusListener.onStatusChanged(account);
@@ -186,9 +189,6 @@ public class XmppConnection implements Runnable {
&& (!account.isOptionSet(Account.OPTION_USETLS))) {
changeStatus(Account.STATUS_SERVER_REQUIRES_TLS);
}
- if (account.isOptionSet(Account.OPTION_REGISTER)) {
- Log.d(LOGTAG,account.getJid()+": trying to register");
- }
} else if (nextTag.isStart("proceed")) {
switchOverToTls(nextTag);
} else if (nextTag.isStart("success")) {
@@ -440,6 +440,43 @@ public class XmppConnection implements Runnable {
if (this.streamFeatures.hasChild("starttls")
&& account.isOptionSet(Account.OPTION_USETLS)) {
sendStartTLS();
+ } else if (this.streamFeatures.hasChild("register")&&(account.isOptionSet(Account.OPTION_REGISTER))) {
+ IqPacket register = new IqPacket(IqPacket.TYPE_GET);
+ register.query("jabber:iq:register");
+ register.setTo(account.getServer());
+ sendIqPacket(register, new OnIqPacketReceived() {
+
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ Element instructions = packet.query().findChild("instructions");
+ if (packet.query().hasChild("username")&&(packet.query().hasChild("password"))) {
+ IqPacket register = new IqPacket(IqPacket.TYPE_SET);
+ Element username = new Element("username").setContent(account.getUsername());
+ Element password = new Element("password").setContent(account.getPassword());
+ register.query("jabber:iq:register").addChild(username).addChild(password);
+ sendIqPacket(register, new OnIqPacketReceived() {
+
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ if (packet.getType()==IqPacket.TYPE_RESULT) {
+ account.setOption(Account.OPTION_REGISTER, false);
+ changeStatus(Account.STATUS_REGISTRATION_SUCCESSFULL);
+ Log.d(LOGTAG,"successfull");
+ } else if (packet.hasChild("error")&&(packet.findChild("error").hasChild("conflict"))){
+ changeStatus(Account.STATUS_REGISTRATION_CONFLICT);
+ } else {
+ changeStatus(Account.STATUS_REGISTRATION_FAILED);
+ Log.d(LOGTAG,packet.toString());
+ }
+ disconnect(true);
+ }
+ });
+ Log.d(LOGTAG,"registering: "+register.toString());
+ } else {
+ Log.d(LOGTAG,account.getJid()+": could not register. instructions are"+instructions.getContent());
+ }
+ }
+ });
} else if (this.streamFeatures.hasChild("mechanisms")
&& shouldAuthenticate) {
sendSaslAuth();
@@ -651,6 +688,7 @@ public class XmppConnection implements Runnable {
}
public void disconnect(boolean force) {
+ changeStatus(Account.STATUS_OFFLINE);
Log.d(LOGTAG,"disconnecting");
try {
if (force) {
@@ -677,6 +715,18 @@ public class XmppConnection implements Runnable {
return this.streamFeatures.hasChild("ver");
}
}
+
+ public boolean hasFeatureStreamManagment() {
+ if (this.streamFeatures==null) {
+ return false;
+ } else {
+ return this.streamFeatures.hasChild("has");
+ }
+ }
+
+ public boolean hasFeaturesCarbon() {
+ return discoFeatures.contains("urn:xmpp:carbons:2");
+ }
public void r() {
this.tagWriter.writeStanzaAsync(new RequestPacket());
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java b/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
index 1675d19d..f70a74dd 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
+++ b/src/eu/siacs/conversations/xmpp/stanzas/IqPacket.java
@@ -1,8 +1,12 @@
package eu.siacs.conversations.xmpp.stanzas;
+import android.graphics.YuvImage;
+import eu.siacs.conversations.xml.Element;
+
public class IqPacket extends AbstractStanza {
+ public static final int TYPE_ERROR = -1;
public static final int TYPE_SET = 0;
public static final int TYPE_RESULT = 1;
public static final int TYPE_GET = 2;
@@ -31,5 +35,35 @@ public class IqPacket extends AbstractStanza {
public IqPacket() {
super("iq");
}
+
+ public Element query() {
+ Element query = findChild("query");
+ if (query==null) {
+ query = new Element("query");
+ addChild(query);
+ }
+ return query;
+ }
+
+ public Element query(String xmlns) {
+ Element query = query();
+ query.setAttribute("xmlns", xmlns);
+ return query();
+ }
+
+ public int getType() {
+ String type = getAttribute("type");
+ if ("error".equals(type)) {
+ return TYPE_ERROR;
+ } else if ("result".equals(type)) {
+ return TYPE_RESULT;
+ } else if ("set".equals(type)) {
+ return TYPE_SET;
+ } else if ("get".equals(type)) {
+ return TYPE_GET;
+ } else {
+ return 1000;
+ }
+ }
}