1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 22:32:06 +01:00

Merge branch smack_3_3_2 and trunk

as the state of the both branches of Smack's SVN repository
http://fisheye.igniterealtime.org/browse/smack on 2013-12-30.

Conflicts:
	documentation/extensions/caps.html
	source/org/jivesoftware/smack/PacketReader.java
	source/org/jivesoftware/smack/SmackConfiguration.java
	source/org/jivesoftware/smack/parsing/ParsingExceptionCallback.java
	source/org/jivesoftware/smackx/ServiceDiscoveryManager.java
This commit is contained in:
Florian Schmaus 2013-12-30 01:29:55 +01:00
commit f8274dda53
8 changed files with 130 additions and 94 deletions

View file

@ -28,8 +28,8 @@ import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback; import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.xmlpull.mxp1.MXParser; import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -123,6 +123,9 @@ public final class SmackConfiguration {
else if (parser.getName().equals("autoEnableEntityCaps")) { else if (parser.getName().equals("autoEnableEntityCaps")) {
autoEnableEntityCaps = Boolean.parseBoolean(parser.nextText()); autoEnableEntityCaps = Boolean.parseBoolean(parser.nextText());
} }
else if (parser.getName().equals("autoEnableEntityCaps")) {
autoEnableEntityCaps = Boolean.parseBoolean(parser.nextText());
}
} }
eventType = parser.next(); eventType = parser.next();
} }
@ -319,14 +322,6 @@ public final class SmackConfiguration {
SmackConfiguration.localSocks5ProxyPort = localSocks5ProxyPort; SmackConfiguration.localSocks5ProxyPort = localSocks5ProxyPort;
} }
/**
* Check if Entity Caps are enabled as default for every new connection
* @return
*/
public static boolean autoEnableEntityCaps() {
return autoEnableEntityCaps;
}
/** /**
* Set if Entity Caps are enabled or disabled for every new connection * Set if Entity Caps are enabled or disabled for every new connection
* *
@ -336,6 +331,14 @@ public final class SmackConfiguration {
autoEnableEntityCaps = b; autoEnableEntityCaps = b;
} }
/**
* Check if Entity Caps are enabled as default for every new connection
* @return
*/
public static boolean autoEnableEntityCaps() {
return autoEnableEntityCaps;
}
/** /**
* Set the default parsing exception callback for all newly created connections * Set the default parsing exception callback for all newly created connections
* *

View file

@ -54,8 +54,11 @@ public class ServiceDiscoveryManager {
private static final String DEFAULT_IDENTITY_NAME = "Smack"; private static final String DEFAULT_IDENTITY_NAME = "Smack";
private static final String DEFAULT_IDENTITY_CATEGORY = "client"; private static final String DEFAULT_IDENTITY_CATEGORY = "client";
private static final String DEFAULT_IDENTITY_TYPE = "pc"; private static final String DEFAULT_IDENTITY_TYPE = "pc";
private static DiscoverInfo.Identity defaultIdentity = new Identity(DEFAULT_IDENTITY_CATEGORY,
DEFAULT_IDENTITY_NAME, DEFAULT_IDENTITY_TYPE);
private static List<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>(); private Set<DiscoverInfo.Identity> identities = new HashSet<DiscoverInfo.Identity>();
private DiscoverInfo.Identity identity = defaultIdentity;
private EntityCapsManager capsManager; private EntityCapsManager capsManager;
@ -75,7 +78,16 @@ public class ServiceDiscoveryManager {
getInstanceFor(connection); getInstanceFor(connection);
} }
}); });
identities.add(new Identity(DEFAULT_IDENTITY_CATEGORY, DEFAULT_IDENTITY_NAME, DEFAULT_IDENTITY_TYPE)); }
/**
* Set the default identity all new connections will have. If unchanged the default identity is an
* identity where category is set to 'client', type is set to 'pc' and name is set to 'Smack'.
*
* @param identity
*/
public static void setDefaultIdentity(DiscoverInfo.Identity identity) {
defaultIdentity = identity;
} }
/** /**
@ -89,6 +101,7 @@ public class ServiceDiscoveryManager {
@Deprecated @Deprecated
public ServiceDiscoveryManager(Connection connection) { public ServiceDiscoveryManager(Connection connection) {
this.connection = new WeakReference<Connection>(connection); this.connection = new WeakReference<Connection>(connection);
// Register the new instance and associate it with the connection // Register the new instance and associate it with the connection
instances.put(connection, this); instances.put(connection, this);
@ -179,6 +192,90 @@ public class ServiceDiscoveryManager {
connection.addPacketListener(packetListener, packetFilter); connection.addPacketListener(packetListener, packetFilter);
} }
/**
* Returns the name of the client that will be returned when asked for the client identity
* in a disco request. The name could be any value you need to identity this client.
*
* @return the name of the client that will be returned when asked for the client identity
* in a disco request.
*/
public String getIdentityName() {
return identity.getName();
}
/**
* Sets the name of the client that will be returned when asked for the client identity
* in a disco request. The name could be any value you need to identity this client.
*
* @param name the name of the client that will be returned when asked for the client identity
* in a disco request.
*/
public void setIdentityName(String name) {
identity.setName(name);
renewEntityCapsVersion();
}
/**
* Returns the type of client that will be returned when asked for the client identity in a
* disco request. The valid types are defined by the category client. Follow this link to learn
* the possible types: <a href="http://xmpp.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
*
* @return the type of client that will be returned when asked for the client identity in a
* disco request.
*/
public String getIdentityType() {
return identity.getType();
}
/**
* Sets the type of client that will be returned when asked for the client identity in a
* disco request. The valid types are defined by the category client. Follow this link to learn
* the possible types: <a href="http://xmpp.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
*
* @param type the type of client that will be returned when asked for the client identity in a
* disco request.
*/
public void setIdentityType(String type) {
identity.setType(type);
renewEntityCapsVersion();
}
/**
* Add an identity to the client.
*
* @param identity
*/
public void addIdentity(DiscoverInfo.Identity identity) {
identities.add(identity);
renewEntityCapsVersion();
}
/**
* Remove an identity from the client. Note that the client needs at least one identity, the default identity, which
* can not be removed.
*
* @param identity
* @return true, if successful. Otherwise the default identity was given.
*/
public boolean removeIdentity(DiscoverInfo.Identity identity) {
if (identity.equals(this.identity)) return false;
identities.remove(identity);
renewEntityCapsVersion();
return true;
}
/**
* Returns all identities of this client as unmodifiable Collection
*
* @return
*/
public Set<DiscoverInfo.Identity> getIdentities() {
Set<Identity> res = new HashSet<Identity>(identities);
// Add the default identity that must exist
res.add(defaultIdentity);
return Collections.unmodifiableSet(res);
}
/** /**
* Returns the ServiceDiscoveryManager instance associated with a given Connection. * Returns the ServiceDiscoveryManager instance associated with a given Connection.
* *
@ -193,79 +290,6 @@ public class ServiceDiscoveryManager {
return sdm; return sdm;
} }
/**
* Returns the name of the client that will be returned when asked for the client identity
* in a disco request. The name could be any value you need to identity this client.
*
* @return the name of the client that will be returned when asked for the client identity
* in a disco request.
*/
public static String getIdentityName() {
DiscoverInfo.Identity identity = identities.get(0);
if (identity != null) {
return identity.getName();
} else {
return null;
}
}
/**
* Sets the name of the client that will be returned when asked for the client identity
* in a disco request. The name could be any value you need to identity this client.
*
* @param name the name of the client that will be returned when asked for the client identity
* in a disco request.
*/
public static void setIdentityName(String name) {
DiscoverInfo.Identity identity = identities.remove(0);
identity = new DiscoverInfo.Identity(DEFAULT_IDENTITY_CATEGORY, name, DEFAULT_IDENTITY_TYPE);
identities.add(identity);
}
/**
* Returns the type of client that will be returned when asked for the client identity in a
* disco request. The valid types are defined by the category client. Follow this link to learn
* the possible types: <a href="http://xmpp.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
*
* @return the type of client that will be returned when asked for the client identity in a
* disco request.
*/
public static String getIdentityType() {
DiscoverInfo.Identity identity = identities.get(0);
if (identity != null) {
return identity.getType();
} else {
return null;
}
}
/**
* Sets the type of client that will be returned when asked for the client identity in a
* disco request. The valid types are defined by the category client. Follow this link to learn
* the possible types: <a href="http://xmpp.org/registrar/disco-categories.html#client">Jabber::Registrar</a>.
*
* @param type the type of client that will be returned when asked for the client identity in a
* disco request.
*/
public static void setIdentityType(String type) {
DiscoverInfo.Identity identity = identities.get(0);
if (identity != null) {
identity.setType(type);
} else {
identity = new DiscoverInfo.Identity(DEFAULT_IDENTITY_CATEGORY, DEFAULT_IDENTITY_NAME, type);
identities.add(identity);
}
}
/**
* Returns all identities of this client as unmodifiable Collection
*
* @return
*/
public static List<DiscoverInfo.Identity> getIdentities() {
return Collections.unmodifiableList(identities);
}
/** /**
* Add discover info response data. * Add discover info response data.
* *
@ -275,7 +299,7 @@ public class ServiceDiscoveryManager {
*/ */
public void addDiscoverInfoTo(DiscoverInfo response) { public void addDiscoverInfoTo(DiscoverInfo response) {
// First add the identities of the connection // First add the identities of the connection
response.addIdentities(identities); response.addIdentities(getIdentities());
// Add the registered features to the response // Add the registered features to the response
synchronized (features) { synchronized (features) {

View file

@ -56,6 +56,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.WeakHashMap; import java.util.WeakHashMap;
@ -444,9 +445,9 @@ public class EntityCapsManager {
if (connection != null) if (connection != null)
jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1")); jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1"));
final List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities());
sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() { sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() {
List<String> features = sdm.getFeaturesList(); List<String> features = sdm.getFeaturesList();
List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getIdentities());
List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList(); List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList();
@Override @Override

View file

@ -28,7 +28,6 @@ import java.io.StringReader;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.Base32Encoder; import org.jivesoftware.smack.util.Base32Encoder;
import org.jivesoftware.smack.util.Base64Encoder;
import org.jivesoftware.smack.util.StringEncoder; import org.jivesoftware.smack.util.StringEncoder;
import org.jivesoftware.smackx.entitycaps.EntityCapsManager; import org.jivesoftware.smackx.entitycaps.EntityCapsManager;
import org.jivesoftware.smackx.packet.DiscoverInfo; import org.jivesoftware.smackx.packet.DiscoverInfo;

View file

@ -313,6 +313,15 @@ public class DiscoverInfo extends IQ {
return name; return name;
} }
/**
* Set the identity's name.
*
* @param name
*/
public void setName(String name) {
this.name = name;
}
/** /**
* Returns the entity's type. To get the official registry of values for the * Returns the entity's type. To get the official registry of values for the
* 'type' attribute refer to <a href="http://www.jabber.org/registrar/disco-categories.html">Jabber::Registrar</a> * 'type' attribute refer to <a href="http://www.jabber.org/registrar/disco-categories.html">Jabber::Registrar</a>

View file

@ -1,6 +1,8 @@
package org.jivesoftware.smackx.entitycaps; package org.jivesoftware.smackx.entitycaps;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -9,11 +11,9 @@ import java.util.LinkedList;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.Base32Encoder; import org.jivesoftware.smack.util.Base32Encoder;
import org.jivesoftware.smack.util.Base64Encoder;
import org.jivesoftware.smack.util.Base64FileUrlEncoder; import org.jivesoftware.smack.util.Base64FileUrlEncoder;
import org.jivesoftware.smack.util.StringEncoder; import org.jivesoftware.smack.util.StringEncoder;
import org.jivesoftware.smackx.FormField; import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.entitycaps.EntityCapsManager;
import org.jivesoftware.smackx.entitycaps.cache.EntityCapsPersistentCache; import org.jivesoftware.smackx.entitycaps.cache.EntityCapsPersistentCache;
import org.jivesoftware.smackx.entitycaps.cache.SimpleDirectoryPersistentCache; import org.jivesoftware.smackx.entitycaps.cache.SimpleDirectoryPersistentCache;
import org.jivesoftware.smackx.packet.DataForm; import org.jivesoftware.smackx.packet.DataForm;

View file

@ -53,10 +53,10 @@ public class ServiceDiscoveryManagerTest extends SmackTestCase {
Iterator<Identity> identities = info.getIdentities(); Iterator<Identity> identities = info.getIdentities();
assertTrue("No identities were found", identities.hasNext()); assertTrue("No identities were found", identities.hasNext());
Identity identity = identities.next(); Identity identity = identities.next();
assertEquals("Name in identity is wrong", ServiceDiscoveryManager.getIdentityName(), assertEquals("Name in identity is wrong", discoManager.getIdentityName(),
identity.getName()); identity.getName());
assertEquals("Category in identity is wrong", "client", identity.getCategory()); assertEquals("Category in identity is wrong", "client", identity.getCategory());
assertEquals("Type in identity is wrong", ServiceDiscoveryManager.getIdentityType(), assertEquals("Type in identity is wrong", discoManager.getIdentityType(),
identity.getType()); identity.getType());
assertFalse("More identities were found", identities.hasNext()); assertFalse("More identities were found", identities.hasNext());
} }