1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

Validate ProviderManager arguments

This commit is contained in:
Florian Schmaus 2014-10-31 00:24:26 +01:00
parent a3de2ecc25
commit 5fcfe548f9

View file

@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.StringUtils;
import org.jxmpp.util.XmppStringUtils;
/**
@ -202,6 +203,7 @@ public final class ProviderManager {
public static void addIQProvider(String elementName, String namespace,
Object provider)
{
validate(elementName, namespace);
// First remove existing providers
String key = removeIQProvider(elementName, namespace);
if (provider instanceof IQProvider) {
@ -272,6 +274,7 @@ public final class ProviderManager {
public static void addExtensionProvider(String elementName, String namespace,
Object provider)
{
validate(elementName, namespace);
// First remove existing providers
String key = removeExtensionProvider(elementName, namespace);
if (provider instanceof PacketExtensionProvider) {
@ -320,6 +323,7 @@ public final class ProviderManager {
}
public static void addStreamFeatureProvider(String elementName, String namespace, PacketExtensionProvider<PacketExtension> provider) {
validate(elementName, namespace);
String key = getKey(elementName, namespace);
streamFeatureProviders.put(key, provider);
}
@ -332,4 +336,13 @@ public final class ProviderManager {
private static String getKey(String elementName, String namespace) {
return XmppStringUtils.generateKey(elementName, namespace);
}
private static void validate(String elementName, String namespace) {
if (StringUtils.isNullOrEmpty(elementName)) {
throw new IllegalArgumentException("elementName must not be null or empty");
}
if (StringUtils.isNullOrEmpty(namespace)) {
throw new IllegalArgumentException("namespace must not be null or empty");
}
}
}