Normalize newlines to '\n'

Change all \r\n into unix style newlines. Add missing newlines at the
end of a file and activate the newline checkstyle module, that enforces
'\n' as newline and a newline at the end of every file.
filetransferTypos
Florian Schmaus 9 years ago
parent 1e57f1c659
commit d069e1be64
  1. 3
      config/checkstyle.xml
  2. 98
      core/src/main/java/org/jivesoftware/smack/AbstractConnectionListener.java
  3. 2
      core/src/main/java/org/jivesoftware/smack/AccountManager.java
  4. 2
      core/src/main/java/org/jivesoftware/smack/Chat.java
  5. 2
      core/src/main/java/org/jivesoftware/smack/ConnectionListener.java
  6. 280
      core/src/main/java/org/jivesoftware/smack/NonSASLAuthentication.java
  7. 92
      core/src/main/java/org/jivesoftware/smack/OpenTrustManager.java
  8. 94
      core/src/main/java/org/jivesoftware/smack/PacketInterceptor.java
  9. 406
      core/src/main/java/org/jivesoftware/smack/ReconnectionManager.java
  10. 2
      core/src/main/java/org/jivesoftware/smack/RosterEntry.java
  11. 2
      core/src/main/java/org/jivesoftware/smack/RosterGroup.java
  12. 2
      core/src/main/java/org/jivesoftware/smack/RosterListener.java
  13. 1176
      core/src/main/java/org/jivesoftware/smack/SASLAuthentication.java
  14. 80
      core/src/main/java/org/jivesoftware/smack/SmackError.java
  15. 152
      core/src/main/java/org/jivesoftware/smack/UserAuthentication.java
  16. 2
      core/src/main/java/org/jivesoftware/smack/XMPPException.java
  17. 2
      core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java
  18. 2
      core/src/main/java/org/jivesoftware/smack/filter/FromContainsFilter.java
  19. 90
      core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
  20. 2
      core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java
  21. 2
      core/src/main/java/org/jivesoftware/smack/filter/ToContainsFilter.java
  22. 110
      core/src/main/java/org/jivesoftware/smack/initializer/LoggingInitializer.java
  23. 70
      core/src/main/java/org/jivesoftware/smack/initializer/SmackInitializer.java
  24. 162
      core/src/main/java/org/jivesoftware/smack/initializer/UrlProviderFileInitializer.java
  25. 82
      core/src/main/java/org/jivesoftware/smack/initializer/VmArgInitializer.java
  26. 136
      core/src/main/java/org/jivesoftware/smack/packet/Bind.java
  27. 2
      core/src/main/java/org/jivesoftware/smack/packet/DefaultPacketExtension.java
  28. 2
      core/src/main/java/org/jivesoftware/smack/packet/Message.java
  29. 2
      core/src/main/java/org/jivesoftware/smack/packet/Presence.java
  30. 2
      core/src/main/java/org/jivesoftware/smack/packet/Registration.java
  31. 84
      core/src/main/java/org/jivesoftware/smack/packet/Session.java
  32. 240
      core/src/main/java/org/jivesoftware/smack/packet/StreamError.java
  33. 82
      core/src/main/java/org/jivesoftware/smack/provider/AbstractProviderInfo.java
  34. 218
      core/src/main/java/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java
  35. 98
      core/src/main/java/org/jivesoftware/smack/provider/ExtensionProviderInfo.java
  36. 2
      core/src/main/java/org/jivesoftware/smack/provider/IQProvider.java
  37. 102
      core/src/main/java/org/jivesoftware/smack/provider/IQProviderInfo.java
  38. 344
      core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
  39. 78
      core/src/main/java/org/jivesoftware/smack/provider/ProviderLoader.java
  40. 2
      core/src/main/java/org/jivesoftware/smack/provider/ProviderManager.java
  41. 118
      core/src/main/java/org/jivesoftware/smack/sasl/SASLAnonymous.java
  42. 70
      core/src/main/java/org/jivesoftware/smack/sasl/SASLCramMD5Mechanism.java
  43. 70
      core/src/main/java/org/jivesoftware/smack/sasl/SASLDigestMD5Mechanism.java
  44. 112
      core/src/main/java/org/jivesoftware/smack/sasl/SASLExternalMechanism.java
  45. 172
      core/src/main/java/org/jivesoftware/smack/sasl/SASLGSSAPIMechanism.java
  46. 800
      core/src/main/java/org/jivesoftware/smack/sasl/SASLMechanism.java
  47. 70
      core/src/main/java/org/jivesoftware/smack/sasl/SASLPlainMechanism.java
  48. 3314
      core/src/main/java/org/jivesoftware/smack/util/Base64.java
  49. 2
      core/src/main/java/org/jivesoftware/smack/util/Cache.java
  50. 2
      core/src/main/java/org/jivesoftware/smack/util/DNSUtil.java
  51. 150
      core/src/main/java/org/jivesoftware/smack/util/FileUtils.java
  52. 134
      core/src/main/java/org/jivesoftware/smack/util/SyncPacketSend.java
  53. 4
      core/src/main/resources/org.jivesoftware.smack/jul.properties
  54. 880
      core/src/test/java/org/jivesoftware/smack/ChatConnectionTest.java
  55. 428
      core/src/test/java/org/jivesoftware/smack/PacketCollectorTest.java
  56. 184
      core/src/test/java/org/jivesoftware/smack/filters/FromMatchesFilterTest.java
  57. 394
      core/src/test/java/org/jivesoftware/smack/packet/PresenceTest.java
  58. 66
      experimental/src/main/java/org/jivesoftware/smackx/ExperimentalProviderInitializer.java
  59. 436
      experimental/src/main/java/org/jivesoftware/smackx/carbons/CarbonManager.java
  60. 234
      experimental/src/main/java/org/jivesoftware/smackx/carbons/packet/CarbonExtension.java
  61. 106
      experimental/src/main/java/org/jivesoftware/smackx/carbons/provider/CarbonManagerProvider.java
  62. 34
      experimental/src/main/resources/org.jivesoftware.smackx/experimental.providers
  63. 228
      experimental/src/test/java/org/jivesoftware/smackx/carbons/CarbonTest.java
  64. 64
      extensions/src/main/java/org/jivesoftware/smackx/ExtensionsProviderInitializer.java
  65. 194
      extensions/src/main/java/org/jivesoftware/smackx/attention/packet/AttentionExtension.java
  66. 100
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamListener.java
  67. 234
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamManager.java
  68. 124
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamRequest.java
  69. 168
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/BytestreamSession.java
  70. 156
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/CloseListener.java
  71. 152
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/DataListener.java
  72. 98
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamListener.java
  73. 1120
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamManager.java
  74. 190
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamRequest.java
  75. 1596
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InBandBytestreamSession.java
  76. 260
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/InitiationListener.java
  77. 136
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/packet/Close.java
  78. 134
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/packet/Data.java
  79. 304
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/packet/DataPacketExtension.java
  80. 258
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/packet/Open.java
  81. 72
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/provider/CloseIQProvider.java
  82. 96
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/provider/DataPacketProvider.java
  83. 96
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/ibb/provider/OpenIQProvider.java
  84. 244
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/InitiationListener.java
  85. 92
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamListener.java
  86. 1566
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamManager.java
  87. 638
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamRequest.java
  88. 162
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5BytestreamSession.java
  89. 414
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Client.java
  90. 240
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ClientForInitiator.java
  91. 856
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Proxy.java
  92. 152
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5Utils.java
  93. 954
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java
  94. 170
      extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/provider/BytestreamsProvider.java
  95. 140
      extensions/src/main/java/org/jivesoftware/smackx/chatstates/packet/ChatStateExtension.java
  96. 894
      extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommand.java
  97. 1406
      extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandManager.java
  98. 166
      extensions/src/main/java/org/jivesoftware/smackx/commands/AdHocCommandNote.java
  99. 332
      extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommand.java
  100. 2
      extensions/src/main/java/org/jivesoftware/smackx/commands/LocalCommandFactory.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -11,6 +11,9 @@
