Пример #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));
  }
Пример #2
0
  static {
    instance = new ConnectionManager();
    Application.getInstance().addManager(instance);

    SmackConfiguration.setPacketReplyTimeout(PACKET_REPLY_TIMEOUT);

    ServiceDiscoveryManager.setIdentityType("handheld");
    ServiceDiscoveryManager.setIdentityName(
        Application.getInstance().getString(R.string.client_name));

    SASLAuthentication.registerSASLMechanism("X-MESSENGER-OAUTH2", XMessengerOAuth2.class);
    SASLAuthentication.supportSASLMechanism("X-MESSENGER-OAUTH2");

    String path = System.getProperty("javax.net.ssl.trustStore");
    if (path == null)
      TRUST_STORE_PATH =
          System.getProperty("java.home")
              + File.separator
              + "etc"
              + File.separator
              + "security"
              + File.separator
              + "cacerts.bks";
    else TRUST_STORE_PATH = path;

    Connection.addConnectionCreationListener(
        new ConnectionCreationListener() {
          @Override
          public void connectionCreated(final Connection connection) {
            ServiceDiscoveryManager.getInstanceFor(connection).addFeature("sslc2s");
          }
        });
  }
Пример #3
0
  private void browse(String serviceName) {
    browsePanel.removeAll();

    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
    DiscoverItems result;
    try {
      result = discoManager.discoverItems(serviceName);
    } catch (XMPPException e) {
      Log.error(e);
      return;
    }

    addAddress(serviceName);

    Iterator<DiscoverItems.Item> discoverItems = result.getItems();
    while (discoverItems.hasNext()) {
      DiscoverItems.Item item = discoverItems.next();
      Entity entity = new Entity(item);
      browsePanel.add(entity);
    }

    browsePanel.invalidate();
    browsePanel.validate();
    browsePanel.repaint();
  }
Пример #4
0
  private void browseItem(DiscoverItems.Item discoveredItem) {
    addAddress(discoveredItem.getEntityID());
    browsePanel.removeAll();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
    DiscoverItems result;
    try {
      result = discoManager.discoverItems(discoveredItem.getEntityID());
    } catch (XMPPException e) {
      browsePanel.invalidate();
      browsePanel.validate();
      browsePanel.repaint();
      return;
    }

    Iterator<DiscoverItems.Item> discoverItems = result.getItems();
    List<Entity> list = new ArrayList<Entity>();

    while (discoverItems.hasNext()) {
      DiscoverItems.Item item = discoverItems.next();
      Entity entity = new Entity(item);
      browsePanel.add(entity);
      list.add(entity);
    }

    GraphicUtils.makeSameSize((JComponent[]) list.toArray(new JComponent[list.size()]));

    browsePanel.invalidate();
    browsePanel.validate();
    browsePanel.repaint();
  }
Пример #5
0
  /** Creates a destination for a service that receives XMPP messages. */
  public Destination getDestination(EndpointInfo endpointInfo) throws IOException {
    // The node name is the full name of the service.
    String nodeName = endpointInfo.getService().getName().toString();
    pepProvider.registerPEPParserExtension(nodeName, soapProvider);

    PEPDestination dest = new PEPDestination(endpointInfo);

    try {
      XMPPConnection conn = destinationConnectionFactory.login(endpointInfo);

      // Advertise interest in receiving information.
      ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(conn);
      disco.addFeature(nodeName + "+notify");

      // Create destination.
      dest.setXmppConnection(conn);
      conn.addPacketListener(
          dest, new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event"));

    } catch (XMPPException e) {
      throw new IOException(e);
    }

    return dest;
  }
Пример #6
0
  /**
   * Enables or disables the XHTML support on a given connection.
   *
   * <p>Before starting to send XHTML messages to a user, check that the user can handle XHTML
   * messages. Enable the XHTML support to indicate that this client handles XHTML messages.
   *
   * @param connection the connection where the service will be enabled or disabled
   * @param enabled indicates if the service will be enabled or disabled
   */
  public static synchronized void setServiceEnabled(Connection connection, boolean enabled) {
    if (isServiceEnabled(connection) == enabled) return;

    if (enabled) {
      ServiceDiscoveryManager.getInstanceFor(connection).addFeature(namespace);
    } else {
      ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(namespace);
    }
  }
Пример #7
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();
 }
Пример #8
0
 /**
  * Get the Discover Information send by your own connection.
  *
  * @return your own DiscoverInfo
  */
 private DiscoverInfo getOwnInformation() {
   DiscoverInfo result = new DiscoverInfo();
   DiscoverInfo.Identity id =
       new DiscoverInfo.Identity("client", ServiceDiscoveryManager.getIdentityName());
   id.setType(ServiceDiscoveryManager.getIdentityType());
   result.addIdentity(id);
   Iterator<String> it = mSdm.getFeatures();
   while (it.hasNext()) {
     result.addFeature(it.next());
   }
   return result;
 }
