Переглянути джерело

Add initial support for working with URIs.

Issue 2921.
tags/0.6.3
Chris Smith 14 роки тому
джерело
коміт
618e76f061

+ 16
- 3
src/com/dmdirc/parser/irc/IRCParser.java Переглянути файл

@@ -48,6 +48,7 @@ import java.net.InetAddress;
48 48
 import java.net.InetSocketAddress;
49 49
 import java.net.Proxy;
50 50
 import java.net.Socket;
51
+import java.net.URI;
51 52
 import java.net.UnknownHostException;
52 53
 import java.security.KeyManagementException;
53 54
 import java.security.NoSuchAlgorithmException;
@@ -269,12 +270,12 @@ public class IRCParser implements SecureParser, Runnable {
269 270
     private String bindIP = "";
270 271
     
271 272
     /** This is list containing 001 - 005 inclusive. */
272
-    private List<String> serverInformationLines = new LinkedList<String>();
273
+    private final List<String> serverInformationLines = new LinkedList<String>();
273 274
 
274 275
     /**
275 276
      * Default constructor, ServerInfo and MyInfo need to be added separately (using IRC.me and IRC.server).
276 277
      */
277
-    public IRCParser() { this(null, null); }
278
+    public IRCParser() { this((MyInfo) null); }
278 279
     /**
279 280
      * Constructor with ServerInfo, MyInfo needs to be added separately (using IRC.me).
280 281
      *
@@ -286,7 +287,7 @@ public class IRCParser implements SecureParser, Runnable {
286 287
      *
287 288
      * @param myDetails Client information.
288 289
      */
289
-    public IRCParser(final MyInfo myDetails) { this(myDetails, null); }
290
+    public IRCParser(final MyInfo myDetails) { this(myDetails, (ServerInfo) null); }
290 291
     /**
291 292
      * Constructor with ServerInfo and MyInfo.
292 293
      *
@@ -300,6 +301,18 @@ public class IRCParser implements SecureParser, Runnable {
300 301
         resetState();
301 302
     }
302 303
 
304
+    /**
305
+     * Creates a new IRCParser with the specified client details which will
306
+     * connect to the specified URI.
307
+     *
308
+     * @since 0.6.3m3
309
+     * @param myDetails The client details to use
310
+     * @param uri The URI to connect to
311
+     */
312
+    public IRCParser(final MyInfo myDetails, final URI uri) {
313
+        this(myDetails, new ServerInfo(uri));
314
+    }
315
+
303 316
     /**
304 317
      * Get the current OutputQueue
305 318
      *

+ 20
- 0
src/com/dmdirc/parser/irc/ServerInfo.java Переглянути файл

@@ -22,6 +22,8 @@
22 22
 
23 23
 package com.dmdirc.parser.irc;
24 24
 
25
+import java.net.URI;
26
+
25 27
 /**
26 28
  * Contains Server information.
27 29
  * 
@@ -71,6 +73,24 @@ public class ServerInfo {
71 73
         port = serverPort;
72 74
         password = serverPass;
73 75
     }
76
+
77
+    /**
78
+     * Creates a new ServerInfo which will represent the server described by
79
+     * the specified URI.
80
+     *
81
+     * @param uri The URI of the server
82
+     * @since 0.6.3m3
83
+     */
84
+    public ServerInfo(final URI uri) {
85
+        host = uri.getHost();
86
+        port = uri.getPort();
87
+
88
+        if ("ircs".equals(uri.getScheme())) {
89
+            setSSL(true);
90
+        }
91
+
92
+        // TODO (uris): Parse passwords
93
+    }
74 94
     
75 95
     /**
76 96
      * Set the hostname.

Завантаження…
Відмінити
Зберегти