# HG changeset patch # User Da Risk # Date 1351721474 -3600 # Node ID 4c7edc276676136e3bda6f4f230e88863c13fc62 # Parent aa8c2dac6d02ace669354b4dc336d8c0619b9037 Switch to Florian Shmauss maintained version of asmack. See doc/asmack-beem/README.txt for more information on how to build the asmack jar. The upstream asmack has a better implementation of XEP-0115 EntityCapabilities. So this commit remove the specific Beem implementation of this XEP and switch to the asmack one. diff -r aa8c2dac6d02 -r 4c7edc276676 doc/asmack-beem/README.txt --- a/doc/asmack-beem/README.txt Sun Oct 28 14:26:54 2012 +0100 +++ b/doc/asmack-beem/README.txt Wed Oct 31 23:11:14 2012 +0100 @@ -1,39 +1,37 @@ INTRODUCTION ------------ asmack http://code.google.com/p/asmack/ is a portage of the Smack library for -the Android platform. The project is mostly maintained by Rene Treffer and you -can find the binaries at http://code.google.com/p/asmack/ and the sources at -http://github.com/rtreffer/asmack +the Android platform. The project is was maintained by Rene Treffer. + +Florian Schmaus maintains a more up to date version of this project. This +version is used by many XMPP clients for Android. + +You can find the sources at + http://github.com/rtreffer/asmack for Rene version + http://github.com/Flowdalic/asmack for Florian version The asmack project is based on the development version of the Smack library. This version is constantly moving but we want a fixed version for BEEM. -We patched the asmack build process to use a fixed version of the Smack -library. Currently, we use the revision 11644 of the Smack SVN repository. +library. +Currently, we use the changeset 0ffd380698bca3502a6f25c4d755fe79f6977b49 of +the Florian's Smack git repository. COMPILE ------- First check out the last version of asmack -> git clone git://github.com/rtreffer/asmack.git - -Then apply the beem-build-process.patch on the source. -> cd asmack -> patch -p1 < beem-build-process.patch -> +> git clone git://github.com/Flowdalic/asmack.git Add the beem flavour to the patch repository +> rm -rf patch/beem > cp -R beem_patches patch/beem > -The 50-fix_chatmanager.patch is only necessary to fix a little bug in smack. The -patch has been proposed to the Smack developers. See -http://www.igniterealtime.org/issues/browse/SMACK-269 for progress. - Edit your local.properties file to contains the path of the android SDK. See local.properties.example -Build asmack -> ./build.batch +Build asmack with beem patches +> ./build.bash -c -b 0ffd380698bca3502a6f25c4d755fe79f6977b49 > The build directory will contains the files : diff -r aa8c2dac6d02 -r 4c7edc276676 doc/asmack-beem/beem_patches/10-custom-sslcontext.patch --- a/doc/asmack-beem/beem_patches/10-custom-sslcontext.patch Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -Index: org/jivesoftware/smack/XMPPConnection.java -=================================================================== ---- org/jivesoftware/smack/XMPPConnection.java (révision 11644) -+++ org/jivesoftware/smack/XMPPConnection.java (copie de travail) -@@ -758,14 +758,14 @@ - * @throws Exception if an exception occurs. - */ - void proceedTLSReceived() throws Exception { -- SSLContext context = SSLContext.getInstance("TLS"); -+ SSLContext context = this.config.getCustomSSLContext(); - KeyStore ks = null; - KeyManager[] kms = null; - PasswordCallback pcb = null; - - if(config.getCallbackHandler() == null) { - ks = null; -- } else { -+ } else if (context == null) { - //System.out.println("Keystore type: "+configuration.getKeystoreType()); - if(config.getKeystoreType().equals("NONE")) { - ks = null; -@@ -821,10 +821,12 @@ - } - - // Verify certificate presented by the server -- context.init(kms, -- new javax.net.ssl.TrustManager[]{new ServerTrustManager(getServiceName(), config)}, -- //new javax.net.ssl.TrustManager[]{new OpenTrustManager()}, -- new java.security.SecureRandom()); -+ if (context == null) { -+ context = SSLContext.getInstance("TLS"); -+ context.init(kms, -+ new javax.net.ssl.TrustManager[]{new ServerTrustManager(getServiceName(), config)}, -+ new java.security.SecureRandom()); -+ } - Socket plain = socket; - // Secure the plain connection - socket = context.getSocketFactory().createSocket(plain, -Index: org/jivesoftware/smack/ConnectionConfiguration.java -=================================================================== ---- org/jivesoftware/smack/ConnectionConfiguration.java (révision 11644) -+++ org/jivesoftware/smack/ConnectionConfiguration.java (copie de travail) -@@ -20,6 +20,7 @@ - - package org.jivesoftware.smack; - -+import javax.net.ssl.SSLContext; - import org.jivesoftware.smack.proxy.ProxyInfo; - import org.jivesoftware.smack.util.DNSUtil; - -@@ -59,6 +60,7 @@ - private boolean selfSignedCertificateEnabled = false; - private boolean expiredCertificatesCheckEnabled = false; - private boolean notMatchingDomainCheckEnabled = false; -+ private SSLContext customSSLContext; - - private boolean compressionEnabled = false; - -@@ -487,6 +489,25 @@ - } - - /** -+ * Gets the custom SSLContext for SSL sockets. This is null by default. -+ * -+ * @return the SSLContext previously set with setCustomSSLContext() or null. -+ */ -+ public SSLContext getCustomSSLContext() { -+ return this.customSSLContext; -+ } -+ -+ /** -+ * Sets a custom SSLContext for creating SSL sockets. A custom Context causes all other -+ * SSL/TLS realted settings to be ignored. -+ * -+ * @param context the custom SSLContext for new sockets; null to reset default behaviour. -+ */ -+ public void setCustomSSLContext(SSLContext context) { -+ this.customSSLContext = context; -+ } -+ -+ /** - * Returns true if the connection is going to use stream compression. Stream compression - * will be requested after TLS was established (if TLS was enabled) and only if the server - * offered stream compression. With stream compression network traffic can be reduced diff -r aa8c2dac6d02 -r 4c7edc276676 doc/asmack-beem/beem_patches/50-fix-chatmanager.patch --- a/doc/asmack-beem/beem_patches/50-fix-chatmanager.patch Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ - Copyright (C) 2010 by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - 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. - ---- ../../../src/smack/org/jivesoftware/smack/ChatManager.java 2010-02-23 19:27:26.000000000 +0100 -+++ org/jivesoftware/smack/ChatManager.java 2010-02-23 19:37:47.000000000 +0100 -@@ -111,7 +111,9 @@ - chat = getUserChat(message.getFrom()); - } - } -- -+ if (chat == null) { -+ chat = getUserChat(StringUtils.parseBareAddress(message.getFrom())); -+ } - if(chat == null) { - chat = createChat(message); - } diff -r aa8c2dac6d02 -r 4c7edc276676 doc/asmack-beem/beem_patches/50-fix-sasl-incorrect-encoding.patch --- a/doc/asmack-beem/beem_patches/50-fix-sasl-incorrect-encoding.patch Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ - Copyright (C) 2010 by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - 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. - ---- org/jivesoftware/smack/sasl/SASLMechanism.java~ 2010-07-20 15:13:25.000000000 +0200 -+++ org/jivesoftware/smack/sasl/SASLMechanism.java 2010-07-20 15:15:41.000000000 +0200 -@@ -263,9 +263,6 @@ - if (authenticationText != null) { - stanza.append(authenticationText); - } -- else { -- stanza.append("="); -- } - stanza.append(""); - return stanza.toString(); - } diff -r aa8c2dac6d02 -r 4c7edc276676 doc/asmack-beem/beem_patches/50-public-info-features.patch --- a/doc/asmack-beem/beem_patches/50-public-info-features.patch Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ - Copyright (C) 2010 by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - 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. - ---- org/jivesoftware/smackx/packet/DiscoverInfo.java 2010-07-22 22:16:27.000000000 +0200 -+++ org/jivesoftware/smackx/packet/DiscoverInfo.java 2010-07-22 22:58:43.000000000 +0200 -@@ -62,7 +62,7 @@ - * - * @return an Iterator on the discovered features of an XMPP entity - */ -- Iterator getFeatures() { -+ public Iterator getFeatures() { - synchronized (features) { - return Collections.unmodifiableList(features).iterator(); - } -@@ -266,4 +266,4 @@ - return buf.toString(); - } - } --} -\ Pas de fin de ligne à la fin du fichier. -+} diff -r aa8c2dac6d02 -r 4c7edc276676 libs/asmack-android-16-beem.jar Binary file libs/asmack-android-16-beem.jar has changed diff -r aa8c2dac6d02 -r 4c7edc276676 libs/asmack-android-7-beem.jar Binary file libs/asmack-android-7-beem.jar has changed diff -r aa8c2dac6d02 -r 4c7edc276676 project.properties --- a/project.properties Sun Oct 28 14:26:54 2012 +0100 +++ b/project.properties Wed Oct 31 23:11:14 2012 +0100 @@ -3,9 +3,12 @@ # # This file must be checked in Version Control Systems. # -# To customize properties used by the Ant build system use, +# To customize properties used by the Ant build system edit # "ant.properties", and override values to adapt the script to your # project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. target=android-16 diff -r aa8c2dac6d02 -r 4c7edc276676 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sun Oct 28 14:26:54 2012 +0100 +++ b/src/com/beem/project/beem/BeemService.java Wed Oct 31 23:11:14 2012 +0100 @@ -43,6 +43,8 @@ */ package com.beem.project.beem; +import java.io.File; +import java.io.IOException; import java.security.GeneralSecurityException; import javax.net.ssl.SSLContext; @@ -73,7 +75,6 @@ import com.beem.project.beem.service.auth.PreferenceAuthenticator; import com.beem.project.beem.smack.avatar.AvatarMetadataProvider; import com.beem.project.beem.smack.avatar.AvatarProvider; -import com.beem.project.beem.smack.caps.CapsProvider; import com.beem.project.beem.smack.ping.PingExtension; import com.beem.project.beem.smack.sasl.SASLGoogleOAuth2Mechanism; import com.beem.project.beem.utils.BeemBroadcastReceiver; @@ -92,7 +93,11 @@ import org.jivesoftware.smack.proxy.ProxyInfo; import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType; import org.jivesoftware.smack.util.StringUtils; +import org.jivesoftware.smackx.entitycaps.EntityCapsManager; +import org.jivesoftware.smackx.entitycaps.SimpleDirectoryPersistentCache; +import org.jivesoftware.smackx.entitycaps.packet.CapsExtension; import org.jivesoftware.smackx.packet.ChatStateExtension; +import org.jivesoftware.smackx.provider.CapsExtensionProvider; import org.jivesoftware.smackx.provider.DelayInfoProvider; import org.jivesoftware.smackx.provider.DiscoverInfoProvider; import org.jivesoftware.smackx.provider.DiscoverItemsProvider; @@ -212,7 +217,7 @@ @Override public boolean onUnbind(Intent intent) { Log.d(TAG, "ONUNBIND()"); - if (!mConnection.getAdaptee().isConnected()) { + if (mConnection != null && !mConnection.getAdaptee().isConnected()) { this.stopSelf(); } return true; @@ -459,7 +464,8 @@ pm.addExtensionProvider("inactive", "http://jabber.org/protocol/chatstates", chatState); pm.addExtensionProvider("gone", "http://jabber.org/protocol/chatstates", chatState); // capabilities - pm.addExtensionProvider("c", "http://jabber.org/protocol/caps", new CapsProvider()); + pm.addExtensionProvider(CapsExtension.NODE_NAME, CapsExtension.XMLNS, new CapsExtensionProvider()); + //Pubsub pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub", new PubSubProvider()); pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider()); @@ -554,6 +560,17 @@ /* register additionnals sasl mechanisms */ SASLAuthentication.registerSASLMechanism(SASLGoogleOAuth2Mechanism.MECHANISM_NAME, SASLGoogleOAuth2Mechanism.class); + + // Configure entity caps manager. This must be done only once + File f = new File(getCacheDir(), "entityCaps"); + f.mkdirs(); + try { + EntityCapsManager.setPersistentCache(new SimpleDirectoryPersistentCache(f)); + } catch (IllegalStateException e) { + Log.v(TAG, "EntityCapsManager already initialized", e); + } catch (IOException e) { + Log.w(TAG, "EntityCapsManager not able to reuse persistent cache"); + } } /** diff -r aa8c2dac6d02 -r 4c7edc276676 src/com/beem/project/beem/service/BeemCapsManager.java --- a/src/com/beem/project/beem/service/BeemCapsManager.java Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -/* - BEEM is a videoconference application on the Android Platform. - - Copyright (C) 2009 by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - This file is part of BEEM. - - BEEM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - BEEM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with BEEM. If not, see . - - Please send bug reports with examples or suggestions to - contact@beem-project.com or http://dev.beem-project.com/ - - Epitech, hereby disclaims all copyright interest in the program "Beem" - written by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - Nicolas Sadirac, November 26, 2009 - President of Epitech. - - Flavien Astraud, November 26, 2009 - Head of the EIP Laboratory. - -*/ -package com.beem.project.beem.service; - -import org.jivesoftware.smack.Connection; -import org.jivesoftware.smackx.packet.DiscoverInfo; -import org.jivesoftware.smackx.ServiceDiscoveryManager; -import org.jivesoftware.smack.util.PacketParserUtils; -import org.xmlpull.v1.XmlPullParserFactory; -import org.xmlpull.v1.XmlPullParserException; -import org.xmlpull.v1.XmlPullParser; - -import android.util.Log; -import java.io.FileReader; -import java.io.Reader; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.Writer; - -import java.io.File; -import java.io.IOException; - -import android.content.Context; - -import com.beem.project.beem.smack.caps.CapsManager; - -/** - * An implementation of CapsManager which keeps DiscoverInfo on the Cache directory of the android application. - */ -public class BeemCapsManager extends CapsManager { - - private static final String TAG = "BeemCapsManager"; - - private Context mContext; - private File mCacheDir; - private XmlPullParser mParser; - - /** - * Create a BeemCapsManager. - * - * @param sdm the ServiceDiscoveryManager to use - * @param conn the connection to use - * @param context the Android context to use to store data - */ - public BeemCapsManager(final ServiceDiscoveryManager sdm, final Connection conn, final Context context) { - super(sdm, conn); - mContext = context; - initCacheDirectory(); - } - - - @Override - protected DiscoverInfo load(String ver) { - File fver = new File(mCacheDir, sanitizeName(ver)); - try { - Reader fr = new BufferedReader(new FileReader(fver)); - try { - if (mParser == null) - mParser = makeParser(); - mParser.setInput(fr); - return (DiscoverInfo) PacketParserUtils.parsePacketExtension("query", - "http://jabber.org/protocol/disco#info", mParser); - - } finally { - fr.close(); - } - } catch (Exception e) { - // The parsePacketExtension throw Exception on error - Log.d(TAG, "Error while loading Capabilities " + ver, e); - } - return null; - } - - @Override - protected void store(String ver, DiscoverInfo info) { - - File fver = new File(mCacheDir, sanitizeName(ver)); - try { - Writer fw = new BufferedWriter(new FileWriter(fver)); - try { - String data = info.toXML(); - fw.write(data, 0, data.length()); - } finally { - fw.close(); - } - } catch (IOException e) { - Log.d(TAG, "Error while saving Capabilities " + ver, e); - } - } - - @Override - protected boolean isInCache(String ver) { - boolean result = super.isInCache(ver); - if (!result) { - File fver = new File(mCacheDir, sanitizeName(ver)); - result = fver.exists(); - } - return result; - } - - /** - * Init the cache directory. - */ - private void initCacheDirectory() { - File dir = mContext.getCacheDir(); - mCacheDir = new File(dir, "capabilities"); - mCacheDir.mkdir(); - } - - /** - * Make an Xml parser. - * - * @return the created xml parser. - * @throws XmlPullParserException if an error occurs while creating the parser. - */ - private XmlPullParser makeParser() throws XmlPullParserException { - XmlPullParserFactory fact = XmlPullParserFactory.newInstance(); - fact.setNamespaceAware(true); - return fact.newPullParser(); - } - - /** - * Sanitize the base64 ver attribute in order to use it as a filename. - * @param ver the base64 ver attribute - * @return a sanitize filename for the ver attribute - */ - private String sanitizeName(String ver) { - return ver.replaceAll("/", "."); - } -} diff -r aa8c2dac6d02 -r 4c7edc276676 src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Sun Oct 28 14:26:54 2012 +0100 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Wed Oct 31 23:11:14 2012 +0100 @@ -88,6 +88,7 @@ import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smackx.ChatStateManager; import org.jivesoftware.smackx.ServiceDiscoveryManager; +import org.jivesoftware.smackx.entitycaps.EntityCapsManager; import org.jivesoftware.smackx.packet.DiscoverInfo; /** @@ -492,8 +493,9 @@ sdm.addFeature(PingExtension.NAMESPACE); mChatStateManager = ChatStateManager.getInstance(mAdaptee); - BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService); - caps.setNode("http://www.beem-project.com"); + + EntityCapsManager em = sdm.getEntityCapsManager(); + em.setNode("http://www.beem-project.com"); } /** diff -r aa8c2dac6d02 -r 4c7edc276676 src/com/beem/project/beem/smack/caps/CapsExtension.java --- a/src/com/beem/project/beem/smack/caps/CapsExtension.java Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -/* - BEEM is a videoconference application on the Android Platform. - - Copyright (C) 2009 by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - This file is part of BEEM. - - BEEM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - BEEM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with BEEM. If not, see . - - Please send bug reports with examples or suggestions to - contact@beem-project.com or http://dev.beem-project.com/ - - Epitech, hereby disclaims all copyright interest in the program "Beem" - written by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - Nicolas Sadirac, November 26, 2009 - President of Epitech. - - Flavien Astraud, November 26, 2009 - Head of the EIP Laboratory. - -*/ - -package com.beem.project.beem.smack.caps; - -import org.jivesoftware.smack.packet.PacketExtension; - -/** - * This extension represents a capability of XEP-0115. - * - */ -public class CapsExtension implements PacketExtension { - - private String mVer; - private String mHash; - private String mNode; - private String mExt; - - - /** - * Create a CapsExtension. - * - * @param hash The value of the hash attribute. - * @param node the value of the node attribute - * @param ver the value of the ver attribute. - */ - public CapsExtension(final String hash, final String node, final String ver) { - mHash = hash; - mNode = node; - mVer = ver; - } - - /** - * Get the ver attribute value. - * - * @return the value of the ver attribute. - */ - public String getVer() { - return mVer; - } - - /** - * Get the hash attribute value. - * - * @return the value of the hash attribute. - */ - public String getHash() { - return mHash; - } - - /** - * Get the node attribute value. - * - * @return the value of the node attribute. - */ - public String getNode() { - return mNode; - } - - /** - * Get the ext attribute value. - * - * @return the value of the ext attribute. - */ - public String getExt() { - return mExt; - } - - /** - * Set the hash attribute. - * - * @param hash the value of hash - */ - public void setHash(String hash) { - mHash = hash; - } - - /** - * Set the ver attribute. - * - * @param ver the value of ver - */ - public void setVer(String ver) { - mVer = ver; - } - - /** - * Set the node attribute. - * - * @param node the value of node - */ - public void setNode(String node) { - mNode = node; - } - - /** - * Set the ext attribute. - * - * @param ext the value of ext - */ - public void setExt(String ext) { - mExt = ext; - } - - @Override - public String getElementName() { - return "c"; - } - - @Override - public String getNamespace() { - return "http://jabber.org/protocol/caps"; - } - - @Override - public String toXML() { - StringBuilder b = new StringBuilder("<"); - b.append(getElementName()); - b.append(" xmlns=\"").append(getNamespace()).append("\" "); - if (mHash != null) { - b.append("hash=\"").append(mHash).append("\" "); - } - if (mNode != null) - b.append("node=\"").append(mNode).append("\" "); - if (mVer != null) - b.append("ver=\"").append(mVer).append("\" "); - if (mExt != null) - b.append("ext=\"").append(mExt).append("\" "); - b.append("/>"); - return b.toString(); - } - -} diff -r aa8c2dac6d02 -r 4c7edc276676 src/com/beem/project/beem/smack/caps/CapsManager.java --- a/src/com/beem/project/beem/smack/caps/CapsManager.java Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,372 +0,0 @@ -/* - BEEM is a videoconference application on the Android Platform. - - Copyright (C) 2009 by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - This file is part of BEEM. - - BEEM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - BEEM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with BEEM. If not, see . - - Please send bug reports with examples or suggestions to - contact@beem-project.com or http://dev.beem-project.com/ - - Epitech, hereby disclaims all copyright interest in the program "Beem" - written by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - Nicolas Sadirac, November 26, 2009 - President of Epitech. - - Flavien Astraud, November 26, 2009 - Head of the EIP Laboratory. - -*/ -package com.beem.project.beem.smack.caps; - -import org.jivesoftware.smack.Connection; -import org.jivesoftware.smack.PacketInterceptor; -import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smackx.packet.DiscoverInfo; -import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smack.packet.PacketExtension; -import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smackx.ServiceDiscoveryManager; -import org.jivesoftware.smack.util.collections.ReferenceMap; -import org.jivesoftware.smack.PacketListener; -import org.jivesoftware.smack.filter.PacketFilter; -import org.jivesoftware.smack.filter.PacketTypeFilter; -import org.jivesoftware.smack.filter.PacketExtensionFilter; - -import java.util.Map; -import java.util.Iterator; -import java.util.Comparator; -import java.util.List; -import java.util.ArrayList; -import java.util.Collections; -import java.security.NoSuchAlgorithmException; -import java.security.MessageDigest; - -import org.jivesoftware.smack.util.StringUtils; - -/** - * Capabilities manager to implements XEP-0115. - * The DiscoverInfo are cached in memory. - * - */ -public class CapsManager { - // the verCache should be stored on disk - private Map mVerCache = new ReferenceMap(); - private Map mJidCache = new ReferenceMap(); - - private ServiceDiscoveryManager mSdm; - private Connection mConnection; - private String mNode; - private List mSupportedAlgorithm = new ArrayList(); - - /** - * Create a CapsManager. - * - * @param sdm The service discovery manager to use. - * @param conn The connection to manage. - */ - public CapsManager(final ServiceDiscoveryManager sdm, final Connection conn) { - mSdm = sdm; - mConnection = conn; - init(); - } - - /** - * Get the discover info associated with a ver attribute. - * - * @param ver the ver attribute. - * @return the discover info or null if it was not cached. - */ - public DiscoverInfo getDiscoverInfo(String ver) { - return mVerCache.get(ver); - } - - /** - * Get the discover info of a contact. - * - * @param jid the jid of the contact. - * @param ver the ver attribute of the contact capability. - * @return The info of the client null if the info was not cached. - */ - public DiscoverInfo getDiscoverInfo(String jid, String ver) { - DiscoverInfo info = mVerCache.get(ver); - if (info == null) { - info = load(ver); - if (info == null) - info = mJidCache.get(jid); - } - return info; - } - - /** - * Set the node attribute to send in your capability. - * This is usually an uri to identify the client. - * - * @param node the node attribute to set. - */ - public void setNode(String node) { - mNode = node; - } - - /** - * Load a persistent DiscoverInfo. - * The default implementation does nothing and always return null. - * - * @param ver the ver hash of the discoverInfo. - * @return The discover info or null if not present. - */ - protected DiscoverInfo load(String ver) { - return null; - } - - /** - * Store a DiscoverInfo for persistence. - * The default implementation does nothing. - * - * @param ver the ver hash of the DiscoverInfo - * @param info the DiscoverInfo to store - */ - protected void store(String ver, DiscoverInfo info) { - } - - /** - * Check if the discover info correspondig to the ver hash is in cache. - * This implementation checks the memory cache. - * If the info is not in cache it is necessary to request it from the network. - * - * @param ver the ver hash - * @return true if it is in cache false otherwise - */ - protected boolean isInCache(String ver) { - return mVerCache.containsKey(ver); - } - - /** - * Initialize this CapsManageer. - */ - private void init() { - initSupportedAlgorithm(); - PacketFilter filter = new PacketExtensionFilter("c", "http://jabber.org/protocol/caps"); - mConnection.addPacketListener(new PacketListener() { - public void processPacket(Packet packet) { - if (packet.getFrom().equals(mConnection.getUser())) - return; - PacketExtension p = packet.getExtension("c", "http://jabber.org/protocol/caps"); - CapsExtension caps = (CapsExtension) p; - if (!isInCache(caps.getVer())) { - validate(packet.getFrom(), caps.getNode(), caps.getVer(), caps.getHash()); - } - } - }, filter); - mConnection.addPacketInterceptor(new PacketInterceptor() { - - public void interceptPacket(Packet packet) { - DiscoverInfo info = getOwnInformation(); - if (mSupportedAlgorithm.size() > 0) { - try { - String algo = mSupportedAlgorithm.get(0); - String ver = calculateVer(info, algo); - CapsExtension caps = new CapsExtension(algo, mNode, ver); - packet.addExtension(caps); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - } - } - }, new PacketTypeFilter(Presence.class)); - } - - /** - * Validate the ver attribute of a received capability. - * - * @param jid the jid of the sender of the capability. - * @param node the node attribute of the capability. - * @param ver the ver attribute of the capability. - * @param hashMethod the hash algorithm to use to calculate ver - * @return true if the ver attribute is valid false otherwise. - */ - private boolean validate(String jid, String node, String ver, String hashMethod) { - try { - DiscoverInfo info = mSdm.discoverInfo(jid, node + "#" + ver); - if (!mSupportedAlgorithm.contains(hashMethod)) { - mJidCache.put(jid, info); - return false; - } - String v = calculateVer(info, hashMethod); - boolean res = v.equals(ver); - if (res) { - mVerCache.put(ver, info); - store(ver, info); - } - return res; - } catch (XMPPException e) { - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - return false; - } - - /** - * Calculate the ver attribute. - * - * @param info The discover info to calculate the ver. - * @param hashMethod the hash algorithm to use. - * @return the value of the ver attribute - * @throws NoSuchAlgorithmException if the hash algorithm is not supported. - */ - private String calculateVer(DiscoverInfo info, String hashMethod) throws NoSuchAlgorithmException { - StringBuilder s = new StringBuilder(); - for (DiscoverInfo.Identity identity : getSortedIdentity(info)) { - String c = identity.getCategory(); - if (c != null) - s.append(c); - s.append('/'); - c = identity.getType(); - if (c != null) - s.append(c); - s.append('/'); - // Should add lang but it is not available -// c = identity.getType(); -// if (c != null) -// S.append(c); - s.append('/'); - c = identity.getName(); - if (c != null) - s.append(c); - s.append('<'); - } - for (String f : getSortedFeature(info)) { - s.append(f); - s.append('<'); - } - // Should add data form (XEP 0128) but it is not available - byte[] hash = getHash(hashMethod, s.toString().getBytes()); - return StringUtils.encodeBase64(hash); - } - - /** - * Get the identities sorted correctly to calculate the ver attribute. - * - * @param info the DiscoverInfo containing the identities - * @return the sorted list of identities. - */ - private List getSortedIdentity(DiscoverInfo info) { - List result = new ArrayList(); - Iterator it = info.getIdentities(); - while (it.hasNext()) { - DiscoverInfo.Identity id = it.next(); - result.add(id); - } - Collections.sort(result, new Comparator() { - public int compare(DiscoverInfo.Identity o1, DiscoverInfo.Identity o2) { - - String cat1 = o1.getCategory(); - if (cat1 == null) cat1 = ""; - String cat2 = o2.getCategory(); - if (cat2 == null) cat2 = ""; - int res = cat1.compareTo(cat2); - if (res != 0) - return res; - String type1 = o1.getType(); - if (type1 == null) type1 = ""; - String type2 = o2.getCategory(); - if (type2 == null) type2 = ""; - res = type1.compareTo(type2); - if (res != 0) - return res; - // should compare lang but not avalaible - return 0; - } - }); - return result; - } - - /** - * Get the features sorted correctly to calculate the ver attribute. - * - * @param info the DiscoverInfo containing the features - * @return the sorted list of features. - */ - private List getSortedFeature(DiscoverInfo info) { - List result = new ArrayList(); - Iterator it = info.getFeatures(); - while (it.hasNext()) { - DiscoverInfo.Feature feat = it.next(); - result.add(feat.getVar()); - } - Collections.sort(result); - return result; - } - - /** - * Get the Discover Information send by your own connection. - * - * @return your own DiscoverInfo - */ - private DiscoverInfo getOwnInformation() { - DiscoverInfo result = new DiscoverInfo(); - DiscoverInfo.Identity id = new DiscoverInfo.Identity("client", ServiceDiscoveryManager.getIdentityName()); - id.setType(ServiceDiscoveryManager.getIdentityType()); - result.addIdentity(id); - Iterator it = mSdm.getFeatures(); - while (it.hasNext()) { - result.addFeature(it.next()); - } - return result; - } - - /** - * Calculate a Hash (digest). - * - * @param algo the algorithm to use - * @param data the data to compute - * @return the resulting hash - * @throws NoSuchAlgorithmException if the algorithm is not supported - */ - private byte[] getHash(String algo, byte[] data) throws NoSuchAlgorithmException { - MessageDigest md = MessageDigest.getInstance(algo); - return md.digest(data); - } - - /** - * Initialize a list of supported Hash algorithm. - */ - private void initSupportedAlgorithm() { - // sort by ""preference" - String[] algo = new String[] {"sha-1", "md2", "md5", "sha-224", "sha-256", "sha-384", "sha-512" }; - for (String a : algo) { - try { - MessageDigest md = MessageDigest.getInstance(a); - mSupportedAlgorithm.add(a); - } catch (NoSuchAlgorithmException e) { - System.err.println("Hash algorithm " + a + " not supported"); - } - } - } - -} diff -r aa8c2dac6d02 -r 4c7edc276676 src/com/beem/project/beem/smack/caps/CapsProvider.java --- a/src/com/beem/project/beem/smack/caps/CapsProvider.java Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - BEEM is a videoconference application on the Android Platform. - - Copyright (C) 2009 by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - This file is part of BEEM. - - BEEM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - BEEM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with BEEM. If not, see . - - Please send bug reports with examples or suggestions to - contact@beem-project.com or http://dev.beem-project.com/ - - Epitech, hereby disclaims all copyright interest in the program "Beem" - written by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - Nicolas Sadirac, November 26, 2009 - President of Epitech. - - Flavien Astraud, November 26, 2009 - Head of the EIP Laboratory. - -*/ -package com.beem.project.beem.smack.caps; - -import org.xmlpull.v1.XmlPullParser; -import org.jivesoftware.smack.provider.PacketExtensionProvider; -import org.jivesoftware.smack.packet.PacketExtension; - -/** - * PacketExtensionProvider for XEP-0115. - * This provider parse c element of namespace - * http://jabber.org/protocol/caps which represents a capability of XEP-0115 - * - */ -public class CapsProvider implements PacketExtensionProvider { - - /** - * Constructor. - */ - public CapsProvider() { } - - @Override - public PacketExtension parseExtension(XmlPullParser parser) { - String ver = parser.getAttributeValue("", "ver"); - String hash = parser.getAttributeValue("", "hash"); - String node = parser.getAttributeValue("", "node"); - String ext = parser.getAttributeValue("", "ext"); - CapsExtension e = new CapsExtension(hash, node, ver); - e.setExt(ext); - return e; - } - -} diff -r aa8c2dac6d02 -r 4c7edc276676 src/com/beem/project/beem/smack/caps/package-info.java --- a/src/com/beem/project/beem/smack/caps/package-info.java Sun Oct 28 14:26:54 2012 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - BEEM is a videoconference application on the Android Platform. - - Copyright (C) 2009 by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - This file is part of BEEM. - - BEEM is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - BEEM is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with BEEM. If not, see . - - Please send bug reports with examples or suggestions to - contact@beem-project.com or http://dev.beem-project.com/ - - Epitech, hereby disclaims all copyright interest in the program "Beem" - written by Frederic-Charles Barthelery, - Jean-Manuel Da Silva, - Nikita Kozlov, - Philippe Lago, - Jean Baptiste Vergely, - Vincent Veronis. - - Nicolas Sadirac, November 26, 2009 - President of Epitech. - - Flavien Astraud, November 26, 2009 - Head of the EIP Laboratory. - -*/ - -/** - * This package contains implementation of XEP-0115. - */ -package com.beem.project.beem.smack.caps;