Пример #9
0
 public boolean initFileTransport() {
   if (connection == null) {
     return false;
   } else if (fileTransferManager != null) {
     return true;
   } else {
     fileTransferManager = new FileTransferManager(connection);
     ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
     if (sdm == null) sdm = new ServiceDiscoveryManager(connection);
     sdm.addFeature("http://jabber.org/protocol/disco#info");
     sdm.addFeature("jabber:iq:privacy");
     FileTransferNegotiator.setServiceEnabled(connection, true);
     return true;
   }
 }
Пример #10
0
  private void initServiceDiscovery() {
    // register connection features
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mXMPPConnection);

    // init Entity Caps manager with storage in app's cache dir
    try {
      if (capsCacheDir == null) {
        capsCacheDir = new File(mService.getCacheDir(), "entity-caps-cache");
        capsCacheDir.mkdirs();
        EntityCapsManager.setPersistentCache(new SimpleDirectoryPersistentCache(capsCacheDir));
      }
    } catch (java.io.IOException e) {
      Log.e(TAG, "Could not init Entity Caps cache: " + e.getLocalizedMessage());
    }

    // reference PingManager, set ping flood protection to 10s
    PingManager.getInstanceFor(mXMPPConnection).setPingMinimumInterval(10 * 1000);

    // set Version for replies
    String app_name = mService.getString(org.yaxim.androidclient.R.string.app_name);
    String build_revision = mService.getString(org.yaxim.androidclient.R.string.build_revision);
    Version.Manager.getInstanceFor(mXMPPConnection)
        .setVersion(new Version(app_name, build_revision, "Android"));

    // reference DeliveryReceiptManager, add listener
    DeliveryReceiptManager dm = DeliveryReceiptManager.getInstanceFor(mXMPPConnection);
    dm.enableAutoReceipts();
    dm.addReceiptReceivedListener(
        new ReceiptReceivedListener() { // DOES NOT WORK IN CARBONS
          public void onReceiptReceived(String fromJid, String toJid, String receiptId) {
            Log.d(TAG, "got delivery receipt for " + receiptId);
            changeMessageDeliveryStatus(receiptId, ChatConstants.DS_ACKED);
          }
        });
  }
 /** 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);
   }
 }
Пример #12
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));
  }
Пример #13
0
  static void registerSmackProviders() {
    ProviderManager pm = ProviderManager.getInstance();
    // add IQ handling
    pm.addIQProvider("query", "http://jabber.org/protocol/disco#info", new DiscoverInfoProvider());
    pm.addIQProvider(
        "query", "http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
    // add delayed delivery notifications
    pm.addExtensionProvider("delay", "urn:xmpp:delay", new DelayInfoProvider());
    pm.addExtensionProvider("x", "jabber:x:delay", new DelayInfoProvider());
    // add XEP-0092 Software Version
    pm.addIQProvider("query", Version.NAMESPACE, new Version.Provider());

    // add carbons and forwarding
    pm.addExtensionProvider("forwarded", Forwarded.NAMESPACE, new Forwarded.Provider());
    pm.addExtensionProvider("sent", Carbon.NAMESPACE, new Carbon.Provider());
    pm.addExtensionProvider("received", Carbon.NAMESPACE, new Carbon.Provider());
    // add delivery receipts
    pm.addExtensionProvider(
        DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE, new DeliveryReceipt.Provider());
    pm.addExtensionProvider(
        DeliveryReceiptRequest.ELEMENT,
        DeliveryReceipt.NAMESPACE,
        new DeliveryReceiptRequest.Provider());
    // add XMPP Ping (XEP-0199)
    pm.addIQProvider("ping", "urn:xmpp:ping", new PingProvider());

    ServiceDiscoveryManager.setDefaultIdentity(YAXIM_IDENTITY);

    // XEP-0115 Entity Capabilities
    pm.addExtensionProvider("c", "http://jabber.org/protocol/caps", new CapsExtensionProvider());

    XmppStreamHandler.addExtensionProviders();
  }
Пример #14
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));
  }
Пример #15
0
  /**
   * Registers a new command with this command manager, which is related to a connection. The
   * <tt>node</tt> is an unique identifier of that command for the connection related to this
   * command manager. The <tt>name</tt> is the human readeale name of the command. The
   * <tt>factory</tt> generates new instances of the command.
   *
   * @param node the unique identifier of the command.
   * @param name the human readable name of the command.
   * @param factory a factory to create new instances of the command.
   */
  public void registerCommand(String node, final String name, LocalCommandFactory factory) {
    AdHocCommandInfo commandInfo = new AdHocCommandInfo(node, name, connection.getUser(), factory);

    commands.put(node, commandInfo);
    // Set the NodeInformationProvider that will provide information about
    // the added command
    ServiceDiscoveryManager.getInstanceFor(connection)
        .setNodeInformationProvider(
            node,
            new NodeInformationProvider() {
              public List<DiscoverItems.Item> getNodeItems() {
                return null;
              }

              public List<String> getNodeFeatures() {
                List<String> answer = new ArrayList<String>();
                answer.add(DISCO_NAMESPACE);
                // TODO: check if this service is provided by the
                // TODO: current connection.
                answer.add("jabber:x:data");
                return answer;
              }

              public List<DiscoverInfo.Identity> getNodeIdentities() {
                List<DiscoverInfo.Identity> answer = new ArrayList<DiscoverInfo.Identity>();
                DiscoverInfo.Identity identity = new DiscoverInfo.Identity("automation", name);
                identity.setType("command-node");
                answer.add(identity);
                return answer;
              }
            });
  }
