From b08a4cb1250a4d402a60b28d12f2dda7a3319167 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Thu, 16 Jan 2003 01:01:27 +0000 Subject: [PATCH] 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 --- .../jivesoftware/smack/XMPPConnection.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java index ccaf76143..53f42a7e8 100644 --- a/source/org/jivesoftware/smack/XMPPConnection.java +++ b/source/org/jivesoftware/smack/XMPPConnection.java @@ -191,7 +191,24 @@ public class XMPPConnection { * @param password the password. * @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()) { throw new IllegalStateException("Not connected to server."); } @@ -200,16 +217,19 @@ public class XMPPConnection { Authentication discoveryAuth = new Authentication(); discoveryAuth.setType(IQ.Type.GET); discoveryAuth.setUsername(username); - packetWriter.sendPacket(discoveryAuth); - // Wait up to five seconds for a response from the server. + PacketCollector collector = packetReader.createPacketCollector( 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); collector.cancel(); if (authTypes == null || authTypes.getType().equals(IQ.Type.ERROR)) { throw new XMPPException("No response from the server."); } + // Now, create the authentication packet we'll send to the server. Authentication auth = new Authentication(); auth.setUsername(username); @@ -225,11 +245,13 @@ public class XMPPConnection { throw new XMPPException("Server does not support compatible authentication mechanism."); } - auth.setResource("Smack"); - packetWriter.sendPacket(auth); - // Wait up to five seconds for a response from the server. + auth.setResource(resource); + collector = packetReader.createPacketCollector( 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); if (response == null) { throw new XMPPException("Authentication failed.");