void MythXmlCommand::execute(const CStdString& hostname, int port, const MythXmlCommandParameters& params, MythXmlCommandResult& result, int timeout){ CStdString strUrl = createRequestUrl(hostname, port, params); CStdString strXML; CCurlFile http; http.SetTimeout(timeout); if (http.Get(strUrl, strXML)) { CLog::Log(LOGDEBUG, "Got response from mythtv backend: %s", strUrl.c_str()); } http.Cancel(); result.parseData(strXML); }
void CRssReader::Process() { while (GetQueueSize()) { CSingleLock lock(m_critical); int iFeed = m_vecQueue.front(); m_vecQueue.erase(m_vecQueue.begin()); m_strFeed[iFeed].clear(); m_strColors[iFeed].clear(); CCurlFile http; http.SetUserAgent(g_advancedSettings.m_userAgent); http.SetTimeout(2); std::string strXML; std::string strUrl = m_vecUrls[iFeed]; lock.Leave(); int nRetries = 3; CURL url(strUrl); std::string fileCharset; // we wait for the network to come up if ((url.IsProtocol("http") || url.IsProtocol("https")) && !g_application.getNetwork().IsAvailable()) { CLog::Log(LOGWARNING, "RSS: No network connection"); strXML = "<rss><item><title>"+g_localizeStrings.Get(15301)+"</title></item></rss>"; } else { XbmcThreads::EndTime timeout(15000); while (!m_bStop && nRetries > 0) { if (timeout.IsTimePast()) { CLog::Log(LOGERROR, "Timeout while retrieving rss feed: %s", strUrl.c_str()); break; } nRetries--; if (!url.IsProtocol("http") && !url.IsProtocol("https")) { CFile file; auto_buffer buffer; if (file.LoadFile(strUrl, buffer) > 0) { 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; } else if (nRetries > 0) Sleep(5000); // Network problems? Retry, but not immediately. else CLog::Log(LOGERROR, "Unable to obtain rss feed: %s", strUrl.c_str()); } } http.Cancel(); } if (!strXML.empty() && m_pObserver) { // erase any <content:encoded> tags (also unsupported by tinyxml) size_t iStart = strXML.find("<content:encoded>"); size_t iEnd = 0; while (iStart != std::string::npos) { // get <content:encoded> end position iEnd = strXML.find("</content:encoded>", iStart) + 18; // erase the section strXML = strXML.erase(iStart, iEnd - iStart); iStart = strXML.find("<content:encoded>"); } if (Parse(strXML, iFeed, fileCharset)) CLog::Log(LOGDEBUG, "Parsed rss feed: %s", strUrl.c_str()); } } UpdateObserver(); }
void CRssReader::Process() { while (GetQueueSize()) { CSingleLock lock(*this); int iFeed = m_vecQueue.front(); m_vecQueue.erase(m_vecQueue.begin()); m_strFeed[iFeed] = ""; m_strColors[iFeed] = ""; CCurlFile http; http.SetUserAgent(g_settings.m_userAgent); http.SetTimeout(2); CStdString strXML; CStdString strUrl = m_vecUrls[iFeed]; lock.Leave(); int nRetries = 3; CURL url(strUrl); // we wait for the network to come up if ((url.GetProtocol() == "http" || url.GetProtocol() == "https") && !g_application.getNetwork().IsAvailable(true)) strXML = "<rss><item><title>"+g_localizeStrings.Get(15301)+"</title></item></rss>"; else { unsigned int starttime = XbmcThreads::SystemClockMillis(); while ( (!m_bStop) && (nRetries > 0) ) { unsigned int currenttimer = XbmcThreads::SystemClockMillis() - starttime; if (currenttimer > 15000) { CLog::Log(LOGERROR,"Timeout whilst retrieving %s", strUrl.c_str()); http.Cancel(); break; } nRetries--; if (url.GetProtocol() != "http" && url.GetProtocol() != "https") { CFile file; if (file.Open(strUrl)) { char *yo = new char[(int)file.GetLength()+1]; file.Read(yo,file.GetLength()); yo[file.GetLength()] = '\0'; strXML = yo; delete[] yo; break; } } else if (http.Get(strUrl, strXML)) { CLog::Log(LOGDEBUG, "Got rss feed: %s", strUrl.c_str()); break; } } http.Cancel(); } if ((!strXML.IsEmpty()) && m_pObserver) { // erase any <content:encoded> tags (also unsupported by tinyxml) int iStart = strXML.Find("<content:encoded>"); int iEnd = 0; while (iStart > 0) { // get <content:encoded> end position iEnd = strXML.Find("</content:encoded>", iStart) + 18; // erase the section strXML = strXML.erase(iStart, iEnd - iStart); iStart = strXML.Find("<content:encoded>"); } if (Parse((LPSTR)strXML.c_str(),iFeed)) { CLog::Log(LOGDEBUG, "Parsed rss feed: %s", strUrl.c_str()); } } } UpdateObserver(); }
bool CTuxBoxDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { // so we know that we have enigma2 static bool enigma2 = false; // Detect and delete slash at end CStdString strRoot = strPath; URIUtils::RemoveSlashAtEnd(strRoot); //Get the request strings CStdString strBQRequest; CStdString strXMLRootString; CStdString strXMLChildString; if(!GetRootAndChildString(strRoot, strBQRequest, strXMLRootString, strXMLChildString)) return false; //Set url Protocol CURL url(strRoot); CStdString strFilter; CStdString protocol = url.GetProtocol(); url.SetProtocol("http"); bool bIsBouquet=false; if (url.HasOption("path")) { // send Zap! return g_tuxbox.ZapToUrl(url, url.GetOption("path")); } else { if (url.HasOption("reference") || enigma2) { //List reference strFilter = url.GetOption("reference"); bIsBouquet = false; //On Empty is Bouquet if (enigma2) { CStdString strPort; strPort.Format(":%i",url.GetPort()); if (strRoot.Right(strPort.GetLength()) != strPort) // If not root dir, enable Channels strFilter = "e2"; // Disable Bouquets for Enigma2 GetRootAndChildStringEnigma2(strBQRequest, strXMLRootString, strXMLChildString); } url.SetOptions(""); url.SetFileName(strBQRequest); } } if(strFilter.IsEmpty()) { url.SetOptions(""); url.SetFileName(strBQRequest); bIsBouquet = true; } //Open CCurlFile http; int iTryConnect = 0; int iWaitTimer = 20; bool result = false; while (iTryConnect < 4) { http.SetTimeout(iWaitTimer); if(http.Open(url)) { //We are connected! iTryConnect = 4; // restore protocol url.SetProtocol(protocol); int size_read = 0; int size_total = (int)http.GetLength(); int data_size = 0; CStdString data; data.reserve(size_total); // read response from server into string buffer char buffer[16384]; while ((size_read = http.Read(buffer, sizeof(buffer)-1)) > 0) { buffer[size_read] = 0; data += buffer; data_size += size_read; } http.Close(); // parse returned xml CXBMCTinyXML doc; data.Replace("></",">-</"); //FILL EMPTY ELEMENTS WITH "-"! doc.Parse(data.c_str()); TiXmlElement *root = doc.RootElement(); if(root == NULL) { CLog::Log(LOGERROR, "%s - Unable to parse xml", __FUNCTION__); CLog::Log(LOGERROR, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str()); return false; } if( strXMLRootString.Equals(root->Value()) && bIsBouquet) { data.Empty(); if (enigma2) result = g_tuxbox.ParseBouquetsEnigma2(root, items, url, strFilter, strXMLChildString); else result = g_tuxbox.ParseBouquets(root, items, url, strFilter, strXMLChildString); } else if( strXMLRootString.Equals(root->Value()) && !strFilter.IsEmpty() ) { data.Empty(); if (enigma2) result = g_tuxbox.ParseChannelsEnigma2(root, items, url, strFilter, strXMLChildString); else result = g_tuxbox.ParseChannels(root, items, url, strFilter, strXMLChildString); } else { CLog::Log(LOGERROR, "%s - Invalid root xml element for TuxBox", __FUNCTION__); CLog::Log(LOGERROR, "%s - Sample follows...\n%s", __FUNCTION__, data.c_str()); data.Empty(); result = false; } } else { CLog::Log(LOGERROR, "%s - Unable to get XML structure! Try count:%i, Wait Timer:%is",__FUNCTION__, iTryConnect, iWaitTimer); iTryConnect++; if (iTryConnect == 2) //try enigma2 instead of enigma1, best entrypoint here i thought { enigma2 = true; GetRootAndChildStringEnigma2(strBQRequest, strXMLRootString, strXMLChildString); url.SetOptions(""); url.SetFileName(strBQRequest); // iTryConnect = 0; iWaitTimer = 20; } else iWaitTimer = iWaitTimer+10; result = false; http.Close(); // Close old connections } } items.SetContent("movies"); return result; }
void CRssReader::Process() { while (GetQueueSize()) { CSingleLock lock(m_critical); int iFeed = m_vecQueue.front(); m_vecQueue.erase(m_vecQueue.begin()); m_strFeed[iFeed] = ""; m_strColors[iFeed] = ""; CCurlFile http; http.SetUserAgent(g_advancedSettings.m_userAgent); http.SetTimeout(2); CStdString strXML; CStdString strUrl = m_vecUrls[iFeed]; lock.Leave(); int nRetries = 3; CURL url(strUrl); // we wait for the network to come up if ((url.GetProtocol() == "http" || url.GetProtocol() == "https") && !g_application.getNetwork().IsAvailable(true)) strXML = "<rss><item><title>"+g_localizeStrings.Get(15301)+"</title></item></rss>"; else { XbmcThreads::EndTime timeout(15000); while (!m_bStop && nRetries > 0) { if (timeout.IsTimePast()) { CLog::Log(LOGERROR, "Timeout whilst retrieving %s", strUrl.c_str()); http.Cancel(); break; } nRetries--; if (url.GetProtocol() != "http" && url.GetProtocol() != "https") { void* bufferPtr; const unsigned int fsize = CFileUtils::LoadFile(strUrl, bufferPtr); if (fsize != 0) { strXML.assign((const char*)bufferPtr, fsize); free(bufferPtr); break; } } else if (http.Get(strUrl, strXML)) { CLog::Log(LOGDEBUG, "Got rss feed: %s", strUrl.c_str()); break; } } http.Cancel(); } if (!strXML.IsEmpty() && m_pObserver) { // erase any <content:encoded> tags (also unsupported by tinyxml) int iStart = strXML.Find("<content:encoded>"); int iEnd = 0; while (iStart > 0) { // get <content:encoded> end position iEnd = strXML.Find("</content:encoded>", iStart) + 18; // erase the section strXML = strXML.erase(iStart, iEnd - iStart); iStart = strXML.Find("<content:encoded>"); } if (Parse((LPSTR)strXML.c_str(), iFeed)) CLog::Log(LOGDEBUG, "Parsed rss feed: %s", strUrl.c_str()); } } UpdateObserver(); }