Search request response patch

2004-12-22
2013-05-02
  • Oliver Newell
    Oliver Newell
    2004-12-22

    Hello -

    I noticed that CLink (1.5 - didn't check 1.6 yet) responds to device-type-specific searches with a USN containing 'upnp:rootdevice' instead of the device type.  Also, the 'ST' field of the search response should just be a copy of the 'ST' field of the search request (according to the Intel UPnP book). Attached is a patch  to the relevant routine in Device.java. 

    -Oliver

    /**
    *  Search response patches
    *
    *  1. Response 'ST' field always set to 'ST' field of incoming request
    *  2. Response for specific device-type modified to respond with a USN
    *     of  'devUSN + "::" + devType'   (was 'devUSN + "::" + USN.ROOTDEVICE)
    *
    */
    public void deviceSearchResponse(SSDPPacket ssdpPacket)
    {
      String ssdpST = ssdpPacket.getST();

      if (ssdpST == null)
        return;

      boolean isRootDevice = isRootDevice();

      String devUSN = getUDN();

      //  ST = ssdp:all ?
      if (ST.isAllDevice(ssdpST) == true) {
        if (isRootDevice == true)
          devUSN += "::" + USN.ROOTDEVICE;

        String devNT = getNotifyDeviceNT();
        int repeatCnt = (isRootDevice == true) ? 3 : 2;
        for (int n=0; n<repeatCnt; n++)
          postSearchResponse(ssdpPacket, ssdpST, devUSN );
      }
      //  ST = upnp:rootdevice
      else if (ST.isRootDevice(ssdpST) == true) {
        if (isRootDevice == true)
          postSearchResponse(ssdpPacket, ssdpST,
                             devUSN + "::" + USN.ROOTDEVICE);
      }
      else if (ST.isUUIDDevice(ssdpST) == true) {
        String devUDN = getUDN();
        if (ssdpST.equals(devUDN) == true)
          postSearchResponse(ssdpPacket, ssdpST, devUSN);
      }
      else if (ST.isURNDevice(ssdpST) == true) {
        String devType= getDeviceType();
        if (ssdpST.equals(devType) == true)
          postSearchResponse(ssdpPacket, ssdpST,
                             devUSN + "::" + devType );
      }

      ServiceList serviceList = getServiceList();
      int serviceCnt = serviceList.size();
      for (int n=0; n<serviceCnt; n++) {
        Service service = serviceList.getService(n);
        service.serviceSearchResponse(ssdpPacket);
      }

      DeviceList childDeviceList = getDeviceList();
      int childDeviceCnt = childDeviceList.size();
      for (int n=0; n<childDeviceCnt; n++) {
        Device childDevice = childDeviceList.getDevice(n);
        childDevice.deviceSearchResponse(ssdpPacket);
      }
    }