Browse Source

Add initial support for working with URIs.

Issue 2921.
tags/0.6.3
Chris Smith 14 years ago
parent
commit
618e76f061

+ 16
- 3
src/com/dmdirc/parser/irc/IRCParser.java View File

48
 import java.net.InetSocketAddress;
48
 import java.net.InetSocketAddress;
49
 import java.net.Proxy;
49
 import java.net.Proxy;
50
 import java.net.Socket;
50
 import java.net.Socket;
51
+import java.net.URI;
51
 import java.net.UnknownHostException;
52
 import java.net.UnknownHostException;
52
 import java.security.KeyManagementException;
53
 import java.security.KeyManagementException;
53
 import java.security.NoSuchAlgorithmException;
54
 import java.security.NoSuchAlgorithmException;
269
     private String bindIP = "";
270
     private String bindIP = "";
270
     
271
     
271
     /** This is list containing 001 - 005 inclusive. */
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
      * Default constructor, ServerInfo and MyInfo need to be added separately (using IRC.me and IRC.server).
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
      * Constructor with ServerInfo, MyInfo needs to be added separately (using IRC.me).
280
      * Constructor with ServerInfo, MyInfo needs to be added separately (using IRC.me).
280
      *
281
      *
286
      *
287
      *
287
      * @param myDetails Client information.
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
      * Constructor with ServerInfo and MyInfo.
292
      * Constructor with ServerInfo and MyInfo.
292
      *
293
      *
300
         resetState();
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
      * Get the current OutputQueue
317
      * Get the current OutputQueue
305
      *
318
      *

+ 20
- 0
src/com/dmdirc/parser/irc/ServerInfo.java View File

22
 
22
 
23
 package com.dmdirc.parser.irc;
23
 package com.dmdirc.parser.irc;
24
 
24
 
25
+import java.net.URI;
26
+
25
 /**
27
 /**
26
  * Contains Server information.
28
  * Contains Server information.
27
  * 
29
  * 
71
         port = serverPort;
73
         port = serverPort;
72
         password = serverPass;
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
      * Set the hostname.
96
      * Set the hostname.

Loading…
Cancel
Save