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; } } }
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; } } }
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; }
bool CXbtFile::Open(const CURL& url) { if (m_open) return false; std::string options = url.GetOptions(); CURL xbtUrl(url); xbtUrl.SetOptions(""); if (!GetReaderAndFile(url, m_xbtfReader, m_xbtfFile)) return false; m_url = url; m_open = true; uint64_t frameStartPosition = 0; const auto& frames = m_xbtfFile.GetFrames(); for (const auto& frame : frames) { m_frameStartPositions.push_back(frameStartPosition); frameStartPosition += frame.GetUnpackedSize(); } m_frameIndex = 0; m_positionWithinFrame = 0; m_positionTotal = 0; m_unpackedFrames.assign(frames.size(), nullptr); return true; }
bool CFileZip::Open(const CURL&url) { CStdString strOpts = url.GetOptions(); CURL url2(url); url2.SetOptions(""); CStdString strPath = url2.Get(); if (!g_ZipManager.GetZipEntry(strPath,mZipItem)) return false; if ((mZipItem.flags & 64) == 64) { CLog::Log(LOGERROR,"FileZip: encrypted file, not supported!"); return false; } if ((mZipItem.method != 8) && (mZipItem.method != 0)) { CLog::Log(LOGERROR,"FileZip: unsupported compression method!"); return false; } if (mZipItem.method != 0 && mZipItem.usize > ZIP_CACHE_LIMIT && strOpts != "?cache=no") { if (!CFile::Exists("special://temp/" + URIUtils::GetFileName(strPath))) { url2.SetOptions("?cache=no"); if (!CFile::Cache(url2.Get(), "special://temp/" + URIUtils::GetFileName(strPath))) return false; } m_bCached = true; return mFile.Open("special://temp/" + URIUtils::GetFileName(strPath)); } if (!mFile.Open(url.GetHostName())) // this is the zip-file, always open binary { CLog::Log(LOGERROR,"FileZip: unable to open zip file %s!",url.GetHostName().c_str()); return false; } mFile.Seek(mZipItem.offset,SEEK_SET); return InitDecompress(); }
CVFSURLWrapper(const CURL& url2) { m_strings.push_back(url2.Get()); m_strings.push_back(url2.GetDomain()); m_strings.push_back(url2.GetHostName()); m_strings.push_back(url2.GetFileName()); m_strings.push_back(url2.GetOptions()); m_strings.push_back(url2.GetUserName()); m_strings.push_back(url2.GetPassWord()); m_strings.push_back(url2.GetRedacted()); m_strings.push_back(url2.GetShareName()); url.url = m_strings[0].c_str(); url.domain = m_strings[1].c_str(); url.hostname = m_strings[2].c_str(); url.filename = m_strings[3].c_str(); url.port = url2.GetPort(); url.options = m_strings[4].c_str(); url.username = m_strings[5].c_str(); url.password = m_strings[6].c_str(); url.redacted = m_strings[7].c_str(); url.sharename = m_strings[8].c_str(); }
void CCurlFile::ParseAndCorrectUrl(CURL &url2) { CStdString strProtocol = url2.GetTranslatedProtocol(); url2.SetProtocol(strProtocol); if( strProtocol.Equals("ftp") || strProtocol.Equals("ftps") ) { /* this is uggly, depending on from where */ /* we get the link it may or may not be */ /* url encoded. if handed from ftpdirectory */ /* it won't be so let's handle that case */ CStdString partial, filename(url2.GetFileName()); CStdStringArray array; /* our current client doesn't support utf8 */ g_charsetConverter.utf8ToStringCharset(filename); /* TODO: create a tokenizer that doesn't skip empty's */ CUtil::Tokenize(filename, array, "/"); filename.Empty(); for(CStdStringArray::iterator it = array.begin(); it != array.end(); it++) { if(it != array.begin()) filename += "/"; partial = *it; CURL::Encode(partial); filename += partial; } /* make sure we keep slashes */ if(url2.GetFileName().Right(1) == "/") filename += "/"; url2.SetFileName(filename); CStdString options = url2.GetOptions().Mid(1); options.TrimRight('/'); // hack for trailing slashes being added from source m_ftpauth = ""; m_ftpport = ""; m_ftppasvip = false; /* parse options given */ CUtil::Tokenize(options, array, "&"); for(CStdStringArray::iterator it = array.begin(); it != array.end(); it++) { CStdString name, value; int pos = it->Find('='); if(pos >= 0) { name = it->Left(pos); value = it->Mid(pos+1, it->size()); } else { name = (*it); value = ""; } if(name.Equals("auth")) { m_ftpauth = value; if(m_ftpauth.IsEmpty()) m_ftpauth = "any"; } else if(name.Equals("active")) { m_ftpport = value; if(value.IsEmpty()) m_ftpport = "-"; } else if(name.Equals("pasvip")) { if(value == "0") m_ftppasvip = false; else m_ftppasvip = true; } } /* ftp has no options */ url2.SetOptions(""); } else if( strProtocol.Equals("http") || strProtocol.Equals("https")) { if (g_guiSettings.GetBool("network.usehttpproxy") && !g_guiSettings.GetString("network.httpproxyserver").empty() && !g_guiSettings.GetString("network.httpproxyport").empty() && m_proxy.IsEmpty()) { m_proxy = g_guiSettings.GetString("network.httpproxyserver"); m_proxy += ":" + g_guiSettings.GetString("network.httpproxyport"); if (g_guiSettings.GetString("network.httpproxyusername").length() > 0 && m_proxyuserpass.IsEmpty()) { m_proxyuserpass = g_guiSettings.GetString("network.httpproxyusername"); m_proxyuserpass += ":" + g_guiSettings.GetString("network.httpproxypassword"); } m_proxytype = (ProxyType)g_guiSettings.GetInt("network.httpproxytype"); CLog::Log(LOGDEBUG, "Using proxy %s, type %d", m_proxy.c_str(), proxyType2CUrlProxyType[m_proxytype]); } // get username and password m_username = url2.GetUserName(); m_password = url2.GetPassWord(); // handle any protocol options CStdString options = url2.GetProtocolOptions(); options.TrimRight('/'); // hack for trailing slashes being added from source if (options.length() > 0) { // clear protocol options url2.SetProtocolOptions(""); // set xbmc headers CStdStringArray array; CUtil::Tokenize(options, array, "&"); for(CStdStringArray::iterator it = array.begin(); it != array.end(); it++) { // parse name, value CStdString name, value; int pos = it->Find('='); if(pos >= 0) { name = it->Left(pos); value = it->Mid(pos+1, it->size()); } else { name = (*it); value = ""; } // url decode value CURL::Decode(value); if(name.Equals("auth")) { m_httpauth = value; if(m_httpauth.IsEmpty()) m_httpauth = "any"; } else if (name.Equals("Referer")) SetReferer(value); else if (name.Equals("User-Agent")) SetUserAgent(value); else if (name.Equals("Cookie")) SetCookie(value); else if (name.Equals("Encoding")) SetContentEncoding(value); else if (name.Equals("noshout") && value.Equals("true")) m_skipshout = true; else SetRequestHeader(name, value); } } } if (m_username.length() > 0 && m_password.length() > 0) m_url = url2.GetWithoutUserDetails(); else m_url = url2.Get(); }
void CCurlFile::ParseAndCorrectUrl(CURL &url2) { CStdString strProtocol = url2.GetTranslatedProtocol(); url2.SetProtocol(strProtocol); if( strProtocol.Equals("ftp") || strProtocol.Equals("ftps") ) { // we was using url optons for urls, keep the old code work and warning if (!url2.GetOptions().IsEmpty()) { CLog::Log(LOGWARNING, "%s: ftp url option is deprecated, please switch to use protocol option (change '?' to '|'), url: [%s]", __FUNCTION__, url2.Get().c_str()); url2.SetProtocolOptions(url2.GetOptions().Mid(1)); /* ftp has no options */ url2.SetOptions(""); } /* this is uggly, depending on from where */ /* we get the link it may or may not be */ /* url encoded. if handed from ftpdirectory */ /* it won't be so let's handle that case */ CStdString partial, filename(url2.GetFileName()); CStdStringArray array; // if server sent us the filename in non-utf8, we need send back with same encoding. if (url2.GetProtocolOption("utf8") == "0") g_charsetConverter.utf8ToStringCharset(filename); /* TODO: create a tokenizer that doesn't skip empty's */ CUtil::Tokenize(filename, array, "/"); filename.Empty(); for(CStdStringArray::iterator it = array.begin(); it != array.end(); it++) { if(it != array.begin()) filename += "/"; partial = *it; CURL::Encode(partial); filename += partial; } /* make sure we keep slashes */ if(url2.GetFileName().Right(1) == "/") filename += "/"; url2.SetFileName(filename); m_ftpauth = ""; if (url2.HasProtocolOption("auth")) { m_ftpauth = url2.GetProtocolOption("auth"); if(m_ftpauth.IsEmpty()) m_ftpauth = "any"; } m_ftpport = ""; if (url2.HasProtocolOption("active")) { m_ftpport = url2.GetProtocolOption("active"); if(m_ftpport.IsEmpty()) m_ftpport = "-"; } m_ftppasvip = url2.HasProtocolOption("pasvip") && url2.GetProtocolOption("pasvip") != "0"; } else if( strProtocol.Equals("http") || strProtocol.Equals("https")) { if (CSettings::Get().GetBool("network.usehttpproxy") && !CSettings::Get().GetString("network.httpproxyserver").empty() && !CSettings::Get().GetString("network.httpproxyport").empty() && m_proxy.IsEmpty()) { m_proxy = CSettings::Get().GetString("network.httpproxyserver"); m_proxy += ":" + CSettings::Get().GetString("network.httpproxyport"); if (CSettings::Get().GetString("network.httpproxyusername").length() > 0 && m_proxyuserpass.IsEmpty()) { m_proxyuserpass = CSettings::Get().GetString("network.httpproxyusername"); m_proxyuserpass += ":" + CSettings::Get().GetString("network.httpproxypassword"); } m_proxytype = (ProxyType)CSettings::Get().GetInt("network.httpproxytype"); CLog::Log(LOGDEBUG, "Using proxy %s, type %d", m_proxy.c_str(), proxyType2CUrlProxyType[m_proxytype]); } // get username and password m_username = url2.GetUserName(); m_password = url2.GetPassWord(); // handle any protocol options std::map<CStdString, CStdString> options; url2.GetProtocolOptions(options); if (options.size() > 0) { // clear protocol options url2.SetProtocolOptions(""); // set xbmc headers for(std::map<CStdString, CStdString>::const_iterator it = options.begin(); it != options.end(); ++it) { const CStdString &name = it->first; CStdString value = it->second; // url decode value CURL::Decode(value); if(name.Equals("auth")) { m_httpauth = value; if(m_httpauth.IsEmpty()) m_httpauth = "any"; } else if (name.Equals("Referer")) SetReferer(value); else if (name.Equals("User-Agent")) SetUserAgent(value); else if (name.Equals("Cookie")) SetCookie(value); else if (name.Equals("Encoding")) SetContentEncoding(value); else if (name.Equals("noshout") && value.Equals("true")) m_skipshout = true; else if (name.Equals("seekable") && value.Equals("0")) m_seekable = false; else SetRequestHeader(name, value); } } } if (m_username.length() > 0 && m_password.length() > 0) m_url = url2.GetWithoutUserDetails(); else m_url = url2.Get(); }