<property name="ignoreLines" value="3"/>
<property name="fileExtensions" value="java"/>
</module>
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf"/>
</module>
<module name="TreeWalker">
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>

@ -1,49 +1,49 @@
/**
*
* Copyright 2009 the original author or authors
*
* 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;
/**
* The AbstractConnectionListener class provides an empty implementation for all
* methods defined by the {@link ConnectionListener} interface. This is a
* convenience class which should be used in case you do not need to implement
* all methods.
*
* @author Henning Staib
*/
public class AbstractConnectionListener implements ConnectionListener {
public void connectionClosed() {
// do nothing
}
public void connectionClosedOnError(Exception e) {
// do nothing
}
public void reconnectingIn(int seconds) {
// do nothing
}
public void reconnectionFailed(Exception e) {
// do nothing
}
public void reconnectionSuccessful() {
// do nothing
}
}
/**
*
* Copyright 2009 the original author or authors
*
* 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;
/**
* The AbstractConnectionListener class provides an empty implementation for all
* methods defined by the {@link ConnectionListener} interface. This is a
* convenience class which should be used in case you do not need to implement
* all methods.
*
* @author Henning Staib
*/
public class AbstractConnectionListener implements ConnectionListener {
public void connectionClosed() {
// do nothing
}
public void connectionClosedOnError(Exception e) {
// do nothing
}
public void reconnectingIn(int seconds) {
// do nothing
}
public void reconnectionFailed(Exception e) {
// do nothing
}
public void reconnectionSuccessful() {
// do nothing
}
}

