Commit 9af72ffb authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Fix for an exception thrown with an IQ set when vcards are read-only. JM-1026

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8476 b35dd754-fafc-0310-a699-88a17e54d16e
parent a73bf247
......@@ -1301,6 +1301,16 @@ public class XMPPServer {
return (STUNService) modules.get(STUNService.class);
}
/**
* Returns the <code>VCardManager</code> registered with this server. The
* <code>VCardManager</code> was registered with the server as a module while starting up
* the server.
* @return the <code>VCardManager</code> registered with this server.
*/
public VCardManager getVCardManager() {
return VCardManager.getInstance();
}
/**
* Returns the <code>InternalComponentManager</code> registered with this server. The
* <code>InternalComponentManager</code> was registered with the server as a module while starting up
......
......@@ -62,34 +62,37 @@ import java.util.Iterator;
*/
public class IQvCardHandler extends IQHandler {
private IQHandlerInfo info;
private final IQHandlerInfo info = new IQHandlerInfo("vCard", "vcard-temp");
private XMPPServer server;
private UserManager userManager;
private VCardManager vCardManager;
public IQvCardHandler() {
super("XMPP vCard Handler");
info = new IQHandlerInfo("vCard", "vcard-temp");
}
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
IQ result = IQ.createResultIQ(packet);
IQ.Type type = packet.getType();
if (type.equals(IQ.Type.set)) {
try {
User user = userManager.getUser(packet.getFrom().getNode());
Element vcard = packet.getChildElement();
if (vcard != null) {
VCardManager.getInstance().setVCard(user.getUsername(), vcard);
}
}
catch (UserNotFoundException e) {
result = IQ.createResultIQ(packet);
if(vCardManager.isReadOnly()) {
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
result.setError(PacketError.Condition.not_allowed);
}
catch (Exception e) {
Log.error(e);
result.setError(PacketError.Condition.internal_server_error);
else {
try {
User user = userManager.getUser(packet.getFrom().getNode());
Element vcard = packet.getChildElement();
vCardManager.setVCard(user.getUsername(), vcard);
}
catch (UserNotFoundException e) {
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.item_not_found);
}
catch (Exception e) {
Log.error("Error setting user vCard: " + packet.getFrom().getNode(), e);
result.setError(PacketError.Condition.internal_server_error);
}
}
}
else if (type.equals(IQ.Type.get)) {
......@@ -103,8 +106,7 @@ public class IQvCardHandler extends IQHandler {
// Only try to get the vCard values of non-anonymous users
if (recipient != null) {
if (recipient.getNode() != null && server.isLocal(recipient)) {
VCardManager vManager = VCardManager.getInstance();
Element userVCard = vManager.getVCard(recipient.getNode());
Element userVCard = vCardManager.getVCard(recipient.getNode());
if (userVCard != null) {
// Check if the requester wants to ignore some vCard's fields
Element filter = packet.getChildElement()
......@@ -143,6 +145,7 @@ public class IQvCardHandler extends IQHandler {
super.initialize(server);
this.server = server;
userManager = server.getUserManager();
this.vCardManager = server.getVCardManager();
}
public IQHandlerInfo getInfo() {
......
......@@ -188,6 +188,7 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
* read-only vCard.
*
* @return the vCard of a given user.
* @param username the username of the user whose vCard is being retrieved.
*/
public Element getVCard(String username) {
Element vCardElement = getOrLoadVCard(username);
......@@ -226,6 +227,16 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
listeners.remove(listener);
}
/**
* Returns true if vCards are read-only. When vCards are read-only and #setVCard is called an
* unsupported operation exception is thrown.
*
* @return true if vCards are read-only.
*/
public boolean isReadOnly() {
return provider.isReadOnly();
}
/**
* Dispatches that a vCard was updated to all listeners.
*
......
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