Beispiel #1
0
  /**
   * Test if entity caps actually prevent a disco info request and reply
   *
   * @throws XMPPException
   */
  public void testPreventDiscoInfo() throws XMPPException {
    con0.addPacketSendingListener(
        new PacketListener() {

          @Override
          public void processPacket(Packet packet) {
            discoInfoSend = true;
          }
        },
        new AndFilter(new PacketTypeFilter(DiscoverInfo.class), new IQTypeFilter(IQ.Type.get)));

    // add a bogus feature so that con1 ver won't match con0's
    sdm1.addFeature(DISCOVER_TEST_FEATURE);

    dropCapsCache();
    // discover that
    DiscoverInfo info = sdm0.discoverInfo(con1.getUser());
    // that discovery should cause a disco#info
    assertTrue(discoInfoSend);
    assertTrue(info.containsFeature(DISCOVER_TEST_FEATURE));
    discoInfoSend = false;

    // discover that
    info = sdm0.discoverInfo(con1.getUser());
    // that discovery shouldn't cause a disco#info
    assertFalse(discoInfoSend);
    assertTrue(info.containsFeature(DISCOVER_TEST_FEATURE));
  }
 /** Discover the features provided by the server. */
 private void discoverServerFeatures() {
   try {
     // jid et server
     ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
     DiscoverInfo info = sdm.discoverInfo(mAdaptee.getServiceName());
     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) {
     Log.w(TAG, "Unable to discover server features", e);
   }
 }
 /**
  * Checks the service discovery item returned from a server component to verify if it is a File
  * Transfer proxy or not.
  *
  * @param manager the service discovery manager which will be used to query the component
  * @param item the discovered item on the server relating
  * @return returns the JID of the proxy if it is a proxy or null if the item is not a proxy.
  */
 private String checkIsProxy(ServiceDiscoveryManager manager, DiscoverItems.Item item) {
   DiscoverInfo info;
   try {
     info = manager.discoverInfo(item.getEntityID());
   } catch (XMPPException e) {
     return null;
   }
   Iterator itx = info.getIdentities();
   while (itx.hasNext()) {
     DiscoverInfo.Identity identity = (DiscoverInfo.Identity) itx.next();
     if ("proxy".equalsIgnoreCase(identity.getCategory())
         && "bytestreams".equalsIgnoreCase(identity.getType())) {
       return info.getFrom();
     }
   }
   return null;
 }
Beispiel #4
0
 /**
  * Tries to discover if the server of the given XMPPConnection provides also a MUC component. Will
  * return the MUCs Component ID if one is found otherwise returns null
  *
  * @param connection
  * @return
  * @throws XMPPException
  */
 public static String disocverMUC(XMPPConnection connection) throws XMPPException {
   ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
   DiscoverItems ditem = sdm.discoverItems(connection.getServiceName());
   Iterator<Item> it = ditem.getItems();
   while (it.hasNext()) {
     Item i = it.next();
     DiscoverInfo dinfo = sdm.discoverInfo(i.getEntityID());
     Iterator<Feature> itFeatures = dinfo.getFeatures();
     while (itFeatures.hasNext()) {
       Feature f = itFeatures.next();
       if (f.getVar().equals(MUC_FEATURE)) {
         return i.getEntityID();
       }
     }
   }
   return null;
 }
Beispiel #5
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());
  }
Beispiel #6
0
 private void populateFeatureSet() {
   final ServiceDiscoveryManager disco =
       ServiceDiscoveryManager.getInstanceFor(ChatsyManager.getConnection());
   final DiscoverItems items = ChatsyManager.getSessionManager().getDiscoveredItems();
   Iterator<DiscoverItems.Item> iter = items.getItems();
   while (iter.hasNext()) {
     DiscoverItems.Item item = iter.next();
     String entity = item.getEntityID();
     if (entity != null) {
       if (entity.startsWith("manager.")) {
         chatsyManagerInstalled = true;
         try {
           featureInfo = disco.discoverInfo(item.getEntityID());
         } catch (XMPPException e) {
           Log.error("Error while retrieving feature list for ChatsyManager.", e);
         }
       }
     }
   }
 }
 private boolean checkIfPrivacyIsSupported(XMPPConnection conn) {
   ServiceDiscoveryManager servDisc = ServiceDiscoveryManager.getInstanceFor(conn);
   DiscoverInfo info = null;
   try {
     String xmppHost = DNSUtil.resolveXMPPDomain(conn.getServiceName()).getHost();
     info = servDisc.discoverInfo(xmppHost);
   } catch (XMPPException e) {
     // We could not query the server
     return false;
   }
   if (info != null) {
     for (Iterator<Feature> i = info.getFeatures(); i.hasNext(); ) {
       String s = i.next().getVar();
       if (s.contains("jabber:iq:privacy")) {
         return true;
       }
     }
   }
   return false;
 }
Beispiel #8
0
 /**
  * Validate the ver attribute of a received capability.
  *
  * @param jid the jid of the sender of the capability.
  * @param node the node attribute of the capability.
  * @param ver the ver attribute of the capability.
  * @param hashMethod the hash algorithm to use to calculate ver
  * @return true if the ver attribute is valid false otherwise.
  */
 private boolean validate(String jid, String node, String ver, String hashMethod) {
   try {
     DiscoverInfo info = mSdm.discoverInfo(jid, node + "#" + ver);
     if (!mSupportedAlgorithm.contains(hashMethod)) {
       mJidCache.put(jid, info);
       return false;
     }
     String v = calculateVer(info, hashMethod);
     boolean res = v.equals(ver);
     if (res) {
       mVerCache.put(ver, info);
       store(ver, info);
     }
     return res;
   } catch (XMPPException e) {
     e.printStackTrace();
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   }
   return false;
 }
  /**
   * Perform a ServiceDiscovery [1] and check if the given resource is among the features supported
   * by the given recipient.
   *
   * <p>[1] XEP-0030 http://xmpp.org/extensions/xep-0030.html
   *
   * @param jid The JID must have a resource identifier (user@host/resource), otherwise you get a
   *     blame StackTrace in your logs.
   * @return DiscoverInfo from recipient or null if an XMPPException was thrown.
   * @blocking This method blocks until the ServiceDiscovery returns.
   * @reentrant This method can be called concurrently.
   * @nonCaching This method does not use a cache, but queries the server directly.
   */
  private DiscoverInfo performServiceDiscovery(final JID jid) {

    if (jid.isBareJID()) {
      LOG.warn(
          "cannot perform service discovery on a non resource qualified jid: " + jid.toString(),
          new StackTrace());
      return null;
    }

    final Connection connection = connectionService.getConnection();

    if (connection == null) {
      LOG.warn("cannot not perform a service discovery because not connected to a XMPP server");
      return null;
    }

    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);

    try {
      return sdm.discoverInfo(jid.toString());
    } catch (XMPPException e) {

      LOG.warn(
          "Service Discovery failed on recipient "
              + jid.toString()
              + " server: "
              + connection.getHost(),
          e);

      /*
       * FIXME handle timeouts and error conditions differently ! see
       * http://xmpp.org/extensions/xep-0030.html#errors
       */
      return null;
    }
  }
 /**
  * Gets the supported features of the servers pubsub implementation as a standard {@link
  * DiscoverInfo} instance.
  *
  * @return The supported features
  * @throws XMPPException
  */
 public DiscoverInfo getSupportedFeatures() throws XMPPException {
   ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(con);
   return mgr.discoverInfo(to);
 }