/* * Jeti, a Java Jabber client, Copyright (C) 2003 E.S. de Boer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For questions, comments etc, * use the website at http://jeti.jabberstudio.org * or mail/im me at jeti@jabber.org * * created 2001 */ package nu.fw.jeti.backend; import java.io.*; import java.net.*; import nu.fw.jeti.backend.Connect.DummySSLSocketFactory; import nu.fw.jeti.jabber.elements.*; import nu.fw.jeti.ui.RegisterWindow; import nu.fw.jeti.jabber.*; /** * @author E.S. de Boer * */ public class NewAccount implements ConnectionPacketReceiver { private String server; private String username; private String password; private Output output; private String registerId=""; private RegisterWindow registerWindow; public NewAccount(String server,int port,Handlers handlers,String username,String password) { this.password = password; this.username = username; try{ connect(server,port,handlers); }catch (IOException e){e.printStackTrace();} } public void connect(String host, int port,Handlers handlers) throws IOException { if(port==5222)port=5223; JabberHandler jH = new JabberHandler(this,handlers); //Socket socket = new Socket(host,port); Socket socket = new DummySSLSocketFactory().createSocket(host,port); new Input(socket.getInputStream(),this,jH); output = new Output(socket,host,this,socket.getOutputStream()); server = host; } public void connected(String connectionID,String xmppVersion) { send(new InfoQuery(new JID(server),"get",new IQRegister())); } public void receivePackets(Packet packet) { if(registerId.equals(packet.getID())) { InfoQuery query = (InfoQuery) packet; if(query.getType().equals("result")) { registerWindow.login(); output.disconnect(true); } //maak mooi else registerWindow.error(packet.getErrorDescription()); } else if(packet instanceof InfoQuery) { IQExtension extension = packet.getIQExtension(); if(extension instanceof IQRegister) { new RegisterWindow(this,(IQRegister)extension,username,password).setVisible(true); } } } public void sendRegister(IQRegister register,RegisterWindow window) { registerWindow = window; registerId = "JetiRegister_"+ new java.util.Date().getTime(); send(new InfoQuery(null,"set",registerId,register)); } public void inputDeath() {//verbeter System.out.println("input death"); } public void outputDeath() {//verbeter System.out.println("input death"); } public void send(Packet packet) { output.send(packet); } } /* * Overrides for emacs * Local variables: * tab-width: 4 * End: */