예제 #1
0
  /**
   * Converts the form field values in the <tt>ffValuesIter</tt> into a caps string.
   *
   * @param ffValuesIter the {@link Iterator} containing the form field values.
   * @param capsBldr a <tt>StringBuilder</tt> to which the caps string representing the form field
   *     values is to be appended
   */
  private static void formFieldValuesToCaps(Iterator<String> ffValuesIter, StringBuilder capsBldr) {
    SortedSet<String> fvs = new TreeSet<String>();

    while (ffValuesIter.hasNext()) fvs.add(ffValuesIter.next());

    for (String fv : fvs) capsBldr.append(fv).append('<');
  }
  /**
   * Closes given {@link #transportManagers} of this <tt>Conference</tt> and removes corresponding
   * channel bundle.
   */
  void closeTransportManager(TransportManager transportManager) {
    synchronized (transportManagers) {
      for (Iterator<IceUdpTransportManager> i = transportManagers.values().iterator();
          i.hasNext(); ) {
        if (i.next() == transportManager) {
          i.remove();
          // Presumably, we have a single association for
          // transportManager.
          break;
        }
      }

      // Close manager
      try {
        transportManager.close();
      } catch (Throwable t) {
        logger.warn(
            "Failed to close an IceUdpTransportManager of" + " conference " + getID() + "!", t);
        // The whole point of explicitly closing the
        // transportManagers of this Conference is to prevent memory
        // leaks. Hence, it does not make sense to possibly leave
        // TransportManagers open because a TransportManager has
        // failed to close.
        if (t instanceof InterruptedException) Thread.currentThread().interrupt();
        else if (t instanceof ThreadDeath) throw (ThreadDeath) t;
      }
    }
  }
예제 #3
0
  void filterServiceEventReceivers(
      final ServiceEvent evt, final Collection /*<ServiceListenerEntry>*/ receivers) {
    ArrayList srl = fwCtx.services.get(EventHook.class.getName());
    if (srl != null) {
      HashSet ctxs = new HashSet();
      for (Iterator ir = receivers.iterator(); ir.hasNext(); ) {
        ctxs.add(((ServiceListenerEntry) ir.next()).getBundleContext());
      }
      int start_size = ctxs.size();
      RemoveOnlyCollection filtered = new RemoveOnlyCollection(ctxs);

      for (Iterator i = srl.iterator(); i.hasNext(); ) {
        ServiceReferenceImpl sr = ((ServiceRegistrationImpl) i.next()).reference;
        EventHook eh = (EventHook) sr.getService(fwCtx.systemBundle);
        if (eh != null) {
          try {
            eh.event(evt, filtered);
          } catch (Exception e) {
            fwCtx.debug.printStackTrace(
                "Failed to call event hook  #" + sr.getProperty(Constants.SERVICE_ID), e);
          }
        }
      }
      // NYI, refactor this for speed!?
      if (start_size != ctxs.size()) {
        for (Iterator ir = receivers.iterator(); ir.hasNext(); ) {
          if (!ctxs.contains(((ServiceListenerEntry) ir.next()).getBundleContext())) {
            ir.remove();
          }
        }
      }
    }
  }
예제 #4
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);
      }
    }
  }
예제 #5
0
  void filterServiceReferences(
      BundleContextImpl bc,
      String service,
      String filter,
      boolean allServices,
      Collection /*<ServiceReference>*/ refs) {
    ArrayList srl = fwCtx.services.get(FindHook.class.getName());
    if (srl != null) {
      RemoveOnlyCollection filtered = new RemoveOnlyCollection(refs);

      for (Iterator i = srl.iterator(); i.hasNext(); ) {
        ServiceReferenceImpl sr = ((ServiceRegistrationImpl) i.next()).reference;
        FindHook fh = (FindHook) sr.getService(fwCtx.systemBundle);
        if (fh != null) {
          try {
            fh.find(bc, service, filter, allServices, filtered);
          } catch (Exception e) {
            fwCtx.listeners.frameworkError(
                bc,
                new BundleException(
                    "Failed to call find hook  #" + sr.getProperty(Constants.SERVICE_ID), e));
          }
        }
      }
    }
  }
