Beispiel #1
0
 //"ssdp:all"; //
 public UpnpSmartControlPoint()
 {
     this.deviceFactory.OnDevice += this.DeviceFactoryCreationSink;
     this.deviceLifeTimeClock.OnExpired += this.DeviceLifeTimeClockSink;
     this.deviceUpdateClock.OnExpired += this.DeviceUpdateClockSink;
     this.hostNetworkInfo = new NetworkInfo(new NetworkInfo.InterfaceHandler(this.NetworkInfoNewInterfaceSink));
     this.hostNetworkInfo.OnInterfaceDisabled += this.NetworkInfoOldInterfaceSink;
     this.genericControlPoint = new UPnPControlPoint(this.hostNetworkInfo);
     this.genericControlPoint.OnSearch += this.UPnPControlPointSearchSink;
     this.genericControlPoint.OnNotify += this.SSDPNotifySink;
     this.genericControlPoint.FindDeviceAsync(searchFilter);
 }
Beispiel #2
0
        /// <summary>
        /// Constructs a new Control Point, and waits for your commands and receives events
        /// </summary>
        public UPnPControlPoint()
        {
            CreateTable = Hashtable.Synchronized(new Hashtable());
            NetInfo = new NetworkInfo(new NetworkInfo.InterfaceHandler(NewInterface));
            SyncData = ArrayList.Synchronized(new ArrayList());
            SSDPSessions = Hashtable.Synchronized(new Hashtable());
            Lifetime = new LifeTimeMonitor();
            Lifetime.OnExpired += new LifeTimeMonitor.LifeTimeHandler(HandleExpired);

            SSDPServer = new SSDP(65535);
            SSDPServer.OnNotify += new SSDP.NotifyHandler(HandleNotify);
        }
        public UPnPControlPoint(NetworkInfo ni)
        {
            CreateTable         = Hashtable.Synchronized(new Hashtable());
            NetInfo             = ni;
            SyncData            = ArrayList.Synchronized(new ArrayList());
            SSDPSessions        = Hashtable.Synchronized(new Hashtable());
            Lifetime            = new LifeTimeMonitor();
            Lifetime.OnExpired += new LifeTimeMonitor.LifeTimeHandler(HandleExpired);

            SSDPServer           = new SSDP(65535);
            SSDPServer.OnNotify += new SSDP.NotifyHandler(HandleNotify);
        }
        public UPnPControlPoint(NetworkInfo ni)
        {
            CreateTable         = Hashtable.Synchronized(new Hashtable());
            NetInfo             = (null != ni) ? ni : new NetworkInfo(new NetworkInfo.InterfaceHandler(NewInterface));
            SyncData            = ArrayList.Synchronized(new ArrayList());
            SSDPSessions        = Hashtable.Synchronized(new Hashtable());
            Lifetime            = new LifeTimeMonitor();
            Lifetime.OnExpired += new LifeTimeMonitor.LifeTimeHandler(HandleExpired);

            SSDPServer                = new SSDP(65535);
            SSDPServer.OnNotify      += new SSDP.NotifyHandler(HandleNotify);
            SSDPServer.OnSniffPacket += new SSDP.SnifferHandler(HandleSniffer);
        }
        /// <summary>
        /// Constructs a new Control Point, and waits for your commands and receives events
        /// </summary>
        public UPnPControlPoint()
        {
            CreateTable = Hashtable.Synchronized(new Hashtable());
            NetInfo = new NetworkInfo(new NetworkInfo.InterfaceHandler(NewInterface));
            SyncData = ArrayList.Synchronized(new ArrayList());
            SSDPSessions = Hashtable.Synchronized(new Hashtable());
            Lifetime = new LifeTimeMonitor();
            Lifetime.OnExpired += new LifeTimeMonitor.LifeTimeHandler(HandleExpired);

            SSDPServer = new SSDP(65535);
            SSDPServer.OnNotify += new SSDP.NotifyHandler(HandleNotify);

            OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Information,"UPnP Object Created");
        }
        public UPnPInternalSmartControlPoint()
        {
            deviceFactory.OnDevice        += new UPnPDeviceFactory.UPnPDeviceHandler(DeviceFactoryCreationSink);
            deviceFactory.OnFailed        += new UPnPDeviceFactory.UPnPDeviceFailedHandler(DeviceFactoryFailedSink);
            deviceLifeTimeClock.OnExpired += new LifeTimeMonitor.LifeTimeHandler(DeviceLifeTimeClockSink);
            deviceUpdateClock.OnExpired   += new LifeTimeMonitor.LifeTimeHandler(DeviceUpdateClockSink);

            hostNetworkInfo = new NetworkInfo(new NetworkInfo.InterfaceHandler(NetworkInfoNewInterfaceSink));
            hostNetworkInfo.OnInterfaceDisabled += new NetworkInfo.InterfaceHandler(NetworkInfoOldInterfaceSink);

            // Launch a search for all devices and start populating the
            // internal smart control point device list.
            genericControlPoint           = new UPnPControlPoint();
            genericControlPoint.OnSearch += new UPnPControlPoint.SearchHandler(UPnPControlPointSearchSink);
            genericControlPoint.OnNotify += new SSDP.NotifyHandler(SSDPNotifySink);

            genericControlPoint.FindDeviceAsync("upnp:rootdevice");
        }
        public UPnPInternalSmartControlPoint()
        {
            deviceFactory.OnDevice += new UPnPDeviceFactory.UPnPDeviceHandler(DeviceFactoryCreationSink);
            deviceFactory.OnFailed += new UPnPDeviceFactory.UPnPDeviceFailedHandler(DeviceFactoryFailedSink);
            deviceLifeTimeClock.OnExpired += new LifeTimeMonitor.LifeTimeHandler(DeviceLifeTimeClockSink);
            deviceUpdateClock.OnExpired += new LifeTimeMonitor.LifeTimeHandler(DeviceUpdateClockSink);

            hostNetworkInfo = new NetworkInfo(new NetworkInfo.InterfaceHandler(NetworkInfoNewInterfaceSink));
            hostNetworkInfo.OnInterfaceDisabled += new NetworkInfo.InterfaceHandler(NetworkInfoOldInterfaceSink);

            // Launch a search for all devices and start populating the
            // internal smart control point device list.
            genericControlPoint = new UPnPControlPoint();
            genericControlPoint.OnSearch += new UPnPControlPoint.SearchHandler(UPnPControlPointSearchSink);
            genericControlPoint.OnNotify += new SSDP.NotifyHandler(SSDPNotifySink);

            genericControlPoint.FindDeviceAsync("upnp:rootdevice");
        }
