5 // Garrett Rooney (rooneg@electricjellyfish.net)
7 // (C) 2001 Garrett Rooney
10 using System.Runtime.Serialization;
14 public class Uri : MarshalByRefObject, ISerializable {
16 private string path = "";
17 private string host = "";
18 private string fragment = "";
19 private string scheme = "";
20 private string port = "";
21 private string query = "";
23 // FIXME: is this correct?
24 private bool userEscaped = false;
26 public static readonly string SchemeDelimiter = "://";
27 public static readonly string UriSchemeFile = "file";
28 public static readonly string UriSchemeFtp = "ftp";
29 public static readonly string UriSchemeGopher = "gopher";
30 public static readonly string UriSchemeHttp = "http";
31 public static readonly string UriSchemeHttps = "https";
32 public static readonly string UriSchemeMailto = "mailto";
33 public static readonly string UriSchemeNntp = "nntp";
35 // the details table holds random info about the types of uri's
36 private struct detail {
39 public string delimiter;
41 public detail(string s, string p, string d) {
48 static detail[] details = new detail[] {
49 new detail(UriSchemeFile, "-1", SchemeDelimiter),
50 new detail(UriSchemeFtp, "23", SchemeDelimiter),
51 new detail(UriSchemeGopher, "70", SchemeDelimiter),
52 new detail(UriSchemeHttp, "80", SchemeDelimiter),
53 new detail(UriSchemeHttps, "223", SchemeDelimiter),
54 new detail(UriSchemeMailto, "25", ":"),
55 new detail(UriSchemeNntp, "119", SchemeDelimiter)
58 public static UriHostNameType CheckHostName(string name) {
59 throw new NotImplementedException();
62 public static bool CheckSchemeName(string schemeName) {
63 throw new NotImplementedException();
66 public static int FromHex(char digit) {
67 throw new NotImplementedException();
70 public static string HexEscape(char character) {
71 throw new NotImplementedException();
74 public static char HexUnescape(string pattern, ref int index) {
75 throw new NotImplementedException();
78 public static bool IsHexDigit(char character) {
79 throw new NotImplementedException();
82 public static bool IsHexEncoding(string pattern, int index) {
83 throw new NotImplementedException();
86 private void Parse(string uri) {
89 // figure out the scheme
90 int colon = uri.IndexOf(':');
91 if (colon == -1 || colon == uri.Length) {
92 throw new UriFormatException();
94 string s = uri.Substring(0, colon).ToLower();
95 uri = uri.Remove(0, colon);
96 for (i = 0; i < details.Length; i++) {
97 if (details[i].scheme == s) {
98 scheme = details[i].scheme;
100 // assume default port. if
101 // they specify one it'll get
103 port = details[i].port;
107 if (i == details.Length) {
108 throw new UriFormatException();
112 // get rid of the delimiter
113 uri = uri.Remove(0, details[i].delimiter.Length);
118 private void parseHost(string uri) {
120 // FIXME: this doesn't handle IPv6 addresses correctly
121 for (int i = 0; i < uri.Length; i++) {
124 host = uri.Substring(0, i);
125 parsePort(uri.Remove(0, i + 1));
128 host = uri.Substring(0, i);
129 parsePath(uri.Remove(0, i + 1));
133 throw new UriFormatException();
142 private void parsePort(string uri) {
144 for (int i = 0; i < uri.Length; i++) {
147 port = uri.Substring(0, i);
148 parsePath(uri.Remove(0, i + 1));
152 throw new UriFormatException();
154 // FIXME: should this check if
155 // uri[i] is a number?
163 private void parsePath(string uri) {
165 for (int i = 0; i < uri.Length; i++) {
168 path = uri.Substring(0, i);
169 fragment = uri.Remove(0, i + 1);
172 path = uri.Substring(0, i);
173 query = uri.Remove(0, i + 1);
183 public Uri(string uri) {
187 protected Uri(SerializationInfo serializationInfo,
188 StreamingContext streamingContext) {
189 throw new NotImplementedException();
192 public Uri(string uri, bool dontEscape) {
193 userEscaped = dontEscape;
197 public Uri(Uri baseUri, string relativeUri) {
198 throw new NotImplementedException();
201 public Uri(Uri baseUri, string relativeUri, bool dontEscape) {
202 userEscaped = dontEscape;
204 throw new NotImplementedException();
207 public string AbsolutePath { get { return path; } }
209 public string AbsoluteUri {
210 get { throw new NotImplementedException(); }
213 public string Authority { get { return host + ":" + port; } }
215 public string Fragment { get { return fragment; } }
217 public string Host { get { return host; } }
219 public UriHostNameType HostNameType {
220 get { throw new NotImplementedException(); }
223 public bool IsDefaultPort {
225 for (int i = 0; i < details.Length; i++) {
226 if (details[i].scheme == scheme) {
227 if (details[i].port == port) {
239 if (scheme == UriSchemeFile)
246 // FIXME: should check IPv6
247 public bool IsLoopback {
249 if (host == "localhost" || host == "127.0.0.1")
257 get { throw new NotImplementedException(); }
260 public string LocalPath {
261 get { throw new NotImplementedException(); }
264 public string PathAndQuery {
265 get { return path + "?" + query; }
268 public string Port { get { return port; } }
270 public string Query { get { return query; } }
272 public string Scheme { get { return scheme; } }
274 // FIXME: what the hell are segments?
275 public string[] Segments {
276 get { throw new NotImplementedException(); }
279 public bool UserEscaped { get { return userEscaped; } }
281 public string UserInfo {
282 get { throw new NotImplementedException(); }
285 public override bool Equals(object compared) {
286 throw new NotImplementedException();
289 public override int GetHashCode() {
290 throw new NotImplementedException();
293 public string GetLeftPart(UriPartial part) {
294 throw new NotImplementedException();
297 public string MakeRelative(Uri toUri) {
298 throw new NotImplementedException();
301 public override string ToString() {
302 throw new NotImplementedException();
305 public void GetObjectData(SerializationInfo info,
306 StreamingContext context)
308 // FIXME: Implement me. yes, it is public because it implements ISerializable
311 protected static string EscapeString(string str) {
312 throw new NotImplementedException();