int nRetries = 3;
CURL url(strUrl);
+ std::string fileCharset;
// we wait for the network to come up
if ((url.GetProtocol() == "http" || url.GetProtocol() == "https") &&
if (url.GetProtocol() != "http" && url.GetProtocol() != "https")
{
- void* bufferPtr;
- const unsigned int fsize = CFileUtils::LoadFile(strUrl, bufferPtr);
- if (fsize != 0)
+ CFile file;
+ auto_buffer buffer;
+ if (file.LoadFile(strUrl, buffer))
{
- strXML.assign((const char*)bufferPtr, fsize);
- free(bufferPtr);
+ strXML.assign(buffer.get(), buffer.length());
break;
}
}
else
if (http.Get(strUrl, strXML))
{
+ fileCharset = http.GetServerReportedCharset();
CLog::Log(LOGDEBUG, "Got rss feed: %s", strUrl.c_str());
break;
}
iStart = strXML.Find("<content:encoded>");
}
- // TODO: Use server reported charset
- if (Parse((LPSTR)strXML.c_str(), iFeed))
+ if (Parse(strXML, iFeed, fileCharset))
CLog::Log(LOGDEBUG, "Parsed rss feed: %s", strUrl.c_str());
}
}
CStdStringW unicodeText, unicodeText2;
- fromRSSToUTF16(htmlText, unicodeText2);
+ g_charsetConverter.utf8ToW(htmlText, unicodeText2, m_rtlText);
html.ConvertHTMLToW(unicodeText2, unicodeText);
mTagElements.insert(StrPair(*i, unicodeText));
}
}
-void CRssReader::fromRSSToUTF16(const CStdStringA& strSource, CStdStringW& strDest)
-{
- CStdString flippedStrSource, strSourceUtf8;
-
- g_charsetConverter.ToUtf8(m_encoding, strSource, strSourceUtf8);
- if (m_rtlText)
- g_charsetConverter.utf8logicalToVisualBiDi(strSourceUtf8, flippedStrSource);
- else
- flippedStrSource = strSourceUtf8;
- g_charsetConverter.utf8ToW(flippedStrSource, strDest, false);
-}
-
-bool CRssReader::Parse(LPSTR szBuffer, int iFeed)
+bool CRssReader::Parse(const std::string& data, int iFeed, const std::string& charset)
{
m_xml.Clear();
- m_xml.Parse((LPCSTR)szBuffer);
- m_encoding = "UTF-8"; // TODO: remove member variable
+ m_xml.Parse(data, charset);
CLog::Log(LOGDEBUG, "RSS feed encoding: %s", m_xml.GetUsedCharset().c_str());
{
CStdString strChannel = titleNode->FirstChild()->Value();
CStdStringW strChannelUnicode;
- fromRSSToUTF16(strChannel, strChannelUnicode);
+ g_charsetConverter.utf8ToW(strChannel, strChannelUnicode, m_rtlText);
AddString(strChannelUnicode, RSS_COLOR_CHANNEL, iFeed);
AddString(":", RSS_COLOR_CHANNEL, iFeed);
virtual ~CRssReader();
void Create(IRssObserver* aObserver, const std::vector<std::string>& aUrl, const std::vector<int>& times, int spacesBetweenFeeds, bool rtl);
- bool Parse(LPSTR szBuffer, int iFeed);
+ bool Parse(const std::string& data, int iFeed, const std::string& charset);
void getFeed(vecText &text);
void AddTag(const CStdString &addTag);
void AddToQueue(int iAdd);
unsigned int m_SavedScrollPos;
private:
- void fromRSSToUTF16(const CStdStringA& strSource, CStdStringW& strDest);
void Process();
bool Parse(int iFeed);
void GetNewsItems(TiXmlElement* channelXmlNode, int iFeed);
std::vector<std::string> m_vecUrls;
std::vector<int> m_vecQueue;
bool m_bIsRunning;
- CStdString m_encoding;
bool m_rtlText;
bool m_requestRefresh;