Example #1
0
/* returns filename extension including period of filename */
const CStdString URIUtils::GetExtension(const CStdString& strFileName)
{
  if(IsURL(strFileName))
  {
    CURL url(strFileName);
    return GetExtension(url.GetFileName());
  }

  int period = strFileName.find_last_of('.');
  if(period >= 0)
  {
    if( strFileName.find_first_of('/', period+1) != string::npos ) return "";
    if( strFileName.find_first_of('\\', period+1) != string::npos ) return "";
    return strFileName.substr(period);
  }
  else
    return "";
}
Example #2
0
BYTE CMapFile::GetObjectAddress( const char * cObjName, DWORD * addr ){
  CStdString sAux;
  CStdString sFindObj;
  int i;
  char cBuffer[512];
  int j;
  DWORD dwRet;

  if ( fIn.bad() == true ){
    return FALSE;
  }

  sFindObj.Format( " %s ", cObjName );
  while( fIn.eof() == false ){
    fIn.getline( cBuffer, sizeof( cBuffer ) );

    sAux = cBuffer;

    if ( sAux.find( sFindObj.c_str() ) != std::string::npos ){
      break;
    }
  }

  if ( fIn.eof() ){
    return FALSE;
  }

  i = sAux.find_first_of( "0x" );
  if ( i == std::string::npos ){
    return -1;
  }
  i+= 2;

  j = sAux.find_first_of( " ", i ); 

  sFindObj = sAux.substr( i, j-i );


  dwRet = atohex( sFindObj.c_str() );

  *addr = dwRet;

  return TRUE;
}
Example #3
0
/*
 * Function takes the title of a show, and a folder to search in
 * returns a path to the artwork in the form of 'special://home/cache/folder/image.jpg'
 */