예제 #6
0
 /**
  * Returns the index of the contact in the contact results list.
  *
  * @param contact the contact.
  * @return the index of the contact in the contact results list.
  */
 public synchronized int indexOf(ChatRoomSourceContact contact) {
   Iterator<ChatRoomSourceContact> it = contactResults.iterator();
   int i = 0;
   while (it.hasNext()) {
     if (contact.equals(it.next())) {
       return i;
     }
     i++;
   }
   return -1;
 }
예제 #7
0
  @Override
  protected void run() {
    Iterator<ChatRoomProviderWrapper> chatRoomProviders = mucService.getChatRoomProviders();

    while (chatRoomProviders.hasNext()) {
      ChatRoomProviderWrapper provider = chatRoomProviders.next();
      providerAdded(provider, true);
    }

    if (getStatus() != QUERY_CANCELED) setStatus(QUERY_COMPLETED);
  }
  /** Closes the {@link #transportManagers} of this <tt>Conference</tt>. */
  private void closeTransportManagers() {
    synchronized (transportManagers) {
      for (Iterator<IceUdpTransportManager> i = transportManagers.values().iterator();
          i.hasNext(); ) {
        IceUdpTransportManager transportManager = i.next();

        i.remove();
        closeTransportManager(transportManager);
      }
    }
  }
 public static void checkPluginPropertiesConsistency(Map map, File configDir) {
   File runtimeDir = new File(configDir, IPDEBuildConstants.BUNDLE_CORE_RUNTIME);
   if (runtimeDir.exists() && runtimeDir.isDirectory()) {
     long timestamp = runtimeDir.lastModified();
     Iterator iter = map.values().iterator();
     while (iter.hasNext()) {
       if (hasChanged((IMonitorModelBase) iter.next(), timestamp)) {
         CoreUtility.deleteContent(runtimeDir);
         break;
       }
     }
   }
 }
예제 #10
0
  public long[] getBundleEvents() {
    synchronized (bundleEvents) {
      long[] r = new long[bundleEvents.size() * 2];
      int i = 0;

      for (Iterator it = bundleEvents.iterator(); it.hasNext(); ) {
        BundleEvent ev = (BundleEvent) it.next();
        r[i * 2] = ev.getBundle().getBundleId();
        r[i * 2 + 1] = ev.getType();
        i++;
      }
      bundleEvents.clear();
      return r;
    }
  }
예제 #11
0
  public long[] getServiceEvents() {
    synchronized (serviceEvents) {
      long[] r = new long[serviceEvents.size() * 2];
      int i = 0;

      for (Iterator it = serviceEvents.iterator(); it.hasNext(); ) {
        ServiceEvent ev = (ServiceEvent) it.next();
        r[i * 2] = ((Long) ev.getServiceReference().getProperty(Constants.SERVICE_ID)).longValue();
        r[i * 2 + 1] = ev.getType();
        i++;
      }

      serviceEvents.clear();
      return r;
    }
  }
예제 #12
0
 void delete(SecurityRow securityRow, boolean firstTry) {
   ConditionalPermissionUpdate update = newConditionalPermissionUpdate();
   List rows = update.getConditionalPermissionInfos();
   for (Iterator iRows = rows.iterator(); iRows.hasNext(); ) {
     ConditionalPermissionInfo info = (ConditionalPermissionInfo) iRows.next();
     if (securityRow.getName().equals(info.getName())) {
       iRows.remove();
       synchronized (lock) {
         if (!update.commit()) {
           if (firstTry)
             // try again
             delete(securityRow, false);
         }
       }
       break;
     }
   }
 }
예제 #13
0
 private static Bundle createMockBundle(String[] signers) {
   Map /* <X509Certificate, List<X509Certificate>> */ signersMap = new HashMap();
   for (int i = 0; i < signers.length; i++) {
     List chain = parseDNchain(signers[i]);
     List /* <X509Certificate> */ signersList = new ArrayList();
     Principal subject = null, issuer = null;
     X509Certificate first = null;
     for (Iterator iChain = chain.iterator(); iChain.hasNext(); ) {
       subject = issuer == null ? new MockPrincipal((String) iChain.next()) : issuer;
       issuer = iChain.hasNext() ? new MockPrincipal((String) iChain.next()) : subject;
       X509Certificate cert = new MockX509Certificate(subject, issuer);
       if (first == null) first = cert;
       signersList.add(cert);
     }
     if (subject != issuer) signersList.add(new MockX509Certificate(issuer, issuer));
     signersMap.put(first, signersList);
   }
   return new MockBundle(signersMap);
 }
