libs/new-android-r1.diff
author Da Risk <darisk972@gmail.com>
Fri, 22 May 2009 22:29:14 +0200
changeset 219 79ccbe331695
parent 19 213b84d2e743
permissions -rw-r--r--
Les conversations sont retenues dans les chats du service. On peut donc les réafficher dans l'activité SendIm. J'en ai profité pour rendre cette activité SingleTop ainsi une seule instance set utilisé. Il reste un probleme avec les notifications qui ne peuvent pas etre réutilisé. Si on a 2 notifications la 2e ne marchera pas.

Index: source/org/jivesoftware/smack/XMPPConnection.java
===================================================================
--- source/org/jivesoftware/smack/XMPPConnection.java	(révision 10982)
+++ source/org/jivesoftware/smack/XMPPConnection.java	(copie de travail)
@@ -1082,7 +1082,7 @@
                     catch (Exception ex) {
                         try {
                             debuggerClass =
-                                    Class.forName("org.jivesoftware.smack.debugger.LiteDebugger");
+                                    Class.forName("org.jivesoftware.smack.debugger.ConsoleDebugger");
                         }
                         catch (Exception ex2) {
                             ex2.printStackTrace();
Index: source/org/jivesoftware/smack/sasl/SASLMechanism.java
===================================================================
--- source/org/jivesoftware/smack/sasl/SASLMechanism.java	(révision 10982)
+++ source/org/jivesoftware/smack/sasl/SASLMechanism.java	(copie de travail)
@@ -20,24 +20,18 @@
 
 package org.jivesoftware.smack.sasl;
 
-import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smack.SASLAuthentication;
-import org.jivesoftware.smack.util.Base64;
-
 import java.io.IOException;
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
+
+import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.sasl.RealmCallback;
-import javax.security.sasl.RealmChoiceCallback;
-import javax.security.sasl.Sasl;
-import javax.security.sasl.SaslClient;
-import javax.security.sasl.SaslException;
 
+import org.jivesoftware.smack.SASLAuthentication;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.util.Base64;
+
 /**
  * Base class for SASL mechanisms. Subclasses must implement these methods:
  * <ul>
@@ -56,7 +50,7 @@
 public abstract class SASLMechanism implements CallbackHandler {
 
     private SASLAuthentication saslAuthentication;
-    protected SaslClient sc;
+    //protected SaslClient sc;
     protected String authenticationId;
     protected String password;
     protected String hostname;
@@ -88,7 +82,7 @@
 
         String[] mechanisms = { getName() };
         Map<String,String> props = new HashMap<String,String>();
-        sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
+        //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
         authenticate();
     }
 
@@ -105,7 +99,7 @@
     public void authenticate(String username, String host, CallbackHandler cbh) throws IOException, XMPPException {
         String[] mechanisms = { getName() };
         Map<String,String> props = new HashMap<String,String>();
-        sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
+        //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
         authenticate();
     }
 
@@ -113,17 +107,17 @@
         StringBuilder stanza = new StringBuilder();
         stanza.append("<auth mechanism=\"").append(getName());
         stanza.append("\" xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
-        try {
-            if(sc.hasInitialResponse()) {
-                byte[] response = sc.evaluateChallenge(new byte[0]);
-                String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
-                if(authenticationText != null && !authenticationText.equals("")) {                 
-                    stanza.append(authenticationText);
-                }
-            }
-        } catch (SaslException e) {
-            throw new XMPPException("SASL authentication failed", e);
-        }
+//        try {
+//            if(sc.hasInitialResponse()) {
+//                byte[] response = sc.evaluateChallenge(new byte[0]);
+//                String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
+//                if(authenticationText != null && !authenticationText.equals("")) {                 
+//                    stanza.append(authenticationText);
+//                }
+//            }
+//        } catch (SaslException e) {
+//            throw new XMPPException("SASL authentication failed", e);
+//        }
         stanza.append("</auth>");
 
         // Send the authentication to the server
@@ -142,12 +136,12 @@
         // Build the challenge response stanza encoding the response text
         StringBuilder stanza = new StringBuilder();
 
-        byte response[];
-        if(challenge != null) {
-            response = sc.evaluateChallenge(Base64.decode(challenge));
-        } else {
-            response = sc.evaluateChallenge(null);
-        }
+        byte response[] = null;
+//        if(challenge != null) {
+//            response = sc.evaluateChallenge(Base64.decode(challenge));
+//        } else {
+//            response = sc.evaluateChallenge(null);
+//        }
 
         String authenticationText = Base64.encodeBytes(response,Base64.DONT_BREAK_LINES);
         if(authenticationText.equals("")) {
@@ -179,21 +173,21 @@
      */
     public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
         for (int i = 0; i < callbacks.length; i++) {
-            if (callbacks[i] instanceof NameCallback) {
-                NameCallback ncb = (NameCallback)callbacks[i];
-                ncb.setName(authenticationId);
-            } else if(callbacks[i] instanceof PasswordCallback) {
-                PasswordCallback pcb = (PasswordCallback)callbacks[i];
-                pcb.setPassword(password.toCharArray());
-            } else if(callbacks[i] instanceof RealmCallback) {
-                RealmCallback rcb = (RealmCallback)callbacks[i];
-                rcb.setText(hostname);
-            } else if(callbacks[i] instanceof RealmChoiceCallback){
-                //unused
-                //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
-            } else {
+//            if (callbacks[i] instanceof NameCallback) {
+//                NameCallback ncb = (NameCallback)callbacks[i];
+//                ncb.setName(authenticationId);
+//            } else if(callbacks[i] instanceof PasswordCallback) {
+//                PasswordCallback pcb = (PasswordCallback)callbacks[i];
+//                pcb.setPassword(password.toCharArray());
+//            } else if(callbacks[i] instanceof RealmCallback) {
+//                RealmCallback rcb = (RealmCallback)callbacks[i];
+//                rcb.setText(hostname);
+//            } else if(callbacks[i] instanceof RealmChoiceCallback){
+//                //unused
+//                //RealmChoiceCallback rccb = (RealmChoiceCallback)callbacks[i];
+//            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
-            }
+            //}
          }
     }
 }
