Esempio n. 1
0
bool CFileCurl::GetMimeType(const CURL &url, CStdString &content, CStdString useragent)
{
/*
	歌方:
		1、
		
	卦指:
		1、
		
	傍苧:
		1、
*/
	CFileCurl file;
	if (!useragent.IsEmpty())
		file.SetUserAgent(useragent);

	if( file.Stat(url, NULL) == 0 )
	{
		content = file.GetMimeType();
		CLog::Log(LOGDEBUG, "CFileCurl::GetMimeType - %s -> %s", url.Get().c_str(), content.c_str());
		return true;
	}
	
	CLog::Log(LOGDEBUG, "CFileCurl::GetMimeType - %s -> failed", url.Get().c_str());
	content = "";
	return false;
}
Esempio n. 2
0
bool CDVDInputStreamFile::Open(const char* strFile, const std::string& content)
{
    CStdString stdFile = strFile;

    CURI url(stdFile);
    if (!CDVDInputStream::Open(strFile, content)) return false;

    m_pFile = new CFile();
    if (!m_pFile) return false;

    unsigned int flags = READ_TRUNCATED;

    if( CFileItem(stdFile, false).IsInternetStream() )
        flags |= READ_CACHED;

    bool bOpen = false;

    // This is a workaround for HTML5 video content. we need to pass a user agent string from
    // the file item into the resulting file, but can only do this if we open ourselves
    if( m_item.m_strPath.Left(7).Equals("http://") ||
            m_item.m_strPath.Left(8).Equals("https://"))
    {
        CStdString extraInfo = m_item.GetExtraInfo();
        if( extraInfo && extraInfo.Left(11).Equals("User-Agent:") )
        {
            CFileCurl* curl = new CFileCurl();
            curl->SetUserAgent(extraInfo);
            if( !curl->Open(stdFile) )
            {
                delete m_pFile;
                m_pFile = NULL;
                return false;
            }

            // success - atttach to m_pfile
            m_pFile->Attach( curl, flags );
            curl = NULL;
            bOpen = true;
        }
    }


    // open file in binary mode
    if( !bOpen && !m_pFile->Open(stdFile, flags))
    {
        delete m_pFile;
        m_pFile = NULL;
        return false;
    }

    if (m_pFile->GetImplemenation() && (content.empty() || content == "application/octet-stream"))
        m_content = m_pFile->GetImplemenation()->GetContent();

    m_eof = true;
    return true;
}
Esempio n. 3
0
bool CFileCurl::GetMimeType(const CURL &url, CStdString &content, CStdString useragent)
{
  CFileCurl file;
  if (!useragent.IsEmpty())
    file.SetUserAgent(useragent);

  struct __stat64 buffer;
  if( file.Stat(url, &buffer) == 0 )
  {
    if (buffer.st_mode == _S_IFDIR)
      content = "x-directory/normal";
    else
      content = file.GetMimeType();
    CLog::Log(LOGDEBUG, "CFileCurl::GetMimeType - %s -> %s", url.Get().c_str(), content.c_str());
    return true;
  }
  CLog::Log(LOGDEBUG, "CFileCurl::GetMimeType - %s -> failed", url.Get().c_str());
  content = "";
  return false;
}
Esempio n. 4
0
bool CFileCurl::GetContent(const CURI &url, CStdString &content, CStdString useragent)
{
   CFileCurl file;
   if (!useragent.IsEmpty())
     file.SetUserAgent(useragent);

   if( file.Stat(url, NULL) == 0 )
   {
     content = file.GetContent();
     return true;
   }
   
   if (file.GetLastRetCode() > 400 )
   {
	 content = "text/html";
   }
   else
   {
   content = "";
   }

   return false;
}
Esempio n. 5
0
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] = "";

    CFileCurl 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 = CTimeUtils::GetTimeMS();
      while ( (!m_bStop) && (nRetries > 0) )
      {
        unsigned int currenttimer = CTimeUtils::GetTimeMS() - 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();
}