Esempio n. 1
0
  public PubSubNodeInfo getNodeDetails(String nodeId) throws SoxLibException {
    PubSubNodeInfo result = new PubSubNodeInfo();
    DiscoverInfo di = null;
    try {
      Node node = mPubSubManager.getNode(nodeId);
      if (!(node instanceof LeafNode)) {
        throw new SoxLibException("Expecting leaf node, but got something else:" + nodeId);
      }
      LeafNode leaf = (LeafNode) node;
      di = leaf.discoverInfo();
    } catch (XMPPException e) {
      throw new SoxLibException("Problem accessing node list:" + nodeId);
    }

    // Expect one and only one identity.
    Iterator<DiscoverInfo.Identity> iter = di.getIdentities();
    if (iter.hasNext()) {
      DiscoverInfo.Identity info = iter.next();
      // logger.log(Level.FINER, "type:" + info.getType());
      // logger.log(Level.FINER, "cat:" + info.getCategory());
      result.nodeType = info.getType();
      // Assert iter.hasNext == false
    }

    // If no form data, returns null for this field.
    result.nodeForm = (DataForm) di.getExtension("jabber:x:data");

    return result;
  }
Esempio n. 2
0
  /**
   * Get the identities sorted correctly to calculate the ver attribute.
   *
   * @param info the DiscoverInfo containing the identities
   * @return the sorted list of identities.
   */
  private List<DiscoverInfo.Identity> getSortedIdentity(DiscoverInfo info) {
    List<DiscoverInfo.Identity> result = new ArrayList<DiscoverInfo.Identity>();
    Iterator<DiscoverInfo.Identity> it = info.getIdentities();
    while (it.hasNext()) {
      DiscoverInfo.Identity id = it.next();
      result.add(id);
    }
    Collections.sort(
        result,
        new Comparator<DiscoverInfo.Identity>() {
          public int compare(DiscoverInfo.Identity o1, DiscoverInfo.Identity o2) {

            String cat1 = o1.getCategory();
            if (cat1 == null) cat1 = "";
            String cat2 = o2.getCategory();
            if (cat2 == null) cat2 = "";
            int res = cat1.compareTo(cat2);
            if (res != 0) return res;
            String type1 = o1.getType();
            if (type1 == null) type1 = "";
            String type2 = o2.getCategory();
            if (type2 == null) type2 = "";
            res = type1.compareTo(type2);
            if (res != 0) return res;
            // should compare lang but not avalaible
            return 0;
          }
        });
    return result;
  }
 /** 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);
   }
 }
 /**
  * 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;
 }
Esempio n. 5
0
  /**
   * Retrieves the requested node, if it exists. It will throw an exception if it does not.
   *
   * @param id - The unique id of the node
   * @return the node
   * @throws XMPPException The node does not exist
   */
  public Node getNode(String id) throws XMPPException {
    Node node = nodeMap.get(id);

    if (node == null) {
      DiscoverInfo info = new DiscoverInfo();
      info.setTo(to);
      info.setNode(id);

      DiscoverInfo infoReply = (DiscoverInfo) SyncPacketSend.getReply(con, info);

      if (infoReply.getIdentities().next().getType().equals(NodeType.leaf.toString()))
        node = new LeafNode(con, id);
      else node = new CollectionNode(con, id);
      node.setTo(to);
      nodeMap.put(id, node);
    }
    return node;
  }
Esempio n. 6
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();
  }