private static void addCapsExtensionInfo(String from, CapsExtension capsExtension) { String capsExtensionHash = capsExtension.getHash(); String hashInUppercase = capsExtensionHash.toUpperCase(Locale.US); // SUPPORTED_HASHES uses the format of MessageDigest, which is uppercase, e.g. "SHA-1" instead of "sha-1" if (!SUPPORTED_HASHES.containsKey(hashInUppercase)) return; String hash = capsExtensionHash.toLowerCase(Locale.US); String node = capsExtension.getNode(); String ver = capsExtension.getVer(); JID_TO_NODEVER_CACHE.put(from, new NodeVerHash(node, ver, hash)); }
public CapsExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { String hash = null; String version = null; String node = null; if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT)) { hash = parser.getAttributeValue(null, "hash"); version = parser.getAttributeValue(null, "ver"); node = parser.getAttributeValue(null, "node"); } else { throw new SmackException("Malformed Caps element"); } parser.next(); if (!(parser.getEventType() == XmlPullParser.END_TAG && parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT))) { throw new SmackException("Malformed nested Caps element"); } if (hash != null && version != null && node != null) { return new CapsExtension(node, version, hash); } else { throw new SmackException("Caps elment with missing attributes. Attributes: hash=" + hash + " version=" + version + " node=" + node); } }
@Test public void parseTest() throws XmlPullParserException, IOException, SmackException { // @formatter:off final String capsExtensionString = "<c xmlns='http://jabber.org/protocol/caps'" + " hash='sha-1'" + " node='http://foo.example.org/bar'" + " ver='QgayPKawpkPSDYmwt/WM94uA1u0='/>"; // @formatter:on CapsExtension capsExtension = TestUtils.parseExtensionElement(capsExtensionString); assertNotNull(capsExtension); }
private Presence createPresence(Presence.Mode mode) { String status = Preferences.getStatusMessage(); Presence p = new Presence(Presence.Type.available); if (!TextUtils.isEmpty(status)) p.setStatus(status); if (mode != null) p.setMode(mode); // TODO find a place for this p.addExtension(new CapsExtension("http://www.kontalk.org/", "none", "sha-1")); return p; }