예제 #14
0
  public void testCreateDB() {
    ArrayList<String> al = new ArrayList<String>();

    Iterator<HistoryID> i = this.historyService.getExistingIDs();
    while (i.hasNext()) {
      HistoryID id = i.next();
      String[] components = id.getID();

      if (components.length == 2 && "test".equals(components[0])) {
        al.add(components[1]);
      }
    }

    int count = al.size();
    boolean unique = false;
    String lastComp = null;
    while (!unique) {
      lastComp = Integer.toHexString(random.nextInt());
      for (int j = 0; j < count; j++) {
        if (lastComp.equals(al.get(j))) {
          continue;
        }
      }
      unique = true;
    }

    HistoryID id = HistoryID.createFromRawID(new String[] {"test", lastComp});

    try {
      this.historyService.createHistory(id, recordStructure);
    } catch (Exception e) {
      fail("Could not create database with id " + id + " with error " + e);
    }

    try {
      // after creating, remove it - do not leave content
      this.historyService.purgeLocallyStoredHistory(id);
    } catch (Exception ex) {
      fail("Cannot delete local history with id " + this.history.getID() + " : " + ex.getMessage());
    }
  }
  /**
   * Creates a <tt>RegistrationStateChangeEvent</tt> corresponding to the specified old and new
   * states and notifies all currently registered listeners.
   *
   * @param oldState the state that the provider had before the change occurred
   * @param newState the state that the provider is currently in.
   * @param reasonCode a value corresponding to one of the REASON_XXX fields of the
   *     RegistrationStateChangeEvent class, indicating the reason for this state transition.
   * @param reason a String further explaining the reason code or null if no such explanation is
   *     necessary.
   */
  private void fireRegistrationStateChanged(
      RegistrationState oldState, RegistrationState newState, int reasonCode, String reason) {
    RegistrationStateChangeEvent event =
        new RegistrationStateChangeEvent(this, oldState, newState, reasonCode, reason);

    logger.debug(
        "Dispatching " + event + " to " + registrationStateListeners.size() + " listeners.");

    Iterator listeners = null;
    synchronized (registrationStateListeners) {
      listeners = new ArrayList(registrationStateListeners).iterator();
    }

    while (listeners.hasNext()) {
      RegistrationStateChangeListener listener = (RegistrationStateChangeListener) listeners.next();

      listener.registrationStateChanged(event);
    }

    logger.trace("Done.");
  }
예제 #16
0
  public long[] getFrameworkEvents() {
    synchronized (frameworkEvents) {
      try {

        long[] r = new long[frameworkEvents.size() * 2];
        if (bDebug) {
          System.out.println("server: getFrameworkEvents size=" + r.length / 2);
        }
        int i = 0;

        for (Iterator it = frameworkEvents.iterator(); it.hasNext(); ) {
          FrameworkEvent ev = (FrameworkEvent) it.next();
          Bundle b = ev.getBundle();
          long bid = -1;
          if (b == null) {
            if (bDebug) {
              System.out.println("fw event: " + ev + " - no bundle");
            }
          } else {
            bid = b.getBundleId();
          }
          r[i * 2] = bid;
          r[i * 2 + 1] = ev.getType();
          i++;
        }

        frameworkEvents.clear();
        if (bDebug) {
          System.out.println("server: getFrameworkEvents -> " + r);
        }
        return r;
      } catch (Exception e) {
        if (bDebug) {
          e.printStackTrace();
        }
      }
    }
    return null;
  }
 /**
  * Registers or unregister as a popup message listener to detect when a user click on
  * notification saying that the device configuration has changed.
  *
  * @param enable True to register to the popup message notifcation handler. False to unregister.
  */
 public void managePopupMessageListenerRegistration(boolean enable) {
   Iterator<NotificationHandler> notificationHandlers =
       notificationService
           .getActionHandlers(
               net.java.sip.communicator.service.notification.NotificationAction
                   .ACTION_POPUP_MESSAGE)
           .iterator();
   NotificationHandler notificationHandler;
   while (notificationHandlers.hasNext()) {
     notificationHandler = notificationHandlers.next();
     if (notificationHandler instanceof PopupMessageNotificationHandler) {
       // Register.
       if (enable) {
         //                        ((PopupMessageNotificationHandler) notificationHandler)
         //                            .addPopupMessageListener(this);
       }
       // Unregister.
       else {
         //                        ((PopupMessageNotificationHandler) notificationHandler)
         //                            .removePopupMessageListener(this);
       }
     }
   }
 }
