source: trunk/jabberit_messenger/java_source/src/nu/fw/jeti/backend/LoginInfo.java @ 1001

Revision 1001, 5.8 KB checked in by alexandrecorreia, 15 years ago (diff)

Ticket #552 - Inclusão do projeto Java referente ao applet do módulo.

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 me at eric@jeti.tk
21 */
22
23package nu.fw.jeti.backend;
24
25import java.net.ProxySelector;
26import java.net.URL;
27
28import com.sun.java.browser.net.ProxyInfo;
29import com.sun.java.browser.net.ProxyService;
30
31import nu.fw.jeti.util.Utils;
32
33/**
34 * @author E.S. de Boer
35 */
36
37public class LoginInfo
38{
39        public final static int NO_PROXY=0;
40        public final static int SOCKS_PROXY=1;
41        public final static int HTTP_PROXY=2;
42        public final static int HTTP_BIND=3;
43               
44        private String server;
45    private String host;
46        private int port;
47        private String username;
48        private String resource;
49        private String password;
50        private boolean useJavaProxy=true;
51        private boolean ssl=false;
52        private int proxyType=NO_PROXY;
53        private String proxyServer;
54        private String proxyPort;
55        private String proxyUsername;
56        private String proxyPassword;  //encrypt?
57        private int priority;
58
59        //applet
60    public LoginInfo(String server, String host, String username,
61                     String password, String resource,int port,boolean ssl,int priority)
62    {
63        if( username != null && username.indexOf("@") !=-1 )
64        {
65                this.host = server;
66                int atPos = username.indexOf('@');
67                this.username = username.substring(0,atPos);
68                this.server = username.substring(atPos+1,username.length());
69        }
70        else
71        {
72                this.server = server;
73            this.host = host;
74                this.username = username;
75        }
76
77        this.ssl = ssl;
78                this.password = password;
79                if(password != null && password.equals("")) this.password =null;
80                this.resource = resource;
81                if(resource != null && resource.equals("")) this.resource ="Jeti";
82                this.port = port;
83                if(port==0)port=5222;
84                this.priority = priority;
85    }
86
87        public LoginInfo(String server, String host, String username,
88            String password, String resource,int port, boolean ssl,int priority,
89            boolean useProxy)
90        {
91                 this(server,host,username,password,resource,port,ssl,priority);
92                 this.useJavaProxy = useProxy;
93        }
94
95        public LoginInfo(String server, String host, String username,
96                     String password, String resource,int port, boolean ssl,int priority,
97                     int proxy, String proxyServer, String proxyUsername,
98                     String proxyPassword, String proxyPort)
99    {
100        this(server,host,username,password,resource,port,ssl,priority);
101                this.proxyType = proxy;
102                this.proxyServer = proxyServer;
103                this.proxyPort = proxyPort;
104                this.proxyUsername = proxyUsername ;
105                this.proxyPassword = proxyPassword;
106    }
107
108        /**
109         * Returns the port.
110         * @return String
111         */
112        public int getPort()
113        {
114                return port;
115        }
116
117        /**
118         * Returns the resource.
119         * @return String
120         */
121        public String getResource()
122        {
123                return resource;
124        }
125
126        /**
127         * Returns the server.
128         * @return String
129         */
130        public String getServer()
131        {
132                return server;
133        }
134
135        /**
136     * Returns the host to connect to.
137     * @return String
138     */
139    public String getHost()
140    {
141        return host;
142    }
143
144    /**
145     * Returns the useJavaProxy.
146     * @return boolean
147     */
148    public boolean getJavaProxy()
149    {
150        return useJavaProxy;
151    }
152   
153    /**
154         * Returns the ssl.
155         * @return boolean
156         */
157        public boolean isSSl() {
158                return ssl;
159        }
160       
161        public int getPriority()
162        {
163                return priority;
164        }
165
166        /**
167         * Returns the username.
168         * @return String
169         */
170        public String getUsername() {
171                return username;
172        }
173
174        /**
175         * Returns the password.
176         * @return String
177         */
178        public String getPassword()
179        {
180                return password;
181        }
182
183        /**
184         * Sets the password.
185         * @param password The password to set
186         */
187        public void setPassword(String password)
188        {
189                this.password = password;
190        }
191
192        /**
193         * Returns the proxyPassword.
194         * @return String
195         */
196        public String getProxyPassword()
197        {
198                return proxyPassword;
199        }
200
201        /**
202         * Returns the proxyPort.
203         * @return int
204         */
205        public String getProxyPort()
206        {
207                return proxyPort;
208        }
209
210        /**
211         * Returns the proxyServer.
212         * @return String
213         */
214        public String getProxyServer()
215        {
216                return proxyServer;
217        }
218
219        /**
220         * Returns the proxyUsername.
221         * @return String
222         */
223        public String getProxyUsername()
224        {
225                return proxyUsername;
226        }
227       
228        /**
229         * returns the type of proxy used
230         * @return proxy type
231         */
232        public int getProxyType()
233        {
234                return proxyType;
235        }
236
237        /**
238         * returns the used proxy
239         * @param proxy the proxy type to test
240         * @return true if the proxy is used
241         */
242        public boolean useProxy(int proxy)
243        {
244                return proxyType == proxy;
245        }
246       
247        public boolean isHTTPProxy()
248        {
249                if( useProxy(LoginInfo.HTTP_PROXY) )
250                        return true;
251
252                if( Start.applet )
253                {
254                        try
255                        {
256                                ProxyInfo info[] = ProxyService.getProxyInfo(new URL("http://www.google.com.br"));
257                               
258                                if (info != null && info.length > 0 )
259                                {
260                                        proxyType = HTTP_PROXY;
261                                        proxyServer = info[0].getHost();
262                                        proxyPort = String.valueOf(info[0].getPort());
263                                        return true;
264                                }
265
266                        }
267                        catch (Exception ex)
268                        {
269                                System.err.println("could not retrieve proxy configuration, attempting direct connection.");
270                        }
271                }
272                return false;
273        }
274
275}
276/*
277 * Overrides for emacs
278 * Local variables:
279 * tab-width: 4
280 * End:
281 */
Note: See TracBrowser for help on using the repository browser.