2 * Copyright 2007 ZXing authors
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 namespace com.google.zxing.client.result
\r
20 /// <author> Sean Owen
\r
22 /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
\r
24 public sealed class URIParsedResult:ParsedResult
\r
26 public System.String URI
\r
34 public System.String Title
\r
42 /// <returns> true if the URI contains suspicious patterns that may suggest it intends to
\r
43 /// mislead the user about its true nature. At the moment this looks for the presence
\r
44 /// of user/password syntax in the host/authority portion of a URI which may be used
\r
45 /// in attempts to make the URI's host appear to be other than it is. Example:
\r
46 /// http://yourbank.com@phisher.com This URI connects to phisher.com but may appear
\r
47 /// to connect to yourbank.com at first glance.
\r
49 public bool PossiblyMaliciousURI
\r
53 return containsUser();
\r
57 override public System.String DisplayResult
\r
61 System.Text.StringBuilder result = new System.Text.StringBuilder(30);
\r
62 maybeAppend(title, result);
\r
63 maybeAppend(uri, result);
\r
64 return result.ToString();
\r
69 //UPGRADE_NOTE: Final was removed from the declaration of 'uri '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
70 private System.String uri;
\r
71 //UPGRADE_NOTE: Final was removed from the declaration of 'title '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
\r
72 private System.String title;
\r
74 public URIParsedResult(System.String uri, System.String title):base(ParsedResultType.URI)
\r
76 this.uri = massageURI(uri);
\r
80 private bool containsUser()
\r
82 // This method is likely not 100% RFC compliant yet
\r
83 int hostStart = uri.IndexOf(':'); // we should always have scheme at this point
\r
85 // Skip slashes preceding host
\r
86 int uriLength = uri.Length;
\r
87 while (hostStart < uriLength && uri[hostStart] == '/')
\r
91 //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
\r
92 int hostEnd = uri.IndexOf('/', hostStart);
\r
95 hostEnd = uriLength;
\r
97 //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
\r
98 int at = uri.IndexOf('@', hostStart);
\r
99 return at >= hostStart && at < hostEnd;
\r
102 /// <summary> Transforms a string that represents a URI into something more proper, by adding or canonicalizing
\r
105 private static System.String massageURI(System.String uri)
\r
107 int protocolEnd = uri.IndexOf(':');
\r
108 if (protocolEnd < 0)
\r
110 // No protocol, assume http
\r
111 uri = "http://" + uri;
\r
113 else if (isColonFollowedByPortNumber(uri, protocolEnd))
\r
115 // Found a colon, but it looks like it is after the host, so the protocol is still missing
\r
116 uri = "http://" + uri;
\r
120 // Lowercase protocol to avoid problems
\r
121 uri = uri.Substring(0, (protocolEnd) - (0)).ToLower() + uri.Substring(protocolEnd);
\r
126 private static bool isColonFollowedByPortNumber(System.String uri, int protocolEnd)
\r
128 //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
\r
129 int nextSlash = uri.IndexOf('/', protocolEnd + 1);
\r
132 nextSlash = uri.Length;
\r
134 if (nextSlash <= protocolEnd + 1)
\r
138 for (int x = protocolEnd + 1; x < nextSlash; x++)
\r
140 if (uri[x] < '0' || uri[x] > '9')
\r