internal override bool OnAsyncResultReceived(AsyncReceiveBuffer result) { try { var dgram = HttpDatagram.Parse(result.Buffer); if (dgram == null || dgram.Type != HttpDatagramType.MSearch) { return(true); } var st = dgram.Headers.Get("ST"); var mx = dgram.Headers.Get("MX"); var man = dgram.Headers.Get("Man"); if (string.IsNullOrEmpty(st) || string.IsNullOrEmpty(mx) || man != Protocol.SsdpDiscoverMan) { return(true); } server.RequestRecieved(new Request(result.SenderIPEndPoint, st, UInt16.Parse(mx))); } catch (Exception e) { Log.Exception("Invalid HTTPMU/M-SEARCH datagram", e); } return(true); }
internal override bool OnAsyncResultReceived(AsyncReceiveBuffer result) { try { HttpDatagram dgram = HttpDatagram.Parse(result.Buffer); if (dgram == null || dgram.Type != HttpDatagramType.Notify) { return(true); } string nts = dgram.Headers.Get("NTS"); string usn = dgram.Headers.Get("USN"); string nt = dgram.Headers.Get("NT"); if (String.IsNullOrEmpty(nts) || String.IsNullOrEmpty(usn)) { return(true); } if (!client.ServiceTypeRegistered(nt)) { return(true); } if (nts == Protocol.SsdpAliveNts) { try { if (!client.ServiceCache.Update(usn, dgram)) { client.ServiceCache.Add(new BrowseService(dgram, true)); } } catch (Exception e) { Log.Exception("Invalid ssdp:alive NOTIFY", e); } } else if (nts == Protocol.SsdpByeByeNts) { client.ServiceCache.Remove(usn); } } catch (Exception e) { Log.Exception("Invalid HTTPMU/NOTIFY datagram", e); } return(true); }