@ -332,4 +332,4 @@ public class AccountManager {
info = (Registration)result;
}
}
}
}

@ -186,4 +186,4 @@ public class Chat {
&& threadID.equals(((Chat)obj).getThreadID())
&& participant.equals(((Chat)obj).getParticipant());
}
}
}

@ -63,4 +63,4 @@ public interface ConnectionListener {
* @param e the exception that caused the reconnection to fail.
*/
public void reconnectionFailed(Exception e);
}
}

@ -1,140 +1,140 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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 org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.Authentication;
import org.jivesoftware.smack.packet.IQ;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.Callback;
/**
* Implementation of JEP-0078: Non-SASL Authentication. Follow the following
* <a href=http://www.jabber.org/jeps/jep-0078.html>link</a> to obtain more
* information about the JEP.
*
* @author Gaston Dombiak
*/
class NonSASLAuthentication implements UserAuthentication {
private Connection connection;
public NonSASLAuthentication(Connection connection) {
super();
this.connection = connection;
}
public String authenticate(String username, String resource, CallbackHandler cbh) throws XMPPException {
//Use the callback handler to determine the password, and continue on.
PasswordCallback pcb = new PasswordCallback("Password: ",false);
try {
cbh.handle(new Callback[]{pcb});
return authenticate(username, String.valueOf(pcb.getPassword()),resource);
} catch (Exception e) {
throw new XMPPException("Unable to determine password.",e);
}
}
public String authenticate(String username, String password, String resource) throws
XMPPException {
// If we send an authentication packet in "get" mode with just the username,
// the server will return the list of authentication protocols it supports.
Authentication discoveryAuth = new Authentication();
discoveryAuth.setType(IQ.Type.GET);
discoveryAuth.setUsername(username);
PacketCollector collector =
connection.createPacketCollector(new PacketIDFilter(discoveryAuth.getPacketID()));
// Send the packet
connection.sendPacket(discoveryAuth);
// Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
// Otherwise, no error so continue processing.
Authentication authTypes = (Authentication) response;
collector.cancel();
// Now, create the authentication packet we'll send to the server.
Authentication auth = new Authentication();
auth.setUsername(username);
// Figure out if we should use digest or plain text authentication.
if (authTypes.getDigest() != null) {
auth.setDigest(connection.getConnectionID(), password);
}
else if (authTypes.getPassword() != null) {
auth.setPassword(password);
}
else {
throw new XMPPException("Server does not support compatible authentication mechanism.");
}
auth.setResource(resource);
collector = connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet.
connection.sendPacket(auth);
// Wait up to a certain number of seconds for a response from the server.
response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
throw new XMPPException("Authentication failed.");
}
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
// We're done with the collector, so explicitly cancel it.
collector.cancel();
return response.getTo();
}
public String authenticateAnonymously() throws XMPPException {
// Create the authentication packet we'll send to the server.
Authentication auth = new Authentication();
PacketCollector collector =
connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet.
connection.sendPacket(auth);
// Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
throw new XMPPException("Anonymous login failed.");
}
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
// We're done with the collector, so explicitly cancel it.
collector.cancel();
if (response.getTo() != null) {
return response.getTo();
}
else {
return connection.getServiceName() + "/" + ((Authentication) response).getResource();
}
}
}
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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 org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.Authentication;
import org.jivesoftware.smack.packet.IQ;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.Callback;
/**
* Implementation of JEP-0078: Non-SASL Authentication. Follow the following
* <a href=http://www.jabber.org/jeps/jep-0078.html>link</a> to obtain more
* information about the JEP.
*
* @author Gaston Dombiak
*/
class NonSASLAuthentication implements UserAuthentication {
private Connection connection;
public NonSASLAuthentication(Connection connection) {
super();
this.connection = connection;
}
public String authenticate(String username, String resource, CallbackHandler cbh) throws XMPPException {
//Use the callback handler to determine the password, and continue on.
PasswordCallback pcb = new PasswordCallback("Password: ",false);
try {
cbh.handle(new Callback[]{pcb});
return authenticate(username, String.valueOf(pcb.getPassword()),resource);
} catch (Exception e) {
throw new XMPPException("Unable to determine password.",e);
}
}
public String authenticate(String username, String password, String resource) throws
XMPPException {
// If we send an authentication packet in "get" mode with just the username,
// the server will return the list of authentication protocols it supports.
Authentication discoveryAuth = new Authentication();
discoveryAuth.setType(IQ.Type.GET);
discoveryAuth.setUsername(username);
PacketCollector collector =
connection.createPacketCollector(new PacketIDFilter(discoveryAuth.getPacketID()));
// Send the packet
connection.sendPacket(discoveryAuth);
// Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
// Otherwise, no error so continue processing.
Authentication authTypes = (Authentication) response;
collector.cancel();
// Now, create the authentication packet we'll send to the server.
Authentication auth = new Authentication();
auth.setUsername(username);
// Figure out if we should use digest or plain text authentication.
if (authTypes.getDigest() != null) {
auth.setDigest(connection.getConnectionID(), password);
}
else if (authTypes.getPassword() != null) {
auth.setPassword(password);
}
else {
throw new XMPPException("Server does not support compatible authentication mechanism.");
}
auth.setResource(resource);
collector = connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet.
connection.sendPacket(auth);
// Wait up to a certain number of seconds for a response from the server.
response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
throw new XMPPException("Authentication failed.");
}
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
// We're done with the collector, so explicitly cancel it.
collector.cancel();
return response.getTo();
}
public String authenticateAnonymously() throws XMPPException {
// Create the authentication packet we'll send to the server.
Authentication auth = new Authentication();
PacketCollector collector =
connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet.
connection.sendPacket(auth);
// Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
throw new XMPPException("Anonymous login failed.");
}
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
// We're done with the collector, so explicitly cancel it.
collector.cancel();
if (response.getTo() != null) {
return response.getTo();
}
else {
return connection.getServiceName() + "/" + ((Authentication) response).getResource();
}
}
}

