/**
   * Get a reference to the basic IM operation set.
   *
   * @throws Exception if this is not a good day.
   */
  protected void setUp() throws Exception {
    super.setUp();
    fixture.setUp();

    Map supportedOperationSets = fixture.provider.getSupportedOperationSets();

    if (supportedOperationSets == null || supportedOperationSets.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this ICQ implementation. ");

    // get the operation set presence here.
    opSetBasicIM =
        (OperationSetBasicInstantMessaging)
            supportedOperationSets.get(OperationSetBasicInstantMessaging.class.getName());

    // if the op set is null then the implementation doesn't offer a typing.
    // operation set which is unacceptable for icq.
    if (opSetBasicIM == null) {
      throw new NullPointerException("No implementation for basic IM was found");
    }

    // we also need the presence op set in order to retrieve contacts.
    opSetPresence =
        (OperationSetPresence) supportedOperationSets.get(OperationSetPresence.class.getName());

    // if the op set is null show that we're not happy.
    if (opSetPresence == null) {
      throw new NullPointerException(
          "An implementation of the ICQ service must provide an "
              + "implementation of at least one of the PresenceOperationSets");
    }
  }
  /**
   * Get a reference to the basic IM operation set.
   *
   * @throws Exception if this is not a good day.
   */
  protected void setUp() throws Exception {
    super.setUp();
    fixture.setUp();

    Map<String, OperationSet> supportedOperationSets1 =
        fixture.provider1.getSupportedOperationSets();

    if (supportedOperationSets1 == null || supportedOperationSets1.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this implementation. ");

    // get the operation set presence here.
    opSetBasicIM1 =
        (OperationSetBasicInstantMessaging)
            supportedOperationSets1.get(OperationSetBasicInstantMessaging.class.getName());

    if (opSetBasicIM1 == null) {
      throw new NullPointerException("No implementation for basic IM was found");
    }

    // we also need the presence op set in order to retrieve contacts.
    opSetPresence1 =
        (OperationSetPresence) supportedOperationSets1.get(OperationSetPresence.class.getName());

    // if the op set is null show that we're not happy.
    if (opSetPresence1 == null) {
      throw new NullPointerException(
          "An implementation of the service must provide an "
              + "implementation of at least one of the PresenceOperationSets");
    }

    Map<String, OperationSet> supportedOperationSets2 =
        fixture.provider2.getSupportedOperationSets();

    if (supportedOperationSets2 == null || supportedOperationSets2.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this implementation. ");

    // get the operation set presence here.
    opSetBasicIM2 =
        (OperationSetBasicInstantMessaging)
            supportedOperationSets2.get(OperationSetBasicInstantMessaging.class.getName());

    if (opSetBasicIM2 == null) {
      throw new NullPointerException("No implementation for basic IM was found");
    }

    opSetPresence2 =
        (OperationSetPresence) supportedOperationSets2.get(OperationSetPresence.class.getName());

    // if the op set is null show that we're not happy.
    if (opSetPresence2 == null) {
      throw new NullPointerException(
          "An implementation of the service must provide an "
              + "implementation of at least one of the PresenceOperationSets");
    }
  }
Пример #3
0
  /**
   * Loads the list of enabled and disabled encryption protocols with their priority.
   *
   * @param enabledEncryptionProtocols The list of enabled encryption protocol available for this
   *     account.
   * @param disabledEncryptionProtocols The list of disabled encryption protocol available for this
   *     account.
   */
  private void loadEncryptionProtocols(
      Map<String, Integer> encryptionProtocols, Map<String, Boolean> encryptionProtocolStatus) {
    int nbEncryptionProtocols = ENCRYPTION_PROTOCOLS.length;
    String[] encryptions = new String[nbEncryptionProtocols];
    boolean[] selectedEncryptions = new boolean[nbEncryptionProtocols];

    // Load stored values.
    int prefixeLength = ProtocolProviderFactory.ENCRYPTION_PROTOCOL.length() + 1;
    String encryptionProtocolPropertyName;
    String name;
    int index;
    boolean enabled;
    Iterator<String> encryptionProtocolNames = encryptionProtocols.keySet().iterator();
    while (encryptionProtocolNames.hasNext()) {
      encryptionProtocolPropertyName = encryptionProtocolNames.next();
      index = encryptionProtocols.get(encryptionProtocolPropertyName);
      // If the property is set.
      if (index != -1) {
        name = encryptionProtocolPropertyName.substring(prefixeLength);
        if (isExistingEncryptionProtocol(name)) {
          enabled =
              encryptionProtocolStatus.get(
                  ProtocolProviderFactory.ENCRYPTION_PROTOCOL_STATUS + "." + name);
          encryptions[index] = name;
          selectedEncryptions[index] = enabled;
        }
      }
    }

    // Load default values.
    String encryptionProtocol;
    boolean set;
    int j = 0;
    for (int i = 0; i < ENCRYPTION_PROTOCOLS.length; ++i) {
      encryptionProtocol = ENCRYPTION_PROTOCOLS[i];
      // Specify a default value only if there is no specific value set.
      if (!encryptionProtocols.containsKey(
          ProtocolProviderFactory.ENCRYPTION_PROTOCOL + "." + encryptionProtocol)) {
        set = false;
        // Search for the first empty element.
        while (j < encryptions.length && !set) {
          if (encryptions[j] == null) {
            encryptions[j] = encryptionProtocol;
            // By default only ZRTP is set to true.
            selectedEncryptions[j] = encryptionProtocol.equals("ZRTP");
            set = true;
          }
          ++j;
        }
      }
    }

    this.encryptionConfigurationTableModel.init(encryptions, selectedEncryptions);
  }
  /**
   * Initializes and creates an account corresponding to the specified accountProperties and
   * registers the resulting ProtocolProvider in the <tt>context</tt> BundleContext parameter.
   *
   * @param accountProperties a set of protocol (or implementation) specific properties defining the
   *     new account.
   * @return the AccountID of the newly created account
   */
  protected AccountID loadAccount(Map accountProperties) {
    BundleContext context = SipActivator.getBundleContext();
    if (context == null) throw new NullPointerException("The specified BundleContext was null");

    String userIDStr = (String) accountProperties.get(USER_ID);
    if (userIDStr == null)
      throw new NullPointerException("The account properties contained no user id.");

    if (accountProperties == null)
      throw new NullPointerException("The specified property map was null");

    String serverAddress = (String) accountProperties.get(SERVER_ADDRESS);

    if (serverAddress == null)
      throw new NullPointerException(serverAddress + " is not a valid ServerAddress");

    if (!accountProperties.containsKey(PROTOCOL))
      accountProperties.put(PROTOCOL, ProtocolNames.SIP);

    SipAccountID accountID = new SipAccountID(userIDStr, accountProperties, serverAddress);

    // get a reference to the configuration service and register whatever
    // properties we have in it.

    Hashtable properties = new Hashtable();
    properties.put(PROTOCOL, ProtocolNames.SIP);
    properties.put(USER_ID, userIDStr);

    ProtocolProviderServiceSipImpl sipProtocolProvider = new ProtocolProviderServiceSipImpl();

    try {
      sipProtocolProvider.initialize(userIDStr, accountID);

      // We store again the account in order to store all properties added
      // during the protocol provider initialization.
      this.storeAccount(SipActivator.getBundleContext(), accountID);
    } catch (OperationFailedException ex) {
      logger.error("Failed to initialize account", ex);
      throw new IllegalArgumentException("Failed to initialize account" + ex.getMessage());
    }

    ServiceRegistration registration =
        context.registerService(
            ProtocolProviderService.class.getName(), sipProtocolProvider, properties);

    registeredAccounts.put(accountID, registration);
    return accountID;
  }
Пример #5
0
  /**
   * Remove records telling what entity caps node a contact has.
   *
   * @param contact the contact
   */
  public void removeContactCapsNode(Contact contact) {
    Caps caps = null;
    String lastRemovedJid = null;

    Iterator<String> iter = userCaps.keySet().iterator();
    while (iter.hasNext()) {
      String jid = iter.next();

      if (StringUtils.parseBareAddress(jid).equals(contact.getAddress())) {
        caps = userCaps.get(jid);
        lastRemovedJid = jid;
        iter.remove();
      }
    }

    // fire only for the last one, at the end the event out
    // of the protocol will be one and for the contact
    if (caps != null) {
      UserCapsNodeListener[] listeners;
      synchronized (userCapsNodeListeners) {
        listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS);
      }
      if (listeners.length != 0) {
        String nodeVer = caps.getNodeVer();

        for (UserCapsNodeListener listener : listeners)
          listener.userCapsNodeRemoved(lastRemovedJid, nodeVer, false);
      }
    }
  }
Пример #6
0
  /**
   * Add a record telling what entity caps node a user has.
   *
   * @param user the user (Full JID)
   * @param node the node (of the caps packet extension)
   * @param hash the hashing algorithm used to calculate <tt>ver</tt>
   * @param ver the version (of the caps packet extension)
   * @param ext the ext (of the caps packet extension)
   * @param online indicates if the user is online
   */
  private void addUserCapsNode(
      String user, String node, String hash, String ver, String ext, boolean online) {
    if ((user != null) && (node != null) && (hash != null) && (ver != null)) {
      Caps caps = userCaps.get(user);

      if ((caps == null)
          || !caps.node.equals(node)
          || !caps.hash.equals(hash)
          || !caps.ver.equals(ver)) {
        caps = new Caps(node, hash, ver, ext);

        userCaps.put(user, caps);
      } else return;

      // Fire userCapsNodeAdded.
      UserCapsNodeListener[] listeners;

      synchronized (userCapsNodeListeners) {
        listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS);
      }
      if (listeners.length != 0) {
        String nodeVer = caps.getNodeVer();

        for (UserCapsNodeListener listener : listeners)
          listener.userCapsNodeAdded(user, nodeVer, online);
      }
    }
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    fixture.setUp();

    Map<String, OperationSet> supportedOperationSets1 =
        fixture.provider1.getSupportedOperationSets();

    if (supportedOperationSets1 == null || supportedOperationSets1.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this Gibberish implementation. ");

    // get the operation set presence here.
    opSetPersPresence1 =
        (OperationSetPersistentPresence)
            supportedOperationSets1.get(OperationSetPersistentPresence.class.getName());

    // if still null then the implementation doesn't offer a presence
    // operation set which is unacceptable for gibberish.
    if (opSetPersPresence1 == null)
      throw new NullPointerException(
          "An implementation of the gibberish service must provide an "
              + "implementation of at least the one of the Presence "
              + "Operation Sets");

    // lets do it once again for the second provider
    Map<String, OperationSet> supportedOperationSets2 =
        fixture.provider2.getSupportedOperationSets();

    if (supportedOperationSets2 == null || supportedOperationSets2.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this Gibberish implementation. ");

    // get the operation set presence here.
    opSetPersPresence2 =
        (OperationSetPersistentPresence)
            supportedOperationSets2.get(OperationSetPersistentPresence.class.getName());

    // if still null then the implementation doesn't offer a presence
    // operation set which is unacceptable for Gibberish.
    if (opSetPersPresence2 == null)
      throw new NullPointerException(
          "An implementation of the Gibberish service must provide an "
              + "implementation of at least the one of the Presence "
              + "Operation Sets");
  }
Пример #8
0
  /**
   * Returns {@link JitsiMeetConference} for given MUC {@code roomName} or {@code null} if no
   * conference has been allocated yet.
   *
   * @param roomName the name of MUC room for which we want get the {@code JitsiMeetConference}
   *     instance.
   * @return the {@code JitsiMeetConference} for the specified {@code roomName} or {@code null} if
   *     no conference has been allocated yet
   */
  public JitsiMeetConference getConference(String roomName) {
    roomName = roomName.toLowerCase();

    // Other public methods which read from and/or write to the field
    // conferences are sychronized (e.g. conferenceEnded, conferenceRequest)
    // so synchronization is necessary here as well.
    synchronized (this) {
      return conferences.get(roomName);
    }
  }
  /**
   * Returns the last jid that the party with the specified <tt>address</tt> contacted us from or
   * <tt>null</tt>(or bare jid) if we don't have a jid for the specified <tt>address</tt> yet. The
   * method would also purge all entries that haven't seen any activity (i.e. no one has tried to
   * get or remap it) for a delay longer than <tt>JID_INACTIVITY_TIMEOUT</tt>.
   *
   * @param jid the <tt>jid</tt> that we'd like to obtain a threadID for.
   * @return the last jid that the party with the specified <tt>address</tt> contacted us from or
   *     <tt>null</tt> if we don't have a jid for the specified <tt>address</tt> yet.
   */
  String getThreadIDForAddress(String jid) {
    synchronized (jids) {
      purgeOldJids();
      StoredThreadID ta = jids.get(jid);

      if (ta == null) return null;

      ta.lastUpdatedTime = System.currentTimeMillis();

      return ta.threadID;
    }
  }
Пример #10
0
  /**
   * Allocates new focus for given MUC room.
   *
   * @param room the name of MUC room for which new conference has to be allocated.
   * @param properties configuration properties map included in the request.
   * @return <tt>true</tt> if conference focus is in the room and ready to handle session
   *     participants.
   * @throws Exception if for any reason we have failed to create the conference
   */
  public synchronized boolean conferenceRequest(String room, Map<String, String> properties)
      throws Exception {
    if (StringUtils.isNullOrEmpty(room)) return false;

    if (shutdownInProgress && !conferences.containsKey(room)) return false;

    if (!conferences.containsKey(room)) {
      createConference(room, properties);
    }

    JitsiMeetConference conference = conferences.get(room);

    return conference.isInTheRoom();
  }
  /**
   * Determines whether the protocol supports the supplied content type for the given contact.
   *
   * @param contentType the type we want to check
   * @param contact contact which is checked for supported contentType
   * @return <tt>true</tt> if the contact supports it and <tt>false</tt> otherwise.
   */
  @Override
  public boolean isContentTypeSupported(String contentType, Contact contact) {
    // by default we support default mime type, for other mimetypes
    // method must be overriden
    if (contentType.equals(DEFAULT_MIME_TYPE)) return true;
    else if (contentType.equals(HTML_MIME_TYPE)) {
      String toJID = recentJIDForAddress.get(contact.getAddress());

      if (toJID == null) toJID = contact.getAddress();

      return jabberProvider.isFeatureListSupported(toJID, HTML_NAMESPACE);
    }

    return false;
  }
  /**
   * Maps the specified <tt>address</tt> to <tt>jid</tt>. The point of this method is to allow us to
   * send all messages destined to the contact with the specified <tt>address</tt> to the
   * <tt>jid</tt> that they last contacted us from.
   *
   * @param threadID the threadID of conversation.
   * @param jid the jid (i.e. address/resource) that the contact with the specified <tt>address</tt>
   *     last contacted us from.
   */
  private void putJidForAddress(String jid, String threadID) {
    synchronized (jids) {
      purgeOldJids();

      StoredThreadID ta = jids.get(jid);

      if (ta == null) {
        ta = new StoredThreadID();
        jids.put(jid, ta);
      }

      recentJIDForAddress.put(StringUtils.parseBareAddress(jid), jid);

      ta.lastUpdatedTime = System.currentTimeMillis();
      ta.threadID = threadID;
    }
  }
Пример #13
0
  /**
   * Applies this filter. This filter is applied over the <tt>MetaContactListService</tt>.
   *
   * @param filterQuery the query which keeps track of the filtering results
   */
  public void applyFilter(FilterQuery filterQuery) {
    // Create the query that will track filtering.
    MetaContactQuery query = new MetaContactQuery();

    // Add this query to the filterQuery.
    filterQuery.addContactQuery(query);

    for (int cssType : contactSourcePreferences.keySet()) {
      Iterator<UIContactSource> filterSources =
          GuiActivator.getContactList().getContactSources(cssType).iterator();

      while (filterSources.hasNext()) {
        UIContactSource filterSource = filterSources.next();

        Integer prefValue = contactSourcePreferences.get(cssType);
        // We are setting the index from contactSourcePreferences map to
        // the contact source. This index is set to reorder the sources
        // in the contact list.
        if (prefValue != null) filterSource.setContactSourceIndex(prefValue);

        ContactSourceService sourceService = filterSource.getContactSourceService();

        ContactQuery contactQuery = sourceService.createContactQuery(null);

        // Add this query to the filterQuery.
        filterQuery.addContactQuery(contactQuery);

        contactQuery.addContactQueryListener(GuiActivator.getContactList());

        contactQuery.start();
      }
    }

    // Closes this filter to indicate that we finished adding queries to it.
    filterQuery.close();

    query.addContactQueryListener(GuiActivator.getContactList());
    int resultCount = 0;

    addMatching(GuiActivator.getContactListService().getRoot(), query, resultCount);

    query.fireQueryEvent(
        query.isCanceled()
            ? MetaContactQueryStatusEvent.QUERY_CANCELED
            : MetaContactQueryStatusEvent.QUERY_COMPLETED);
  }
  /**
   * Initializes and creates an account corresponding to the specified accountProperties and
   * registers the resulting ProtocolProvider in the <tt>context</tt> BundleContext parameter.
   *
   * @param userIDStr the user identifier uniquely representing the newly created account within the
   *     protocol namespace.
   * @param accountProperties a set of protocol (or implementation) specific properties defining the
   *     new account.
   * @return the AccountID of the newly created account.
   * @throws IllegalArgumentException if userID does not correspond to an identifier in the context
   *     of the underlying protocol or if accountProperties does not contain a complete set of
   *     account installation properties.
   * @throws IllegalStateException if the account has already been installed.
   * @throws NullPointerException if any of the arguments is null.
   */
  public AccountID installAccount(String userIDStr, Map accountProperties) {
    BundleContext context = SipActivator.getBundleContext();
    if (context == null) throw new NullPointerException("The specified BundleContext was null");

    if (userIDStr == null) throw new NullPointerException("The specified AccountID was null");

    accountProperties.put(USER_ID, userIDStr);

    if (accountProperties == null)
      throw new NullPointerException("The specified property map was null");

    String serverAddress = (String) accountProperties.get(SERVER_ADDRESS);

    if (serverAddress == null) throw new NullPointerException("null is not a valid ServerAddress");

    if (!accountProperties.containsKey(PROTOCOL))
      accountProperties.put(PROTOCOL, ProtocolNames.SIP);

    AccountID accountID = new SipAccountID(userIDStr, accountProperties, serverAddress);

    // make sure we haven't seen this account id before.
    if (registeredAccounts.containsKey(accountID))
      throw new IllegalStateException("An account for id " + userIDStr + " was already installed!");

    // first store the account and only then load it as the load generates
    // an osgi event, the osgi event triggers (trhgough the UI) a call to
    // the register() method and it needs to acces the configuration service
    // and check for a password.
    this.storeAccount(SipActivator.getBundleContext(), accountID);

    try {
      accountID = loadAccount(accountProperties);
    } catch (RuntimeException exc) {
      // it might happen that load-ing the account fails because of a bad
      // initialization. if this is the case, make sure we remove it.
      this.removeStoredAccount(SipActivator.getBundleContext(), accountID);

      throw exc;
    }

    return accountID;
  }
  protected void setUp() throws Exception {
    super.setUp();
    fixture.setUp();

    Map<String, OperationSet> supportedOperationSets = fixture.provider.getSupportedOperationSets();

    if (supportedOperationSets == null || supportedOperationSets.size() < 1)
      throw new NullPointerException(
          "No OperationSet implementations are supported by " + "this ICQ implementation. ");

    // get the operation set presence here.
    operationSetPresence =
        (OperationSetPresence) supportedOperationSets.get(OperationSetPresence.class.getName());

    // if the op set is null then the implementation doesn't offer a presence
    // operation set which is unacceptable for icq.
    if (operationSetPresence == null) {
      throw new NullPointerException(
          "An implementation of the ICQ service must provide an "
              + "implementation of at least the one of the Presence "
              + "Operation Sets");
    }
  }
Пример #16
0
 /**
  * Gets the <tt>Caps</tt> i.e. the node, the hash and the ver of a user.
  *
  * @param user the user (Full JID)
  * @return the <tt>Caps</tt> i.e. the node, the hash and the ver of <tt>user</tt>
  */
 public Caps getCapsByUser(String user) {
   return userCaps.get(user);
 }
 public String getRecentJIDForAddress(String address) {
   return recentJIDForAddress.get(address);
 }
Пример #18
0
 /**
  * Returns {@link JitsiMeetConference} for given MUC <tt>roomName</tt> or <tt>null</tt> if no
  * conference has been allocated yet.
  *
  * @param roomName the name of MUC room for which we want get the {@link JitsiMeetConference}
  *     instance.
  */
 public JitsiMeetConference getConference(String roomName) {
   return conferences.get(roomName);
 }
Пример #19
0
  /**
   * Get the discover info given a user name. The discover info is returned if the user has a
   * node#ver associated with it and the node#ver has a discover info associated with it.
   *
   * @param user user name (Full JID)
   * @return the discovered info
   */
  public DiscoverInfo getDiscoverInfoByUser(String user) {
    Caps caps = userCaps.get(user);

    return (caps == null) ? null : getDiscoverInfoByCaps(caps);
  }
Пример #20
0
  /**
   * Retrieve DiscoverInfo for a specific node.
   *
   * @param caps the <tt>Caps</tt> i.e. the node, the hash and the ver
   * @return The corresponding DiscoverInfo or null if none is known.
   */
  public static DiscoverInfo getDiscoverInfoByCaps(Caps caps) {
    synchronized (caps2discoverInfo) {
      DiscoverInfo discoverInfo = caps2discoverInfo.get(caps);

      /*
       * If we don't have the discoverInfo in the runtime cache yet, we
       * may have it remembered in a previous application instance.
       */
      if (discoverInfo == null) {
        ConfigurationService configurationService = getConfigService();
        String capsPropertyName = getCapsPropertyName(caps);
        String xml = configurationService.getString(capsPropertyName);

        if ((xml != null) && (xml.length() != 0)) {
          IQProvider discoverInfoProvider =
              (IQProvider)
                  ProviderManager.getInstance()
                      .getIQProvider("query", "http://jabber.org/protocol/disco#info");

          if (discoverInfoProvider != null) {
            XmlPullParser parser = new MXParser();

            try {
              parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
              parser.setInput(new StringReader(xml));
              // Start the parser.
              parser.next();
            } catch (XmlPullParserException xppex) {
              parser = null;
            } catch (IOException ioex) {
              parser = null;
            }

            if (parser != null) {
              try {
                discoverInfo = (DiscoverInfo) discoverInfoProvider.parseIQ(parser);
              } catch (Exception ex) {
              }

              if (discoverInfo != null) {
                if (caps.isValid(discoverInfo)) caps2discoverInfo.put(caps, discoverInfo);
                else {
                  logger.error(
                      "Invalid DiscoverInfo for " + caps.getNodeVer() + ": " + discoverInfo);
                  /*
                   * The discoverInfo doesn't seem valid
                   * according to the caps which means that we
                   * must have stored invalid information.
                   * Delete the invalid information in order
                   * to not try to validate it again.
                   */
                  configurationService.removeProperty(capsPropertyName);
                }
              }
            }
          }
        }
      }
      return discoverInfo;
    }
  }