diff --git a/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java index bb6dd2448..057caec65 100644 --- a/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java +++ b/core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java @@ -22,7 +22,9 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -54,17 +56,13 @@ public final class SmackConfiguration { private static final String DEFAULT_CONFIG_FILE = "classpath:org.jivesoftware.smack/smack-config.xml"; private static final Logger log = Logger.getLogger(SmackConfiguration.class.getName()); - - private static InputStream configFileStream; - + private static int defaultPacketReplyTimeout = 5000; + private static int packetCollectorSize = 5000; + private static List defaultMechs = new ArrayList(); - private static boolean localSocks5ProxyEnabled = true; - private static int localSocks5ProxyPort = 7777; - private static int packetCollectorSize = 5000; - - private static boolean initialized = false; + private static Set disabledSmackClasses = new HashSet(); static { String smackVersion; @@ -78,6 +76,34 @@ public final class SmackConfiguration { smackVersion = "unkown"; } SMACK_VERSION = smackVersion; + + String disabledClasses = System.getProperty("smack.disabledClasses"); + if (disabledClasses != null) { + String[] splitDisabledClasses = disabledClasses.split(","); + for (String s : splitDisabledClasses) disabledSmackClasses.add(s); + } + try { + FileUtils.addLines("classpath:org.jivesoftware.smack/disabledClasses", disabledSmackClasses); + } + catch (Exception e) { + throw new IllegalStateException(e); + } + + + InputStream configFileStream; + try { + configFileStream = FileUtils.getStreamForUrl(DEFAULT_CONFIG_FILE, null); + } + catch (Exception e) { + throw new IllegalStateException(e); + } + + try { + processConfigFile(configFileStream, null); + } + catch (Exception e) { + throw new IllegalStateException(e); + } } /** @@ -86,11 +112,6 @@ public final class SmackConfiguration { */ private static ParsingExceptionCallback defaultCallback = new ExceptionThrowingCallback(); - /** - * This automatically enables EntityCaps for new connections if it is set to true - */ - private static boolean autoEnableEntityCaps = true; - private SmackConfiguration() { } @@ -101,39 +122,7 @@ public final class SmackConfiguration { * 1) a set of classes will be loaded in order to execute their static init block * 2) retrieve and set the current Smack release */ - - /** - * Sets the location of the config file on the classpath. Only required if changing from the default location of classpath:org.jivesoftware.smack/smack-config.xml. - * - *

- * This method must be called before accessing any other class in Smack. - * - * @param configFileUrl The location of the config file. - * @param loader The classloader to use if the URL has a protocol of classpath and the file is not located on the default classpath. - * This can be set to null to use defaults and is ignored for all other protocols. - * @throws IllegalArgumentException If the config URL is invalid in that it cannot open an {@link InputStream} - */ - public static void setConfigFileUrl(String configFileUrl, ClassLoader loader) { - try { - configFileStream = FileUtils.getStreamForUrl(configFileUrl, loader); - } - catch (Exception e) { - throw new IllegalArgumentException("Failed to create input stream from specified file URL ["+ configFileUrl + "]", e); - } - initialize(); - } - - /** - * Sets the {@link InputStream} representing the smack configuration file. This can be used to override the default with something that is not on the classpath. - *

- * This method must be called before accessing any other class in Smack. - * @param configFile - */ - public static void setConfigFileStream(InputStream configFile) { - configFileStream = configFile; - initialize(); - } - + /** * Returns the Smack version information, eg "1.3.0". * @@ -150,8 +139,6 @@ public final class SmackConfiguration { * @return the milliseconds to wait for a response from the server */ public static int getDefaultPacketReplyTimeout() { - initialize(); - // The timeout value must be greater than 0 otherwise we will answer the default value if (defaultPacketReplyTimeout <= 0) { defaultPacketReplyTimeout = 5000; @@ -166,8 +153,6 @@ public final class SmackConfiguration { * @param timeout the milliseconds to wait for a response from the server */ public static void setDefaultPacketReplyTimeout(int timeout) { - initialize(); - if (timeout <= 0) { throw new IllegalArgumentException(); } @@ -181,8 +166,7 @@ public final class SmackConfiguration { * @return The number of packets to queue before deleting older packets. */ public static int getPacketCollectorSize() { - initialize(); - return packetCollectorSize; + return packetCollectorSize; } /** @@ -192,8 +176,7 @@ public final class SmackConfiguration { * @param The number of packets to queue before deleting older packets. */ public static void setPacketCollectorSize(int collectorSize) { - initialize(); - packetCollectorSize = collectorSize; + packetCollectorSize = collectorSize; } /** @@ -202,8 +185,6 @@ public final class SmackConfiguration { * @param mech the SASL mechanism to be added */ public static void addSaslMech(String mech) { - initialize(); - if(! defaultMechs.contains(mech) ) { defaultMechs.add(mech); } @@ -215,8 +196,6 @@ public final class SmackConfiguration { * @param mechs the Collection of SASL mechanisms to be added */ public static void addSaslMechs(Collection mechs) { - initialize(); - for(String mech : mechs) { addSaslMech(mech); } @@ -228,7 +207,6 @@ public final class SmackConfiguration { * @param mech the SASL mechanism to be removed */ public static void removeSaslMech(String mech) { - initialize(); defaultMechs.remove(mech); } @@ -238,7 +216,6 @@ public final class SmackConfiguration { * @param mechs the Collection of SASL mechanisms to be removed */ public static void removeSaslMechs(Collection mechs) { - initialize(); defaultMechs.removeAll(mechs); } @@ -253,66 +230,6 @@ public final class SmackConfiguration { return Collections.unmodifiableList(defaultMechs); } - /** - * Returns true if the local Socks5 proxy should be started. Default is true. - * - * @return if the local Socks5 proxy should be started - */ - public static boolean isLocalSocks5ProxyEnabled() { - initialize(); - return localSocks5ProxyEnabled; - } - - /** - * Sets if the local Socks5 proxy should be started. Default is true. - * - * @param localSocks5ProxyEnabled if the local Socks5 proxy should be started - */ - public static void setLocalSocks5ProxyEnabled(boolean localSocks5ProxyEnabled) { - initialize(); - SmackConfiguration.localSocks5ProxyEnabled = localSocks5ProxyEnabled; - } - - /** - * Return the port of the local Socks5 proxy. Default is 7777. - * - * @return the port of the local Socks5 proxy - */ - public static int getLocalSocks5ProxyPort() { - initialize(); - return localSocks5ProxyPort; - } - - /** - * Sets the port of the local Socks5 proxy. Default is 7777. If you set the port to a negative - * value Smack tries the absolute value and all following until it finds an open port. - * - * @param localSocks5ProxyPort the port of the local Socks5 proxy to set - */ - public static void setLocalSocks5ProxyPort(int localSocks5ProxyPort) { - initialize(); - SmackConfiguration.localSocks5ProxyPort = localSocks5ProxyPort; - } - - /** - * Check if Entity Caps are enabled as default for every new connection - * @return - */ - public static boolean autoEnableEntityCaps() { - initialize(); - return autoEnableEntityCaps; - } - - /** - * Set if Entity Caps are enabled or disabled for every new connection - * - * @param true if Entity Caps should be auto enabled, false if not - */ - public static void setAutoEnableEntityCaps(boolean b) { - initialize(); - autoEnableEntityCaps = b; - } - /** * Set the default parsing exception callback for all newly created connections * @@ -320,7 +237,6 @@ public final class SmackConfiguration { * @see ParsingExceptionCallback */ public static void setDefaultParsingExceptionCallback(ParsingExceptionCallback callback) { - initialize(); defaultCallback = callback; } @@ -331,11 +247,35 @@ public final class SmackConfiguration { * @see ParsingExceptionCallback */ public static ParsingExceptionCallback getDefaultParsingExceptionCallback() { - initialize(); return defaultCallback; } - public static void parseClassesToLoad(XmlPullParser parser, boolean optional) throws XmlPullParserException, IOException, Exception { + public static void processConfigFile(InputStream cfgFileStream, Collection exceptions) throws Exception { + XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); + parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); + parser.setInput(cfgFileStream, "UTF-8"); + int eventType = parser.getEventType(); + do { + if (eventType == XmlPullParser.START_TAG) { + if (parser.getName().equals("startupClasses")) { + parseClassesToLoad(parser, false, exceptions); + } + else if (parser.getName().equals("optionalStartupClasses")) { + parseClassesToLoad(parser, true, exceptions); + } + } + eventType = parser.next(); + } + while (eventType != XmlPullParser.END_DOCUMENT); + try { + cfgFileStream.close(); + } + catch (IOException e) { + log.log(Level.SEVERE, "Error while closing config file input stream", e); + } + } + + private static void parseClassesToLoad(XmlPullParser parser, boolean optional, Collection exceptions) throws XmlPullParserException, IOException, Exception { final String startName = parser.getName(); int eventType; String name; @@ -343,13 +283,22 @@ public final class SmackConfiguration { eventType = parser.next(); name = parser.getName(); if (eventType == XmlPullParser.START_TAG && "className".equals(name)) { - String classToLoad = parser.nextText(); - loadSmackClass(classToLoad, optional); + if (disabledSmackClasses.contains(name)) { + log.info("Not loading disabled Smack class " + name); + } + else { + String classToLoad = parser.nextText(); + try { + loadSmackClass(classToLoad, optional); + } catch (Exception e) { + exceptions.add(e); + } + } } } while (! (eventType == XmlPullParser.END_TAG && startName.equals(name))); } - public static void loadSmackClass(String className, boolean optional) throws Exception { + private static void loadSmackClass(String className, boolean optional) throws Exception { // Attempt to load the class so that the class can get initialized try { Class initClass = Class.forName(className); @@ -373,101 +322,4 @@ public final class SmackConfiguration { throw cnfe; } } - - private static int parseIntProperty(XmlPullParser parser, int defaultValue) - throws Exception - { - try { - return Integer.parseInt(parser.nextText()); - } - catch (NumberFormatException nfe) { - log.log(Level.SEVERE, "Could not parse integer", nfe); - return defaultValue; - } - } - - /* - * Order of precedence for config file is VM arg, setConfigXXX methods and embedded default file location. - */ - private static void initialize() { - if (initialized) { - return; - } - initialized = true; - - String configFileLocation = System.getProperty("smack.config.file"); - - if (configFileLocation != null) { - try { - configFileStream = FileUtils.getStreamForUrl(configFileLocation, null); - } - catch (Exception e) { - log.log(Level.SEVERE, "Error creating input stream for config file [" + configFileLocation + "] from VM argument", e); - } - } - - if (configFileStream == null) { - try { - configFileStream = FileUtils.getStreamForUrl(DEFAULT_CONFIG_FILE, null); - } - catch (Exception e) { - throw new IllegalStateException(e); - } - } - - if (configFileStream != null) { - try { - readFile(configFileStream); - } - catch (Exception e) { - throw new IllegalStateException(e); - } - } - else { - log.log(Level.INFO, "No configuration file found"); - } - } - - private static void readFile(InputStream cfgFileStream) throws Exception { - XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - parser.setInput(cfgFileStream, "UTF-8"); - int eventType = parser.getEventType(); - do { - if (eventType == XmlPullParser.START_TAG) { - if (parser.getName().equals("startupClasses")) { - parseClassesToLoad(parser, false); - } - else if (parser.getName().equals("optionalStartupClasses")) { - parseClassesToLoad(parser, true); - } - else if (parser.getName().equals("defaultPacketReplyTimeout")) { - defaultPacketReplyTimeout = parseIntProperty(parser, defaultPacketReplyTimeout); - } - else if (parser.getName().equals("mechName")) { - defaultMechs.add(parser.nextText()); - } - else if (parser.getName().equals("localSocks5ProxyEnabled")) { - localSocks5ProxyEnabled = Boolean.parseBoolean(parser.nextText()); - } - else if (parser.getName().equals("localSocks5ProxyPort")) { - localSocks5ProxyPort = parseIntProperty(parser, localSocks5ProxyPort); - } - else if (parser.getName().equals("packetCollectorSize")) { - packetCollectorSize = parseIntProperty(parser, packetCollectorSize); - } - else if (parser.getName().equals("autoEnableEntityCaps")) { - autoEnableEntityCaps = Boolean.parseBoolean(parser.nextText()); - } - } - eventType = parser.next(); - } - while (eventType != XmlPullParser.END_DOCUMENT); - try { - cfgFileStream.close(); - } - catch (IOException e) { - log.log(Level.SEVERE, "Error while closing config file input stream", e); - } - } } diff --git a/core/src/main/java/org/jivesoftware/smack/util/FileUtils.java b/core/src/main/java/org/jivesoftware/smack/util/FileUtils.java index dae5609a3..59dfb214d 100644 --- a/core/src/main/java/org/jivesoftware/smack/util/FileUtils.java +++ b/core/src/main/java/org/jivesoftware/smack/util/FileUtils.java @@ -16,31 +16,31 @@ */ package org.jivesoftware.smack.util; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URI; import java.util.ArrayList; import java.util.List; +import java.util.Set; public final class FileUtils { - private FileUtils() { - } - public static InputStream getStreamForUrl(String url, ClassLoader loader) throws MalformedURLException, IOException { URI fileUri = URI.create(url); - + if (fileUri.getScheme() == null) { throw new MalformedURLException("No protocol found in file URL: " + url); } - + if (fileUri.getScheme().equals("classpath")) { // Get an array of class loaders to try loading the providers files from. ClassLoader[] classLoaders = getClassLoaders(); for (ClassLoader classLoader : classLoaders) { InputStream is = classLoader.getResourceAsStream(fileUri.getSchemeSpecificPart()); - + if (is != null) { return is; } @@ -51,7 +51,7 @@ public final class FileUtils { } return null; } - + /** * Returns default classloaders. * @@ -72,4 +72,14 @@ public final class FileUtils { return loaders.toArray(new ClassLoader[loaders.size()]); } + public static boolean addLines(String url, Set set) throws MalformedURLException, IOException { + InputStream is = getStreamForUrl(url, null); + if (is == null) return false; + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line; + while ((line = br.readLine()) != null) { + set.add(line); + } + return true; + } } diff --git a/core/src/main/resources/org.jivesoftware.smack/smack-config.xml b/core/src/main/resources/org.jivesoftware.smack/smack-config.xml index f998360f5..e6afbba9d 100644 --- a/core/src/main/resources/org.jivesoftware.smack/smack-config.xml +++ b/core/src/main/resources/org.jivesoftware.smack/smack-config.xml @@ -1,22 +1,6 @@ - - - 5000 - - - true - - - 7777 - - - 10000 - - - false - org.jivesoftware.smack.initializer.VmArgInitializer diff --git a/documentation/gettingstarted.html b/documentation/gettingstarted.html index 7c6d5725d..006e4b136 100644 --- a/documentation/gettingstarted.html +++ b/documentation/gettingstarted.html @@ -29,12 +29,25 @@ to be as small as possible. The library ships as several JAR files to provide mo over which features applications require:

    -
  • smack.jar -- provides core XMPP functionality and is the only required +
  • smack-core.jar -- provides core XMPP functionality and is the only required library. All XMPP features that are part of the XMPP RFCs are included.
  • -
  • smackx.jar -- support for many of the the extensions (XEPs) defined +
  • smack-extensions.jar -- support for many of the extensions (XEPs) defined by the XMPP Standards Foundation, including multi-user chat, file transfer, user search, etc. The extensions are documented in the extensions manual.
  • -
  • smackx-debug.jar -- an enhanced GUI debugger for protocol traffic. It will +
  • smack-experimental.jar -- support for experimental extensions (XEPs) defined + by the XMPP Standards Foundation. The API and functionality of those extensions should be + considered as unstable.
  • +
  • smack-legacy.jar -- support for legacy extensions (XEPs) defined + by the XMPP Standards Foundation.
  • +
  • smack-bosh.jar -- support for BOSH (XEP-0124). This code should be considered + as beta.
  • +
  • smack-jingle.jar -- support for Jingle. This code is old and currenlty + unmaintained.
  • +
  • smack-resolver-dnsjava.jar -- support for resolving DNS SRV records with the + help of dnsjava. Ideal for platforms that do not support the javax.naming API.
  • +
  • smack-resolver-javax.jar -- support for resolving DNS SRV records with the + javax namespace API.
  • +
  • smack-debug.jar -- an enhanced GUI debugger for protocol traffic. It will automatically be used when found in the classpath and when debugging is enabled.
@@ -51,25 +64,13 @@ If it does not extend this interface, then initialization will have to take plac which is automatically executed when the class is loaded.

-Initialization is accomplished via a configuration file. By default, Smack will load the one embedded in -the Smack jar at META-INF/smack-config.xml. This particular configuration contains all the default -property values as well as a list of initializer classes to load. All manager type classes are contained -in this list of initializers. If your application does not use all the features provided by Smack via the -aforementioned managers, you may want to 'turn them off' by providing a custom config file that does not -include that feature. -

-If you want to change the configuration file used, you have two options: -

    -
  • Programmatically - Call the setConfigFileUrl method of SmackConfiguration with the location -of a new config file. -
    SmackConfiguration.setConfigFileUrl("classpath:test/smack-config.xml", null)
    -
  • VM Argument - Set the VM argument smack.config.file to the location of a new config file. -
    -Dsmack.config.file=file:///c:/com/myco/provider/myco_custom_config.xml
    -
- -

-Please note, there is a copy of the smack-config.xml in the samples directory of the deployment -archive file (zip or tar). +Initialization is accomplished via a configuration file. By default, +Smack will load the one embedded in the Smack jar +at org.jivesoftware.smack/smack-config.xml. This particular +configuration contains a list of initializer classes to load. All +manager type classes that need to be initialized are contained in this +list of initializers. +

Establishing a Connection @@ -150,4 +151,4 @@ Copyright © Jive Software 2002-2008 - \ No newline at end of file + diff --git a/extensions/src/main/java/org/jivesoftware/smackx/ExtensionsStartupClasses.java b/extensions/src/main/java/org/jivesoftware/smackx/ExtensionsStartupClasses.java index dd36d539d..7ec5d2aa5 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/ExtensionsStartupClasses.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/ExtensionsStartupClasses.java @@ -24,8 +24,6 @@ import java.util.List; import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.initializer.SmackInitializer; import org.jivesoftware.smack.util.FileUtils; -import org.xmlpull.v1.XmlPullParserFactory; -import org.xmlpull.v1.XmlPullParser; public class ExtensionsStartupClasses implements SmackInitializer { @@ -37,36 +35,9 @@ public class ExtensionsStartupClasses implements SmackInitializer { @Override public void initialize() { InputStream is; - XmlPullParser parser; - int eventType; try { is = FileUtils.getStreamForUrl(EXTENSIONS_XML, null); - parser = XmlPullParserFactory.newInstance().newPullParser(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - parser.setInput(is, "UTF-8"); - eventType = parser.getEventType(); - } - catch (Exception e) { - exceptions.add(e); - return; - } - try { - do { - String name = parser.getName(); - if (eventType == XmlPullParser.START_TAG) { - if ("startupClasses".equals(name)) { - try { - SmackConfiguration.parseClassesToLoad(parser, false); - } - catch (Exception e) { - exceptions.add(e); - } - } - } - eventType = parser.next(); - } - while (eventType != XmlPullParser.END_DOCUMENT); - is.close(); + SmackConfiguration.processConfigFile(is, exceptions);; } catch (Exception e) { exceptions.add(e); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java index cbe4cc971..9a66e7571 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java @@ -77,6 +77,9 @@ public class Socks5Proxy { /* SOCKS5 proxy singleton */ private static Socks5Proxy socks5Server; + private static boolean localSocks5ProxyEnabled = true; + private static int localSocks5ProxyPort = 7777; + /* reusable implementation of a SOCKS5 proxy server process */ private Socks5ServerProcess serverProcess; @@ -110,6 +113,43 @@ public class Socks5Proxy { } + /** + * Returns true if the local Socks5 proxy should be started. Default is true. + * + * @return if the local Socks5 proxy should be started + */ + public static boolean isLocalSocks5ProxyEnabled() { + return localSocks5ProxyEnabled; + } + + /** + * Sets if the local Socks5 proxy should be started. Default is true. + * + * @param localSocks5ProxyEnabled if the local Socks5 proxy should be started + */ + public static void setLocalSocks5ProxyEnabled(boolean localSocks5ProxyEnabled) { + Socks5Proxy.localSocks5ProxyEnabled = localSocks5ProxyEnabled; + } + + /** + * Return the port of the local Socks5 proxy. Default is 7777. + * + * @return the port of the local Socks5 proxy + */ + public static int getLocalSocks5ProxyPort() { + return localSocks5ProxyPort; + } + + /** + * Sets the port of the local Socks5 proxy. Default is 7777. If you set the port to a negative + * value Smack tries the absolute value and all following until it finds an open port. + * + * @param localSocks5ProxyPort the port of the local Socks5 proxy to set + */ + public static void setLocalSocks5ProxyPort(int localSocks5ProxyPort) { + Socks5Proxy.localSocks5ProxyPort = localSocks5ProxyPort; + } + /** * Returns the local SOCKS5 proxy server. * @@ -119,7 +159,7 @@ public class Socks5Proxy { if (socks5Server == null) { socks5Server = new Socks5Proxy(); } - if (SmackConfiguration.isLocalSocks5ProxyEnabled()) { + if (isLocalSocks5ProxyEnabled()) { socks5Server.start(); } return socks5Server; @@ -133,8 +173,8 @@ public class Socks5Proxy { return; } try { - if (SmackConfiguration.getLocalSocks5ProxyPort() < 0) { - int port = Math.abs(SmackConfiguration.getLocalSocks5ProxyPort()); + if (getLocalSocks5ProxyPort() < 0) { + int port = Math.abs(getLocalSocks5ProxyPort()); for (int i = 0; i < 65535 - port; i++) { try { this.serverSocket = new ServerSocket(port + i); @@ -146,7 +186,7 @@ public class Socks5Proxy { } } else { - this.serverSocket = new ServerSocket(SmackConfiguration.getLocalSocks5ProxyPort()); + this.serverSocket = new ServerSocket(getLocalSocks5ProxyPort()); } if (this.serverSocket != null) { @@ -156,7 +196,7 @@ public class Socks5Proxy { } catch (IOException e) { // couldn't setup server - log.log(Level.SEVERE, "couldn't setup local SOCKS5 proxy on port " + SmackConfiguration.getLocalSocks5ProxyPort(), e); + log.log(Level.SEVERE, "couldn't setup local SOCKS5 proxy on port " + getLocalSocks5ProxyPort(), e); } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java index eeba8fe9a..7d632da60 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java @@ -21,7 +21,6 @@ import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.PacketInterceptor; import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; @@ -78,6 +77,8 @@ public class EntityCapsManager { protected static EntityCapsPersistentCache persistentCache; + private static boolean autoEnableEntityCaps = true; + private static Map instances = Collections .synchronizedMap(new WeakHashMap()); @@ -249,7 +250,7 @@ public class EntityCapsManager { // This calculates the local entity caps version updateLocalEntityCaps(); - if (SmackConfiguration.autoEnableEntityCaps()) + if (autoEnableEntityCaps) enableEntityCaps(); PacketFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class), new PacketExtensionFilter( diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java index d1bfb110b..31aeefc2c 100644 --- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java +++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java @@ -25,7 +25,6 @@ import java.io.OutputStream; import java.net.ConnectException; import org.jivesoftware.smack.Connection; -import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.XMPPError; @@ -169,7 +168,7 @@ public class Socks5ByteStreamManagerTest { public void shouldFailIfNoSocks5ProxyFound1() { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -220,7 +219,7 @@ public class Socks5ByteStreamManagerTest { public void shouldFailIfNoSocks5ProxyFound2() { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -284,7 +283,7 @@ public class Socks5ByteStreamManagerTest { public void shouldBlacklistNonSocks5Proxies() { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -375,7 +374,7 @@ public class Socks5ByteStreamManagerTest { public void shouldFailIfTargetDoesNotAcceptSocks5Bytestream() { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -465,7 +464,7 @@ public class Socks5ByteStreamManagerTest { public void shouldFailIfTargetUsesInvalidSocks5Proxy() { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -547,7 +546,7 @@ public class Socks5ByteStreamManagerTest { public void shouldFailIfInitiatorCannotConnectToSocks5Proxy() { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -641,7 +640,7 @@ public class Socks5ByteStreamManagerTest { public void shouldNegotiateSocks5BytestreamAndTransferData() throws Exception { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -754,8 +753,8 @@ public class Socks5ByteStreamManagerTest { public void shouldUseMultipleAddressesForLocalSocks5Proxy() throws Exception { // enable clients local SOCKS5 proxy on port 7778 - SmackConfiguration.setLocalSocks5ProxyEnabled(true); - SmackConfiguration.setLocalSocks5ProxyPort(7778); + Socks5Proxy.setLocalSocks5ProxyEnabled(true); + Socks5Proxy.setLocalSocks5ProxyPort(7778); // start a local SOCKS5 proxy Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy(); @@ -837,7 +836,7 @@ public class Socks5ByteStreamManagerTest { // reset proxy settings socks5Proxy.stop(); socks5Proxy.removeLocalAddress("localAddress"); - SmackConfiguration.setLocalSocks5ProxyPort(7777); + Socks5Proxy.setLocalSocks5ProxyPort(7777); } @@ -852,7 +851,7 @@ public class Socks5ByteStreamManagerTest { public void shouldPrioritizeSecondSocks5ProxyOnSecondAttempt() throws Exception { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -935,7 +934,7 @@ public class Socks5ByteStreamManagerTest { public void shouldNotPrioritizeSocks5ProxyIfPrioritizationDisabled() throws Exception { // disable clients local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); // get Socks5ByteStreamManager for connection Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); @@ -1093,7 +1092,7 @@ public class Socks5ByteStreamManagerTest { @After public void cleanUp() { Socks5TestProxy.stopProxy(); - SmackConfiguration.setLocalSocks5ProxyEnabled(true); + Socks5Proxy.setLocalSocks5ProxyEnabled(true); } } diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java index a87e06da7..eb5502b42 100644 --- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java +++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamRequestTest.java @@ -24,7 +24,6 @@ import java.net.ServerSocket; import java.net.Socket; import org.jivesoftware.smack.Connection; -import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; @@ -427,7 +426,7 @@ public class Socks5ByteStreamRequestTest { @After public void cleanUp() { Socks5TestProxy.stopProxy(); - SmackConfiguration.setLocalSocks5ProxyEnabled(true); + Socks5Proxy.setLocalSocks5ProxyEnabled(true); } } diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java index 1f1c1a8fc..8d7c7adb4 100644 --- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java +++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiatorTest.java @@ -23,7 +23,6 @@ import java.io.OutputStream; import java.net.Socket; import org.jivesoftware.smack.Connection; -import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.XMPPError; @@ -87,7 +86,7 @@ public class Socks5ClientForInitiatorTest { public void shouldFailIfTargetIsNotConnectedToLocalSocks5Proxy() throws Exception { // start a local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyPort(proxyPort); + Socks5Proxy.setLocalSocks5ProxyPort(proxyPort); Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy(); socks5Proxy.start(); @@ -125,7 +124,7 @@ public class Socks5ClientForInitiatorTest { public void shouldSuccessfullyConnectThroughLocalSocks5Proxy() throws Exception { // start a local SOCKS5 proxy - SmackConfiguration.setLocalSocks5ProxyPort(proxyPort); + Socks5Proxy.setLocalSocks5ProxyPort(proxyPort); Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy(); socks5Proxy.start(); @@ -308,7 +307,7 @@ public class Socks5ClientForInitiatorTest { */ @After public void cleanup() { - SmackConfiguration.setLocalSocks5ProxyPort(7777); + Socks5Proxy.setLocalSocks5ProxyPort(7777); } } diff --git a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java index 62e83bc7b..27b60df99 100644 --- a/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java +++ b/extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ProxyTest.java @@ -32,7 +32,6 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; -import org.jivesoftware.smack.SmackConfiguration; import org.junit.After; import org.junit.Test; @@ -48,7 +47,7 @@ public class Socks5ProxyTest { */ @Test public void shouldBeASingleton() { - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); Socks5Proxy proxy1 = Socks5Proxy.getSocks5Proxy(); Socks5Proxy proxy2 = Socks5Proxy.getSocks5Proxy(); @@ -63,7 +62,7 @@ public class Socks5ProxyTest { */ @Test public void shouldNotBeRunningIfDisabled() { - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy(); assertFalse(proxy.isRunning()); } @@ -75,12 +74,12 @@ public class Socks5ProxyTest { */ @Test public void shouldUseFreePortOnNegativeValues() throws Exception { - SmackConfiguration.setLocalSocks5ProxyEnabled(false); + Socks5Proxy.setLocalSocks5ProxyEnabled(false); Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy(); assertFalse(proxy.isRunning()); ServerSocket serverSocket = new ServerSocket(0); - SmackConfiguration.setLocalSocks5ProxyPort(-serverSocket.getLocalPort()); + Socks5Proxy.setLocalSocks5ProxyPort(-serverSocket.getLocalPort()); proxy.start(); @@ -155,7 +154,7 @@ public class Socks5ProxyTest { public void shouldOnlyStartOneServerThread() { int threadCount = Thread.activeCount(); - SmackConfiguration.setLocalSocks5ProxyPort(7890); + Socks5Proxy.setLocalSocks5ProxyPort(7890); Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy(); proxy.start(); @@ -189,7 +188,7 @@ public class Socks5ProxyTest { */ @Test public void shouldCloseSocketIfNoSocks5Request() throws Exception { - SmackConfiguration.setLocalSocks5ProxyPort(7890); + Socks5Proxy.setLocalSocks5ProxyPort(7890); Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy(); proxy.start(); @@ -219,7 +218,7 @@ public class Socks5ProxyTest { */ @Test public void shouldRespondWithErrorIfNoSupportedAuthenticationMethod() throws Exception { - SmackConfiguration.setLocalSocks5ProxyPort(7890); + Socks5Proxy.setLocalSocks5ProxyPort(7890); Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy(); proxy.start(); @@ -249,7 +248,7 @@ public class Socks5ProxyTest { */ @Test public void shouldRespondWithErrorIfConnectionIsNotAllowed() throws Exception { - SmackConfiguration.setLocalSocks5ProxyPort(7890); + Socks5Proxy.setLocalSocks5ProxyPort(7890); Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy(); proxy.start(); @@ -290,7 +289,7 @@ public class Socks5ProxyTest { */ @Test public void shouldSuccessfullyEstablishConnection() throws Exception { - SmackConfiguration.setLocalSocks5ProxyPort(7890); + Socks5Proxy.setLocalSocks5ProxyPort(7890); Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy(); proxy.start(); @@ -355,8 +354,8 @@ public class Socks5ProxyTest { */ @After public void cleanup() { - SmackConfiguration.setLocalSocks5ProxyEnabled(true); - SmackConfiguration.setLocalSocks5ProxyPort(7777); + Socks5Proxy.setLocalSocks5ProxyEnabled(true); + Socks5Proxy.setLocalSocks5ProxyPort(7777); Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy(); try { String address = InetAddress.getLocalHost().getHostAddress();