Exemplo n.º 1
0
 public void AddExtraHeader(string header, object value)
 {
     if (value != null && !RawHeaders.ContainsKey(header))
     {
         RawHeaders.Add(header, value);
     }
 }
Exemplo n.º 2
0
        internal void NotifyDevice(UpnpDevice dev, string type, bool sticky)
        {
            Debug("NotifyDevice");
            var headers = new RawHeaders();

            headers.Add("HOST", "239.255.255.250:1900");
            headers.Add("CACHE-CONTROL", "max-age = 600");
            headers.Add("LOCATION", dev.Descriptor.ToString());
            headers.Add("SERVER", HttpServer.Signature);
            headers.Add("NTS", "ssdp:" + type);
            headers.Add("NT", dev.Type);
            headers.Add("USN", dev.USN);

            SendDatagram(
                SSDP_ENDP,
                dev.Address,
                String.Format("NOTIFY * HTTP/1.1\r\n{0}\r\n", headers.HeaderBlock),
                sticky
                );
            // Some buggy network equipment will swallow multicast packets, so lets
            // cheat, increase the odds, by sending to broadcast.
            SendDatagram(
                BROAD_ENDP,
                dev.Address,
                String.Format("NOTIFY * HTTP/1.1\r\n{0}\r\n", headers.HeaderBlock),
                sticky
                );
            DebugFormat("{0} said {1}", dev.USN, type);
        }
Exemplo n.º 3
0
        internal void NotifyDevice(UpnpDevice dev, string type, bool sticky)
        {
            Logger.LogTrace("NotifyDevice");
            var headers = new RawHeaders
            {
                { "HOST", "239.255.255.250:1900" },
                { "CACHE-CONTROL", "max-age = 600" },
                { "LOCATION", dev.Descriptor.ToString() },
                { "SERVER", HttpServer.Signature },
                { "NTS", "ssdp:" + type },
                { "NT", dev.Type },
                { "USN", dev.USN }
            };

            SendDatagram(
                ssdpEndp,
                dev.Address,
                $"NOTIFY * HTTP/1.1\r\n{headers.HeaderBlock}\r\n",
                sticky
                );
            // Some buggy network equipment will swallow multicast packets, so lets
            // cheat, increase the odds, by sending to broadcast.
            SendDatagram(
                BroadEndp,
                dev.Address,
                $"NOTIFY * HTTP/1.1\r\n{headers.HeaderBlock}\r\n",
                sticky
                );
            Logger.LogTrace($"{dev.USN} said {type}");
        }
Exemplo n.º 4
0
        private void SendSearchResponse(IPEndPoint endpoint, UpnpDevice dev)
        {
            var headers = new RawHeaders();

            headers.Add("CACHE-CONTROL", "max-age = 600");
            headers.Add("DATE", DateTime.Now.ToString("R"));
            headers.Add("EXT", "");
            headers.Add("LOCATION", dev.Descriptor.ToString());
            headers.Add("SERVER", HttpServer.Signature);
            headers.Add("ST", dev.Type);
            headers.Add("USN", dev.USN);

            SendDatagram(endpoint, dev.Address, String.Format("HTTP/1.1 200 OK\r\n{0}\r\n", headers.HeaderBlock), false);
            InfoFormat("{2}, {1} - Responded to a {0} request", dev.Type, endpoint, dev.Address);
        }
Exemplo n.º 5
0
                public void SetHeader(string key, string value)
                {
                    if (string.IsNullOrWhiteSpace(key))
                    {
                        throw new ArgumentNullException(nameof(key));
                    }

                    if (string.IsNullOrWhiteSpace(value))
                    {
                        RawHeaders.Remove(key);
                    }
                    else
                    {
                        RawHeaders[key] = new[] { value }
                    };
                }
