예제 #1
0
 public final void connectionCreated(XMPPConnection connection) {
   ServiceDiscoveryManager.getInstanceFor(connection)
       .addFeature("http://jabber.org/protocol/muc");
   ServiceDiscoveryManager.getInstanceFor(connection)
       .setNodeInformationProvider(
           "http://jabber.org/protocol/muc#rooms", new C13301(new WeakReference(connection)));
 }
예제 #2
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(XMPPConnection connection, boolean enabled) {
    if (isServiceEnabled(connection) == enabled) return;

    if (enabled) {
      ServiceDiscoveryManager.getInstanceFor(connection).addFeature(namespace);
    } else {
      ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(namespace);
    }
  }
예제 #3
0
  /**
   * The workgroup service may be configured to send email. This queries the Workgroup Service to
   * see if the email service has been configured and is available.
   *
   * @return true if the email service is available, otherwise return false.
   */
  public boolean isEmailAvailable() {
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);

    try {
      String workgroupService = StringUtils.parseServer(workgroupJID);
      DiscoverInfo infoResult = discoManager.discoverInfo(workgroupService);
      return infoResult.containsFeature("jive:email:provider");
    } catch (XMPPException e) {
      return false;
    }
  }
예제 #4
0
 private ChatStateManager(XMPPConnection xmppconnection)
 {
     super(xmppconnection);
     chatManager = ChatManager.getInstanceFor(xmppconnection);
     chatManager.addOutgoingMessageInterceptor(outgoingInterceptor, filter);
     chatManager.addChatListener(incomingInterceptor);
     ServiceDiscoveryManager.getInstanceFor(xmppconnection).addFeature("http://jabber.org/protocol/chatstates");
     INSTANCES.put(xmppconnection, this);
 }
예제 #5
0
  @Before
  public void setUp() throws Exception {
    // Uncomment this to enable debug output
    // XMPPConnection.DEBUG_ENABLED = true;

    connection = new DummyConnection();
    connection.connect();
    connection.login("me", "secret");
    ServiceDiscoveryManager.getInstanceFor(connection);
  }
예제 #6
0
 /**
  * Returns true if XMPP Carbons are supported by the server.
  *
  * @return true if supported
  */
 public boolean isSupportedByServer() {
   Connection connection = weakRefConnection.get();
   try {
     DiscoverInfo result =
         ServiceDiscoveryManager.getInstanceFor(connection)
             .discoverInfo(connection.getServiceName());
     return result.containsFeature(CarbonExtension.NAMESPACE);
   } catch (XMPPException e) {
     return false;
   }
 }
예제 #7
0
  /**
   * Returns the address of the multiple recipients service. To obtain such address service
   * discovery is going to be used on the connected server and if none was found then another
   * attempt will be tried on the server items. The discovered information is going to be cached for
   * 24 hours.
   *
   * @param connection the connection to use for disco. The connected server is going to be queried.
   * @return the address of the multiple recipients service or <tt>null</tt> if none was found.
   */
  private static String getMultipleRecipienServiceAddress(Connection connection) {
    String serviceName = connection.getServiceName();
    String serviceAddress = (String) services.get(serviceName);
    if (serviceAddress == null) {
      synchronized (services) {
        serviceAddress = (String) services.get(serviceName);
        if (serviceAddress == null) {

          // Send the disco packet to the server itself
          try {
            DiscoverInfo info =
                ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(serviceName);
            // Check if the server supports JEP-33
            if (info.containsFeature("http://jabber.org/protocol/address")) {
              serviceAddress = serviceName;
            } else {
              // Get the disco items and send the disco packet to each server item
              DiscoverItems items =
                  ServiceDiscoveryManager.getInstanceFor(connection).discoverItems(serviceName);
              for (Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); ) {
                DiscoverItems.Item item = it.next();
                info =
                    ServiceDiscoveryManager.getInstanceFor(connection)
                        .discoverInfo(item.getEntityID(), item.getNode());
                if (info.containsFeature("http://jabber.org/protocol/address")) {
                  serviceAddress = serviceName;
                  break;
                }
              }
            }
            // Cache the discovered information
            services.put(serviceName, serviceAddress == null ? "" : serviceAddress);
          } catch (XMPPException e) {
            LOGGER.log(Level.SEVERE, "Error occurred retrieving multiple recipients service", e);
          }
        }
      }
    }

    return "".equals(serviceAddress) ? null : serviceAddress;
  }
 private CarbonManager(XMPPConnection connection) {
   super(connection);
   ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
   sdm.addFeature(CarbonExtension.NAMESPACE);
 }
 /**
  * Returns true if XMPP Carbons are supported by the server.
  *
  * @return true if supported
  * @throws NotConnectedException
  * @throws XMPPErrorException
  * @throws NoResponseException
  */
 public boolean isSupportedByServer()
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   return ServiceDiscoveryManager.getInstanceFor(connection())
       .serverSupportsFeature(CarbonExtension.NAMESPACE);
 }
