Exemplo n.º 1
0
 /** Entity Capabilities */
 public void setEntityCapsManager(EntityCapsManager manager) {
   capsManager = manager;
   if (connection.getCapsNode() != null && connection.getHost() != null) {
     capsManager.addUserCapsNode(connection.getHost(), connection.getCapsNode());
   }
   capsManager.addPacketListener(connection);
 }
Exemplo n.º 2
0
  public void testLocalEntityCaps() throws InterruptedException {
    DiscoverInfo info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecm1.getLocalNodeVer());
    assertFalse(info.containsFeature(DISCOVER_TEST_FEATURE));

    dropWholeEntityCapsCache();

    // This should cause a new presence stanza from con1 with and updated
    // 'ver' String
    sdm1.addFeature(DISCOVER_TEST_FEATURE);

    // Give the server some time to handle the stanza and send it to con0
    Thread.sleep(2000);

    // The presence stanza should get received by con0 and the data should
    // be recorded in the map
    // Note that while both connections use the same static Entity Caps
    // cache,
    // it's assured that *not* con1 added the data to the Entity Caps cache.
    // Every time the entities features
    // and identities change only a new caps 'ver' is calculated and send
    // with the presence stanza
    // The other connection has to receive this stanza and record the
    // information in order for this test to succeed.
    info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecm1.getLocalNodeVer());
    assertNotNull(info);
    assertTrue(info.containsFeature(DISCOVER_TEST_FEATURE));
  }
Exemplo n.º 3
0
  /**
   * Returns the discovered information of a given XMPP entity addressed by its JID.
   *
   * @param entityID the address of the XMPP entity.
   * @return the discovered information.
   * @throws XMPPException if the operation failed for some reason.
   */
  public DiscoverInfo discoverInfo(String entityID) throws XMPPException {
    // Check if the have it cached in the Entity Capabilities Manager
    DiscoverInfo info = discoverInfoByCaps(entityID);

    if (info != null) {
      return info;
    } else {
      // If the caps node is known, use it in the request.
      String node = null;

      if (capsManager != null) {
        // Get the newest node#version
        node = capsManager.getNodeVersionByUser(entityID);
      }

      // Check if we cached DiscoverInfo for nonCaps entity
      if (cacheNonCaps && node == null && nonCapsCache.containsKey(entityID)) {
        return nonCapsCache.get(entityID);
      }
      // Discover by requesting from the remote client
      info = discoverInfo(entityID, node);

      // If the node version is known, store the new entry.
      if (node != null && capsManager != null) {
        EntityCapsManager.addDiscoverInfoByNode(node, info);
      }
      // If this is a non caps entity store the discover in nonCapsCache map
      else if (cacheNonCaps && node == null) {
        nonCapsCache.put(entityID, info);
      }
      return info;
    }
  }
Exemplo n.º 4
0
  public void testCapsChanged() {
    String nodeVerBefore = EntityCapsManager.getNodeVersionByJid(con1.getUser());
    sdm1.addFeature(DISCOVER_TEST_FEATURE);
    String nodeVerAfter = EntityCapsManager.getNodeVersionByJid(con1.getUser());

    assertFalse(nodeVerBefore.equals(nodeVerAfter));
  }
Exemplo n.º 5
0
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   SmackConfiguration.setAutoEnableEntityCaps(true);
   con0 = getConnection(0);
   con1 = getConnection(1);
   ecm0 = EntityCapsManager.getInstanceFor(getConnection(0));
   ecm1 = EntityCapsManager.getInstanceFor(getConnection(1));
   sdm0 = ServiceDiscoveryManager.getInstanceFor(con0);
   sdm1 = ServiceDiscoveryManager.getInstanceFor(con1);
   letsAllBeFriends();
 }
Exemplo n.º 6
0
 private String getEntityCapsVersion() {
   if (capsManager != null) {
     return capsManager.getCapsVersion();
   } else {
     return null;
   }
 }
Exemplo n.º 7
0
  /**
   * Get a DiscoverInfo for the current entity caps node.
   *
   * @return a DiscoverInfo for the current entity caps node
   */
  public DiscoverInfo getOwnDiscoverInfo() {
    DiscoverInfo di = new DiscoverInfo();
    di.setType(IQ.Type.RESULT);
    di.setNode(capsManager.getNode() + "#" + getEntityCapsVersion());

    // Add discover info
    addDiscoverInfoTo(di);

    return di;
  }
Exemplo n.º 8
0
 private void renewEntityCapsVersion() {
   // If a XMPPConnection is the managed one, see that the new
   // version is updated
   if (connection instanceof XMPPConnection) {
     if (capsManager != null) {
       capsManager.calculateEntityCapsVersion(
           getOwnDiscoverInfo(), identityType, identityName, features, extendedInfo);
       // capsManager.notifyCapsVerListeners();
     }
   }
 }
Exemplo n.º 9
0
  /**
   * Returns the discovered information of a given XMPP entity addressed by its JID if it's known by
   * the entity caps manager.
   *
   * @param entityID the address of the XMPP entity
   * @return the disovered info or null if no such info is available from the entity caps manager.
   * @throws XMPPException if the operation failed for some reason.
   */
  public DiscoverInfo discoverInfoByCaps(String entityID) throws XMPPException {
    DiscoverInfo info = capsManager.getDiscoverInfoByUser(entityID);

    if (info != null) {
      DiscoverInfo newInfo = cloneDiscoverInfo(info);
      newInfo.setFrom(entityID);
      return newInfo;
    } else {
      return null;
    }
  }
Exemplo n.º 10
0
  /**
   * Creates a new ServiceDiscoveryManager for a given connection. This means that the service
   * manager will respond to any service discovery request that the connection may receive.
   *
   * @param connection the connection to which a ServiceDiscoveryManager is going to be created.
   */
  public ServiceDiscoveryManager(Connection connection) {
    this.connection = connection;

    // For every XMPPConnection, add one EntityCapsManager.
    if (connection instanceof XMPPConnection) {
      setEntityCapsManager(new EntityCapsManager());
      capsManager.addCapsVerListener(new CapsPresenceRenewer());
    }

    renewEntityCapsVersion();

    init();
  }
Exemplo n.º 11
0
  public void testEntityCaps() throws XMPPException, InterruptedException {
    dropWholeEntityCapsCache();
    sdm1.addFeature(DISCOVER_TEST_FEATURE);

    Thread.sleep(3000);

    DiscoverInfo info = sdm0.discoverInfo(con1.getUser());
    assertTrue(info.containsFeature(DISCOVER_TEST_FEATURE));

    String u1ver = EntityCapsManager.getNodeVersionByJid(con1.getUser());
    assertNotNull(u1ver);

    DiscoverInfo entityInfo = EntityCapsManager.caps.get(u1ver);
    assertNotNull(entityInfo);

    assertEquals(info.toXML(), entityInfo.toXML());
  }