Index: source/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java
===================================================================
--- source/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java	(révision 10982)
+++ source/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java	(copie de travail)
@@ -25,8 +25,6 @@
 import java.io.IOException;
 import java.util.Map;
 import java.util.HashMap;
-import javax.security.sasl.Sasl;
-import javax.security.sasl.SaslClient;
 import javax.security.auth.callback.CallbackHandler;
 
 /**
@@ -62,8 +60,8 @@
     public void authenticate(String username, String host, CallbackHandler cbh) throws IOException, XMPPException {
         String[] mechanisms = { getName() };
         Map props = new HashMap();
-        props.put(Sasl.SERVER_AUTH,"TRUE");
-        sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
+        //props.put(Sasl.SERVER_AUTH,"TRUE");
+        //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, cbh);
         authenticate();
     }
 
@@ -81,8 +79,8 @@
     public void authenticate(String username, String host, String password) throws IOException, XMPPException {
         String[] mechanisms = { getName() };
         Map props = new HashMap();
-        props.put(Sasl.SERVER_AUTH,"TRUE");
-        sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
+        //props.put(Sasl.SERVER_AUTH,"TRUE");
+        //sc = Sasl.createSaslClient(mechanisms, username, "xmpp", host, props, this);
         authenticate();
     }
 
Index: source/org/jivesoftware/smack/ConnectionConfiguration.java
===================================================================
--- source/org/jivesoftware/smack/ConnectionConfiguration.java	(révision 10982)
+++ source/org/jivesoftware/smack/ConnectionConfiguration.java	(copie de travail)
@@ -57,13 +57,13 @@
 
     private boolean compressionEnabled = false;
 
-    private boolean saslAuthenticationEnabled = true;
+    private boolean saslAuthenticationEnabled = false;
     /**
      * Used to get information from the user
      */
     private CallbackHandler callbackHandler;
 