예제 #18
0
 protected String makeKeys() {
   StringBuffer sb = new StringBuffer();
   for (Iterator it = props.keySet().iterator(); it.hasNext(); ) {
     if (sb.length() > 0) {
       sb.append(',');
     }
     sb.append(it.next().toString());
   }
   for (Iterator it = props_default.keySet().iterator(); it.hasNext(); ) {
     sb.append(',');
     sb.append(it.next().toString());
   }
   return sb.toString();
 }
예제 #19
0
  /**
   * Implements the ContactListListener.contactSelected method.
   *
   * @param evt the <tt>ContactListEvent</tt> that notified us
   */
  public void contactClicked(ContactListEvent evt) {
    // We're interested only in two click events.
    if (evt.getClickCount() < 2) return;

    UIContact descriptor = evt.getSourceContact();

    // We're currently only interested in MetaContacts.
    if (descriptor.getDescriptor() instanceof MetaContact) {
      MetaContact metaContact = (MetaContact) descriptor.getDescriptor();

      // Searching for the right proto contact to use as default for the
      // chat conversation.
      Contact defaultContact =
          metaContact.getDefaultContact(OperationSetBasicInstantMessaging.class);

      // do nothing
      if (defaultContact == null) {
        defaultContact = metaContact.getDefaultContact(OperationSetSmsMessaging.class);

        if (defaultContact == null) return;
      }

      ProtocolProviderService defaultProvider = defaultContact.getProtocolProvider();

      OperationSetBasicInstantMessaging defaultIM =
          defaultProvider.getOperationSet(OperationSetBasicInstantMessaging.class);

      ProtocolProviderService protoContactProvider;
      OperationSetBasicInstantMessaging protoContactIM;

      boolean isOfflineMessagingSupported =
          defaultIM != null && !defaultIM.isOfflineMessagingSupported();

      if (defaultContact.getPresenceStatus().getStatus() < 1
          && (!isOfflineMessagingSupported || !defaultProvider.isRegistered())) {
        Iterator<Contact> protoContacts = metaContact.getContacts();

        while (protoContacts.hasNext()) {
          Contact contact = protoContacts.next();

          protoContactProvider = contact.getProtocolProvider();

          protoContactIM =
              protoContactProvider.getOperationSet(OperationSetBasicInstantMessaging.class);

          if (protoContactIM != null
              && protoContactIM.isOfflineMessagingSupported()
              && protoContactProvider.isRegistered()) {
            defaultContact = contact;
          }
        }
      }

      ContactEventHandler contactHandler =
          mainFrame.getContactHandler(defaultContact.getProtocolProvider());

      contactHandler.contactClicked(defaultContact, evt.getClickCount());
    } else if (descriptor.getDescriptor() instanceof SourceContact) {
      SourceContact contact = (SourceContact) descriptor.getDescriptor();

      List<ContactDetail> imDetails =
          contact.getContactDetails(OperationSetBasicInstantMessaging.class);
      List<ContactDetail> mucDetails = contact.getContactDetails(OperationSetMultiUserChat.class);

      if (imDetails != null && imDetails.size() > 0) {
        ProtocolProviderService pps =
            imDetails.get(0).getPreferredProtocolProvider(OperationSetBasicInstantMessaging.class);

        GuiActivator.getUIService()
            .getChatWindowManager()
            .startChat(contact.getContactAddress(), pps);
      } else if (mucDetails != null && mucDetails.size() > 0) {
        ChatRoomWrapper room =
            GuiActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact);

        if (room == null) {
          // lets check by id
          ProtocolProviderService pps =
              mucDetails.get(0).getPreferredProtocolProvider(OperationSetMultiUserChat.class);

          room =
              GuiActivator.getMUCService()
                  .findChatRoomWrapperFromChatRoomID(contact.getContactAddress(), pps);

          if (room == null) {
            GuiActivator.getMUCService()
                .createChatRoom(
                    contact.getContactAddress(),
                    pps,
                    new ArrayList<String>(),
                    "",
                    false,
                    false,
                    false);
          }
        }

        if (room != null) GuiActivator.getMUCService().openChatRoom(room);
      } else {
        List<ContactDetail> smsDetails = contact.getContactDetails(OperationSetSmsMessaging.class);

        if (smsDetails != null && smsDetails.size() > 0) {
          GuiActivator.getUIService()
              .getChatWindowManager()
              .startChat(contact.getContactAddress(), true);
        }
      }
    }
  }
