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(); }