class log extends ActiveCacheInterface {
  // the main function of the applet
  public static int FromCache(String User_HTTP_Request,
                            String Client_IP_Address,
                            String Client_Name,
                            int Cache_File,
                            int New_File) {
    int fd;
    // create returns -1 if the object already exists
    fd = create(".log", 00700);
    if (fd == -1) {
      // if object already exists, just open it
      fd = open(".log", 9);
      if (fd == -1) {
        return -1;
      } else {
        int status = lock(fd);
        Log(User_HTTP_Request, Client_IP_Address, Client_Name, fd);
        status = unlock(fd);
        close(fd);
      }
    } else {
      // object not exists, but just created
      int status = lock(fd);
      Log(User_HTTP_Request, Client_IP_Address, Client_Name, fd);
      status = unlock(fd);
      close(fd);
    }
    return 0;
  }

  // convert a String into a byte array
  private static byte[] Convert(String str)
  {
    int i;
    byte buf[] = new byte[str.length()+1];
    for (i=0; i<str.length(); i++) {
      buf[i] = (byte)(str.charAt(i));
    }
    return buf;
  }

  // write access information into log object
  private static void Log(String User_HTTP_Request,
                            String Client_IP_Address,
                            String Client_Name,
                            int Log_File)
  {
    byte buf[];
    String thetime = curtime();
    buf = Convert(thetime);
    write(Log_File, buf, buf.length);
    buf = Convert(Client_Name);
    write(Log_File, buf, buf.length);
    buf = Convert(Client_IP_Address);
    write(Log_File, buf, buf.length);
    buf = Convert(User_HTTP_Request);
    write(Log_File, buf, buf.length);
  }
}