merge
authorDa Risk <darisk972@gmail.com>
Tue, 26 Oct 2010 00:34:30 +0200
changeset 805 98aab3d53fe3
parent 804 eaecdcf75b02 (diff)
parent 797 fbd3585af53e (current diff)
child 806 64e540927466
merge
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/asmack-beem/beem_patches/10-PubSubManager-non-final.patch	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,13 @@
+Index: org/jivesoftware/smackx/pubsub/PubSubManager.java
+===================================================================
+--- org/jivesoftware/smackx/pubsub/PubSubManager.java	(revision 11464)
++++ org/jivesoftware/smackx/pubsub/PubSubManager.java	(working copy)
+@@ -41,7 +41,7 @@
+  * 
+  * @author Robin Collier
+  */
+-final public class PubSubManager
++public class PubSubManager
+ {
+ 	private XMPPConnection con;
+ 	private String to;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/asmack-beem/beem_patches/50-improved-pubsub.patch	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,46 @@
+--- ../../../src/smack/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java	(révision 11644)
++++ org/jivesoftware/smackx/pubsub/provider/ItemProvider.java	(copie de travail)
+@@ -45,6 +45,8 @@
+ 		}
+ 		else
+ 		{
++		    while (tag != XmlPullParser.START_TAG)
++			tag = parser.next();
+ 			String payloadElemName = parser.getName();
+ 			String payloadNS = parser.getNamespace();
+ 			
+--- ../../../src/org/jivesoftware/smackx/pubsub/Node.java	(révision 11644)
++++ org/jivesoftware/smackx/pubsub/Node.java	(copie de travail)
+@@ -60,7 +60,7 @@
+ 	 * 
+ 	 *   For example, OpenFire requires the server to be prefixed by <b>pubsub</b>
+ 	 */
+-	void setTo(String toAddress)
++	public void setTo(String toAddress)
+ 	{
+ 		to = toAddress;
+ 	}
+--- ../../../src/org/jivesoftware/smackx/pubsub/LeafNode.java	(révision 11644)
++++ org/jivesoftware/smackx/pubsub/LeafNode.java	(copie de travail)
+@@ -34,7 +34,7 @@
+  */
+ public class LeafNode extends Node
+ {
+-	LeafNode(Connection connection, String nodeName)
++	public LeafNode(Connection connection, String nodeName)
+ 	{
+ 		super(connection, nodeName);
+ 	}
+--- ../../../src/org/jivesoftware/smackx/pubsub/PubSubManager.java	(révision 11644)
++++ org/jivesoftware/smackx/pubsub/PubSubManager.java	(copie de travail)
+@@ -43,8 +43,8 @@
+  */
+ final public class PubSubManager
+ {
+-	private Connection con;
+-	private String to;
++	protected Connection con;
++	protected String to;
+ 	private Map<String, Node> nodeMap = new ConcurrentHashMap<String, Node>();
+ 	
+ 	/**
Binary file libs/asmack-android-7-beem.jar has changed
--- a/src/com/beem/project/beem/BeemService.java	Thu Aug 26 09:58:50 2010 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Tue Oct 26 00:34:30 2010 +0200
@@ -57,6 +57,11 @@
 import org.jivesoftware.smack.proxy.ProxyInfo;
 import org.jivesoftware.smack.proxy.ProxyInfo.ProxyType;
 import org.jivesoftware.smack.util.StringUtils;
+import org.jivesoftware.smackx.pubsub.provider.PubSubProvider;
+import org.jivesoftware.smackx.pubsub.provider.ItemsProvider;
+import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
+import org.jivesoftware.smackx.pubsub.provider.EventProvider;
+import org.jivesoftware.smackx.provider.PEPProvider;
 
 import android.app.Notification;
 import android.app.NotificationManager;
@@ -80,6 +85,8 @@
 import com.beem.project.beem.utils.BeemBroadcastReceiver;
 import com.beem.project.beem.utils.BeemConnectivity;
 import com.beem.project.beem.utils.Status;
+import com.beem.project.beem.smack.avatar.AvatarMetadataProvider;
+import com.beem.project.beem.smack.avatar.AvatarProvider;
 import com.beem.project.beem.smack.caps.CapsProvider;
 
 /**
@@ -148,7 +155,7 @@
 	    || mSettings.getBoolean("settings_key_gmail", false)) {
 	    mConnectionConfiguration.setSecurityMode(SecurityMode.required);
 	}
-	mConnectionConfiguration.setDebuggerEnabled(false);
+	mConnectionConfiguration.setDebuggerEnabled(true);
 	mConnectionConfiguration.setSendPresence(true);
 	// maybe not the universal path, but it works on most devices (Samsung Galaxy, Google Nexus One)
 	mConnectionConfiguration.setTruststoreType("BKS");
@@ -317,6 +324,12 @@
      * @param pm The ProviderManager.
      */
     private void configure(ProviderManager pm) {
+	Log.d(TAG, "configure");
+	// 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());
+
 	// Privacy
 	pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());
 	// Delayed Delivery only the new version
@@ -335,7 +348,29 @@
 	pm.addExtensionProvider("paused", "http://jabber.org/protocol/chatstates", chatState);
 	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());
+	//Pubsub
+	pm.addIQProvider("pubsub", "http://jabber.org/protocol/pubsub", new PubSubProvider());
+	pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider());
+	pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub", new ItemsProvider());
+	pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub", new ItemProvider());
+
+	pm.addExtensionProvider("items", "http://jabber.org/protocol/pubsub#event", new ItemsProvider());
+	pm.addExtensionProvider("item", "http://jabber.org/protocol/pubsub#event", new ItemProvider());
+	pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", new EventProvider());
+	//TODO rajouter les manquants pour du full pubsub
+
+
+	//PEP avatar
+	pm.addExtensionProvider("metadata", "urn:xmpp:avatar:metadata", new AvatarMetadataProvider());
+	pm.addExtensionProvider("data", "urn:xmpp:avatar:data", new AvatarProvider());
+
+//         PEPProvider pep  = new PEPProvider();
+//         AvatarMetadataProvider avaMeta  = new AvatarMetadataProvider();
+//         pep.registerPEPParserExtension("urn:xmpp:avatar:metadata", avaMeta);
+//         pm.addExtensionProvider("event", "http://jabber.org/protocol/pubsub#event", pep);
+
 	/*
 	// Private Data Storage
 	pm.addIQProvider("query", "jabber:iq:private", new PrivateDataManager.PrivateDataIQProvider());
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Thu Aug 26 09:58:50 2010 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Tue Oct 26 00:34:30 2010 +0200
@@ -55,6 +55,8 @@
 import org.jivesoftware.smack.packet.Presence;
 import org.jivesoftware.smackx.ChatStateManager;
 import org.jivesoftware.smackx.ServiceDiscoveryManager;
+import org.jivesoftware.smackx.packet.DiscoverInfo;
+import org.jivesoftware.smackx.pubsub.PayloadItem;
 
 import android.app.Notification;
 import android.app.PendingIntent;
@@ -63,8 +65,12 @@
 import android.content.SharedPreferences;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
+import android.os.Environment;
 import android.util.Log;
 
+import java.util.Iterator;
+import java.io.File;
+
 import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
 import com.beem.project.beem.BeemApplication;
@@ -76,6 +82,10 @@
 import com.beem.project.beem.ui.Subscription;
 import com.beem.project.beem.utils.BeemBroadcastReceiver;
 import com.beem.project.beem.utils.Status;
+import com.beem.project.beem.smack.avatar.AvatarMetadataExtension;
+import com.beem.project.beem.smack.avatar.AvatarCache;
+import com.beem.project.beem.smack.avatar.FileAvatarCache;
+import com.beem.project.beem.smack.avatar.AvatarManager;
 
 /**
  * This class implements an adapter for XMPPConnection.
@@ -229,6 +239,7 @@
 	    mPrivacyListManager = new PrivacyListManagerAdapter(PrivacyListManager.getInstanceFor(mAdaptee));
 	    mService.resetStatus();
 	    mService.initJingle(mAdaptee);
+	    discoverServerFeatures();
 
 	    mApplication.setConnected(true);
 	    changeStatus(Status.CONTACT_STATUS_AVAILABLE, mService.getServicePreference().getString("status_text", ""));
@@ -240,6 +251,17 @@
 	}
     }
 
+    private void testPEP() {
+	Log.d(TAG, "TEST PEP activate");
+	AvatarMetadataExtension meta = new AvatarMetadataExtension();
+	AvatarMetadataExtension.Info info = new AvatarMetadataExtension.Info("test", "image/png", 5);
+	info.setUrl("http://elyzion.net/img.png");
+	meta.addInfo(info);
+	PayloadItem<AvatarMetadataExtension> item = new PayloadItem<AvatarMetadataExtension>("test", meta);
+	//         pmgr.publish(item, "urn:xmpp:avatar:data");
+	Log.d(TAG, "END TEST PEP ");
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -383,22 +405,6 @@
 	return mRoster;
     }
 
-    /**
-     * enregistre les features dispo dans notre version Liste de features que Telepathy supporte.
-     */
-    private void initFeatures() {
-	ServiceDiscoveryManager.setIdentityName("Beem");
-	ServiceDiscoveryManager.setIdentityType("phone");
-	ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
-	if (sdm == null)
-	    sdm = new ServiceDiscoveryManager(mAdaptee);
-	sdm.addFeature("http://jabber.org/protocol/disco#info");
-	sdm.addFeature("jabber:iq:privacy");
-	sdm.addFeature("http://jabber.org/protocol/caps");
-	mChatStateManager = ChatStateManager.getInstance(mAdaptee);
-	BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService);
-	caps.setNode("http://www.beem-project.com");
-    }
 
     /**
      * Returns true if currently authenticated by successfully calling the login method.
@@ -442,6 +448,64 @@
     }
 
     /**
+     * Initialize the features provided by beem.
+     */
+    private void initFeatures() {
+	ServiceDiscoveryManager.setIdentityName("Beem");
+	ServiceDiscoveryManager.setIdentityType("phone");
+	ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
+	if (sdm == null)
+	    sdm = new ServiceDiscoveryManager(mAdaptee);
+
+	sdm.addFeature("http://jabber.org/protocol/disco#info");
+	sdm.addFeature("jabber:iq:privacy");
+	sdm.addFeature("http://jabber.org/protocol/caps");
+	sdm.addFeature("urn:xmpp:avatar:metadata");
+	sdm.addFeature("urn:xmpp:avatar:metadata+notify");
+	sdm.addFeature("urn:xmpp:avatar:data");
+	sdm.addFeature("http://jabber.org/protocol/nick");
+	sdm.addFeature("http://jabber.org/protocol/nick+notify");
+
+	mChatStateManager = ChatStateManager.getInstance(mAdaptee);
+	BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService);
+	caps.setNode("http://www.beem-project.com");
+    }
+
+    /**
+     * Discover the features provided by the server.
+     */
+    private void discoverServerFeatures() {
+	try {
+	    // jid et server
+	    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
+	    DiscoverInfo info = sdm.discoverInfo("elyzion.net");
+	    Iterator<DiscoverInfo.Identity> it = info.getIdentities();
+	    while (it.hasNext()) {
+		DiscoverInfo.Identity identity = it.next();
+		if ("pubsub".equals(identity.getCategory()) && "pep".equals(identity.getType())) {
+		    initPEP();
+		}
+	    }
+	} catch (XMPPException e) {
+	    // No Pep
+	}
+    }
+
+    /**
+     * Initialize PEP.
+     */
+    private void initPEP() {
+	// Enable pep sending
+	// API 8
+	// mService.getExternalCacheDir()
+	File cacheDir = Environment.getExternalStorageDirectory();
+	cacheDir = new File(cacheDir, "/Android/data/com.beem.project.beem/cache/");
+	AvatarCache avatarCache = new FileAvatarCache(cacheDir);
+	new AvatarManager(mAdaptee, avatarCache, true);
+	testPEP();
+    }
+
+    /**
      * Listener for XMPP connection events. It will calls the remote listeners for connection events.
      * @author darisk
      */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/AvatarCache.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,90 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Interface for an AvatarCache.