Beispiel #8
0
        /// <summary>
        /// Constructs a new SSDP Server
        /// </summary>
        /// <param name="LocalEP">The EndPoint which this will bind to</param>
        /// <param name="Expiration">The number of seconds before a Refresh will be triggered</param>
        public SSDP(int Expiration)
        {
            LifeTimeHandler = new LifeTimeMonitor.LifeTimeHandler(SearchTimerSink);
            SearchTimer.OnExpired += LifeTimeHandler;

            SSDP_EXPIRATION = Expiration;
            if (SSDP_EXPIRATION < 5) SSDP_EXPIRATION = 5;
            int MinVal = (int)((double)SSDP_EXPIRATION * 0.25 * 1000);
            int MaxVal = (int)((double)SSDP_EXPIRATION * 0.45 * 1000);

            NotifyTimer.OnElapsed += new SafeTimer.TimeElapsedHandler(__NotifyCheck);
            NotifyTimer.Interval = RND.Next(MinVal, MaxVal);
            NotifyTimer.AutoReset = true;
            NotifyTimer.Start();

            NetInfo = new NetworkInfo();
            SetupSessions();
        }
Beispiel #9
0
        /// <summary>
        /// Constructs a new SSDP Server
        /// </summary>
        /// <param name="LocalEP">The EndPoint which this will bind to</param>
        /// <param name="Expiration">The number of seconds before a Refresh will be triggered</param>
        public SSDP(int Expiration)
        {
            //OpenSource.Utilities.InstanceTracker.Add(this);
            LifeTimeHandler = new LifeTimeMonitor.LifeTimeHandler(SearchTimerSink);
            SearchTimer.OnExpired += LifeTimeHandler;

            SSDP_EXPIRATION = Expiration;
            if (SSDP_EXPIRATION < 5)
                SSDP_EXPIRATION = 5;
            int MinVal = (int)((double)SSDP_EXPIRATION * 0.25 * 1000);
            int MaxVal = (int)((double)SSDP_EXPIRATION * 0.45 * 1000);

            NotifyTimer.SetTimer(5000, __NotifyCheck);
            /*
            NotifyTimer.Interval = RND.Next(MinVal, MaxVal);
            NotifyTimer.AutoReset = true;
            NotifyTimer.Start();
            */
            NetInfo = new NetworkInfo();
            SetupSessions();
        }
        /// <summary>
        /// Constructs a new SSDP Server
        /// </summary>
        /// <param name="LocalEP">The EndPoint which this will bind to</param>
        /// <param name="Expiration">The number of seconds before a Refresh will be triggered</param>
        public SSDP(int Expiration)
        {
            OpenSource.Utilities.InstanceTracker.Add(this);
            LifeTimeHandler        = new LifeTimeMonitor.LifeTimeHandler(SearchTimerSink);
            SearchTimer.OnExpired += LifeTimeHandler;

            SSDP_EXPIRATION = Expiration;
            if (SSDP_EXPIRATION < 5)
            {
                SSDP_EXPIRATION = 5;
            }
            int MinVal = (int)((double)SSDP_EXPIRATION * 0.25 * 1000);
            int MaxVal = (int)((double)SSDP_EXPIRATION * 0.45 * 1000);

            NotifyTimer.OnElapsed += new SafeTimer.TimeElapsedHandler(__NotifyCheck);
            NotifyTimer.Interval   = RND.Next(MinVal, MaxVal);
            NotifyTimer.AutoReset  = true;
            NotifyTimer.Start();

            NetInfo = new NetworkInfo();
            SetupSessions();
        }
        private void DisabledInterface(NetworkInfo sender, IPAddress ip)
        {
            SendNotify(); // Advertise on other valid interfaces

            MiniWebServer y;
            try
            {
                y = (MiniWebServer)WebServerTable[ip.ToString()];
                if (y != null) y.Dispose();
                WebServerTable[ip.ToString()] = null;
            }
            catch (Exception)
            {
            }
        }
 private void NewInterface(NetworkInfo sender, IPAddress Intfce)
 {
 }
