コード例 #1
0
        protected void HandleNotifyRequest(SimpleHTTPRequest header, EndpointConfiguration config, IPEndPoint remoteEndPoint)
        {
            if (header.Param != "*")
            {
                // Invalid message
                return;
            }
            HTTPVersion httpVersion;

            if (!HTTPVersion.TryParse(header.HttpVersion, out httpVersion))
            {
                // Invalid message
                return;
            }
            // HOST not interesting
            //string host = header["HOST"];
            string cacheControl = header["CACHE-CONTROL"];
            string location     = header["LOCATION"];
            string server       = header["SERVER"];
            // NT is not evaluated, we get all information from the USN header
            //string nt = header["NT"];
            string nts = header["NTS"];
            string usn = header["USN"];
            string bi  = header["BOOTID.UPNP.ORG"];
            string ci  = header["CONFIGID.UPNP.ORG"];
            string sp  = header["SEARCHPORT.UPNP.ORG"];

            HandleNotifyPacket(config, remoteEndPoint, httpVersion, DateTime.Now.ToUniversalTime().ToString("R"), cacheControl, location, server, nts, usn, bi, ci, sp);
        }
コード例 #2
0
        protected void HandleSSDPResponse(SimpleHTTPResponse header, EndpointConfiguration config, IPEndPoint remoteEndPoint)
        {
            HTTPVersion httpVersion;

            if (!HTTPVersion.TryParse(header.HttpVersion, out httpVersion))
            {
                // Invalid response
                return;
            }
            string cacheControl = header["CACHE-CONTROL"];
            string date         = header["DATE"];
            // EXT is not used
            //string ext = header["EXT"];
            string location = header["LOCATION"];
            string server   = header["SERVER"];
            // ST is not used
            //string st = header["ST"];
            string usn = header["USN"];
            string bi  = header["BOOTID.UPNP.ORG"];
            string ci  = header["CONFIGID.UPNP.ORG"];
            string sp  = header["SEARCHPORT.UPNP.ORG"];

            HandleNotifyPacket(config, remoteEndPoint, httpVersion, date, cacheControl, location, server, "ssdp:alive", usn, bi, ci, sp);
        }
コード例 #3
0
        protected void HandleUpdatePacket(SimpleHTTPRequest header, EndpointConfiguration config)
        {
            if (header.Param != "*")
            {
                // Invalid message
                return;
            }
            HTTPVersion httpVersion;

            if (!HTTPVersion.TryParse(header.HttpVersion, out httpVersion))
            {
                // Invalid message
                return;
            }
            // Host, NT, NTS, USN are not interesting
            //string host = header["HOST"];
            //string nt = header["NT"];
            //string nts = header["NTS"];
            string usn = header["USN"];
            //string location = header["LOCATION"];
            string bi = header["BOOTID.UPNP.ORG"];
            uint   bootID;

            if (!uint.TryParse(bi, out bootID))
            {
                // Invalid message
                return;
            }
            string nbi = header["NEXTBOOTID.UPNP.ORG"];
            uint   nextBootID;

            if (!uint.TryParse(nbi, out nextBootID))
            {
                // Invalid message
                return;
            }
            if (!usn.StartsWith("uuid:"))
            {
                // Invalid usn
                return;
            }
            int separatorIndex = usn.IndexOf("::");

            if (separatorIndex < 6) // separatorIndex == -1 or separatorIndex not after "uuid:" prefix with at least one char UUID
            // We only use messages containing a "::" substring and discard the "uuid:device-UUID" message
            {
                return;
            }
            string    deviceUUID = usn.Substring(5, separatorIndex - 5);
            RootEntry rootEntry  = GetRootEntryByContainedDeviceUUID(deviceUUID);

            if (rootEntry == null)
            {
                return;
            }
            if (rootEntry.BootID > bootID)
            {
                // Invalid message
                return;
            }
            bool fireDeviceRebooted = false;

            lock (_cpData.SyncObj)
            {
                if (rootEntry.BootID < bootID)
                {
                    // Device reboot
                    fireDeviceRebooted = true;
                }
                rootEntry.BootID = nextBootID;
            }
            if (fireDeviceRebooted)
            {
                InvokeDeviceRebooted(rootEntry, false);
            }
        }