예제 #20
0
  /**
   * Calculates the <tt>String</tt> for a specific <tt>DiscoverInfo</tt> which is to be hashed in
   * order to compute the ver string for that <tt>DiscoverInfo</tt>.
   *
   * @param discoverInfo the <tt>DiscoverInfo</tt> for which the <tt>String</tt> to be hashed in
   *     order to compute its ver string is to be calculated
   * @return the <tt>String</tt> for <tt>discoverInfo</tt> which is to be hashed in order to compute
   *     its ver string
   */
  private static String calculateEntityCapsString(DiscoverInfo discoverInfo) {
    StringBuilder bldr = new StringBuilder();

    // Add identities
    {
      Iterator<DiscoverInfo.Identity> identities = discoverInfo.getIdentities();
      SortedSet<DiscoverInfo.Identity> is =
          new TreeSet<DiscoverInfo.Identity>(
              new Comparator<DiscoverInfo.Identity>() {
                public int compare(DiscoverInfo.Identity i1, DiscoverInfo.Identity i2) {
                  int category = i1.getCategory().compareTo(i2.getCategory());

                  if (category != 0) return category;

                  int type = i1.getType().compareTo(i2.getType());

                  if (type != 0) return type;

                  /*
                   * TODO Sort by xml:lang.
                   *
                   * Since sort by xml:lang is currently missing,
                   * use the last supported sort criterion i.e.
                   * type.
                   */
                  return type;
                }
              });

      if (identities != null) while (identities.hasNext()) is.add(identities.next());

      for (DiscoverInfo.Identity i : is) {
        bldr.append(i.getCategory())
            .append('/')
            .append(i.getType())
            .append("//")
            .append(i.getName())
            .append('<');
      }
    }

    // Add features
    {
      Iterator<DiscoverInfo.Feature> features = getDiscoverInfoFeatures(discoverInfo);
      SortedSet<String> fs = new TreeSet<String>();

      if (features != null) while (features.hasNext()) fs.add(features.next().getVar());

      for (String f : fs) bldr.append(f).append('<');
    }

    DataForm extendedInfo = (DataForm) discoverInfo.getExtension("x", "jabber:x:data");

    if (extendedInfo != null) {
      synchronized (extendedInfo) {
        SortedSet<FormField> fs =
            new TreeSet<FormField>(
                new Comparator<FormField>() {
                  public int compare(FormField f1, FormField f2) {
                    return f1.getVariable().compareTo(f2.getVariable());
                  }
                });

        FormField formType = null;

        for (Iterator<FormField> fieldsIter = extendedInfo.getFields(); fieldsIter.hasNext(); ) {
          FormField f = fieldsIter.next();
          if (!f.getVariable().equals("FORM_TYPE")) fs.add(f);
          else formType = f;
        }

        // Add FORM_TYPE values
        if (formType != null) formFieldValuesToCaps(formType.getValues(), bldr);

        // Add the other values
        for (FormField f : fs) {
          bldr.append(f.getVariable()).append('<');
          formFieldValuesToCaps(f.getValues(), bldr);
        }
      }
    }

    return bldr.toString();
  }