Beispiel #13
0
        private void NewDeviceInterface(NetworkInfo sender, IPAddress ip)
        {
            try
            {
                //String tmp = ip.ToString();

                MiniWebServer WebServer;
                WebServer = new MiniWebServer(new IPEndPoint(ip, UseThisPort));
                if ((this.OnSniff != null) || (this.OnSniffPacket != null))
                    WebServer.OnSession += new MiniWebServer.NewSessionHandler(SniffSessionSink);

                WebServer.OnReceive += new MiniWebServer.HTTPReceiveHandler(HandleWebRequest);
                WebServer.OnHeader += new MiniWebServer.HTTPReceiveHandler(HandleHeaderRequest);
                WebServerTable[ip.ToString()] = WebServer;
                SendNotify(ip);
            }
            catch (SocketException ex)
            {
                // Cannot bind to this IPAddress, so just ignore
                OpenSource.Utilities.EventLogger.Log(ex);
                OpenSource.Utilities.EventLogger.Log(ex, "UPnPDevice: " + this.FriendlyName + " @" + ip.ToString());
                //				System.Windows.Forms.MessageBox.Show(ex.ToString(),"UPnPDevice: " + this.FriendlyName+" @"+ip.ToString());
            }
        }
Beispiel #14
0
        private void NewCPInterface(NetworkInfo sender, IPAddress ip)
        {
            lock (typeof(UPnPDevice))
            {
                if (CPWebServerTable.ContainsKey(ip.ToString()) == false)
                {
                    MiniWebServer ws = new MiniWebServer(new IPEndPoint(ip, 0));
                    ws.OnReceive += new MiniWebServer.HTTPReceiveHandler(HandleWebRequest);
                    ws.OnHeader += new MiniWebServer.HTTPReceiveHandler(HandleHeaderRequest);
                    CPWebServerTable[ip.ToString()] = ws;
                }
                else
                {
                    if (CP_RegisteredInterfaces.ContainsKey(ip.ToString()) == false)
                    {
                        CP_RegisteredInterfaces[ip.ToString()] = true;
                        ((MiniWebServer)CPWebServerTable[ip.ToString()]).OnReceive += new MiniWebServer.HTTPReceiveHandler(HandleWebRequest);
                        ((MiniWebServer)CPWebServerTable[ip.ToString()]).OnHeader += new MiniWebServer.HTTPReceiveHandler(HandleHeaderRequest);
                    }
                }

            }
        }
Beispiel #15
0
 public void RefreshNetworkInfo()
 {
     sessions.Clear();
     NetInfo = new NetworkInfo();
     SetupSessions();
 }
Beispiel #16
0
 private void NetworkInfoNewInterfaceSink(NetworkInfo sender, IPAddress Intfce)
 {
     if (this.genericControlPoint != null)
     {
         this.genericControlPoint.FindDeviceAsync(searchFilter);
     }
 }
 private void NetworkInfoNewInterfaceSink(NetworkInfo sender, IPAddress Intfce)
 {
     if (genericControlPoint != null) genericControlPoint.FindDeviceAsync("upnp:rootdevice");
 }
        private void NetworkInfoOldInterfaceSink(NetworkInfo sender, IPAddress Intfce)
        {
            UPnPDevice[] listing;
            ArrayList TempList = new ArrayList();

            lock (deviceTableLock)
            {
                listing = GetCurrentDevices();
                foreach (UPnPDevice d in listing)
                {
                    if (d.InterfaceToHost.Equals(Intfce))
                    {
                        TempList.Add(UnprotectedRemoveMe(d));
                    }
                }
            }

            foreach (UPnPDevice d in TempList)
            {
                d.Removed();
                OnRemovedDeviceEvent.Fire(this, d);
            }

            genericControlPoint.FindDeviceAsync("upnp:rootdevice");
        }
