Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 void AsyncReadResult (AsyncReceiveBuffer buffer)
 {
     try {
         buffer.Socket.BeginReceiveFrom (buffer, OnAsyncResultReceived);
     } catch (ObjectDisposedException) {
         // Socket disposed while we were receiving from it... just ignore this
     }
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
 private void AsyncReadResult(AsyncReceiveBuffer buffer)
 {
     buffer.Socket.BeginReceiveFrom (buffer, OnAsyncResultReceived);
 }
Ejemplo n.º 7
0
 internal virtual bool OnAsyncResultReceived(AsyncReceiveBuffer result)
 {
     return false;
 }
Ejemplo n.º 8
0
 public IAsyncResult BeginReceiveFrom(AsyncReceiveBuffer buffer, AsyncCallback callback)
 {
     return(base.BeginReceiveFrom(buffer.Buffer, 0, buffer.Buffer.Length, SocketFlags.None,
                                  ref buffer.SenderEndPoint, callback, buffer));
 }
Ejemplo n.º 9
0
 public IAsyncResult BeginReceiveFrom(AsyncReceiveBuffer buffer, AsyncCallback callback)
 {
     return base.BeginReceiveFrom (buffer.Buffer, 0, buffer.Buffer.Length, SocketFlags.None,
         ref buffer.SenderEndPoint, callback, buffer);
 }
Ejemplo n.º 10
0
 internal override bool OnAsyncResultReceived (AsyncReceiveBuffer result)
 {
     try {
         HttpDatagram dgram = HttpDatagram.Parse (result.Buffer);
         if (dgram == null) {
             return true;
         }
         
         try {
             client.ServiceCache.Add (new BrowseService (dgram, false));
         } catch (Exception e) {
             Log.Exception ("Invalid browse response", e);
         }
     } catch (Exception e) {
         Log.Exception ("Invalid HTTPU datagram", e);
     }
     
     return true;
 }