⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pubsubengine.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        isNodeType = false;                    }                }            }            if (nodeAffiliate != null) {                for (NodeSubscription subscription : nodeAffiliate.getSubscriptions()) {                    if (isNodeType) {                        // User is requesting a subscription of type "nodes"                        if (NodeSubscription.Type.nodes == subscription.getType()) {                            // Cannot have 2 subscriptions of the same type. Return conflict error                            sendErrorPacket(iq, PacketError.Condition.conflict, null);                            return;                        }                    }                    else if (!node.isMultipleSubscriptionsEnabled()) {                        // User is requesting a subscription of type "items" and                        // multiple subscriptions is not allowed                        if (NodeSubscription.Type.items == subscription.getType()) {                            // User is trying to create another subscription so                            // return current subscription state                            subscription.sendSubscriptionState(iq);                            return;                        }                    }                }            }        }        // Create a subscription and an affiliation if the subscriber doesn't have one        node.createSubscription(iq, owner, subscriberJID, accessModel.isAuthorizationRequired(),                optionsForm);    }    private void unsubscribeNode(PubSubService service, IQ iq, Element unsubscribeElement) {        String nodeID = unsubscribeElement.attributeValue("node");        String subID = unsubscribeElement.attributeValue("subid");        Node node;        if (nodeID == null) {            if (service.isCollectionNodesSupported()) {                // Entity unsubscribes from root collection node                node = service.getRootCollectionNode();            }            else {                // Service does not have a root collection node so return a nodeid-required error                Element pubsubError = DocumentHelper.createElement(QName.get(                        "nodeid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }        }        else {            // Look for the specified node            node = service.getNode(nodeID);            if (node == null) {                // Node does not exist. Return item-not-found error                sendErrorPacket(iq, PacketError.Condition.item_not_found, null);                return;            }        }        NodeSubscription subscription;        if (node.isMultipleSubscriptionsEnabled()) {            if (subID == null) {                // No subid was specified and the node supports multiple subscriptions                Element pubsubError = DocumentHelper.createElement(                        QName.get("subid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }            else {                // Check if the specified subID belongs to an existing node subscription                subscription = node.getSubscription(subID);                if (subscription == null) {                    Element pubsubError = DocumentHelper.createElement(                            QName.get("invalid-subid", "http://jabber.org/protocol/pubsub#errors"));                    sendErrorPacket(iq, PacketError.Condition.not_acceptable, pubsubError);                    return;                }            }        }        else {            String jidAttribute = unsubscribeElement.attributeValue("jid");            // Check if the specified JID has a subscription with the node            if (jidAttribute == null) {                // No JID was specified so return an error indicating that jid is required                Element pubsubError = DocumentHelper.createElement(                        QName.get("jid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }            JID subscriberJID = new JID(jidAttribute);            subscription = node.getSubscription(subscriberJID);            if (subscription == null) {                Element pubsubError = DocumentHelper.createElement(                        QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.unexpected_request, pubsubError);                return;            }        }        JID from = iq.getFrom();        // Check that unsubscriptions to the node are enabled        if (!node.isSubscriptionEnabled() && !service.isServiceAdmin(from)) {            // Sender is not a sysadmin and unsubscription is disabled so return an error            sendErrorPacket(iq, PacketError.Condition.not_allowed, null);            return;        }        // TODO Assumed that the owner of the subscription is the bare JID of the subscription JID. Waiting StPeter answer for explicit field.        JID owner = new JID(from.toBareJID());        // A subscription was found so check if the user is allowed to cancel the subscription        if (!subscription.canModify(from) && !subscription.canModify(owner)) {            // Requestor is prohibited from unsubscribing entity            sendErrorPacket(iq, PacketError.Condition.forbidden, null);            return;        }        // Cancel subscription        node.cancelSubscription(subscription);        // Send reply with success        router.route(IQ.createResultIQ(iq));    }    private void getSubscriptionConfiguration(PubSubService service, IQ iq,                                              Element childElement, Element optionsElement) {        String nodeID = optionsElement.attributeValue("node");        String subID = optionsElement.attributeValue("subid");        Node node;        if (nodeID == null) {            if (service.isCollectionNodesSupported()) {                // Entity requests subscription options of root collection node                node = service.getRootCollectionNode();            }            else {                // Service does not have a root collection node so return a nodeid-required error                Element pubsubError = DocumentHelper.createElement(QName.get(                        "nodeid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }        }        else {            // Look for the specified node            node = service.getNode(nodeID);            if (node == null) {                // Node does not exist. Return item-not-found error                sendErrorPacket(iq, PacketError.Condition.item_not_found, null);                return;            }        }        NodeSubscription subscription;        if (node.isMultipleSubscriptionsEnabled()) {            if (subID == null) {                // No subid was specified and the node supports multiple subscriptions                Element pubsubError = DocumentHelper.createElement(                        QName.get("subid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }            else {                // Check if the specified subID belongs to an existing node subscription                subscription = node.getSubscription(subID);                if (subscription == null) {                    Element pubsubError = DocumentHelper.createElement(                            QName.get("invalid-subid", "http://jabber.org/protocol/pubsub#errors"));                    sendErrorPacket(iq, PacketError.Condition.not_acceptable, pubsubError);                    return;                }            }        }        else {            // Check if the specified JID has a subscription with the node            String jidAttribute = optionsElement.attributeValue("jid");            if (jidAttribute == null) {                // No JID was specified so return an error indicating that jid is required                Element pubsubError = DocumentHelper.createElement(                        QName.get("jid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }            JID subscriberJID = new JID(jidAttribute);            subscription = node.getSubscription(subscriberJID);            if (subscription == null) {                Element pubsubError = DocumentHelper.createElement(                        QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.unexpected_request, pubsubError);                return;            }        }        // A subscription was found so check if the user is allowed to get the subscription options        if (!subscription.canModify(iq.getFrom())) {            // Requestor is prohibited from getting the subscription options            sendErrorPacket(iq, PacketError.Condition.forbidden, null);            return;        }        // Return data form containing subscription configuration to the subscriber        IQ reply = IQ.createResultIQ(iq);        Element replyChildElement = childElement.createCopy();        reply.setChildElement(replyChildElement);        replyChildElement.element("options").add(subscription.getConfigurationForm().getElement());        router.route(reply);    }    private void configureSubscription(PubSubService service, IQ iq, Element optionsElement) {        String nodeID = optionsElement.attributeValue("node");        String subID = optionsElement.attributeValue("subid");        Node node;        if (nodeID == null) {            if (service.isCollectionNodesSupported()) {                // Entity submits new subscription options of root collection node                node = service.getRootCollectionNode();            }            else {                // Service does not have a root collection node so return a nodeid-required error                Element pubsubError = DocumentHelper.createElement(QName.get(                        "nodeid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }        }        else {            // Look for the specified node            node = service.getNode(nodeID);            if (node == null) {                // Node does not exist. Return item-not-found error                sendErrorPacket(iq, PacketError.Condition.item_not_found, null);                return;            }        }        NodeSubscription subscription;        if (node.isMultipleSubscriptionsEnabled()) {            if (subID == null) {                // No subid was specified and the node supports multiple subscriptions                Element pubsubError = DocumentHelper.createElement(                        QName.get("subid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }            else {                // Check if the specified subID belongs to an existing node subscription                subscription = node.getSubscription(subID);                if (subscription == null) {                    Element pubsubError = DocumentHelper.createElement(                            QName.get("invalid-subid", "http://jabber.org/protocol/pubsub#errors"));                    sendErrorPacket(iq, PacketError.Condition.not_acceptable, pubsubError);                    return;                }            }        }        else {            // Check if the specified JID has a subscription with the node            String jidAttribute = optionsElement.attributeValue("jid");            if (jidAttribute == null) {                // No JID was specified so return an error indicating that jid is required                Element pubsubError = DocumentHelper.createElement(                        QName.get("jid-required", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);                return;            }            JID subscriberJID = new JID(jidAttribute);            subscription = node.getSubscription(subscriberJID);            if (subscription == null) {                Element pubsubError = DocumentHelper.createElement(                        QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.unexpected_request, pubsubError);                return;            }        }        // A subscription was found so check if the user is allowed to submits        // new subscription options        if (!subscription.canModify(iq.getFrom())) {            // Requestor is prohibited from setting new subscription options            sendErrorPacket(iq, PacketError.Condition.forbidden, null);            return;        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -