diff --git a/pom.xml b/pom.xml index cb04d17..05aaa6a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.jamppa jamppa jamppa - 0.1.0 + 0.1.1 jar jamppa is a XMPP client/component library https://github.com/abmargb/jamppa diff --git a/src/main/java/org/jamppa/client/plugin/AbstractPlugin.java b/src/main/java/org/jamppa/client/plugin/AbstractPlugin.java index 299dc3a..08f1515 100644 --- a/src/main/java/org/jamppa/client/plugin/AbstractPlugin.java +++ b/src/main/java/org/jamppa/client/plugin/AbstractPlugin.java @@ -25,7 +25,16 @@ public void checkSupport(Element featuresEl) { protected boolean isSupported() { return isSupported; } + + protected void setSupported(boolean isSupported) { + this.isSupported = isSupported; + } + @Override + public void shutdown() { + isSupported = false; + } + protected abstract boolean supports(Element featuresEl); } diff --git a/src/main/java/org/jamppa/client/plugin/Plugin.java b/src/main/java/org/jamppa/client/plugin/Plugin.java index 4b56bfc..9a00059 100644 --- a/src/main/java/org/jamppa/client/plugin/Plugin.java +++ b/src/main/java/org/jamppa/client/plugin/Plugin.java @@ -11,5 +11,7 @@ public interface Plugin { public void checkSupport(Element featuresEl); public Packet parse(Element el); + + public void shutdown(); } diff --git a/src/main/java/org/jamppa/client/plugin/xep0077/XEP0077.java b/src/main/java/org/jamppa/client/plugin/xep0077/XEP0077.java index 0c74110..435515d 100644 --- a/src/main/java/org/jamppa/client/plugin/xep0077/XEP0077.java +++ b/src/main/java/org/jamppa/client/plugin/xep0077/XEP0077.java @@ -44,11 +44,19 @@ public String getAccountAttribute(String name) { return null; } + private void checkAccountCreationSupported() throws XMPPException { + if (!isSupported()) { + Registration info = getRegistrationInfo(); + setSupported(!info.getType().equals(IQ.Type.error)); + if (!isSupported()) { + throw new XMPPException("Server does not support account creation."); + } + } + } + public void createAccount(String bareJid, String password) throws XMPPException { - if (!isSupported()) { - throw new XMPPException("Server does not support account creation."); - } + checkAccountCreationSupported(); Map attributes = new HashMap(); for (String attributeName : getAccountAttributes()) { attributes.put(attributeName, ""); @@ -58,16 +66,17 @@ public void createAccount(String bareJid, String password) public void createAccount(String bareJid, String password, Map attributes) throws XMPPException { - if (!isSupported()) { - throw new XMPPException("Server does not support account creation."); - } + checkAccountCreationSupported(); + Registration reg = new Registration(); reg.setType(IQ.Type.set); + XMPPConnection connection = getXMPPClient().getConnection(); reg.setTo(connection.getServiceName()); attributes.put("username", new JID(bareJid).getNode()); attributes.put("password", password); reg.setAttributes(attributes); + SyncPacketSend.getReply(connection, reg); } diff --git a/src/main/java/org/jivesoftware/smack/XMPPConnection.java b/src/main/java/org/jivesoftware/smack/XMPPConnection.java index eb5dc47..2812fef 100644 --- a/src/main/java/org/jivesoftware/smack/XMPPConnection.java +++ b/src/main/java/org/jivesoftware/smack/XMPPConnection.java @@ -495,6 +495,11 @@ protected void shutdown(Presence unavailablePresence) { } catch (Exception e) { e.printStackTrace(); } + + for (Plugin plugin : plugins) { + plugin.shutdown(); + } + // In most cases the close() should be successful, so set // connected to false here. connected = false;