Пример #1
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;
   }
 }
Пример #2
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;
  }
Пример #3
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));
  }
Пример #4
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));
  }
Пример #5
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));
  }
Пример #6
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());
  }
  /** Initialize the features provided by beem. */
  private void initFeatures() {
    ServiceDiscoveryManager.setIdentityName("Beem");
    ServiceDiscoveryManager.setIdentityType("phone");
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
    if (sdm == null) sdm = new ServiceDiscoveryManager(mAdaptee);

    sdm.addFeature("http://jabber.org/protocol/disco#info");
    // nikita: must be uncommented when the feature will be enabled
    // sdm.addFeature("jabber:iq:privacy");
    sdm.addFeature("http://jabber.org/protocol/caps");
    sdm.addFeature("urn:xmpp:avatar:metadata");
    sdm.addFeature("urn:xmpp:avatar:metadata+notify");
    sdm.addFeature("urn:xmpp:avatar:data");
    sdm.addFeature("http://jabber.org/protocol/nick");
    sdm.addFeature("http://jabber.org/protocol/nick+notify");
    sdm.addFeature(PingExtension.NAMESPACE);

    mChatStateManager = ChatStateManager.getInstance(mAdaptee);
    BeemCapsManager caps = new BeemCapsManager(sdm, mAdaptee, mService);
    caps.setNode("http://www.beem-project.com");
  }
  /**
   * 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);
      }
    }
  }
Пример #9
0
  public void startup() throws XMPPException {
    String host;
    Integer port;
    String service;

    synchronized (mDefaultSettings) {
      host = (String) mDefaultSettings.get("host");
      port = Integer.parseInt((String) mDefaultSettings.get("port"));
      service = (String) mDefaultSettings.get("service");
    }

    ConnectionConfiguration connConfig = new ConnectionConfiguration(host, port, service);
    mConnection = new XMPPConnection(connConfig);
    mConnection.connect();

    String password = null;
    String resource = null;

    synchronized (mDefaultSettings) {
      mJid = mDefaultSettings.get("username") + "@" + mDefaultSettings.get("service");
      password = (String) mDefaultSettings.get("password");
      resource = (String) mDefaultSettings.get("resource");
    }

    mConnection.login(mJid, password, resource);
    mConnection.addConnectionListener(this);

    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mConnection);

    // Set on every established connection that this client supports the Mobilis
    // protocol. This information will be used when another client tries to
    // discover whether this client supports Mobilis or not.
    try {
      sdm.addFeature(MobilisManager.discoNamespace);
    } catch (Exception e) {
      MobilisManager.getLogger().warning("Problem with ServiceDiscoveryManager: " + e.getMessage());
    }

    synchronized (mServices) {
      for (MobilisService ms : mServices) {
        try {
          ms.startup();
          sdm.setNodeInformationProvider(ms.getNode(), ms);
        } catch (Exception e) {
          MobilisManager.getLogger()
              .warning(
                  "Couldn't startup Mobilis Service ("
                      + ms.getIdent()
                      + ") because of "
                      + e.getClass().getName()
                      + ": "
                      + e.getMessage());
        }
      }
    }

    // Set the NodeInformationProvider that will provide information about the
    // offered services whenever a disco request is received
    try {
      sdm.setNodeInformationProvider(MobilisManager.discoServicesNode, this);
    } catch (Exception e) {
      MobilisManager.getLogger()
          .warning(
              "Problem with NodeInformationProvider: "
                  + MobilisManager.discoServicesNode
                  + " ("
                  + getIdent()
                  + ") "
                  + e.getMessage());
    }

    // try {
    //	String entityID = mJid;
    //	DiscoverItems discoverItems = new DiscoverItems();
    //	Item item = new Item(entityID);
    //	item.setAction(Item.UPDATE_ACTION);
    //	item.setName("Mobilis Agent");
    //	item.setNode(null);
    //	discoverItems.addItem(item);
    //	sdm.publishItems(entityID, discoverItems);
    // } catch (Exception e) {
    //	MobilisManager.getLogger().warning("Problem with ServiceDiscoveryManager: " +
    // e.getMessage());
    // }

    // logging
    MobilisManager.getLogger().info("Mobilis Agent (" + getIdent() + ") started up.");
  }