Skip to content

Commit

Permalink
Fixes #3. Prepare for release 0.1.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
abmargb committed Mar 14, 2014
1 parent 71e1c79 commit 22b780a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>org.jamppa</groupId>
<artifactId>jamppa</artifactId>
<name>jamppa</name>
<version>0.1.0</version>
<version>0.1.1</version>
<packaging>jar</packaging>
<description>jamppa is a XMPP client/component library</description>
<url>https://github.com/abmargb/jamppa</url>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jamppa/client/plugin/AbstractPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
2 changes: 2 additions & 0 deletions src/main/java/org/jamppa/client/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public interface Plugin {
public void checkSupport(Element featuresEl);

public Packet parse(Element el);

public void shutdown();

}
21 changes: 15 additions & 6 deletions src/main/java/org/jamppa/client/plugin/xep0077/XEP0077.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> attributes = new HashMap<String, String>();
for (String attributeName : getAccountAttributes()) {
attributes.put(attributeName, "");
Expand All @@ -58,16 +66,17 @@ public void createAccount(String bareJid, String password)

public void createAccount(String bareJid, String password,
Map<String, String> 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);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jivesoftware/smack/XMPPConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 22b780a

Please sign in to comment.