예제 #10
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
  * @throws XMPPErrorException
  * @throws NoResponseException
  * @throws NotConnectedException
  */
 public static boolean isServiceEnabled(XMPPConnection connection, String userID)
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(userID, namespace);
 }
예제 #11
0
 /**
  * Returns true if the XHTML support is enabled for the given connection.
  *
  * @param connection the connection to look for XHTML support
  * @return a boolean indicating if the XHTML support is enabled for the given connection
  */
 public static boolean isServiceEnabled(XMPPConnection connection) {
   return ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(namespace);
 }
예제 #12
0
 public boolean isSupported(String str) {
   return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(str, NAMESPACE);
 }
예제 #13
0
 private VCardManager(XMPPConnection xMPPConnection) {
   super(xMPPConnection);
   ServiceDiscoveryManager.getInstanceFor(xMPPConnection).addFeature(NAMESPACE);
 }
예제 #14
0
 private CarbonManager(Connection connection) {
   ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
   sdm.addFeature(CarbonExtension.NAMESPACE);
   weakRefConnection = new WeakReference<Connection>(connection);
   instances.put(connection, this);
 }
  public static void initialize(final XMPPConnection theConnection, final History h) {
    final String jid = XmppStringUtils.parseBareJid(theConnection.getUser());
    // Hash fetch service
    theConnection.registerIQRequestHandler(
        new IQRequestHandler() {

          @Override
          public IQ handleIQRequest(IQ iqRequest) {
            HistorySyncQuery query = (HistorySyncQuery) iqRequest;
            if (query.getType() != IQ.Type.get) {
              throw new Error();
            }
            if (!XmppStringUtils.parseBareJid(iqRequest.getFrom()).equals(jid)) {
              return error(query);
            }

            HistorySyncHashes response = query.reply(h);
            return response;
          }

          @Override
          public Mode getMode() {
            return Mode.async;
          }

          @Override
          public Type getType() {
            return Type.get;
          }

          @Override
          public String getElement() {
            return "query";
          }

          @Override
          public String getNamespace() {
            return "http://jlenet.de/histsync";
          }
        });

    // sync service
    theConnection.registerIQRequestHandler(
        new IQRequestHandler() {
          @Override
          public IQ handleIQRequest(IQ iqRequest) {
            HistorySyncSet sync = (HistorySyncSet) iqRequest;
            if (!XmppStringUtils.parseBareJid(iqRequest.getFrom()).equals(jid)) {
              return error(sync);
            }

            if (Debug.ENABLED) {
              System.out.println("sync pack");
            }
            HistoryLeafNode hln =
                (HistoryLeafNode) h.getAnyBlock(sync.getHour() * History.BASE, History.LEVELS);
            if (Debug.ENABLED) {
              System.out.println("Have: " + hln.getMessages().size());
              System.out.println("Got: " + sync.getMessages().size());
            }
            TreeSet<HistoryEntry> forMe = new TreeSet<HistoryEntry>();
            TreeSet<HistoryEntry> forOther = new TreeSet<HistoryEntry>();
            Iterator<HistoryEntry> have = hln.getMessages().iterator();
            Iterator<HistoryEntry> got = sync.getMessages().iterator();
            HistoryEntry currentGot = null;
            HistoryEntry currentHave = null;
            while (have.hasNext() || got.hasNext() || currentHave != null || currentGot != null) {
              if (currentGot == null && got.hasNext()) {
                currentGot = got.next();
              }
              if (currentHave == null && have.hasNext()) {
                currentHave = have.next();
              }
              if (currentHave == null && currentGot == null) {
                // Should never happen;
                System.out.println("this should never happen");
                break;
              }
              if (currentGot == null
                  || (currentHave != null && currentHave.compareTo(currentGot) < 0)) {
                // current Have is alone
                forOther.add(currentHave);
                currentHave = null;
              } else if (currentHave == null || currentHave.compareTo(currentGot) > 0) {
                // current Got is alone
                forMe.add(currentGot);
                currentGot = null;
              } else {
                currentHave = null;
                currentGot = null;
              }
            }
            hln.getMessages().addAll(forMe);
            h.modified(sync.getHour() * History.BASE);
            // Construct response
            HistorySyncSet hss =
                new HistorySyncSet(
                    sync.getHour(), History.beautifyChecksum(hln.getChecksum()), false);
            hss.setMessages(forOther);
            hss.setType(IQ.Type.result);
            hss.setTo(sync.getFrom());
            hss.setStanzaId(sync.getStanzaId());
            h.store();

            if (Debug.ENABLED) {
              System.out.println("now Have: " + hln.getMessages().size());
              System.out.println("adding: " + forMe.size());
              System.out.println("for other: " + forOther.size());
            }
            return hss;
          }

          @Override
          public Mode getMode() {
            return Mode.async;
          }

          @Override
          public Type getType() {
            return Type.set;
          }

          @Override
          public String getElement() {
            return "syncSet";
          }

          @Override
          public String getNamespace() {
            return "http://jlenet.de/histsync#syncSet";
          }
        });
    theConnection.registerIQRequestHandler(
        new IQRequestHandler() {

          @Override
          public IQ handleIQRequest(IQ iqRequest) {
            HistorySyncSet sync = (HistorySyncSet) iqRequest;
            if (!XmppStringUtils.parseBareJid(iqRequest.getFrom()).equals(jid)) {
              return error(sync);
            }
            HistoryLeafNode hln =
                (HistoryLeafNode) h.getAnyBlock(sync.getHour() * History.BASE, History.LEVELS);
            if (Debug.ENABLED) {
              System.out.println("Have: " + hln.getMessages().size());
              System.out.println("Got: " + sync.getMessages().size());
            }

            hln.getMessages().addAll(sync.getMessages());
            h.modified(sync.getHour() * History.BASE);
            h.store();

            byte[] myChecksum = hln.getChecksum();
            String status;
            if (!Arrays.equals(myChecksum, History.parseChecksum(sync.getChecksum()))) {
              status = "success";
            } else {
              status = "mismatch";
            }
            HistorySyncUpdateResponse hss = new HistorySyncUpdateResponse(status);
            hss.setType(IQ.Type.result);
            hss.setTo(sync.getFrom());
            hss.setStanzaId(sync.getStanzaId());
            if (Debug.ENABLED) {
              System.out.println("update was: " + status);
            }
            if (Debug.ENABLED) {
              System.out.println("now Have: " + hln.getMessages().size());
            }
            return hss;
          }

          @Override
          public Type getType() {
            return Type.set;
          }

          @Override
          public Mode getMode() {
            return Mode.async;
          }

          @Override
          public String getElement() {
            return "syncUpdate";
          }

          @Override
          public String getNamespace() {
            return "http://jlenet.de/histsync#syncUpdate";
          }
        });

    ProviderManager.addIQProvider(
        "query", "http://jlenet.de/histsync", new HistorySyncQueryProvider());
    ProviderManager.addIQProvider(
        "hashes", "http://jlenet.de/histsync#hashes", new HistorySyncResponseProvider());

    HistorySyncSetProvider setProvider = new HistorySyncSetProvider();
    ProviderManager.addIQProvider("syncSet", "http://jlenet.de/histsync#syncSet", setProvider);
    ProviderManager.addIQProvider(
        "syncUpdate", "http://jlenet.de/histsync#syncUpdate", setProvider);
    ProviderManager.addIQProvider(
        "syncStatus",
        "http://jlenet.de/histsync#syncStatus",
        new HistorySyncUpdateResponse.Provider());

    ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(theConnection);
    manager.addFeature("http://jlenet.de/histsync#disco");
  }