-    private boolean debuggerEnabled = XMPPConnection.DEBUG_ENABLED;
+    private boolean debuggerEnabled = true;//XMPPConnection.DEBUG_ENABLED;
 
     // Flag that indicates if a reconnection should be attempted when abruptly disconnected
     private boolean reconnectionAllowed = true;
@@ -517,7 +517,7 @@
      *        logging into the server.
      */
     public void setSASLAuthenticationEnabled(boolean saslAuthenticationEnabled) {
-        this.saslAuthenticationEnabled = saslAuthenticationEnabled;
+        //this.saslAuthenticationEnabled = saslAuthenticationEnabled;
     }
 
     /**
Index: source/org/jivesoftware/smack/util/DNSUtil.java
===================================================================
--- source/org/jivesoftware/smack/util/DNSUtil.java	(révision 10982)
+++ source/org/jivesoftware/smack/util/DNSUtil.java	(copie de travail)
@@ -24,9 +24,6 @@
 
 import javax.naming.NamingEnumeration;
 import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
 
 /**
  * Utilty class to perform DNS lookups for XMPP services.
@@ -41,13 +38,13 @@
      */
     private static Map cache = new Cache(100, 1000*60*10);
 
-    private static DirContext context;
+//    private static DirContext context;
 
     static {
         try {
             Hashtable env = new Hashtable();
             env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
-            context = new InitialDirContext(env);
+ //           context = new InitialDirContext(env);
         }
         catch (Exception e) {
             // Ignore.
@@ -79,64 +76,7 @@
      *      server can be reached at for the specified domain.
      */
     public static HostAddress resolveXMPPDomain(String domain) {
-        if (context == null) {
             return new HostAddress(domain, 5222);
-        }
-        String key = "c" + domain;
-        // Return item from cache if it exists.
-        if (cache.containsKey(key)) {
-            HostAddress address = (HostAddress)cache.get(key);
-            if (address != null) {
-                return address;
-            }
-        }
-        String bestHost = domain;
-        int bestPort = 5222;
-        int bestPriority = 0;
-        int bestWeight = 0;
-        try {
-            Attributes dnsLookup = context.getAttributes("_xmpp-client._tcp." + domain, new String[]{"SRV"});
-            Attribute srvAttribute = dnsLookup.get("SRV");
-            NamingEnumeration srvRecords = srvAttribute.getAll();
-            while(srvRecords.hasMore()) {
-				String srvRecord = (String) srvRecords.next();
-	            String [] srvRecordEntries = srvRecord.split(" ");
-	            int priority = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 4]);
-	            int port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]);
-	            int weight = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 3]);
-	            String host = srvRecordEntries[srvRecordEntries.length-1];
-	            
-	            // Randomize the weight.
-	            weight *= Math.random() * weight;
-	            
-	            if ((bestPriority == 0) || (priority < bestPriority)) {
-	            	// Choose a server with the lowest priority.
-	            	bestPriority = priority;
-	            	bestWeight = weight;
-	            	bestHost = host;
-	            	bestPort = port;
-	            } else if (priority == bestPriority) {
-	            	// When we have like priorities then randomly choose a server based on its weight
-	            	// The weights were randomized above.
-	            	if (weight > bestWeight) {
-	            		bestWeight = weight;
-	            		bestHost = host;
-	            		bestPort = port;
-	            	}
-	            }
-			}
-        }
-        catch (Exception e) {
-            // Ignore.
-        }
-        // Host entries in DNS should end with a ".".
-        if (bestHost.endsWith(".")) {
-        	bestHost = bestHost.substring(0, bestHost.length()-1);
-        }
-        HostAddress address = new HostAddress(bestHost, bestPort);
-        // Add item to cache.
-        cache.put(key, address);
-        return address;
     }
 
     /**
@@ -157,49 +97,7 @@
      *      server can be reached at for the specified domain.
      */
     public static HostAddress resolveXMPPServerDomain(String domain) {
-        if (context == null) {
             return new HostAddress(domain, 5269);
-        }
-        String key = "s" + domain;
-        // Return item from cache if it exists.
-        if (cache.containsKey(key)) {
-            HostAddress address = (HostAddress)cache.get(key);
-            if (address != null) {
-                return address;
-            }
-        }
-        String host = domain;
-        int port = 5269;
-        try {
-            Attributes dnsLookup =
-                    context.getAttributes("_xmpp-server._tcp." + domain, new String[]{"SRV"});
-            String srvRecord = (String)dnsLookup.get("SRV").get();
-            String [] srvRecordEntries = srvRecord.split(" ");
-            port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]);
-            host = srvRecordEntries[srvRecordEntries.length-1];
-        }
-        catch (Exception e) {
-            // Attempt lookup with older "jabber" name.
-            try {
-                Attributes dnsLookup =
-                        context.getAttributes("_jabber._tcp." + domain, new String[]{"SRV"});
-                String srvRecord = (String)dnsLookup.get("SRV").get();
-                String [] srvRecordEntries = srvRecord.split(" ");
-                port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length-2]);
-                host = srvRecordEntries[srvRecordEntries.length-1];
-            }
-            catch (Exception e2) {
-                // Ignore.
-            }
-        }
-        // Host entries in DNS should end with a ".".
-        if (host.endsWith(".")) {
-            host = host.substring(0, host.length()-1);
-        }
-        HostAddress address = new HostAddress(host, port);
-        // Add item to cache.
-        cache.put(key, address);
-        return address;
     }
 
     /**
@@ -253,4 +151,4 @@
             return port == address.port;
         }
     }
-}
\ No newline at end of file
+}
Index: source/org/jivesoftware/smack/util/PacketParserUtils.java
===================================================================
--- source/org/jivesoftware/smack/util/PacketParserUtils.java	(révision 10982)
+++ source/org/jivesoftware/smack/util/PacketParserUtils.java	(copie de travail)
@@ -25,7 +25,7 @@
 import org.jivesoftware.smack.provider.ProviderManager;
 import org.xmlpull.v1.XmlPullParser;
 
-import java.beans.PropertyDescriptor;
+//import java.beans.PropertyDescriptor;
 import java.io.ByteArrayInputStream;
 import java.io.ObjectInputStream;
 import java.util.ArrayList;
@@ -428,26 +428,26 @@
     {
         boolean done = false;
         Object object = objectClass.newInstance();
-        while (!done) {
-            int eventType = parser.next();
-            if (eventType == XmlPullParser.START_TAG) {
-                String name = parser.getName();
-                String stringValue = parser.nextText();
-                PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass);
-                // Load the class type of the property.
-                Class propertyType = descriptor.getPropertyType();
-                // Get the value of the property by converting it from a
-                // String to the correct object type.
-                Object value = decode(propertyType, stringValue);
-                // Set the value of the bean.
-                descriptor.getWriteMethod().invoke(object, value);
-            }
-            else if (eventType == XmlPullParser.END_TAG) {
-                if (parser.getName().equals(elementName)) {
-                    done = true;
-                }
-            }
-        }
+//        while (!done) {
+//            int eventType = parser.next();
+//            if (eventType == XmlPullParser.START_TAG) {
+//                String name = parser.getName();
+//                String stringValue = parser.nextText();
+//                PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass);
+//                // Load the class type of the property.
+//                Class propertyType = descriptor.getPropertyType();
+//                // Get the value of the property by converting it from a
+//                // String to the correct object type.
+//                Object value = decode(propertyType, stringValue);
+//                // Set the value of the bean.
+//                descriptor.getWriteMethod().invoke(object, value);
+//            }
+//            else if (eventType == XmlPullParser.END_TAG) {
+//                if (parser.getName().equals(elementName)) {
+//                    done = true;
+//                }
+//            }
+//        }
         return object;
     }