Commit 23c7e0a2 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

Contact Subscription: Implemented auto-subscriptions to PEP services via presence subscriptions.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/pep@8812 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3e101197
......@@ -101,10 +101,10 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
// the reply.
if (packet.getTo() != null && packet.getTo().getNode() != null) {
String name = packet.getTo().getNode();
reply.setChildElement(packet.getChildElement().createCopy());
Element queryElement = reply.getChildElement();
List<UserItemsProvider> itemsProviders = XMPPServer.getInstance().getUserItemsProviders();
if (itemsProviders.isEmpty()) {
// If we didn't find any UserItemsProviders, then answer a not found error
......@@ -126,10 +126,10 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
}
}
}
return reply;
}
// Look for a DiscoItemsProvider associated with the requested entity.
// We consider the host of the recipient JID of the packet as the entity. It's the
// DiscoItemsProvider responsibility to provide the items associated with the JID's name
......
......@@ -16,6 +16,7 @@ import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.user.PresenceEventDispatcher;
import org.jivesoftware.openfire.user.UserAlreadyExistsException;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
......@@ -168,6 +169,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
JID prober = localServer.isLocal(recipientJID) ?
new JID(recipientJID.toBareJID()) : recipientJID;
presenceManager.probePresence(prober, senderJID);
PresenceEventDispatcher.subscribedToPresence(prober, senderJID);
}
}
......
......@@ -270,7 +270,7 @@ public class PEPService implements PubSubService {
}
public boolean isCollectionNodesSupported() {
return false;
return true;
}
public boolean isInstantNodeSupported() {
......
......@@ -88,6 +88,13 @@ public class NodeAffiliate {
Element items = event.addElement("items");
items.addAttribute("node", getNode().getNodeID());
for (PublishedItem publishedItem : itemsBySubs.get(nodeSubscriptions)) {
// FIXME: This was added for compatibility with PEP supporting clients like Psi.
// May not be the best of solutions.
//
// If the node ID looks like a JID, replace it with the published item's node ID.
if (getNode().getNodeID().indexOf("@") >= 0) {
items.addAttribute("node", publishedItem.getNode().getNodeID());
}
// Add item information to the event notification
Element item = items.addElement("item");
if (leafNode.isItemRequired()) {
......
......@@ -35,14 +35,22 @@ import java.util.concurrent.LinkedBlockingQueue;
*/
public class PubSubPersistenceManager {
private static final String LOAD_NODES =
private static final String LOAD_NON_LEAF_NODES =
"SELECT nodeID, leaf, creationDate, modificationDate, parent, deliverPayloads, " +
"maxPayloadSize, persistItems, maxItems, notifyConfigChanges, notifyDelete, " +
"notifyRetract, presenceBased, sendItemSubscribe, publisherModel, " +
"subscriptionEnabled, configSubscription, accessModel, payloadType, " +
"bodyXSLT, dataformXSLT, creator, description, language, name, " +
"replyPolicy, associationPolicy, maxLeafNodes FROM pubsubNode " +
"WHERE serviceID=? ORDER BY nodeID";
"WHERE serviceID=? AND leaf=0 ORDER BY nodeID";
private static final String LOAD_LEAF_NODES =
"SELECT nodeID, leaf, creationDate, modificationDate, parent, deliverPayloads, " +
"maxPayloadSize, persistItems, maxItems, notifyConfigChanges, notifyDelete, " +
"notifyRetract, presenceBased, sendItemSubscribe, publisherModel, " +
"subscriptionEnabled, configSubscription, accessModel, payloadType, " +
"bodyXSLT, dataformXSLT, creator, description, language, name, " +
"replyPolicy, associationPolicy, maxLeafNodes FROM pubsubNode " +
"WHERE serviceID=? AND leaf=1 ORDER BY nodeID";
private static final String UPDATE_NODE =
"UPDATE pubsubNode SET modificationDate=?, parent=?, deliverPayloads=?, " +
"maxPayloadSize=?, persistItems=?, maxItems=?, " +
......@@ -446,11 +454,22 @@ public class PubSubPersistenceManager {
Map<String, Node> nodes = new HashMap<String, Node>();
try {
con = DbConnectionManager.getConnection();
// Get all nodes at once (with 1 query)
pstmt = con.prepareStatement(LOAD_NODES);
// Get all non-leaf nodes (to ensure parent nodes are loaded before their children)
pstmt = con.prepareStatement(LOAD_NON_LEAF_NODES);
pstmt.setString(1, service.getServiceID());
ResultSet rs = pstmt.executeQuery();
// Rebuild all loaded nodes
// Rebuild loaded non-leaf nodes
while(rs.next()) {
loadNode(service, nodes, rs);
}
rs.close();
pstmt.close();
// Get all leaf nodes (remaining unloaded nodes)
pstmt = con.prepareStatement(LOAD_LEAF_NODES);
pstmt.setString(1, service.getServiceID());
rs = pstmt.executeQuery();
// Rebuild loaded leaf nodes
while(rs.next()) {
loadNode(service, nodes, rs);
}
......
......@@ -12,6 +12,7 @@
package org.jivesoftware.openfire.user;
import org.jivesoftware.openfire.session.ClientSession;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import java.util.List;
......@@ -123,4 +124,19 @@ public class PresenceEventDispatcher {
}
}
}
/**
* Notification message indicating that a user has successfully subscribed
* to the presence of another user.
*
* @param subscriberJID the user that initiated the subscription.
* @param authorizerJID the user that authorized the subscription.
*/
public static void subscribedToPresence(JID subscriberJID, JID authorizerJID) {
if (!listeners.isEmpty()) {
for (PresenceEventListener listener : listeners) {
listener.subscribedToPresence(subscriberJID, authorizerJID);
}
}
}
}
......@@ -12,6 +12,7 @@
package org.jivesoftware.openfire.user;
import org.jivesoftware.openfire.session.ClientSession;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
/**
......@@ -64,4 +65,13 @@ public interface PresenceEventListener {
* @param presence the received available presence with the new information.
*/
public void presenceChanged(ClientSession session, Presence presence);
/**
* Notification message indicating that a user has successfully subscribed
* to the presence of another user.
*
* @param subscriberJID the user that initiated the subscription.
* @param authorizerJID the user that authorized the subscription.
*/
public void subscribedToPresence(JID subscriberJID, JID authorizerJID);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment