Beispiel #1
0
bool CWin32SMBDirectory::GetNetworkResources(const CURL& basePath, CFileItemList& items)
{
  assert(basePath.GetShareName().empty()); // this function returns only servers or shares

  std::string hostName(basePath.GetHostName());
  if (hostName.empty())
    return localGetNetworkResources(NULL, basePath.Get(), items, false); // get all servers from network
  
  // get all shares from server
  std::string basePathStr(basePath.Get());
  if (basePathStr.empty())
    return false;
  if (basePathStr.back() != '/')
    basePathStr.push_back('/');

  std::wstring remoteName;
  if (!basePathStr.empty() && !g_charsetConverter.utf8ToW("\\\\" + basePath.GetHostName(), remoteName, false, false, true))
  {
    CLog::Log(LOGERROR, "%s: can't convert host name \"%s\" to wide character form", __FUNCTION__, basePath.GetHostName().c_str());
    return false;
  }

  _NETRESOURCEW netResBasePath = {};
  netResBasePath.dwScope = RESOURCE_GLOBALNET;
  netResBasePath.dwType = RESOURCETYPE_ANY;
  netResBasePath.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
  netResBasePath.dwUsage = RESOURCEUSAGE_CONTAINER;
  netResBasePath.lpRemoteName = (LPWSTR)remoteName.c_str();

  return localGetNetworkResources(&netResBasePath, basePathStr, items, true);
}
Beispiel #2
0
std::wstring CWIN32Util::ConvertPathToWin32Form(const CURL& url)
{
  assert(url.GetProtocol().empty() || url.IsProtocol("smb"));

  if (url.GetFileName().empty())
    return std::wstring(); // empty string

  if (url.GetProtocol().empty())
  {
    std::wstring result;
    if (g_charsetConverter.utf8ToW("\\\\?\\" +
          URIUtils::CanonicalizePath(URIUtils::FixSlashesAndDups(url.GetFileName(), '\\'), '\\'), result, false, false, true))
      return result;
  }
  else if (url.IsProtocol("smb"))
  {
    if (url.GetHostName().empty())
      return std::wstring(); // empty string
    
    std::wstring result;
    if (g_charsetConverter.utf8ToW("\\\\?\\UNC\\" +
          URIUtils::CanonicalizePath(URIUtils::FixSlashesAndDups(url.GetHostName() + '\\' + url.GetFileName(), '\\'), '\\'),
          result, false, false, true))
      return result;
  }
  else
    return std::wstring(); // unsupported protocol, return empty string

  CLog::Log(LOGERROR, "%s: Error converting path \"%s\" to Win32 form", __FUNCTION__, url.Get().c_str());
  return std::wstring(); // empty string
}
Beispiel #3
0
int CXbtFile::Stat(const CURL& url, struct __stat64* buffer)
{
  memset(buffer, 0, sizeof(struct __stat64));

  // check if the file exists
  CXBTFReaderPtr reader;
  CXBTFFile file;
  if (!GetReaderAndFile(url, reader, file))
  {
    // check if the URL points to the XBT file itself
    if (!url.GetFileName().empty() || !CFile::Exists(url.GetHostName()))
      return -1;

    // stat the XBT file itself
    if (XFILE::CFile::Stat(url.GetHostName(), buffer) != 0)
      return -1;

    buffer->st_mode = _S_IFDIR;
    return 0;
  }

  // stat the XBT file itself
  if (XFILE::CFile::Stat(url.GetHostName(), buffer) != 0)
    return -1;

  buffer->st_size = file.GetUnpackedSize();

  return 0;
}
Beispiel #4
0
//*********************************************************************************************
std::string CWINFileSMB::GetLocal(const CURL &url)
{
  std::string path(url.GetFileName());
  if (url.GetProtocol().Equals("smb", false) && !url.GetHostName().empty())
    path = "\\\\?\\UNC\\" + (std::string&)url.GetHostName() + "\\" + path;

  return path;
}
Beispiel #5
0
void CNfsConnection::resolveHost(const CURL &url)
{ 
  //resolve if hostname has changed
  if( !url.GetHostName().Equals(m_hostName) )
  {
    CDNSNameCache::Lookup(url.GetHostName(), m_resolvedHostName);
  }
}
Beispiel #6
0
bool CPluginSettings::Load(const CURL& url)
{
  m_url = url;  

  // create the users filepath
  m_userFileName.Format("P:\\plugin_data\\%s\\%s", url.GetHostName().c_str(), url.GetFileName().c_str());
  CUtil::RemoveSlashAtEnd(m_userFileName);
  CUtil::AddFileToFolder(m_userFileName, "settings.xml", m_userFileName);
  
  // Create our final path
  CStdString pluginFileName = "Q:\\plugins\\";

  CUtil::AddFileToFolder(pluginFileName, url.GetHostName(), pluginFileName);
  CUtil::AddFileToFolder(pluginFileName, url.GetFileName(), pluginFileName);

  // Replace the / at end, GetFileName() leaves a / at the end
  pluginFileName.Replace("/", "\\");

  CUtil::AddFileToFolder(pluginFileName, "resources", pluginFileName);
  CUtil::AddFileToFolder(pluginFileName, "settings.xml", pluginFileName);

  pluginFileName = _P(pluginFileName);
  m_userFileName = _P(m_userFileName);

  if (!m_pluginXmlDoc.LoadFile(pluginFileName.c_str()))
  {
    CLog::Log(LOGERROR, "Unable to load: %s, Line %d\n%s", pluginFileName.c_str(), m_pluginXmlDoc.ErrorRow(), m_pluginXmlDoc.ErrorDesc());
    return false;
  }
  
  // Make sure that the plugin XML has the settings element
  TiXmlElement *setting = m_pluginXmlDoc.RootElement();
  if (!setting || strcmpi(setting->Value(), "settings") != 0)
  {
    CLog::Log(LOGERROR, "Error loading Settings %s: cannot find root element 'settings'", pluginFileName.c_str());
    return false;
  }  
  
  // Load the user saved settings. If it does not exist, create it
  if (!m_userXmlDoc.LoadFile(m_userFileName.c_str()))
  {
    TiXmlDocument doc;
    TiXmlDeclaration decl("1.0", "UTF-8", "yes");
    doc.InsertEndChild(decl);
    
    TiXmlElement xmlRootElement("settings");
    doc.InsertEndChild(xmlRootElement);
    
    m_userXmlDoc = doc;
    
    // Don't worry about the actual settings, they will be set when the user clicks "Ok"
    // in the settings dialog
  }

  return true;
}
Beispiel #7
0
/*
 * For each new connection samba creates a new session
 * But this is not what we want, we just want to have one session at the time
 * This means that we have to call smbc_purge() if samba created a new session
 * Samba will create a new session when:
 * - connecting to another server
 * - connecting to another share on the same server (share, not a different folder!)
 *
 * We try to avoid lot's of purge commands because it slow samba down.
 */
void CSMB::PurgeEx(const CURL& url)
{
  CSingleLock lock(*this);
  CStdString strShare = url.GetFileName().substr(0, url.GetFileName().Find('/'));

#ifndef _LINUX
  if (m_strLastShare.length() > 0 && (m_strLastShare != strShare || m_strLastHost != url.GetHostName()))
    smbc_purge();
#endif

  m_strLastShare = strShare;
  m_strLastHost = url.GetHostName();
}
Beispiel #8
0
// check for empty string, remove trailing slash if any, convert to win32 form
inline static std::wstring prepareWin32SMBDirectoryName(const CURL& url)
{
  assert(url.GetProtocol() == "smb");

  if (url.GetHostName().empty() || url.GetShareName().empty())
    return std::wstring(); // can't use win32 standard file API, return empty string

  std::wstring nameW(CWIN32Util::ConvertPathToWin32Form("\\\\?\\UNC\\" + url.GetHostName() + '\\' + url.GetFileName()));
  if (!nameW.empty() && nameW.back() == L'\\')
    nameW.pop_back(); // remove slash at the end if any

  return nameW;
}
Beispiel #9
0
bool CNfsConnection::Connect(const CURL& url, CStdString &relativePath)
{
  CSingleLock lock(*this);
  bool ret = false;
  int nfsRet = 0;
  CStdString exportPath = "";

  resolveHost(url);
  ret = splitUrlIntoExportAndPath(url, exportPath, relativePath);
  
  if( (ret && (!exportPath.Equals(m_exportPath,true)  || 
      !url.GetHostName().Equals(m_hostName,false)))    ||
      (XbmcThreads::SystemClockMillis() - m_lastAccessedTime) > CONTEXT_TIMEOUT )
  {
    int contextRet = getContextForExport(url.GetHostName() + exportPath);
    
    if(contextRet == CONTEXT_INVALID)//we need a new context because sharename or hostname has changed
    {
      return false;
    }
    
    if(contextRet == CONTEXT_NEW) //new context was created - we need to mount it
    {
      //we connect to the directory of the path. This will be the "root" path of this connection then.
      //So all fileoperations are relative to this mountpoint...
      nfsRet = m_pLibNfs->nfs_mount(m_pNfsContext, m_resolvedHostName.c_str(), exportPath.c_str());

      if(nfsRet != 0) 
      {
        CLog::Log(LOGERROR,"NFS: Failed to mount nfs share: %s (%s)\n", exportPath.c_str(), m_pLibNfs->nfs_get_error(m_pNfsContext));
        destroyContext(url.GetHostName() + exportPath);
        return false;
      }
      CLog::Log(LOGDEBUG,"NFS: Connected to server %s and export %s\n", url.GetHostName().c_str(), exportPath.c_str());
    }
    m_exportPath = exportPath;
    m_hostName = url.GetHostName();
    //read chunksize only works after mount
    m_readChunkSize = m_pLibNfs->nfs_get_readmax(m_pNfsContext);
    m_writeChunkSize = m_pLibNfs->nfs_get_writemax(m_pNfsContext);

    if(contextRet == CONTEXT_NEW)
    {
      CLog::Log(LOGDEBUG,"NFS: chunks: r/w %i/%i\n", (int)m_readChunkSize,(int)m_writeChunkSize);          
    }
  }
  return ret; 
}
Beispiel #10
0
std::string CXbtManager::NormalizePath(const CURL& path)
{
  if (path.IsProtocol("xbt"))
    return path.GetHostName();

  return path.Get();
}
Beispiel #11
0
bool CResourceFile::TranslatePath(const CURL &url, std::string &translatedPath)
{
  translatedPath = url.Get();

  // only handle resource:// paths
  if (!url.IsProtocol("resource"))
    return false;

  // the share name represents an identifier that can be mapped to an addon ID
  std::string addonId = url.GetHostName();
  if (addonId.empty())
    return false;

  AddonPtr addon;
  if (!CAddonMgr::Get().GetAddon(addonId, addon, ADDON_UNKNOWN, true) || addon == NULL)
    return false;

  std::shared_ptr<CResource> resource = std::dynamic_pointer_cast<ADDON::CResource>(addon);
  if (resource == NULL)
    return false;

  std::string filePath = url.GetFileName();
  if (!resource->IsAllowed(filePath))
    return false;

  translatedPath = CUtil::ValidatePath(resource->GetFullPath(filePath));
  return true;
}
Beispiel #12
0
void CPluginDirectory::LoadPluginStrings(const CURL &url)
{
  // Path where the plugin resides
  CStdString pathToPlugin = "U:\\plugins\\";
  CUtil::AddFileToFolder(pathToPlugin, url.GetHostName(), pathToPlugin);
  CUtil::AddFileToFolder(pathToPlugin, url.GetFileName(), pathToPlugin);

  // Replace the / at end, GetFileName() leaves a / at the end
  pathToPlugin.Replace("/", "\\");

  // Path where the language strings reside
  CStdString pathToLanguageFile = pathToPlugin;
  CStdString pathToFallbackLanguageFile = pathToPlugin;
  CUtil::AddFileToFolder(pathToLanguageFile, "resources", pathToLanguageFile);
  CUtil::AddFileToFolder(pathToFallbackLanguageFile, "resources", pathToFallbackLanguageFile);
  CUtil::AddFileToFolder(pathToLanguageFile, "language", pathToLanguageFile);
  CUtil::AddFileToFolder(pathToFallbackLanguageFile, "language", pathToFallbackLanguageFile);
  CUtil::AddFileToFolder(pathToLanguageFile, g_guiSettings.GetString("region.language"), pathToLanguageFile);
  CUtil::AddFileToFolder(pathToFallbackLanguageFile, "english", pathToFallbackLanguageFile);
  CUtil::AddFileToFolder(pathToLanguageFile, "strings.xml", pathToLanguageFile);
  CUtil::AddFileToFolder(pathToFallbackLanguageFile, "strings.xml", pathToFallbackLanguageFile);

  // Load language strings temporarily
  g_localizeStringsTemp.Load(pathToLanguageFile, pathToFallbackLanguageFile);
}
Beispiel #13
0
bool CAndroidSettingDirectory::GetDirectory(const CURL& url, CFileItemList &items)
{
  std::string dirname = url.GetFileName();
  URIUtils::RemoveSlashAtEnd(dirname);
  int sdk = CJNIBase::GetSDKVersion();
  CLog::Log(LOGDEBUG, "CAndroidSettingDirectory::GetDirectory: %s (sdk:%d;intents:%d)",dirname.c_str(), sdk, m_intents.size());
  if (dirname == "settings")
  {
    for(size_t i=0; i < m_intents.size(); ++i)
    {
      int sdk = CJNIBase::GetSDKVersion();
      if (m_intents[i].sdk > sdk)
        continue;

      CFileItemPtr pItem(new CFileItem(m_intents[i].intent));
      pItem->m_bIsFolder = false;
      std::string path = StringUtils::Format("androidsetting://%s/%s/%s", url.GetHostName().c_str(), dirname.c_str(), m_intents[i].intent.c_str());
      pItem->SetPath(path);
      pItem->SetLabel(m_intents[i].name);
      pItem->SetArt("thumb", "DefaultProgram.png");
      items.Add(pItem);
    }
    return true;
  }

  CLog::Log(LOGERROR, "CAndroidSettingDirectory::GetDirectory Failed to open %s",url.Get().c_str());
  return false;
}
Beispiel #14
0
void CRarFile::InitFromUrl(const CURL& url)
{
  m_strCacheDir = g_advancedSettings.m_cachePath;//url.GetDomain();
  URIUtils::AddSlashAtEnd(m_strCacheDir);
  m_strRarPath = url.GetHostName();
  m_strPassword = url.GetUserName();
  m_strPathInRar = url.GetFileName();

  std::vector<std::string> options;
  if (!url.GetOptions().empty())
    StringUtils::Tokenize(url.GetOptions().substr(1), options, "&");

  m_bFileOptions = 0;

  for(std::vector<std::string>::iterator it = options.begin();it != options.end(); ++it)
  {
    size_t iEqual = (*it).find('=');
    if(iEqual != std::string::npos)
    {
      std::string strOption = StringUtils::Left((*it), iEqual);
      std::string strValue = StringUtils::Mid((*it), iEqual+1);

      if( strOption == "flags" )
        m_bFileOptions = atoi(strValue.c_str());
      else if( strOption == "cache" )
        m_strCacheDir = strValue;
    }
  }

}
Beispiel #15
0
bool CZipManager::GetZipEntry(const CURL& url, SZipEntry& item)
{
  std::string strFile = url.GetHostName();

  map<std::string,vector<SZipEntry> >::iterator it = mZipMap.find(strFile);
  vector<SZipEntry> items;
  if (it == mZipMap.end()) // we need to list the zip
  {
    GetZipList(url,items);
  }
  else
  {
    items = it->second;
  }

  std::string strFileName = url.GetFileName();
  for (vector<SZipEntry>::iterator it2=items.begin();it2 != items.end();++it2)
  {
    if (std::string(it2->name) == strFileName)
    {
      memcpy(&item,&(*it2),sizeof(SZipEntry));
      return true;
    }
  }
  return false;
}
Beispiel #16
0
bool CEventsDirectory::GetDirectory(const CURL& url, CFileItemList &items)
{
  items.ClearProperties();
  items.SetContent("events");

  CEventLog& log = CEventLog::GetInstance();
  Events events;

  std::string hostname = url.GetHostName();
  if (hostname.empty())
    events = log.Get();
  else
  {
    bool includeHigherLevels = false;
    // check if we should only retrieve events from a specific level or
    // also from all higher levels
    if (StringUtils::EndsWith(hostname, "+"))
    {
      includeHigherLevels = true;

      // remove the "+" from the end of the hostname
      hostname = hostname.substr(0, hostname.size() - 1);
    }

    EventLevel level = EventLevelFromString(hostname);

    // get the events of the specified level(s)
    events = log.Get(level, includeHigherLevels);
  }

  for (auto eventItem : events)
    items.Add(EventToFileItem(eventItem));

  return true;
}
Beispiel #17
0
bool CAndroidAppDirectory::GetDirectory(const CURL& url, CFileItemList &items)
{
  std::string dirname = url.GetFileName();
  URIUtils::RemoveSlashAtEnd(dirname);
  CLog::Log(LOGDEBUG, "CAndroidAppDirectory::GetDirectory: %s",dirname.c_str()); 
  if (dirname == "apps")
  {
    vector<androidPackage> applications;
    CXBMCApp::ListApplications(&applications);
    if (!applications.size())
    {
      CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Application lookup listing failed");
      return false;
    }
    for(unsigned int i = 0; i < applications.size(); i++)
    {
      if (applications[i].packageName == "org.xbmc.xbmc")
        continue;
      CFileItemPtr pItem(new CFileItem(applications[i].packageName));
      pItem->m_bIsFolder = false;
      std::string path = StringUtils::Format("androidapp://%s/%s/%s", url.GetHostName().c_str(), dirname.c_str(),  applications[i].packageName.c_str());
      pItem->SetPath(path);
      pItem->SetLabel(applications[i].packageLabel);
      pItem->SetArt("thumb", path+".png");
      items.Add(pItem);
    }
    return true;
  }

  CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Failed to open %s", url.Get().c_str());
  return false;
}
Beispiel #18
0
CURL CBlurayDirectory::GetUnderlyingCURL(const CURL& url)
{
  assert(url.IsProtocol("bluray"));
  std::string host = url.GetHostName();
  std::string filename = url.GetFileName();
  return CURL(host.append(filename));
}
Beispiel #19
0
//*********************************************************************************************
CStdString CHDFile::GetLocal(const CURL &url)
{
    CStdString path( url.GetFileName() );

    if( url.GetProtocol().Equals("file", false) )
    {
        // file://drive[:]/path
        // file:///drive:/path
        CStdString host( url.GetHostName() );

        if(host.size() > 0)
        {
            if(host.Right(1) == ":")
                path = host + "/" + path;
            else
                path = host + ":/" + path;
        }
    }

#ifdef TARGET_WINDOWS
    path.Insert(0, "\\\\?\\");
    path.Replace('/', '\\');
#endif

    if (IsAliasShortcut(path))
        TranslateAliasShortcut(path);

    return path;
}
Beispiel #20
0
void CFileRar::InitFromUrl(const CURL& url)
{
  m_strCacheDir = g_advancedSettings.m_cachePath;//url.GetDomain();
  CUtil::AddSlashAtEnd(m_strCacheDir);
  m_strRarPath = url.GetHostName();
  m_strPassword = url.GetUserName();
  m_strPathInRar = url.GetFileName();

  vector<CStdString> options;
  CUtil::Tokenize(url.GetOptions().Mid(1), options, "&");

  m_bFileOptions = 0;

  for( vector<CStdString>::iterator it = options.begin();it != options.end(); it++)
  {
    int iEqual = (*it).Find('=');
    if( iEqual >= 0 )
    {
      CStdString strOption = (*it).Left(iEqual);
      CStdString strValue = (*it).Mid(iEqual+1);

      if( strOption.Equals("flags") )
        m_bFileOptions = atoi(strValue.c_str());
      else if( strOption.Equals("cache") )
        m_strCacheDir = strValue;
    }
  }

}
Beispiel #21
0
void CWakeOnAccess::QueueMACDiscoveryForAllRemotes()
{
  vector<string> hosts;

  // add media sources
  CMediaSourceSettings& ms = CMediaSourceSettings::Get();

  AddHostsFromVecSource(ms.GetSources("video"), hosts);
  AddHostsFromVecSource(ms.GetSources("music"), hosts);
  AddHostsFromVecSource(ms.GetSources("files"), hosts);
  AddHostsFromVecSource(ms.GetSources("pictures"), hosts);
  AddHostsFromVecSource(ms.GetSources("programs"), hosts);

  // add mysql servers
  AddHostFromDatabase(g_advancedSettings.m_databaseVideo, hosts);
  AddHostFromDatabase(g_advancedSettings.m_databaseMusic, hosts);
  AddHostFromDatabase(g_advancedSettings.m_databaseEpg, hosts);
  AddHostFromDatabase(g_advancedSettings.m_databaseTV, hosts);

  // add from path substitutions ..
  for (CAdvancedSettings::StringMapping::iterator i = g_advancedSettings.m_pathSubstitutions.begin(); i != g_advancedSettings.m_pathSubstitutions.end(); ++i)
  {
    CURL url = i->second;

    AddHost (url.GetHostName(), hosts);
  }

  for (vector<string>::const_iterator it = hosts.begin(); it != hosts.end(); it++)
    QueueMACDiscoveryForHost(*it);
}
Beispiel #22
0
CStdString CWINSMBDirectory::URLEncode(const CURL &url)
{
  /* due to smb wanting encoded urls we have to build it manually */

  CStdString flat = "smb://";

  /* samba messes up of password is set but no username is set. don't know why yet */
  /* probably the url parser that goes crazy */
  if(url.GetUserName().length() > 0 /* || url.GetPassWord().length() > 0 */)
  {
    flat += url.GetUserName();
    flat += ":";
    flat += url.GetPassWord();
    flat += "@";
  }
  flat += url.GetHostName();

  /* okey sadly since a slash is an invalid name we have to tokenize */
  std::vector<CStdString> parts;
  std::vector<CStdString>::iterator it;
  CUtil::Tokenize(url.GetFileName(), parts, "/");
  for( it = parts.begin(); it != parts.end(); it++ )
  {
    flat += "/";
    flat += (*it);
  }

  /* okey options should go here, thou current samba doesn't support any */

  return flat;
}
Beispiel #23
0
void CWakeOnAccess::WakeUpHost(const CURL& url)
{
  CStdString hostName = url.GetHostName();

  if (!hostName.IsEmpty())
    WakeUpHost (hostName, url.Get());
}
Beispiel #24
0
bool CHomeRunFile::Open(const CURL &url)
{
  if(!m_pdll->IsLoaded())
    return false;

  m_device = m_pdll->device_create_from_str(url.GetHostName().c_str(), NULL);
  if(!m_device)
    return false;

  m_pdll->device_set_tuner_from_str(m_device, url.GetFileName().c_str());

  CUrlOptions options(url.GetOptions().Mid(1));
  CUrlOptions::iterator it;

  if( (it = options.find("channel")) != options.end() )
    m_pdll->device_set_tuner_channel(m_device, it->second.c_str());

  if( (it = options.find("program")) != options.end() )
    m_pdll->device_set_tuner_program(m_device, it->second.c_str());

  // start streaming from selected device and tuner
  if( m_pdll->device_stream_start(m_device) <= 0 )
    return false;

  return true;
}
Beispiel #25
0
StorageFolder CWinLibraryDirectory::GetRootFolder(const CURL& url)
{
  if (!url.IsProtocol("win-lib"))
    return nullptr;

  std::string lib = url.GetHostName();
  try
  {
    if (lib == "music")
      return KnownFolders::MusicLibrary();
    if (lib == "video")
      return KnownFolders::VideosLibrary();
    if (lib == "pictures")
      return KnownFolders::PicturesLibrary();
    if (lib == "photos")
      return KnownFolders::CameraRoll();
    if (lib == "documents")
      return KnownFolders::DocumentsLibrary();
    if (lib == "removable")
      return KnownFolders::RemovableDevices();
  }
  catch (const winrt::hresult_error& ex)
  {
    std::string strError = KODI::PLATFORM::WINDOWS::FromW(ex.message().c_str());
    CLog::LogF(LOGERROR, "unexpected error occurs during WinRT API call: {}", strError);
  }

  return nullptr;
}
Beispiel #26
0
CStdString CWIN32Util::URLEncode(const CURL &url)
{
  /* due to smb wanting encoded urls we have to build it manually */

  CStdString flat = "smb://";

  if(url.GetDomain().length() > 0)
  {
    flat += url.GetDomain();
    flat += ";";
  }

  /* samba messes up of password is set but no username is set. don't know why yet */
  /* probably the url parser that goes crazy */
  if(url.GetUserName().length() > 0 /* || url.GetPassWord().length() > 0 */)
  {
    flat += url.GetUserName();
    flat += ":";
    flat += url.GetPassWord();
    flat += "@";
  }
  else if( !url.GetHostName().IsEmpty() && !g_guiSettings.GetString("smb.username").IsEmpty() )
  {
    /* okey this is abit uggly to do this here, as we don't really only url encode */
    /* but it's the simplest place to do so */
    flat += g_guiSettings.GetString("smb.username");
    flat += ":";
    flat += g_guiSettings.GetString("smb.password");
    flat += "@";
  }

  flat += url.GetHostName();

  /* okey sadly since a slash is an invalid name we have to tokenize */
  std::vector<CStdString> parts;
  std::vector<CStdString>::iterator it;
  CUtil::Tokenize(url.GetFileName(), parts, "/");
  for( it = parts.begin(); it != parts.end(); it++ )
  {
    flat += "/";
    flat += (*it);
  }

  /* okey options should go here, thou current samba doesn't support any */

  return flat;
}
Beispiel #27
0
bool CAPKFile::Open(const CURL& url)
{
  Close();

  m_url = url;
  CStdString path = url.GetFileName();
  CStdString host = url.GetHostName();
  // host name might be encoded rfc1738.txt, decode it.
  CURL::Decode(host);

  int zip_flags = 0, zip_error = 0;
  m_zip_archive = zip_open(host.c_str(), zip_flags, &zip_error);
  if (!m_zip_archive || zip_error)
  {
    CLog::Log(LOGERROR, "CAPKFile::Open: Unable to open archive : '%s'",
      host.c_str());
    return false;
  }

  m_zip_index = zip_name_locate(m_zip_archive, path.c_str(), zip_flags);
  if (m_zip_index == -1)
  {
    // might not be an error if caller is just testing for presence/absence 
    CLog::Log(LOGDEBUG, "CAPKFile::Open: Unable to locate file : '%s'",
      path.c_str());
    zip_close(m_zip_archive);
    m_zip_archive = NULL;
    return false;
  }

  // cache the file size
  struct zip_stat sb;
  zip_stat_init(&sb);
  int rtn = zip_stat_index(m_zip_archive, m_zip_index, zip_flags, &sb);
  if (rtn == -1)
  {
    CLog::Log(LOGERROR, "CAPKFile::Open: Unable to stat file : '%s'",
      path.c_str());
    zip_close(m_zip_archive);
    m_zip_archive = NULL;
    return false;
  }
  m_file_pos = 0;
  m_file_size = sb.size;

  // finally open the file
  m_zip_file = zip_fopen_index(m_zip_archive, m_zip_index, zip_flags);
  if (!m_zip_file)
  {
    CLog::Log(LOGERROR, "CAPKFile::Open: Unable to open file : '%s'",
      path.c_str());
    zip_close(m_zip_archive);
    m_zip_archive = NULL;
    return false;
  }

  // We've successfully opened the file!
  return true;
}
Beispiel #28
0
// Android apk directory i/o. Depends on libzip
// Basically the same format as zip.
// We might want to refactor CZipDirectory someday...
//////////////////////////////////////////////////////////////////////
bool CAPKDirectory::GetDirectory(const CURL& url, CFileItemList &items)
{
    // uses a <fully qualified path>/filename.apk/...
    std::string path = url.GetFileName();
    std::string host = url.GetHostName();
    URIUtils::AddSlashAtEnd(path);

    int zip_flags = 0, zip_error = 0;
    struct zip *zip_archive;
    zip_archive = zip_open(host.c_str(), zip_flags, &zip_error);
    if (!zip_archive || zip_error)
    {
        CLog::Log(LOGERROR, "CAPKDirectory::GetDirectory: Unable to open archive : '%s'",
                  host.c_str());
        return false;
    }

    std::string test_name;
    int numFiles = zip_get_num_files(zip_archive);
    for (int zip_index = 0; zip_index < numFiles; zip_index++)
    {
        test_name = zip_get_name(zip_archive, zip_index, zip_flags);

        // check for non matching path.
        if (!StringUtils::StartsWith(test_name, path))
            continue;

        // libzip does not index folders, only filenames. We search for a /,
        // add it if it's not in our list already, and hope that no one has
        // any "file/name.exe" files in a zip.

        size_t dir_marker = test_name.find('/', path.size() + 1);
        if (dir_marker != std::string::npos)
        {
            // return items relative to path
            test_name=test_name.substr(0, dir_marker);

            if (items.Contains(host + "/" + test_name))
                continue;
        }

        struct zip_stat sb;
        zip_stat_init(&sb);
        if (zip_stat_index(zip_archive, zip_index, zip_flags, &sb) != -1)
        {
            g_charsetConverter.unknownToUTF8(test_name);
            CFileItemPtr pItem(new CFileItem(test_name));
            pItem->m_dwSize    = sb.size;
            pItem->m_dateTime  = sb.mtime;
            pItem->m_bIsFolder = dir_marker > 0 ;
            pItem->SetPath(host + "/" + test_name);
            pItem->SetLabel(test_name.substr(path.size()));
            items.Add(pItem);
        }
    }
    zip_close(zip_archive);

    return true;
}
Beispiel #29
0
/*
 * For each new connection samba creates a new session
 * But this is not what we want, we just want to have one session at the time
 * This means that we have to call smbc_purge() if samba created a new session
 * Samba will create a new session when:
 * - connecting to another server
 * - connecting to another share on the same server (share, not a different folder!)
 *
 * We try to avoid lot's of purge commands because it slow samba down.
 */
void CSMB::PurgeEx(const CURL& url)
{
  CSingleLock lock(*this);
  std::string strShare = url.GetFileName().substr(0, url.GetFileName().find('/'));

  m_strLastShare = strShare;
  m_strLastHost = url.GetHostName();
}
Beispiel #30
0
bool CWakeOnAccess::WakeUpHost(const CURL& url)
{
  std::string hostName = url.GetHostName();

  if (!hostName.empty())
    return WakeUpHost (hostName, url.Get());
  return true;
}