Пример #16
0
  private void initServiceDiscovery() {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(extXMPPConnection);
    try {
      if (capsCacheDir == null) {
        capsCacheDir = new File(service.getCacheDir(), "entity-caps-cache");
        capsCacheDir.mkdirs();
        EntityCapsManager.setPersistentCache(new SimpleDirectoryPersistentCache(capsCacheDir));
      }
    } catch (java.io.IOException e) {
      Log.e(TAG, "Could not init : " + e.getLocalizedMessage());
    }

    PingManager.getInstanceFor(extXMPPConnection).setPingMinimumInterval(10 * 1000);
    String app_name = service.getString(R.string.app_name);
    String build_revision = service.getString(R.string.build_revision);
    Version.Manager.getInstanceFor(extXMPPConnection)
        .setVersion(new Version(app_name, build_revision, Constant.ANDROID));

    DeliveryReceiptManager dm = DeliveryReceiptManager.getInstanceFor(extXMPPConnection);
    dm.enableAutoReceipts();
    dm.addReceiptReceivedListener(
        new ReceiptReceivedListener() { // DOES NOT WORK IN CARBONS
          public void onReceiptReceived(String fromJid, String toJid, String receiptId) {

            changeMessageDeliveryStatus(receiptId, ChatConstants.DS_ACKED);
          }
        });
  }
Пример #17
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());
  }
  /**
   * Checks to see if all file transfer related services are enabled on the connection.
   *
   * @param connection The connection to check
   * @return True if all related services are enabled, false if they are not.
   */
  public static boolean isServiceEnabled(final Connection connection) {
    final ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection);

    final List<String> namespaces = new ArrayList<String>();
    namespaces.addAll(Arrays.asList(NAMESPACE));
    namespaces.add(InBandBytestreamManager.NAMESPACE);
    if (!IBB_ONLY) {
      namespaces.add(Socks5BytestreamManager.NAMESPACE);
    }

    for (final String namespace : namespaces) {
      if (!manager.includesFeature(namespace)) {
        return false;
      }
    }
    return true;
  }
Пример #19
0
  /**
   * Publish the commands to an specific JID.
   *
   * @param jid the full JID to publish the commands to.
   * @throws XMPPException if the operation failed for some reason.
   */
  public void publishCommands(String jid) throws XMPPException {
    ServiceDiscoveryManager serviceDiscoveryManager =
        ServiceDiscoveryManager.getInstanceFor(connection);

    // Collects the commands to publish as items
    DiscoverItems discoverItems = new DiscoverItems();
    Collection<AdHocCommandInfo> xCommandsList = getRegisteredCommands();

    for (AdHocCommandInfo info : xCommandsList) {
      DiscoverItems.Item item = new DiscoverItems.Item(info.getOwnerJID());
      item.setName(info.getName());
      item.setNode(info.getNode());
      discoverItems.addItem(item);
    }

    serviceDiscoveryManager.publishItems(jid, discoNode, discoverItems);
  }
Пример #20
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;
 }
Пример #21
0
 /**
  * Returns true if the specified user handles XHTML messages.
  *
  * @param connection the connection to use to perform the service discovery
  * @param userID the user to check. A fully qualified xmpp ID, e.g. [email protected]
  * @return a boolean indicating whether the specified user handles XHTML messages
  */
 public static boolean isServiceEnabled(Connection connection, String userID) {
   try {
     DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(userID);
     return result.containsFeature(namespace);
   } catch (XMPPException e) {
     e.printStackTrace();
     return false;
   }
 }
