diff --git a/Example/Example.pidb b/Example/Example.pidb index 4fb45023..e7223650 100644 Binary files a/Example/Example.pidb and b/Example/Example.pidb differ diff --git a/Example/Program.cs b/Example/Program.cs index 0d82b8b9..418b99ef 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -111,7 +111,7 @@ namespace Example "notification-message-im"); }; - //ws.SetCookie(new Cookie("nobita", "idiot")); + //ws.SetCookie(new Cookie("nobita", "\"idiot, gunfighter\"")); //ws.SetCookie(new Cookie("dora", "tanuki")); ws.Connect(); diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index 60976ef5..42dbe898 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/example.exe.mdb b/Example/bin/Debug_Ubuntu/example.exe.mdb index fb55a479..337ab055 100644 Binary files a/Example/bin/Debug_Ubuntu/example.exe.mdb and b/Example/bin/Debug_Ubuntu/example.exe.mdb differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index 9347d87b..0e30c581 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 169caa6b..456b2c4f 100644 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index 1539fe27..a124fbb9 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe.mdb b/Example1/bin/Debug_Ubuntu/example1.exe.mdb index d6be9cec..d9eed770 100644 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe.mdb and b/Example1/bin/Debug_Ubuntu/example1.exe.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index 9347d87b..0e30c581 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 169caa6b..456b2c4f 100644 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 3c59e210..6d06d3e9 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe.mdb b/Example2/bin/Debug_Ubuntu/example2.exe.mdb index 60515c93..23e84267 100644 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe.mdb and b/Example2/bin/Debug_Ubuntu/example2.exe.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index 9347d87b..0e30c581 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 169caa6b..456b2c4f 100644 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index 7b0dbb14..8afa802c 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb index d7fb78ea..e07de90c 100644 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb and b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index 9347d87b..0e30c581 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 169caa6b..456b2c4f 100644 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/Net/Cookie.cs b/websocket-sharp/Net/Cookie.cs index ab2cb561..2cb7ab8f 100644 --- a/websocket-sharp/Net/Cookie.cs +++ b/websocket-sharp/Net/Cookie.cs @@ -40,18 +40,21 @@ using System.Collections; namespace WebSocketSharp.Net { /// - /// Provides a set of properties and methods to use to manage the HTTP Cookie. + /// Provides a set of properties and methods used to manage an HTTP Cookie. /// /// - /// The Cookie class cannot be inherited. + /// + /// The Cookie class supports the following cookie formats: + /// Netscape specification, + /// RFC 2109 and + /// RFC 2965. + /// + /// + /// The Cookie class cannot be inherited. + /// /// [Serializable] - public sealed class Cookie - { - // Supported cookie formats are: - // Netscape: http://home.netscape.com/newsref/std/cookie_spec.html - // RFC 2109: http://www.ietf.org/rfc/rfc2109.txt - // RFC 2965: http://www.ietf.org/rfc/rfc2965.txt + public sealed class Cookie { #region Static Private Fields @@ -79,7 +82,7 @@ namespace WebSocketSharp.Net { #endregion - #region Constructors + #region Public Constructors /// /// Initializes a new instance of the class. @@ -135,15 +138,8 @@ namespace WebSocketSharp.Net { public Cookie (string name, string value) : this () { - string msg; - if (!CanSetName (name, out msg)) - throw new CookieException (msg); - - if (!CanSetValue (value, out msg)) - throw new CookieException (msg); - - this.name = name; - this.val = value; + Name = name; + Value = value; } /// @@ -465,23 +461,28 @@ namespace WebSocketSharp.Net { /// /// A that contains the Value of the cookie. /// + /// + /// + /// The value specified for a set operation is . + /// + /// + /// - or - + /// + /// + /// The value specified for a set operation contains a string not enclosed in double quotes + /// that contains an invalid character. + /// + /// public string Value { get { return val; } - set { - if (value == null) { - val = String.Empty; - return; - } - - // LAMESPEC: According to .Net specs the Value property should not accept - // the semicolon and comma characters, yet it does. For now we'll follow - // the behaviour of MS.Net instead of the specs. - /* - if (value.IndexOfAny(reservedCharsForValue) != -1) - throw new CookieException("Invalid value. Value cannot contain semicolon or comma characters."); - */ + set { + string msg; + if (!CanSetValue (value, out msg)) + throw new CookieException (msg); - val = value; + val = value.IsEmpty () + ? "\"\"" + : value; } } @@ -512,7 +513,7 @@ namespace WebSocketSharp.Net { static bool CanSetName (string name, out string message) { if (name.IsNullOrEmpty ()) { - message = "Name can not be null or empty."; + message = "Name must not be null or empty."; return false; } @@ -528,7 +529,7 @@ namespace WebSocketSharp.Net { static bool CanSetValue (string value, out string message) { if (value.IsNull ()) { - message = "Value can not be null."; + message = "Value must not be null."; return false; } @@ -548,7 +549,7 @@ namespace WebSocketSharp.Net { return i ^ (j << 13 | j >> 19) ^ (k << 26 | k >> 6) ^ (l << 7 | l >> 25) ^ (m << 20 | m >> 12); } - // See par 3.6 of RFC 2616 + // See para 3.6 of RFC 2616 string Quote (string value) { if (version == 0 || value.IsToken ()) @@ -559,7 +560,7 @@ namespace WebSocketSharp.Net { string ToResponseStringVersion0 () { - var result = new StringBuilder (); + var result = new StringBuilder (64); result.AppendFormat ("{0}={1}", name, val); if (expires != DateTime.MinValue) result.AppendFormat ("; Expires={0}", @@ -583,7 +584,7 @@ namespace WebSocketSharp.Net { string ToResponseStringVersion1 () { - var result = new StringBuilder (); + var result = new StringBuilder (64); result.AppendFormat ("{0}={1}; Version={2}", name, val, version); if (expires != DateTime.MinValue) result.AppendFormat ("; Max-Age={0}", MaxAge); @@ -595,7 +596,10 @@ namespace WebSocketSharp.Net { result.AppendFormat ("; Domain={0}", domain); if (!port.IsNullOrEmpty ()) - result.AppendFormat ("; Port={0}", port); + if (port == "\"\"") + result.Append ("; Port"); + else + result.AppendFormat ("; Port={0}", port); if (!comment.IsNullOrEmpty ()) result.AppendFormat ("; Comment={0}", comment.UrlEncode ()); @@ -647,7 +651,7 @@ namespace WebSocketSharp.Net { if (version == 0) return String.Format ("{0}={1}", name, val); - var result = new StringBuilder (); + var result = new StringBuilder (64); result.AppendFormat ("$Version={0}; {1}={2}", version, name, val); if (!path.IsNullOrEmpty ()) result.AppendFormat ("; $Path={0}", path); @@ -661,7 +665,10 @@ namespace WebSocketSharp.Net { result.AppendFormat ("; $Domain={0}", domain); if (!port.IsNullOrEmpty ()) - result.AppendFormat ("; $Port={0}", port); + if (port == "\"\"") + result.Append ("; $Port"); + else + result.AppendFormat ("; $Port={0}", port); return result.ToString (); } diff --git a/websocket-sharp/Net/CookieCollection.cs b/websocket-sharp/Net/CookieCollection.cs index b3477907..3e7a5645 100644 --- a/websocket-sharp/Net/CookieCollection.cs +++ b/websocket-sharp/Net/CookieCollection.cs @@ -62,20 +62,20 @@ namespace WebSocketSharp.Net { } } - #region Static Field + #region Private Static Fields static CookieCollectionComparer Comparer = new CookieCollectionComparer (); #endregion - #region Field + #region Private Fields List list; object sync; #endregion - #region Constructor + #region Public Constructors /// /// Initializes a new instance of the class. @@ -87,7 +87,7 @@ namespace WebSocketSharp.Net { #endregion - #region Internal Property + #region Internal Properties internal IList List { get { return list; } @@ -182,7 +182,7 @@ namespace WebSocketSharp.Net { if (name.IsNull ()) throw new ArgumentNullException ("name"); - foreach (var cookie in list) { + foreach (var cookie in Sorted) { if (cookie.Name.Equals (name, StringComparison.InvariantCultureIgnoreCase)) return cookie; } @@ -208,7 +208,7 @@ namespace WebSocketSharp.Net { #endregion - #region Private Method + #region Private Methods static CookieCollection ParseRequest (string value) { @@ -216,9 +216,8 @@ namespace WebSocketSharp.Net { Cookie cookie = null; int version = 0; - string [] pairs = value.Split (',', ';'); - for (int i = 0; i < pairs.Length; i++) - { + string [] pairs = Split(value).ToArray(); + for (int i = 0; i < pairs.Length; i++) { string pair = pairs [i].Trim (); if (pair.IsEmpty ()) continue; @@ -235,27 +234,32 @@ namespace WebSocketSharp.Net { cookie.Domain = pair.GetValueInternal ("="); } else if (pair.StartsWith ("$port", StringComparison.InvariantCultureIgnoreCase)) { - if (!pair.Equals ("$port", StringComparison.InvariantCultureIgnoreCase) && !pair.EndsWith ("\"")) { - var buffer = new StringBuilder (pair); - string port; - while (i < pairs.Length - 1) { - port = pairs [++i].Trim (); - buffer.AppendFormat (", {0}", port); - if (port.EndsWith ("\"")) - break; - } - - pair = buffer.ToString (); - } + var port = pair.Equals ("$port", StringComparison.InvariantCultureIgnoreCase) + ? "\"\"" + : pair.GetValueInternal ("="); if (!cookie.IsNull ()) - cookie.Port = pair.GetValueInternal ("="); + cookie.Port = port; } else { if (!cookie.IsNull ()) cookies.Add (cookie); - cookie = new Cookie (pair.GetNameInternal ("="), pair.GetValueInternal ("=")); + string name; + string val = String.Empty; + int pos = pair.IndexOf ('='); + if (pos == -1) { + name = pair; + } + else if (pos == pair.Length - 1) { + name = pair.Substring (0, pos).TrimEnd (' '); + } + else { + name = pair.Substring (0, pos).TrimEnd (' '); + val = pair.Substring (pos + 1).TrimStart (' '); + } + + cookie = new Cookie (name, val); if (version != 0) cookie.Version = version; } @@ -272,9 +276,8 @@ namespace WebSocketSharp.Net { var cookies = new CookieCollection (); Cookie cookie = null; - string [] pairs = value.Split (',', ';'); - for (int i = 0; i < pairs.Length; i++) - { + string [] pairs = Split(value).ToArray(); + for (int i = 0; i < pairs.Length; i++) { string pair = pairs [i].Trim (); if (pair.IsEmpty ()) continue; @@ -284,7 +287,7 @@ namespace WebSocketSharp.Net { cookie.Version = Int32.Parse (pair.GetValueInternal ("=").Trim ('"')); } else if (pair.StartsWith ("expires", StringComparison.InvariantCultureIgnoreCase)) { - var buffer = new StringBuilder (pair.GetValueInternal ("=")); + var buffer = new StringBuilder (pair.GetValueInternal ("="), 32); if (i < pairs.Length - 1) buffer.AppendFormat (", {0}", pairs [++i].Trim ()); @@ -314,21 +317,12 @@ namespace WebSocketSharp.Net { cookie.Domain = pair.GetValueInternal ("="); } else if (pair.StartsWith ("port", StringComparison.InvariantCultureIgnoreCase)) { - if (!pair.Equals ("port", StringComparison.InvariantCultureIgnoreCase) && !pair.EndsWith ("\"")) { - var buffer = new StringBuilder (pair); - string port; - while (i < pairs.Length - 1) { - port = pairs [++i].Trim (); - buffer.AppendFormat (", {0}", port); - if (port.EndsWith ("\"")) - break; - } - - pair = buffer.ToString (); - } + var port = pair.Equals ("port", StringComparison.InvariantCultureIgnoreCase) + ? "\"\"" + : pair.GetValueInternal ("="); if (!cookie.IsNull ()) - cookie.Port = pair.GetValueInternal ("="); + cookie.Port = port; } else if (pair.StartsWith ("comment", StringComparison.InvariantCultureIgnoreCase)) { if (!cookie.IsNull ()) @@ -354,7 +348,21 @@ namespace WebSocketSharp.Net { if (!cookie.IsNull ()) cookies.Add (cookie); - cookie = new Cookie (pair.GetNameInternal ("="), pair.GetValueInternal ("=")); + string name; + string val = String.Empty; + int pos = pair.IndexOf ('='); + if (pos == -1) { + name = pair; + } + else if (pos == pair.Length - 1) { + name = pair.Substring (0, pos).TrimEnd (' '); + } + else { + name = pair.Substring (0, pos).TrimEnd (' '); + val = pair.Substring (pos + 1).TrimStart (' '); + } + + cookie = new Cookie (name, val); } } @@ -391,9 +399,33 @@ namespace WebSocketSharp.Net { return -1; } + static IEnumerable Split (string value) + { + var buffer = new StringBuilder (64); + bool quoted = false; + foreach (char c in value) { + if (c == '"') { + quoted = !quoted; + } + else if (c == ',' || c == ';') { + if (!quoted) { + yield return buffer.ToString (); + buffer.Length = 0; + continue; + } + } + else { + } + + buffer.Append (c); + } + + yield return buffer.ToString (); + } + #endregion - #region Internal Method + #region Internal Methods internal static CookieCollection Parse (string value, bool response) { diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 9347d87b..0e30c581 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 169caa6b..456b2c4f 100644 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll index 382ec27b..d4bdc4ea 100755 Binary files a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml index 4ebb5c09..ce684b8d 100644 --- a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml +++ b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.xml @@ -1574,10 +1574,18 @@ - Provides a set of properties and methods to use to manage the HTTP Cookie. + Provides a set of properties and methods used to manage an HTTP Cookie. + + The Cookie class supports the following cookie formats: + Netscape specification, + RFC 2109 and + RFC 2965. + + The Cookie class cannot be inherited. + @@ -1830,6 +1838,18 @@ A that contains the Value of the cookie. + + + The value specified for a set operation is . + + + - or - + + + The value specified for a set operation contains a string not enclosed in double quotes + that contains an invalid character. + + diff --git a/websocket-sharp/doc/html/WebSocketSharp.Net/Cookie.html b/websocket-sharp/doc/html/WebSocketSharp.Net/Cookie.html index bcdcbb35..a8d6912a 100644 --- a/websocket-sharp/doc/html/WebSocketSharp.Net/Cookie.html +++ b/websocket-sharp/doc/html/WebSocketSharp.Net/Cookie.html @@ -207,7 +207,7 @@

