libs/smack-android-r1.diff
changeset 645 115665c0d25a
parent 644 77cb07054bb2
child 646 49e83a4b67b9
equal deleted inserted replaced
644:77cb07054bb2 645:115665c0d25a
     1 Index: org/jivesoftware/smack/XMPPConnection.java
       
     2 ===================================================================
       
     3 --- org/jivesoftware/smack/XMPPConnection.java	(revision 10869)
       
     4 +++ org/jivesoftware/smack/XMPPConnection.java	(working copy)
       
     5 @@ -1082,7 +1082,7 @@
       
     6                      catch (Exception ex) {
       
     7                          try {
       
     8                              debuggerClass =
       
     9 -                                    Class.forName("org.jivesoftware.smack.debugger.LiteDebugger");
       
    10 +                                    Class.forName("org.jivesoftware.smack.debugger.ConsoleDebugger");
       
    11                          }
       
    12                          catch (Exception ex2) {
       
    13                              ex2.printStackTrace();
       
    14 Index: org/jivesoftware/smack/sasl/SASLMechanism.java
       
    15 ===================================================================
       
    16 --- org/jivesoftware/smack/sasl/SASLMechanism.java	(revision 10869)
       
    17 +++ org/jivesoftware/smack/sasl/SASLMechanism.java	(working copy)
       
    18 @@ -20,24 +20,18 @@
       
    19  
       
    20  package org.jivesoftware.smack.sasl;
       
    21  
       
    22 -import org.jivesoftware.smack.XMPPException;
       
    23 -import org.jivesoftware.smack.SASLAuthentication;
       
    24 -import org.jivesoftware.smack.util.Base64;
       
    25 -
       
    26  import java.io.IOException;
       
    27 -import java.util.Map;
       
    28  import java.util.HashMap;
       
    29 +import java.util.Map;
       
    30 +
       
    31 +import javax.security.auth.callback.Callback;
       
    32  import javax.security.auth.callback.CallbackHandler;
       
    33  import javax.security.auth.callback.UnsupportedCallbackException;
       
    34 -import javax.security.auth.callback.Callback;
       
    35 -import javax.security.auth.callback.NameCallback;
       
    36 -import javax.security.auth.callback.PasswordCallback;
       
    37 -import javax.security.sasl.RealmCallback;
       
    38 -import javax.security.sasl.RealmChoiceCallback;
       
    39 -import javax.security.sasl.Sasl;
       
    40 -import javax.security.sasl.SaslClient;
       
    41 -import javax.security.sasl.SaslException;
       
    42  
       
    43 +import org.jivesoftware.smack.SASLAuthentication;
       
    44 +import org.jivesoftware.smack.XMPPException;
       
    45 +import org.jivesoftware.smack.util.Base64;
       
    46 +
       
    47  /**
       
    48   * Base class for SASL mechanisms. Subclasses must implement these methods:
       
    49   * <ul>
       
    50 @@ -56,7 +50,7 @@
       
    51  public abstract class SASLMechanism implements CallbackHandler {
       
    52  
       
    53      private SASLAuthentication saslAuthentication;
       
    54 -    protected SaslClient sc;
       
    55 +    //protected SaslClient sc;
       
    56      protected String authenticationId;
       
    57      protected String password;
       
    58      protected String hostname;
       
    59 @@ -88,7 +82,7 @@
       
    60  
       
    61          String[] mechanisms = { getName() };
       
    62          Map<String,String> props = new HashMap<String,String>();
       
    63 -        sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
       
    64 +        //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
       
    65          authenticate();
       
    66      }
       
    67  
       
    68 @@ -105,7 +99,7 @@
       
    69      public void authenticate(String username, String host, CallbackHandler cbh) throws IOException, XMPPException {
       
    70          String[] mechanisms = { getName() };
       
    71          Map<String,String> props = new HashMap<String,String>();
       
    72 -        sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
       
    73 +        //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
       
    74          authenticate();
       
    75      }
       
    76  
       
    77 @@ -113,17 +107,17 @@
       
    78          StringBuilder stanza = new StringBuilder();
       
    79          stanza.append("<auth mechanism=\"").append(getName());
       
    80          stanza.append("\" xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
       
    81 -        try {
       
    82 -            if(sc.hasInitialResponse()) {
       
    83 -                byte[] response = sc.evaluateChallenge(new byte[0]);
       
    84 -                String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
       
    85 -                if(authenticationText != null && !authenticationText.equals("")) {                 
       
    86 -                    stanza.append(authenticationText);
       
    87 -                }
       
    88 -            }
       
    89 -        } catch (SaslException e) {
       
    90 -            throw new XMPPException("SASL authentication failed", e);
       
    91 -        }
       
    92 +//        try {
       
    93 +//            if(sc.hasInitialResponse()) {
       
    94 +//                byte[] response = sc.evaluateChallenge(new byte[0]);
       
    95 +//                String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
       
    96 +//                if(authenticationText != null && !authenticationText.equals("")) {                 
       
    97 +//                    stanza.append(authenticationText);
       
    98 +//                }
       
    99 +//            }
       
   100 +//        } catch (SaslException e) {
       
   101 +//            throw new XMPPException("SASL authentication failed", e);
       
   102 +//        }
       
   103          stanza.append("</auth>");
       
   104  
       
   105          // Send the authentication to the server
       
   106 @@ -142,12 +136,12 @@
       
   107          // Build the challenge response stanza encoding the response text
       
   108          StringBuilder stanza = new StringBuilder();
       
   109  
       
   110 -        byte response[];
       
   111 -        if(challenge != null) {
       
   112 -            response = sc.evaluateChallenge(Base64.decode(challenge));
       
   113 -        } else {
       
   114 -            response = sc.evaluateChallenge(null);
       
   115 -        }
       
   116 +        byte response[] = null;
       
   117 +//        if(challenge != null) {
       
   118 +//            response = sc.evaluateChallenge(Base64.decode(challenge));
       
   119 +//        } else {
       
   120 +//            response = sc.evaluateChallenge(null);
       
   121 +//        }
       
   122  
       
   123          String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
       
   124          if(authenticationText.equals("")) {
       
   125 @@ -179,21 +173,21 @@
       
   126       */
       
   127      public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
       
   128          for (int i = 0; i < callbacks.length; i++) {
       
   129 -            if (callbacks[i] instanceof NameCallback) {
       
   130 -                NameCallback ncb = (NameCallback)callbacks[i];
       
   131 -                ncb.setName(authenticationId);
       
   132 -            } else if(callbacks[i] instanceof PasswordCallback) {
       
   133 -                PasswordCallback pcb = (PasswordCallback)callbacks[i];
       
   134 -                pcb.setPassword(password.toCharArray());
       
   135 -            } else if(callbacks[i] instanceof RealmCallback) {
       
   136 -                RealmCallback rcb = (RealmCallback)callbacks[i];
       
   137 -                rcb.setText(hostname);
       
   138 -            } else if(callbacks[i] instanceof RealmChoiceCallback){
       
   139 -                //unused
       
   140 -                //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
       
   141 -            } else {
       
   142 +//            if (callbacks[i] instanceof NameCallback) {
       
   143 +//                NameCallback ncb = (NameCallback)callbacks[i];
       
   144 +//                ncb.setName(authenticationId);
       
   145 +//            } else if(callbacks[i] instanceof PasswordCallback) {
       
   146 +//                PasswordCallback pcb = (PasswordCallback)callbacks[i];
       
   147 +//                pcb.setPassword(password.toCharArray());
       
   148 +//            } else if(callbacks[i] instanceof RealmCallback) {
       
   149 +//                RealmCallback rcb = (RealmCallback)callbacks[i];
       
   150 +//                rcb.setText(hostname);
       
   151 +//            } else if(callbacks[i] instanceof RealmChoiceCallback){
       
   152 +//                //unused
       
   153 +//                //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
       
   154 +//            } else {
       
   155                 throw new UnsupportedCallbackException(callbacks[i]);
       
   156 -            }
       
   157 +            //}
       
   158           }
       
   159      }
       
   160  }
       
   161 Index: org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java
       
   162 ===================================================================
       
   163 --- org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java	(revision 10869)
       
   164 +++ org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java	(working copy)
       
   165 @@ -25,8 +25,6 @@
       
   166  import java.io.IOException;
       
   167  import java.util.Map;
       
   168  import java.util.HashMap;
       
   169 -import javax.security.sasl.Sasl;
       
   170 -import javax.security.sasl.SaslClient;
       
   171  import javax.security.auth.callback.CallbackHandler;
       
   172  
       
   173  /**
       
   174 @@ -62,8 +60,8 @@
       
   175      public void authenticate(String username, String host, CallbackHandler cbh) throws IOException, XMPPException {
       
   176          String[] mechanisms = { getName() };
       
   177          Map props = new HashMap();
       
   178 -        props.put(Sasl.SERVER_AUTH,"TRUE");
       
   179 -        sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
       
   180 +        //props.put(Sasl.SERVER_AUTH,"TRUE");
       
   181 +        //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
       
   182          authenticate();
       
   183      }
       
   184  
       
   185 @@ -81,8 +79,8 @@
       
   186      public void authenticate(String username, String host, String password) throws IOException, XMPPException {
       
   187          String[] mechanisms = { getName() };
       
   188          Map props = new HashMap();
       
   189 -        props.put(Sasl.SERVER_AUTH,"TRUE");
       
   190 -        sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
       
   191 +        //props.put(Sasl.SERVER_AUTH,"TRUE");
       
   192 +        //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
       
   193          authenticate();
       
   194      }
       
   195  
       
   196 Index: org/jivesoftware/smack/ConnectionConfiguration.java
       
   197 ===================================================================
       
   198 --- org/jivesoftware/smack/ConnectionConfiguration.java	(revision 10869)
       
   199 +++ org/jivesoftware/smack/ConnectionConfiguration.java	(working copy)
       
   200 @@ -57,13 +57,13 @@
       
   201  
       
   202      private boolean compressionEnabled = false;
       
   203  
       
   204 -    private boolean saslAuthenticationEnabled = true;
       
   205 +    private boolean saslAuthenticationEnabled = false;
       
   206      /**
       
   207       * Used to get information from the user
       
   208       */
       
   209      private CallbackHandler callbackHandler;
       
   210  
       
   211 -    private boolean debuggerEnabled = XMPPConnection.DEBUG_ENABLED;
       
   212 +    private boolean debuggerEnabled = true;//XMPPConnection.DEBUG_ENABLED;
       
   213  
       
   214      // Flag that indicates if a reconnection should be attempted when abruptly disconnected
       
   215      private boolean reconnectionAllowed = true;
       
   216 @@ -517,7 +517,7 @@
       
   217       *        logging into the server.
       
   218       */
       
   219      public void setSASLAuthenticationEnabled(boolean saslAuthenticationEnabled) {
       
   220 -        this.saslAuthenticationEnabled = saslAuthenticationEnabled;
       
   221 +        //this.saslAuthenticationEnabled = saslAuthenticationEnabled;
       
   222      }
       
   223  
       
   224      /**
       
   225 Index: org/jivesoftware/smack/util/DNSUtil.java
       
   226 ===================================================================
       
   227 --- org/jivesoftware/smack/util/DNSUtil.java	(revision 10869)
       
   228 +++ org/jivesoftware/smack/util/DNSUtil.java	(working copy)
       
   229 @@ -19,9 +19,6 @@
       
   230  
       
   231  package org.jivesoftware.smack.util;
       
   232  
       
   233 -import javax.naming.directory.Attributes;
       
   234 -import javax.naming.directory.DirContext;
       
   235 -import javax.naming.directory.InitialDirContext;
       
   236  import java.util.Hashtable;
       
   237  import java.util.Map;
       
   238  
       
   239 @@ -38,13 +35,13 @@
       
   240       */
       
   241      private static Map cache = new Cache(100, 1000*60*10);
       
   242  
       
   243 -    private static DirContext context;
       
   244 +    //private static DirContext context;
       
   245  
       
   246      static {
       
   247          try {
       
   248              Hashtable env = new Hashtable();
       
   249              env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
       
   250 -            context = new InitialDirContext(env);
       
   251 +//            context = new InitialDirContext(env);
       
   252          }
       
   253          catch (Exception e) {
       
   254              // Ignore.
       
   255 @@ -69,39 +66,8 @@
       
   256       *      server can be reached at for the specified domain.
       
   257       */
       
   258      public static HostAddress resolveXMPPDomain(String domain) {
       
   259 -        if (context == null) {
       
   260              return new HostAddress(domain, 5222);
       
   261 -        }
       
   262 -        String key = "c" + domain;
       
   263 -        // Return item from cache if it exists.
       
   264 -        if (cache.containsKey(key)) {
       
   265 -            HostAddress address = (HostAddress)cache.get(key);
       
   266 -            if (address != null) {
       
   267 -                return address;
       
   268 -            }
       
   269 -        }
       
   270 -        String host = domain;
       
   271 -        int port = 5222;
       
   272 -        try {
       
   273 -            Attributes dnsLookup =
       
   274 -                    context.getAttributes("_xmpp-client._tcp." + domain, new String[]{"SRV"});
       
   275 -            String srvRecord = (String)dnsLookup.get("SRV").get();
       
   276 -            String [] srvRecordEntries = srvRecord.split(" ");
       
   277 -            port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]);
       
   278 -            host = srvRecordEntries[srvRecordEntries.length-1];
       
   279 -        }
       
   280 -        catch (Exception e) {
       
   281 -            // Ignore.
       
   282 -        }
       
   283 -        // Host entries in DNS should end with a ".".
       
   284 -        if (host.endsWith(".")) {
       
   285 -            host = host.substring(0, host.length()-1);
       
   286 -        }
       
   287 -        HostAddress address = new HostAddress(host, port);
       
   288 -        // Add item to cache.
       
   289 -        cache.put(key, address);
       
   290 -        return address;
       
   291 -    }
       
   292 +      }
       
   293  
       
   294      /**
       
   295       * Returns the host name and port that the specified XMPP server can be
       
   296 @@ -121,50 +87,8 @@
       
   297       *      server can be reached at for the specified domain.
       
   298       */
       
   299      public static HostAddress resolveXMPPServerDomain(String domain) {
       
   300 -        if (context == null) {
       
   301              return new HostAddress(domain, 5269);
       
   302 -        }
       
   303 -        String key = "s" + domain;
       
   304 -        // Return item from cache if it exists.
       
   305 -        if (cache.containsKey(key)) {
       
   306 -            HostAddress address = (HostAddress)cache.get(key);
       
   307 -            if (address != null) {
       
   308 -                return address;
       
   309 -            }
       
   310 -        }
       
   311 -        String host = domain;
       
   312 -        int port = 5269;
       
   313 -        try {
       
   314 -            Attributes dnsLookup =
       
   315 -                    context.getAttributes("_xmpp-server._tcp." + domain, new String[]{"SRV"});
       
   316 -            String srvRecord = (String)dnsLookup.get("SRV").get();
       
   317 -            String [] srvRecordEntries = srvRecord.split(" ");
       
   318 -            port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]);
       
   319 -            host = srvRecordEntries[srvRecordEntries.length-1];
       
   320 -        }
       
   321 -        catch (Exception e) {
       
   322 -            // Attempt lookup with older "jabber" name.
       
   323 -            try {
       
   324 -                Attributes dnsLookup =
       
   325 -                        context.getAttributes("_jabber._tcp." + domain, new String[]{"SRV"});
       
   326 -                String srvRecord = (String)dnsLookup.get("SRV").get();
       
   327 -                String [] srvRecordEntries = srvRecord.split(" ");
       
   328 -                port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]);
       
   329 -                host = srvRecordEntries[srvRecordEntries.length-1];
       
   330 -            }
       
   331 -            catch (Exception e2) {
       
   332 -                // Ignore.
       
   333 -            }
       
   334 -        }
       
   335 -        // Host entries in DNS should end with a ".".
       
   336 -        if (host.endsWith(".")) {
       
   337 -            host = host.substring(0, host.length()-1);
       
   338 -        }
       
   339 -        HostAddress address = new HostAddress(host, port);
       
   340 -        // Add item to cache.
       
   341 -        cache.put(key, address);
       
   342 -        return address;
       
   343 -    }
       
   344 +      }
       
   345  
       
   346      /**
       
   347       * Encapsulates a hostname and port.
       
   348 Index: org/jivesoftware/smack/util/PacketParserUtils.java
       
   349 ===================================================================
       
   350 --- org/jivesoftware/smack/util/PacketParserUtils.java	(revision 10869)
       
   351 +++ org/jivesoftware/smack/util/PacketParserUtils.java	(working copy)
       
   352 @@ -25,7 +25,7 @@
       
   353  import org.jivesoftware.smack.provider.ProviderManager;
       
   354  import org.xmlpull.v1.XmlPullParser;
       
   355  
       
   356 -import java.beans.PropertyDescriptor;
       
   357 +//import java.beans.PropertyDescriptor;
       
   358  import java.io.ByteArrayInputStream;
       
   359  import java.io.ObjectInputStream;
       
   360  import java.util.ArrayList;
       
   361 @@ -428,26 +428,26 @@
       
   362      {
       
   363          boolean done = false;
       
   364          Object object = objectClass.newInstance();
       
   365 -        while (!done) {
       
   366 -            int eventType = parser.next();
       
   367 -            if (eventType == XmlPullParser.START_TAG) {
       
   368 -                String name = parser.getName();
       
   369 -                String stringValue = parser.nextText();
       
   370 -                PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass);
       
   371 -                // Load the class type of the property.
       
   372 -                Class propertyType = descriptor.getPropertyType();
       
   373 -                // Get the value of the property by converting it from a
       
   374 -                // String to the correct object type.
       
   375 -                Object value = decode(propertyType, stringValue);
       
   376 -                // Set the value of the bean.
       
   377 -                descriptor.getWriteMethod().invoke(object, value);
       
   378 -            }
       
   379 -            else if (eventType == XmlPullParser.END_TAG) {
       
   380 -                if (parser.getName().equals(elementName)) {
       
   381 -                    done = true;
       
   382 -                }
       
   383 -            }
       
   384 -        }
       
   385 +//        while (!done) {
       
   386 +//            int eventType = parser.next();
       
   387 +//            if (eventType == XmlPullParser.START_TAG) {
       
   388 +//                String name = parser.getName();
       
   389 +//                String stringValue = parser.nextText();
       
   390 +//                PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass);
       
   391 +//                // Load the class type of the property.
       
   392 +//                Class propertyType = descriptor.getPropertyType();
       
   393 +//                // Get the value of the property by converting it from a
       
   394 +//                // String to the correct object type.
       
   395 +//                Object value = decode(propertyType, stringValue);
       
   396 +//                // Set the value of the bean.
       
   397 +//                descriptor.getWriteMethod().invoke(object, value);
       
   398 +//            }
       
   399 +//            else if (eventType == XmlPullParser.END_TAG) {
       
   400 +//                if (parser.getName().equals(elementName)) {
       
   401 +//                    done = true;
       
   402 +//                }
       
   403 +//            }
       
   404 +//        }
       
   405          return object;
       
   406      }
       
   407