示例#1
0
 public boolean postControlAction() {
   // Thanks for Giordano Sassaroli <*****@*****.**> (08/30/03)
   ArgumentList actionArgList = getArgumentList();
   ArgumentList actionInputArgList = getInputArgumentList();
   ActionRequest ctrlReq = new ActionRequest();
   ctrlReq.setRequest(this, actionInputArgList);
   if (Debug.isOn() == true) ctrlReq.print();
   ActionResponse ctrlRes = ctrlReq.post();
   if (Debug.isOn() == true) ctrlRes.print();
   setControlResponse(ctrlRes);
   // Thanks for Dimas <*****@*****.**> and Stefano Lenzi
   // <*****@*****.**> (07/09/04)
   int statCode = ctrlRes.getStatusCode();
   setStatus(statCode);
   if (ctrlRes.isSuccessful() == false) return false;
   ArgumentList outArgList = ctrlRes.getResponse();
   try {
     actionArgList.setResArgs(outArgList);
   } catch (IllegalArgumentException ex) {
     setStatus(
         UPnPStatus.INVALID_ARGS, "Action succesfully delivered but invalid arguments returned.");
     return false;
   }
   return true;
 }
示例#2
0
 public void print() {
   Debug.message("Action : " + getName());
   ArgumentList argList = getArgumentList();
   int nArgs = argList.size();
   for (int n = 0; n < nArgs; n++) {
     Argument arg = argList.getArgument(n);
     String name = arg.getName();
     String value = arg.getValue();
     String dir = arg.getDirection();
     Debug.message(" [" + n + "] = " + dir + ", " + name + ", " + value);
   }
 }
 public void run() {
   Thread thread = Thread.currentThread();
   ControlPoint controlpoint = getControlPoint();
   do {
     SSDPPacket ssdppacket;
     do {
       if (deviceNotifyThread != thread) {
         return;
       }
       Thread.yield();
       InetAddress inetaddress;
       InetAddress inetaddress1;
       try {
         ssdppacket = receive();
       } catch (IOException ioexception) {
         return;
       }
     } while (ssdppacket == null);
     inetaddress = getMulticastInetAddress();
     inetaddress1 = ssdppacket.getHostInetAddress();
     if (!inetaddress.equals(inetaddress1)) {
       Debug.warning(
           (new StringBuilder("Invalidate Multicast Recieved from IP "))
               .append(inetaddress)
               .append(" on ")
               .append(inetaddress1)
               .toString());
     } else if (controlpoint != null) {
       controlpoint.notifyReceived(ssdppacket);
     }
   } while (true);
 }
  public void run() {
    Thread thisThread = Thread.currentThread();

    ControlPoint ctrlPoint = getControlPoint();

    while (deviceNotifyThread == thisThread) {
      Thread.yield();

      // Thanks for Kazuyuki Shudo (08/23/07)
      SSDPPacket packet = null;
      try {
        packet = receive();
      } catch (IOException e) {
        break;
      }

      // Thanks for Mikael Hakman (04/20/05)
      if (packet == null) continue;

      // Thanks for Inma (02/20/04)
      InetAddress maddr = getMulticastInetAddress();
      InetAddress pmaddr = packet.getHostInetAddress();
      if (maddr.equals(pmaddr) == false) {
        Debug.warning("Invalidate Multicast Recieved from IP " + maddr + " on " + pmaddr);
        continue;
      }
      // TODO Must be performed on a different Thread in order to prevent UDP packet losses.
      if (ctrlPoint != null) ctrlPoint.notifyReceived(packet);
    }
  }
  @SuppressWarnings("unchecked")
  private boolean updateItemNode(FileItemNode itemNode, File file, MusicItem info) {
    Format format = getContentDirectory().getFormat(info.mime_type);
    if (format == null) {
      Log.d(TAG, "dms file format ==null filepath=" + info.filePath);
      return false;
    }
    FormatObject formatObj = format.createObject(file);

    // File/TimeStamp
    itemNode.setFile(file);

    // Title
    String title = info.title;
    if (title != null) itemNode.setTitle(title);

    // Creator
    String creator = formatObj.getCreator();
    if (0 < creator.length()) itemNode.setCreator(creator);

    // Media Class
    String mediaClass = format.getMediaClass();
    if (0 < mediaClass.length()) itemNode.setUPnPClass(mediaClass);

    // Date
    long lastModTime = file.lastModified();
    itemNode.setDate(lastModTime);

    // Storatge Used
    try {
      long fileSize = file.length();
      itemNode.setStorageUsed(fileSize);
    } catch (Exception e) {
      Debug.warning(e);
    }
    itemNode.setMimeType(format.getMimeType());
    itemNode.addProperty(UPnP.ALBUM, info.album);
    itemNode.addProperty(UPnP.ARITIST, info.artist);
    itemNode.addProperty(UPnP.FILEPATH, info.filePath);
    itemNode.setAlbumArtURI(getContentDirectory().getContentExportArmArtURL(info.albumArtURI));

    // ProtocolInfo
    String mimeType = format.getMimeType();
    String protocol = ConnectionManager.HTTP_GET + ":*:" + mimeType + ":*";
    String id = itemNode.getID();
    String url = getContentDirectory().getContentExportURL(id);
    info.itemUri = url;
    AttributeList objAttrList = formatObj.getAttributeList();
    objAttrList.add(new Attribute(UPnP.DURATION, info.duration));
    itemNode.setResource(url, protocol, objAttrList);

    DIDLLite didlLite = new DIDLLite();
    didlLite.setContentNode(itemNode);
    info.metaData = didlLite.toString();
    // Update SystemUpdateID
    getContentDirectory().updateSystemUpdateID();

    return true;
  }
