/// <summary> /// Handles SSDP M-SEARCH requests over UDP multicast and unicast. /// </summary> /// <param name="header">HTTP request header of the request to handle.</param> /// <param name="config">Endpoint configuration which received the request.</param> /// <param name="remoteEP">Remote endpoint which sent the request.</param> protected void HandleSSDPRequest(SimpleHTTPRequest header, EndpointConfiguration config, IPEndPoint remoteEP) { switch (header.Method) { case "M-SEARCH": if (header.Param != "*" || header["MAN"] != "\"ssdp:discover\"") throw new InvalidDataException("Unsupported Request"); // We don't make a difference between multicast and unicast search requests here, // the only difference is the existance of the MX header field. // If it is present, we simply use this random delay for the answer, and if it is // not present, we send the answer at once. int mx; // Max. seconds to delay response if (!int.TryParse(header["MX"], out mx)) mx = 0; else if (mx < 1) // Malformed request throw new InvalidDataException("Invalid MX header value"); if (mx > 5) mx = 5; // Should be bounded to 5, according to (DevArch) string st = header["ST"]; // Search target if (header.ContainsHeader("USER-AGENT")) // Optional CheckUserAgentUPnPVersion(header["USER-AGENT"]); DelaySearchResponse(new PendingSearchRequest(st, config, remoteEP), mx); break; } }