diff options
Diffstat (limited to 'asmack-master/static-src/custom')
10 files changed, 1145 insertions, 0 deletions
diff --git a/asmack-master/static-src/custom/META-INF/services/com.kenai.jbosh.HTTPSender b/asmack-master/static-src/custom/META-INF/services/com.kenai.jbosh.HTTPSender new file mode 100644 index 0000000..3608d8e --- /dev/null +++ b/asmack-master/static-src/custom/META-INF/services/com.kenai.jbosh.HTTPSender @@ -0,0 +1 @@ +com.kenai.jbosh.ApacheHTTPSender diff --git a/asmack-master/static-src/custom/com/kenai/jbosh/QName.java b/asmack-master/static-src/custom/com/kenai/jbosh/QName.java new file mode 100644 index 0000000..d395a06 --- /dev/null +++ b/asmack-master/static-src/custom/com/kenai/jbosh/QName.java @@ -0,0 +1,269 @@ +/* + * The Apache Software License, Version 1.1 + * + * + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Axis" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ +package com.kenai.jbosh; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; + +/** + * <code>QName</code> class represents the value of a qualified name + * as specified in <a href="http://www.w3.org/TR/xmlschema-2/#QName">XML + * Schema Part2: Datatypes specification</a>. + * <p> + * The value of a QName contains a <b>namespaceURI</b>, a <b>localPart</b> and a <b>prefix</b>. + * The localPart provides the local part of the qualified name. The + * namespaceURI is a URI reference identifying the namespace. + * + * @version 1.1 + */ +public class QName implements Serializable { + + /** comment/shared empty string */ + private static final String emptyString = "".intern(); + + /** Field namespaceURI */ + private String namespaceURI; + + /** Field localPart */ + private String localPart; + + /** Field prefix */ + private String prefix; + + /** + * Constructor for the QName. + * + * @param localPart Local part of the QName + */ + public QName(String localPart) { + this(emptyString, localPart, emptyString); + } + + /** + * Constructor for the QName. + * + * @param namespaceURI Namespace URI for the QName + * @param localPart Local part of the QName. + */ + public QName(String namespaceURI, String localPart) { + this(namespaceURI, localPart, emptyString); + } + + /** + * Constructor for the QName. + * + * @param namespaceURI Namespace URI for the QName + * @param localPart Local part of the QName. + * @param prefix Prefix of the QName. + */ + public QName(String namespaceURI, String localPart, String prefix) { + this.namespaceURI = (namespaceURI == null) + ? emptyString + : namespaceURI.intern(); + if (localPart == null) { + throw new IllegalArgumentException("invalid QName local part"); + } else { + this.localPart = localPart.intern(); + } + + if (prefix == null) { + throw new IllegalArgumentException("invalid QName prefix"); + } else { + this.prefix = prefix.intern(); + } + } + + /** + * Gets the Namespace URI for this QName + * + * @return Namespace URI + */ + public String getNamespaceURI() { + return namespaceURI; + } + + /** + * Gets the Local part for this QName + * + * @return Local part + */ + public String getLocalPart() { + return localPart; + } + + /** + * Gets the Prefix for this QName + * + * @return Prefix + */ + public String getPrefix() { + return prefix; + } + + /** + * Returns a string representation of this QName + * + * @return a string representation of the QName + */ + public String toString() { + + return ((namespaceURI == emptyString) + ? localPart + : '{' + namespaceURI + '}' + localPart); + } + + /** + * Tests this QName for equality with another object. + * <p> + * If the given object is not a QName or is null then this method + * returns <tt>false</tt>. + * <p> + * For two QNames to be considered equal requires that both + * localPart and namespaceURI must be equal. This method uses + * <code>String.equals</code> to check equality of localPart + * and namespaceURI. Any class that extends QName is required + * to satisfy this equality contract. + * <p> + * This method satisfies the general contract of the <code>Object.equals</code> method. + * + * @param obj the reference object with which to compare + * + * @return <code>true</code> if the given object is identical to this + * QName: <code>false</code> otherwise. + */ + public final boolean equals(Object obj) { + + if (obj == this) { + return true; + } + + if (!(obj instanceof QName)) { + return false; + } + + if ((namespaceURI == ((QName) obj).namespaceURI) + && (localPart == ((QName) obj).localPart)) { + return true; + } + + return false; + } + + /** + * Returns a QName holding the value of the specified String. + * <p> + * The string must be in the form returned by the QName.toString() + * method, i.e. "{namespaceURI}localPart", with the "{namespaceURI}" + * part being optional. + * <p> + * This method doesn't do a full validation of the resulting QName. + * In particular, it doesn't check that the resulting namespace URI + * is a legal URI (per RFC 2396 and RFC 2732), nor that the resulting + * local part is a legal NCName per the XML Namespaces specification. + * + * @param s the string to be parsed + * @throws java.lang.IllegalArgumentException If the specified String cannot be parsed as a QName + * @return QName corresponding to the given String + */ + public static QName valueOf(String s) { + + if ((s == null) || s.equals("")) { + throw new IllegalArgumentException("invalid QName literal"); + } + + if (s.charAt(0) == '{') { + int i = s.indexOf('}'); + + if (i == -1) { + throw new IllegalArgumentException("invalid QName literal"); + } + + if (i == s.length() - 1) { + throw new IllegalArgumentException("invalid QName literal"); + } else { + return new QName(s.substring(1, i), s.substring(i + 1)); + } + } else { + return new QName(s); + } + } + + /** + * Returns a hash code value for this QName object. The hash code + * is based on both the localPart and namespaceURI parts of the + * QName. This method satisfies the general contract of the + * <code>Object.hashCode</code> method. + * + * @return a hash code value for this Qname object + */ + public final int hashCode() { + return namespaceURI.hashCode() ^ localPart.hashCode(); + } + + /** + * Ensure that deserialization properly interns the results. + * @param in the ObjectInputStream to be read + */ + private void readObject(ObjectInputStream in) throws + IOException, ClassNotFoundException { + in.defaultReadObject(); + + namespaceURI = namespaceURI.intern(); + localPart = localPart.intern(); + prefix = prefix.intern(); + } +} + diff --git a/asmack-master/static-src/custom/de/measite/smack/AndroidDebugger.java b/asmack-master/static-src/custom/de/measite/smack/AndroidDebugger.java new file mode 100644 index 0000000..4dfc622 --- /dev/null +++ b/asmack-master/static-src/custom/de/measite/smack/AndroidDebugger.java @@ -0,0 +1,185 @@ +package de.measite.smack; + +import org.jivesoftware.smack.debugger.SmackDebugger; +import org.jivesoftware.smack.ConnectionListener; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.packet.Packet; +import org.jivesoftware.smack.util.*; + +import android.util.Log; + +import java.io.Reader; +import java.io.Writer; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Very simple debugger that prints to the android log the sent and received stanzas. Use + * this debugger with caution since printing to the console is an expensive operation that may + * even block the thread since only one thread may print at a time.<p> + * <p/> + * It is possible to not only print the raw sent and received stanzas but also the interpreted + * packets by Smack. By default interpreted packets won't be printed. To enable this feature + * just change the <tt>printInterpreted</tt> static variable to <tt>true</tt>. + * + * @author Gaston Dombiak + */ +public class AndroidDebugger implements SmackDebugger { + + public static boolean printInterpreted = false; + private SimpleDateFormat dateFormatter = new SimpleDateFormat("hh:mm:ss aaa"); + + private Connection connection = null; + + private PacketListener listener = null; + private ConnectionListener connListener = null; + + private Writer writer; + private Reader reader; + private ReaderListener readerListener; + private WriterListener writerListener; + + public AndroidDebugger(Connection connection, Writer writer, Reader reader) { + this.connection = connection; + this.writer = writer; + this.reader = reader; + createDebug(); + } + + /** + * Creates the listeners that will print in the console when new activity is detected. + */ + private void createDebug() { + // Create a special Reader that wraps the main Reader and logs data to the GUI. + ObservableReader debugReader = new ObservableReader(reader); + readerListener = new ReaderListener() { + public void read(String str) { + Log.d("SMACK", + dateFormatter.format(new Date()) + " RCV (" + connection.hashCode() + + "): " + + str); + } + }; + debugReader.addReaderListener(readerListener); + + // Create a special Writer that wraps the main Writer and logs data to the GUI. + ObservableWriter debugWriter = new ObservableWriter(writer); + writerListener = new WriterListener() { + public void write(String str) { + Log.d("SMACK", + dateFormatter.format(new Date()) + " SENT (" + connection.hashCode() + + "): " + + str); + } + }; + debugWriter.addWriterListener(writerListener); + + // Assign the reader/writer objects to use the debug versions. The packet reader + // and writer will use the debug versions when they are created. + reader = debugReader; + writer = debugWriter; + + // Create a thread that will listen for all incoming packets and write them to + // the GUI. This is what we call "interpreted" packet data, since it's the packet + // data as Smack sees it and not as it's coming in as raw XML. + listener = new PacketListener() { + public void processPacket(Packet packet) { + if (printInterpreted) { + Log.d("SMACK", + dateFormatter.format(new Date()) + " RCV PKT (" + + connection.hashCode() + + "): " + + packet.toXML()); + } + } + }; + + connListener = new ConnectionListener() { + public void connectionClosed() { + Log.d("SMACK", + dateFormatter.format(new Date()) + " Connection closed (" + + connection.hashCode() + + ")"); + } + + public void connectionClosedOnError(Exception e) { + Log.d("SMACK", + dateFormatter.format(new Date()) + + " Connection closed due to an exception (" + + connection.hashCode() + + ")"); + e.printStackTrace(); + } + public void reconnectionFailed(Exception e) { + Log.d("SMACK", + dateFormatter.format(new Date()) + + " Reconnection failed due to an exception (" + + connection.hashCode() + + ")"); + e.printStackTrace(); + } + public void reconnectionSuccessful() { + Log.d("SMACK", + dateFormatter.format(new Date()) + " Connection reconnected (" + + connection.hashCode() + + ")"); + } + public void reconnectingIn(int seconds) { + Log.d("SMACK", + dateFormatter.format(new Date()) + " Connection (" + + connection.hashCode() + + ") will reconnect in " + seconds); + } + }; + } + + public Reader newConnectionReader(Reader newReader) { + ((ObservableReader)reader).removeReaderListener(readerListener); + ObservableReader debugReader = new ObservableReader(newReader); + debugReader.addReaderListener(readerListener); + reader = debugReader; + return reader; + } + + public Writer newConnectionWriter(Writer newWriter) { + ((ObservableWriter)writer).removeWriterListener(writerListener); + ObservableWriter debugWriter = new ObservableWriter(newWriter); + debugWriter.addWriterListener(writerListener); + writer = debugWriter; + return writer; + } + + public void userHasLogged(String user) { + boolean isAnonymous = "".equals(StringUtils.parseName(user)); + String title = + "User logged (" + connection.hashCode() + "): " + + (isAnonymous ? "" : StringUtils.parseBareAddress(user)) + + "@" + + connection.getServiceName() + + ":" + + connection.getPort(); + title += "/" + StringUtils.parseResource(user); + Log.d("SMACK", title); + // Add the connection listener to the connection so that the debugger can be notified + // whenever the connection is closed. + connection.addConnectionListener(connListener); + } + + public Reader getReader() { + return reader; + } + + public Writer getWriter() { + return writer; + } + + public PacketListener getReaderListener() { + return listener; + } + + public PacketListener getWriterListener() { + return null; + } +} + diff --git a/asmack-master/static-src/custom/de/measite/smack/Sasl.java b/asmack-master/static-src/custom/de/measite/smack/Sasl.java new file mode 100644 index 0000000..a59135d --- /dev/null +++ b/asmack-master/static-src/custom/de/measite/smack/Sasl.java @@ -0,0 +1,108 @@ +/* + * Copyright 2009 Rene Treffer + * + * 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 de.measite.smack; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Map; + +import org.apache.harmony.javax.security.auth.callback.CallbackHandler; +import org.apache.harmony.javax.security.sasl.SaslClient; +import org.apache.harmony.javax.security.sasl.SaslException; +import org.apache.harmony.javax.security.sasl.SaslServer; +import org.apache.harmony.javax.security.sasl.SaslServerFactory; + +public class Sasl { + + // SaslClientFactory service name + private static final String CLIENTFACTORYSRV = "SaslClientFactory"; //$NON-NLS-1$ + + // SaslServerFactory service name + private static final String SERVERFACTORYSRV = "SaslServerFactory"; //$NON-NLS-1$ + + public static final String POLICY_NOPLAINTEXT = "javax.security.sasl.policy.noplaintext"; //$NON-NLS-1$ + + public static final String POLICY_NOACTIVE = "javax.security.sasl.policy.noactive"; //$NON-NLS-1$ + + public static final String POLICY_NODICTIONARY = "javax.security.sasl.policy.nodictionary"; //$NON-NLS-1$ + + public static final String POLICY_NOANONYMOUS = "javax.security.sasl.policy.noanonymous"; //$NON-NLS-1$ + + public static final String POLICY_FORWARD_SECRECY = "javax.security.sasl.policy.forward"; //$NON-NLS-1$ + + public static final String POLICY_PASS_CREDENTIALS = "javax.security.sasl.policy.credentials"; //$NON-NLS-1$ + + public static final String MAX_BUFFER = "javax.security.sasl.maxbuffer"; //$NON-NLS-1$ + + public static final String RAW_SEND_SIZE = "javax.security.sasl.rawsendsize"; //$NON-NLS-1$ + + public static final String REUSE = "javax.security.sasl.reuse"; //$NON-NLS-1$ + + public static final String QOP = "javax.security.sasl.qop"; //$NON-NLS-1$ + + public static final String STRENGTH = "javax.security.sasl.strength"; //$NON-NLS-1$ + + public static final String SERVER_AUTH = "javax.security.sasl.server.authentication"; //$NON-NLS-1$ + + public static Enumeration<SaslClientFactory> getSaslClientFactories() { + Hashtable<SaslClientFactory,Object> factories = new Hashtable<SaslClientFactory,Object>(); + factories.put(new SaslClientFactory(), new Object()); + return factories.keys(); + } + + public static Enumeration<SaslServerFactory> getSaslServerFactories() { + return org.apache.harmony.javax.security.sasl.Sasl.getSaslServerFactories(); + } + + public static SaslServer createSaslServer(String mechanism, String protocol, + String serverName, Map<String, ?> prop, CallbackHandler cbh) throws SaslException { + return org.apache.harmony.javax.security.sasl.Sasl.createSaslServer(mechanism, protocol, serverName, prop, cbh); + } + + public static SaslClient createSaslClient(String[] mechanisms, String authanticationID, + String protocol, String serverName, Map<String, ?> prop, CallbackHandler cbh) + throws SaslException { + if (mechanisms == null) { + throw new NullPointerException("auth.33"); //$NON-NLS-1$ + } + SaslClientFactory fact = getSaslClientFactories().nextElement(); + String[] mech = fact.getMechanismNames(null); + boolean is = false; + if (mech != null) { + for (int j = 0; j < mech.length; j++) { + for (int n = 0; n < mechanisms.length; n++) { + if (mech[j].equals(mechanisms[n])) { + is = true; + break; + } + } + } + } + if (is) { + return fact.createSaslClient( + mechanisms, + authanticationID, + protocol, + serverName, + prop, + cbh + ); + } + return null; + } + +} diff --git a/asmack-master/static-src/custom/de/measite/smack/SaslClientFactory.java b/asmack-master/static-src/custom/de/measite/smack/SaslClientFactory.java new file mode 100644 index 0000000..2fa1ebd --- /dev/null +++ b/asmack-master/static-src/custom/de/measite/smack/SaslClientFactory.java @@ -0,0 +1,60 @@ +/* + * Copyright 2009 Rene Treffer + * + * 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 de.measite.smack; + +import java.util.Map; + +import com.novell.sasl.client.DigestMD5SaslClient; + +import org.apache.harmony.javax.security.auth.callback.CallbackHandler; +import org.apache.harmony.javax.security.sasl.SaslClient; +import org.apache.harmony.javax.security.sasl.SaslException; +import org.apache.qpid.management.common.sasl.PlainSaslClient; + +public class SaslClientFactory implements + org.apache.harmony.javax.security.sasl.SaslClientFactory { + + @Override + public SaslClient createSaslClient(String[] mechanisms, + String authorizationId, String protocol, String serverName, + Map<String, ?> props, CallbackHandler cbh) throws SaslException { + for (String mech: mechanisms) { + if ("PLAIN".equals(mech)) { + return new PlainSaslClient(authorizationId, cbh); + } else + if ("DIGEST-MD5".equals(mech)) { + return DigestMD5SaslClient.getClient( + authorizationId, + protocol, + serverName, + props, + cbh + ); + } + } + return null; + } + + @Override + public String[] getMechanismNames(Map<String, ?> props) { + return new String[]{ + "PLAIN", + "DIGEST-MD5" + }; + } + +} diff --git a/asmack-master/static-src/custom/org/jivesoftware/smack/AndroidConnectionConfiguration.java b/asmack-master/static-src/custom/org/jivesoftware/smack/AndroidConnectionConfiguration.java new file mode 100644 index 0000000..6ec05e0 --- /dev/null +++ b/asmack-master/static-src/custom/org/jivesoftware/smack/AndroidConnectionConfiguration.java @@ -0,0 +1,113 @@ +package org.jivesoftware.smack; + +import java.io.File; + +import android.os.Build; + +import org.jivesoftware.smack.proxy.ProxyInfo; +import org.jivesoftware.smack.util.DNSUtil; +import org.jivesoftware.smack.util.dns.HostAddress; + +import java.util.List; + +/** + * This class wraps DNS SRV lookups for a new ConnectionConfiguration in a + * new thread, since Android API >= 11 (Honeycomb) does not allow network + * activity in the main thread. + * + * @author Florian Schmaus fschmaus@gmail.com + * + */ +public class AndroidConnectionConfiguration extends ConnectionConfiguration { + private static final int DEFAULT_TIMEOUT = 10000; + + /** + * Creates a new ConnectionConfiguration for the specified service name. + * A DNS SRV lookup will be performed to find out the actual host address + * and port to use for the connection. + * + * @param serviceName the name of the service provided by an XMPP server. + */ + public AndroidConnectionConfiguration(String serviceName) throws XMPPException { + super(); + AndroidInit(serviceName, DEFAULT_TIMEOUT); + } + + /** + * + * @param serviceName + * @param timeout + * @throws XMPPException + */ + public AndroidConnectionConfiguration(String serviceName, int timeout) throws XMPPException { + super(); + AndroidInit(serviceName, timeout); + } + + public AndroidConnectionConfiguration(String host, int port, String name) { + super(host, port, name); + AndroidInit(); + } + + private void AndroidInit() { + // API 14 is Ice Cream Sandwich + if (Build.VERSION.SDK_INT >= 14) { + setTruststoreType("AndroidCAStore"); + setTruststorePassword(null); + setTruststorePath(null); + } else { + setTruststoreType("BKS"); + String path = System.getProperty("javax.net.ssl.trustStore"); + if (path == null) + path = System.getProperty("java.home") + File.separator + "etc" + + File.separator + "security" + File.separator + + "cacerts.bks"; + setTruststorePath(path); + } + } + + /** + * + * @param serviceName + * @param timeout + * @throws XMPPException + */ + private void AndroidInit(String serviceName, int timeout) throws XMPPException { + AndroidInit(); + class DnsSrvLookupRunnable implements Runnable { + String serviceName; + List<HostAddress> addresses; + + public DnsSrvLookupRunnable(String serviceName) { + this.serviceName = serviceName; + } + + @Override + public void run() { + addresses = DNSUtil.resolveXMPPDomain(serviceName); + } + + public List<HostAddress> getHostAddresses() { + return addresses; + } + } + + DnsSrvLookupRunnable dnsSrv = new DnsSrvLookupRunnable(serviceName); + Thread t = new Thread(dnsSrv, "dns-srv-lookup"); + t.start(); + try { + t.join(timeout); + } catch (InterruptedException e) { + throw new XMPPException("DNS lookup timeout after " + timeout + "ms", e); + } + + hostAddresses = dnsSrv.getHostAddresses(); + if (hostAddresses == null) { + throw new XMPPException("DNS lookup failure"); + } + + ProxyInfo proxy = ProxyInfo.forDefaultProxy(); + + init(serviceName, proxy); + } +} diff --git a/asmack-master/static-src/custom/org/jivesoftware/smack/SmackAndroid.java b/asmack-master/static-src/custom/org/jivesoftware/smack/SmackAndroid.java new file mode 100644 index 0000000..a18d675 --- /dev/null +++ b/asmack-master/static-src/custom/org/jivesoftware/smack/SmackAndroid.java @@ -0,0 +1,59 @@ +package org.jivesoftware.smack; + +import org.jivesoftware.smack.util.DNSUtil; +import org.jivesoftware.smack.util.dns.DNSJavaResolver; +import org.jivesoftware.smackx.ConfigureProviderManager; +import org.jivesoftware.smackx.InitStaticCode; +import org.xbill.DNS.ResolverConfig; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; + +public class SmackAndroid { + private static SmackAndroid sSmackAndroid = null; + + private BroadcastReceiver mConnectivityChangedReceiver; + private Context mCtx; + + private SmackAndroid(Context ctx) { + mCtx = ctx; + DNSUtil.setDNSResolver(DNSJavaResolver.getInstance()); + InitStaticCode.initStaticCode(ctx); + ConfigureProviderManager.configureProviderManager(); + maybeRegisterReceiver(); + } + + public static SmackAndroid init(Context ctx) { + if (sSmackAndroid == null) { + sSmackAndroid = new SmackAndroid(ctx); + } else { + sSmackAndroid.maybeRegisterReceiver(); + } + return sSmackAndroid; + } + + public void onDestroy() { + if (mConnectivityChangedReceiver != null) { + mCtx.unregisterReceiver(mConnectivityChangedReceiver); + mConnectivityChangedReceiver = null; + } + } + + private void maybeRegisterReceiver() { + if (mConnectivityChangedReceiver == null) { + mConnectivityChangedReceiver = new ConnectivtyChangedReceiver(); + mCtx.registerReceiver(mConnectivityChangedReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE")); + } + } + + class ConnectivtyChangedReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + ResolverConfig.refresh(); + } + + } +} diff --git a/asmack-master/static-src/custom/org/jivesoftware/smackx/ConfigureProviderManager.java b/asmack-master/static-src/custom/org/jivesoftware/smackx/ConfigureProviderManager.java new file mode 100644 index 0000000..7c0cdf2 --- /dev/null +++ b/asmack-master/static-src/custom/org/jivesoftware/smackx/ConfigureProviderManager.java @@ -0,0 +1,207 @@ +/** + * 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.smackx; + +import org.jivesoftware.smack.provider.PrivacyProvider; +import org.jivesoftware.smack.provider.ProviderManager; +import org.jivesoftware.smackx.GroupChatInvitation; +import org.jivesoftware.smackx.PrivateDataManager; +import org.jivesoftware.smackx.bytestreams.ibb.provider.CloseIQProvider; +import org.jivesoftware.smackx.bytestreams.ibb.provider.DataPacketProvider; +import org.jivesoftware.smackx.bytestreams.ibb.provider.OpenIQProvider; +import org.jivesoftware.smackx.bytestreams.socks5.provider.BytestreamsProvider; +import org.jivesoftware.smackx.carbons.Carbon; +import org.jivesoftware.smackx.entitycaps.provider.CapsExtensionProvider; +import org.jivesoftware.smackx.forward.Forwarded; +import org.jivesoftware.smackx.packet.AttentionExtension; +import org.jivesoftware.smackx.packet.ChatStateExtension; +import org.jivesoftware.smackx.packet.LastActivity; +import org.jivesoftware.smackx.packet.Nick; +import org.jivesoftware.smackx.packet.OfflineMessageInfo; +import org.jivesoftware.smackx.packet.OfflineMessageRequest; +import org.jivesoftware.smackx.packet.SharedGroupsInfo; +import org.jivesoftware.smackx.ping.provider.PingProvider; +import org.jivesoftware.smackx.provider.DataFormProvider; +import org.jivesoftware.smackx.provider.DelayInformationProvider; +import org.jivesoftware.smackx.provider.DiscoverInfoProvider; +import org.jivesoftware.smackx.provider.DiscoverItemsProvider; +import org.jivesoftware.smackx.provider.HeadersProvider; +import org.jivesoftware.smackx.provider.HeaderProvider; +import org.jivesoftware.smackx.provider.MUCAdminProvider; +import org.jivesoftware.smackx.provider.MUCOwnerProvider; +import org.jivesoftware.smackx.provider.MUCUserProvider; +import org.jivesoftware.smackx.provider.MessageEventProvider; +import org.jivesoftware.smackx.provider.MultipleAddressesProvider; +import org.jivesoftware.smackx.provider.RosterExchangeProvider; +import org.jivesoftware.smackx.provider.StreamInitiationProvider; +import org.jivesoftware.smackx.provider.VCardProvider; +import org.jivesoftware.smackx.provider.XHTMLExtensionProvider; +import org.jivesoftware.smackx.pubsub.provider.AffiliationProvider; +import org.jivesoftware.smackx.pubsub.provider.AffiliationsProvider; +import org.jivesoftware.smackx.pubsub.provider.ConfigEventProvider; +import org.jivesoftware.smackx.pubsub.provider.EventProvider; +import org.jivesoftware.smackx.pubsub.provider.FormNodeProvider; +import org.jivesoftware.smackx.pubsub.provider.ItemProvider; +import org.jivesoftware.smackx.pubsub.provider.ItemsProvider; +import org.jivesoftware.smackx.pubsub.provider.PubSubProvider; +import org.jivesoftware.smackx.pubsub.provider.RetractEventProvider; +import org.jivesoftware.smackx.pubsub.provider.SimpleNodeProvider; +import org.jivesoftware.smackx.pubsub.provider.SubscriptionProvider; +import org.jivesoftware.smackx.pubsub.provider.SubscriptionsProvider; +import org.jivesoftware.smackx.receipts.DeliveryReceipt; +import org.jivesoftware.smackx.search.UserSearch; + +/** + * Since dalvik on Android does not allow the loading of META-INF files from the + * filesystem, you have to register every provider manually. + * + * The full list of providers is at: + * http://fisheye.igniterealtime.org/browse/smack/trunk/build/resources/META-INF/smack.providers?hb=true + * + * @author Florian Schmaus fschmaus@gmail.com + * + */ +public class ConfigureProviderManager { + + public static void configureProviderManager() { + ProviderManager pm = ProviderManager.getInstance(); + + // The order is the same as in the smack.providers file + + // Private Data Storage + pm.addIQProvider("query","jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider()); + // Time + try { + pm.addIQProvider("query","jabber:iq:time", Class.forName("org.jivesoftware.smackx.packet.Time")); + } catch (ClassNotFoundException e) { + System.err.println("Can't load class for org.jivesoftware.smackx.packet.Time"); + } + + // Roster Exchange + pm.addExtensionProvider("x","jabber:x:roster", new RosterExchangeProvider()); + // Message Events + pm.addExtensionProvider("x","jabber:x:event", new MessageEventProvider()); + // Chat State + pm.addExtensionProvider("active","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider()); + pm.addExtensionProvider("composing","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider()); + pm.addExtensionProvider("paused","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider()); + pm.addExtensionProvider("inactive","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider()); + pm.addExtensionProvider("gone","http://jabber.org/protocol/chatstates", new ChatStateExtension.Provider()); + + // XHTML + pm.addExtensionProvider("html","http://jabber.org/protocol/xhtml-im", new XHTMLExtensionProvider()); + + // Group Chat Invitations + pm.addExtensionProvider("x","jabber:x:conference", new GroupChatInvitation.Provider()); + // Service Discovery # Items + pm.addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider()); + // Service Discovery # Info + pm.addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider()); + // Data Forms + pm.addExtensionProvider("x","jabber:x:data", new DataFormProvider()); + // MUC User + pm.addExtensionProvider("x","http://jabber.org/protocol/muc#user", new MUCUserProvider()); + // MUC Admin + pm.addIQProvider("query","http://jabber.org/protocol/muc#admin", new MUCAdminProvider()); + // MUC Owner + pm.addIQProvider("query","http://jabber.org/protocol/muc#owner", new MUCOwnerProvider()); + // Delayed Delivery + pm.addExtensionProvider("x","jabber:x:delay", new DelayInformationProvider()); + pm.addExtensionProvider("delay", "urn:xmpp:delay", new DelayInformationProvider()); + // Version + try { + pm.addIQProvider("query","jabber:iq:version", Class.forName("org.jivesoftware.smackx.packet.Version")); + } catch (ClassNotFoundException e) { + System.err.println("Can't load class for org.jivesoftware.smackx.packet.Version"); + } + // VCard + pm.addIQProvider("vCard","vcard-temp", new VCardProvider()); + // Offline Message Requests + pm.addIQProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider()); + // Offline Message Indicator + pm.addExtensionProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider()); + // Last Activity + pm.addIQProvider("query","jabber:iq:last", new LastActivity.Provider()); + // User Search + pm.addIQProvider("query","jabber:iq:search", new UserSearch.Provider()); + // SharedGroupsInfo + pm.addIQProvider("sharedgroup","http://www.jivesoftware.org/protocol/sharedgroup", new SharedGroupsInfo.Provider()); + + // JEP-33: Extended Stanza Addressing + pm.addExtensionProvider("addresses","http://jabber.org/protocol/address", new MultipleAddressesProvider()); + + // FileTransfer + pm.addIQProvider("si","http://jabber.org/protocol/si", new StreamInitiationProvider()); + pm.addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider()); + pm.addIQProvider("open","http://jabber.org/protocol/ibb", new OpenIQProvider()); + pm.addIQProvider("data","http://jabber.org/protocol/ibb", new DataPacketProvider()); + pm.addIQProvider("close","http://jabber.org/protocol/ibb", new CloseIQProvider()); + pm.addExtensionProvider("data","http://jabber.org/protocol/ibb", new DataPacketProvider()); + + // Privacy + pm.addIQProvider("query","jabber:iq:privacy", new PrivacyProvider()); + + // SHIM + pm.addExtensionProvider("headers", "http://jabber.org/protocol/shim", new HeadersProvider()); + pm.addExtensionProvider("header", "http://jabber.org/protocol/shim", new HeaderProvider()); + + // PubSub + pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub", new PubSubProvider()); + pm.addExtensionProvider("create", "http://jabber.org/protocol/pubsub", new SimpleNodeProvider()); + pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider()); + pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub", new ItemProvider()); + pm.addExtensionProvider("subscriptions", "http://jabber.org/protocol/pubsub", new SubscriptionsProvider()); + pm.addExtensionProvider("subscription", "http://jabber.org/protocol/pubsub", new SubscriptionProvider()); + pm.addExtensionProvider("affiliations", "http://jabber.org/protocol/pubsub", new AffiliationsProvider()); + pm.addExtensionProvider("affiliation", "http://jabber.org/protocol/pubsub", new AffiliationProvider()); + pm.addExtensionProvider("options", "http://jabber.org/protocol/pubsub", new FormNodeProvider()); + // PubSub owner + pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub#owner", new PubSubProvider()); + pm.addExtensionProvider("configure", "http://jabber.org/protocol/pubsub#owner", new FormNodeProvider()); + pm.addExtensionProvider("default", "http://jabber.org/protocol/pubsub#owner", new FormNodeProvider()); + // PubSub event + pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", new EventProvider()); + pm.addExtensionProvider("configuration", "http://jabber.org/protocol/pubsub#event", new ConfigEventProvider()); + pm.addExtensionProvider("delete", "http://jabber.org/protocol/pubsub#event", new SimpleNodeProvider()); + pm.addExtensionProvider("options", "http://jabber.org/protocol/pubsub#event", new FormNodeProvider()); + pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub#event", new ItemsProvider()); + pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub#event", new ItemProvider()); + pm.addExtensionProvider("retract", "http://jabber.org/protocol/pubsub#event", new RetractEventProvider()); + pm.addExtensionProvider("purge", "http://jabber.org/protocol/pubsub#event", new SimpleNodeProvider()); + + // Nick Exchange + pm.addExtensionProvider("nick", "http://jabber.org/protocol/nick", new Nick.Provider()); + + // Attention + pm.addExtensionProvider("attention", "urn:xmpp:attention:0", new AttentionExtension.Provider()); + + // XEP-0297 Stanza Forwarding + pm.addExtensionProvider("forwarded", "urn:xmpp:forward:0", new Forwarded.Provider()); + + // XEP-0280 Message Carbons + pm.addExtensionProvider("sent", "urn:xmpp:carbons:2", new Carbon.Provider()); + pm.addExtensionProvider("received", "urn:xmpp:carbons:2", new Carbon.Provider()); + + // XEP-0199 XMPP Ping + pm.addIQProvider("ping", "urn:xmpp:ping", new PingProvider()); + + // XEP-184 Message Delivery Receipts + pm.addExtensionProvider("received", "urn:xmpp:receipts", new DeliveryReceipt.Provider()); + pm.addExtensionProvider("request", "urn:xmpp:receipts", new DeliveryReceipt.Provider()); + + // XEP-0115 Entity Capabilities + pm.addExtensionProvider("c", "http://jabber.org/protocol/caps", new CapsExtensionProvider()); + } +} diff --git a/asmack-master/static-src/custom/org/jivesoftware/smackx/InitStaticCode.java b/asmack-master/static-src/custom/org/jivesoftware/smackx/InitStaticCode.java new file mode 100644 index 0000000..12de5af --- /dev/null +++ b/asmack-master/static-src/custom/org/jivesoftware/smackx/InitStaticCode.java @@ -0,0 +1,51 @@ +/** + * 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.smackx; + +import android.content.Context; + +/** + * Since dalvik on Android does not allow the loading of META-INF files from the + * filesystem, the static blocks of some classes have to be inited manually. + * + * The full list can be found here: + * http://fisheye.igniterealtime.org/browse/smack/trunk/build/resources/META-INF/smack-config.xml?hb=true + * + * @author Florian Schmaus fschmaus@gmail.com + * + */ +public class InitStaticCode { + + public static void initStaticCode(Context ctx) { + // This has the be the application class loader, + // *not* the system class loader + ClassLoader appClassLoader = ctx.getClassLoader(); + + try { + Class.forName(org.jivesoftware.smackx.ServiceDiscoveryManager.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smack.PrivacyListManager.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smackx.XHTMLManager.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smackx.muc.MultiUserChat.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smackx.filetransfer.FileTransferManager.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smackx.LastActivityManager.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smack.ReconnectionManager.class.getName(), true, appClassLoader); + Class.forName(org.jivesoftware.smackx.commands.AdHocCommandManager.class.getName(), true, appClassLoader); + } catch (ClassNotFoundException e) { + throw new IllegalStateException("Could not init static class blocks", e); + } + } +} diff --git a/asmack-master/static-src/custom/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java b/asmack-master/static-src/custom/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java new file mode 100644 index 0000000..a6b8694 --- /dev/null +++ b/asmack-master/static-src/custom/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java @@ -0,0 +1,92 @@ +/**
+ * 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.smackx.pubsub.provider;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.jivesoftware.smack.provider.ProviderManager;
+import org.jivesoftware.smack.util.PacketParserUtils;
+import org.jivesoftware.smackx.pubsub.Item;
+import org.jivesoftware.smackx.pubsub.PayloadItem;
+import org.jivesoftware.smackx.pubsub.SimplePayload;
+import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * Parses an <b>item</b> element as is defined in both the {@link PubSubNamespace#BASIC} and {@link PubSubNamespace#EVENT}
+ * namespaces. To parse the item contents, it will use whatever {@link PacketExtensionProvider} is registered in
+ * <b>smack.providers</b> for its element name and namespace. If no provider is registered, it will return a {@link SimplePayload}.
+ *
+ * @author Robin Collier
+ */
+public class ItemProvider implements PacketExtensionProvider {
+ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
+ String id = parser.getAttributeValue(null, "id");
+ String node = parser.getAttributeValue(null, "node");
+ String elem = parser.getName();
+
+ int tag = parser.next();
+
+ if (tag == XmlPullParser.END_TAG) {
+ return new Item(id, node);
+ } else {
+ String payloadElemName = parser.getName();
+ String payloadNS = parser.getNamespace();
+
+ if (ProviderManager.getInstance().getExtensionProvider(payloadElemName, payloadNS) == null) {
+ StringBuilder payloadText = new StringBuilder();
+ boolean done = false;
+ boolean isEmptyElement = false;
+
+ // Parse custom payload
+ while (!done) {
+ if (tag == XmlPullParser.END_TAG && parser.getName().equals(elem)) {
+ done = true;
+ } else if (parser.getEventType() == XmlPullParser.START_TAG) {
+ payloadText.append("<").append(parser.getName());
+ if (parser.getName().equals(payloadElemName) && (!"".equals(payloadNS))) {
+ payloadText.append(" xmlns=\"").append(payloadNS).append("\"");
+ }
+ int n = parser.getAttributeCount();
+ for (int i = 0; i < n; i++) {
+ payloadText.append(" ").append(parser.getAttributeName(i)).append("=\"")
+ .append(parser.getAttributeValue(i)).append("\"");
+ }
+ if (parser.isEmptyElementTag()) {
+ payloadText.append("/>");
+ isEmptyElement = true;
+ } else {
+ payloadText.append(">");
+ }
+ } else if (parser.getEventType() == XmlPullParser.END_TAG) {
+ if (isEmptyElement) {
+ isEmptyElement = false;
+ } else {
+ payloadText.append("</").append(parser.getName()).append(">");
+ }
+ } else if (parser.getEventType() == XmlPullParser.TEXT) {
+ payloadText.append(parser.getText());
+ }
+
+ tag = parser.next();
+ }
+ return new PayloadItem<SimplePayload>(id, node, new SimplePayload(payloadElemName, payloadNS,
+ payloadText.toString()));
+ } else {
+ return new PayloadItem<PacketExtension>(id, node, PacketParserUtils.parsePacketExtension(
+ payloadElemName, payloadNS, parser));
+ }
+ }
+ }
+}
|