CStdString fileOps::getArtworkPath ( CStdString title, FILE_OPTIONS Get_What )
{
  CStdString retPath;
  if (title.IsEmpty()) 
    return retPath;
  
  CStdString awGroup;
  if (Get_What == FILE_OPS_GET_CHAN_ICONS)
    awGroup = "channels";
  else if (Get_What == FILE_OPS_GET_COVERART)
    awGroup = "coverart";
  else if (Get_What == FILE_OPS_GET_FANART)
    awGroup = "fanart";
  else
    return retPath;
  
  if (Get_What == FILE_OPS_GET_CHAN_ICONS) 
  {
    CURL someUrl(title);
    title = someUrl.GetFileNameWithoutPath();
  }
  else {
    int mrkrPos = title.find_first_of("::");
    if (mrkrPos<=0)
      mrkrPos=title.length();
    
    title = title.Left(mrkrPos);
  }
  
  XBMC->Log(LOG_DEBUG,"%s - ## - Checking for Artwork File - %s - in - %s - ##",
	    __FUNCTION__, title.c_str(), awGroup.c_str());
  
  retPath = checkFolderForTitle(title,awGroup);
  
  if (retPath.IsEmpty() && isMyth)
  {
    // If still no result check if we can sync with mythbackends storage group and try again
    if (!mythConP.IsConnected()) 
    {
      XBMC->Log(LOG_DEBUG,"%s - ###########Not connected to mythbackend#######", __FUNCTION__);
      return retPath;
    }
    
    if (Get_What == FILE_OPS_GET_CHAN_ICONS) 
    {
      GetFileFromBackend(title,"channels");
    }
    else
    {
      syncSGCache(awGroup); //Thread this function, so xbmc doesnt hang when getting recordings.
    } 
    retPath = checkFolderForTitle(title,awGroup);
  }
  
  return retPath;
}
Example #4
0
void ff_avutil_log(void* ptr, int level, const char* format, va_list va)
{
  static CStdString buffer;

  AVClass* avc= ptr ? *(AVClass**)ptr : NULL;

  if(level >= AV_LOG_DEBUG && g_advancedSettings.m_logLevel <= LOG_LEVEL_DEBUG_SAMBA)
    return;
  else if(g_advancedSettings.m_logLevel <= LOG_LEVEL_NORMAL)
    return;

  int type;
  switch(level)
  {
    case AV_LOG_INFO   : type = LOGINFO;    break;
    case AV_LOG_ERROR  : type = LOGERROR;   break;
    case AV_LOG_DEBUG  :
    default            : type = LOGDEBUG;   break;
  }

  CStdString message, prefix;
  message.FormatV(format, va);

  prefix = "ffmpeg: ";
  if(avc)
  {
    if(avc->item_name)
      prefix += CStdString("[") + avc->item_name(ptr) + "] ";
    else if(avc->class_name)
      prefix += CStdString("[") + avc->class_name + "] ";
  }

  buffer += message;
  int pos, start = 0;
  while( (pos = buffer.find_first_of('\n', start)) >= 0 )
  {
    if(pos>start)
      CLog::Log(type, "%s%s", prefix.c_str(), buffer.substr(start, pos-start).c_str());
    start = pos+1;
  }
  buffer.erase(0, start);
}
Example #5
0
std::vector<CStdString> PdfListLevel::Tokenize(const CStdString &sText, const CStdString &breakChars)
{
    int iPos = -1;

    std::vector<CStdString> results;

    do
    {
        int iNextPos = (x64_int_cast)sText.find_first_of(breakChars, iPos+1);

        if (iNextPos == 0)
        {
            // first char is a breakChar
            results.push_back(sText.substr(0,1));
        }
        else if (iNextPos == -1)
        {
            // end of string
            results.push_back(sText.substr(iPos+1));
        }
        else if (iNextPos == iPos+1)
        {
            // another break char hmmm
            results.back()+=sText.substr(iNextPos,1);
        }
        else
        {
            results.push_back(sText.substr(iPos+1, iNextPos-iPos -1));
            results.push_back(sText.substr(iNextPos, 1));
        }

        iPos = iNextPos;

        if (iPos == (int)(x64_int_cast)sText.size()-1)
            break;
    } while (iPos != -1);


    return results;

}
Example #6
0
bool fileOps::checkDirectory ( CStdString dirPath, bool hasFilename/* = false */)
{
  int pos = 0;
  int offset = 0;
  CStdString srchString = dirPath;
  while (pos >= 0) {
    pos = srchString.find_first_of("/",pos+1);
    if (pos < 0) {
      break;
    }
    if (pos <= baseLocalCachepath.length()) {
      continue;
    }
    CUtil::CreateDirectoryEx(srchString.Left(pos)); 
    if (offset > 20) {
      break;
    }
    offset++;
  }
  if (!hasFilename) {
    CUtil::CreateDirectoryEx(dirPath);
  }
  return true;
}
Example #7
0
bool CIniFile::ReadFile()
{
  // Normally you would use ifstream, but the SGI CC compiler has
  // a few bugs with ifstream. So ... fstream used.
  fstream f;
  CStdString   line;
  CStdString   keyname, valuename, value;
  CStdString::size_type pLeft, pRight;

  f.open( (LPCSTR)path, fstream::in );
  if ( f.fail()){
    f.open( (LPCSTR)path, fstream::out );

    if ( f.fail() )
      return false;

    f.close();

    f.open( (LPCSTR)path, fstream::in );
  }
  
  while( getline( f, line)) {
    if ( !line.length() ){
      continue;
    }
    // To be compatible with Win32, check for existence of '\r'.
    // Win32 files have the '\r' and Unix files don't at the end of a line.
    // Note that the '\r' will be written to INI files from
    // Unix so that the created INI file can be read under Win32
    // without change.
    if ( line[line.length() - 1] == '\r')
      line = line.substr( 0, line.length() - 1);
    
    if ( line.length()) {
      // Check that the user hasn't openned a binary file by checking the first
      // character of each line!
      if ( !isprint( line[0])) {
	      printf( "Failing on char %d\n", line[0]);
	      f.close();
	      return false;
      }

      if (( pLeft = line.find_first_of(";#[=")) != CStdString::npos) {
	      switch ( line[pLeft]) {
	      case '[':
	        if ((pRight = line.find_last_of("]")) != CStdString::npos && pRight > pLeft) {
	          keyname = line.substr( pLeft + 1, pRight - pLeft - 1);
	          AddKeyName( keyname);
	        }
	        break;
      	  
	      case '=':
	        valuename = line.substr( 0, pLeft);
	        value = line.substr( pLeft + 1);
	        SetValue( keyname, valuename, value);
	        break;
      	  
	      case ';':
	      case '#':
	        if ( !names.size())
	          HeaderComment( line.substr( pLeft + 1));
	        else
	          KeyComment( keyname, line.substr( pLeft + 1));
	        break;
	      }
      }
    }
  }

  f.close();
  if ( names.size())
    return true;
  return false;
}
Example #8
0
void CURL::Parse(const CStdString& strURL1)
{
  Reset();
  // start by validating the path
  CStdString strURL = CUtil::ValidatePath(strURL1);

  // strURL can be one of the following:
  // format 1: protocol://[username:password]@hostname[:port]/directoryandfile
  // format 2: protocol://file
  // format 3: drive:directoryandfile
  //
  // first need 2 check if this is a protocol or just a normal drive & path
  if (!strURL.size()) return ;
  if (strURL.Equals("?", true)) return;

  // form is format 1 or 2
  // format 1: protocol://[domain;][username:password]@hostname[:port]/directoryandfile
  // format 2: protocol://file

  // decode protocol
  int iPos = strURL.Find("://");
  if (iPos < 0)
  {
    // This is an ugly hack that needs some work.
    // example: filename /foo/bar.zip/alice.rar/bob.avi
    // This should turn into zip://rar:///foo/bar.zip/alice.rar/bob.avi
    iPos = 0;
    bool is_apk = (strURL.Find(".apk/", iPos) > 0);
    while (1)
    {
      if (is_apk)
        iPos = strURL.Find(".apk/", iPos);
      else
        iPos = strURL.Find(".zip/", iPos);

      int extLen = 3;
      if (iPos < 0)
      {
        /* set filename and update extension*/
        SetFileName(strURL);
        return ;
      }
      iPos += extLen + 1;
      CStdString archiveName = strURL.Left(iPos);
      struct __stat64 s;
      if (XFILE::CFile::Stat(archiveName, &s) == 0)
      {
#ifdef _LINUX
        if (!S_ISDIR(s.st_mode))
#else
        if (!(s.st_mode & S_IFDIR))
#endif
        {
          Encode(archiveName);
          if (is_apk)
          {
            CURL c((CStdString)"apk" + "://" + archiveName + '/' + strURL.Right(strURL.size() - iPos - 1));
            *this = c;
          }
          else
          {
            CURL c((CStdString)"zip" + "://" + archiveName + '/' + strURL.Right(strURL.size() - iPos - 1));
            *this = c;
          }
          return;
        }
      }
    }
  }
  else
  {
    SetProtocol(strURL.Left(iPos));
    iPos += 3;
  }

  // virtual protocols
  // why not handle all format 2 (protocol://file) style urls here?
  // ones that come to mind are iso9660, cdda, musicdb, etc.
  // they are all local protocols and have no server part, port number, special options, etc.
  // this removes the need for special handling below.
  if (
    m_strProtocol.Equals("stack") ||
    m_strProtocol.Equals("virtualpath") ||
    m_strProtocol.Equals("multipath") ||
    m_strProtocol.Equals("filereader") ||
    m_strProtocol.Equals("special")
    )
  {
    SetFileName(strURL.Mid(iPos));
    return;
  }

  // check for username/password - should occur before first /
  if (iPos == -1) iPos = 0;

  // for protocols supporting options, chop that part off here
  // maybe we should invert this list instead?
  int iEnd = strURL.length();
  const char* sep = NULL;

  //TODO fix all Addon paths
  CStdString strProtocol2 = GetTranslatedProtocol();
  if(m_strProtocol.Equals("rss") ||
     m_strProtocol.Equals("rar") ||
     m_strProtocol.Equals("addons") ||
     m_strProtocol.Equals("image") ||
     m_strProtocol.Equals("videodb") ||
     m_strProtocol.Equals("musicdb") ||
     m_strProtocol.Equals("androidapp"))
    sep = "?";
  else
  if(strProtocol2.Equals("http")
    || strProtocol2.Equals("https")
    || strProtocol2.Equals("plugin")
    || strProtocol2.Equals("addons")
    || strProtocol2.Equals("hdhomerun")
    || strProtocol2.Equals("rtsp")
    || strProtocol2.Equals("apk")
    || strProtocol2.Equals("zip"))
    sep = "?;#|";
  else if(strProtocol2.Equals("ftp")
       || strProtocol2.Equals("ftps"))
    sep = "?;";

  if(sep)
  {
    int iOptions = strURL.find_first_of(sep, iPos);
    if (iOptions >= 0 )
    {
      // we keep the initial char as it can be any of the above
      int iProto = strURL.find_first_of("|",iOptions);
      if (iProto >= 0)
      {
        m_strProtocolOptions = strURL.substr(iProto+1);
        m_strOptions = strURL.substr(iOptions,iProto-iOptions);
      }
      else
        m_strOptions = strURL.substr(iOptions);
      iEnd = iOptions;
      m_options.AddOptions(m_strOptions);
    }
  }

  int iSlash = strURL.Find("/", iPos);
  if(iSlash >= iEnd)
    iSlash = -1; // was an invalid slash as it was contained in options

  if( !m_strProtocol.Equals("iso9660") )
  {
    int iAlphaSign = strURL.Find("@", iPos);
    if (iAlphaSign >= 0 && iAlphaSign < iEnd && (iAlphaSign < iSlash || iSlash < 0))
    {
      // username/password found
      CStdString strUserNamePassword = strURL.Mid(iPos, iAlphaSign - iPos);

      // first extract domain, if protocol is smb
      if (m_strProtocol.Equals("smb"))
      {
        int iSemiColon = strUserNamePassword.Find(";");

        if (iSemiColon >= 0)
        {
          m_strDomain = strUserNamePassword.Left(iSemiColon);
          strUserNamePassword.Delete(0, iSemiColon + 1);
        }
      }

      // username:password
      int iColon = strUserNamePassword.Find(":");
      if (iColon >= 0)
      {
        m_strUserName = strUserNamePassword.Left(iColon);
        iColon++;
        m_strPassword = strUserNamePassword.Right(strUserNamePassword.size() - iColon);
      }
      // username
      else
      {
        m_strUserName = strUserNamePassword;
      }

      iPos = iAlphaSign + 1;
      iSlash = strURL.Find("/", iAlphaSign);

      if(iSlash >= iEnd)
        iSlash = -1;
    }
  }

  // detect hostname:port/
  if (iSlash < 0)
  {
    CStdString strHostNameAndPort = strURL.Mid(iPos, iEnd - iPos);
    int iColon = strHostNameAndPort.Find(":");
    if (iColon >= 0)
    {
      m_strHostName = strHostNameAndPort.Left(iColon);
      iColon++;
      CStdString strPort = strHostNameAndPort.Right(strHostNameAndPort.size() - iColon);
      m_iPort = atoi(strPort.c_str());
    }
    else
    {
      m_strHostName = strHostNameAndPort;
    }

  }
  else
  {
    CStdString strHostNameAndPort = strURL.Mid(iPos, iSlash - iPos);
    int iColon = strHostNameAndPort.Find(":");
    if (iColon >= 0)
    {
      m_strHostName = strHostNameAndPort.Left(iColon);
      iColon++;
      CStdString strPort = strHostNameAndPort.Right(strHostNameAndPort.size() - iColon);
      m_iPort = atoi(strPort.c_str());
    }
    else
    {
      m_strHostName = strHostNameAndPort;
    }
    iPos = iSlash + 1;
    if (iEnd > iPos)
    {
      m_strFileName = strURL.Mid(iPos, iEnd - iPos);

      iSlash = m_strFileName.Find("/");
      if(iSlash < 0)
        m_strShareName = m_strFileName;
      else
        m_strShareName = m_strFileName.Left(iSlash);
    }
  }

  // iso9960 doesnt have an hostname;-)
  if (m_strProtocol.CompareNoCase("iso9660") == 0
    || m_strProtocol.CompareNoCase("musicdb") == 0
    || m_strProtocol.CompareNoCase("videodb") == 0
    || m_strProtocol.CompareNoCase("sources") == 0
    || m_strProtocol.CompareNoCase("lastfm") == 0
    || m_strProtocol.CompareNoCase("pvr") == 0
    || m_strProtocol.Left(3).CompareNoCase("mem") == 0)
  {
    if (m_strHostName != "" && m_strFileName != "")
    {
      CStdString strFileName = m_strFileName;
      m_strFileName.Format("%s/%s", m_strHostName.c_str(), strFileName.c_str());
      m_strHostName = "";
    }
    else
    {
      if (!m_strHostName.IsEmpty() && strURL[iEnd-1]=='/')
        m_strFileName = m_strHostName + "/";
      else
        m_strFileName = m_strHostName;
      m_strHostName = "";
    }
  }

  m_strFileName.Replace("\\", "/");

  /* update extension */
  SetFileName(m_strFileName);

  /* decode urlencoding on this stuff */
  if(URIUtils::ProtocolHasEncodedHostname(m_strProtocol))
  {
    Decode(m_strHostName);
    // Validate it as it is likely to contain a filename
    SetHostName(CUtil::ValidatePath(m_strHostName));
  }

  Decode(m_strUserName);
  Decode(m_strPassword);
}
Example #9
0
bool CURL::IsFileOnly(const CStdString &url)
{
  return url.find_first_of("/\\") == CStdString::npos;
}
Example #10
0
CStdString CID3Tag::ParseMP3Genre(const CStdString& str) const
{
  m_dll.Load();

  CStdString strTemp = str;
  set<CStdString> setGenres;

  while (!strTemp.IsEmpty())
  {
    // remove any leading spaces
    strTemp.TrimLeft();

    if (strTemp.IsEmpty())
      break;

    // start off looking for (something)
    if (strTemp[0] == '(')
    {
      strTemp.erase(0, 1);
      if (strTemp.empty())
        break;

      // now look for ((something))
      if (strTemp[0] == '(')
      {
        // remove ((something))
        int i = strTemp.find_first_of(')');
        strTemp.erase(0, i + 2);
      }
    }

    // no parens, so we have a start of a string
    // push chars into temp string until valid terminator found
    // valid terminators are ) or , or ;
    else
    {
      CStdString t;
      size_t i = strTemp.find_first_of("),;");
      if (i != std::string::npos)
      {
        t = strTemp.Left(i);
        strTemp.erase(0, i + 1);
      } else {
        t = strTemp;
        strTemp.clear();
      }
      
      // remove any leading or trailing white space
      // from temp string
      t.Trim();
      if (!t.length()) continue;

      // if the temp string is natural number try to convert it to a genre string
      if (StringUtils::IsNaturalNumber(t))
      {
        id3_ucs4_t* ucs4=m_dll.id3_latin1_ucs4duplicate((id3_latin1_t*)t.c_str());
        const id3_ucs4_t* genre=m_dll.id3_genre_name(ucs4);
        m_dll.id3_ucs4_free(ucs4);
        t=ToStringCharset(genre, ID3_FIELD_TEXTENCODING_ISO_8859_1);
      }

      // convert RX to Remix as per ID3 V2.3 spec
      else if ((t == "RX") || (t == "Rx") || (t == "rX") || (t == "rx"))
      {
        t = "Remix";
      }

      // convert CR to Cover as per ID3 V2.3 spec
      else if ((t == "CR") || (t == "Cr") || (t == "cR") || (t == "cr"))
      {
        t = "Cover";
      }

      // insert genre name in set
      setGenres.insert(t);
    }

  }

  // return a " / " seperated string
  CStdString strGenre;
  set<CStdString>::iterator it;
  for (it = setGenres.begin(); it != setGenres.end(); it++)
  {
    CStdString strTemp = *it;
    if (!strGenre.IsEmpty())
      strGenre += g_advancedSettings.m_musicItemSeparator;
    strGenre += strTemp;
  }
  return strGenre;
}
Example #11
0
CStdString CID3Tag::ParseMP3Genre(const CStdString& str) const
{
  if (!m_dll.IsLoaded())
    m_dll.Load();

  CStdString strTemp = str;
  set<CStdString> setGenres;

  while (!strTemp.IsEmpty())
  {
    // remove any leading spaces
    int i = strTemp.find_first_not_of(" ");
    if (i > 0) strTemp.erase(0, i);

    // pull off the first character
    char p = strTemp[0];

    // start off looking for (something)
    if (p == '(')
    {
      strTemp.erase(0, 1);

      // now look for ((something))
      p = strTemp[0];
      if (p == '(')
      {
        // remove ((something))
        i = strTemp.find_first_of("))");
        strTemp.erase(0, i + 2);
      }
    }

    // no parens, so we have a start of a string
    // push chars into temp string until valid terminator found
    // valid terminators are ) or , or ;
    else
    {
      CStdString t;
      while ((!strTemp.IsEmpty()) && (p != ')') && (p != ',') && (p != ';'))
      {
        strTemp.erase(0, 1);
        t.push_back(p);
        p = strTemp[0];
      }
      // loop exits when terminator is found
      // be sure to remove the terminator
      strTemp.erase(0, 1);

      // remove any leading or trailing white space
      // from temp string
      t.Trim();
      if (!t.size()) continue;

      // if the temp string is natural number try to convert it to a genre string
      if (StringUtils::IsNaturalNumber(t))
      {
        id3_ucs4_t* ucs4=m_dll.id3_latin1_ucs4duplicate((id3_latin1_t*)t.c_str());
        const id3_ucs4_t* genre=m_dll.id3_genre_name(ucs4);
        m_dll.id3_ucs4_free(ucs4);
        t=ToStringCharset(genre, ID3_FIELD_TEXTENCODING_ISO_8859_1);
      }

      // convert RX to Remix as per ID3 V2.3 spec
      else if ((t == "RX") || (t == "Rx") || (t == "rX") || (t == "rx"))
      {
        t = "Remix";
      }

      // convert CR to Cover as per ID3 V2.3 spec
      else if ((t == "CR") || (t == "Cr") || (t == "cR") || (t == "cr"))
      {
        t = "Cover";
      }

      // insert genre name in set
      setGenres.insert(t);
    }

  }

  // return a " / " seperated string
  CStdString strGenre;
  set<CStdString>::iterator it;
  for (it = setGenres.begin(); it != setGenres.end(); it++)
  {
    CStdString strTemp = *it;
    if (!strGenre.IsEmpty())
      strGenre += g_advancedSettings.m_musicItemSeparator;
    strGenre += strTemp;
  }
  return strGenre;
}