/// <summary> /// Triggered when a SSDP search result is received /// </summary> private void UPnPControlPointSearchSink(IPEndPoint source, IPEndPoint local, Uri LocationURL, String USN, String SearchTarget, int MaxAge) { // A bit like getting a SSDP notification, but we don't do automatic // source change in this case. The only valid scenario of a search // result is device creation. lock (deviceTableLock) { if (deviceTable.ContainsKey(USN) == false) { // Never saw this device before DeviceInfo deviceInfo = new DeviceInfo(); deviceInfo.Device = null; deviceInfo.UDN = USN; deviceInfo.NotifyTime = DateTime.Now; deviceInfo.BaseURL = LocationURL; deviceInfo.MaxAge = MaxAge; deviceInfo.LocalEP = local; deviceInfo.SourceEP = source; deviceTable[USN] = deviceInfo; deviceFactory.CreateDevice(deviceInfo.BaseURL, deviceInfo.MaxAge, local.Address, USN); } else { DeviceInfo deviceInfo = (DeviceInfo)deviceTable[USN]; if (deviceInfo.Device != null) // If the device is in creation mode, do nothing { if (deviceInfo.BaseURL.Equals(LocationURL)) { // Cancel a possible source change deviceUpdateClock.Remove(deviceInfo); deviceInfo.PendingBaseURL = null; deviceInfo.PendingMaxAge = 0; deviceInfo.PendingLocalEP = null; deviceInfo.PendingSourceEP = null; // Then simply update the lifetime deviceInfo.NotifyTime = DateTime.Now; deviceTable[USN] = deviceInfo; deviceLifeTimeClock.Add(deviceInfo.UDN, MaxAge); } else { // Wow, same device, different source - Check timing if (deviceInfo.NotifyTime.AddSeconds(10).Ticks < DateTime.Now.Ticks) { // This is a possible source change. Wait for 3 seconds and make the switch. deviceInfo.PendingBaseURL = LocationURL; deviceInfo.PendingMaxAge = MaxAge; deviceInfo.PendingLocalEP = local; deviceInfo.PendingSourceEP = source; deviceUpdateClock.Add(deviceInfo.UDN, 3); } } } } } }
internal UPnPDevice UnprotectedRemoveMe(string UDN) { DeviceInfo deviceInfo; UPnPDevice removedDevice = null; if (deviceTable.ContainsKey(UDN)) { deviceInfo = (DeviceInfo)deviceTable[UDN]; removedDevice = deviceInfo.Device; deviceTable.Remove(UDN); deviceLifeTimeClock.Remove(deviceInfo.UDN); deviceUpdateClock.Remove(deviceInfo); activeDeviceList.Remove(removedDevice); } return(removedDevice); }
private void ContinueRequest(IPEndPoint dest, string PQ, object Tag, HTTPMessage MSG) { HTTPMessage r = null; if (MSG == null) { r = new HTTPMessage(); r.Directive = "GET"; r.DirectiveObj = PQ; if (dest.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { r.AddTag("Host", dest.ToString()); } if (dest.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { r.AddTag("Host", "[" + RemoveIPv6Scope(dest.ToString()) + "]"); } } else { r = MSG; } lock (TagQueue) { this.IdleTimeout = false; KeepAliveTimer.Remove(this.GetHashCode()); LastMessage = r; if ((PIPELINE == false && _PIPELINE == false) || (_PIPELINE == false)) { HTTPRequest TR = new HTTPRequest(); TR.ProxySetting = ProxySetting; TR._PIPELINE = true; if (this.OnSniff != null) { TR.OnSniff += new HTTPRequest.SniffHandler(NonPipelinedSniffSink); } if (this.OnSniffPacket != null) { TR.OnSniffPacket += new HTTPRequest.RequestHandler(NonPipelinedSniffPacketSink); } TR.OnResponse += new HTTPRequest.RequestHandler(NonPipelinedResponseSink); this.NotPipelinedTable[TR] = TR; TR.PipelineRequest(dest, r, Tag); return; } bool NeedSend = (TagQueue.Count == 0); TagQueue.Enqueue(new StateData(r, dest, Tag, null)); IPAddress localif = IPAddress.Any; if (dest.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { localif = IPAddress.IPv6Any; } if (s == null) { ReceivedFirstResponse = false; if (ProxySetting != null) { s = new HTTPSession(new IPEndPoint(localif, 0), ProxySetting, new HTTPSession.SessionHandler(CreateSink), new HTTPSession.SessionHandler(CreateFailedSink), null); } else { s = new HTTPSession(new IPEndPoint(localif, 0), dest, new HTTPSession.SessionHandler(CreateSink), new HTTPSession.SessionHandler(CreateFailedSink), null); } } else { if (s.IsConnected && this.ReceivedFirstResponse) { try { if (ProxySetting == null) { s.Send(r); } else { HTTPMessage pr = (HTTPMessage)r.Clone(); pr.DirectiveObj = "http://" + dest.ToString() + pr.DirectiveObj; pr.Version = "1.0"; s.Send(pr); } } catch (Exception ex) { OpenSource.Utilities.EventLogger.Log(ex); } } } } }
private void HandleHeader(HTTPSession sender, HTTPMessage Header, Stream StreamObject) { SessionTimer.Remove(sender); OnHeaderEvent.Fire(Header, sender); }