Beispiel #1
0
        internal Notify(IHttpRequest request)
        {
            try
            {
                LocalIpEndPoint     = request.LocalIpEndPoint;
                RemoteIpEndPoint    = request.RemoteIpEndPoint;
                HOST                = GetHeaderValue(request.Headers, "HOST");
                NotifyTransportType = GetCastMetod(request);
                CacheControl        = TimeSpan.FromSeconds(GetMaxAge(request.Headers));
                Location            = UrlToUri(GetHeaderValue(request.Headers, "LOCATION"));
                NT     = GetHeaderValue(request.Headers, "NT");
                NTS    = ConvertToNotificationSubTypeEnum(GetHeaderValue(request.Headers, "NTS"));
                Server = ConvertToServer(GetHeaderValue(request.Headers, "SERVER"));
                USN    = new USN(GetHeaderValue(request.Headers, "USN"));

                BOOTID         = uint.TryParse(GetHeaderValue(request.Headers, "BOOTID.UPNP.ORG"), out var b) ? b : 0;
                CONFIGID       = GetHeaderValue(request.Headers, "CONFIGID.UPNP.ORG");
                SEARCHPORT     = uint.TryParse(GetHeaderValue(request.Headers, "SEARCHPORT.UPNP.ORG"), out var s) ? s : 0;
                NEXTBOOTID     = uint.TryParse(GetHeaderValue(request.Headers, "NEXTBOOTID.UPNP.ORG"), out var n) ? n : 0;
                SECURELOCATION = GetHeaderValue(request.Headers, "SECURELOCATION.UPNP.ORG");

                Headers = HeaderHelper.SingleOutAdditionalHeaders(new List <string>
                {
                    "HOST", "CACHE-CONTROL", "LOCATION", "NT", "NTS", "SERVER", "USN",
                    "BOOTID.UPNP.ORG", "CONFIGID.UPNP.ORG",
                    "SEARCHPORT.UPNP.ORG", "NEXTBOOTID.UPNP.ORG", "SECURELOCATION.UPNP.ORG"
                }, request.Headers);
            }
            catch (Exception)
            {
                InvalidRequest = true;
            }

            IsUuidUpnp2Compliant = Guid.TryParse(USN.DeviceUUID, out var guid);
        }
Beispiel #2
0
        internal MSearchResponse(IHttpResponse response, ILogger logger = null)
        {
            try
            {
                LocalIpEndPoint  = response.LocalIpEndPoint;
                RemoteIpEndPoint = response.RemoteIpEndPoint;
                HasParsingError  = response.HasParsingErrors;
                TransportType    = Convert.GetCastMetod(response);
                StatusCode       = response.StatusCode;
                ResponseReason   = response.ResponseReason;
                CacheControl     = TimeSpan.FromSeconds(Convert.GetMaxAge(response.Headers));
                Location         = Convert.UrlToUri(Convert.GetHeaderValue(response.Headers, "LOCATION"));
                Date             = Convert.ToRfc2616Date(Convert.GetHeaderValue(response.Headers, "DATE"));
                Ext            = response.Headers.ContainsKey("EXT");
                Server         = Convert.ConvertToServer(Convert.GetHeaderValue(response.Headers, "SERVER"));
                ST             = new ST(Convert.GetHeaderValue(response.Headers, "ST"), ignoreError: true);
                USN            = new USN(Convert.GetHeaderValue(response.Headers, "USN")); Convert.GetHeaderValue(response.Headers, "USN");
                BOOTID         = int.TryParse(Convert.GetHeaderValue(response.Headers, "BOOTID.UPNP.ORG"), out var b) ? b : 0;
                CONFIGID       = int.TryParse(Convert.GetHeaderValue(response.Headers, "CONFIGID.UPNP.ORG"), out var c) ? c : 0;
                SEARCHPORT     = int.TryParse(Convert.GetHeaderValue(response.Headers, "SEARCHPORT.UPNP.ORG"), out var s) ? s : 0;
                SECURELOCATION = Convert.GetHeaderValue(response.Headers, "SECURELOCATION.UPNP.ORG");

                Headers = HeaderHelper.SingleOutAdditionalHeaders(new List <string>
                {
                    "HOST", "CACHE-CONTROL", "LOCATION", "DATE", "EXT", "SERVER", "ST", "USN",
                    "BOOTID.UPNP.ORG", "CONFIGID.UPNP.ORG", "SEARCHPORT.UPNP.ORG", "SECURELOCATION.UPNP.ORG"
                }, response.Headers);

                RemoteIpEndPoint = response.RemoteIpEndPoint;
            }
            catch (Exception ex)
            {
                logger?.Error(ex);
                InvalidRequest = true;
            }
        }