示例#6
0
 public long getLong(int n) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return 0;
     return rs.getLong(n);
   } catch (Exception e) {
     Debug.warning(e);
   }
   return 0;
 }
示例#7
0
 public int getInteger(int n) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return 0;
     return rs.getInt(n);
   } catch (Exception e) {
     Debug.warning(e);
   }
   return 0;
 }
示例#8
0
 public String getString(int n) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return "";
     byte[] str_b = rs.getBytes(n);
     return new String(str_b);
   } catch (Exception e) {
     Debug.warning(e);
   }
   return "";
 }
示例#9
0
 public void close() {
   Connection con = getConnection();
   if (con != null) {
     try {
       con.close();
       setConnection(null);
     } catch (Exception e) {
       Debug.warning(e);
     }
   }
 }
示例#10
0
 public long getDate(int n) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return 0;
     Date ts = rs.getDate(n);
     return ts.getTime();
   } catch (Exception e) {
     Debug.warning(e);
   }
   return 0;
 }
示例#11
0
 public long getTimestamp(String name) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return 0;
     Timestamp ts = rs.getTimestamp(name);
     return ts.getTime();
   } catch (Exception e) {
     Debug.warning(e);
   }
   return 0;
 }
  private boolean updateItemNode(FileItemNode itemNode, File file, PhotoItem info) {
    Format format = getContentDirectory().getFormat(file);
    if (format == null) return false;
    FormatObject formatObj = format.createObject(file);

    // File/TimeStamp
    itemNode.setFile(file);

    String title = info.title;
    if (title != null) itemNode.setTitle(title);

    // Creator
    String creator = formatObj.getCreator();
    if (0 < creator.length()) itemNode.setCreator(creator);

    // Media Class
    String mediaClass = format.getMediaClass();
    if (0 < mediaClass.length()) itemNode.setUPnPClass(mediaClass);

    // Date
    long lastModTime = file.lastModified();
    itemNode.setDate(lastModTime);

    // Storatge Used
    try {
      long fileSize = file.length();
      itemNode.setStorageUsed(fileSize);
    } catch (Exception e) {
      Debug.warning(e);
    }
    itemNode.addProperty(UPnP.FILEPATH, info.filePath);
    itemNode.setAlbumArtURI(info.thumbFilePath);

    // ProtocolInfo
    String mimeType = format.getMimeType();
    String protocol = ConnectionManager.HTTP_GET + ":*:" + mimeType + ":*";
    String id = itemNode.getID();
    String url = getContentDirectory().getContentExportURL(id);

    AttributeList objAttrList = formatObj.getAttributeList();
    itemNode.setResource(url, protocol, objAttrList);
    info.itemUri = url;

    DIDLLite didlLite = new DIDLLite();
    didlLite.setContentNode(itemNode);
    info.metaData = didlLite.toString();
    // Update SystemUpdateID
    getContentDirectory().updateSystemUpdateID();

    return true;
  }
示例#13
0
 public UPnPManager(RouterContext context, TransportManager manager) {
     _context = context;
     _manager = manager;
     _log = _context.logManager().getLog(UPnPManager.class);
     // UPnP wants to bind to IPv6 link local interfaces by default, but what UPnP router
     // is going to want to talk IPv6 anyway? Just make it easy and force IPv4 only
     org.cybergarage.upnp.UPnP.setEnable(org.cybergarage.upnp.UPnP.USE_ONLY_IPV4_ADDR);
     // set up logging in the UPnP package
     Debug.initialize(context);
     _upnp = new UPnP(context);
     _upnp.setHTTPPort(_context.getProperty(PROP_HTTP_PORT, DEFAULT_HTTP_PORT));
     _upnp.setSSDPPort(_context.getProperty(PROP_SSDP_PORT, DEFAULT_SSDP_PORT));
     _upnpCallback = new UPnPCallback();
     _rescanner = new Rescanner();
 }