@ -1,46 +1,46 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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 javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* Dummy trust manager that trust all certificates presented by the server. This class
* is used during old SSL connections.
*
* @author Gaston Dombiak
*/
class OpenTrustManager implements X509TrustManager {
public OpenTrustManager() {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
}
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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 javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* Dummy trust manager that trust all certificates presented by the server. This class
* is used during old SSL connections.
*
* @author Gaston Dombiak
*/
class OpenTrustManager implements X509TrustManager {
public OpenTrustManager() {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
}

@ -1,47 +1,47 @@
/**
*
* Copyright 2003-2005 Jive Software.
*
* 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 org.jivesoftware.smack.packet.Packet;
/**
* Provides a mechanism to intercept and modify packets that are going to be
* sent to the server. PacketInterceptors are added to the {@link Connection}
* together with a {@link org.jivesoftware.smack.filter.PacketFilter} so that only
* certain packets are intercepted and processed by the interceptor.<p>
*
* This allows event-style programming -- every time a new packet is found,
* the {@link #interceptPacket(Packet)} method will be called.
*
* @see Connection#addPacketInterceptor(PacketInterceptor, org.jivesoftware.smack.filter.PacketFilter)
* @author Gaston Dombiak
*/
public interface PacketInterceptor {
/**
* Process the packet that is about to be sent to the server. The intercepted
* packet can be modified by the interceptor.<p>
*
* Interceptors are invoked using the same thread that requested the packet
* to be sent, so it's very important that implementations of this method
* not block for any extended period of time.
*
* @param packet the packet to is going to be sent to the server.
*/
public void interceptPacket(Packet packet);
}
/**
*
* Copyright 2003-2005 Jive Software.
*
* 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 org.jivesoftware.smack.packet.Packet;
/**
* Provides a mechanism to intercept and modify packets that are going to be
* sent to the server. PacketInterceptors are added to the {@link Connection}
* together with a {@link org.jivesoftware.smack.filter.PacketFilter} so that only
* certain packets are intercepted and processed by the interceptor.<p>
*
* This allows event-style programming -- every time a new packet is found,
* the {@link #interceptPacket(Packet)} method will be called.
*
* @see Connection#addPacketInterceptor(PacketInterceptor, org.jivesoftware.smack.filter.PacketFilter)
* @author Gaston Dombiak
*/
public interface PacketInterceptor {
/**
* Process the packet that is about to be sent to the server. The intercepted
* packet can be modified by the interceptor.<p>
*
* Interceptors are invoked using the same thread that requested the packet
* to be sent, so it's very important that implementations of this method
* not block for any extended period of time.
*
* @param packet the packet to is going to be sent to the server.
*/
public void interceptPacket(Packet packet);
}

@ -14,215 +14,215 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.StreamError;
import java.util.Random;
package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.StreamError;
import java.util.Random;
import java.util.logging.Logger;
/**
* Handles the automatic reconnection process. Every time a connection is dropped without
* the application explictly closing it, the manager automatically tries to reconnect to
* the server.<p>
*
* The reconnection mechanism will try to reconnect periodically:
* <ol>
* <li>For the first minute it will attempt to connect once every ten seconds.
* <li>For the next five minutes it will attempt to connect once a minute.
* <li>If that fails it will indefinitely try to connect once every five minutes.
* </ol>
*
* @author Francisco Vives
*/
public class ReconnectionManager implements ConnectionListener {
/**
* Handles the automatic reconnection process. Every time a connection is dropped without
* the application explictly closing it, the manager automatically tries to reconnect to
* the server.<p>
*
* The reconnection mechanism will try to reconnect periodically:
* <ol>
* <li>For the first minute it will attempt to connect once every ten seconds.
* <li>For the next five minutes it will attempt to connect once a minute.
* <li>If that fails it will indefinitely try to connect once every five minutes.
* </ol>
*
* @author Francisco Vives
*/
public class ReconnectionManager implements ConnectionListener {
private static Logger log = Logger.getLogger(ReconnectionManager.class.getName());
// Holds the connection to the server
private Connection connection;
private Thread reconnectionThread;
private int randomBase = new Random().nextInt(11) + 5; // between 5 and 15 seconds
// Holds the state of the reconnection
boolean done = false;
static {
// Create a new PrivacyListManager on every established connection. In the init()
// method of PrivacyListManager, we'll add a listener that will delete the
// instance when the connection is closed.
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
connection.addConnectionListener(new ReconnectionManager(connection));
}
});
}
private ReconnectionManager(Connection connection) {
this.connection = connection;
}
/**
* Returns true if the reconnection mechanism is enabled.
*
* @return true if automatic reconnections are allowed.
*/
private boolean isReconnectionAllowed() {
// Holds the connection to the server
private Connection connection;
private Thread reconnectionThread;
private int randomBase = new Random().nextInt(11) + 5; // between 5 and 15 seconds
// Holds the state of the reconnection
boolean done = false;
static {
// Create a new PrivacyListManager on every established connection. In the init()
// method of PrivacyListManager, we'll add a listener that will delete the
// instance when the connection is closed.
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(Connection connection) {
connection.addConnectionListener(new ReconnectionManager(connection));
}
});
}
private ReconnectionManager(Connection connection) {
this.connection = connection;
}
/**
* Returns true if the reconnection mechanism is enabled.
*
* @return true if automatic reconnections are allowed.
*/
private boolean isReconnectionAllowed() {
return !done && !connection.isConnected()
&& connection.isReconnectionAllowed();
}
/**
* Starts a reconnection mechanism if it was configured to do that.
* The algorithm is been executed when the first connection error is detected.
* <p/>
* The reconnection mechanism will try to reconnect periodically in this way:
* <ol>
* <li>First it will try 6 times every 10 seconds.
* <li>Then it will try 10 times every 1 minute.
* <li>Finally it will try indefinitely every 5 minutes.
* </ol>
*/
synchronized protected void reconnect() {
if (this.isReconnectionAllowed()) {
// Since there is no thread running, creates a new one to attempt
// the reconnection.
// avoid to run duplicated reconnectionThread -- fd: 16/09/2010
if (reconnectionThread!=null && reconnectionThread.isAlive()) return;
reconnectionThread = new Thread() {
/**
* Holds the current number of reconnection attempts
*/
private int attempts = 0;
/**
* Returns the number of seconds until the next reconnection attempt.
*
* @return the number of seconds until the next reconnection attempt.
*/
private int timeDelay() {
attempts++;
if (attempts > 13) {
return randomBase*6*5; // between 2.5 and 7.5 minutes (~5 minutes)
}
if (attempts > 7) {
return randomBase*6; // between 30 and 90 seconds (~1 minutes)
}
return randomBase; // 10 seconds
}
/**
* The process will try the reconnection until the connection succeed or the user
* cancell it
*/
public void run() {
// The process will try to reconnect until the connection is established or
// the user cancel the reconnection process {@link Connection#disconnect()}
while (ReconnectionManager.this.isReconnectionAllowed()) {
// Find how much time we should wait until the next reconnection
int remainingSeconds = timeDelay();
// Sleep until we're ready for the next reconnection attempt. Notify
// listeners once per second about how much time remains before the next
// reconnection attempt.
while (ReconnectionManager.this.isReconnectionAllowed() &&
remainingSeconds > 0)
{
try {
Thread.sleep(1000);
remainingSeconds--;
ReconnectionManager.this
.notifyAttemptToReconnectIn(remainingSeconds);
}
}
/**
* Starts a reconnection mechanism if it was configured to do that.
* The algorithm is been executed when the first connection error is detected.
* <p/>
* The reconnection mechanism will try to reconnect periodically in this way:
* <ol>
* <li>First it will try 6 times every 10 seconds.
* <li>Then it will try 10 times every 1 minute.
* <li>Finally it will try indefinitely every 5 minutes.
* </ol>
*/
synchronized protected void reconnect() {
if (this.isReconnectionAllowed()) {
// Since there is no thread running, creates a new one to attempt
// the reconnection.
// avoid to run duplicated reconnectionThread -- fd: 16/09/2010
if (reconnectionThread!=null && reconnectionThread.isAlive()) return;
reconnectionThread = new Thread() {
/**
* Holds the current number of reconnection attempts
*/
private int attempts = 0;
/**
* Returns the number of seconds until the next reconnection attempt.
*
* @return the number of seconds until the next reconnection attempt.
*/
private int timeDelay() {
attempts++;
if (attempts > 13) {
return randomBase*6*5; // between 2.5 and 7.5 minutes (~5 minutes)
}
if (attempts > 7) {
return randomBase*6; // between 30 and 90 seconds (~1 minutes)
}
return randomBase; // 10 seconds
}
/**
* The process will try the reconnection until the connection succeed or the user
* cancell it
*/
public void run() {
// The process will try to reconnect until the connection is established or
// the user cancel the reconnection process {@link Connection#disconnect()}
while (ReconnectionManager.this.isReconnectionAllowed()) {
// Find how much time we should wait until the next reconnection
int remainingSeconds = timeDelay();
// Sleep until we're ready for the next reconnection attempt. Notify
// listeners once per second about how much time remains before the next
// reconnection attempt.
while (ReconnectionManager.this.isReconnectionAllowed() &&
remainingSeconds > 0)
{
try {
Thread.sleep(1000);
remainingSeconds--;
ReconnectionManager.this
.notifyAttemptToReconnectIn(remainingSeconds);
}
catch (InterruptedException e1) {
log.warning("Sleeping thread interrupted");
// Notify the reconnection has failed
ReconnectionManager.this.notifyReconnectionFailed(e1);
}
}
// Makes a reconnection attempt
try {
if (ReconnectionManager.this.isReconnectionAllowed()) {
connection.connect();
}
}
catch (XMPPException e) {
// Fires the failed reconnection notification
ReconnectionManager.this.notifyReconnectionFailed(e);
}
}
}
};
reconnectionThread.setName("Smack Reconnection Manager");
reconnectionThread.setDaemon(true);
reconnectionThread.start();
}
}
/**
* Fires listeners when a reconnection attempt has failed.
*
* @param exception the exception that occured.
*/
protected void notifyReconnectionFailed(Exception exception) {
log.warning("Sleeping thread interrupted");
// Notify the reconnection has failed
ReconnectionManager.this.notifyReconnectionFailed(e1);
}
}
// Makes a reconnection attempt
try {
if (ReconnectionManager.this.isReconnectionAllowed()) {
connection.connect();
}
}
catch (XMPPException e) {
// Fires the failed reconnection notification
ReconnectionManager.this.notifyReconnectionFailed(e);
}
}
}
};
reconnectionThread.setName("Smack Reconnection Manager");
reconnectionThread.setDaemon(true);
reconnectionThread.start();
}
}
/**
* Fires listeners when a reconnection attempt has failed.
*
* @param exception the exception that occured.
*/
protected void notifyReconnectionFailed(Exception exception) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.connectionListeners) {
listener.reconnectionFailed(exception);
}
}
}
/**
* Fires listeners when The Connection will retry a reconnection. Expressed in seconds.
*
* @param seconds the number of seconds that a reconnection will be attempted in.
*/
protected void notifyAttemptToReconnectIn(int seconds) {
listener.reconnectionFailed(exception);
}
}
}
/**
* Fires listeners when The Connection will retry a reconnection. Expressed in seconds.
*
* @param seconds the number of seconds that a reconnection will be attempted in.
*/
protected void notifyAttemptToReconnectIn(int seconds) {
if (isReconnectionAllowed()) {
for (ConnectionListener listener : connection.connectionListeners) {
listener.reconnectingIn(seconds);
}
}
}
public void connectionClosed() {
done = true;
}
public void connectionClosedOnError(Exception e) {
done = false;
if (e instanceof XMPPException) {
XMPPException xmppEx = (XMPPException) e;
StreamError error = xmppEx.getStreamError();
// Make sure the error is not null
if (error != null) {
String reason = error.getCode();
if ("conflict".equals(reason)) {
return;
}
}
}
if (this.isReconnectionAllowed()) {
this.reconnect();
}
}
public void reconnectingIn(int seconds) {
// ignore
}
public void reconnectionFailed(Exception e) {
// ignore
}
/**
* The connection has successfull gotten connected.
*/
public void reconnectionSuccessful() {
// ignore
}
}
listener.reconnectingIn(seconds);
}
}
}
public void connectionClosed() {
done = true;
}
public void connectionClosedOnError(Exception e) {
done = false;
if (e instanceof XMPPException) {
XMPPException xmppEx = (XMPPException) e;
StreamError error = xmppEx.getStreamError();
// Make sure the error is not null
if (error != null) {
String reason = error.getCode();
if ("conflict".equals(reason)) {
return;
}
}
}
if (this.isReconnectionAllowed()) {
this.reconnect();
}
}
public void reconnectingIn(int seconds) {
// ignore
}
public void reconnectionFailed(Exception e) {
// ignore
}
/**
* The connection has successfull gotten connected.
*/
public void reconnectionSuccessful() {
// ignore
}
}

