use of org.jivesoftware.smackx.pubsub.PayloadItem in project Smack by igniterealtime.
the class OpenPgpPubSubUtil method fetchSecretKey.
/**
* Fetch the latest {@link SecretkeyElement} from the private backup node.
*
* @see <a href="https://xmpp.org/extensions/xep-0373.html#synchro-pep">
* XEP-0373 §5. Synchronizing the Secret Key with a Private PEP Node</a>
*
* @param pepManager the PEP manager.
* @return the secret key node or null, if it doesn't exist.
*
* @throws InterruptedException if the thread gets interrupted
* @throws PubSubException.NotALeafNodeException if there is an issue with the PubSub node
* @throws XMPPException.XMPPErrorException if there is an XMPP protocol related issue
* @throws SmackException.NotConnectedException if we are not connected
* @throws SmackException.NoResponseException /watch?v=7U0FzQzJzyI
*/
public static SecretkeyElement fetchSecretKey(PepManager pepManager) throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
PubSubManager pm = pepManager.getPepPubSubManager();
LeafNode secretKeyNode = pm.getOrCreateLeafNode(PEP_NODE_SECRET_KEY);
List<PayloadItem<SecretkeyElement>> list = secretKeyNode.getItems(1);
if (list.size() == 0) {
LOGGER.log(Level.INFO, "No secret key published!");
return null;
}
SecretkeyElement secretkeyElement = list.get(0).getPayload();
return secretkeyElement;
}
use of org.jivesoftware.smackx.pubsub.PayloadItem in project Smack by igniterealtime.
the class OmemoService method fetchBundle.
/**
* Retrieve a users OMEMO bundle.
*
* @param connection authenticated XMPP connection.
* @param contactsDevice device of which we want to retrieve the bundle.
* @return OmemoBundle of the device or null, if it doesn't exist.
*
* @throws SmackException.NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
* @throws SmackException.NoResponseException if there was no response from the remote entity.
* @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
* @throws PubSubException.NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node.
* @throws PubSubException.NotAPubSubNodeException if a involved node is not a PubSub node.
*/
private static OmemoBundleElement fetchBundle(XMPPConnection connection, OmemoDevice contactsDevice) throws SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException, PubSubException.NotAPubSubNodeException {
PubSubManager pm = PubSubManager.getInstanceFor(connection, contactsDevice.getJid());
LeafNode node = pm.getLeafNode(contactsDevice.getBundleNodeName());
if (node == null) {
return null;
}
List<PayloadItem<OmemoBundleElement>> bundleItems = node.getItems();
if (bundleItems.isEmpty()) {
return null;
}
return bundleItems.get(bundleItems.size() - 1).getPayload();
}
use of org.jivesoftware.smackx.pubsub.PayloadItem in project Smack by igniterealtime.
the class ItemProvider method parse.
@Override
public Item parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
String id = parser.getAttributeValue(null, "id");
String node = parser.getAttributeValue(null, "node");
String xmlns = parser.getNamespace();
ItemNamespace itemNamespace = ItemNamespace.fromXmlns(xmlns);
XmlPullParser.TagEvent event = parser.nextTag();
switch(event) {
case START_ELEMENT:
String payloadElemName = parser.getName();
String payloadNS = parser.getNamespace();
final ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS);
if (extensionProvider == null) {
// TODO: Should we use StandardExtensionElement in this case? And probably remove SimplePayload all together.
CharSequence payloadText = PacketParserUtils.parseElement(parser, true);
return new PayloadItem<>(itemNamespace, id, node, new SimplePayload(payloadText.toString()));
} else {
return new PayloadItem<>(itemNamespace, id, node, extensionProvider.parse(parser));
}
case END_ELEMENT:
return new Item(itemNamespace, id, node);
default:
throw new AssertionError("unknown: " + event);
}
}
use of org.jivesoftware.smackx.pubsub.PayloadItem in project Smack by igniterealtime.
the class OpenPgpPubSubUtil method fetchPubkeysList.
/**
* Consult the public key metadata node of {@code contact} to fetch the list of their published OpenPGP public keys.
*
* @see <a href="https://xmpp.org/extensions/xep-0373.html#discover-pubkey-list">
* XEP-0373 §4.3: Discovering Public Keys of a User</a>
*
* @param connection XMPP connection
* @param contact {@link BareJid} of the user we want to fetch the list from.
* @return content of {@code contact}'s metadata node.
*
* @throws InterruptedException if the thread gets interrupted.
* @throws XMPPException.XMPPErrorException in case of an XMPP protocol exception.
* @throws SmackException.NoResponseException in case the server doesn't respond
* @throws PubSubException.NotALeafNodeException in case the queried node is not a {@link LeafNode}
* @throws SmackException.NotConnectedException in case we are not connected
* @throws PubSubException.NotAPubSubNodeException in case the queried entity is not a PubSub node
*/
public static PublicKeysListElement fetchPubkeysList(XMPPConnection connection, BareJid contact) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException, PubSubException.NotALeafNodeException, SmackException.NotConnectedException, PubSubException.NotAPubSubNodeException {
PubSubManager pm = PubSubManager.getInstanceFor(connection, contact);
LeafNode node = getLeafNode(pm, PEP_NODE_PUBLIC_KEYS);
List<PayloadItem<PublicKeysListElement>> list = node.getItems(1);
if (list.isEmpty()) {
return null;
}
return list.get(0).getPayload();
}
Aggregations