示例#1
0
 protected void ProcessSearchRequest(PendingSearchRequest ps)
 {
     lock (_serverData.SyncObj)
     {
         SearchResultMessageSender srms = new SearchResultMessageSender(_serverData, ps.LocalEndpointConfiguration, ps.RequesterEndPoint);
         if (ps.ST == "ssdp:all")
         {
             DeviceTreeNotificationProducer.SendMessagesServer(_serverData.Server, srms);
         }
         else if (ps.ST == "upnp:rootdevice")
         { // Search root device
             foreach (DvDevice rootDevice in _serverData.Server.RootDevices)
             {
                 string deviceUDN = rootDevice.UDN;
                 srms.SendMessage("upnp:rootdevice", deviceUDN + "::upnp:rootdevice", rootDevice);
             }
         }
         else if (ps.ST.StartsWith("uuid:"))
         { // Search by device id
             string   deviceUDN = ps.ST;
             DvDevice device    = _serverData.Server.FindDeviceByUDN(deviceUDN);
             if (device != null)
             {
                 srms.SendMessage(deviceUDN, deviceUDN, device.RootDevice);
             }
         }
         else if (ps.ST.StartsWith("urn:") && (ps.ST.IndexOf(":device:") > -1 || ps.ST.IndexOf(":service:") > -1))
         { // Search by device type or service type and version
             string type;
             int    version;
             if (!ParserHelper.TryParseTypeVersion_URN(ps.ST, out type, out version))
             {
                 UPnPConfiguration.LOGGER.Debug("SSDPServerController: Problem parsing incoming packet, UPnP device or service search query '{0}'", ps.ST);
                 return;
             }
             if (type.IndexOf(":device:") > -1)
             {
                 IEnumerable <DvDevice> devices = _serverData.Server.FindDevicesByDeviceTypeAndVersion(
                     type, version, true);
                 foreach (DvDevice device in devices)
                 {
                     srms.SendMessage(device.DeviceTypeVersion_URN, device.UDN + "::" + device.DeviceTypeVersion_URN, device.RootDevice);
                 }
             }
             else if (type.IndexOf(":service:") > -1)
             {
                 foreach (DvDevice rootDevice in _serverData.Server.RootDevices)
                 {
                     IEnumerable <DvService> services = rootDevice.FindServicesByServiceTypeAndVersion(
                         type, version, true);
                     foreach (DvService service in services)
                     {
                         srms.SendMessage(service.ServiceTypeVersion_URN, service.ParentDevice.UDN + "::" + service.ServiceTypeVersion_URN, service.ParentDevice.RootDevice);
                     }
                 }
             }
         }
     }
 }
示例#2
0
 /// <summary>
 /// Adds the given <paramref name="ps"/> data to the collection of pending searches and reconfigures the internal
 /// timer to send pending search responses in max. <paramref name="maxDelaySeconds"/> seconds.
 /// </summary>
 /// <param name="ps">Data containing the pending search request.</param>
 /// <param name="maxDelaySeconds">The search response will be send in a random time from 0 to
 /// <paramref name="maxDelaySeconds"/> seconds.</param>
 protected void DelaySearchResponse(PendingSearchRequest ps, int maxDelaySeconds)
 {
     lock (_serverData.SyncObj)
     {
         _serverData.PendingSearches.Add(ps);
         ReconfigureSearchResponseTimer(_rnd.Next(maxDelaySeconds * 1000));
     }
 }
 /// <summary>
 /// Adds the given <paramref name="ps"/> data to the collection of pending searches and reconfigures the internal
 /// timer to send pending search responses in max. <paramref name="maxDelaySeconds"/> seconds.
 /// </summary>
 /// <param name="ps">Data containing the pending search request.</param>
 /// <param name="maxDelaySeconds">The search response will be send in a random time from 0 to
 /// <paramref name="maxDelaySeconds"/> seconds.</param>
 protected void DelaySearchResponse(PendingSearchRequest ps, int maxDelaySeconds)
 {
   lock (_serverData.SyncObj)
   {
     _serverData.PendingSearches.Add(ps);
     ReconfigureSearchResponseTimer(_rnd.Next(maxDelaySeconds * 1000));
   }
 }
 protected void ProcessSearchRequest(PendingSearchRequest ps)
 {
   lock (_serverData.SyncObj)
   {
     SearchResultMessageSender srms = new SearchResultMessageSender(_serverData, ps.LocalEndpointConfiguration, ps.RequesterEndPoint);
     if (ps.ST == "ssdp:all")
       DeviceTreeNotificationProducer.SendMessagesServer(_serverData.Server, srms);
     else if (ps.ST == "upnp:rootdevice")
     { // Search root device
       foreach (DvDevice rootDevice in _serverData.Server.RootDevices)
       {
         string deviceUDN = rootDevice.UDN;
         srms.SendMessage("upnp:rootdevice", deviceUDN + "::upnp:rootdevice", rootDevice);
       }
     }
     else if (ps.ST.StartsWith("uuid:"))
     { // Search by device id
       string deviceUDN = ps.ST;
       DvDevice device = _serverData.Server.FindDeviceByUDN(deviceUDN);
       if (device != null)
         srms.SendMessage(deviceUDN, deviceUDN, device.RootDevice);
     }
     else if (ps.ST.StartsWith("urn:") && (ps.ST.IndexOf(":device:") > -1 || ps.ST.IndexOf(":service:") > -1))
     { // Search by device type or service type and version
       string type;
       int version;
       if (!ParserHelper.TryParseTypeVersion_URN(ps.ST, out type, out version))
       {
         UPnPConfiguration.LOGGER.Debug("SSDPServerController: Problem parsing incoming packet, UPnP device or service search query '{0}'", ps.ST);
         return;
       }
       if (type.IndexOf(":device:") > -1)
       {
         IEnumerable<DvDevice> devices = _serverData.Server.FindDevicesByDeviceTypeAndVersion(
             type, version, true);
         foreach (DvDevice device in devices)
           srms.SendMessage(device.DeviceTypeVersion_URN, device.UDN + "::" + device.DeviceTypeVersion_URN, device.RootDevice);
       }
       else if (type.IndexOf(":service:") > -1)
       {
         foreach (DvDevice rootDevice in _serverData.Server.RootDevices)
         {
           IEnumerable<DvService> services = rootDevice.FindServicesByServiceTypeAndVersion(
               type, version, true);
           foreach (DvService service in services)
             srms.SendMessage(service.ServiceTypeVersion_URN, service.ParentDevice.UDN + "::" + service.ServiceTypeVersion_URN, service.ParentDevice.RootDevice);
         }
       }
     }
   }
 }