1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 00:02:06 +01:00

Added login method so that setting the resource is supported.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1789 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-01-16 01:01:27 +00:00 committed by mtucker
parent 087d031b3d
commit b08a4cb125

View file

@ -191,7 +191,24 @@ public class XMPPConnection {
* @param password the password. * @param password the password.
* @throws XMPPException if an error occurs. * @throws XMPPException if an error occurs.
*/ */
public synchronized void login(String username, String password) throws XMPPException { public void login(String username, String password) throws XMPPException {
login(username, password, "Smack");
}
/**
* Login to the server using the strongest authentication mode supported by
* the server, then set our presence to available. If more than five seconds
* elapses in each step of the authentication process without a response from
* the server, or if an error occurs, a XMPPException will be thrown.
*
* @param username the username.
* @param password the password.
* @param resource the resource.
* @throws XMPPException if an error occurs.
*/
public synchronized void login(String username, String password, String resource)
throws XMPPException
{
if (!isConnected()) { if (!isConnected()) {
throw new IllegalStateException("Not connected to server."); throw new IllegalStateException("Not connected to server.");
} }
@ -200,16 +217,19 @@ public class XMPPConnection {
Authentication discoveryAuth = new Authentication(); Authentication discoveryAuth = new Authentication();
discoveryAuth.setType(IQ.Type.GET); discoveryAuth.setType(IQ.Type.GET);
discoveryAuth.setUsername(username); discoveryAuth.setUsername(username);
packetWriter.sendPacket(discoveryAuth);
// Wait up to five seconds for a response from the server.
PacketCollector collector = packetReader.createPacketCollector( PacketCollector collector = packetReader.createPacketCollector(
new PacketIDFilter(discoveryAuth.getPacketID())); new PacketIDFilter(discoveryAuth.getPacketID()));
// Send the packet
packetWriter.sendPacket(discoveryAuth);
// Wait up to five seconds for a response from the server.
Authentication authTypes = (Authentication)collector.nextResult(5000); Authentication authTypes = (Authentication)collector.nextResult(5000);
collector.cancel(); collector.cancel();
if (authTypes == null || authTypes.getType().equals(IQ.Type.ERROR)) { if (authTypes == null || authTypes.getType().equals(IQ.Type.ERROR)) {
throw new XMPPException("No response from the server."); throw new XMPPException("No response from the server.");
} }
// Now, create the authentication packet we'll send to the server. // Now, create the authentication packet we'll send to the server.
Authentication auth = new Authentication(); Authentication auth = new Authentication();
auth.setUsername(username); auth.setUsername(username);
@ -225,11 +245,13 @@ public class XMPPConnection {
throw new XMPPException("Server does not support compatible authentication mechanism."); throw new XMPPException("Server does not support compatible authentication mechanism.");
} }
auth.setResource("Smack"); auth.setResource(resource);
packetWriter.sendPacket(auth);
// Wait up to five seconds for a response from the server.
collector = packetReader.createPacketCollector( collector = packetReader.createPacketCollector(
new PacketIDFilter(auth.getPacketID())); new PacketIDFilter(auth.getPacketID()));
// Send the packet.
packetWriter.sendPacket(auth);
// Wait up to five seconds for a response from the server.
IQ response = (IQ)collector.nextResult(5000); IQ response = (IQ)collector.nextResult(5000);
if (response == null) { if (response == null) {
throw new XMPPException("Authentication failed."); throw new XMPPException("Authentication failed.");