diff --git a/source/org/jivesoftware/smack/AccountManager.java b/source/org/jivesoftware/smack/AccountManager.java index 5a0ebfb17..d68b1f5a0 100644 --- a/source/org/jivesoftware/smack/AccountManager.java +++ b/source/org/jivesoftware/smack/AccountManager.java @@ -28,10 +28,7 @@ import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Registration; import org.jivesoftware.smack.util.StringUtils; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; +import java.util.*; /** * Allows creation and management of accounts on an XMPP server. @@ -73,8 +70,8 @@ public class AccountManager { } /** - * Returns an Iterator for the (String) names of the required account attributes. - * All attributes must be set when creating new accounts. The standard + * Returns an unmodifiable collection of the names of the required account attributes. + * All attributes must be set when creating new accounts. The standard set of possible * attributes are as follows:
+ * The default subscription mode is {@link SubscriptionMode#accept_all}.
* * If using the manual mode, a PacketListener should be registered that * listens for Presence packets that have a type of @@ -140,14 +121,14 @@ public class Roster { * * @return the subscription mode. */ - public int getSubscriptionMode() { + public SubscriptionMode getSubscriptionMode() { return subscriptionMode; } /** * Sets the subscription processing mode, which dictates what action * Smack will take when subscription requests from other users are made. - * The default subscription mode is {@link #SUBSCRIPTION_ACCEPT_ALL}.
+ * The default subscription mode is {@link SubscriptionMode#accept_all}.
*
* If using the manual mode, a PacketListener should be registered that
* listens for Presence packets that have a type of
@@ -155,13 +136,7 @@ public class Roster {
*
* @param subscriptionMode the subscription mode.
*/
- public void setSubscriptionMode(int subscriptionMode) {
- if (subscriptionMode != SUBSCRIPTION_ACCEPT_ALL &&
- subscriptionMode != SUBSCRIPTION_REJECT_ALL &&
- subscriptionMode != SUBSCRIPTION_MANUAL)
- {
- throw new IllegalArgumentException("Invalid mode.");
- }
+ public void setSubscriptionMode(SubscriptionMode subscriptionMode) {
this.subscriptionMode = subscriptionMode;
}
@@ -342,15 +317,14 @@ public class Roster {
}
/**
- * Returns an Iterator for the unfiled roster entries. An unfiled entry is
+ * Returns an unmodifiable collection for the unfiled roster entries. An unfiled entry is
* an entry that doesn't belong to any groups.
*
- * @return an iterator the unfiled roster entries.
+ * @return the unfiled roster entries.
*/
- public Iterator
- *
+ *
* If the user has several presences (one for each resource) then answer the presence
* with the highest priority.
*
@@ -472,7 +446,7 @@ public class Roster {
* when you are not subscribed to the user's presence updates.
*
* @param userResource a fully qualified xmpp ID including a resource.
- * @return the user's current presence, or null if the user is unavailable
+ * @return the user's current presence, or null if the user is unavailable
* or if no presence information is available.
*/
public Presence getPresenceResource(String userResource) {
@@ -575,6 +549,32 @@ public class Roster {
}
}
+ /**
+ * An enumeration for the subscription mode options.
+ */
+ public enum SubscriptionMode {
+
+ /**
+ * Automatically accept all subscription and unsubscription requests. This is
+ * the default mode and is suitable for simple client. More complex client will
+ * likely wish to handle subscription requests manually.
+ */
+ accept_all,
+
+ /**
+ * Automatically reject all subscription requests.
+ */
+ reject_all,
+
+ /**
+ * Subscription requests are ignored, which means they must be manually
+ * processed by registering a listener for presence packets and then looking
+ * for any presence requests that have the type Presence.Type.SUBSCRIBE or
+ * Presence.Type.UNSUBSCRIBE.
+ */
+ manual
+ }
+
/**
* Listens for all presence packets and processes them.
*/
@@ -630,13 +630,13 @@ public class Roster {
}
}
else if (presence.getType() == Presence.Type.subscribe) {
- if (subscriptionMode == SUBSCRIPTION_ACCEPT_ALL) {
+ if (subscriptionMode == SubscriptionMode.accept_all) {
// Accept all subscription requests.
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(presence.getFrom());
connection.sendPacket(response);
}
- else if (subscriptionMode == SUBSCRIPTION_REJECT_ALL) {
+ else if (subscriptionMode == SubscriptionMode.reject_all) {
// Reject all subscription requests.
Presence response = new Presence(Presence.Type.unsubscribed);
response.setTo(presence.getFrom());
@@ -645,9 +645,9 @@ public class Roster {
// Otherwise, in manual mode so ignore.
}
else if (presence.getType() == Presence.Type.unsubscribe) {
- if (subscriptionMode != SUBSCRIPTION_MANUAL) {
+ if (subscriptionMode != SubscriptionMode.manual) {
// Acknowledge and accept unsubscription notification so that the
- // server will stop sending notifications saying that the contact
+ // server will stop sending notifications saying that the contact
// has unsubscribed to our presence.
Presence response = new Presence(Presence.Type.unsubscribed);
response.setTo(presence.getFrom());
diff --git a/source/org/jivesoftware/smack/SSLXMPPConnection.java b/source/org/jivesoftware/smack/SSLXMPPConnection.java
deleted file mode 100644
index bb3a72f98..000000000
--- a/source/org/jivesoftware/smack/SSLXMPPConnection.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * $RCSfile$
- * $Revision$
- * $Date$
- *
- * Copyright 2003-2004 Jive Software.
- *
- * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jivesoftware.smack;
-
-import javax.net.SocketFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManager;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-
-/**
- * Creates an SSL connection to a XMPP server using the legacy dedicated SSL port
- * mechanism. Fully compliant XMPP 1.0 servers (e.g. Wildfire 2.4.0) do not
- * require using a dedicated SSL port. Instead, TLS (a standardized version of SSL 3.0)
- * is dynamically negotiated over the standard XMPP port. Therefore, only use this
- * class to connect to an XMPP server if you know that the server does not support
- * XMPP 1.0 TLS connections.
- *
- * @author Matt Tucker
- */
-public class SSLXMPPConnection extends XMPPConnection {
-
- private static SocketFactory socketFactory = new DummySSLSocketFactory();
-
- /**
- * Creates a new SSL connection to the specified host on the default
- * SSL port (5223). The IP address of the server is assumed to match the
- * service name.
- *
- * @param host the XMPP host.
- * @throws XMPPException if an error occurs while trying to establish the connection.
- * Two possible errors can occur which will be wrapped by an XMPPException --
- * UnknownHostException (XMPP error code 504), and IOException (XMPP error code
- * 502). The error codes and wrapped exceptions can be used to present more
- * appropiate error messages to end-users.
- */
- public SSLXMPPConnection(String host) throws XMPPException {
- this(host, 5223);
- }
-
- /**
- * Creates a new SSL connection to the specified host on the specified port. The IP address
- * of the server is assumed to match the service name.
- *
- * @param host the XMPP host.
- * @param port the port to use for the connection (default XMPP SSL port is 5223).
- * @throws XMPPException if an error occurs while trying to establish the connection.
- * Two possible errors can occur which will be wrapped by an XMPPException --
- * UnknownHostException (XMPP error code 504), and IOException (XMPP error code
- * 502). The error codes and wrapped exceptions can be used to present more
- * appropiate error messages to end-users.
- */
- public SSLXMPPConnection(String host, int port) throws XMPPException {
- this(host, port, host);
- }
-
- /**
- * Creates a new SSL connection to the specified XMPP server on the given host and port.
- *
- * @param host the host name, or null for the loopback address.
- * @param port the port on the server that should be used (default XMPP SSL port is 5223).
- * @param serviceName the name of the XMPP server to connect to; e.g. jivesoftware.com.
- * @throws XMPPException if an error occurs while trying to establish the connection.
- * Two possible errors can occur which will be wrapped by an XMPPException --
- * UnknownHostException (XMPP error code 504), and IOException (XMPP error code
- * 502). The error codes and wrapped exceptions can be used to present more
- * appropiate error messages to end-users.
- */
- public SSLXMPPConnection(String host, int port, String serviceName) throws XMPPException {
- super(host, port, serviceName, socketFactory);
- }
-
- public boolean isSecureConnection() {
- return true;
- }
-
- /**
- * An SSL socket factory that will let any certifacte past, even if it's expired or
- * not singed by a root CA.
- */
- private static class DummySSLSocketFactory extends SSLSocketFactory {
-
- private SSLSocketFactory factory;
-
- public DummySSLSocketFactory() {
-
- try {
- SSLContext sslcontent = SSLContext.getInstance("TLS");
- sslcontent.init(null, // KeyManager not required
- new TrustManager[] { new OpenTrustManager() },
- new java.security.SecureRandom());
- factory = sslcontent.getSocketFactory();
- }
- catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- catch (KeyManagementException e) {
- e.printStackTrace();
- }
- }
-
- public static SocketFactory getDefault() {
- return new DummySSLSocketFactory();
- }
-
- public Socket createSocket(Socket socket, String s, int i, boolean flag)
- throws IOException
- {
- return factory.createSocket(socket, s, i, flag);
- }
-
- public Socket createSocket(InetAddress inaddr, int i, InetAddress inaddr2, int j)
- throws IOException
- {
- return factory.createSocket(inaddr, i, inaddr2, j);
- }
-
- public Socket createSocket(InetAddress inaddr, int i) throws IOException {
- return factory.createSocket(inaddr, i);
- }
-
- public Socket createSocket(String s, int i, InetAddress inaddr, int j) throws IOException {
- return factory.createSocket(s, i, inaddr, j);
- }
-
- public Socket createSocket(String s, int i) throws IOException {
- return factory.createSocket(s, i);
- }
-
- public String[] getDefaultCipherSuites() {
- return factory.getSupportedCipherSuites();
- }
-
- public String[] getSupportedCipherSuites() {
- return factory.getSupportedCipherSuites();
- }
- }
-}
diff --git a/source/org/jivesoftware/smack/SmackConfiguration.java b/source/org/jivesoftware/smack/SmackConfiguration.java
index 40500f442..2e83f56f1 100644
--- a/source/org/jivesoftware/smack/SmackConfiguration.java
+++ b/source/org/jivesoftware/smack/SmackConfiguration.java
@@ -44,7 +44,7 @@ import java.util.Enumeration;
*/
public final class SmackConfiguration {
- private static final String SMACK_VERSION = "2.2.1";
+ private static final String SMACK_VERSION = "3.0.0";
private static int packetReplyTimeout = 5000;
private static int keepAliveInterval = 30000;
@@ -100,6 +100,7 @@ public final class SmackConfiguration {
systemStream.close();
}
catch (Exception e) {
+ // Ignore.
}
}
}
diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java
index d7ed5fa25..53bb15c98 100644
--- a/source/org/jivesoftware/smack/XMPPConnection.java
+++ b/source/org/jivesoftware/smack/XMPPConnection.java
@@ -178,7 +178,7 @@ public class XMPPConnection {
/**
* Creates a new connection to the XMPP server at the specifiec host and port.
- *
+ *
* @param host the name of the XMPP server to connect to; e.g. jivesoftware.com.
* @param port the port on the server that should be used; e.g. 5222.
* @throws XMPPException if an error occurs while trying to establish the connection.
@@ -941,20 +941,20 @@ public class XMPPConnection {
Class> zoClass = Class.forName("com.jcraft.jzlib.ZOutputStream");
//ZOutputStream out = new ZOutputStream(socket.getOutputStream(), JZlib.Z_BEST_COMPRESSION);
Constructor> constructor =
- zoClass.getConstructor(new Class[]{OutputStream.class, Integer.TYPE});
- Object out = constructor.newInstance(new Object[] {socket.getOutputStream(), new Integer(9)});
+ zoClass.getConstructor(OutputStream.class, Integer.TYPE);
+ Object out = constructor.newInstance(socket.getOutputStream(), 9);
//out.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
- Method method = zoClass.getMethod("setFlushMode", new Class[] {Integer.TYPE});
- method.invoke(out, new Object[] {new Integer(1)});
+ Method method = zoClass.getMethod("setFlushMode", Integer.TYPE);
+ method.invoke(out, 1);
writer = new BufferedWriter(new OutputStreamWriter((OutputStream) out, "UTF-8"));
Class> ziClass = Class.forName("com.jcraft.jzlib.ZInputStream");
//ZInputStream in = new ZInputStream(socket.getInputStream());
- constructor = ziClass.getConstructor(new Class[]{InputStream.class});
- Object in = constructor.newInstance(new Object[] {socket.getInputStream()});
+ constructor = ziClass.getConstructor(InputStream.class);
+ Object in = constructor.newInstance(socket.getInputStream());
//in.setFlushMode(JZlib.Z_PARTIAL_FLUSH);
- method = ziClass.getMethod("setFlushMode", new Class[] {Integer.TYPE});
- method.invoke(in, new Object[] {new Integer(1)});
+ method = ziClass.getMethod("setFlushMode", Integer.TYPE);
+ method.invoke(in, 1);
reader = new BufferedReader(new InputStreamReader((InputStream) in, "UTF-8"));
}
catch (Exception e) {
@@ -982,6 +982,7 @@ public class XMPPConnection {
className = System.getProperty("smack.debuggerClass");
}
catch (Throwable t) {
+ // Ignore.
}
Class> debuggerClass = null;
if (className != null) {
@@ -1010,10 +1011,8 @@ public class XMPPConnection {
// option
try {
Constructor> constructor =
- debuggerClass.getConstructor(
- new Class[] { XMPPConnection.class, Writer.class, Reader.class });
- debugger = (SmackDebugger) constructor
- .newInstance(new Object[]{this, writer, reader});
+ debuggerClass.getConstructor(XMPPConnection.class, Writer.class, Reader.class);
+ debugger = (SmackDebugger) constructor.newInstance(this, writer, reader);
reader = debugger.getReader();
writer = debugger.getWriter();
}
@@ -1143,7 +1142,7 @@ public class XMPPConnection {
* speed network connection. However, the server will need to use more CPU time in order to
* un/compress network data so under high load the server performance might be affected.
*
- * Note: To use stream compression the smackx.jar file has to be present in the classpath.
+ * Note: to use stream compression the smackx.jar file has to be present in the classpath.
*
* @return true if network traffic is being compressed.
*/
@@ -1161,7 +1160,7 @@ public class XMPPConnection {
* zlib method is supported by the client. Stream compression negotiation has to be done
* before authentication took place.
*
- * Note: To use stream compression the smackx.jar file has to be present in the classpath.
+ * Note: to use stream compression the smackx.jar file has to be present in the classpath.
*
* @return true if stream compression negotiation was successful.
*/
@@ -1184,7 +1183,9 @@ public class XMPPConnection {
try {
this.wait(SmackConfiguration.getPacketReplyTimeout() * 5);
}
- catch (InterruptedException e) {}
+ catch (InterruptedException e) {
+ // Ignore.
+ }
}
return usingCompression;
}
diff --git a/source/org/jivesoftware/smack/packet/DefaultPacketExtension.java b/source/org/jivesoftware/smack/packet/DefaultPacketExtension.java
index 3a04356ae..b8a55cff6 100644
--- a/source/org/jivesoftware/smack/packet/DefaultPacketExtension.java
+++ b/source/org/jivesoftware/smack/packet/DefaultPacketExtension.java
@@ -20,10 +20,7 @@
package org.jivesoftware.smack.packet;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
/**
* Default implementation of the PacketExtension interface. Unless a PacketExtensionProvider
@@ -51,7 +48,7 @@ public class DefaultPacketExtension implements PacketExtension {
private String elementName;
private String namespace;
- private Map map;
+ private Map