mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Merge branch '4.2'
This commit is contained in:
commit
7a5f9e6a03
187 changed files with 2284 additions and 588 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,6 +1,8 @@
|
||||||
# IntelliJ
|
# IntelliJ
|
||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
# Mac OS X
|
# Mac OS X
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
|
@ -10,7 +10,7 @@ cache:
|
||||||
- $HOME/.m2
|
- $HOME/.m2
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- export GRADLE_VERSION=2.12
|
- export GRADLE_VERSION=3.5
|
||||||
- wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
|
- wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
|
||||||
- unzip -q gradle-${GRADLE_VERSION}-all.zip
|
- unzip -q gradle-${GRADLE_VERSION}-all.zip
|
||||||
- export PATH="$(pwd)/gradle-${GRADLE_VERSION}/bin:$PATH"
|
- export PATH="$(pwd)/gradle-${GRADLE_VERSION}/bin:$PATH"
|
||||||
|
@ -19,6 +19,6 @@ install: gradle assemble --stacktrace
|
||||||
script: gradle check --stacktrace
|
script: gradle check --stacktrace
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- JAVAC_VERSION=$((javac -version) 2>&1)
|
- JAVAC_VERSION=$((javac -version) 2>&1)
|
||||||
# Only run jacocoRootReport in the Java7 build
|
# Only run jacocoRootReport in the Java 8 build
|
||||||
- if [[ "$JAVAC_VERSION" = javac\ 1.7.* ]]; then gradle jacocoRootReport coveralls; fi
|
- if [[ "$JAVAC_VERSION" = javac\ 1.8.* ]]; then gradle jacocoRootReport coveralls; fi
|
||||||
|
|
|
@ -8,9 +8,9 @@ buildscript {
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'org.kordamp:markdown-gradle-plugin:1.0.0'
|
classpath 'org.kordamp:markdown-gradle-plugin:1.0.0'
|
||||||
classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.0'
|
classpath 'org.kordamp.gradle:clirr-gradle-plugin:0.2.2'
|
||||||
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
|
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1"
|
||||||
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.9'
|
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.10'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apply plugin: 'org.kordamp.gradle.markdown'
|
apply plugin: 'org.kordamp.gradle.markdown'
|
||||||
|
@ -20,6 +20,7 @@ apply from: 'version.gradle'
|
||||||
allprojects {
|
allprojects {
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
|
apply plugin: 'idea'
|
||||||
apply plugin: 'jacoco'
|
apply plugin: 'jacoco'
|
||||||
apply plugin: 'net.ltgt.errorprone'
|
apply plugin: 'net.ltgt.errorprone'
|
||||||
|
|
||||||
|
@ -266,6 +267,7 @@ subprojects {
|
||||||
|
|
||||||
checkstyle {
|
checkstyle {
|
||||||
configFile = new File(rootConfigDir, 'checkstyle.xml')
|
configFile = new File(rootConfigDir, 'checkstyle.xml')
|
||||||
|
toolVersion = '7.7'
|
||||||
}
|
}
|
||||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||||
classifier = 'sources'
|
classifier = 'sources'
|
||||||
|
|
|
@ -117,5 +117,75 @@
|
||||||
, INDEX_OP
|
, INDEX_OP
|
||||||
"/>
|
"/>
|
||||||
</module>
|
</module>
|
||||||
|
<module name="WhitespaceAfter">
|
||||||
|
<property name="tokens" value="TYPECAST
|
||||||
|
, LITERAL_IF
|
||||||
|
, LITERAL_ELSE
|
||||||
|
, LITERAL_WHILE
|
||||||
|
, LITERAL_DO
|
||||||
|
, LITERAL_FOR
|
||||||
|
, DO_WHILE
|
||||||
|
"/>
|
||||||
|
</module>
|
||||||
|
<module name="WhitespaceAround">
|
||||||
|
<property
|
||||||
|
name="ignoreEnhancedForColon"
|
||||||
|
value="false"
|
||||||
|
/>
|
||||||
|
<!-- Currently disabled tokens: LCURLY, RCURLY, WILDCARD_TYPE, GENERIC_START, GENERIC_END -->
|
||||||
|
<property
|
||||||
|
name="tokens"
|
||||||
|
value="ASSIGN
|
||||||
|
, ARRAY_INIT
|
||||||
|
, BAND
|
||||||
|
, BAND_ASSIGN
|
||||||
|
, BOR
|
||||||
|
, BOR_ASSIGN
|
||||||
|
, BSR
|
||||||
|
, BSR_ASSIGN
|
||||||
|
, BXOR
|
||||||
|
, BXOR_ASSIGN
|
||||||
|
, COLON
|
||||||
|
, DIV
|
||||||
|
, DIV_ASSIGN
|
||||||
|
, DO_WHILE
|
||||||
|
, EQUAL
|
||||||
|
, GE
|
||||||
|
, GT
|
||||||
|
, LAMBDA
|
||||||
|
, LAND
|
||||||
|
, LE
|
||||||
|
, LITERAL_CATCH
|
||||||
|
, LITERAL_DO
|
||||||
|
, LITERAL_ELSE
|
||||||
|
, LITERAL_FINALLY
|
||||||
|
, LITERAL_FOR
|
||||||
|
, LITERAL_IF
|
||||||
|
, LITERAL_RETURN
|
||||||
|
, LITERAL_SWITCH
|
||||||
|
, LITERAL_SYNCHRONIZED
|
||||||
|
, LITERAL_TRY
|
||||||
|
, LITERAL_WHILE
|
||||||
|
, LOR
|
||||||
|
, LT
|
||||||
|
, MINUS
|
||||||
|
, MINUS_ASSIGN
|
||||||
|
, MOD
|
||||||
|
, MOD_ASSIGN
|
||||||
|
, NOT_EQUAL
|
||||||
|
, PLUS
|
||||||
|
, PLUS_ASSIGN
|
||||||
|
, QUESTION
|
||||||
|
, SL
|
||||||
|
, SLIST
|
||||||
|
, SL_ASSIGN
|
||||||
|
, SR
|
||||||
|
, SR_ASSIGN
|
||||||
|
, STAR
|
||||||
|
, STAR_ASSIGN
|
||||||
|
, LITERAL_ASSERT
|
||||||
|
, TYPE_EXTENSION_AND
|
||||||
|
"/>
|
||||||
|
</module>
|
||||||
</module>
|
</module>
|
||||||
</module>
|
</module>
|
||||||
|
|
|
@ -87,6 +87,7 @@ Experimental Smack Extensions and currently supported XEPs of smack-experimental
|
||||||
| [Internet of Things - Control](iot.md) | [XEP-0325](http://xmpp.org/extensions/xep-0325.html) | Describes how to control devices or actuators in an XMPP-based sensor netowrk. |
|
| [Internet of Things - Control](iot.md) | [XEP-0325](http://xmpp.org/extensions/xep-0325.html) | Describes how to control devices or actuators in an XMPP-based sensor netowrk. |
|
||||||
| [HTTP over XMPP transport](hoxt.md) | [XEP-0332](http://xmpp.org/extensions/xep-0332.html) | Allows to transport HTTP communication over XMPP peer-to-peer networks. |
|
| [HTTP over XMPP transport](hoxt.md) | [XEP-0332](http://xmpp.org/extensions/xep-0332.html) | Allows to transport HTTP communication over XMPP peer-to-peer networks. |
|
||||||
| Chat Markers | [XEP-0333](http://xmpp.org/extensions/xep-0333.html) | A solution of marking the last received, displayed and acknowledged message in a chat. |
|
| Chat Markers | [XEP-0333](http://xmpp.org/extensions/xep-0333.html) | A solution of marking the last received, displayed and acknowledged message in a chat. |
|
||||||
|
| Message Processing Hints | [XEP-0334](http://xmpp.org/extensions/xep-0334.html) | Hints to entities routing or receiving a message. |
|
||||||
| JSON Containers | [XEP-0335](http://xmpp.org/extensions/xep-0335.html) | Encapsulation of JSON data within XMPP Stanzas. |
|
| JSON Containers | [XEP-0335](http://xmpp.org/extensions/xep-0335.html) | Encapsulation of JSON data within XMPP Stanzas. |
|
||||||
| [Internet of Things - Discovery](iot.md) | [XEP-0347](http://xmpp.org/extensions/xep-0347.html) | Describes how Things can be installed and discovered by their owners. |
|
| [Internet of Things - Discovery](iot.md) | [XEP-0347](http://xmpp.org/extensions/xep-0347.html) | Describes how Things can be installed and discovered by their owners. |
|
||||||
| Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. |
|
| Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. |
|
||||||
|
|
|
@ -325,7 +325,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
|
||||||
writer = new Writer() {
|
writer = new Writer() {
|
||||||
@Override
|
@Override
|
||||||
public void write(char[] cbuf, int off, int len) {
|
public void write(char[] cbuf, int off, int len) {
|
||||||
/* ignore */}
|
/* ignore */ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
|
|
@ -41,6 +41,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
|
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
|
||||||
|
import org.jivesoftware.smack.SmackConfiguration.UnknownIqRequestReplyMode;
|
||||||
import org.jivesoftware.smack.SmackException.AlreadyConnectedException;
|
import org.jivesoftware.smack.SmackException.AlreadyConnectedException;
|
||||||
import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
|
import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
|
@ -626,7 +627,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
hostAddresses = DNSUtil.resolveXMPPServiceDomain(config.getXMPPServiceDomain().toString(), failedAddresses, config.getDnssecMode());
|
hostAddresses = DNSUtil.resolveXMPPServiceDomain(config.getXMPPServiceDomain().toString(), failedAddresses, config.getDnssecMode());
|
||||||
}
|
}
|
||||||
// Either the populated host addresses are not empty *or* there must be at least one failed address.
|
// Either the populated host addresses are not empty *or* there must be at least one failed address.
|
||||||
assert(!hostAddresses.isEmpty() || !failedAddresses.isEmpty());
|
assert (!hostAddresses.isEmpty() || !failedAddresses.isEmpty());
|
||||||
return failedAddresses;
|
return failedAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,7 +666,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
@Override
|
@Override
|
||||||
public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
|
public void sendStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
|
||||||
Objects.requireNonNull(stanza, "Stanza must not be null");
|
Objects.requireNonNull(stanza, "Stanza must not be null");
|
||||||
assert(stanza instanceof Message || stanza instanceof Presence || stanza instanceof IQ);
|
assert (stanza instanceof Message || stanza instanceof Presence || stanza instanceof IQ);
|
||||||
|
|
||||||
throwNotConnectedExceptionIfAppropriate();
|
throwNotConnectedExceptionIfAppropriate();
|
||||||
switch (fromMode) {
|
switch (fromMode) {
|
||||||
|
@ -894,7 +895,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -991,20 +993,31 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
replyTimeout = timeout;
|
replyTimeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean replyToUnknownIqDefault = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the default value used to determine if new connection will reply to unknown IQ requests. The pre-configured
|
* Set the default value used to determine if new connection will reply to unknown IQ requests. The pre-configured
|
||||||
* default is 'true'.
|
* default is 'true'.
|
||||||
*
|
*
|
||||||
* @param replyToUnkownIqDefault
|
* @param replyToUnkownIqDefault
|
||||||
* @see #setReplyToUnknownIq(boolean)
|
* @see #setReplyToUnknownIq(boolean)
|
||||||
|
* @deprecated Use {@link SmackConfiguration#setUnknownIqRequestReplyMode(org.jivesoftware.smack.SmackConfiguration.UnknownIqRequestReplyMode)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
|
// TODO Remove in Smack 4.3
|
||||||
public static void setReplyToUnknownIqDefault(boolean replyToUnkownIqDefault) {
|
public static void setReplyToUnknownIqDefault(boolean replyToUnkownIqDefault) {
|
||||||
AbstractXMPPConnection.replyToUnknownIqDefault = replyToUnkownIqDefault;
|
SmackConfiguration.UnknownIqRequestReplyMode mode;
|
||||||
|
if (replyToUnkownIqDefault) {
|
||||||
|
mode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
|
||||||
|
} else {
|
||||||
|
mode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
|
||||||
|
}
|
||||||
|
SmackConfiguration.setUnknownIqRequestReplyMode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean replyToUnkownIq = replyToUnknownIqDefault;
|
private SmackConfiguration.UnknownIqRequestReplyMode unknownIqRequestReplyMode = SmackConfiguration.getUnknownIqRequestReplyMode();
|
||||||
|
|
||||||
|
public void setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode unknownIqRequestReplyMode) {
|
||||||
|
this.unknownIqRequestReplyMode = Objects.requireNonNull(unknownIqRequestReplyMode, "Mode must not be null");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set if Smack will automatically send
|
* Set if Smack will automatically send
|
||||||
|
@ -1012,9 +1025,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
* registered {@link IQRequestHandler} is received.
|
* registered {@link IQRequestHandler} is received.
|
||||||
*
|
*
|
||||||
* @param replyToUnknownIq
|
* @param replyToUnknownIq
|
||||||
|
* @deprecated use {@link #setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
|
// TODO Remove in Smack 4.3
|
||||||
public void setReplyToUnknownIq(boolean replyToUnknownIq) {
|
public void setReplyToUnknownIq(boolean replyToUnknownIq) {
|
||||||
this.replyToUnkownIq = replyToUnknownIq;
|
SmackConfiguration.UnknownIqRequestReplyMode mode;
|
||||||
|
if (replyToUnknownIq) {
|
||||||
|
mode = SmackConfiguration.UnknownIqRequestReplyMode.replyServiceUnavailable;
|
||||||
|
} else {
|
||||||
|
mode = SmackConfiguration.UnknownIqRequestReplyMode.doNotReply;
|
||||||
|
}
|
||||||
|
unknownIqRequestReplyMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseAndProcessStanza(XmlPullParser parser) throws Exception {
|
protected void parseAndProcessStanza(XmlPullParser parser) throws Exception {
|
||||||
|
@ -1048,7 +1070,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
protected void processStanza(final Stanza stanza) throws InterruptedException {
|
protected void processStanza(final Stanza stanza) throws InterruptedException {
|
||||||
assert(stanza != null);
|
assert (stanza != null);
|
||||||
lastStanzaReceived = System.currentTimeMillis();
|
lastStanzaReceived = System.currentTimeMillis();
|
||||||
// Deliver the incoming packet to listeners.
|
// Deliver the incoming packet to listeners.
|
||||||
executorService.executeBlocking(new Runnable() {
|
executorService.executeBlocking(new Runnable() {
|
||||||
|
@ -1089,13 +1111,24 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
|
throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
|
||||||
}
|
}
|
||||||
if (iqRequestHandler == null) {
|
if (iqRequestHandler == null) {
|
||||||
if (!replyToUnkownIq) {
|
XMPPError.Condition replyCondition;
|
||||||
|
switch (unknownIqRequestReplyMode) {
|
||||||
|
case doNotReply:
|
||||||
return;
|
return;
|
||||||
|
case replyFeatureNotImplemented:
|
||||||
|
replyCondition = XMPPError.Condition.feature_not_implemented;
|
||||||
|
break;
|
||||||
|
case replyServiceUnavailable:
|
||||||
|
replyCondition = XMPPError.Condition.service_unavailable;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the IQ stanza is of type "get" or "set" with no registered IQ request handler, then answer an
|
// If the IQ stanza is of type "get" or "set" with no registered IQ request handler, then answer an
|
||||||
// IQ of type 'error' with condition 'service-unavailable'.
|
// IQ of type 'error' with condition 'service-unavailable'.
|
||||||
ErrorIQ errorIQ = IQ.createErrorResponse(iq, XMPPError.getBuilder((
|
ErrorIQ errorIQ = IQ.createErrorResponse(iq, XMPPError.getBuilder((
|
||||||
XMPPError.Condition.service_unavailable)));
|
replyCondition)));
|
||||||
try {
|
try {
|
||||||
sendStanza(errorIQ);
|
sendStanza(errorIQ);
|
||||||
}
|
}
|
||||||
|
@ -1170,7 +1203,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through all collectors and notify the appropriate ones.
|
// Loop through all collectors and notify the appropriate ones.
|
||||||
for (StanzaCollector collector: collectors) {
|
for (StanzaCollector collector : collectors) {
|
||||||
collector.processStanza(packet);
|
collector.processStanza(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1192,7 +1225,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
for (StanzaListener listener : listenersToNotify) {
|
for (StanzaListener listener : listenersToNotify) {
|
||||||
try {
|
try {
|
||||||
listener.processStanza(packet);
|
listener.processStanza(packet);
|
||||||
} catch(NotConnectedException e) {
|
} catch (NotConnectedException e) {
|
||||||
LOGGER.log(Level.WARNING, "Got not connected exception, aborting", e);
|
LOGGER.log(Level.WARNING, "Got not connected exception, aborting", e);
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -162,7 +162,7 @@ public abstract class ConnectionConfiguration {
|
||||||
enabledSaslMechanisms = builder.enabledSaslMechanisms;
|
enabledSaslMechanisms = builder.enabledSaslMechanisms;
|
||||||
|
|
||||||
// If the enabledSaslmechanisms are set, then they must not be empty
|
// If the enabledSaslmechanisms are set, then they must not be empty
|
||||||
assert(enabledSaslMechanisms != null ? !enabledSaslMechanisms.isEmpty() : true);
|
assert (enabledSaslMechanisms != null ? !enabledSaslMechanisms.isEmpty() : true);
|
||||||
|
|
||||||
if (dnssecMode != DnssecMode.disabled && customSSLContext != null) {
|
if (dnssecMode != DnssecMode.disabled && customSSLContext != null) {
|
||||||
throw new IllegalStateException("You can not use a custom SSL context with DNSSEC enabled");
|
throw new IllegalStateException("You can not use a custom SSL context with DNSSEC enabled");
|
||||||
|
|
|
@ -132,13 +132,13 @@ public final class SASLAuthentication {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean blacklistSASLMechanism(String mechansim) {
|
public static boolean blacklistSASLMechanism(String mechansim) {
|
||||||
synchronized(BLACKLISTED_MECHANISMS) {
|
synchronized (BLACKLISTED_MECHANISMS) {
|
||||||
return BLACKLISTED_MECHANISMS.add(mechansim);
|
return BLACKLISTED_MECHANISMS.add(mechansim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean unBlacklistSASLMechanism(String mechanism) {
|
public static boolean unBlacklistSASLMechanism(String mechanism) {
|
||||||
synchronized(BLACKLISTED_MECHANISMS) {
|
synchronized (BLACKLISTED_MECHANISMS) {
|
||||||
return BLACKLISTED_MECHANISMS.remove(mechanism);
|
return BLACKLISTED_MECHANISMS.remove(mechanism);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ public final class SASLAuthentication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saslException != null){
|
if (saslException != null) {
|
||||||
if (saslException instanceof SmackException) {
|
if (saslException instanceof SmackException) {
|
||||||
throw (SmackException) saslException;
|
throw (SmackException) saslException;
|
||||||
} else if (saslException instanceof SASLErrorException) {
|
} else if (saslException instanceof SASLErrorException) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.jivesoftware.smack.debugger.SmackDebugger;
|
||||||
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
|
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
|
||||||
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
|
import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
|
||||||
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
||||||
|
import org.jivesoftware.smack.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the configuration of Smack. The configuration is used for:
|
* Represents the configuration of Smack. The configuration is used for:
|
||||||
|
@ -173,7 +174,7 @@ public final class SmackConfiguration {
|
||||||
* @param mech the SASL mechanism to be added
|
* @param mech the SASL mechanism to be added
|
||||||
*/
|
*/
|
||||||
public static void addSaslMech(String mech) {
|
public static void addSaslMech(String mech) {
|
||||||
if(!defaultMechs.contains(mech)) {
|
if (!defaultMechs.contains(mech)) {
|
||||||
defaultMechs.add(mech);
|
defaultMechs.add(mech);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,7 +185,7 @@ public final class SmackConfiguration {
|
||||||
* @param mechs the Collection of SASL mechanisms to be added
|
* @param mechs the Collection of SASL mechanisms to be added
|
||||||
*/
|
*/
|
||||||
public static void addSaslMechs(Collection<String> mechs) {
|
public static void addSaslMechs(Collection<String> mechs) {
|
||||||
for(String mech : mechs) {
|
for (String mech : mechs) {
|
||||||
addSaslMech(mech);
|
addSaslMech(mech);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,4 +371,20 @@ public final class SmackConfiguration {
|
||||||
return defaultHostnameVerififer;
|
return defaultHostnameVerififer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum UnknownIqRequestReplyMode {
|
||||||
|
doNotReply,
|
||||||
|
replyFeatureNotImplemented,
|
||||||
|
replyServiceUnavailable,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Change to replyFeatureNotImplemented in Smack 4.3
|
||||||
|
private static UnknownIqRequestReplyMode unknownIqRequestReplyMode = UnknownIqRequestReplyMode.replyServiceUnavailable;
|
||||||
|
|
||||||
|
public static UnknownIqRequestReplyMode getUnknownIqRequestReplyMode() {
|
||||||
|
return unknownIqRequestReplyMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setUnknownIqRequestReplyMode(UnknownIqRequestReplyMode unknownIqRequestReplyMode) {
|
||||||
|
SmackConfiguration.unknownIqRequestReplyMode = Objects.requireNonNull(unknownIqRequestReplyMode, "Must set mode");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
170
smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java
Normal file
170
smack-core/src/main/java/org/jivesoftware/smack/SmackFuture.java
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
import org.jivesoftware.smack.packet.Stanza;
|
||||||
|
|
||||||
|
public abstract class SmackFuture<V> implements Future<V> {
|
||||||
|
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
private V result;
|
||||||
|
|
||||||
|
protected Exception exception;
|
||||||
|
|
||||||
|
private SuccessCallback<V> successCallback;
|
||||||
|
|
||||||
|
private ExceptionCallback exceptionCallback;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized final boolean cancel(boolean mayInterruptIfRunning) {
|
||||||
|
if (isDone()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelled = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized final boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized final boolean isDone() {
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSuccessOrError(SuccessCallback<V> successCallback, ExceptionCallback exceptionCallback) {
|
||||||
|
this.successCallback = successCallback;
|
||||||
|
this.exceptionCallback = exceptionCallback;
|
||||||
|
|
||||||
|
maybeInvokeCallbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSuccess(SuccessCallback<V> successCallback) {
|
||||||
|
onSuccessOrError(successCallback, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(ExceptionCallback exceptionCallback) {
|
||||||
|
onSuccessOrError(null, exceptionCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final V getResultOrThrow() throws ExecutionException {
|
||||||
|
assert (result != null || exception != null);
|
||||||
|
if (result != null) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ExecutionException(exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized final V get() throws InterruptedException, ExecutionException {
|
||||||
|
while (result == null && exception == null) {
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getResultOrThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized final V get(long timeout, TimeUnit unit)
|
||||||
|
throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
final long deadline = System.currentTimeMillis() + unit.toMillis(timeout);
|
||||||
|
while (result != null && exception != null) {
|
||||||
|
final long waitTimeRemaining = deadline - System.currentTimeMillis();
|
||||||
|
if (waitTimeRemaining > 0) {
|
||||||
|
wait(waitTimeRemaining);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == null || exception == null) {
|
||||||
|
throw new TimeoutException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return getResultOrThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final synchronized void maybeInvokeCallbacks() {
|
||||||
|
if (result != null && successCallback != null) {
|
||||||
|
successCallback.onSuccess(result);
|
||||||
|
} else if (exception != null && exceptionCallback != null) {
|
||||||
|
exceptionCallback.processException(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method checks if the given exception is <b>not</b> fatal. If this method returns <code>false</code>, then
|
||||||
|
* the future will automatically set the given exception as failure reason and notify potential waiting threads.
|
||||||
|
*
|
||||||
|
* @param exception the exception to check.
|
||||||
|
* @return <code>true</code> if the exception is not fatal, <code>false</code> otherwise.
|
||||||
|
*/
|
||||||
|
protected abstract boolean isNonFatalException(Exception exception);
|
||||||
|
|
||||||
|
protected abstract void handleStanza(Stanza stanza) throws NotConnectedException, InterruptedException;
|
||||||
|
|
||||||
|
protected final void setResult(V result) {
|
||||||
|
assert (Thread.holdsLock(this));
|
||||||
|
|
||||||
|
this.result = result;
|
||||||
|
this.notifyAll();
|
||||||
|
|
||||||
|
maybeInvokeCallbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class InternalSmackFuture<V> extends SmackFuture<V> implements StanzaListener, ExceptionCallback {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized final void processException(Exception exception) {
|
||||||
|
if (!isNonFatalException(exception)) {
|
||||||
|
this.exception = exception;
|
||||||
|
this.notifyAll();
|
||||||
|
|
||||||
|
maybeInvokeCallbacks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper method for {@link #handleStanza(Stanza)}. Note that this method is <code>synchronized</code>.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized final void processStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
|
||||||
|
handleStanza(stanza);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple version of InternalSmackFuture which implements {@link #isNonFatalException(Exception)} as always returning <code>false</code> method.
|
||||||
|
*
|
||||||
|
* @param <V>
|
||||||
|
*/
|
||||||
|
public static abstract class SimpleInternalSmackFuture<V> extends InternalSmackFuture<V> {
|
||||||
|
@Override
|
||||||
|
protected boolean isNonFatalException(Exception exception) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -68,7 +68,7 @@ public final class SmackInitialization {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.log(Level.WARNING, "IOException closing stream", e);
|
LOGGER.log(Level.WARNING, "IOException closing stream", e);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not determine Smack version", e);
|
LOGGER.log(Level.SEVERE, "Could not determine Smack version", e);
|
||||||
smackVersion = "unkown";
|
smackVersion = "unkown";
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
|
public interface SuccessCallback<T> {
|
||||||
|
|
||||||
|
public void onSuccess(T result);
|
||||||
|
|
||||||
|
}
|
|
@ -79,7 +79,7 @@ public class SynchronizationPoint<E extends Exception> {
|
||||||
if (request instanceof Stanza) {
|
if (request instanceof Stanza) {
|
||||||
connection.sendStanza((Stanza) request);
|
connection.sendStanza((Stanza) request);
|
||||||
}
|
}
|
||||||
else if (request instanceof Nonza){
|
else if (request instanceof Nonza) {
|
||||||
connection.sendNonza((Nonza) request);
|
connection.sendNonza((Nonza) request);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unsupported element type");
|
throw new IllegalStateException("Unsupported element type");
|
||||||
|
|
|
@ -413,6 +413,7 @@ public interface XMPPConnection {
|
||||||
* @deprecated use {@link #getReplyTimeout()} instead.
|
* @deprecated use {@link #getReplyTimeout()} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
// TODO Remove in Smack 4.3
|
||||||
public long getPacketReplyTimeout();
|
public long getPacketReplyTimeout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -423,6 +424,7 @@ public interface XMPPConnection {
|
||||||
* @deprecated use {@link #setReplyTimeout(long)} instead.
|
* @deprecated use {@link #setReplyTimeout(long)} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
// TODO Remove in Smack 4.3
|
||||||
public void setPacketReplyTimeout(long timeout);
|
public void setPacketReplyTimeout(long timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,7 +39,7 @@ public abstract class AbstractJidTypeFilter implements StanzaFilter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean accept(Stanza stanza) {
|
public final boolean accept(Stanza stanza) {
|
||||||
final Jid jid = stanza.getFrom();
|
final Jid jid = getJidToInspect(stanza);
|
||||||
|
|
||||||
if (jid == null) {
|
if (jid == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -45,7 +45,7 @@ public abstract class AbstractListFilter implements StanzaFilter {
|
||||||
*/
|
*/
|
||||||
protected AbstractListFilter(StanzaFilter... filters) {
|
protected AbstractListFilter(StanzaFilter... filters) {
|
||||||
Objects.requireNonNull(filters, "Parameter must not be null.");
|
Objects.requireNonNull(filters, "Parameter must not be null.");
|
||||||
for(StanzaFilter filter : filters) {
|
for (StanzaFilter filter : filters) {
|
||||||
Objects.requireNonNull(filter, "Parameter must not be null.");
|
Objects.requireNonNull(filter, "Parameter must not be null.");
|
||||||
}
|
}
|
||||||
this.filters = new ArrayList<StanzaFilter>(Arrays.asList(filters));
|
this.filters = new ArrayList<StanzaFilter>(Arrays.asList(filters));
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jivesoftware.smack.filter;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters message stanzas which have at least one body.
|
||||||
|
*/
|
||||||
|
public final class MessageWithThreadFilter extends FlexibleStanzaTypeFilter<Message> {
|
||||||
|
|
||||||
|
public static final StanzaFilter INSTANCE = new MessageWithThreadFilter();
|
||||||
|
|
||||||
|
private MessageWithThreadFilter() {
|
||||||
|
super(Message.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean acceptSpecific(Message message) {
|
||||||
|
return StringUtils.isNotEmpty(message.getThread());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
}
|
|
@ -67,7 +67,10 @@ public class AbstractError {
|
||||||
String defaultLocale = Locale.getDefault().getLanguage();
|
String defaultLocale = Locale.getDefault().getLanguage();
|
||||||
String descriptiveText = getDescriptiveText(defaultLocale);
|
String descriptiveText = getDescriptiveText(defaultLocale);
|
||||||
if (descriptiveText == null) {
|
if (descriptiveText == null) {
|
||||||
descriptiveText = getDescriptiveText("");
|
descriptiveText = getDescriptiveText("en");
|
||||||
|
if (descriptiveText == null) {
|
||||||
|
descriptiveText = getDescriptiveText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return descriptiveText;
|
return descriptiveText;
|
||||||
}
|
}
|
||||||
|
|
|
@ -488,7 +488,7 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
|
||||||
// Add the subject in other languages
|
// Add the subject in other languages
|
||||||
for (Subject subject : getSubjects()) {
|
for (Subject subject : getSubjects()) {
|
||||||
// Skip the default language
|
// Skip the default language
|
||||||
if(subject.equals(defaultSubject))
|
if (subject.equals(defaultSubject))
|
||||||
continue;
|
continue;
|
||||||
buf.append(subject.toXML());
|
buf.append(subject.toXML());
|
||||||
}
|
}
|
||||||
|
@ -500,7 +500,7 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
|
||||||
// Add the bodies in other languages
|
// Add the bodies in other languages
|
||||||
for (Body body : getBodies()) {
|
for (Body body : getBodies()) {
|
||||||
// Skip the default language
|
// Skip the default language
|
||||||
if(body.equals(defaultBody))
|
if (body.equals(defaultBody))
|
||||||
continue;
|
continue;
|
||||||
buf.append(body.toXML());
|
buf.append(body.toXML());
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ public final class StandardExtensionElement implements ExtensionElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StandardExtensionElement> getElements() {
|
public List<StandardExtensionElement> getElements() {
|
||||||
if (elements == null){
|
if (elements == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return elements.values();
|
return elements.values();
|
||||||
|
|
|
@ -23,7 +23,7 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
public abstract class Provider<E extends Element> {
|
public abstract class Provider<E extends Element> {
|
||||||
|
|
||||||
public final E parse(XmlPullParser parser) throws Exception{
|
public final E parse(XmlPullParser parser) throws Exception {
|
||||||
// XPP3 calling convention assert: Parser should be at start tag
|
// XPP3 calling convention assert: Parser should be at start tag
|
||||||
ParserUtils.assertAtStartTag(parser);
|
ParserUtils.assertAtStartTag(parser);
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class ProviderFileLoader implements ProviderLoader {
|
||||||
}
|
}
|
||||||
while (eventType != XmlPullParser.END_DOCUMENT);
|
while (eventType != XmlPullParser.END_DOCUMENT);
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e) {
|
||||||
LOGGER.log(Level.SEVERE, "Unknown error occurred while parsing provider file", e);
|
LOGGER.log(Level.SEVERE, "Unknown error occurred while parsing provider file", e);
|
||||||
exceptions.add(e);
|
exceptions.add(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ProxyException extends IOException {
|
||||||
|
|
||||||
public ProxyException(ProxyInfo.ProxyType type, String ex)
|
public ProxyException(ProxyInfo.ProxyType type, String ex)
|
||||||
{
|
{
|
||||||
super("Proxy Exception " + type.toString() + " : "+ex);
|
super("Proxy Exception " + type.toString() + " : " + ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyException(ProxyInfo.ProxyType type)
|
public ProxyException(ProxyInfo.ProxyType type)
|
||||||
|
|
|
@ -50,12 +50,12 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
|
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
|
||||||
in=socket.getInputStream();
|
in = socket.getInputStream();
|
||||||
out=socket.getOutputStream();
|
out = socket.getOutputStream();
|
||||||
socket.setTcpNoDelay(true);
|
socket.setTcpNoDelay(true);
|
||||||
|
|
||||||
byte[] buf=new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
int index=0;
|
int index = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1) CONNECT
|
1) CONNECT
|
||||||
|
@ -75,27 +75,27 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
|
||||||
of all zero bits.
|
of all zero bits.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
index=0;
|
index = 0;
|
||||||
buf[index++]=4;
|
buf[index++] = 4;
|
||||||
buf[index++]=1;
|
buf[index++] = 1;
|
||||||
|
|
||||||
buf[index++]=(byte)(port>>>8);
|
buf[index++] = (byte) (port >>> 8);
|
||||||
buf[index++]=(byte)(port&0xff);
|
buf[index++] = (byte) (port & 0xff);
|
||||||
|
|
||||||
InetAddress inetAddress = InetAddress.getByName(proxy_host);
|
InetAddress inetAddress = InetAddress.getByName(proxy_host);
|
||||||
byte[] byteAddress = inetAddress.getAddress();
|
byte[] byteAddress = inetAddress.getAddress();
|
||||||
for (int i = 0; i < byteAddress.length; i++)
|
for (int i = 0; i < byteAddress.length; i++)
|
||||||
{
|
{
|
||||||
buf[index++]=byteAddress[i];
|
buf[index++] = byteAddress[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(user!=null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
byte[] userBytes = user.getBytes(StringUtils.UTF8);
|
byte[] userBytes = user.getBytes(StringUtils.UTF8);
|
||||||
System.arraycopy(userBytes, 0, buf, index, user.length());
|
System.arraycopy(userBytes, 0, buf, index, user.length());
|
||||||
index+=user.length();
|
index += user.length();
|
||||||
}
|
}
|
||||||
buf[index++]=0;
|
buf[index++] = 0;
|
||||||
out.write(buf, 0, index);
|
out.write(buf, 0, index);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -125,49 +125,49 @@ public class Socks4ProxySocketConnection implements ProxySocketConnection {
|
||||||
The remaining fields are ignored.
|
The remaining fields are ignored.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int len=6;
|
int len = 6;
|
||||||
int s=0;
|
int s = 0;
|
||||||
while(s<len)
|
while (s < len)
|
||||||
{
|
{
|
||||||
int i=in.read(buf, s, len-s);
|
int i = in.read(buf, s, len - s);
|
||||||
if(i<=0)
|
if (i <= 0)
|
||||||
{
|
{
|
||||||
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,
|
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,
|
||||||
"stream is closed");
|
"stream is closed");
|
||||||
}
|
}
|
||||||
s+=i;
|
s += i;
|
||||||
}
|
}
|
||||||
if(buf[0]!=0)
|
if (buf[0] != 0)
|
||||||
{
|
{
|
||||||
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,
|
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,
|
||||||
"server returns VN "+buf[0]);
|
"server returns VN " + buf[0]);
|
||||||
}
|
}
|
||||||
if(buf[1]!=90)
|
if (buf[1] != 90)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
catch(Exception eee)
|
catch (Exception eee)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
String message="ProxySOCKS4: server returns CD "+buf[1];
|
String message = "ProxySOCKS4: server returns CD " + buf[1];
|
||||||
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4,message);
|
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, message);
|
||||||
}
|
}
|
||||||
byte[] temp = new byte[2];
|
byte[] temp = new byte[2];
|
||||||
in.read(temp, 0, 2);
|
in.read(temp, 0, 2);
|
||||||
}
|
}
|
||||||
catch(RuntimeException e)
|
catch (RuntimeException e)
|
||||||
{
|
{
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
catch(Exception eee)
|
catch (Exception eee)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, e.toString());
|
throw new ProxyException(ProxyInfo.ProxyType.SOCKS4, e.toString());
|
||||||
|
|
|
@ -50,13 +50,13 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
|
socket.connect(new InetSocketAddress(proxy_host, proxy_port), timeout);
|
||||||
in=socket.getInputStream();
|
in = socket.getInputStream();
|
||||||
out=socket.getOutputStream();
|
out = socket.getOutputStream();
|
||||||
|
|
||||||
socket.setTcpNoDelay(true);
|
socket.setTcpNoDelay(true);
|
||||||
|
|
||||||
byte[] buf=new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
int index=0;
|
int index = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
+----+----------+----------+
|
+----+----------+----------+
|
||||||
|
@ -79,11 +79,11 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
o X'FF' NO ACCEPTABLE METHODS
|
o X'FF' NO ACCEPTABLE METHODS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
buf[index++]=5;
|
buf[index++] = 5;
|
||||||
|
|
||||||
buf[index++]=2;
|
buf[index++] = 2;
|
||||||
buf[index++]=0; // NO AUTHENTICATION REQUIRED
|
buf[index++] = 0; // NO AUTHENTICATION REQUIRED
|
||||||
buf[index++]=2; // USERNAME/PASSWORD
|
buf[index++] = 2; // USERNAME/PASSWORD
|
||||||
|
|
||||||
out.write(buf, 0, index);
|
out.write(buf, 0, index);
|
||||||
|
|
||||||
|
@ -100,14 +100,14 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
//in.read(buf, 0, 2);
|
//in.read(buf, 0, 2);
|
||||||
fill(in, buf, 2);
|
fill(in, buf, 2);
|
||||||
|
|
||||||
boolean check=false;
|
boolean check = false;
|
||||||
switch((buf[1])&0xff)
|
switch ((buf[1]) & 0xff)
|
||||||
{
|
{
|
||||||
case 0: // NO AUTHENTICATION REQUIRED
|
case 0: // NO AUTHENTICATION REQUIRED
|
||||||
check=true;
|
check = true;
|
||||||
break;
|
break;
|
||||||
case 2: // USERNAME/PASSWORD
|
case 2: // USERNAME/PASSWORD
|
||||||
if(user==null || passwd==null)
|
if (user == null || passwd == null)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -131,18 +131,18 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
PASSWD field that follows. The PASSWD field contains the password
|
PASSWD field that follows. The PASSWD field contains the password
|
||||||
association with the given UNAME.
|
association with the given UNAME.
|
||||||
*/
|
*/
|
||||||
index=0;
|
index = 0;
|
||||||
buf[index++]=1;
|
buf[index++] = 1;
|
||||||
buf[index++]=(byte)(user.length());
|
buf[index++] = (byte) (user.length());
|
||||||
byte[] userBytes = user.getBytes(StringUtils.UTF8);
|
byte[] userBytes = user.getBytes(StringUtils.UTF8);
|
||||||
System.arraycopy(userBytes, 0, buf, index,
|
System.arraycopy(userBytes, 0, buf, index,
|
||||||
user.length());
|
user.length());
|
||||||
index+=user.length();
|
index += user.length();
|
||||||
byte[] passwordBytes = user.getBytes(StringUtils.UTF8);
|
byte[] passwordBytes = user.getBytes(StringUtils.UTF8);
|
||||||
buf[index++]=(byte)(passwordBytes.length);
|
buf[index++] = (byte) (passwordBytes.length);
|
||||||
System.arraycopy(passwordBytes, 0, buf, index,
|
System.arraycopy(passwordBytes, 0, buf, index,
|
||||||
passwd.length());
|
passwd.length());
|
||||||
index+=passwd.length();
|
index += passwd.length();
|
||||||
|
|
||||||
out.write(buf, 0, index);
|
out.write(buf, 0, index);
|
||||||
|
|
||||||
|
@ -162,21 +162,21 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
*/
|
*/
|
||||||
//in.read(buf, 0, 2);
|
//in.read(buf, 0, 2);
|
||||||
fill(in, buf, 2);
|
fill(in, buf, 2);
|
||||||
if(buf[1]==0)
|
if (buf[1] == 0)
|
||||||
{
|
{
|
||||||
check=true;
|
check = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!check)
|
if (!check)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
catch(Exception eee)
|
catch (Exception eee)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
|
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
|
||||||
|
@ -209,19 +209,19 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
order
|
order
|
||||||
*/
|
*/
|
||||||
|
|
||||||
index=0;
|
index = 0;
|
||||||
buf[index++]=5;
|
buf[index++] = 5;
|
||||||
buf[index++]=1; // CONNECT
|
buf[index++] = 1; // CONNECT
|
||||||
buf[index++]=0;
|
buf[index++] = 0;
|
||||||
|
|
||||||
byte[] hostb= host.getBytes(StringUtils.UTF8);
|
byte[] hostb = host.getBytes(StringUtils.UTF8);
|
||||||
int len=hostb.length;
|
int len = hostb.length;
|
||||||
buf[index++]=3; // DOMAINNAME
|
buf[index++] = 3; // DOMAINNAME
|
||||||
buf[index++]=(byte)(len);
|
buf[index++] = (byte) (len);
|
||||||
System.arraycopy(hostb, 0, buf, index, len);
|
System.arraycopy(hostb, 0, buf, index, len);
|
||||||
index+=len;
|
index += len;
|
||||||
buf[index++]=(byte)(port>>>8);
|
buf[index++] = (byte) (port >>> 8);
|
||||||
buf[index++]=(byte)(port&0xff);
|
buf[index++] = (byte) (port & 0xff);
|
||||||
|
|
||||||
out.write(buf, 0, index);
|
out.write(buf, 0, index);
|
||||||
|
|
||||||
|
@ -263,20 +263,20 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
//in.read(buf, 0, 4);
|
//in.read(buf, 0, 4);
|
||||||
fill(in, buf, 4);
|
fill(in, buf, 4);
|
||||||
|
|
||||||
if(buf[1]!=0)
|
if (buf[1] != 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
catch(Exception eee)
|
catch (Exception eee)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
|
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5,
|
||||||
"server returns "+buf[1]);
|
"server returns " + buf[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(buf[3]&0xff)
|
switch (buf[3] & 0xff)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
//in.read(buf, 0, 6);
|
//in.read(buf, 0, 6);
|
||||||
|
@ -286,7 +286,7 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
//in.read(buf, 0, 1);
|
//in.read(buf, 0, 1);
|
||||||
fill(in, buf, 1);
|
fill(in, buf, 1);
|
||||||
//in.read(buf, 0, buf[0]+2);
|
//in.read(buf, 0, buf[0]+2);
|
||||||
fill(in, buf, (buf[0]&0xff)+2);
|
fill(in, buf, (buf[0] & 0xff) + 2);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
//in.read(buf, 0, 18);
|
//in.read(buf, 0, 18);
|
||||||
|
@ -295,17 +295,17 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(RuntimeException e)
|
catch (RuntimeException e)
|
||||||
{
|
{
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
catch(Exception eee)
|
catch (Exception eee)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
// TODO convert to IOException(e) when minimum Android API level is 9 or higher
|
// TODO convert to IOException(e) when minimum Android API level is 9 or higher
|
||||||
|
@ -316,16 +316,16 @@ public class Socks5ProxySocketConnection implements ProxySocketConnection {
|
||||||
private static void fill(InputStream in, byte[] buf, int len)
|
private static void fill(InputStream in, byte[] buf, int len)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
int s=0;
|
int s = 0;
|
||||||
while(s<len)
|
while (s < len)
|
||||||
{
|
{
|
||||||
int i=in.read(buf, s, len-s);
|
int i = in.read(buf, s, len - s);
|
||||||
if(i<=0)
|
if (i <= 0)
|
||||||
{
|
{
|
||||||
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, "stream " +
|
throw new ProxyException(ProxyInfo.ProxyType.SOCKS5, "stream " +
|
||||||
"is closed");
|
"is closed");
|
||||||
}
|
}
|
||||||
s+=i;
|
s += i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.authorizationId = authzid;
|
this.authorizationId = authzid;
|
||||||
this.sslSession = sslSession;
|
this.sslSession = sslSession;
|
||||||
assert(authorizationId == null || authzidSupported());
|
assert (authorizationId == null || authzidSupported());
|
||||||
authenticateInternal();
|
authenticateInternal();
|
||||||
authenticate();
|
authenticate();
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ public abstract class SASLMechanism implements Comparable<SASLMechanism> {
|
||||||
this.serviceName = serviceName;
|
this.serviceName = serviceName;
|
||||||
this.authorizationId = authzid;
|
this.authorizationId = authzid;
|
||||||
this.sslSession = sslSession;
|
this.sslSession = sslSession;
|
||||||
assert(authorizationId == null || authzidSupported());
|
assert (authorizationId == null || authzidSupported());
|
||||||
authenticateInternal(cbh);
|
authenticateInternal(cbh);
|
||||||
authenticate();
|
authenticate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ public abstract class ScramMechanism extends SASLMechanism {
|
||||||
}
|
}
|
||||||
|
|
||||||
String cbName = getChannelBindingName();
|
String cbName = getChannelBindingName();
|
||||||
assert(StringUtils.isNotEmpty(cbName));
|
assert (StringUtils.isNotEmpty(cbName));
|
||||||
|
|
||||||
return cbName + ',' + authzidPortion + ",";
|
return cbName + ',' + authzidPortion + ",";
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class EventManger<K, R, E extends Exception> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
reference.eventResult = eventResult;
|
reference.eventResult = eventResult;
|
||||||
synchronized(reference) {
|
synchronized (reference) {
|
||||||
reference.notifyAll();
|
reference.notifyAll();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2014 Florian Schmaus
|
* Copyright 2014-2017 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -19,9 +19,13 @@ package org.jivesoftware.smack.util;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class LazyStringBuilder implements Appendable, CharSequence {
|
public class LazyStringBuilder implements Appendable, CharSequence {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(LazyStringBuilder.class.getName());
|
||||||
|
|
||||||
private final List<CharSequence> list;
|
private final List<CharSequence> list;
|
||||||
|
|
||||||
private String cache;
|
private String cache;
|
||||||
|
@ -69,8 +73,15 @@ public class LazyStringBuilder implements Appendable, CharSequence {
|
||||||
return cache.length();
|
return cache.length();
|
||||||
}
|
}
|
||||||
int length = 0;
|
int length = 0;
|
||||||
for (CharSequence csq : list) {
|
try {
|
||||||
length += csq.length();
|
for (CharSequence csq : list) {
|
||||||
|
length += csq.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NullPointerException npe) {
|
||||||
|
StringBuilder sb = safeToStringBuilder();
|
||||||
|
LOGGER.log(Level.SEVERE, "The following LazyStringBuilder threw a NullPointerException: " + sb, npe);
|
||||||
|
throw npe;
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
@ -107,6 +118,14 @@ public class LazyStringBuilder implements Appendable, CharSequence {
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StringBuilder safeToStringBuilder() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (CharSequence csq : list) {
|
||||||
|
sb.append(csq);
|
||||||
|
}
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the List of CharSequences representation of this instance. The list is unmodifiable. If
|
* Get the List of CharSequences representation of this instance. The list is unmodifiable. If
|
||||||
* the resulting String was already cached, a list with a single String entry will be returned.
|
* the resulting String was already cached, a list with a single String entry will be returned.
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class MultiMap<K,V> {
|
||||||
if (res == null) {
|
if (res == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
assert(!res.isEmpty());
|
assert (!res.isEmpty());
|
||||||
return res.iterator().next();
|
return res.iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ public class PacketParserUtils {
|
||||||
public static Message parseMessage(XmlPullParser parser)
|
public static Message parseMessage(XmlPullParser parser)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ParserUtils.assertAtStartTag(parser);
|
ParserUtils.assertAtStartTag(parser);
|
||||||
assert(parser.getName().equals(Message.ELEMENT));
|
assert (parser.getName().equals(Message.ELEMENT));
|
||||||
|
|
||||||
final int initialDepth = parser.getDepth();
|
final int initialDepth = parser.getDepth();
|
||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
|
@ -247,7 +247,7 @@ public class PacketParserUtils {
|
||||||
case XmlPullParser.START_TAG:
|
case XmlPullParser.START_TAG:
|
||||||
String elementName = parser.getName();
|
String elementName = parser.getName();
|
||||||
String namespace = parser.getNamespace();
|
String namespace = parser.getNamespace();
|
||||||
switch(elementName) {
|
switch (elementName) {
|
||||||
case "subject":
|
case "subject":
|
||||||
String xmlLangSubject = getLanguageAttribute(parser);
|
String xmlLangSubject = getLanguageAttribute(parser);
|
||||||
if (xmlLangSubject == null) {
|
if (xmlLangSubject == null) {
|
||||||
|
@ -385,7 +385,7 @@ public class PacketParserUtils {
|
||||||
*/
|
*/
|
||||||
public static CharSequence parseContent(XmlPullParser parser)
|
public static CharSequence parseContent(XmlPullParser parser)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
assert(parser.getEventType() == XmlPullParser.START_TAG);
|
assert (parser.getEventType() == XmlPullParser.START_TAG);
|
||||||
if (parser.isEmptyElementTag()) {
|
if (parser.isEmptyElementTag()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -546,7 +546,7 @@ public class PacketParserUtils {
|
||||||
case XmlPullParser.START_TAG:
|
case XmlPullParser.START_TAG:
|
||||||
String elementName = parser.getName();
|
String elementName = parser.getName();
|
||||||
String namespace = parser.getNamespace();
|
String namespace = parser.getNamespace();
|
||||||
switch(elementName) {
|
switch (elementName) {
|
||||||
case "status":
|
case "status":
|
||||||
presence.setStatus(parser.nextText());
|
presence.setStatus(parser.nextText());
|
||||||
break;
|
break;
|
||||||
|
@ -620,7 +620,7 @@ public class PacketParserUtils {
|
||||||
case XmlPullParser.START_TAG:
|
case XmlPullParser.START_TAG:
|
||||||
String elementName = parser.getName();
|
String elementName = parser.getName();
|
||||||
String namespace = parser.getNamespace();
|
String namespace = parser.getNamespace();
|
||||||
switch(elementName) {
|
switch (elementName) {
|
||||||
case "error":
|
case "error":
|
||||||
error = PacketParserUtils.parseError(parser);
|
error = PacketParserUtils.parseError(parser);
|
||||||
break;
|
break;
|
||||||
|
@ -775,7 +775,7 @@ public class PacketParserUtils {
|
||||||
descriptiveTexts = parseDescriptiveTexts(parser, descriptiveTexts);
|
descriptiveTexts = parseDescriptiveTexts(parser, descriptiveTexts);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(condition == null);
|
assert (condition == null);
|
||||||
condition = parser.getName();
|
condition = parser.getName();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -945,7 +945,7 @@ public class PacketParserUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(parser.getEventType() == XmlPullParser.END_TAG);
|
assert (parser.getEventType() == XmlPullParser.END_TAG);
|
||||||
return new StartTls(required);
|
return new StartTls(required);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -954,7 +954,7 @@ public class PacketParserUtils {
|
||||||
final int initialDepth = parser.getDepth();
|
final int initialDepth = parser.getDepth();
|
||||||
boolean optional = false;
|
boolean optional = false;
|
||||||
if (!parser.isEmptyElementTag()) {
|
if (!parser.isEmptyElementTag()) {
|
||||||
outerloop: while(true) {
|
outerloop: while (true) {
|
||||||
int event = parser.next();
|
int event = parser.next();
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case XmlPullParser.START_TAG:
|
case XmlPullParser.START_TAG:
|
||||||
|
@ -1022,7 +1022,7 @@ public class PacketParserUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
|
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
|
||||||
String namespace) throws Exception{
|
String namespace) throws Exception {
|
||||||
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
|
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
|
||||||
packet.addExtension(packetExtension);
|
packet.addExtension(packetExtension);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class ParserUtils {
|
||||||
public static final String JID = "jid";
|
public static final String JID = "jid";
|
||||||
|
|
||||||
public static void assertAtStartTag(XmlPullParser parser) throws XmlPullParserException {
|
public static void assertAtStartTag(XmlPullParser parser) throws XmlPullParserException {
|
||||||
assert(parser.getEventType() == XmlPullParser.START_TAG);
|
assert (parser.getEventType() == XmlPullParser.START_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertAtStartTag(XmlPullParser parser, String name) throws XmlPullParserException {
|
public static void assertAtStartTag(XmlPullParser parser, String name) throws XmlPullParserException {
|
||||||
|
@ -52,7 +52,7 @@ public class ParserUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertAtEndTag(XmlPullParser parser) throws XmlPullParserException {
|
public static void assertAtEndTag(XmlPullParser parser) throws XmlPullParserException {
|
||||||
assert(parser.getEventType() == XmlPullParser.END_TAG);
|
assert (parser.getEventType() == XmlPullParser.END_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forwardToEndTagOfDepth(XmlPullParser parser, int depth)
|
public static void forwardToEndTagOfDepth(XmlPullParser parser, int depth)
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class StringUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final int len = input.length();
|
final int len = input.length();
|
||||||
final StringBuilder out = new StringBuilder((int)(len*1.3));
|
final StringBuilder out = new StringBuilder((int) (len * 1.3));
|
||||||
CharSequence toAppend;
|
CharSequence toAppend;
|
||||||
char ch;
|
char ch;
|
||||||
int last = 0;
|
int last = 0;
|
||||||
|
@ -153,7 +153,7 @@ public class StringUtils {
|
||||||
break;
|
break;
|
||||||
case forAttribute:
|
case forAttribute:
|
||||||
// No need to escape '>' for attributes.
|
// No need to escape '>' for attributes.
|
||||||
switch(ch) {
|
switch (ch) {
|
||||||
case '<':
|
case '<':
|
||||||
toAppend = LT_ENCODE;
|
toAppend = LT_ENCODE;
|
||||||
break;
|
break;
|
||||||
|
@ -172,7 +172,7 @@ public class StringUtils {
|
||||||
break;
|
break;
|
||||||
case forAttributeApos:
|
case forAttributeApos:
|
||||||
// No need to escape '>' and '"' for attributes using '\'' as quote.
|
// No need to escape '>' and '"' for attributes using '\'' as quote.
|
||||||
switch(ch) {
|
switch (ch) {
|
||||||
case '<':
|
case '<':
|
||||||
toAppend = LT_ENCODE;
|
toAppend = LT_ENCODE;
|
||||||
break;
|
break;
|
||||||
|
@ -188,7 +188,7 @@ public class StringUtils {
|
||||||
break;
|
break;
|
||||||
case forText:
|
case forText:
|
||||||
// No need to escape '"', '\'', and '>' for text.
|
// No need to escape '"', '\'', and '>' for text.
|
||||||
switch(ch) {
|
switch (ch) {
|
||||||
case '<':
|
case '<':
|
||||||
toAppend = LT_ENCODE;
|
toAppend = LT_ENCODE;
|
||||||
break;
|
break;
|
||||||
|
@ -307,8 +307,8 @@ public class StringUtils {
|
||||||
|
|
||||||
final Random random = randGen.get();
|
final Random random = randGen.get();
|
||||||
// Create a char buffer to put random letters and numbers in.
|
// Create a char buffer to put random letters and numbers in.
|
||||||
char [] randBuffer = new char[length];
|
char[] randBuffer = new char[length];
|
||||||
for (int i=0; i<randBuffer.length; i++) {
|
for (int i = 0; i < randBuffer.length; i++) {
|
||||||
randBuffer[i] = numbersAndLetters[random.nextInt(numbersAndLetters.length)];
|
randBuffer[i] = numbersAndLetters[random.nextInt(numbersAndLetters.length)];
|
||||||
}
|
}
|
||||||
return new String(randBuffer);
|
return new String(randBuffer);
|
||||||
|
@ -336,7 +336,7 @@ public class StringUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static char getPrintableChar(byte indexByte) {
|
private static char getPrintableChar(byte indexByte) {
|
||||||
assert(numbersAndLetters.length < Byte.MAX_VALUE * 2);
|
assert (numbersAndLetters.length < Byte.MAX_VALUE * 2);
|
||||||
|
|
||||||
// Convert indexByte as it where an unsigned byte by promoting it to int
|
// Convert indexByte as it where an unsigned byte by promoting it to int
|
||||||
// and masking it with 0xff. Yields results from 0 - 254.
|
// and masking it with 0xff. Yields results from 0 - 254.
|
||||||
|
|
|
@ -172,7 +172,7 @@ public class XmlStringBuilder implements Appendable, CharSequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmlStringBuilder halfOpenElement(String name) {
|
public XmlStringBuilder halfOpenElement(String name) {
|
||||||
assert(StringUtils.isNotEmpty(name));
|
assert (StringUtils.isNotEmpty(name));
|
||||||
sb.append('<').append(name);
|
sb.append('<').append(name);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class HostAddress {
|
||||||
|
|
||||||
public void setException(InetAddress inetAddress, Exception exception) {
|
public void setException(InetAddress inetAddress, Exception exception) {
|
||||||
Exception old = exceptions.put(inetAddress, exception);
|
Exception old = exceptions.put(inetAddress, exception);
|
||||||
assert(old == null);
|
assert (old == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smack;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
import org.jivesoftware.smack.SmackFuture.InternalSmackFuture;
|
||||||
|
import org.jivesoftware.smack.SmackFuture.SimpleInternalSmackFuture;
|
||||||
|
import org.jivesoftware.smack.packet.Stanza;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class SmackFutureTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void simpleSmackFutureSuccessTest() throws NotConnectedException, InterruptedException, ExecutionException {
|
||||||
|
InternalSmackFuture<Boolean> future = new SimpleInternalSmackFuture<Boolean>() {
|
||||||
|
@Override
|
||||||
|
protected void handleStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
|
||||||
|
setResult(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
future.processStanza(null);
|
||||||
|
|
||||||
|
assertTrue(future.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = TimeoutException.class)
|
||||||
|
public void simpleSmackFutureTimeoutTest() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
InternalSmackFuture<Boolean> future = new SimpleInternalSmackFuture<Boolean>() {
|
||||||
|
@Override
|
||||||
|
protected void handleStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
future.get(5, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,7 +31,7 @@ public class StanzaCollectorTest
|
||||||
{
|
{
|
||||||
TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5);
|
TestStanzaCollector collector = new TestStanzaCollector(null, new OKEverything(), 5);
|
||||||
|
|
||||||
for (int i=0; i<6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
Stanza testPacket = new TestPacket(i);
|
Stanza testPacket = new TestPacket(i);
|
||||||
collector.processStanza(testPacket);
|
collector.processStanza(testPacket);
|
||||||
|
@ -45,7 +45,7 @@ public class StanzaCollectorTest
|
||||||
assertEquals("5", collector.pollResult().getStanzaId());
|
assertEquals("5", collector.pollResult().getStanzaId());
|
||||||
assertNull(collector.pollResult());
|
assertNull(collector.pollResult());
|
||||||
|
|
||||||
for (int i=10; i<15; i++)
|
for (int i = 10; i < 15; i++)
|
||||||
{
|
{
|
||||||
Stanza testPacket = new TestPacket(i);
|
Stanza testPacket = new TestPacket(i);
|
||||||
collector.processStanza(testPacket);
|
collector.processStanza(testPacket);
|
||||||
|
@ -156,7 +156,7 @@ public class StanzaCollectorTest
|
||||||
consumer2.start();
|
consumer2.start();
|
||||||
consumer3.start();
|
consumer3.start();
|
||||||
|
|
||||||
for(int i=0; i<insertCount; i++)
|
for (int i = 0; i < insertCount; i++)
|
||||||
{
|
{
|
||||||
collector.processStanza(new TestPacket(i));
|
collector.processStanza(new TestPacket(i));
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,10 @@ public class ThreadedDummyConnection extends DummyConnection {
|
||||||
replyQ.add(replyPacket);
|
replyQ.add(replyPacket);
|
||||||
}
|
}
|
||||||
replyPacket.setStanzaId(packet.getStanzaId());
|
replyPacket.setStanzaId(packet.getStanzaId());
|
||||||
replyPacket.setFrom(packet.getTo());
|
|
||||||
replyPacket.setTo(packet.getFrom());
|
replyPacket.setTo(packet.getFrom());
|
||||||
replyPacket.setType(Type.result);
|
if (replyPacket.getType() == null) {
|
||||||
|
replyPacket.setType(Type.result);
|
||||||
|
}
|
||||||
|
|
||||||
new ProcessQueue(replyQ).start();
|
new ProcessQueue(replyQ).start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class FilterToStringTest {
|
||||||
andFilter.addFilter(new ThreadFilter("42"));
|
andFilter.addFilter(new ThreadFilter("42"));
|
||||||
andFilter.addFilter(MessageWithBodiesFilter.INSTANCE);
|
andFilter.addFilter(MessageWithBodiesFilter.INSTANCE);
|
||||||
|
|
||||||
final String res =andFilter.toString();
|
final String res = andFilter.toString();
|
||||||
assertEquals("AndFilter: (StanzaIdFilter: id=foo, ThreadFilter: thread=42, MessageWithBodiesFilter)", res);
|
assertEquals("AndFilter: (StanzaIdFilter: id=foo, ThreadFilter: thread=42, MessageWithBodiesFilter)", res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class MessageTest {
|
||||||
assertXMLEqual(control, messageTypeSet.toXML().toString());
|
assertXMLEqual(control, messageTypeSet.toXML().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void setNullMessageBodyTest() {
|
public void setNullMessageBodyTest() {
|
||||||
Message message = getNewMessage();
|
Message message = getNewMessage();
|
||||||
message.addBody(null, null);
|
message.addBody(null, null);
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class PresenceTest {
|
||||||
assertXMLEqual(control, presenceTypeSet.toXML().toString());
|
assertXMLEqual(control, presenceTypeSet.toXML().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void setNullPresenceTypeTest() {
|
public void setNullPresenceTypeTest() {
|
||||||
getNewPresence().setType(null);
|
getNewPresence().setType(null);
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public class PresenceTest {
|
||||||
assertXMLEqual(control, presence.toXML().toString());
|
assertXMLEqual(control, presence.toXML().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void setIllegalPriorityTest() {
|
public void setIllegalPriorityTest() {
|
||||||
getNewPresence().setPriority(Integer.MIN_VALUE);
|
getNewPresence().setPriority(Integer.MIN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class ProviderConfigTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addClasspathFileLoaderProvider() throws Exception{
|
public void addClasspathFileLoaderProvider() throws Exception {
|
||||||
ProviderManager.addLoader(new ProviderFileLoader(FileUtils.getStreamForUrl("classpath:test.providers", null)));
|
ProviderManager.addLoader(new ProviderFileLoader(FileUtils.getStreamForUrl("classpath:test.providers", null)));
|
||||||
Assert.assertNotNull(ProviderManager.getIQProvider("provider", "test:file_provider"));
|
Assert.assertNotNull(ProviderManager.getIQProvider("provider", "test:file_provider"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class ProviderManagerTest {
|
||||||
* This test should be run in a clean (e.g. forked) VM
|
* This test should be run in a clean (e.g. forked) VM
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldInitializeSmackTest() throws Exception{
|
public void shouldInitializeSmackTest() throws Exception {
|
||||||
ProviderManager.addIQProvider("foo", "bar", new TestIQProvider());
|
ProviderManager.addIQProvider("foo", "bar", new TestIQProvider());
|
||||||
assertTrue(SmackConfiguration.isSmackInitialized());
|
assertTrue(SmackConfiguration.isSmackInitialized());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright © 2014 Florian Schmaus
|
* Copyright © 2014-2017 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,7 +32,7 @@ import org.jxmpp.jid.EntityBareJid;
|
||||||
|
|
||||||
public class DigestMd5SaslTest extends AbstractSaslTest {
|
public class DigestMd5SaslTest extends AbstractSaslTest {
|
||||||
|
|
||||||
protected static final String challenge = "realm=\"xmpp.org\",nonce=\"aTUr3GXqUtyy2B7HVDW6C+gQs+j+0EhWWjoBKkkg\",qop=\"auth\",charset=utf-8,algorithm=md5-sess";
|
protected static final String challenge = "realm=\"xmpp.org\",nonce=\"jgGgnz+cQcmyVaAs2n88kQ==\",qop=\"auth\",charset=utf-8,algorithm=md5-sess";
|
||||||
protected static final byte[] challengeBytes = StringUtils.toBytes(challenge);
|
protected static final byte[] challengeBytes = StringUtils.toBytes(challenge);
|
||||||
|
|
||||||
public DigestMd5SaslTest(SASLMechanism saslMechanism) {
|
public DigestMd5SaslTest(SASLMechanism saslMechanism) {
|
||||||
|
@ -50,8 +50,7 @@ public class DigestMd5SaslTest extends AbstractSaslTest {
|
||||||
String[] responseParts = responseString.split(",");
|
String[] responseParts = responseString.split(",");
|
||||||
Map<String, String> responsePairs = new HashMap<String, String>();
|
Map<String, String> responsePairs = new HashMap<String, String>();
|
||||||
for (String part : responseParts) {
|
for (String part : responseParts) {
|
||||||
String[] keyValue = part.split("=");
|
String[] keyValue = part.split("=", 2);
|
||||||
assertTrue(keyValue.length == 2);
|
|
||||||
String key = keyValue[0];
|
String key = keyValue[0];
|
||||||
String value = keyValue[1].replace("\"", "");
|
String value = keyValue[1].replace("\"", "");
|
||||||
responsePairs.put(key, value);
|
responsePairs.put(key, value);
|
||||||
|
@ -59,7 +58,7 @@ public class DigestMd5SaslTest extends AbstractSaslTest {
|
||||||
if (useAuthzid) {
|
if (useAuthzid) {
|
||||||
assertMapValue("authzid", "shazbat@xmpp.org", responsePairs);
|
assertMapValue("authzid", "shazbat@xmpp.org", responsePairs);
|
||||||
} else {
|
} else {
|
||||||
assert(!responsePairs.containsKey("authzid"));
|
assertTrue (!responsePairs.containsKey("authzid"));
|
||||||
}
|
}
|
||||||
assertMapValue("username", "florian", responsePairs);
|
assertMapValue("username", "florian", responsePairs);
|
||||||
assertMapValue("realm", "xmpp.org", responsePairs);
|
assertMapValue("realm", "xmpp.org", responsePairs);
|
||||||
|
|
|
@ -664,7 +664,7 @@ public class PacketParserUtilsTest {
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test(expected=XmlPullParserException.class)
|
@Test(expected = XmlPullParserException.class)
|
||||||
public void invalidMessageBodyContainingTagTest() throws Exception {
|
public void invalidMessageBodyContainingTagTest() throws Exception {
|
||||||
String control = XMLBuilder.create("message")
|
String control = XMLBuilder.create("message")
|
||||||
.a("from", "romeo@montague.lit/orchard")
|
.a("from", "romeo@montague.lit/orchard")
|
||||||
|
@ -701,7 +701,7 @@ public class PacketParserUtilsTest {
|
||||||
try {
|
try {
|
||||||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
fail("Exception should be thrown");
|
||||||
} catch(XmlPullParserException e) {
|
} catch (XmlPullParserException e) {
|
||||||
assertTrue(e.getMessage().contains("end tag name </span>"));
|
assertTrue(e.getMessage().contains("end tag name </span>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +710,7 @@ public class PacketParserUtilsTest {
|
||||||
try {
|
try {
|
||||||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
fail("Exception should be thrown");
|
||||||
} catch(XmlPullParserException e) {
|
} catch (XmlPullParserException e) {
|
||||||
assertTrue(e.getMessage().contains("end tag name </body>"));
|
assertTrue(e.getMessage().contains("end tag name </body>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -719,7 +719,7 @@ public class PacketParserUtilsTest {
|
||||||
try {
|
try {
|
||||||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
fail("Exception should be thrown");
|
||||||
} catch(XmlPullParserException e) {
|
} catch (XmlPullParserException e) {
|
||||||
assertTrue(e.getMessage().contains("end tag name </message>"));
|
assertTrue(e.getMessage().contains("end tag name </message>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class SHA1Test {
|
||||||
*/
|
*/
|
||||||
private boolean isValidHash(String result) {
|
private boolean isValidHash(String result) {
|
||||||
boolean valid = true;
|
boolean valid = true;
|
||||||
for (int i=0; i<result.length(); i++) {
|
for (int i = 0; i < result.length(); i++) {
|
||||||
char c = result.charAt(i);
|
char c = result.charAt(i);
|
||||||
if (HASH_CHARS.indexOf(c) < 0) {
|
if (HASH_CHARS.indexOf(c) < 0) {
|
||||||
valid = false;
|
valid = false;
|
||||||
|
|
|
@ -263,7 +263,7 @@ public class EnhancedDebugger implements SmackDebugger {
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void reconnectingIn(final int seconds){
|
public void reconnectingIn(final int seconds) {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -301,7 +301,7 @@ public class EnhancedDebugger implements SmackDebugger {
|
||||||
|
|
||||||
messagesTable =
|
messagesTable =
|
||||||
new DefaultTableModel(
|
new DefaultTableModel(
|
||||||
new Object[]{"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"},
|
new Object[] {"Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From"},
|
||||||
0) {
|
0) {
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
private static final long serialVersionUID = 8136121224474217264L;
|
private static final long serialVersionUID = 8136121224474217264L;
|
||||||
|
@ -735,9 +735,9 @@ public class EnhancedDebugger implements SmackDebugger {
|
||||||
packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets"));
|
packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets"));
|
||||||
|
|
||||||
statisticsTable =
|
statisticsTable =
|
||||||
new DefaultTableModel(new Object[][]{{"IQ", 0, 0}, {"Message", 0, 0},
|
new DefaultTableModel(new Object[][] { {"IQ", 0, 0}, {"Message", 0, 0},
|
||||||
{"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}},
|
{"Presence", 0, 0}, {"Other", 0, 0}, {"Total", 0, 0}},
|
||||||
new Object[]{"Type", "Received", "Sent"}) {
|
new Object[] {"Type", "Received", "Sent"}) {
|
||||||
// CHECKSTYLE:OFF
|
// CHECKSTYLE:OFF
|
||||||
private static final long serialVersionUID = -6793886085109589269L;
|
private static final long serialVersionUID = -6793886085109589269L;
|
||||||
@Override
|
@Override
|
||||||
|
@ -878,7 +878,7 @@ public class EnhancedDebugger implements SmackDebugger {
|
||||||
}
|
}
|
||||||
|
|
||||||
messagesTable.addRow(
|
messagesTable.addRow(
|
||||||
new Object[]{
|
new Object[] {
|
||||||
formatXML(packet.toXML().toString()),
|
formatXML(packet.toXML().toString()),
|
||||||
dateFormatter.format(new Date()),
|
dateFormatter.format(new Date()),
|
||||||
packetReceivedIcon,
|
packetReceivedIcon,
|
||||||
|
@ -940,7 +940,7 @@ public class EnhancedDebugger implements SmackDebugger {
|
||||||
}
|
}
|
||||||
|
|
||||||
messagesTable.addRow(
|
messagesTable.addRow(
|
||||||
new Object[]{
|
new Object[] {
|
||||||
formatXML(packet.toXML().toString()),
|
formatXML(packet.toXML().toString()),
|
||||||
dateFormatter.format(new Date()),
|
dateFormatter.format(new Date()),
|
||||||
packetSentIcon,
|
packetSentIcon,
|
||||||
|
|
|
@ -289,8 +289,8 @@ public class LiteDebugger implements SmackDebugger {
|
||||||
*/
|
*/
|
||||||
public void rootWindowClosing(WindowEvent evt) {
|
public void rootWindowClosing(WindowEvent evt) {
|
||||||
connection.removeAsyncStanzaListener(listener);
|
connection.removeAsyncStanzaListener(listener);
|
||||||
((ObservableReader)reader).removeReaderListener(readerListener);
|
((ObservableReader) reader).removeReaderListener(readerListener);
|
||||||
((ObservableWriter)writer).removeWriterListener(writerListener);
|
((ObservableWriter) writer).removeWriterListener(writerListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -322,7 +322,7 @@ public class LiteDebugger implements SmackDebugger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Reader newConnectionReader(Reader newReader) {
|
public Reader newConnectionReader(Reader newReader) {
|
||||||
((ObservableReader)reader).removeReaderListener(readerListener);
|
((ObservableReader) reader).removeReaderListener(readerListener);
|
||||||
ObservableReader debugReader = new ObservableReader(newReader);
|
ObservableReader debugReader = new ObservableReader(newReader);
|
||||||
debugReader.addReaderListener(readerListener);
|
debugReader.addReaderListener(readerListener);
|
||||||
reader = debugReader;
|
reader = debugReader;
|
||||||
|
@ -331,7 +331,7 @@ public class LiteDebugger implements SmackDebugger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Writer newConnectionWriter(Writer newWriter) {
|
public Writer newConnectionWriter(Writer newWriter) {
|
||||||
((ObservableWriter)writer).removeWriterListener(writerListener);
|
((ObservableWriter) writer).removeWriterListener(writerListener);
|
||||||
ObservableWriter debugWriter = new ObservableWriter(newWriter);
|
ObservableWriter debugWriter = new ObservableWriter(newWriter);
|
||||||
debugWriter.addWriterListener(writerListener);
|
debugWriter.addWriterListener(writerListener);
|
||||||
writer = debugWriter;
|
writer = debugWriter;
|
||||||
|
|
|
@ -123,7 +123,7 @@ public final class CarbonManager extends Manager {
|
||||||
// also reset here.
|
// also reset here.
|
||||||
enabled_state = false;
|
enabled_state = false;
|
||||||
boolean removed = connection().removeSyncStanzaListener(carbonsListener);
|
boolean removed = connection().removeSyncStanzaListener(carbonsListener);
|
||||||
assert(removed);
|
assert (removed);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.eme;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||||
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement;
|
||||||
|
|
||||||
|
public final class ExplicitMessageEncryptionManager {
|
||||||
|
|
||||||
|
private static final Map<XMPPConnection, ExplicitMessageEncryptionManager> INSTANCES = new WeakHashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||||
|
@Override
|
||||||
|
public void connectionCreated(XMPPConnection connection) {
|
||||||
|
getInstanceFor(connection);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String NAMESPACE_V0 = ExplicitMessageEncryptionElement.NAMESPACE;
|
||||||
|
|
||||||
|
public static synchronized ExplicitMessageEncryptionManager getInstanceFor(XMPPConnection connection) {
|
||||||
|
ExplicitMessageEncryptionManager manager = INSTANCES.get(connection);
|
||||||
|
if (manager == null) {
|
||||||
|
manager = new ExplicitMessageEncryptionManager(connection);
|
||||||
|
INSTANCES.put(connection, manager);
|
||||||
|
}
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExplicitMessageEncryptionManager(XMPPConnection connection) {
|
||||||
|
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||||
|
sdm.addFeature(NAMESPACE_V0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,146 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.eme.element;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
|
|
||||||
|
public class ExplicitMessageEncryptionElement implements ExtensionElement {
|
||||||
|
|
||||||
|
private static final Map<String, ExplicitMessageEncryptionProtocol> PROTOCOL_LUT = new HashMap<>();
|
||||||
|
|
||||||
|
public static final String ELEMENT = "encryption";
|
||||||
|
|
||||||
|
public static final String NAMESPACE = "urn:xmpp:eme:0";
|
||||||
|
|
||||||
|
public enum ExplicitMessageEncryptionProtocol {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The encryption method specified in <a href="https://xmpp.org/extensions/xep-0373.html">XEP-0373: OpenPGP for
|
||||||
|
* XMPP</a>.
|
||||||
|
*/
|
||||||
|
openpgpV0("urn:xmpp:openpgp:0", "OpenPGP for XMPP (XEP-0373)"),
|
||||||
|
|
||||||
|
otrV0("urn:xmpp:otr:0", "Off-the-Record Messaging (XEP-0364)"),
|
||||||
|
|
||||||
|
legacyOpenPGP("jabber:x:encrypted", "Legacy OpenPGP for XMPP [DANGEROUS, DO NOT USE!]"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String namespace;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private ExplicitMessageEncryptionProtocol(String namespace, String name) {
|
||||||
|
this.namespace = namespace;
|
||||||
|
this.name = name;
|
||||||
|
PROTOCOL_LUT.put(namespace, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNamespace() {
|
||||||
|
return namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExplicitMessageEncryptionProtocol from(String namespace) {
|
||||||
|
return PROTOCOL_LUT.get(namespace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String encryptionNamespace;
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private boolean isUnknownProtocol;
|
||||||
|
|
||||||
|
private ExplicitMessageEncryptionProtocol protocolCache;
|
||||||
|
|
||||||
|
public ExplicitMessageEncryptionElement(ExplicitMessageEncryptionProtocol protocol) {
|
||||||
|
this(protocol.getNamespace(), protocol.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExplicitMessageEncryptionElement(String encryptionNamespace) {
|
||||||
|
this(encryptionNamespace, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExplicitMessageEncryptionElement(String encryptionNamespace, String name) {
|
||||||
|
this.encryptionNamespace = StringUtils.requireNotNullOrEmpty(encryptionNamespace,
|
||||||
|
"encryptionNamespace must not be null");
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExplicitMessageEncryptionProtocol getProtocol() {
|
||||||
|
if (protocolCache != null) {
|
||||||
|
return protocolCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isUnknownProtocol) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExplicitMessageEncryptionProtocol protocol = PROTOCOL_LUT.get(encryptionNamespace);
|
||||||
|
if (protocol == null) {
|
||||||
|
isUnknownProtocol = true;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protocolCache = protocol;
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEncryptionNamespace() {
|
||||||
|
return encryptionNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the optional name of the encryption method.
|
||||||
|
*
|
||||||
|
* @return the name of the encryption method or <code>null</code>.
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespace() {
|
||||||
|
return NAMESPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlStringBuilder toXML() {
|
||||||
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||||
|
xml.attribute("namespace", getEncryptionNamespace());
|
||||||
|
xml.optAttribute("name", getName());
|
||||||
|
xml.closeEmptyElement();
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ExplicitMessageEncryptionElement from(Message message) {
|
||||||
|
return message.getExtension(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* XMPP extension elements for XEP-0380: Explicit Message Encryption.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.eme.element;
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2015 Florian Schmaus
|
* Copyright 2017 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -14,8 +14,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO describe me
|
* Smack's API for XEP-0380: Explicit Message Encryption.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.iqprivate;
|
package org.jivesoftware.smackx.eme;
|
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.eme.provider;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||||
|
import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement;
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
|
public class ExplicitMessageEncryptionProvider extends ExtensionElementProvider<ExplicitMessageEncryptionElement> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExplicitMessageEncryptionElement parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||||
|
String namespace = parser.getAttributeValue(null, "namespace");
|
||||||
|
String name = parser.getAttributeValue(null, "name");
|
||||||
|
return new ExplicitMessageEncryptionElement(namespace, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Smack Provider for XEP-0380: Explicit Message Encryption.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.eme.provider;
|
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
import org.jivesoftware.smackx.hints.element.MessageProcessingHintType;
|
||||||
|
import org.jivesoftware.smackx.hints.element.NoCopyHint;
|
||||||
|
import org.jivesoftware.smackx.hints.element.NoPermanentStoreHint;
|
||||||
|
import org.jivesoftware.smackx.hints.element.NoStoreHint;
|
||||||
|
import org.jivesoftware.smackx.hints.element.StoreHint;
|
||||||
|
|
||||||
|
public class MessageProcessingHintsManager {
|
||||||
|
|
||||||
|
public static Set<MessageProcessingHintType> getHintsFrom(Message message) {
|
||||||
|
Set<MessageProcessingHintType> hints = null;
|
||||||
|
|
||||||
|
boolean noCopyHint = NoCopyHint.hasHint(message);
|
||||||
|
if (noCopyHint) {
|
||||||
|
hints = new HashSet<>(MessageProcessingHintType.values().length);
|
||||||
|
hints.add(MessageProcessingHintType.no_copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean noPermanentStoreHint = NoPermanentStoreHint.hasHint(message);
|
||||||
|
if (noPermanentStoreHint) {
|
||||||
|
if (hints == null) {
|
||||||
|
hints = new HashSet<>(MessageProcessingHintType.values().length);
|
||||||
|
}
|
||||||
|
hints.add(MessageProcessingHintType.no_permanent_store);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean noStoreHint = NoStoreHint.hasHint(message);
|
||||||
|
if (noStoreHint) {
|
||||||
|
if (hints == null) {
|
||||||
|
hints = new HashSet<>(MessageProcessingHintType.values().length);
|
||||||
|
}
|
||||||
|
hints.add(MessageProcessingHintType.no_store);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean storeHint = StoreHint.hasHint(message);
|
||||||
|
if (storeHint) {
|
||||||
|
if (hints == null) {
|
||||||
|
hints = new HashSet<>(MessageProcessingHintType.values().length);
|
||||||
|
}
|
||||||
|
hints.add(MessageProcessingHintType.store);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hints == null) {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
return hints;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.element;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
|
|
||||||
|
public abstract class MessageProcessingHint implements ExtensionElement {
|
||||||
|
|
||||||
|
public static final String NAMESPACE = "urn:xmpp:hints";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getNamespace() {
|
||||||
|
return NAMESPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract MessageProcessingHintType getHintType();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.element;
|
||||||
|
|
||||||
|
public enum MessageProcessingHintType {
|
||||||
|
|
||||||
|
no_permanent_store,
|
||||||
|
no_store,
|
||||||
|
no_copy,
|
||||||
|
store,
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.element;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A "no copy" hint. Messages with this hint should not be copied to addresses other than the one to which it is addressed.
|
||||||
|
*
|
||||||
|
* @see <a href="https://xmpp.org/extensions/xep-0334.html#no-copy">XEP-0344 § 4.3 No copies</a>
|
||||||
|
*/
|
||||||
|
public final class NoCopyHint extends MessageProcessingHint {
|
||||||
|
|
||||||
|
public static final NoCopyHint INSTANCE = new NoCopyHint();
|
||||||
|
|
||||||
|
public static final String ELEMENT = "no-copy";
|
||||||
|
|
||||||
|
private NoCopyHint() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toXML() {
|
||||||
|
return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageProcessingHintType getHintType() {
|
||||||
|
return MessageProcessingHintType.no_copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NoCopyHint from(Message message) {
|
||||||
|
return message.getExtension(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasHint(Message message) {
|
||||||
|
return from(message) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(Message message) {
|
||||||
|
message.addExtension(INSTANCE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.element;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A "no permanent store" hint. Messages with this hint should not be stored in permanent stores or archives.
|
||||||
|
*
|
||||||
|
* @see <a href="https://xmpp.org/extensions/xep-0334.html#no-permanent-store">XEP-0334 § 4.1 No permanent store</a>
|
||||||
|
*/
|
||||||
|
public final class NoPermanentStoreHint extends MessageProcessingHint {
|
||||||
|
|
||||||
|
public static final NoPermanentStoreHint INSTANCE = new NoPermanentStoreHint();
|
||||||
|
|
||||||
|
public static final String ELEMENT = "no-permanent-store";
|
||||||
|
|
||||||
|
private NoPermanentStoreHint() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toXML() {
|
||||||
|
return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageProcessingHintType getHintType() {
|
||||||
|
return MessageProcessingHintType.no_permanent_store;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NoPermanentStoreHint from(Message message) {
|
||||||
|
return message.getExtension(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasHint(Message message) {
|
||||||
|
return from(message) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(Message message) {
|
||||||
|
if (StoreHint.hasHint(message)) {
|
||||||
|
// No need to set the no-permanent-store hint when a no-store hint is already set.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setExplicitly(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setExplicitly(Message message) {
|
||||||
|
message.addExtension(INSTANCE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.element;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A "no store" hint. Messages with this hint should not be stored in stores or archives.
|
||||||
|
*
|
||||||
|
* <a href="https://xmpp.org/extensions/xep-0334.html#no-store">XEP-0334 § 4.2 No store</a>
|
||||||
|
*/
|
||||||
|
public final class NoStoreHint extends MessageProcessingHint {
|
||||||
|
|
||||||
|
public static final NoStoreHint INSTANCE = new NoStoreHint();
|
||||||
|
|
||||||
|
public static final String ELEMENT = "no-store";
|
||||||
|
|
||||||
|
private NoStoreHint() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toXML() {
|
||||||
|
return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageProcessingHintType getHintType() {
|
||||||
|
return MessageProcessingHintType.no_store;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NoStoreHint from(Message message) {
|
||||||
|
return message.getExtension(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasHint(Message message) {
|
||||||
|
return from(message) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(Message message) {
|
||||||
|
message.addExtension(INSTANCE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.element;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A "store" hint. Messages with this hint should be stored in permanent stores or archives.
|
||||||
|
*
|
||||||
|
* @see <a href="https://xmpp.org/extensions/xep-0334.html#sect-idm140684698220992">XEP-0334 § 4.4 Store</a>
|
||||||
|
*/
|
||||||
|
public final class StoreHint extends MessageProcessingHint {
|
||||||
|
|
||||||
|
public static final StoreHint INSTANCE = new StoreHint();
|
||||||
|
|
||||||
|
public static final String ELEMENT = "store";
|
||||||
|
|
||||||
|
private StoreHint() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toXML() {
|
||||||
|
return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MessageProcessingHintType getHintType() {
|
||||||
|
return MessageProcessingHintType.store;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StoreHint from(Message message) {
|
||||||
|
return message.getExtension(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasHint(Message message) {
|
||||||
|
return from(message) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(Message message) {
|
||||||
|
message.addExtension(INSTANCE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* XMPP extension elements for XEP-0334: Message Processing Hints.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.element;
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Smack's API for XEP-0334: Message Processing Hints.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints;
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.provider;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||||
|
import org.jivesoftware.smackx.hints.element.MessageProcessingHint;
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
|
public abstract class MessageProcessingHintProvider<H extends MessageProcessingHint> extends ExtensionElementProvider<H> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public H parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||||
|
return getHint();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract H getHint();
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.provider;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.hints.element.NoCopyHint;
|
||||||
|
|
||||||
|
public class NoCopyHintProvider extends MessageProcessingHintProvider<NoCopyHint> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected NoCopyHint getHint() {
|
||||||
|
return NoCopyHint.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.provider;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.hints.element.NoPermanentStoreHint;
|
||||||
|
|
||||||
|
public class NoPermanentStoreHintProvider extends MessageProcessingHintProvider<NoPermanentStoreHint> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected NoPermanentStoreHint getHint() {
|
||||||
|
return NoPermanentStoreHint.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.provider;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.hints.element.NoStoreHint;
|
||||||
|
|
||||||
|
public class NoStoreHintProvider extends MessageProcessingHintProvider<NoStoreHint> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected NoStoreHint getHint() {
|
||||||
|
return NoStoreHint.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.provider;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.hints.element.StoreHint;
|
||||||
|
|
||||||
|
public class StoreHintProvider extends MessageProcessingHintProvider<StoreHint> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected StoreHint getHint() {
|
||||||
|
return StoreHint.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Smack Provider for XEP-0334: Message Processing Hints.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.hints.provider;
|
|
@ -121,7 +121,7 @@ public final class HttpFileUploadManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UploadService uploadServiceFrom(DiscoverInfo discoverInfo) {
|
private static UploadService uploadServiceFrom(DiscoverInfo discoverInfo) {
|
||||||
assert(containsHttpFileUploadNamespace(discoverInfo));
|
assert (containsHttpFileUploadNamespace(discoverInfo));
|
||||||
|
|
||||||
UploadService.Version version;
|
UploadService.Version version;
|
||||||
if (discoverInfo.containsFeature(NAMESPACE)) {
|
if (discoverInfo.containsFeature(NAMESPACE)) {
|
||||||
|
|
|
@ -34,13 +34,13 @@ public class FileTooLargeErrorProvider extends ExtensionElementProvider<FileTooL
|
||||||
final String namespace = parser.getNamespace();
|
final String namespace = parser.getNamespace();
|
||||||
Long maxFileSize = null;
|
Long maxFileSize = null;
|
||||||
|
|
||||||
outerloop: while(true) {
|
outerloop: while (true) {
|
||||||
int event = parser.next();
|
int event = parser.next();
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case XmlPullParser.START_TAG:
|
case XmlPullParser.START_TAG:
|
||||||
String name = parser.getName();
|
String name = parser.getName();
|
||||||
switch(name) {
|
switch (name) {
|
||||||
case "max-file-size":
|
case "max-file-size":
|
||||||
maxFileSize = Long.valueOf(parser.nextText());
|
maxFileSize = Long.valueOf(parser.nextText());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class SlotProvider extends IQProvider<Slot> {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case XmlPullParser.START_TAG:
|
case XmlPullParser.START_TAG:
|
||||||
String name = parser.getName();
|
String name = parser.getName();
|
||||||
switch(name) {
|
switch (name) {
|
||||||
case "put":
|
case "put":
|
||||||
putUrl = new URL(parser.nextText());
|
putUrl = new URL(parser.nextText());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright © 2016 Florian Schmaus
|
* Copyright © 2016-2017 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -21,7 +21,7 @@ import org.jxmpp.jid.BareJid;
|
||||||
|
|
||||||
public class IoTIsFriendResponse extends IQ {
|
public class IoTIsFriendResponse extends IQ {
|
||||||
|
|
||||||
public static final String ELEMENT = "isFriend";
|
public static final String ELEMENT = "isFriendResponse";
|
||||||
public static final String NAMESPACE = Constants.IOT_PROVISIONING_NAMESPACE;
|
public static final String NAMESPACE = Constants.IOT_PROVISIONING_NAMESPACE;
|
||||||
|
|
||||||
private final BareJid jid;
|
private final BareJid jid;
|
||||||
|
@ -46,6 +46,7 @@ public class IoTIsFriendResponse extends IQ {
|
||||||
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
xml.attribute("jid", jid);
|
xml.attribute("jid", jid);
|
||||||
xml.attribute("result", result);
|
xml.attribute("result", result);
|
||||||
|
xml.setEmptyElement();
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class EnablePushNotificationsIQ extends IQ {
|
||||||
xml.rightAngleBracket();
|
xml.rightAngleBracket();
|
||||||
|
|
||||||
if (publishOptions != null) {
|
if (publishOptions != null) {
|
||||||
DataForm dataForm = new DataForm(DataForm.Type.form);
|
DataForm dataForm = new DataForm(DataForm.Type.submit);
|
||||||
|
|
||||||
FormField formTypeField = new FormField("FORM_TYPE");
|
FormField formTypeField = new FormField("FORM_TYPE");
|
||||||
formTypeField.addValue(PubSub.NAMESPACE + "#publish-options");
|
formTypeField.addValue(PubSub.NAMESPACE + "#publish-options");
|
||||||
|
|
|
@ -233,6 +233,28 @@
|
||||||
<className>org.jivesoftware.smackx.chat_markers.provider.AcknowledgedProvider</className>
|
<className>org.jivesoftware.smackx.chat_markers.provider.AcknowledgedProvider</className>
|
||||||
</extensionProvider>
|
</extensionProvider>
|
||||||
|
|
||||||
|
<!-- XEP-0334: Message Processing Hints -->
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>no-copy</elementName>
|
||||||
|
<namespace>urn:xmpp:hints</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.hints.provider.NoCopyHintProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>no-permanent-store</elementName>
|
||||||
|
<namespace>urn:xmpp:hints</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.hints.provider.NoPermanentStoreHintProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>no-store</elementName>
|
||||||
|
<namespace>urn:xmpp:hints</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.hints.provider.NoStoreHintProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>store</elementName>
|
||||||
|
<namespace>urn:xmpp:hints</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.hints.provider.StoreHintProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
g
|
||||||
<!-- XEP-0363: HTTP File Upload -->
|
<!-- XEP-0363: HTTP File Upload -->
|
||||||
<iqProvider>
|
<iqProvider>
|
||||||
<elementName>slot</elementName>
|
<elementName>slot</elementName>
|
||||||
|
@ -255,4 +277,11 @@
|
||||||
<className>org.jivesoftware.smackx.httpfileupload.provider.FileTooLargeErrorProvider</className>
|
<className>org.jivesoftware.smackx.httpfileupload.provider.FileTooLargeErrorProvider</className>
|
||||||
</extensionProvider>
|
</extensionProvider>
|
||||||
|
|
||||||
|
<!-- XEP-0380: Explicit Message Encryption -->
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>encryption</elementName>
|
||||||
|
<namespace>urn:xmpp:eme:0</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.eme.provider.ExplicitMessageEncryptionProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
</smackProviders>
|
</smackProviders>
|
||||||
|
|
|
@ -5,5 +5,6 @@
|
||||||
<className>org.jivesoftware.smackx.iot.discovery.IoTDiscoveryManager</className>
|
<className>org.jivesoftware.smackx.iot.discovery.IoTDiscoveryManager</className>
|
||||||
<className>org.jivesoftware.smackx.iot.provisioning.IoTProvisioningManager</className>
|
<className>org.jivesoftware.smackx.iot.provisioning.IoTProvisioningManager</className>
|
||||||
<className>org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager</className>
|
<className>org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager</className>
|
||||||
|
<className>org.jivesoftware.smackx.eme.ExplicitMessageEncryptionManager</className>
|
||||||
</startupClasses>
|
</startupClasses>
|
||||||
</smack>
|
</smack>
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class CarbonTest extends ExperimentalInitializerTest {
|
||||||
assertEquals("received", parser.getName());
|
assertEquals("received", parser.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=Exception.class)
|
@Test(expected = Exception.class)
|
||||||
public void carbonEmptyTest() throws Exception {
|
public void carbonEmptyTest() throws Exception {
|
||||||
XmlPullParser parser;
|
XmlPullParser parser;
|
||||||
String control;
|
String control;
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2017 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.eme.provider;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.test.util.TestUtils;
|
||||||
|
import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement;
|
||||||
|
import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ExplicitMessageEncryptionProviderTest {
|
||||||
|
|
||||||
|
private static final String OX_EME_ELEMENT = "<encryption xmlns='urn:xmpp:eme:0' namespace='urn:xmpp:openpgp:0'/>";
|
||||||
|
|
||||||
|
private static final String UNKNOWN_NAMESPACE = "urn:xmpp:foobar:0";
|
||||||
|
private static final String UNKNOWN_NAME = "Foo Bar";
|
||||||
|
private static final String UNKNOWN_EME_ELEMENT = "<encryption xmlns='urn:xmpp:eme:0' namespace='" + UNKNOWN_NAMESPACE
|
||||||
|
+ "' name='" + UNKNOWN_NAME + "'/>";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseOxEmeElement() throws Exception {
|
||||||
|
ExplicitMessageEncryptionElement eme = TestUtils.parseExtensionElement(OX_EME_ELEMENT);
|
||||||
|
assertEquals(ExplicitMessageEncryptionProtocol.openpgpV0, eme.getProtocol());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParseUnknownEmeElement() throws Exception {
|
||||||
|
ExplicitMessageEncryptionElement eme = TestUtils.parseExtensionElement(UNKNOWN_EME_ELEMENT);
|
||||||
|
assertEquals(UNKNOWN_NAMESPACE, eme.getEncryptionNamespace());
|
||||||
|
assertEquals(UNKNOWN_NAME, eme.getName());
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ public class MUCLightDestroyTest {
|
||||||
+ "<query xmlns='urn:xmpp:muclight:0#destroy'/>" + "</iq>";
|
+ "<query xmlns='urn:xmpp:muclight:0#destroy'/>" + "</iq>";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkDestroyMUCLightStanza() throws Exception{
|
public void checkDestroyMUCLightStanza() throws Exception {
|
||||||
MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(JidCreate.from("coven@muclight.shakespeare.lit"));
|
MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(JidCreate.from("coven@muclight.shakespeare.lit"));
|
||||||
mucLightDestroyIQ.setStanzaId("destroy1");
|
mucLightDestroyIQ.setStanzaId("destroy1");
|
||||||
Assert.assertEquals(mucLightDestroyIQ.toXML().toString(), stanza);
|
Assert.assertEquals(mucLightDestroyIQ.toXML().toString(), stanza);
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class EnablePushNotificationsIQTest {
|
||||||
|
|
||||||
String exampleEnableIQWithPublishOptions = "<iq id='x42' type='set'>"
|
String exampleEnableIQWithPublishOptions = "<iq id='x42' type='set'>"
|
||||||
+ "<enable xmlns='urn:xmpp:push:0' jid='push-5.client.example' node='yxs32uqsflafdk3iuqo'>"
|
+ "<enable xmlns='urn:xmpp:push:0' jid='push-5.client.example' node='yxs32uqsflafdk3iuqo'>"
|
||||||
+ "<x xmlns='jabber:x:data' type='form'>"
|
+ "<x xmlns='jabber:x:data' type='submit'>"
|
||||||
+ "<field var='FORM_TYPE'><value>http://jabber.org/protocol/pubsub#publish-options</value></field>"
|
+ "<field var='FORM_TYPE'><value>http://jabber.org/protocol/pubsub#publish-options</value></field>"
|
||||||
+ "<field var='secret'><value>eruio234vzxc2kla-91</value></field>" + "</x>" + "</enable>" + "</iq>";
|
+ "<field var='secret'><value>eruio234vzxc2kla-91</value></field>" + "</x>" + "</enable>" + "</iq>";
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class ServiceAdministrationManager extends Manager {
|
||||||
passwordVerifyField.addValue(password);
|
passwordVerifyField.addValue(password);
|
||||||
|
|
||||||
command.next(answerForm);
|
command.next(answerForm);
|
||||||
assert(command.isCompleted());
|
assert (command.isCompleted());
|
||||||
}
|
}
|
||||||
|
|
||||||
public RemoteCommand deleteUser() {
|
public RemoteCommand deleteUser() {
|
||||||
|
@ -112,6 +112,6 @@ public class ServiceAdministrationManager extends Manager {
|
||||||
accountJids.addValues(JidUtil.toStringList(jidsToDelete));
|
accountJids.addValues(JidUtil.toStringList(jidsToDelete));
|
||||||
|
|
||||||
command.next(answerForm);
|
command.next(answerForm);
|
||||||
assert(command.isCompleted());
|
assert (command.isCompleted());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,7 @@ public class AMPExtension implements ExtensionElement {
|
||||||
String getName();
|
String getName();
|
||||||
String getValue();
|
String getValue();
|
||||||
|
|
||||||
static final String ATTRIBUTE_NAME="condition";
|
static final String ATTRIBUTE_NAME = "condition";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -265,7 +265,7 @@ public class AMPExtension implements ExtensionElement {
|
||||||
*/
|
*/
|
||||||
notify;
|
notify;
|
||||||
|
|
||||||
public static final String ATTRIBUTE_NAME="action";
|
public static final String ATTRIBUTE_NAME = "action";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class BoBData {
|
||||||
|
|
||||||
private void setContentBinaryIfRequired() {
|
private void setContentBinaryIfRequired() {
|
||||||
if (contentBinary == null) {
|
if (contentBinary == null) {
|
||||||
assert(StringUtils.isNotEmpty(contentString));
|
assert (StringUtils.isNotEmpty(contentString));
|
||||||
contentBinary = Base64.decode(contentString);
|
contentBinary = Base64.decode(contentString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,9 +118,9 @@ public final class BookmarkManager {
|
||||||
BookmarkedConference bookmark
|
BookmarkedConference bookmark
|
||||||
= new BookmarkedConference(name, jid, isAutoJoin, nickname, password);
|
= new BookmarkedConference(name, jid, isAutoJoin, nickname, password);
|
||||||
List<BookmarkedConference> conferences = bookmarks.getBookmarkedConferences();
|
List<BookmarkedConference> conferences = bookmarks.getBookmarkedConferences();
|
||||||
if(conferences.contains(bookmark)) {
|
if (conferences.contains(bookmark)) {
|
||||||
BookmarkedConference oldConference = conferences.get(conferences.indexOf(bookmark));
|
BookmarkedConference oldConference = conferences.get(conferences.indexOf(bookmark));
|
||||||
if(oldConference.isShared()) {
|
if (oldConference.isShared()) {
|
||||||
throw new IllegalArgumentException("Cannot modify shared bookmark");
|
throw new IllegalArgumentException("Cannot modify shared bookmark");
|
||||||
}
|
}
|
||||||
oldConference.setAutoJoin(isAutoJoin);
|
oldConference.setAutoJoin(isAutoJoin);
|
||||||
|
@ -149,10 +149,10 @@ public final class BookmarkManager {
|
||||||
public void removeBookmarkedConference(EntityBareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
public void removeBookmarkedConference(EntityBareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
retrieveBookmarks();
|
retrieveBookmarks();
|
||||||
Iterator<BookmarkedConference> it = bookmarks.getBookmarkedConferences().iterator();
|
Iterator<BookmarkedConference> it = bookmarks.getBookmarkedConferences().iterator();
|
||||||
while(it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
BookmarkedConference conference = it.next();
|
BookmarkedConference conference = it.next();
|
||||||
if(conference.getJid().equals(jid)) {
|
if (conference.getJid().equals(jid)) {
|
||||||
if(conference.isShared()) {
|
if (conference.isShared()) {
|
||||||
throw new IllegalArgumentException("Conference is shared and can't be removed");
|
throw new IllegalArgumentException("Conference is shared and can't be removed");
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
|
@ -192,9 +192,9 @@ public final class BookmarkManager {
|
||||||
retrieveBookmarks();
|
retrieveBookmarks();
|
||||||
BookmarkedURL bookmark = new BookmarkedURL(URL, name, isRSS);
|
BookmarkedURL bookmark = new BookmarkedURL(URL, name, isRSS);
|
||||||
List<BookmarkedURL> urls = bookmarks.getBookmarkedURLS();
|
List<BookmarkedURL> urls = bookmarks.getBookmarkedURLS();
|
||||||
if(urls.contains(bookmark)) {
|
if (urls.contains(bookmark)) {
|
||||||
BookmarkedURL oldURL = urls.get(urls.indexOf(bookmark));
|
BookmarkedURL oldURL = urls.get(urls.indexOf(bookmark));
|
||||||
if(oldURL.isShared()) {
|
if (oldURL.isShared()) {
|
||||||
throw new IllegalArgumentException("Cannot modify shared bookmarks");
|
throw new IllegalArgumentException("Cannot modify shared bookmarks");
|
||||||
}
|
}
|
||||||
oldURL.setName(name);
|
oldURL.setName(name);
|
||||||
|
@ -219,10 +219,10 @@ public final class BookmarkManager {
|
||||||
public void removeBookmarkedURL(String bookmarkURL) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
public void removeBookmarkedURL(String bookmarkURL) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
retrieveBookmarks();
|
retrieveBookmarks();
|
||||||
Iterator<BookmarkedURL> it = bookmarks.getBookmarkedURLS().iterator();
|
Iterator<BookmarkedURL> it = bookmarks.getBookmarkedURLS().iterator();
|
||||||
while(it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
BookmarkedURL bookmark = it.next();
|
BookmarkedURL bookmark = it.next();
|
||||||
if(bookmark.getURL().equalsIgnoreCase(bookmarkURL)) {
|
if (bookmark.getURL().equalsIgnoreCase(bookmarkURL)) {
|
||||||
if(bookmark.isShared()) {
|
if (bookmark.isShared()) {
|
||||||
throw new IllegalArgumentException("Cannot delete a shared bookmark.");
|
throw new IllegalArgumentException("Cannot delete a shared bookmark.");
|
||||||
}
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
|
@ -249,8 +249,8 @@ public final class BookmarkManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bookmarks retrieveBookmarks() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
private Bookmarks retrieveBookmarks() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
synchronized(bookmarkLock) {
|
synchronized (bookmarkLock) {
|
||||||
if(bookmarks == null) {
|
if (bookmarks == null) {
|
||||||
bookmarks = (Bookmarks) privateDataManager.getPrivateData("storage",
|
bookmarks = (Bookmarks) privateDataManager.getPrivateData("storage",
|
||||||
"storage:bookmarks");
|
"storage:bookmarks");
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,10 +115,10 @@ public class BookmarkedConference implements SharedBookmark {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if(obj == null || !(obj instanceof BookmarkedConference)) {
|
if (obj == null || !(obj instanceof BookmarkedConference)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BookmarkedConference conference = (BookmarkedConference)obj;
|
BookmarkedConference conference = (BookmarkedConference) obj;
|
||||||
return conference.getJid().equals(jid);
|
return conference.getJid().equals(jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,10 +86,10 @@ public class BookmarkedURL implements SharedBookmark {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if(!(obj instanceof BookmarkedURL)) {
|
if (!(obj instanceof BookmarkedURL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BookmarkedURL url = (BookmarkedURL)obj;
|
BookmarkedURL url = (BookmarkedURL) obj;
|
||||||
return url.getURL().equalsIgnoreCase(URL);
|
return url.getURL().equalsIgnoreCase(URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class Bookmarks implements PrivateData {
|
||||||
buf.halfOpenElement(ELEMENT).xmlnsAttribute(NAMESPACE).rightAngleBracket();
|
buf.halfOpenElement(ELEMENT).xmlnsAttribute(NAMESPACE).rightAngleBracket();
|
||||||
|
|
||||||
for (BookmarkedURL urlStorage : getBookmarkedURLS()) {
|
for (BookmarkedURL urlStorage : getBookmarkedURLS()) {
|
||||||
if(urlStorage.isShared()) {
|
if (urlStorage.isShared()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
buf.halfOpenElement("url").attribute("name", urlStorage.getName()).attribute("url", urlStorage.getURL());
|
buf.halfOpenElement("url").attribute("name", urlStorage.getName()).attribute("url", urlStorage.getURL());
|
||||||
|
@ -187,7 +187,7 @@ public class Bookmarks implements PrivateData {
|
||||||
|
|
||||||
// Add Conference additions
|
// Add Conference additions
|
||||||
for (BookmarkedConference conference : getBookmarkedConferences()) {
|
for (BookmarkedConference conference : getBookmarkedConferences()) {
|
||||||
if(conference.isShared()) {
|
if (conference.isShared()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
buf.halfOpenElement("conference");
|
buf.halfOpenElement("conference");
|
||||||
|
@ -260,7 +260,7 @@ public class Bookmarks implements PrivateData {
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
int eventType = parser.next();
|
int eventType = parser.next();
|
||||||
if(eventType == XmlPullParser.START_TAG
|
if (eventType == XmlPullParser.START_TAG
|
||||||
&& "shared_bookmark".equals(parser.getName())) {
|
&& "shared_bookmark".equals(parser.getName())) {
|
||||||
urlStore.setShared(true);
|
urlStore.setShared(true);
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ public class Bookmarks implements PrivateData {
|
||||||
else if (eventType == XmlPullParser.START_TAG && "password".equals(parser.getName())) {
|
else if (eventType == XmlPullParser.START_TAG && "password".equals(parser.getName())) {
|
||||||
conf.setPassword(parser.nextText());
|
conf.setPassword(parser.nextText());
|
||||||
}
|
}
|
||||||
else if(eventType == XmlPullParser.START_TAG
|
else if (eventType == XmlPullParser.START_TAG
|
||||||
&& "shared_bookmark".equals(parser.getName())) {
|
&& "shared_bookmark".equals(parser.getName())) {
|
||||||
conf.setShared(true);
|
conf.setShared(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ class DataListener extends AbstractIqRequestHandler {
|
||||||
ibbSession.processIQPacket(data);
|
ibbSession.processIQPacket(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NotConnectedException|InterruptedException e) {
|
catch (NotConnectedException | InterruptedException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -415,7 +415,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Socks5BytestreamSession establishSession(Jid targetJID, String sessionID)
|
public Socks5BytestreamSession establishSession(Jid targetJID, String sessionID)
|
||||||
throws IOException, InterruptedException, NoResponseException, SmackException, XMPPException{
|
throws IOException, InterruptedException, NoResponseException, SmackException, XMPPException {
|
||||||
XMPPConnection connection = connection();
|
XMPPConnection connection = connection();
|
||||||
XMPPErrorException discoveryException = null;
|
XMPPErrorException discoveryException = null;
|
||||||
// check if target supports SOCKS5 Bytestream
|
// check if target supports SOCKS5 Bytestream
|
||||||
|
@ -556,7 +556,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
||||||
try {
|
try {
|
||||||
proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
|
proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
|
||||||
}
|
}
|
||||||
catch (NoResponseException|XMPPErrorException e) {
|
catch (NoResponseException | XMPPErrorException e) {
|
||||||
// blacklist errornous server
|
// blacklist errornous server
|
||||||
proxyBlacklist.add(item.getEntityID());
|
proxyBlacklist.add(item.getEntityID());
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -280,7 +280,7 @@ public final class Socks5Proxy {
|
||||||
* @return true if the address was removed.
|
* @return true if the address was removed.
|
||||||
*/
|
*/
|
||||||
public boolean removeLocalAddress(String address) {
|
public boolean removeLocalAddress(String address) {
|
||||||
synchronized(localAddresses) {
|
synchronized (localAddresses) {
|
||||||
return localAddresses.remove(address);
|
return localAddresses.remove(address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,7 @@ public final class Socks5Proxy {
|
||||||
if (addresses == null) {
|
if (addresses == null) {
|
||||||
throw new IllegalArgumentException("list must not be null");
|
throw new IllegalArgumentException("list must not be null");
|
||||||
}
|
}
|
||||||
synchronized(localAddresses) {
|
synchronized (localAddresses) {
|
||||||
localAddresses.clear();
|
localAddresses.clear();
|
||||||
localAddresses.addAll(addresses);
|
localAddresses.addAll(addresses);
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ public class Bytestream extends IQ {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
switch(getType()) {
|
switch (getType()) {
|
||||||
case set:
|
case set:
|
||||||
xml.optAttribute("sid", getSessionID());
|
xml.optAttribute("sid", getSessionID());
|
||||||
xml.optAttribute("mode", getMode());
|
xml.optAttribute("mode", getMode());
|
||||||
|
|
|
@ -717,7 +717,7 @@ public final class EntityCapsManager extends Manager {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
byte[] digest;
|
byte[] digest;
|
||||||
synchronized(md) {
|
synchronized (md) {
|
||||||
digest = md.digest(bytes);
|
digest = md.digest(bytes);
|
||||||
}
|
}
|
||||||
String version = Base64.encodeToString(digest);
|
String version = Base64.encodeToString(digest);
|
||||||
|
|
|
@ -105,10 +105,10 @@ public final class ChatStateManager extends Manager {
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public void setCurrentState(ChatState newState, org.jivesoftware.smack.chat.Chat chat) throws NotConnectedException, InterruptedException {
|
public void setCurrentState(ChatState newState, org.jivesoftware.smack.chat.Chat chat) throws NotConnectedException, InterruptedException {
|
||||||
if(chat == null || newState == null) {
|
if (chat == null || newState == null) {
|
||||||
throw new IllegalArgumentException("Arguments cannot be null.");
|
throw new IllegalArgumentException("Arguments cannot be null.");
|
||||||
}
|
}
|
||||||
if(!updateChatState(chat, newState)) {
|
if (!updateChatState(chat, newState)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
|
|
|
@ -140,7 +140,7 @@ public final class ServiceDiscoveryManager extends Manager {
|
||||||
response.addItems(nodeInformationProvider.getNodeItems());
|
response.addItems(nodeInformationProvider.getNodeItems());
|
||||||
// Add packet extensions
|
// Add packet extensions
|
||||||
response.addExtensions(nodeInformationProvider.getNodePacketExtensions());
|
response.addExtensions(nodeInformationProvider.getNodePacketExtensions());
|
||||||
} else if(discoverItems.getNode() != null) {
|
} else if (discoverItems.getNode() != null) {
|
||||||
// Return <item-not-found/> error since client doesn't contain
|
// Return <item-not-found/> error since client doesn't contain
|
||||||
// the specified node
|
// the specified node
|
||||||
response.setType(IQ.Type.error);
|
response.setType(IQ.Type.error);
|
||||||
|
@ -761,7 +761,7 @@ public final class ServiceDiscoveryManager extends Manager {
|
||||||
try {
|
try {
|
||||||
// Get the disco items and send the disco packet to each server item
|
// Get the disco items and send the disco packet to each server item
|
||||||
items = discoverItems(serviceName);
|
items = discoverItems(serviceName);
|
||||||
} catch(XMPPErrorException e) {
|
} catch (XMPPErrorException e) {
|
||||||
LOGGER.log(Level.WARNING, "Could not discover items about service", e);
|
LOGGER.log(Level.WARNING, "Could not discover items about service", e);
|
||||||
return serviceDiscoInfo;
|
return serviceDiscoInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class DiscoverInfoProvider extends IQProvider<DiscoverInfo> {
|
||||||
if (parser.getName().equals("feature")) {
|
if (parser.getName().equals("feature")) {
|
||||||
// Create a new feature and add it to the discovered info.
|
// Create a new feature and add it to the discovered info.
|
||||||
boolean notADuplicateFeature = discoverInfo.addFeature(variable);
|
boolean notADuplicateFeature = discoverInfo.addFeature(variable);
|
||||||
assert(notADuplicateFeature);
|
assert (notADuplicateFeature);
|
||||||
}
|
}
|
||||||
if (parser.getName().equals("query")) {
|
if (parser.getName().equals("query")) {
|
||||||
done = true;
|
done = true;
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
|
||||||
private StreamNegotiator determineNegotiator(Stanza streamInitiation) {
|
private StreamNegotiator determineNegotiator(Stanza streamInitiation) {
|
||||||
if (streamInitiation instanceof Bytestream) {
|
if (streamInitiation instanceof Bytestream) {
|
||||||
return primaryNegotiator;
|
return primaryNegotiator;
|
||||||
} else if (streamInitiation instanceof Open){
|
} else if (streamInitiation instanceof Open) {
|
||||||
return secondaryNegotiator;
|
return secondaryNegotiator;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Unknown stream initation type");
|
throw new IllegalStateException("Unknown stream initation type");
|
||||||
|
|
|
@ -308,7 +308,7 @@ public abstract class FileTransfer {
|
||||||
* Return the length of bytes written out to the stream.
|
* Return the length of bytes written out to the stream.
|
||||||
* @return the amount in bytes written out.
|
* @return the amount in bytes written out.
|
||||||
*/
|
*/
|
||||||
public long getAmountWritten(){
|
public long getAmountWritten() {
|
||||||
return amountWritten;
|
return amountWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class OutgoingFileTransfer extends FileTransfer {
|
||||||
final long fileSize, final String description,
|
final long fileSize, final String description,
|
||||||
final NegotiationProgress progress)
|
final NegotiationProgress progress)
|
||||||
{
|
{
|
||||||
if(progress == null) {
|
if (progress == null) {
|
||||||
throw new IllegalArgumentException("Callback progress cannot be null.");
|
throw new IllegalArgumentException("Callback progress cannot be null.");
|
||||||
}
|
}
|
||||||
checkTransferThread();
|
checkTransferThread();
|
||||||
|
@ -295,7 +295,7 @@ public class OutgoingFileTransfer extends FileTransfer {
|
||||||
* @param fileSize the size of the file that is transferred
|
* @param fileSize the size of the file that is transferred
|
||||||
* @param description a description for the file to transfer.
|
* @param description a description for the file to transfer.
|
||||||
*/
|
*/
|
||||||
public synchronized void sendStream(final InputStream in, final String fileName, final long fileSize, final String description){
|
public synchronized void sendStream(final InputStream in, final String fileName, final long fileSize, final String description) {
|
||||||
checkTransferThread();
|
checkTransferThread();
|
||||||
|
|
||||||
setFileInfo(fileName, fileSize);
|
setFileInfo(fileName, fileSize);
|
||||||
|
@ -409,7 +409,7 @@ public class OutgoingFileTransfer extends FileTransfer {
|
||||||
@Override
|
@Override
|
||||||
protected boolean updateStatus(Status oldStatus, Status newStatus) {
|
protected boolean updateStatus(Status oldStatus, Status newStatus) {
|
||||||
boolean isUpdated = super.updateStatus(oldStatus, newStatus);
|
boolean isUpdated = super.updateStatus(oldStatus, newStatus);
|
||||||
if(callback != null && isUpdated) {
|
if (callback != null && isUpdated) {
|
||||||
callback.statusUpdated(oldStatus, newStatus);
|
callback.statusUpdated(oldStatus, newStatus);
|
||||||
}
|
}
|
||||||
return isUpdated;
|
return isUpdated;
|
||||||
|
@ -419,7 +419,7 @@ public class OutgoingFileTransfer extends FileTransfer {
|
||||||
protected void setStatus(Status status) {
|
protected void setStatus(Status status) {
|
||||||
Status oldStatus = getStatus();
|
Status oldStatus = getStatus();
|
||||||
super.setStatus(status);
|
super.setStatus(status);
|
||||||
if(callback != null) {
|
if (callback != null) {
|
||||||
callback.statusUpdated(oldStatus, status);
|
callback.statusUpdated(oldStatus, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -427,7 +427,7 @@ public class OutgoingFileTransfer extends FileTransfer {
|
||||||
@Override
|
@Override
|
||||||
protected void setException(Exception exception) {
|
protected void setException(Exception exception) {
|
||||||
super.setException(exception);
|
super.setException(exception);
|
||||||
if(callback != null) {
|
if (callback != null) {
|
||||||
callback.errorEstablishingStream(exception);
|
callback.errorEstablishingStream(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue