예제 #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);
                     }
                 }
             }
         }
     }
 }
 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);
         }
       }
     }
   }
 }