source: branches/2.2/jabberit_messenger/java_source/src/nu/fw/jeti/backend/NewAccount.java @ 3102

Revision 3102, 3.2 KB checked in by amuller, 14 years ago (diff)

Ticket #986 - Efetuado merge para o Branch 2.2( atualizacao do modulo)

  • Property svn:executable set to *
Line 
1/*
2 *      Jeti, a Java Jabber client, Copyright (C) 2003 E.S. de Boer 
3 *
4 *  This program is free software; you can redistribute it and/or modify
5 *  it under the terms of the GNU General Public License as published by
6 *  the Free Software Foundation; either version 2 of the License, or
7 *  (at your option) any later version.
8 *
9 *  This program is distributed in the hope that it will be useful,
10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *      GNU General Public License for more details.
13 *
14 *  You should have received a copy of the GNU General Public License
15 *  along with this program; if not, write to the Free Software
16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 *
18 *      For questions, comments etc,
19 *      use the website at http://jeti.jabberstudio.org
20 *  or mail/im me at jeti@jabber.org
21 * 
22 *  created 2001
23 */
24
25package nu.fw.jeti.backend;
26
27import java.io.*;
28import java.net.*;
29
30import nu.fw.jeti.backend.Connect.DummySSLSocketFactory;
31import nu.fw.jeti.jabber.elements.*;
32import nu.fw.jeti.ui.RegisterWindow;
33
34import nu.fw.jeti.jabber.*;
35
36/**
37 * @author E.S. de Boer
38 *
39 */
40public class NewAccount implements ConnectionPacketReceiver
41{
42        private String server;
43        private String username;
44        private String password;
45        private Output output;
46        private String registerId="";
47        private RegisterWindow registerWindow;
48
49        public NewAccount(String server,int port,Handlers handlers,String username,String password)
50        {
51                this.password = password;
52                this.username = username;
53                try{
54                    connect(server,port,handlers);
55                }catch (IOException e){e.printStackTrace();}
56        }
57
58        public void connect(String host, int port,Handlers handlers) throws IOException
59        {
60                if(port==5222)port=5223;
61                JabberHandler jH = new JabberHandler(this,handlers);
62                //Socket socket = new Socket(host,port);
63                Socket socket = new DummySSLSocketFactory().createSocket(host,port);
64                new Input(socket.getInputStream(),this,jH);
65                output = new Output(socket,host,this,socket.getOutputStream());
66                server = host;
67        }
68
69        public void connected(String connectionID,String xmppVersion)
70        {
71                send(new InfoQuery(new JID(server),"get",new IQRegister()));
72        }
73
74        public void receivePackets(Packet packet)
75        {
76                if(registerId.equals(packet.getID()))
77                {
78                        InfoQuery query = (InfoQuery) packet;
79                        if(query.getType().equals("result"))
80                        {
81                            registerWindow.login();
82                                output.disconnect(true);
83                        }
84                        //maak mooi
85                        else registerWindow.error(packet.getErrorDescription());
86                }
87                else if(packet instanceof InfoQuery)
88                {
89                    IQExtension extension = packet.getIQExtension();
90                        if(extension instanceof IQRegister)
91                        {
92                                new RegisterWindow(this,(IQRegister)extension,username,password).setVisible(true);
93                        }
94
95                }
96        }
97
98        public void sendRegister(IQRegister register,RegisterWindow window)
99        {
100                registerWindow = window;
101                registerId = "JetiRegister_"+ new java.util.Date().getTime();
102                send(new InfoQuery(null,"set",registerId,register));
103        }
104
105
106        public void inputDeath()
107        {//verbeter
108                System.out.println("input death");
109        }
110
111        public void outputDeath()
112        {//verbeter
113                System.out.println("input death");
114        }
115
116        public void send(Packet packet)
117        {
118                output.send(packet);
119        }
120}
121/*
122 * Overrides for emacs
123 * Local variables:
124 * tab-width: 4
125 * End:
126 */
Note: See TracBrowser for help on using the repository browser.