+ * This can be improved to a generic cache.
+ *
+ */
+public interface AvatarCache {
+
+    /**
+     * Put some datas in cache.
+     *
+     * @param id the key id of the data
+     * @param data the datato cache
+     * @throws IOException if an IO error occurs while caching the data
+     */
+    void put(String id, byte[] data) throws IOException;
+
+    /**
+     * Put some datas in cache.
+     *
+     * @param id the key id of the data
+     * @param data an InputStream to the data to cache
+     * @throws IOException if an IO error occurs while caching the data
+     */
+    void put(String id, InputStream data) throws IOException;
+
+    /**
+     * Get some data from the cache.
+     *
+     * @param id the id of the data to get
+     * @return the cached data
+     * @throws IOException  if an IO error occurs while geting the data
+     */
+    byte[] get(String id) throws IOException;
+
+    /**
+     * Test if a data is in cache.
+     *
+     * @param id the id of the data
+     * @return true if data is in cache false otherwise
+     */
+    boolean contains(String id);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/AvatarExtension.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,109 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import org.jivesoftware.smack.util.Base64;
+import org.jivesoftware.smack.packet.PacketExtension;
+
+/**
+ * PacketExtension to represent the Avatar data.
+ * XML namespace urn:xmpp:avatar:data
+ *
+ */
+public class AvatarExtension implements PacketExtension {
+
+    private String mData;
+
+    /**
+     * Create an AvatarExtension.
+     */
+    public AvatarExtension(final String base64) {
+	mData = base64;
+    }
+
+    /**
+     * Create an AvatarExtension.
+     */
+    public AvatarExtension(final byte[] data) {
+	mData = Base64.encodeBytes(data);
+    }
+
+    /**
+     * Get the avatar data as a Base64 string.
+     *
+     * @return a base64 string.
+     */
+    public String getBase64() {
+	return mData;
+    }
+
+    /**
+     * Get the avatar data.
+     *
+     * @return the decoded data
+     */
+    public byte[] getData() {
+	return Base64.decode(mData);
+    }
+
+    @Override
+    public String getElementName() {
+	return "data";
+    }
+
+    @Override
+    public String getNamespace() {
+	return "urn:xmpp:avatar:data";
+    }
+
+    @Override
+    public String toXML() {
+	StringBuilder builder = new StringBuilder("<data xmlns=\"");
+	builder.append(getNamespace()).append("\">");
+	builder.append(mData);
+	builder.append("</data>");
+	return builder.toString();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/AvatarManager.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,161 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import android.util.Log;
+
+import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info;
+import com.beem.project.beem.smack.pep.PEPListener;
+import com.beem.project.beem.smack.pep.PepSubManager;
+
+import java.io.IOException;
+
+import java.util.List;
+
+import org.jivesoftware.smack.Connection;
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smackx.pubsub.Item;
+import org.jivesoftware.smackx.pubsub.PayloadItem;
+
+/**
+ * This class deals with the avatar data.
+ * It can be configured to auto retrieve the avatar and put it in cache.
+ *
+ */
+public class AvatarManager {
+
+    private PepSubManager mPep;
+    private Connection mCon;
+    private boolean mAutoDownload;
+    private AvatarCache mCache;
+
+    /**
+     * Create an AvatarManager.
+     *
+     * @param con the connection
+     * @param cache the cache which will store the avatars
+     * @param autoDownload true to enable auto download of avatars
+     */
+    public AvatarManager(final Connection con, final AvatarCache cache, final boolean autoDownload) {
+	Log.d("AvatarMgr", "creation");
+	mCon = con;
+	mPep = new PepSubManager(mCon);
+	mAutoDownload = autoDownload;
+	mCache = cache;
+	if (mAutoDownload)
+	    mPep.addPEPListener(new Listener());
+    }
+
+    /**
+     * Get an avatar from the cache.
+     *
+     * @param avatarId the id of the avatar
+     * @return the avatar or null if it cannot be retrieved from the cache
+     */
+    public byte[] getAvatar(String avatarId) {
+	try {
+	    return mCache.get(avatarId);
+	} catch (IOException e) {
+	    return null;
+	}
+    }
+
+    /**
+     * Select the avatar to download.
+     * Subclass should override this method to take control over the selection process.
+     * This implementation select the first element.
+     *
+     * @param available list of the avatar metadata information
+     * @return the metadata of the avatar to download
+     */
+    protected Info selectAvatar(List<Info> available) {
+	return available.get(0);
+    }
+
+    /**
+     * Doawload an avatar.
+     *
+     * @param from The jid of the user
+     * @param info the metadata information of the avatar to download
+     */
+    private void downloadAvatar(String from, Info info) {
+	try {
+	    AvatarRetriever retriever = AvatarRetrieverFactory.getRetriever(mCon, from, info);
+	    byte[] avatar = retriever.getAvatar();
+	// TODO check the hash before store
+	    mCache.put(info.getId(), avatar);
+	} catch (IOException e) {
+	    Log.d("AvatarMgr", "Error while downloading avatar", e);
+	}
+    }
+
+    /**
+     * A listener to PEPEevent.
+     */
+    private class Listener implements PEPListener {
+
+	/**
+	 * Create a listener.
+	 */
+	public Listener() {
+	}
+
+	@Override
+	public void eventReceived(String from, String node, List<Item> items) {
+	    Log.d("AvatarMgr", "Received pep event ");
+	    Item i = items.get(0);
+	    if (i instanceof PayloadItem) {
+		PayloadItem<PacketExtension> pi = (PayloadItem<PacketExtension>) i;
+		PacketExtension ex = pi.getPayload();
+		if (ex instanceof AvatarMetadataExtension) {
+		    Log.d("AvatarMgr", "Received avatar meta");
+		    AvatarMetadataExtension ext = (AvatarMetadataExtension) ex;
+		    Info info = selectAvatar(ext.getInfos());
+		    if (!mCache.contains(info.getId()))
+			downloadAvatar(from, info);
+		}
+	    }
+	}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/AvatarMetadataExtension.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,257 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+
+/**
+ * PacketExtension to represent the Avatar metadata.
+ * XML namespace urn:xmpp:avatar:metadata
+ *
+ */
+public class AvatarMetadataExtension implements PacketExtension {
+    private List<Info> mInfos = new LinkedList<Info>();
+
+    /**
+     * Create an AvatarMetadataExtension.
+     */
+    public AvatarMetadataExtension() {
+    }
+
+    /**
+     * Get the metadata informations.
+     *
+     * @return a list of informations
+     */
+    public List<Info> getInfos() {
+	return mInfos;
+    }
+
+    /**
+     * Add a metadate information.
+     *
+     * @param info the metadata information to add
+     */
+    public void addInfo(Info info) {
+	mInfos.add(info);
+    }
+
+    @Override
+    public String getElementName() {
+	return "metadata";
+    }
+
+    @Override
+    public String getNamespace() {
+	return "urn:xmpp:avatar:metadata";
+    }
+
+    @Override
+    public String toXML() {
+	StringBuilder builder = new StringBuilder("<metadata xmlns=\"");
+	builder.append(getNamespace()).append("\">");
+	for (Info info : mInfos) {
+	    builder.append(info.toXML());
+	}
+	builder.append("</metadata>");
+	return builder.toString();
+    }
+
+    /**
+     * A metadata information element.
+     */
+    public static class Info {
+	private int mBytes;
+	private int mHeight;
+	private int mWidth;
+	private String mId;
+	private String mType;
+	private String mUrl;
+
+	/**
+	 * Create an Info.
+	 *
+	 * @param id the id of the info
+	 * @param type the MIME type of the avatar
+	 * @param bytes the size of the avatar in bytes
+	 */
+	public Info(final String id, final String type, final int bytes) {
+	    mId = id;
+	    mType = type;
+	    mBytes = bytes;
+	}
+
+	/**
+	 * Set the size of the avatar in bytes.
+	 *
+	 * @param bytes the size
+	 */
+	public void setBytes(int bytes) {
+	    this.mBytes = bytes;
+	}
+
+	/**
+	 * Set the size of the avatar in bytes.
+	 *
+	 * @return the size
+	 */
+	public int getBytes() {
+	    return mBytes;
+	}
+
+	/**
+	 * Set the height.
+	 *
+	 * @param height the height
+	 */
+	public void setHeight(int height) {
+	    this.mHeight = height;
+	}
+
+	/**
+	 * Get the height.
+	 *
+	 * @return the height
+	 */
+	public int getHeight() {
+	    return mHeight;
+	}
+
+	/**
+	 * Set the width.
+	 *
+	 * @param width the width
+	 */
+	public void setWidth(int width) {
+	    this.mWidth = width;
+	}
+
+	/**
+	 * Get the width.
+	 *
+	 * @return the width
+	 */
+	public int getWidth() {
+	    return mWidth;
+	}
+
+	/**
+	 * Set the url.
+	 *
+	 * @param url the url
+	 */
+	public void setUrl(String url) {
+	    this.mUrl = url;
+	}
+
+	/**
+	 * Get the url.
+	 *
+	 * @return the url, null if no url is present
+	 */
+	public String getUrl() {
+	    return mUrl;
+	}
+
+	/**
+	 * Get the id.
+	 *
+	 * @return the id
+	 */
+	public String getId() {
+	    return mId;
+	}
+
+	/**
+	 * Set the id.
+	 *
+	 * @param id the id
+	 */
+	public void setId(String id) {
+	    this.mId = id;
+	}
+
+	/**
+	 * Set the MIME type of the avatar.
+	 *
+	 * @param type the type
+	 */
+	public void setType(String type) {
+	    this.mType = type;
+	}
+
+	/**
+	 * Get the MIME type of the avatar.
+	 *
+	 * @return the type, null if no type is present
+	 */
+	public String getType() {
+	    return mType;
+	}
+
+	/**
+	 * Return this information as an xml element.
+	 *
+	 * @return an xml element representing this information
+	 */
+	public String toXML() {
+	    StringBuilder builder = new StringBuilder("<info ");
+	    builder.append("id=\"" + mId + "\"");
+	    builder.append(" type=\"" + mType + "\"");
+	    builder.append(" bytes=\"" + mBytes + "\"");
+
+	    if (mHeight > 0)
+		builder.append(" height=\"" + mHeight + "\"");
+	    if (mWidth > 0)
+		builder.append(" width=\"" + mWidth + "\"");
+	    if (mUrl != null)
+		builder.append(" url=\"" + mUrl + "\"");
+	    builder.append(" />");
+	    return builder.toString();
+	}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/AvatarMetadataProvider.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,93 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * A PacketExtensionProvider to parse the Avatar metadata.
+ * XML namespace urn:xmpp:avatar:metadata
+ */
+public class AvatarMetadataProvider implements PacketExtensionProvider {
+
+    /**
+     * Creates a new AvatarMetadataProvider.
+     * ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
+     */
+    public AvatarMetadataProvider() {
+    }
+
+    @Override
+    public PacketExtension parseExtension(XmlPullParser parser)
+	throws Exception {
+	AvatarMetadataExtension metadata = new AvatarMetadataExtension();
+	boolean done = false;
+	StringBuilder buffer = new StringBuilder();
+	while (!done) {
+	    int eventType = parser.next();
+	    if (eventType == XmlPullParser.START_TAG) {
+		if ("info".equals(parser.getName())) {
+		    int bytes = Integer.parseInt(parser.getAttributeValue(null, "bytes"));
+		    int height = Integer.parseInt(parser.getAttributeValue(null, "height"));
+		    int width = Integer.parseInt(parser.getAttributeValue(null, "width"));
+		    String id = parser.getAttributeValue(null, "id");
+		    String type = parser.getAttributeValue(null, "type");
+		    String url = parser.getAttributeValue(null, "url");
+		    AvatarMetadataExtension.Info info = new AvatarMetadataExtension.Info(id, type, bytes);
+		    info.setHeight(height);
+		    info.setWidth(width);
+		    info.setUrl(url);
+		    metadata.addInfo(info);
+		}
+	    } else if (eventType == XmlPullParser.END_TAG) {
+		if (parser.getName().equals(metadata.getElementName())) {
+		    done = true;
+		}
+	    }
+	}
+	return metadata;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/AvatarProvider.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,82 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * A PacketExtensionProvider to parse the Avatar data.
+ * XML namespace urn:xmpp:avatar:data
+ */
+public class AvatarProvider implements PacketExtensionProvider {
+
+    /**
+     * Creates a new AvatarProvider.
+     * ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
+     */
+    public AvatarProvider() {
+    }
+
+    @Override
+    public PacketExtension parseExtension(XmlPullParser parser)
+	throws Exception {
+	AvatarMetadataExtension metadata = new AvatarMetadataExtension();
+	boolean done = false;
+	StringBuilder buffer = new StringBuilder();
+	while (!done) {
+	    int eventType = parser.getEventType();
+	    if (eventType == XmlPullParser.START_TAG) {
+		if ("data".equals(parser.getName())) {
+		    String data = parser.nextText();
+		    AvatarExtension avatar = new AvatarExtension(data);
+		    return avatar;
+		}
+	    }
+	    parser.next();
+	}
+	return null;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/AvatarRetriever.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,60 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import java.io.IOException;
+
+/**
+ * Interface for an AvatarRetriever.
+ */
+public interface AvatarRetriever {
+
+    /**
+     * Retrieve the avatar.
+     *
+     * @return the avatar
+     * @throws IOException if an IO error occurs while retrieving the avatar
+     */
+    byte[] getAvatar() throws IOException;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/AvatarRetrieverFactory.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,80 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import com.beem.project.beem.smack.avatar.AvatarMetadataExtension.Info;
+import org.jivesoftware.smack.Connection;
+// API level 8
+//import android.net.http.AndroidHttpClient;
+import org.apache.http.client.HttpClient;
+
+/**
+ * A factory for AvatarRetriever.
+ */
+public final class AvatarRetrieverFactory {
+
+    /**
+     * Private constructor.
+     */
+    private AvatarRetrieverFactory() {
+    }
+
+    /**
+     * Get a AvatarRetriever to retrieve this avatar.
+     *
+     * @param con the connection
+     * @param from the user which own the avatar
+     * @param info the metadata information of the avatar to retrieve
+     * @return an AvatarRetriever null if none can retrieve this avatar
+     */
+    public static AvatarRetriever getRetriever(Connection con, String from, Info info) {
+	String url = info.getUrl();
+	if (url != null) {
+	    // return new HttpAvatarRetriever(url);
+	    // HttpClient client = AndroidHttpClient.newInstance("Beem");
+	    return new HttpClientAvatarRetriever(url);
+	}
+	return new XmppAvatarRetriever(con, from, info.getId());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/FileAvatarCache.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,121 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * An implementation of an AvatarCache which store the data of the filesystem.
+ */
+public class FileAvatarCache implements AvatarCache {
+
+    private File mStoreDir;
+
+    /**
+     * Create a FileAvatarCache.
+     *
+     * @param storedir The directory used to store the data.
+     */
+    public FileAvatarCache(final File storedir) {
+	if (storedir.exists() && !storedir.isDirectory())
+	    throw new IllegalArgumentException("The store directory must be a directory");
+	mStoreDir = storedir;
+	mStoreDir.mkdirs();
+    }
+
+    @Override
+    public void put(String key, byte[] data) throws IOException {
+	File f = new File(mStoreDir, key);
+	OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
+	try {
+	    os.write(data);
+	} finally {
+	    os.close();
+	}
+    }
+
+    @Override
+    public void put(String key, InputStream in) throws IOException {
+	File f = new File(mStoreDir, key);
+	OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
+	try {
+	    byte[] data = new byte[1024];
+	    int nbread;
+	    while ((nbread = in.read(data)) != -1)
+		    os.write(data, 0, nbread);
+	} finally {
+	    in.close();
+	    os.close();
+	}
+    }
+
+    @Override
+    public byte[] get(String key) throws IOException {
+	File f = new File(mStoreDir, key);
+	InputStream is = new BufferedInputStream(new FileInputStream(f));
+	ByteArrayOutputStream bos = new ByteArrayOutputStream();
+	try {
+	    byte[] data = new byte[1024];
+	    is.read(data);
+	    bos.write(data);
+	} finally {
+	    is.close();
+	}
+	return bos.toByteArray();
+    }
+
+    @Override
+    public boolean contains(String key) {
+	File f = new File(mStoreDir, key);
+	return f.exists();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/HttpAvatarRetriever.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,96 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * An AvatarRetriever which retrieve the avatar over HTTP.
+ */
+public  class HttpAvatarRetriever implements AvatarRetriever {
+
+    private URL mUrl;
+    private String mUrlString;
+
+    /**
+     * Create a HttpAvatarRetriever.
+     *
+     * @param url the url of the avatar to download.
+     */
+    public HttpAvatarRetriever(final URL url) {
+	mUrl = url;
+    }
+
+    /**
+     * Create a HttpAvatarRetriever.
+     *
+     * @param url the url of the avatar to download.
+     */
+    public HttpAvatarRetriever(final String url) {
+	mUrlString = url;
+    }
+
+    @Override
+    public byte[] getAvatar() throws IOException {
+	if (mUrl == null)
+	    mUrl = new URL(mUrlString);
+	InputStream in = mUrl.openStream();
+	ByteArrayOutputStream os = new ByteArrayOutputStream();
+	try {
+	    byte[] data = new byte[1024];
+	    int nbread;
+	    while ((nbread = in.read(data)) != -1) {
+		os.write(data, 0, nbread);
+	    }
+	} finally {
+	    in.close();
+	    os.close();
+	}
+	return os.toByteArray();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/HttpClientAvatarRetriever.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,113 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import java.io.InputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpEntity;
+
+/**
+ * An AvatarRetriever which retrieve the avatar over HTTP using the Apache HttpClient.
+ */
+public  class HttpClientAvatarRetriever implements AvatarRetriever {
+
+    private String mUrl;
+    private HttpClient mClient;
+
+    /**
+     * Create a HttpAvatarRetriever.
+     *
+     * @param client the custom HttpClient to use to downlowad
+     * @param url the url of the avatar to download.
+     */
+    public HttpClientAvatarRetriever(final HttpClient client, final String url) {
+	mUrl = url;
+	mClient = client;
+    }
+
+    /**
+     * Create a HttpAvatarRetriever.
+     *
+     * @param url the url of the avatar to download.
+     */
+    public HttpClientAvatarRetriever(final String url) {
+	mUrl= url;
+	mClient = new DefaultHttpClient();
+    }
+
+    @Override
+    public byte[] getAvatar() throws IOException {
+	HttpUriRequest request;
+	try {
+	    request = new HttpGet(mUrl);
+	} catch(IllegalArgumentException e) {
+	    IOException ioe = new IOException("Invalid url " +mUrl);
+	    ioe.initCause(e);
+	    throw ioe;
+	}
+	HttpResponse response = mClient.execute(request);
+	HttpEntity entity = response.getEntity();
+	InputStream in = entity.getContent();
+	ByteArrayOutputStream os = new ByteArrayOutputStream();
+	try {
+	    byte[] data = new byte[1024];
+	    int nbread;
+	    while ((nbread = in.read(data)) != -1) {
+		os.write(data, 0, nbread);
+	    }
+	} finally {
+	    in.close();
+	    os.close();
+	}
+	return os.toByteArray();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/XmppAvatarRetriever.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,85 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.avatar;
+
+import java.util.List;
+import java.util.Arrays;
+import org.jivesoftware.smack.Connection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smackx.pubsub.LeafNode;
+import org.jivesoftware.smackx.pubsub.Item;
+import org.jivesoftware.smackx.pubsub.PayloadItem;
+
+import com.beem.project.beem.smack.pep.PepSubManager;
+
+/**
+ * An AvatarRetriever which retrieve the avatar over the XMPP connection.
+ */
+public class XmppAvatarRetriever implements AvatarRetriever {
+
+    private static String AVATARDATANODE = "urn:xmpp:avatar:data";
+    private PepSubManager mPubsub;
+    private String mFrom;
+    private String mId;
+
+    public XmppAvatarRetriever(final Connection con, final String from, final String id) {
+	mPubsub = new PepSubManager(con, from);
+	mFrom = from;
+	mId = id;
+    }
+
+    @Override
+    public byte[] getAvatar() {
+	try {
+	    LeafNode node = mPubsub.getPEPNode(AVATARDATANODE);
+	    List<Item> items = node.getItems(Arrays.asList(mId));
+	    PayloadItem<AvatarExtension> item = (PayloadItem<AvatarExtension>) items.get(0);
+	    AvatarExtension avatar = item.getPayload();
+	    return avatar.getData();
+	} catch (XMPPException e) {
+	    return null;
+	}
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/avatar/package-info.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,48 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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-0084 User Avatar.
+ */
+package com.beem.project.beem.smack.avatar;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/pep/PEPListener.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,63 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.pep;
+
+import org.jivesoftware.smackx.pubsub.Item;
+import java.util.List;
+
+/**
+ * A listener that is fired anytime a PEP event message is received.
+ */
+public interface PEPListener {
+
+    /**
+     *  Called when PEP events are received.
+     *
+     * @param from the JID of the user who send the event
+     * @param node the node of the items in the event
+     * @param items the different items of the event
+     */
+    void eventReceived(String from, String node, List<Item> items);
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/pep/PepSubManager.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,151 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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.pep;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jivesoftware.smack.Connection;
+import org.jivesoftware.smack.filter.PacketExtensionFilter;
+import org.jivesoftware.smack.filter.PacketFilter;
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smackx.pubsub.EventElement;
+import org.jivesoftware.smackx.pubsub.EventElementType;
+import org.jivesoftware.smackx.pubsub.Item;
+import org.jivesoftware.smackx.pubsub.ItemsExtension;
+import org.jivesoftware.smackx.pubsub.PubSubManager;
+import org.jivesoftware.smackx.pubsub.LeafNode;
+
+/**
+ * Little extension of {@link PubSubManager} which allows to add {@link PEPListener}.
+ *
+ */
+public class PepSubManager extends PubSubManager {
+    private List<PEPListener> mPepListeners = new ArrayList<PEPListener>();
+    private PacketFilter mPacketFilter = new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event");
+
+    /**
+     * Create a PepSubManager.
+     *
+     * @param connection the connection
+     */
+    public PepSubManager(final Connection connection) {
+	super(connection);
+	init(connection);
+    }
+
+    /**
+     * Create a PepSubManager associated to the specified connection where the pubsub
+     * requests require a specific to address for packets.
+     *
+     * @param connection the connection
+     * @param toAddress The pubsub specific to address (required for some servers)
+     */
+    public PepSubManager(final Connection connection, final String toAddress) {
+	super(connection, toAddress);
+	init(connection);
+    }
+
+    /**
+     * Add a listener to PEP event.
+     *
+     * @param listener the listener
+     */
+    public void addPEPListener(PEPListener listener) {
+	if (!mPepListeners.contains(listener))
+	    mPepListeners.add(listener);
+    }
+
+    /**
+     * Remove a listener to PEP event.
+     *
+     * @param listener the listener
+     */
+    public void removePEPListener(PEPListener listener) {
+	mPepListeners.remove(listener);
+    }
+
+    public LeafNode getPEPNode(String nodeName) {
+	LeafNode node = new LeafNode(con, nodeName);
+	node.setTo(to);
+	return node;
+    }
+
+    /**
+     * Initialize the PepSubManager.
+     *
+     * @param con the connection
+     */
+    private void init(Connection con) {
+	PacketListener packetListener = new PacketListener() {
+
+	    @Override
+	    public void processPacket(Packet packet) {
+		EventElement e = (EventElement) packet.getExtension("event", "http://jabber.org/protocol/pubsub#event");
+		if (e.getEventType() != EventElementType.items)
+		    return;
+		ItemsExtension it = (ItemsExtension) e.getEvent();
+		if (it.getItemsElementType() != ItemsExtension.ItemsElementType.items)
+		    return;
+		List<Item> items = (List<Item>) it.getItems();
+		firePEPListeners(packet.getFrom(), it.getNode(), items);
+	    }
+	};
+	con.addPacketListener(packetListener, mPacketFilter);
+    }
+
+    /**
+     * Fire the PEP listeners.
+     *
+     * @param from the JID of the user who send the event
+     * @param node the node of the items in the event
+     * @param items the different items of the event
+     */
+    private void firePEPListeners(String from, String node, List<Item> items) {
+	for (PEPListener listener : mPepListeners) {
+	    listener.eventReceived(from, node, items);
+	}
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/smack/pep/package-info.java	Tue Oct 26 00:34:30 2010 +0200
@@ -0,0 +1,49 @@
+/*
+    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 <http://www.gnu.org/licenses/>.
+
+    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 an implementation of XEP-0163 Personnal Eventing Protocol based on the pubsub implementation.
+ */
+package com.beem.project.beem.smack.pep;
+