package org.jivesoftware.smack;

import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.net.ssl.HostnameVerifier;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.ReflectionDebuggerFactory;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;

public final class SmackConfiguration {
   private static int defaultPacketReplyTimeout = 5000;
   private static int packetCollectorSize = 5000;
   private static List<String> defaultMechs = new ArrayList();
   static Set<String> disabledSmackClasses = new HashSet();
   static final List<XMPPInputOutputStream> compressionHandlers = new ArrayList(2);
   static boolean smackInitialized = false;
   private static SmackDebuggerFactory debuggerFactory = new ReflectionDebuggerFactory();
   public static boolean DEBUG = false;
   private static ParsingExceptionCallback defaultCallback = new ExceptionThrowingCallback();
   private static HostnameVerifier defaultHostnameVerififer;

   public static String getVersion() {
      return SmackInitialization.SMACK_VERSION;
   }

   public static int getDefaultPacketReplyTimeout() {
      if (defaultPacketReplyTimeout <= 0) {
         defaultPacketReplyTimeout = 5000;
      }

      return defaultPacketReplyTimeout;
   }

   public static void setDefaultPacketReplyTimeout(int timeout) {
      if (timeout <= 0) {
         throw new IllegalArgumentException();
      } else {
         defaultPacketReplyTimeout = timeout;
      }
   }

   public static int getPacketCollectorSize() {
      return packetCollectorSize;
   }

   public static void setPacketCollectorSize(int collectorSize) {
      packetCollectorSize = collectorSize;
   }

   public static void addSaslMech(String mech) {
      if (!defaultMechs.contains(mech)) {
         defaultMechs.add(mech);
      }

   }

   public static void addSaslMechs(Collection<String> mechs) {
      Iterator i$ = mechs.iterator();

      while(i$.hasNext()) {
         String mech = (String)i$.next();
         addSaslMech(mech);
      }

   }

   public static void setDebuggerFactory(SmackDebuggerFactory debuggerFactory) {
      SmackConfiguration.debuggerFactory = debuggerFactory;
   }

   public static SmackDebuggerFactory getDebuggerFactory() {
      return debuggerFactory;
   }

   public static SmackDebugger createDebugger(XMPPConnection connection, Writer writer, Reader reader) {
      SmackDebuggerFactory factory = getDebuggerFactory();
      return factory == null ? null : factory.create(connection, writer, reader);
   }

   public static void removeSaslMech(String mech) {
      defaultMechs.remove(mech);
   }

   public static void removeSaslMechs(Collection<String> mechs) {
      defaultMechs.removeAll(mechs);
   }

   public static List<String> getSaslMechs() {
      return Collections.unmodifiableList(defaultMechs);
   }

   public static void setDefaultParsingExceptionCallback(ParsingExceptionCallback callback) {
      defaultCallback = callback;
   }

   public static ParsingExceptionCallback getDefaultParsingExceptionCallback() {
      return defaultCallback;
   }

   public static void addCompressionHandler(XMPPInputOutputStream xmppInputOutputStream) {
      compressionHandlers.add(xmppInputOutputStream);
   }

   public static List<XMPPInputOutputStream> getCompresionHandlers() {
      List<XMPPInputOutputStream> res = new ArrayList(compressionHandlers.size());
      Iterator i$ = compressionHandlers.iterator();

      while(i$.hasNext()) {
         XMPPInputOutputStream ios = (XMPPInputOutputStream)i$.next();
         if (ios.isSupported()) {
            res.add(ios);
         }
      }

      return res;
   }

   public static void setDefaultHostnameVerifier(HostnameVerifier verifier) {
      defaultHostnameVerififer = verifier;
   }

   public static void addDisabledSmackClass(Class<?> clz) {
      addDisabledSmackClass(clz.getName());
   }

   public static void addDisabledSmackClass(String className) {
      disabledSmackClasses.add(className);
   }

   public static boolean isDisabledSmackClass(String className) {
      Iterator i$ = disabledSmackClasses.iterator();

      String disabledClassOrPackage;
      int lastDotIndex;
      do {
         if (!i$.hasNext()) {
            return false;
         }

         disabledClassOrPackage = (String)i$.next();
         if (disabledClassOrPackage.equals(className)) {
            return true;
         }

         lastDotIndex = disabledClassOrPackage.lastIndexOf(46);
      } while(disabledClassOrPackage.length() <= lastDotIndex || Character.isUpperCase(disabledClassOrPackage.charAt(lastDotIndex + 1)) || !className.startsWith(disabledClassOrPackage));

      return true;
   }

   public static boolean isSmackInitialized() {
      return smackInitialized;
   }

   static HostnameVerifier getDefaultHostnameVerifier() {
      return defaultHostnameVerififer;
   }
}
