Example #1
0
bool CFile::Rename(const CURL& url, const CURL& urlnew)
{
  smb.Init();
  CStdString strFile = GetAuthenticatedPath(url);
  CStdString strFileNew = GetAuthenticatedPath(urlnew);
  CLockObject lock(smb);

  int result = smbc_rename(strFile.c_str(), strFileNew.c_str());

  if(result != 0)
    XBMC->Log(LOG_ERROR, "%s - Error( %s )", __FUNCTION__, strerror(errno));

  return (result == 0);
}
Example #2
0
bool Rename(VFSURL* url, VFSURL* url2)
{
  CSMB2::Get().Init();
  std::string strFile = GetAuthenticatedPath(url);
  std::string strFileNew = GetAuthenticatedPath(url2);
  PLATFORM::CLockObject lock(CSMB2::Get());

  int result = smbc_rename(strFile.c_str(), strFileNew.c_str());

  if(result != 0)
    XBMC->Log(ADDON::LOG_ERROR, "%s - Error( %s )", __FUNCTION__, strerror(errno));

  return (result == 0);
}
Example #3
0
bool CFile::OpenForWrite(const CURL& url, bool bOverWrite)
{
  m_fileSize = 0;

  Close();
  smb.Init();
  // we can't open files like smb://file.f or smb://server/file.f
  // if a file matches the if below return false, it can't exist on a samba share.
  if (!IsValidFile(url.GetFileName())) return false;

  CStdString strFileName = GetAuthenticatedPath(url);
  CLockObject lock(smb);

  if (bOverWrite)
  {
    XBMC->Log(LOG_WARNING, "FileSmb::OpenForWrite() called with overwriting enabled! - %s", strFileName.c_str());
    m_fd = smbc_creat(strFileName.c_str(), 0);
  }
  else
  {
    m_fd = smbc_open(strFileName.c_str(), O_RDWR, 0);
  }

  if (m_fd == -1)
  {
    // write error to logfile
    XBMC->Log(LOG_ERROR, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strFileName.c_str(), errno, strerror(errno));
    return false;
  }

  // We've successfully opened the file!
  return true;
}
Example #4
0
void* OpenForWrite(VFSURL* url, bool bOverWrite)
{ 
  CSMB2::Get().Init();
  // we can't open files like smb://file.f or smb://server/file.f
  // if a file matches the if below return false, it can't exist on a samba share.
  if (!IsValidFile(url->filename))
    return NULL;

  std::string strFileName = GetAuthenticatedPath(url);
  PLATFORM::CLockObject lock(CSMB2::Get());

  SMBContext* result = new SMBContext;
  if (bOverWrite)
  {
    XBMC->Log(ADDON::LOG_INFO, "FileSmb::OpenForWrite() called with overwriting enabled! - %s", strFileName.c_str());
    result->fd = smbc_creat(strFileName.c_str(), 0);
  }
  else
  {
    result->fd = smbc_open(strFileName.c_str(), O_RDWR, 0);
  }

  if (result->fd == -1)
  {
    // write error to logfile
    XBMC->Log(ADDON::LOG_ERROR, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", strFileName.c_str(), errno, strerror(errno));
    delete result;
    return NULL;
  }

  // We've successfully opened the file!
  return result;
}
Example #5
0
int Stat(VFSURL* url, struct __stat64* buffer)
{
  CSMB2::Get().Init();
  std::string strFileName = GetAuthenticatedPath(url);
  PLATFORM::CLockObject lock(CSMB2::Get());

  struct stat tmpBuffer = {0};
  int iResult = smbc_stat(strFileName.c_str(), &tmpBuffer);

  if (buffer)
  {
    memset(buffer, 0, sizeof(struct __stat64));
    buffer->st_dev = tmpBuffer.st_dev;
    buffer->st_ino = tmpBuffer.st_ino;
    buffer->st_mode = tmpBuffer.st_mode;
    buffer->st_nlink = tmpBuffer.st_nlink;
    buffer->st_uid = tmpBuffer.st_uid;
    buffer->st_gid = tmpBuffer.st_gid;
    buffer->st_rdev = tmpBuffer.st_rdev;
    buffer->st_size = tmpBuffer.st_size;
    buffer->st_atime = tmpBuffer.st_atime;
    buffer->st_mtime = tmpBuffer.st_mtime;
    buffer->st_ctime = tmpBuffer.st_ctime;
  }

  return iResult;
}
Example #6
0
//int CFile::OpenFile(const CURL &url, CStdString& strAuth)
int CFile::OpenFile()
{
  int fd = -1;
  smb.Init();

  //strAuth = GetAuthenticatedPath(url);
  //CStdString strPath = strAuth;
  CStdString strPath = m_fileName;

  {
    CLockObject lock(smb);
    fd = smbc_open(strPath.c_str(), O_RDONLY, 0);
  }

  // file open failed, try to open the directory to force authentication
  if (fd < 0 && errno == EACCES)
  {
#if 0
    CURL urlshare(url);

    /* just replace the filename with the sharename */
    urlshare.SetFileName(url.GetShareName());

    CSMBDirectory smbDir;
    // TODO: Currently we always allow prompting on files.  This may need to
    // change in the future as background scanners are more prolific.
    smbDir.SetFlags(DIR_FLAG_ALLOW_PROMPT);
    fd = smbDir.Open(urlshare);

    // directory open worked, try opening the file again
    if (fd >= 0)
    {
      CLockObject lock(smb);
      // close current directory filehandle
      // dont need to purge since its the same server and share
      smbc_closedir(fd);

      // set up new filehandle (as CFile::Open does)
      strPath = GetAuthenticatedPath(url);

      fd = smbc_open(strPath.c_str(), O_RDONLY, 0);
    }
#else
  XBMC->Log(LOG_ERROR, "%s: File open on %s failed\n", __FUNCTION__, strPath.c_str());
#endif
  }

//  if (fd >= 0)
//    strAuth = strPath;

  return fd;
}
Example #7
0
bool Exists(VFSURL* url)
{
  // we can't open files like smb://file.f or smb://server/file.f
  // if a file matches the if below return false, it can't exist on a samba share.
  if (!IsValidFile(url->filename))
    return false;

  CSMB2::Get().Init();
  std::string strFileName = GetAuthenticatedPath(url);

  struct stat info;

  CSMB2& smb = CSMB2::Get();

  PLATFORM::CLockObject lock(smb);
  int iResult = smbc_stat(strFileName.c_str(), &info);

  if (iResult < 0)
    return false;

  return true;
}
Example #8
0
int CFile::Stat(const CURL& url, struct stat64* buffer)
{
  smb.Init();
  CStdString strFileName = GetAuthenticatedPath(url);
  CLockObject lock(smb);

  struct stat tmpBuffer = {0};
  int iResult = smbc_stat(strFileName, &tmpBuffer);

  memset(buffer, 0, sizeof(struct stat64));
  buffer->st_dev = tmpBuffer.st_dev;
  buffer->st_ino = tmpBuffer.st_ino;
  buffer->st_mode = tmpBuffer.st_mode;
  buffer->st_nlink = tmpBuffer.st_nlink;
  buffer->st_uid = tmpBuffer.st_uid;
  buffer->st_gid = tmpBuffer.st_gid;
  buffer->st_rdev = tmpBuffer.st_rdev;
  buffer->st_size = tmpBuffer.st_size;
  buffer->st_atime = tmpBuffer.st_atime;
  buffer->st_mtime = tmpBuffer.st_mtime;
  buffer->st_ctime = tmpBuffer.st_ctime;

  return iResult;
}
Example #9
0
void* Open(VFSURL* url)
{
  CSMB2::Get().Init();
  CSMB2::Get().AddActiveConnection();
  if (!IsValidFile(url->filename))
  {
    XBMC->Log(ADDON::LOG_INFO, "FileSmb->Open: Bad URL : '%s'",url->redacted);
    return NULL;
  }
  int fd = -1;
  std::string filename = GetAuthenticatedPath(url);
  PLATFORM::CLockObject lock(CSMB2::Get());
  fd = smbc_open(filename.c_str(), O_RDONLY, 0);
  if (fd == -1)
  {
    XBMC->Log(ADDON::LOG_INFO, "FileSmb->Open: Unable to open file : '%s'\nunix_err:'%x' error : '%s'", url->redacted, errno, strerror(errno));
    return NULL;
  }
  XBMC->Log(ADDON::LOG_DEBUG,"CSMB2File::Open - opened %s, fd=%d", url->filename, fd);
  struct stat tmpBuffer;
  if (smbc_stat(filename.c_str(), &tmpBuffer) < 0)
  {
    smbc_close(fd);
    return NULL;
  }
  int64_t ret = smbc_lseek(fd, 0, SEEK_SET);
  if (ret < 0)
  {
    smbc_close(fd);
    return NULL;
  }
  SMBContext* result = new SMBContext;
  result->fd = fd;
  result->size = tmpBuffer.st_size;
  return result;
}