Пример #22
0
 /**
  * Returns the number of offline messages for the user of the connection.
  *
  * @return the number of offline messages for the user of the connection.
  * @throws XMPPException If the user is not allowed to make this request or the server does not
  *     support offline message retrieval.
  */
 public int getMessageCount() throws XMPPException {
   DiscoverInfo info =
       ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null, namespace);
   Form extendedInfo = Form.getFormFrom(info);
   if (extendedInfo != null) {
     String value = (String) extendedInfo.getField("number_of_messages").getValues().next();
     return Integer.parseInt(value);
   }
   return 0;
 }
Пример #23
0
 /**
  * Returns an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline
  * message. The OfflineMessageHeader includes a stamp that could be used to retrieve the complete
  * message or delete the specific message.
  *
  * @return an iterator on <tt>OfflineMessageHeader</tt> that keep information about the offline
  *     message.
  * @throws XMPPException If the user is not allowed to make this request or the server does not
  *     support offline message retrieval.
  */
 public Iterator getHeaders() throws XMPPException {
   List answer = new ArrayList();
   DiscoverItems items =
       ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(null, namespace);
   for (Iterator it = items.getItems(); it.hasNext(); ) {
     DiscoverItems.Item item = (DiscoverItems.Item) it.next();
     answer.add(new OfflineMessageHeader(item));
   }
   return answer.iterator();
 }
Пример #24
0
  /**
   * Deletes the session agent account, frees all resources and disconnects the XMPP connection.
   *
   * @throws org.jivesoftware.smack.XMPPException
   */
  public void shutdown() throws XMPPException {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mConnection);

    // ServiceDiscovery (feature) http://rn.inf.tu-dresden.de/mobilis
    try {
      sdm.removeFeature(MobilisManager.discoNamespace);
    } catch (Exception e) {
      MobilisManager.getLogger().warning("Problem with ServiceDiscoveryManager: " + e.getMessage());
    }

    // ServiceDiscovery (info+items) http://rn.inf.tu-dresden.de/mobilis#services
    try {
      sdm.removeNodeInformationProvider(MobilisManager.discoServicesNode);
    } catch (Exception e) {
      MobilisManager.getLogger()
          .warning(
              "Problem with NodeInformationProvider: "
                  + MobilisManager.discoServicesNode
                  + " ("
                  + getIdent()
                  + ") "
                  + e.getMessage());
    }

    for (MobilisService service : mServices) {
      try {
        sdm.removeNodeInformationProvider(service.getNode());
        service.shutdown();
      } catch (Exception e) {
        // TODO Auto-generated catch block
      }
    }

    if ((mConnection != null) && mConnection.isConnected()) {
      mConnection.removeConnectionListener(this);
      mConnection.disconnect();
    }
    mConnection = null;

    // logging
    MobilisManager.getLogger().info("Mobilis Agent (" + getIdent() + ") shut down.");
  }
Пример #25
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);
         }
       }
     }
   }
 }
  /**
   * Enable the Jabber services related to file transfer on the particular connection.
   *
   * @param connection The connection on which to enable or disable the services.
   * @param isEnabled True to enable, false to disable.
   */
  public static void setServiceEnabled(final Connection connection, final boolean isEnabled) {
    final ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection);

    final List<String> namespaces = new ArrayList<String>();
    namespaces.addAll(Arrays.asList(NAMESPACE));
    namespaces.add(InBandBytestreamManager.NAMESPACE);
    if (!IBB_ONLY) {
      namespaces.add(Socks5BytestreamManager.NAMESPACE);
    }

    for (final String namespace : namespaces) {
      if (isEnabled) {
        if (!manager.includesFeature(namespace)) {
          manager.addFeature(namespace);
        }
      } else {
        manager.removeFeature(namespace);
      }
    }
  }
 private void initProxies() {
   proxies = new ArrayList<String>();
   ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection);
   try {
     DiscoverItems discoItems = manager.discoverItems(connection.getServiceName());
     Iterator it = discoItems.getItems();
     while (it.hasNext()) {
       DiscoverItems.Item item = (DiscoverItems.Item) it.next();
       String proxy = checkIsProxy(manager, item);
       if (proxy != null) {
         proxies.add(proxy);
       }
     }
   } catch (XMPPException e) {
     return;
   }
   if (proxies.size() > 0) {
     initStreamHosts();
   }
 }
Пример #28
0
 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;
 }
Пример #29
0
  /**
   * 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;
    }
  }
 /**
  * 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;
 }