Esempio n. 1
0
 public static IQ parseIQ(XmlPullParser xmlPullParser)
     throws XmlPullParserException, IOException, SmackException {
   XMPPError xMPPError = null;
   ParserUtils.assertAtStartTag(xmlPullParser);
   int depth = xmlPullParser.getDepth();
   String attributeValue = xmlPullParser.getAttributeValue("", "id");
   String attributeValue2 = xmlPullParser.getAttributeValue("", PrivacyItem.SUBSCRIPTION_TO);
   String attributeValue3 = xmlPullParser.getAttributeValue("", PrivacyItem.SUBSCRIPTION_FROM);
   Type fromString = Type.fromString(xmlPullParser.getAttributeValue("", "type"));
   IQ iq = null;
   while (true) {
     switch (xmlPullParser.next()) {
       case VideoSize.HVGA /*2*/:
         XMPPError parseError;
         IQ iq2;
         String name = xmlPullParser.getName();
         String namespace = xmlPullParser.getNamespace();
         Object obj = -1;
         switch (name.hashCode()) {
           case 96784904:
             if (name.equals(XMPPError.ERROR)) {
               obj = null;
               break;
             }
             break;
         }
         switch (obj) {
           case VideoSize.QCIF /*0*/:
             parseError = parseError(xmlPullParser);
             iq2 = iq;
             break;
           default:
             IQProvider iQProvider = ProviderManager.getIQProvider(name, namespace);
             XMPPError xMPPError2;
             if (iQProvider == null) {
               xMPPError2 = xMPPError;
               iq2 = new UnparsedIQ(name, namespace, parseElement(xmlPullParser));
               parseError = xMPPError2;
               break;
             }
             xMPPError2 = xMPPError;
             iq2 = (IQ) iQProvider.parse(xmlPullParser);
             parseError = xMPPError2;
             break;
         }
         iq = iq2;
         xMPPError = parseError;
         break;
       case Version.API03_CUPCAKE_15 /*3*/:
         if (xmlPullParser.getDepth() != depth) {
           break;
         }
         if (iq == null) {
           switch (C01861.$SwitchMap$org$jivesoftware$smack$packet$IQ$Type[fromString.ordinal()]) {
             case VideoSize.CIF /*1*/:
               iq = new ErrorIQ(xMPPError);
               break;
             case VideoSize.HVGA /*2*/:
               iq = new EmptyResultIQ();
               break;
           }
         }
         iq.setStanzaId(attributeValue);
         iq.setTo(attributeValue2);
         iq.setFrom(attributeValue3);
         iq.setType(fromString);
         iq.setError(xMPPError);
         return iq;
       default:
         break;
     }
   }
 }
Esempio n. 2
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;
    }
  }