Cookie Class

- Provides a set of properties and methods to use to manage the HTTP Cookie. + Provides a set of properties and methods used to manage an HTTP Cookie.

Syntax

@@ -216,8 +216,16 @@

Remarks

+

+ The Cookie class supports the following cookie formats: + Netscape specification, + RFC 2109 and + RFC 2965. +

+

The Cookie class cannot be inherited. -

+

+

Requirements

Namespace: WebSocketSharp.Net
Assembly: websocket-sharp (in websocket-sharp.dll)
@@ -1239,6 +1247,32 @@
A string that contains the Value of the cookie.
+

Exceptions

+
+ + + + + + + + + +
TypeReason
+ WebSocketSharp.Net.CookieException + +

+ The value specified for a set operation is null. +

+

+ - or - +

+

+ The value specified for a set operation contains a string not enclosed in double quotes + that contains an invalid character. +

+
+

Remarks

Documentation for this section has not yet been entered. diff --git a/websocket-sharp/doc/html/WebSocketSharp.Net/index.html b/websocket-sharp/doc/html/WebSocketSharp.Net/index.html index 65c03d8e..4c7b2d29 100644 --- a/websocket-sharp/doc/html/WebSocketSharp.Net/index.html +++ b/websocket-sharp/doc/html/WebSocketSharp.Net/index.html @@ -223,7 +223,7 @@ Cookie - Provides a set of properties and methods to use to manage the HTTP Cookie. + Provides a set of properties and methods used to manage an HTTP Cookie. diff --git a/websocket-sharp/doc/html/index.html b/websocket-sharp/doc/html/index.html index b19790e9..996bd8c4 100644 --- a/websocket-sharp/doc/html/index.html +++ b/websocket-sharp/doc/html/index.html @@ -315,7 +315,7 @@ Cookie - Provides a set of properties and methods to use to manage the HTTP Cookie. + Provides a set of properties and methods used to manage an HTTP Cookie. diff --git a/websocket-sharp/doc/mdoc/WebSocketSharp.Net/Cookie.xml b/websocket-sharp/doc/mdoc/WebSocketSharp.Net/Cookie.xml index 6e8a17c1..8f877881 100644 --- a/websocket-sharp/doc/mdoc/WebSocketSharp.Net/Cookie.xml +++ b/websocket-sharp/doc/mdoc/WebSocketSharp.Net/Cookie.xml @@ -10,11 +10,19 @@ - Provides a set of properties and methods to use to manage the HTTP Cookie. + Provides a set of properties and methods used to manage an HTTP Cookie. + + The Cookie class supports the following cookie formats: + Netscape specification, + RFC 2109 and + RFC 2965. + + The Cookie class cannot be inherited. - + + @@ -484,6 +492,18 @@ A that contains the Value of the cookie. To be added. + + + The value specified for a set operation is . + + + - or - + + + The value specified for a set operation contains a string not enclosed in double quotes + that contains an invalid character. + + diff --git a/websocket-sharp/doc/mdoc/index.xml b/websocket-sharp/doc/mdoc/index.xml index fee68d67..8f384164 100644 --- a/websocket-sharp/doc/mdoc/index.xml +++ b/websocket-sharp/doc/mdoc/index.xml @@ -1,6 +1,6 @@ - + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 11 00 00 00 29 17 fb 89 fe c3 91 f7 2b cb 8b e2 61 d2 3f 05 93 6d 65 a8 9e 63 72 a6 f5 d5 2c f2 9d 20 fa 0b c0 70 6a f6 88 7e 8b 90 3f 39 f5 76 c8 48 e0 bb 7b b2 7b ed d3 10 a7 1a 0f 70 98 0f 7f f4 4b 53 09 d2 a5 ef 36 c3 56 b4 aa f0 91 72 63 25 07 89 e0 93 3e 3f 2e f2 b9 73 0e 12 15 5d 43 56 c3 f4 70 a5 89 fe f7 f6 ac 3e 77 c2 d8 d0 84 91 f4 0c d1 f3 8e dc c3 c3 b8 38 3d 0c bf 17 de 20 78 c1 ] diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index e986d6b8..a8f1dc6f 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