示例#14
0
 public boolean performActionListener(ActionRequest actionReq) {
   ActionListener listener = (ActionListener) getActionListener();
   if (listener == null) return false;
   ActionResponse actionRes = new ActionResponse();
   setStatus(UPnPStatus.INVALID_ACTION);
   clearOutputAgumentValues();
   if (listener.actionControlReceived(this) == true) {
     actionRes.setResponse(this);
   } else {
     UPnPStatus upnpStatus = getStatus();
     actionRes.setFaultResponse(upnpStatus.getCode(), upnpStatus.getDescription());
   }
   if (Debug.isOn() == true) actionRes.print();
   actionReq.post(actionRes);
   return true;
 }
示例#15
0
 public boolean query(String sql) {
   try {
     Statement stmt = getStatement();
     if (stmt != null) stmt.close();
     ResultSet rs = getResultSet();
     if (rs != null) rs.close();
     Connection con = getConnection();
     if (con == null) return false;
     stmt = con.createStatement();
     setStatement(stmt);
     rs = stmt.executeQuery(sql);
     setResultSet(rs);
   } catch (Exception e) {
     Debug.warning(e);
     return false;
   }
   return true;
 }
示例#16
0
 public boolean fetch() {
   boolean fetchRet = false;
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return false;
     fetchRet = rs.next();
     if (!fetchRet) {
       Statement stmt = getStatement();
       if (stmt != null) {
         stmt.close();
         setStatement(null);
       }
       rs.close();
       setResultSet(null);
     }
   } catch (Exception e) {
     Debug.warning(e);
   }
   return fetchRet;
 }
示例#17
0
 public static final int getLeaseTime(String cacheCont) {
   /*
    * Search for max-age keyword instead of equals sign Found value of max-age ends at next
    * comma or end of string
    */
   int mx = 0;
   int maxAgeIdx = cacheCont.indexOf("max-age");
   if (maxAgeIdx >= 0) {
     int endIdx = cacheCont.indexOf(',', maxAgeIdx);
     if (endIdx < 0) endIdx = cacheCont.length();
     try {
       maxAgeIdx = cacheCont.indexOf("=", maxAgeIdx);
       String mxStr = cacheCont.substring(maxAgeIdx + 1, endIdx).trim();
       mx = Integer.parseInt(mxStr);
     } catch (Exception e) {
       Debug.warning(e);
     }
   }
   return mx;
 }
示例#18
0
 public int update(String sql) {
   int numOfUpdated = 0;
   try {
     Statement stmt = getStatement();
     if (stmt != null) {
       stmt.close();
       setStatement(null);
     }
     ResultSet rs = getResultSet();
     if (rs != null) {
       rs.close();
       setResultSet(null);
     }
     Connection con = getConnection();
     if (con == null) return 0;
     stmt = con.createStatement();
     numOfUpdated = stmt.executeUpdate(sql);
     stmt.close();
   } catch (Exception e) {
     Debug.warning(e);
   }
   return numOfUpdated;
 }
