Smack 4 (#136) - SPARK-1567

* SMACK4: Prevent NPE in Roar plugin.

* SMACK4: Replaced Smack 3 libs with Smack 4.

* SMACK4: ProviderManager's methods are now static.

* SMACK4: Move MUCUser to org.jivesoftware.smackx.muc.packet.MUCUser

* SMACK4: Move PrivateDataManager to org.jivesoftware.smackx.iqprivate.PrivateDataManager

* SMACK4: Move ServiceDiscoveryManager to org.jivesoftware.smackx.disco.ServiceDiscoveryManager

* SMACK4: Move DiscoverInfo/Items to org.jivesoftware.smackx.disco.packet.DiscoverInfo/Items

* SMACK4: Renamed org.jivesoftware.smackx.bookmark package -> org.jivesoftware.smackx.bookmarks

* SMACK4: Move DelayInformation to org.jivesoftware.smackx.delay.packet.DelayInformation

* SMACK4: Move PrivateData(Provider) to org.jivesoftware.smackx.iqprivate.packet

* SMACK4: Move Roster* to org.jivesoftware.smack.Roster

* SMACK4: Move VCard to org.jivesoftware.smackx.vcardtemp.packet.VCard

* SMACK4: Move Form to org.jivesoftware.smackx.xdata.Form

* SMACK4: Move ChatState to org.jivesoftware.smackx.chatstates.ChatState

* SMACK4: Move Chat to org.jivesoftware.smack.chat.Chat

* SMACK4: Move RosterPacket to import org.jivesoftware.smack.roster.packet.RosterPacket;

* SMACK4: Move ReportedData to import org.jivesoftware.smackx.search.ReportedData

* SMACK4: Move Privacy* to org.jivesoftware.smackx.privacy

* SMACK4: Move Time to org.jivesoftware.smackx.time.packet.Time

* SMACK4: Move Version to org.jivesoftware.smackx.iqversion.packet.Version

* SMACK4: Renamed org.jivesoftware.smack.Connection to org.jivesoftware.smack.XMPPConnection

* SMACK-4: Packet -> Stanza

A rather large commit that refactors all 'Packet' implementations to the new
'Stanza' alternatives. As a side-effect, most filters and extension-related
classes are affected.

* SMACK4: Fixed the IQ.Type enum (all to lowercase)

* SMACK4: Fixed obtaining a Roster instance.

* SMACK4: Fixed service discovery element iteration (from iterator to collection).

* SMACK4: Replaced StingUtils with XMPPStringUtils

* SMACK4: Move LastActivity to org.jivesoftware.smackx.iqlast

* SMACK4: Move SharedGroups to org.jivesoftware.smackx.sharedgroups

* SMACK4: Fixed obtaining a Roster instance.

* SMACK4: Fixed dataform iteration (from iterator to collection).

* SMACK4: Changed the FormField type constants to enum values.

* SMACK4: Fixed dataform iteration (from iterator to collection).

* SMACK4: Replaced Smack 3 libs with Smack 4.

* SMACK4: Renamed org.jivesoftware.smackx.jingle to org.jivesoftware.smackx.jingleold

* SMACK4: Migrated the jive property extensions to stanzas.

* SMACK4: Fixed obtaining a ChatManager instance (Smack's, not Spark's).

* SMACK4: Move MessageEvent to org.jivesoftware.smackx.xevent

* SMACK4: Fixed obtaining a MultiUserChatManager instance.

* SMACK4: Added SmackException to catches for XMPPException.

* SMACK4: MUC Service refactoring.

* SMACK4: MessageEvent#setPacketID -> setStanzaId

* SMACK4: Refactored PacketExtensionProvider to ExtensionElementProvider

* SMACK4: Fixed changed interface of Version.

* SMACK4: Fixed for Privacy List

* SMACK4: Fixed for Scratchpad

* SMACK4: Fixed for Systray

* SMACK4: ConnectionListener fixes (and some various others)

* SMACK4: Fixed Translator plugin.

* SMACK4: Fixed TicTacToe plugin.

* SMACK4: Fixed Reversi plugin.

* SMACK4: Fixed OTR plugin.

* SMACK4: Fixed Jingle plugin.

* SMACK4: Fixed FasthPath plugin.

* SMACK4: Fixed Battleship plugin (although it had an error to begin with, and still has).

* SMACK4: Fixed SIP plugin.

* SMACK4: Fixes for MUC (mostly error handling).

* SMACK4: Various fixes.

* SMACK4: Fixes for iqVersion.

* SMACK4: Fixes for MUC.

* SMACK4: Fixes for Bookmark plugin.

* SMACK4: Fixes for PresenceChange plugin.

* SMACK4: Fixes for FileTransfer

* SMACK4: Fixes for Gateway plugin.

* SMACK4: Fixes for Privacy List.

* SMACK4: Fixes for VCardManager.

* SMACK4: Fixes for UserSearch.

* SMACK4: Fixes for connection logic.

* SMACK4: Fixes for MUC.

* SMACK4: Fixes for connection logic.

* SMACK4: Fixes PhonePlugin

This commit introduces a new asterisk-im-client library (which is Smack 4 based).
It also renames of other libraries to conform to standards.

* SMACK4: Do not confuse compiler with SingletonMap-hack.

* SMACK4: Fix the last few compiler errors.

* SMACK4: Settled Smack dependencies.

This commit re-organizes the libraries that ship with Spark, primarily
to fulfill Smack's dependencies.

On a side-note: Using this code, I was able to compile and start
Spark, joining a MUC and exchanging messages. There's plenty of things
going wrong, but hey, getting close. :)

