Smack

org.jivesoftware.smackx.entitycaps
Class EntityCapsManager

java.lang.Object
  extended by org.jivesoftware.smackx.entitycaps.EntityCapsManager

public class EntityCapsManager
extends Object

Keeps track of entity capabilities.

Author:
Florian Schmaus

Nested Class Summary
static class EntityCapsManager.NodeVerHash
           
 
Field Summary
protected static Map<String,DiscoverInfo> caps
          Map of (node + '#" + hash algorithm) to DiscoverInfo data
static String ELEMENT
           
protected static Map<String,EntityCapsManager.NodeVerHash> jidCaps
          Map of Full JID -> DiscoverInfo/null.
static String NAMESPACE
           
protected static EntityCapsPersistentCache persistentCache
           
 
Method Summary
static void addDiscoverInfoByNode(String nodeVer, DiscoverInfo info)
          Add DiscoverInfo to the database.
 boolean areEntityCapsSupported(String jid)
          Returns true if Entity Caps are supported by a given JID
 boolean areEntityCapsSupportedByServer()
          Returns true if Entity Caps are supported by the local service/server
 void disableEntityCaps()
           
 void enableEntityCaps()
           
 boolean entityCapsEnabled()
           
protected static String generateVerificationString(DiscoverInfo discoverInfo, String hash)
          Generates a XEP-115 Verification String
 String getCapsVersion()
          Get our own caps version.
static DiscoverInfo getDiscoverInfoByUser(String user)
          Get the discover info given a user name.
static DiscoverInfo getDiscoveryInfoByNodeVer(String nodeVer)
          Retrieve DiscoverInfo for a specific node.
static EntityCapsManager getInstanceFor(Connection connection)
           
 String getLocalNodeVer()
          Returns the local entity's NodeVer (e.g.
static EntityCapsManager.NodeVerHash getNodeVerHashByJid(String jid)
           
static String getNodeVersionByJid(String jid)
          Get the Node version (node#ver) of a JID.
 void removeUserCapsNode(String user)
          Remove a record telling what entity caps node a user has.
static void setCapsMaxCacheSize(int maxCacheSize)
          Sets the maximum Cache size for the nodeVer to DiscoverInfo Cache
static void setJidCapsMaxCacheSize(int maxCacheSize)
          Sets the maximum Cache size for the JID to nodeVer Cache
static void setPersistentCache(EntityCapsPersistentCache cache)
          Set the persistent cache implementation
 void updateLocalEntityCaps()
          Updates the local user Entity Caps information with the data provided If we are connected and there was already a presence send, another presence is send to inform others about your new Entity Caps node string.
static boolean verifyDiscoverInfoVersion(String ver, String hash, DiscoverInfo info)
          Verify DisoverInfo and Caps Node as defined in XEP-0115 5.4 Processing Method
protected static boolean verifyPacketExtensions(DiscoverInfo info)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACE

public static final String NAMESPACE
See Also:
Constant Field Values

ELEMENT

public static final String ELEMENT
See Also:
Constant Field Values

persistentCache

protected static EntityCapsPersistentCache persistentCache

caps

protected static Map<String,DiscoverInfo> caps
Map of (node + '#" + hash algorithm) to DiscoverInfo data


jidCaps

protected static Map<String,EntityCapsManager.NodeVerHash> jidCaps
Map of Full JID -> DiscoverInfo/null. In case of c2s connection the key is formed as user@server/resource (resource is required) In case of link-local connection the key is formed as user@host (no resource) In case of a server or component the key is formed as domain

Method Detail

addDiscoverInfoByNode

public static void addDiscoverInfoByNode(String nodeVer,
                                         DiscoverInfo info)
Add DiscoverInfo to the database.

Parameters:
nodeVer - The node and verification String (e.g. "http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w=").
info - DiscoverInfo for the specified node.

getNodeVersionByJid

public static String getNodeVersionByJid(String jid)
Get the Node version (node#ver) of a JID. Returns a String or null if EntiyCapsManager does not have any information.

Parameters:
user - the user (Full JID)
Returns:
the node version (node#ver) or null

getNodeVerHashByJid

public static EntityCapsManager.NodeVerHash getNodeVerHashByJid(String jid)

getDiscoverInfoByUser

public static DiscoverInfo getDiscoverInfoByUser(String user)
Get the discover info given a user name. The discover info is returned if the user has a node#ver associated with it and the node#ver has a discover info associated with it.

Parameters:
user - user name (Full JID)
Returns:
the discovered info

getDiscoveryInfoByNodeVer

public static DiscoverInfo getDiscoveryInfoByNodeVer(String nodeVer)
Retrieve DiscoverInfo for a specific node.

Parameters:
nodeVer - The node name (e.g. "http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w=").
Returns:
The corresponding DiscoverInfo or null if none is known.

setPersistentCache

public static void setPersistentCache(EntityCapsPersistentCache cache)
                               throws IOException
Set the persistent cache implementation

Parameters:
cache -
Throws:
IOException

setJidCapsMaxCacheSize

public static void setJidCapsMaxCacheSize(int maxCacheSize)
Sets the maximum Cache size for the JID to nodeVer Cache

Parameters:
maxCacheSize -

setCapsMaxCacheSize

public static void setCapsMaxCacheSize(int maxCacheSize)
Sets the maximum Cache size for the nodeVer to DiscoverInfo Cache

Parameters:
maxCacheSize -

getInstanceFor

public static EntityCapsManager getInstanceFor(Connection connection)

enableEntityCaps

public void enableEntityCaps()

disableEntityCaps

public void disableEntityCaps()

entityCapsEnabled

public boolean entityCapsEnabled()

removeUserCapsNode

public void removeUserCapsNode(String user)
Remove a record telling what entity caps node a user has.

Parameters:
user - the user (Full JID)

getCapsVersion

public String getCapsVersion()
Get our own caps version. The version depends on the enabled features. A caps version looks like '66/0NaeaBKkwk85efJTGmU47vXI='

Returns:
our own caps version

getLocalNodeVer

public String getLocalNodeVer()
Returns the local entity's NodeVer (e.g. "http://www.igniterealtime.org/projects/smack/#66/0NaeaBKkwk85efJTGmU47vXI= )

Returns:

areEntityCapsSupported

public boolean areEntityCapsSupported(String jid)
Returns true if Entity Caps are supported by a given JID

Parameters:
jid -
Returns:

areEntityCapsSupportedByServer

public boolean areEntityCapsSupportedByServer()
Returns true if Entity Caps are supported by the local service/server

Returns:

updateLocalEntityCaps

public void updateLocalEntityCaps()
Updates the local user Entity Caps information with the data provided If we are connected and there was already a presence send, another presence is send to inform others about your new Entity Caps node string.

Parameters:
discoverInfo - the local users discover info (mostly the service discovery features)
identityType - the local users identity type
identityName - the local users identity name
extendedInfo - the local users extended info

verifyDiscoverInfoVersion

public static boolean verifyDiscoverInfoVersion(String ver,
                                                String hash,
                                                DiscoverInfo info)
Verify DisoverInfo and Caps Node as defined in XEP-0115 5.4 Processing Method

Parameters:
capsNode - the caps node (i.e. node#ver)
info -
Returns:
true if it's valid and should be cache, false if not
See Also:
XEP-0115 5.4 Processing Method

verifyPacketExtensions

protected static boolean verifyPacketExtensions(DiscoverInfo info)
Parameters:
info -
Returns:
true if the packet extensions is ill-formed

generateVerificationString

protected static String generateVerificationString(DiscoverInfo discoverInfo,
                                                   String hash)
Generates a XEP-115 Verification String

Parameters:
discoverInfo -
hash - the used hash function
Returns:
The generated verification String or null if the hash is not supported
See Also:
XEP-115 Verification String

Smack

Copyright © 2003-2007 Jive Software.