aboutsummaryrefslogtreecommitdiff
path: root/RSSDP
diff options
context:
space:
mode:
authortelans <telans@protonmail.com>2020-06-20 21:12:36 +1200
committertelans <telans@protonmail.com>2020-06-20 21:12:36 +1200
commit7f307f9082cb4be296e745c2c066334858f000af (patch)
tree4f5e3ca5a628624f631ccf1da9deeed90481d9bc /RSSDP
parent98db8f72e01b608e6c384ecf5b107fc2d105b652 (diff)
brace multiline if statements
Diffstat (limited to 'RSSDP')
-rw-r--r--RSSDP/HttpParserBase.cs12
-rw-r--r--RSSDP/HttpRequestParser.cs4
-rw-r--r--RSSDP/HttpResponseParser.cs4
-rw-r--r--RSSDP/SsdpCommunicationsServer.cs4
-rw-r--r--RSSDP/SsdpDevice.cs12
-rw-r--r--RSSDP/SsdpDeviceLocator.cs16
-rw-r--r--RSSDP/SsdpDevicePublisher.cs31
7 files changed, 79 insertions, 4 deletions
diff --git a/RSSDP/HttpParserBase.cs b/RSSDP/HttpParserBase.cs
index 058bfbf55..00c2b7b45 100644
--- a/RSSDP/HttpParserBase.cs
+++ b/RSSDP/HttpParserBase.cs
@@ -114,9 +114,13 @@ namespace Rssdp.Infrastructure
var headersToAddTo = IsContentHeader(headerName) ? contentHeaders : headers;
if (values.Count > 1)
+ {
headersToAddTo.TryAddWithoutValidation(headerName, values);
+ }
else
+ {
headersToAddTo.TryAddWithoutValidation(headerName, values.First());
+ }
}
private int ParseHeaders(System.Net.Http.Headers.HttpHeaders headers, System.Net.Http.Headers.HttpHeaders contentHeaders, string[] lines)
@@ -160,7 +164,9 @@ namespace Rssdp.Infrastructure
var indexOfSeparator = headerValue.IndexOfAny(SeparatorCharacters);
if (indexOfSeparator <= 0)
+ {
values.Add(headerValue);
+ }
else
{
var segments = headerValue.Split(SeparatorCharacters);
@@ -170,7 +176,9 @@ namespace Rssdp.Infrastructure
{
var segment = segments[segmentIndex];
if (segment.Trim().StartsWith("\"", StringComparison.OrdinalIgnoreCase))
+ {
segment = CombineQuotedSegments(segments, ref segmentIndex, segment);
+ }
values.Add(segment);
}
@@ -199,12 +207,16 @@ namespace Rssdp.Infrastructure
}
if (index + 1 < segments.Length)
+ {
trimmedSegment += "," + segments[index + 1].TrimEnd();
+ }
}
segmentIndex = segments.Length;
if (trimmedSegment.StartsWith("\"", StringComparison.OrdinalIgnoreCase) && trimmedSegment.EndsWith("\"", StringComparison.OrdinalIgnoreCase))
+ {
return trimmedSegment.Substring(1, trimmedSegment.Length - 2);
+ }
else
return trimmedSegment;
}
diff --git a/RSSDP/HttpRequestParser.cs b/RSSDP/HttpRequestParser.cs
index 6b27fc4df..7fa42f466 100644
--- a/RSSDP/HttpRequestParser.cs
+++ b/RSSDP/HttpRequestParser.cs
@@ -34,7 +34,9 @@ namespace Rssdp.Infrastructure
finally
{
if (retVal != null)
+ {
retVal.Dispose();
+ }
}
}
@@ -64,7 +66,9 @@ namespace Rssdp.Infrastructure
message.Method = new HttpMethod(parts[0].Trim());
Uri requestUri;
if (Uri.TryCreate(parts[1].Trim(), UriKind.RelativeOrAbsolute, out requestUri))
+ {
message.RequestUri = requestUri;
+ }
else
System.Diagnostics.Debug.WriteLine(parts[1]);
diff --git a/RSSDP/HttpResponseParser.cs b/RSSDP/HttpResponseParser.cs
index 0337b3e36..0dd4bb45a 100644
--- a/RSSDP/HttpResponseParser.cs
+++ b/RSSDP/HttpResponseParser.cs
@@ -34,7 +34,9 @@ namespace Rssdp.Infrastructure
catch
{
if (retVal != null)
+ {
retVal.Dispose();
+ }
throw;
}
@@ -77,7 +79,9 @@ namespace Rssdp.Infrastructure
int statusCode = -1;
if (!Int32.TryParse(parts[1].Trim(), out statusCode))
+ {
throw new ArgumentException("data status line is invalid. Status code is not a valid integer.", nameof(data));
+ }
message.StatusCode = (HttpStatusCode)statusCode;
diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs
index 31ca90424..e4c4a2017 100644
--- a/RSSDP/SsdpCommunicationsServer.cs
+++ b/RSSDP/SsdpCommunicationsServer.cs
@@ -480,17 +480,21 @@ namespace Rssdp.Infrastructure
var handlers = this.RequestReceived;
if (handlers != null)
+ {
handlers(this, new RequestReceivedEventArgs(data, remoteEndPoint, receivedOnLocalIpAddress));
+ }
}
private void OnResponseReceived(HttpResponseMessage data, IPEndPoint endPoint, IPAddress localIpAddress)
{
var handlers = this.ResponseReceived;
if (handlers != null)
+ {
handlers(this, new ResponseReceivedEventArgs(data, endPoint)
{
LocalIpAddress = localIpAddress
});
+ }
}
}
}
diff --git a/RSSDP/SsdpDevice.cs b/RSSDP/SsdpDevice.cs
index 42f95862c..7030c6ec1 100644
--- a/RSSDP/SsdpDevice.cs
+++ b/RSSDP/SsdpDevice.cs
@@ -55,7 +55,9 @@ namespace Rssdp
var rootDevice = device as SsdpRootDevice;
if (rootDevice == null)
+ {
rootDevice = ((SsdpEmbeddedDevice)device).RootDevice;
+ }
return rootDevice;
}
@@ -163,7 +165,9 @@ namespace Rssdp
get
{
if (String.IsNullOrEmpty(_Udn) && !String.IsNullOrEmpty(this.Uuid))
+ {
return "uuid:" + this.Uuid;
+ }
else
return _Udn;
}
@@ -283,7 +287,9 @@ namespace Rssdp
}
if (wasAdded)
+ {
OnDeviceAdded(device);
+ }
}
/// <summary>
@@ -314,7 +320,9 @@ namespace Rssdp
}
if (wasRemoved)
+ {
OnDeviceRemoved(device);
+ }
}
/// <summary>
@@ -327,7 +335,9 @@ namespace Rssdp
{
var handlers = this.DeviceAdded;
if (handlers != null)
+ {
handlers(this, new DeviceEventArgs(device));
+ }
}
/// <summary>
@@ -340,7 +350,9 @@ namespace Rssdp
{
var handlers = this.DeviceRemoved;
if (handlers != null)
+ {
handlers(this, new DeviceEventArgs(device));
+ }
}
}
}
diff --git a/RSSDP/SsdpDeviceLocator.cs b/RSSDP/SsdpDeviceLocator.cs
index a774ee23c..9a31db7a2 100644
--- a/RSSDP/SsdpDeviceLocator.cs
+++ b/RSSDP/SsdpDeviceLocator.cs
@@ -217,10 +217,12 @@ namespace Rssdp.Infrastructure
var handlers = this.DeviceAvailable;
if (handlers != null)
+ {
handlers(this, new DeviceAvailableEventArgs(device, isNewDevice)
{
LocalIpAddress = localIpAddress
});
+ }
}
/// <summary>
@@ -426,7 +428,9 @@ namespace Rssdp.Infrastructure
};
if (NotificationTypeMatchesFilter(deadDevice))
+ {
OnDeviceUnavailable(deadDevice, false);
+ }
}
}
}
@@ -439,7 +443,9 @@ namespace Rssdp.Infrastructure
{
message.Headers.TryGetValues(headerName, out values);
if (values != null)
+ {
retVal = values.FirstOrDefault();
+ }
}
return retVal;
@@ -453,7 +459,9 @@ namespace Rssdp.Infrastructure
{
message.Headers.TryGetValues(headerName, out values);
if (values != null)
+ {
retVal = values.FirstOrDefault();
+ }
}
return retVal;
@@ -467,7 +475,9 @@ namespace Rssdp.Infrastructure
{
request.Headers.TryGetValues(headerName, out values);
if (values != null)
+ {
value = values.FirstOrDefault();
+ }
}
Uri retVal;
@@ -483,7 +493,9 @@ namespace Rssdp.Infrastructure
{
response.Headers.TryGetValues(headerName, out values);
if (values != null)
+ {
value = values.FirstOrDefault();
+ }
}
Uri retVal;
@@ -560,7 +572,9 @@ namespace Rssdp.Infrastructure
foreach (var removedDevice in existingDevices)
{
if (NotificationTypeMatchesFilter(removedDevice))
+ {
OnDeviceUnavailable(removedDevice, expired);
+ }
}
return true;
@@ -572,7 +586,9 @@ namespace Rssdp.Infrastructure
private TimeSpan SearchTimeToMXValue(TimeSpan searchWaitTime)
{
if (searchWaitTime.TotalSeconds < 2 || searchWaitTime == TimeSpan.Zero)
+ {
return OneSecond;
+ }
else
return searchWaitTime.Subtract(OneSecond);
}
diff --git a/RSSDP/SsdpDevicePublisher.cs b/RSSDP/SsdpDevicePublisher.cs
index 1b64d230d..7c6e87201 100644
--- a/RSSDP/SsdpDevicePublisher.cs
+++ b/RSSDP/SsdpDevicePublisher.cs
@@ -215,7 +215,9 @@ namespace Rssdp.Infrastructure
if (commsServer != null)
{
if (!commsServer.IsShared)
+ {
commsServer.Dispose();
+ }
}
_RecentSearchRequests = null;
@@ -328,7 +330,9 @@ namespace Rssdp.Infrastructure
{
SendSearchResponse(SsdpConstants.UpnpDeviceTypeRootDevice, device, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), endPoint, receivedOnlocalIpAddress, cancellationToken);
if (this.SupportPnpRootDevice)
+ {
SendSearchResponse(SsdpConstants.PnpDeviceTypeRootDevice, device, GetUsn(device.Udn, SsdpConstants.PnpDeviceTypeRootDevice), endPoint, receivedOnlocalIpAddress, cancellationToken);
+ }
}
SendSearchResponse(device.Udn, device, device.Udn, endPoint, receivedOnlocalIpAddress, cancellationToken);
@@ -394,7 +398,9 @@ namespace Rssdp.Infrastructure
{
var lastRequest = _RecentSearchRequests[newRequest.Key];
if (lastRequest.IsOld())
+ {
_RecentSearchRequests[newRequest.Key] = newRequest;
+ }
else
isDuplicateRequest = true;
}
@@ -402,7 +408,9 @@ namespace Rssdp.Infrastructure
{
_RecentSearchRequests.Add(newRequest.Key, newRequest);
if (_RecentSearchRequests.Count > 10)
+ {
CleanUpRecentSearchRequestsAsync();
+ }
}
}
@@ -462,7 +470,9 @@ namespace Rssdp.Infrastructure
{
SendAliveNotification(device, SsdpConstants.UpnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), cancellationToken);
if (this.SupportPnpRootDevice)
+ {
SendAliveNotification(device, SsdpConstants.PnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.PnpDeviceTypeRootDevice), cancellationToken);
+ }
}
SendAliveNotification(device, device.Udn, device.Udn, cancellationToken);
@@ -506,7 +516,9 @@ namespace Rssdp.Infrastructure
{
tasks.Add(SendByeByeNotification(device, SsdpConstants.UpnpDeviceTypeRootDevice, GetUsn(device.Udn, SsdpConstants.UpnpDeviceTypeRootDevice), cancellationToken));
if (this.SupportPnpRootDevice)
+ {
tasks.Add(SendByeByeNotification(device, "pnp:rootdevice", GetUsn(device.Udn, "pnp:rootdevice"), cancellationToken));
+ }
}
tasks.Add(SendByeByeNotification(device, device.Udn, device.Udn, cancellationToken));
@@ -547,20 +559,27 @@ namespace Rssdp.Infrastructure
var timer = _RebroadcastAliveNotificationsTimer;
_RebroadcastAliveNotificationsTimer = null;
if (timer != null)
+ {
timer.Dispose();
+ }
}
private TimeSpan GetMinimumNonZeroCacheLifetime()
{
- var nonzeroCacheLifetimesQuery = (from device
- in _Devices
- where device.CacheLifetime != TimeSpan.Zero
- select device.CacheLifetime).ToList();
+ var nonzeroCacheLifetimesQuery = (
+ from device
+ in _Devices
+ where device.CacheLifetime != TimeSpan.Zero
+ select device.CacheLifetime).ToList();
if (nonzeroCacheLifetimesQuery.Any())
+ {
return nonzeroCacheLifetimesQuery.Min();
+ }
else
+ {
return TimeSpan.Zero;
+ }
}
private string GetFirstHeaderValue(System.Net.Http.Headers.HttpRequestHeaders httpRequestHeaders, string headerName)
@@ -568,7 +587,9 @@ namespace Rssdp.Infrastructure
string retVal = null;
IEnumerable<String> values = null;
if (httpRequestHeaders.TryGetValues(headerName, out values) && values != null)
+ {
retVal = values.FirstOrDefault();
+ }
return retVal;
}
@@ -588,7 +609,9 @@ namespace Rssdp.Infrastructure
{
var rootDevice = device as SsdpRootDevice;
if (rootDevice != null)
+ {
WriteTrace(text + " " + device.DeviceType + " - " + device.Uuid + " - " + rootDevice.Location);
+ }
else
WriteTrace(text + " " + device.DeviceType + " - " + device.Uuid);
}