Exemplo n.º 6
0
Arquivo: SSDP.cs Projeto: tngraf/UPnP
        }             // RemoveSearchResult()

        /// <summary>
        /// Sends the search response.
        /// </summary>
        /// <param name="remoteEndpoint">The remote endpoint.</param>
        /// <param name="sendClient">The send client.</param>
        private static void SendSearchRequest(IPEndPoint remoteEndpoint, UdpClient sendClient)
        {
            var headers = new RawHeaders();

            headers.Add("HOST", "239.255.255.250:1900");
            ////headers.Add("ST", QueryAll);
            headers.Add("ST", QueryDevices);
            headers.Add("MAN", "\"ssdp:discover\"");
            headers.Add("MX", SecondsForSearch.ToString());

            var dgram = new Datagram(remoteEndpoint, sendClient,
                                     $"M-SEARCH * HTTP/1.1\r\n{headers.HeaderBlock}\r\n",
                                     false);

            dgram.Send();
        } // SendSearchRequest()
Exemplo n.º 7
0
        internal void NotifyDevice(UpnpDevice dev, string type, bool sticky)
        {
            Debug("NotifyDevice");
            var headers = new RawHeaders();

            headers.Add("HOST", "239.255.255.250:1900");
            headers.Add("CACHE-CONTROL", "max-age = 600");
            headers.Add("LOCATION", dev.Descriptor.ToString());
            headers.Add("SERVER", HttpServer.Signature);
            headers.Add("NTS", "ssdp:" + type);
            headers.Add("NT", dev.Type);
            headers.Add("USN", dev.USN);

            SendDatagram(SSDP_ENDP, dev.Address, String.Format("NOTIFY * HTTP/1.1\r\n{0}\r\n", headers.HeaderBlock), sticky);
            DebugFormat("{0} said {1}", dev.USN, type);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Adds a single header or updates it if it already exists
        /// </summary>
        /// <param name="headerName">The name of the header</param>
        /// <param name="headerValue">The value for the header</param>
        public void SetHeaderValue(string headerName, string headerValue)
        {
            if (!RawHeaders.ContainsKey(headerName))
            {
                RawHeaders.Add(headerName, new List <string> {
                    headerValue
                });
            }
            else
            {
                RawHeaders[headerName] = new List <string> {
                    headerValue
                }
            };

            ParseHeader(headerName, headerValue);
        }
Exemplo n.º 9
0
        private void SendSearchResponse(IPEndPoint endpoint, UpnpDevice dev)
        {
            var headers = new RawHeaders
            {
                { "CACHE-CONTROL", "max-age = 600" },
                { "DATE", DateTime.Now.ToString("R") },
                { "EXT", string.Empty },
                { "LOCATION", dev.Descriptor.ToString() },
                { "SERVER", HttpServer.Signature },
                { "ST", dev.Type },
                { "USN", dev.USN }
            };

            SendDatagram(
                endpoint,
                dev.Address,
                $"HTTP/1.1 200 OK\r\n{headers.HeaderBlock}\r\n",
                false
                );
            Logger.LogTrace($"{dev.Address}, {endpoint} - Responded to a {dev.Type} request");
        }
Exemplo n.º 10
0
 /// <summary>
 ///     Returns the value(s) of the header, <c>null</c> will be returned when the
 ///     header does not exist
 /// </summary>
 /// <param name="headerName">The name of the header</param>
 public string HeaderValue(string headerName)
 {
     return(RawHeaders.ContainsKey(headerName) ? string.Join(Environment.NewLine, RawHeaders[headerName]) : null);
 }
Exemplo n.º 11
0
 public NetStandardRequestContext(HttpContext context)
 {
     _ctx      = context;
     _conn     = _ctx.Features.Get <IHttpConnectionFeature>();
     _headersD = new Lazy <IDictionary <string, string> >(() => RawHeaders.ToDictionary(x => x.Key, y => y.Value.First()));
 }
Exemplo n.º 12
0
    internal void NotifyDevice(UpnpDevice dev, string type, bool sticky)
    {
      Debug("NotifyDevice");
      var headers = new RawHeaders();
      headers.Add("HOST", "239.255.255.250:1900");
      headers.Add("CACHE-CONTROL", "max-age = 600");
      headers.Add("LOCATION", dev.Descriptor.ToString());
      headers.Add("SERVER", HttpServer.Signature);
      headers.Add("NTS", "ssdp:" + type);
      headers.Add("NT", dev.Type);
      headers.Add("USN", dev.USN);

      SendDatagram(
        SSDP_ENDP,
        dev.Address,
        String.Format("NOTIFY * HTTP/1.1\r\n{0}\r\n", headers.HeaderBlock),
        sticky
        );
      DebugFormat("{0} said {1}", dev.USN, type);
    }
Exemplo n.º 13
0
    private void SendSearchResponse(IPEndPoint endpoint, UpnpDevice dev)
    {
      var headers = new RawHeaders();
      headers.Add("CACHE-CONTROL", "max-age = 600");
      headers.Add("DATE", DateTime.Now.ToString("R"));
      headers.Add("EXT", string.Empty);
      headers.Add("LOCATION", dev.Descriptor.ToString());
      headers.Add("SERVER", HttpServer.Signature);
      headers.Add("ST", dev.Type);
      headers.Add("USN", dev.USN);

      SendDatagram(
        endpoint,
        dev.Address,
        String.Format("HTTP/1.1 200 OK\r\n{0}\r\n", headers.HeaderBlock),
        false
        );
      InfoFormat(
        "{2}, {1} - Responded to a {0} request", dev.Type, endpoint,
        dev.Address);
    }
Exemplo n.º 14
0
 private string[] GetHeaderUnmodified(string key)
 {
     string[] values;
     return(RawHeaders.TryGetValue(key, out values) ? values : null);
 }
Exemplo n.º 15
0
        internal void NotifyDevice(UpnpDevice dev, string type, bool sticky)
        {
            _logger.Debug("NotifyDevice");
              var headers = new RawHeaders();
              headers.Add("HOST", "239.255.255.250:1900");
              headers.Add("CACHE-CONTROL", "max-age = 600");
              headers.Add("LOCATION", dev.Descriptor.ToString());
              headers.Add("SERVER", HttpServer.Signature);
              headers.Add("NTS", "ssdp:" + type);
              headers.Add("NT", dev.Type);
              headers.Add("USN", dev.USN);

              SendDatagram(
            SSDP_ENDP,
            dev.Address,
            String.Format("NOTIFY * HTTP/1.1\r\n{0}\r\n", headers.HeaderBlock),
            sticky
            );
              // Some buggy network equipment will swallow multicast packets, so lets
              // cheat, increase the odds, by sending to broadcast.
              SendDatagram(
            BROAD_ENDP,
            dev.Address,
            String.Format("NOTIFY * HTTP/1.1\r\n{0}\r\n", headers.HeaderBlock),
            sticky
            );
              _logger.DebugFormat("{0} said {1}", dev.USN, type);
        }
Exemplo n.º 16
0
        internal void NotifyDevice(UpnpDevice dev, string type, bool sticky)
        {
            Debug("NotifyDevice");
              var headers = new RawHeaders
              {
            {"HOST", "239.255.255.250:1900"},
            {"CACHE-CONTROL", "max-age = 600"},
            {"LOCATION", dev.Descriptor.ToString()},
            {"SERVER", HttpServer.Signature},
            {"NTS", "ssdp:" + type},
            {"NT", dev.Type},
            {"USN", dev.USN}
              };

              SendDatagram(
            ssdpEndp,
            dev.Address,
            $"NOTIFY * HTTP/1.1\r\n{headers.HeaderBlock}\r\n",
            sticky
            );
              // Some buggy network equipment will swallow multicast packets, so lets
              // cheat, increase the odds, by sending to broadcast.
              SendDatagram(
            BroadEndp,
            dev.Address,
            $"NOTIFY * HTTP/1.1\r\n{headers.HeaderBlock}\r\n",
            sticky
            );
              DebugFormat("{0} said {1}", dev.USN, type);
        }