示例#19
0
  private Node getSCPDNode() {
    ServiceData data = getServiceData();
    Node scpdNode = data.getSCPDNode();
    if (scpdNode != null) return scpdNode;

    // Thanks for Jaap (Sep 18, 2010)
    Device rootDev = getRootDevice();
    if (rootDev == null) return null;

    String scpdURLStr = getSCPDURL();

    // Thanks for Robin V. (Sep 18, 2010)
    String rootDevPath = rootDev.getDescriptionFilePath();
    if (rootDevPath != null) {
      File f;
      f = new File(rootDevPath.concat(scpdURLStr));

      if (f.exists()) {
        try {
          scpdNode = getSCPDNode(f);
        } catch (ParserException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        if (scpdNode != null) {
          data.setSCPDNode(scpdNode);
          return scpdNode;
        }
      }
    }

    try {
      URL scpdUrl = new URL(rootDev.getAbsoluteURL(scpdURLStr));
      scpdNode = getSCPDNode(scpdUrl);
      if (scpdNode != null) {
        data.setSCPDNode(scpdNode);
        return scpdNode;
      }
    } catch (Exception e) {
    }

    // ms777		I found this necessary to get the correct scpdUrl on Windows / PC
    try {
      URL urlLoc = new URL(rootDev.getLocation());
      URL scpdUrl = new URL(urlLoc.getProtocol(), urlLoc.getHost(), urlLoc.getPort(), scpdURLStr);
      scpdNode = getSCPDNode(scpdUrl);
      if (scpdNode != null) {
        data.setSCPDNode(scpdNode);
        return scpdNode;
      }
    } catch (Exception e) {
    }
    // ms777 end

    String newScpdURLStr = rootDev.getDescriptionFilePath() + HTTP.toRelativeURL(scpdURLStr);
    try {
      scpdNode = getSCPDNode(new File(newScpdURLStr));
      return scpdNode;
    } catch (Exception e) {
      Debug.warning(e);
    }

    return null;
  }
示例#20
0
  protected boolean set(InputStream in, boolean onlyHeaders) {
    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      // try{
      String firstLine = reader.readLine();
      /*
       * }catch(SocketException se){ System.out.println("[HTTP ERROR START]"); System.out.println(this);
       * System.out.println("[HTTP ERROR END]"); throw se; }
       */
      if (firstLine == null || firstLine.length() <= 0) return false;
      setFirstLine(firstLine);

      // Thanks for Giordano Sassaroli <*****@*****.**> (09/03/03)
      HTTPStatus httpStatus = new HTTPStatus(firstLine);
      int statCode = httpStatus.getStatusCode();
      if (statCode == HTTPStatus.CONTINUE) {
        // ad hoc code for managing iis non-standard behaviour
        // iis sends 100 code response and a 200 code response in the same
        // stream, so the code should check the presence of the actual
        // response in the stream.
        // skip all header lines
        String headerLine = reader.readLine();
        while ((headerLine != null) && (0 < headerLine.length())) {
          HTTPHeader header = new HTTPHeader(headerLine);
          if (header.hasName() == true) setHeader(header);
          headerLine = reader.readLine();
        }
        // look forward another first line
        String actualFirstLine = reader.readLine();
        if ((actualFirstLine != null) && (0 < actualFirstLine.length())) {
          // this is the actual first line
          setFirstLine(actualFirstLine);
        } else {
          return true;
        }
      }

      String headerLine = reader.readLine();
      while ((headerLine != null) && (0 < headerLine.length())) {
        HTTPHeader header = new HTTPHeader(headerLine);
        if (header.hasName() == true) setHeader(header);
        headerLine = reader.readLine();
      }

      if (onlyHeaders == true) {
        setContent("", false);
        return true;
      }

      boolean isChunkedRequest = isChunked();

      long contentLen = 0;
      if (isChunkedRequest == true) {
        try {
          String chunkSizeLine = reader.readLine();
          contentLen =
              Long.parseLong(new String(chunkSizeLine.getBytes(), 0, chunkSizeLine.length() - 2));
        } catch (Exception e) {
        }
        ;
      } else {
        if (getHeader(HTTP.CONTENT_LENGTH) != null) {
          contentLen = getContentLength();
        } else if ((getHeader(HTTP.CONNECTION) != null)
            && (getHeader(HTTP.CONNECTION).getValue().toLowerCase().indexOf("keep-alive") != -1)
            && (getHeader(HTTP.CONTENT_LENGTH) == null)) {
          contentLen = 0;
        } else {
          StringBuffer sb = new StringBuffer("");
          int ch;
          while ((ch = reader.read()) != -1) {
            sb.append((char) ch);
          }
          setContent(sb.toString());
          return true;
        }
      }
      StringBuffer contentBuf = new StringBuffer();

      while (0 < contentLen) {
        int chunkSize = HTTP.getChunkSize();
        char readBuf[] = new char[chunkSize];
        long readCnt = 0;
        while (readCnt < contentLen) {
          try {
            // Thanks for Mark Retallack (02/02/05)
            long bufReadLen = contentLen - readCnt;
            if (chunkSize < bufReadLen) bufReadLen = chunkSize;
            int readLen = reader.read(readBuf, 0, (int) bufReadLen);
            if (readLen < 0) break;
            contentBuf.append(new String(readBuf, 0, readLen));
            readCnt += readLen;
          } catch (Exception e) {
            Debug.warning(e);
            break;
          }
        }
        if (isChunkedRequest == true) {
          // skip CRLF
          long skipLen = 0;
          do {
            long skipCnt = reader.skip(HTTP.CRLF.length() - skipLen);
            if (skipCnt < 0) break;
            skipLen += skipCnt;
          } while (skipLen < HTTP.CRLF.length());
          // read next chunk size
          try {
            String chunkSizeLine = reader.readLine();
            contentLen =
                Long.parseLong(new String(chunkSizeLine.getBytes(), 0, chunkSizeLine.length() - 2));
          } catch (Exception e) {
            contentLen = 0;
          }
          ;
        } else contentLen = 0;
      }

      // Thanks for Ralf G. R. Bergs (02/09/04)
      String contentStr = contentBuf.toString();

      setContent(contentStr.getBytes(), false);
    } catch (Exception e) {
      Debug.warning(e);
      return false;
    }

    return true;
  }