* SMACK4: Fixing self-presence evaluation in MUC (prevents NPEs).

* SMACK4: Fixing VCards.

* SMACK4: Fixing FastPath plugin.

* SMACK4: Fixing SIP plugin.

* SMACK4: Fixing TransferGuard plugin.

* SMACK4: Fixing Buzz plugin.
This commit is contained in:
Guus der Kinderen
2016-05-04 20:31:00 +02:00
committed by wroot
parent d68c92107c
commit 1122172ed2
208 changed files with 3042 additions and 2499 deletions

View File

@ -88,15 +88,14 @@ import org.dom4j.io.SAXReader;
import org.jivesoftware.resource.Default;
import org.jivesoftware.resource.Res;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.proxy.ProxyInfo;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.sasl.javax.SASLExternalMechanism;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.ChatStateManager;
import org.jivesoftware.smackx.chatstates.ChatStateManager;
import org.jivesoftware.spark.SessionManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.Workspace;
@ -113,6 +112,7 @@ import org.jivesoftware.sparkimpl.plugin.layout.LayoutSettings;
import org.jivesoftware.sparkimpl.plugin.layout.LayoutSettingsManager;
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
import org.jxmpp.util.XmppStringUtils;
/**
* Dialog to log in a user into the Spark Server. The LoginDialog is used only
@ -233,7 +233,7 @@ public class LoginDialog {
// settings
}
protected ConnectionConfiguration retrieveConnectionConfiguration() {
protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {
int port = localPref.getXmppPort();
int checkForPort = loginServer.indexOf(":");
@ -248,8 +248,6 @@ public class LoginDialog {
boolean useSSL = localPref.isSSL();
boolean hostPortConfigured = localPref.isHostAndPortConfigured();
ConnectionConfiguration config = null;
ProxyInfo proxyInfo = null;
if (localPref.isProxyEnabled()) {
ProxyInfo.ProxyType pType = localPref.getProtocol().equals("SOCKS") ?
@ -277,83 +275,59 @@ public class LoginDialog {
Log.error("No proxy info found but proxy type is enabled!");
}
}
final XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword( "username", "password" )
.setServiceName( loginServer )
.setPort( port )
.setSendPresence( false )
.setCompressionEnabled( localPref.isCompressionEnabled() );
if ( hostPortConfigured ) {
builder.setHost( localPref.getXmppHost() );
}
if ( localPref.isProxyEnabled() )
{
builder.setProxyInfo( proxyInfo );
}
if (useSSL) {
if (!hostPortConfigured) {
config = new ConnectionConfiguration(loginServer, 5223);
config.setSocketFactory(new DummySSLSocketFactory());
}
else {
config = new ConnectionConfiguration(localPref.getXmppHost(), port, loginServer);
config.setSocketFactory(new DummySSLSocketFactory());
}
if(localPref.isProxyEnabled() && !hostPortConfigured)
{
config = new ConnectionConfiguration(loginServer,5223,proxyInfo);
}
else if(localPref.isProxyEnabled() && !hostPortConfigured)
{
config = new ConnectionConfiguration(localPref.getXmppHost(), port, loginServer,proxyInfo);
builder.setPort( 5223 );
}
builder.setSocketFactory( new DummySSLSocketFactory() );
}
else {
if(!localPref.isProxyEnabled())
{
if (!hostPortConfigured) {
config = new ConnectionConfiguration(loginServer);
}
else {
config = new ConnectionConfiguration(localPref.getXmppHost(), port, loginServer);
}
}
else
{
if (!hostPortConfigured) {
config = new ConnectionConfiguration(loginServer,proxyInfo);
}
else {
config = new ConnectionConfiguration(localPref.getXmppHost(), port, loginServer,proxyInfo);
}
}
}
config.setReconnectionAllowed(true);
config.setRosterLoadedAtLogin(true);
config.setSendPresence(false);
final XMPPTCPConnectionConfiguration configuration = builder.build();
if (localPref.isPKIEnabled()) {
SASLAuthentication.supportSASLMechanism("EXTERNAL");
config.setKeystoreType(localPref.getPKIStore());
SASLAuthentication.registerSASLMechanism( new SASLExternalMechanism() );
builder.setKeystoreType(localPref.getPKIStore());
if(localPref.getPKIStore().equals("PKCS11")) {
config.setPKCS11Library(localPref.getPKCS11Library());
builder.setPKCS11Library(localPref.getPKCS11Library());
}
else if(localPref.getPKIStore().equals("JKS")) {
config.setKeystoreType("JKS");
config.setKeystorePath(localPref.getJKSPath());
builder.setKeystoreType("JKS");
builder.setKeystorePath(localPref.getJKSPath());
}
else if(localPref.getPKIStore().equals("X509")) {
//do something
}
else if(localPref.getPKIStore().equals("Apple")) {
config.setKeystoreType("Apple");
builder.setKeystoreType("Apple");
}
}
boolean compressionEnabled = localPref.isCompressionEnabled();
config.setCompressionEnabled(compressionEnabled);
if(ModelUtil.hasLength(localPref.getTrustStorePath())) {
config.setTruststorePath(localPref.getTrustStorePath());
config.setTruststorePassword(localPref.getTrustStorePassword());
}
return config;
// TODO These were used in Smack 3. Find Smack 4 alternative.
// config.setReconnectionAllowed(true);
// config.setRosterLoadedAtLogin(true);
// if(ModelUtil.hasLength(localPref.getTrustStorePath())) {
// config.setTruststorePath(localPref.getTrustStorePath());
// config.setTruststorePassword(localPref.getTrustStorePassword());
// }
return builder.build();
}
/**
@ -388,7 +362,7 @@ public class LoginDialog {
final JPanel buttonPanel = new JPanel(new GridBagLayout());
private final GridBagLayout GRIDBAGLAYOUT = new GridBagLayout();
private XMPPConnection connection = null;
private AbstractXMPPConnection connection = null;
private JLabel headerLabel = new JLabel();
private JLabel accountLabel = new JLabel();
@ -601,7 +575,7 @@ public class LoginDialog {
if (userProp != null) {
usernameField.setText(StringUtils.unescapeNode(userProp));
usernameField.setText( XmppStringUtils.unescapeLocalpart(userProp));
}
if (serverProp != null) {
serverField.setText(serverProp);
@ -672,7 +646,7 @@ public class LoginDialog {
* @return the username.
*/
private String getUsername() {
return StringUtils.escapeNode(usernameField.getText().trim());
return XmppStringUtils.escapeLocalpart(usernameField.getText().trim());
}
/**
@ -1085,15 +1059,14 @@ public class LoginDialog {
if (!hasErrors) {
localPref = SettingsManager.getLocalPreferences();
if (localPref.isDebuggerEnabled()) {
XMPPConnection.DEBUG_ENABLED = true;
SmackConfiguration.DEBUG = true;
}
SmackConfiguration.setPacketReplyTimeout(localPref.getTimeOut() * 1000);
SmackConfiguration.setDefaultPacketReplyTimeout(localPref.getTimeOut() * 1000);
// Get connection
try {
ConnectionConfiguration config = retrieveConnectionConfiguration();
connection = new XMPPConnection(config,this);
connection = new XMPPTCPConnection(retrieveConnectionConfiguration());
//If we want to use the debug version of smack, we have to check if
//we are on the dispatch thread because smack will create an UI
if (localPref.isDebuggerEnabled()) {
@ -1106,7 +1079,7 @@ public class LoginDialog {
public void run() {
try {
connection.connect();
} catch (XMPPException e) {
} catch (IOException | XMPPException | SmackException e) {
Log.error("connection error",e);
}
@ -1143,39 +1116,42 @@ public class LoginDialog {
sessionManager.setJID(connection.getUser());
}
catch (Exception xee) {
errorMessage = SparkRes.getString(SparkRes.UNRECOVERABLE_ERROR);
hasErrors = true;
if (!loginDialog.isVisible()) {
loginDialog.setVisible(true);
}
if (xee instanceof XMPPException) {
if (xee instanceof XMPPException.XMPPErrorException) {
XMPPException xe = (XMPPException)xee;
final XMPPError error = xe.getXMPPError();
int errorCode = 0;
if (error != null) {
errorCode = error.getCode();
}
if (errorCode == 401) {
errorMessage = Res.getString("message.invalid.username.password");
}
else if (errorCode == 502 || errorCode == 504) {
errorMessage = Res.getString("message.server.unavailable");
}
else if (errorCode == 409) {
errorMessage = Res.getString("label.conflict.error");
}
else {
errorMessage = Res.getString("message.unrecoverable.error");
}
}
else {
errorMessage = SparkRes.getString(SparkRes.UNRECOVERABLE_ERROR);
XMPPException.XMPPErrorException xe = (XMPPException.XMPPErrorException)xee;
switch ( xe.getXMPPError().getCondition() )
{
case conflict:
errorMessage = Res.getString("label.conflict.error");
break;
case not_authorized:
errorMessage = Res.getString("message.invalid.username.password");
break;
case remote_server_not_found:
errorMessage = Res.getString("message.server.unavailable");
break;
case remote_server_timeout:
errorMessage = Res.getString("message.server.unavailable");
break;
default:
errorMessage = Res.getString("message.unrecoverable.error");
break;
}
}
// Log Error
Log.warning("Exception in Login:", xee);
hasErrors = true;
}
}