Beispiel #19
0
 private void NewInterface(NetworkInfo sender, IPAddress Intfce)
 {
 }
Beispiel #20
0
 /// <summary>
 /// Start the UPnPDevice
 /// </summary>
 public void StartDevice()
 {
     if (ControlPointOnly == false)
     {
         if (IsRoot == true)
         {
             NetInfo = new NetworkInfo(new NetworkInfo.InterfaceHandler(NewDeviceInterface));
             NetInfo.OnInterfaceDisabled += new NetworkInfo.InterfaceHandler(DisabledInterface);
             Advertise();
         }
         else
         {
             throw (new Exception("Cannot Start/Stop a Non-Root Device directly"));
         }
     }
     else
     {
         throw (new Exception("Cannot Start/Stop a Device instantiated by a Control Point"));
     }
 }
Beispiel #21
0
 public void ShutDown()
 {
     this.deviceFactory.OnDevice -= this.DeviceFactoryCreationSink;
     this.deviceLifeTimeClock.OnExpired -= this.DeviceLifeTimeClockSink;
     this.deviceUpdateClock.OnExpired -= this.DeviceUpdateClockSink;
     this.hostNetworkInfo.OnInterfaceDisabled -= this.NetworkInfoOldInterfaceSink;
     this.genericControlPoint.OnSearch -= this.UPnPControlPointSearchSink;
     this.genericControlPoint.OnNotify -= this.SSDPNotifySink;
     this.deviceFactory.Shutdown();
     this.deviceFactory = null;
     this.hostNetworkInfo = null;
     this.genericControlPoint = null;
 }
Beispiel #22
0
        /// <summary>
        /// Constructs a UPnPDevice for use as a control point
        /// </summary>
        internal UPnPDevice()
        {
            //OpenSource.Utilities.InstanceTracker.Add(this);

            // Control Point Only
            parent = null;
            ControlPointOnly = true;
            Services = new UPnPService[0];
            HasPresentation = false;

            VirtualDir_Table = new Hashtable();
            VirtualDir_Header_Table = new Hashtable();

            lock (typeof(UPnPDevice))
            {
                if (DeviceCount == 0)
                {
                    CPWebServerTable = new Hashtable();
                    CPNetworkInfo = new NetworkInfo(new NetworkInfo.InterfaceHandler(NewCPInterface));
                }
                else
                {
                    IPAddress[] alist = CPNetworkInfo.GetLocalAddresses();
                    for (int i = 0; i < alist.Length; ++i)
                    {
                        CP_RegisteredInterfaces[alist[i].ToString()] = true;
                        ((MiniWebServer)CPWebServerTable[alist[i].ToString()]).OnReceive += new MiniWebServer.HTTPReceiveHandler(HandleWebRequest);
                        ((MiniWebServer)CPWebServerTable[alist[i].ToString()]).OnHeader += new MiniWebServer.HTTPReceiveHandler(HandleHeaderRequest);
                    }
                    CPNetworkInfo.OnNewInterface += new NetworkInfo.InterfaceHandler(NewCPInterface);
                }
                ++DeviceCount;
            }

            SSDPServer = new SSDP(ExpirationTimeout);
            SSDPServer.OnRefresh += SendNotify;
            SSDPServer.OnSearch += HandleSearch;
        }
Beispiel #23
0
 private void NetworkInfoOldInterfaceSink(NetworkInfo sender, IPAddress Intfce)
 {
     ArrayList list = new ArrayList();
     lock (this.deviceTableLock)
     {
         foreach (UPnPDevice device in this.GetCurrentDevices())
         {
             if (device.InterfaceToHost.Equals(Intfce))
             {
                 list.Add(this.UnprotectedRemoveMe(device));
             }
         }
     }
     foreach (UPnPDevice device2 in list)
     {
         //device2.Removed();
         this.OnRemovedDeviceEvent.Fire(this, device2);
     }
     this.genericControlPoint.FindDeviceAsync(searchFilter);
 }
Beispiel #24
0
        private void DisabledInterface(NetworkInfo sender, IPAddress ip)
        {
            SendNotify(); // Advertise on other valid interfaces

            MiniWebServer y;
            try
            {
                y = (MiniWebServer)WebServerTable[ip.ToString()];
                if (y != null)
                    y.Dispose();
                WebServerTable[ip.ToString()] = null;
            }
            catch (Exception ex)
            {
                OpenSource.Utilities.EventLogger.Log(ex);
            }
        }