Luke Pulverenti 7 lat temu
rodzic
commit
808f2f3095
3 zmienionych plików z 21 dodań i 6 usunięć
  1. 6 3
      RSSDP/HttpRequestParser.cs
  2. 7 3
      RSSDP/HttpResponseParser.cs
  3. 8 0
      RSSDP/SsdpDevice.cs

+ 6 - 3
RSSDP/HttpRequestParser.cs

@@ -64,7 +64,7 @@ namespace Rssdp.Infrastructure
 			if (message == null) throw new ArgumentNullException("message");
 
 			var parts = data.Split(' ');
-			if (parts.Length < 3) throw new ArgumentException("Status line is invalid. Insufficient status parts.", "data");
+			if (parts.Length < 2) throw new ArgumentException("Status line is invalid. Insufficient status parts.", "data");
 
 			message.Method = new HttpMethod(parts[0].Trim());
 			Uri requestUri;
@@ -73,8 +73,11 @@ namespace Rssdp.Infrastructure
 			else
 				System.Diagnostics.Debug.WriteLine(parts[1]);
 
-			message.Version = ParseHttpVersion(parts[2].Trim());
-		}
+            if (parts.Length >= 3)
+            {
+                message.Version = ParseHttpVersion(parts[2].Trim());
+            }
+        }
 
 		/// <summary>
 		/// Returns a boolean indicating whether the specified HTTP header name represents a content header (true), or a message header (false).

+ 7 - 3
RSSDP/HttpResponseParser.cs

@@ -75,7 +75,7 @@ namespace Rssdp.Infrastructure
 			if (message == null) throw new ArgumentNullException("message");
 
 			var parts = data.Split(' ');
-			if (parts.Length < 3) throw new ArgumentException("data status line is invalid. Insufficient status parts.", "data");
+			if (parts.Length < 2) throw new ArgumentException("data status line is invalid. Insufficient status parts.", "data");
 
 			message.Version = ParseHttpVersion(parts[0].Trim());
 
@@ -84,8 +84,12 @@ namespace Rssdp.Infrastructure
 				throw new ArgumentException("data status line is invalid. Status code is not a valid integer.", "data");
 
 			message.StatusCode = (HttpStatusCode)statusCode;
-			message.ReasonPhrase = parts[2].Trim();
-		}
+
+            if (parts.Length >= 3)
+            {
+                message.ReasonPhrase = parts[2].Trim();
+            }
+        }
 
 		#endregion
 

+ 8 - 0
RSSDP/SsdpDevice.cs

@@ -743,6 +743,14 @@ namespace Rssdp
 
         private static void AddCustomProperty(XmlReader reader, SsdpDevice device)
         {
+            // If the property is an empty element, there is no value to read
+            // Advance the reader and return
+            if (reader.IsEmptyElement)
+            {
+                reader.Read();
+                return;
+            }
+
             var newProp = new SsdpDeviceProperty() { Namespace = reader.Prefix, Name = reader.LocalName };
             int depth = reader.Depth;
             reader.Read();