Commit 62f711bf authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Renamed #getUserPresence to getPresence and prepared it for getting component...

Renamed #getUserPresence to getPresence and prepared it for getting component presences in a future version (and presences of remote servers).


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1679 b35dd754-fafc-0310-a699-88a17e54d16e
parent 31592a7f
...@@ -43,11 +43,13 @@ public class PresencePlugin implements Plugin { ...@@ -43,11 +43,13 @@ public class PresencePlugin implements Plugin {
private UserManager userManager; private UserManager userManager;
private PresenceManager presenceManager; private PresenceManager presenceManager;
private String hostname;
public void initializePlugin(PluginManager manager, File pluginDirectory) { public void initializePlugin(PluginManager manager, File pluginDirectory) {
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
userManager = server.getUserManager(); userManager = server.getUserManager();
presenceManager = server.getPresenceManager(); presenceManager = server.getPresenceManager();
hostname = server.getServerInfo().getName();
} }
public void destroyPlugin() { public void destroyPlugin() {
...@@ -83,22 +85,36 @@ public class PresencePlugin implements Plugin { ...@@ -83,22 +85,36 @@ public class PresencePlugin implements Plugin {
* of the request is subscribed to the user presence. * of the request is subscribed to the user presence.
* *
* @param sender the bare JID of the user making the request. * @param sender the bare JID of the user making the request.
* @param username the username of the user whose presence is being probed. * @param jid the bare JID of the entity whose presence is being probed.
* @return the presence of the requested user. * @return the presence of the requested user.
* @throws UserNotFoundException If presences are not public and the sender is null or the * @throws UserNotFoundException If presences are not public and the sender is null or the
* sender cannot probe the presence of the requested user. Or if the requested user * sender cannot probe the presence of the requested user. Or if the requested user
* does not exist in the local server. * does not exist in the local server.
*/ */
public Presence getUserPresence(String sender, String username) throws UserNotFoundException { public Presence getPresence(String sender, String jid) throws UserNotFoundException {
JID targetJID = new JID(jid);
// Check that the sender is not requesting information of a remote server entity
if (targetJID.getDomain() == null || !targetJID.getDomain().contains(hostname)) {
throw new UserNotFoundException("Domain does not matches local server domain");
}
if (!hostname.equals(targetJID.getDomain())) {
// Sender is requesting information about component presence
// TODO Implement this
throw new UserNotFoundException("Presence of components not supported yet!");
}
if (targetJID.getNode() == null) {
// Sender is requesting presence information of an anonymous user
throw new UserNotFoundException("Username is null");
}
if (!isPresencePublic()) { if (!isPresencePublic()) {
if (sender == null) { if (sender == null) {
throw new UserNotFoundException("Sender is null"); throw new UserNotFoundException("Sender is null");
} }
else if (!presenceManager.canProbePresence(new JID(sender), username)) { else if (!presenceManager.canProbePresence(new JID(sender), targetJID.getNode())) {
throw new UserNotFoundException("Sender is not allowed to probe this user"); throw new UserNotFoundException("Sender is not allowed to probe this user");
} }
} }
User user = userManager.getUser(username); User user = userManager.getUser(targetJID.getNode());
return presenceManager.getPresence(user); return presenceManager.getPresence(user);
} }
} }
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