protected List handleSet()

in server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubUnsubscribeHandler.java [82:135]


    protected List<Stanza> handleSet(IQStanza stanza, ServerRuntimeContext serverRuntimeContext, SessionContext sessionContext, StanzaBroker stanzaBroker) {
        Entity serverJID = serviceConfiguration.getDomainJID();
        CollectionNode root = serviceConfiguration.getRootNode();

        Entity sender = extractSenderJID(stanza, sessionContext);
        Entity subJID = null;

        StanzaBuilder sb = StanzaBuilder.createDirectReply(stanza, false, IQStanzaType.RESULT);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB);

        XMLElement unsub = stanza.getFirstInnerElement().getFirstInnerElement(); // pubsub/unsubscribe
        String strSubJID = unsub.getAttributeValue("jid"); // MUST
        String strSubID = unsub.getAttributeValue("subid"); // SHOULD (req. for more than one subscription)

        try {
            subJID = EntityImpl.parse(strSubJID);
        } catch (EntityFormatException e) {
            // return error stanza... (general error)
            return Collections.singletonList(errorStanzaGenerator.generateJIDMalformedErrorStanza(sender, serverJID, stanza));
        }

        if (!sender.getBareJID().equals(subJID.getBareJID())) {
            // insufficient privileges (error condition 3 (6.2.3))
            return Collections.singletonList(errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, serverJID, stanza));
        }

        String nodeName = extractNodeName(stanza);
        LeafNode node = root.find(nodeName);

        if (node == null) {
            // no such node (error condition 4 (6.2.3))
            return Collections.singletonList(errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza));
        }

        if (strSubID == null) {
            try {
                if (!node.unsubscribe(subJID)) {
                    // has no subscription (6.2.3.2)
                    return Collections.singletonList(errorStanzaGenerator.generateNoSuchSubscriberErrorStanza(sender, serverJID, stanza));
                }
            } catch (MultipleSubscriptionException e) {
                // error case 6.2.3.1
                return Collections.singletonList(errorStanzaGenerator.generateSubIDRequiredErrorStanza(sender, serverJID, stanza));
            }
        } else {
            if (!node.unsubscribe(strSubID, subJID)) {
                // subID not valid (6.2.3.5)
                return Collections.singletonList(errorStanzaGenerator.generateSubIDNotValidErrorStanza(sender, serverJID, stanza));
            }
        }

        sb.endInnerElement(); // pubsub
        return Collections.singletonList(new IQStanza(sb.build()));
    }