@ -238,4 +238,4 @@ public class RosterEntry {
return item;
}
}
}

@ -248,4 +248,4 @@ public class RosterGroup {
}
}
}
}
}

@ -77,4 +77,4 @@ public interface RosterListener {
* @see Roster#getPresence(String)
*/
public void presenceChanged(Presence presence);
}
}

@ -1,40 +1,40 @@
/**
*
* Copyright the original author or authors
*
* 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 enum SmackError {
NO_RESPONSE_FROM_SERVER("No response from server.");
private String message;
private SmackError(String errMessage) {
message = errMessage;
}
public String getErrorMessage() {
return message;
}
public static SmackError getErrorCode(String message) {
for (SmackError code : values()) {
if (code.message.equals(message)) {
return code;
}
}
return null;
}
}
/**
*
* Copyright the original author or authors
*
* 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 enum SmackError {
NO_RESPONSE_FROM_SERVER("No response from server.");
private String message;
private SmackError(String errMessage) {
message = errMessage;
}
public String getErrorMessage() {
return message;
}
public static SmackError getErrorCode(String message) {
for (SmackError code : values()) {
if (code.message.equals(message)) {
return code;
}
}
return null;
}
}

@ -1,76 +1,76 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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 javax.security.auth.callback.CallbackHandler;
/**
* There are two ways to authenticate a user with a server. Using SASL or Non-SASL
* authentication. This interface makes {@link SASLAuthentication} and
* {@link NonSASLAuthentication} polyphormic.
*
* @author Gaston Dombiak
* @author Jay Kline
*/
interface UserAuthentication {
/**
* Authenticates the user with the server. This method will return the full JID provided by
* the server. The server may assign a full JID with a username and resource different than
* requested by this method.
*
* Note that using callbacks is the prefered method of authenticating users since it allows
* more flexability in the mechanisms used.
*
* @param username the requested username (authorization ID) for authenticating to the server
* @param resource the requested resource.
* @param cbh the CallbackHandler used to obtain authentication ID, password, or other
* information
* @return the full JID provided by the server while binding a resource for the connection.
* @throws XMPPException if an error occurs while authenticating.
*/
String authenticate(String username, String resource, CallbackHandler cbh) throws
XMPPException;
/**
* Authenticates the user with the server. This method will return the full JID provided by
* the server. The server may assign a full JID with a username and resource different than
* the requested by this method.
*
* It is recommended that @{link #authenticate(String, String, CallbackHandler)} be used instead
* since it provides greater flexability in authenticaiton and authorization.
*
* @param username the username that is authenticating with the server.
* @param password the password to send to the server.
* @param resource the desired resource.
* @return the full JID provided by the server while binding a resource for the connection.
* @throws XMPPException if an error occures while authenticating.
*/
String authenticate(String username, String password, String resource) throws
XMPPException;
/**
* Performs an anonymous authentication with the server. The server will created a new full JID
* for this connection. An exception will be thrown if the server does not support anonymous
* authentication.
*
* @return the full JID provided by the server while binding a resource for the connection.
* @throws XMPPException if an error occures while authenticating.
*/
String authenticateAnonymously() throws XMPPException;
}
/**
*
* Copyright 2003-2007 Jive Software.
*
* 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 javax.security.auth.callback.CallbackHandler;
/**
* There are two ways to authenticate a user with a server. Using SASL or Non-SASL
* authentication. This interface makes {@link SASLAuthentication} and
* {@link NonSASLAuthentication} polyphormic.
*
* @author Gaston Dombiak
* @author Jay Kline
*/
interface UserAuthentication {
/**
* Authenticates the user with the server. This method will return the full JID provided by
* the server. The server may assign a full JID with a username and resource different than
* requested by this method.
*
* Note that using callbacks is the prefered method of authenticating users since it allows
* more flexability in the mechanisms used.
*
* @param username the requested username (authorization ID) for authenticating to the server
* @param resource the requested resource.
* @param cbh the CallbackHandler used to obtain authentication ID, password, or other
* information
* @return the full JID provided by the server while binding a resource for the connection.
* @throws XMPPException if an error occurs while authenticating.
*/
String authenticate(String username, String resource, CallbackHandler cbh) throws
XMPPException;
/**
* Authenticates the user with the server. This method will return the full JID provided by
* the server. The server may assign a full JID with a username and resource different than
* the requested by this method.
*
* It is recommended that @{link #authenticate(String, String, CallbackHandler)} be used instead
* since it provides greater flexability in authenticaiton and authorization.
*
* @param username the username that is authenticating with the server.
* @param password the password to send to the server.
* @param resource the desired resource.
* @return the full JID provided by the server while binding a resource for the connection.
* @throws XMPPException if an error occures while authenticating.
*/
String authenticate(String username, String password, String resource) throws
XMPPException;
/**
* Performs an anonymous authentication with the server. The server will created a new full JID
* for this connection. An exception will be thrown if the server does not support anonymous
* authentication.
*
* @return the full JID provided by the server while binding a resource for the connection.
* @throws XMPPException if an error occures while authenticating.
*/
String authenticateAnonymously() throws XMPPException;
}

@ -235,4 +235,4 @@ public class XMPPException extends Exception {
return buf.toString();
}
}