Exemple #1
0
bool KServer::load_ssl()
{
	if (!sslParsed) {
		//多进程模型ssl证书查找
		std::vector<KListenHost *>::iterator it;
		int port = server.get_self_port();
		for (it=conf.service.begin();it!=conf.service.end();it++) {
			//优先根据name查找,如果name为空,则查找port.
			if( model==(*it)->model
				&& ((name.size()>0 && name==(*it)->name) || (name.size()==0 && port==(*it)->port))) {
				certificate = (*it)->certificate;
				certificate_key = (*it)->certificate_key;
				cipher = (*it)->cipher;
				protocols = (*it)->protocols;
				break;
			}
		
		}
	}
	std::string certFile = certificate;
	if(certFile.size()>0 && !isAbsolutePath(certFile.c_str())){
		certFile = conf.path + certificate;
	}
	std::string privateKeyFile = certificate_key;
	if(privateKeyFile.size()>0 && !isAbsolutePath(privateKeyFile.c_str())){
		privateKeyFile = conf.path + certificate_key;
	}
	if (certFile.size()>0) {
		ssl_ctx = KSSLSocket::init_server(
						(certFile.size() > 0 ? certFile.c_str() : NULL),
						 privateKeyFile.c_str(),
						NULL);
		if (ssl_ctx == NULL) {
			klog(KLOG_ERR,
					"Cann't init ssl context certificate=[%s],certificate_key=[%s]\n",
					certificate.c_str(), certificate_key.c_str());
			return false;
		}
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
		if(sni && 0 == SSL_CTX_set_tlsext_servername_callback(ssl_ctx,httpSSLServerName)){
			 klog(KLOG_WARNING, "kangle was built with SNI support, however, now it is linked "
					"dynamically to an OpenSSL library which has no tlsext support, "
					"therefore SNI is not available");
		}
#endif
		/////////[62]
		if (cipher.size()>0 && 
			SSL_CTX_set_cipher_list(ssl_ctx,cipher.c_str())!=1) {
			klog(KLOG_WARNING,"cipher [%s] is not support\n",cipher.c_str());
		}
		if (protocols.size() > 0) {
			KSSLSocket::set_ssl_protocols(ssl_ctx, protocols.c_str());
		}
		return true;
	}
	return false;
}
Exemple #2
0
void
beginProgram (int argumentCount, char **argumentVector) {
#if defined(GRUB_RUNTIME)

#else /* at exit */
  atexit(endProgram);
#endif /* at exit */

  initializeSystemObject();
  prepareLocale();

  if ((programPath = getProgramPath())) {
    registerProgramMemory("program-path", &programPath);
  } else {
    programPath = argumentVector[0];
  }

  if (!isExplicitPath(programPath)) {
    char *path = findProgram(programPath);
    if (!path) path = testProgram(".", programPath);
    if (path) programPath = path;
  }

  if (isExplicitPath(programPath)) {
#if defined(HAVE_REALPATH) && defined(PATH_MAX)
    if (!isAbsolutePath(programPath)) {
      char buffer[PATH_MAX];
      char *path = realpath(programPath, buffer);

      if (path) {
        char *realPath = strdup(path);

        if (realPath) {
          programPath = realPath;
        } else {
          logMallocError();
        }
      } else {
        logSystemError("realpath");
      }
    }
#endif /* defined(HAVE_REALPATH) && defined(PATH_MAX) */

    if (!isAbsolutePath(programPath)) {
      char *directory;

      if ((directory = getWorkingDirectory())) {
        char *path;
        if ((path = makePath(directory, programPath))) programPath = path;
        free(directory);
      }
    }
  }

  programName = locatePathName(programPath);
  pushLogPrefix(programName);
}
long FileUtils::getFileSize(const std::string &filepath)
{
    CCASSERT(!filepath.empty(), "Invalid path");

    std::string fullpath = filepath;
    if (!isAbsolutePath(filepath))
    {
        fullpath = searchFullPathForFilename(filepath);
        if (fullpath.empty())
            return 0;
    }

    struct stat info;
    // Get data associated with "crt_stat.c":
    int result = stat( fullpath.c_str(), &info );

    // Check if statistics are valid:
    if( result != 0 )
    {
        // Failed
        return -1;
    }
    else
    {
        return (long)(info.st_size);
    }
}
void FileUtils::setSearchPaths(const std::vector<std::string>& searchPaths)
{
    bool existDefaultRootPath = false;

    _fullPathCache.clear();
    _searchPathArray.clear();
    for (const auto& iter : searchPaths)
    {
        std::string prefix;
        std::string path;

        if (!isAbsolutePath(iter))
        {   // Not an absolute path
            prefix = _defaultResRootPath;
        }
        path = prefix + (iter);
        if (path.length() > 0 && path[path.length()-1] != '/')
        {
            path += "/";
        }
        if (!existDefaultRootPath && path == _defaultResRootPath)
        {
            existDefaultRootPath = true;
        }
        _searchPathArray.push_back(path);
    }

    if (!existDefaultRootPath)
    {
        //CCLOG("Default root path doesn't exist, adding it.");
        _searchPathArray.push_back(_defaultResRootPath);
    }
}
Exemple #5
0
static void setInputFileParametersCommon (inputFileInfo *finfo, vString *const fileName,
					  const langType language,
					  stringList *holder)
{
	if (finfo->name != NULL)
		vStringDelete (finfo->name);
	finfo->name = fileName;

	if (finfo->tagPath != NULL)
	{
		if (holder)
			stringListAdd (holder, finfo->tagPath);
		else
			vStringDelete (finfo->tagPath);
	}

	if (0)
		;
	else if (  Option.tagRelative == TREL_ALWAYS )
		finfo->tagPath =
			vStringNewOwn (relativeFilename (vStringValue (fileName),
							 getTagFileDirectory ()));
	else if ( Option.tagRelative == TREL_NEVER )
		finfo->tagPath =
			vStringNewOwn (absoluteFilename (vStringValue (fileName)));
	else if ( Option.tagRelative == TREL_NO || isAbsolutePath (vStringValue (fileName)) )
		finfo->tagPath = vStringNewCopy (fileName);
	else
		finfo->tagPath =
			vStringNewOwn (relativeFilename (vStringValue (fileName),
							 getTagFileDirectory ()));

	finfo->isHeader = isIncludeFile (vStringValue (fileName));
}
Exemple #6
0
static void *mapPath(PathMapFn fn, string path, string filename, void *data) {
   char *p1, *p2;
   string localpath, tempname;
   void *result;

   if (filename == NULL) filename = "";
   if (path == NULL || path[0] == '\0' || isAbsolutePath(filename)) {
      return fn(expandPathname(filename), data);
   }
   localpath = concat(path, ":");
   result = NULL;
   p1 = localpath;
   while (result == NULL) {
      for (p2 = p1; (*p2 != '\0') && (*p2 != ':') && (*p2 != ';') ; p2++) {
         /* Empty */
      }
      if (*p2 == '\0') break;
      *p2 = '\0';
      if (p1 != p2 || strlen(localpath) == 1) {
         tempname = concat(p1, concat("/", filename));
         result = fn(expandPathname(tempname), data);
      }
      p1 = p2 + 1;
   }
   return result;
}
const std::string FileSystem::toAbsolutePath( const std::string& path )
{
	if( isAbsolutePath( path ) )
	{
		return path;
	}
	std::string unix_path = win32ConvertPathFormatToUnixStyle( path );

	auto cache_itr = s_absolute_path_cache_map.find( unix_path );
	if( cache_itr != s_absolute_path_cache_map.end() )
	{
		return cache_itr->second;
	}

	std::string abs_path;
	for( const auto& prefix : s_search_path_array )
	{
		abs_path = std::move( prefix + unix_path );
		int ret = GetFileAttributesA( abs_path.c_str() );
		if( ret != -1 )
		{
			s_absolute_path_cache_map.insert( std::make_pair(unix_path, abs_path) );
			return std::move( abs_path );
		}
	}
	return "";
}
Exemple #8
0
void
fixInstallPaths (char **const *paths) {
  static const char *programDirectory = NULL;

  if (!programDirectory) {
    if (!(programDirectory = getPathDirectory(programPath))) {
      logMessage(LOG_WARNING, gettext("cannot determine program directory"));
      programDirectory = ".";
    }

    logMessage(LOG_DEBUG, "program directory: %s", programDirectory);
  }

  while (*paths) {
    if (**paths && ***paths) {
      char *newPath = makePath(programDirectory, **paths);

      if (!newPath) {
        logMessage(LOG_WARNING, "%s: %s", gettext("cannot fix install path"), **paths);
      } else if (!isAbsolutePath(**paths=newPath)) {
        logMessage(LOG_WARNING, "%s: %s", gettext("install path not absolute"), **paths);
      }
    }

    paths += 1;
  }
}
Exemple #9
0
std::string getRelativePath(const std::string& baseDirectory,
    const std::string& path)
{
    if(isAbsolutePath(path)) return path;

    return joinPaths(baseDirectory, path);
}
Exemple #10
0
void CCFileUtils::updateSearchPathArrayCheck(void)
{
    size_t len = m_strDefaultResRootPath.length();
    if (len > 0 && m_strDefaultResRootPath[len - 1] != '/' && m_strDefaultResRootPath[len - 1] != '\\')
    {
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
        m_strDefaultResRootPath.append("\\");
#else
        m_strDefaultResRootPath.append("/");
#endif
    }

    m_searchPathArrayCheck.clear();
    for (std::vector<std::string>::iterator it = m_searchPathArray.begin(); it != m_searchPathArray.end(); ++it)
    {
        std::string path = *it;
        if (!isAbsolutePath(path))
        {
            path = m_strDefaultResRootPath + path;
        }
        m_searchPathArrayCheck.push_back(path);
    }
    if (m_strDefaultResRootPath.length())
    {
        m_searchPathArrayCheck.push_back(m_strDefaultResRootPath);
    }
}
bool FileUtils::isDirectoryExist(const std::string& dirPath)
{
    CCASSERT(!dirPath.empty(), "Invalid path");

    if (isAbsolutePath(dirPath))
    {
        return isDirectoryExistInternal(dirPath);
    }

    // Already Cached ?
    auto cacheIter = _fullPathCache.find(dirPath);
    if( cacheIter != _fullPathCache.end() )
    {
        return isDirectoryExistInternal(cacheIter->second);
    }

    std::string fullpath;
    for (const auto& searchIt : _searchPathArray)
    {
        for (const auto& resolutionIt : _searchResolutionsOrderArray)
        {
            // searchPath + file_path + resourceDirectory
            fullpath = searchIt + dirPath + resolutionIt;
            if (isDirectoryExistInternal(fullpath))
            {
                const_cast<FileUtils*>(this)->_fullPathCache.insert(std::make_pair(dirPath, fullpath));
                return true;
            }
        }
    }

    return false;
}
Exemple #12
0
VCProject::VCProject(VSTemplateProject* projTemplate, const std::string& id)
: m_template(projTemplate)
{
  sbAssert(projTemplate);
  sbAssert(isAbsolutePath(projTemplate->getPath()));

  // Determine subtype (shared or not)
   m_subType = projTemplate->isShared() ? VCShared : VCNone;

  // TODO: validate passed in id
  if (!id.empty())
    m_id = id;
  else
    m_id = sole::uuid4().str();

  string guid = formatVSGUID(m_id);
  if (m_subType == VCShared)
  {
      TELEMETRY_EVENT_GUID(L"VSImporterSharedProjectGuid", guid);
  }
  else
  {
      TELEMETRY_EVENT_GUID(L"VSImporterProjectGuid", guid);
  }
  addGlobalProperty("ProjectGuid", guid);
}
bool FileSystem::isFileExist( const std::string& file )
{
	if( file.length() == 0 )
	{
		return false;
	}

	std::string file_path = std::move( win32ConvertPathFormatToUnixStyle( file ) );
	if( isAbsolutePath( file_path ) == false )
	{
		std::string abs_path;
		for( const auto& prefix : s_search_path_array )
		{
			abs_path = std::move( prefix + file_path );
			int ret = GetFileAttributesA( abs_path.c_str() );
			if( ret != -1 )
			{
				return true;
			}
		}
	}
	else
	{
		return GetFileAttributesA( file_path.c_str() ) != -1 ? true : false;
	}

	return false;
}
Exemple #14
0
string ProjectConfig::getDebugLogFilePath() const
{
    if (isAbsolutePath(_debugLogFile)) return _debugLogFile;

    auto path(getProjectDir());
    path.append(_debugLogFile);
    return path;
}
VCProjectItem* VCSharedProject::addItem(const std::string& itemName, const std::string& includePath, const std::string& filterPath)
{
  // Without this fix, VS looks for the files in the wrong place
  String fixedIncludePath(includePath);
  if (!isAbsolutePath(includePath)) {
    fixedIncludePath = "$(MSBuildThisFileDirectory)" + fixedIncludePath;
  }
  return VCProject::addItem(itemName, fixedIncludePath, filterPath);
}
Exemple #16
0
LODEN_CORE_EXPORT std::string joinPath(const std::string &path1, const std::string &path2)
{
    if (path1.empty())
        return path2;
    if (isAbsolutePath(path2))
        return path2;
    if(path1.back() == '/' || path1.back() == '\\')
        return path1 + path2;
    return path1 + "/" + path2;
}
Exemple #17
0
std::string CellCache::getTexturePath(int cellMapIndex) const
{
	assert(cellMapIndex >= 0 && cellMapIndex < m_imagePaths.size());	//indexのassertチェックはする
#if 0
	if(isAbsolutePath(m_imagePaths[cellMapIndex])){
		return m_imagePaths[cellMapIndex];	//絶対パスのときはそのまま扱う
	}
#endif
	std::string texturePath = m_imageBaseDir + m_imagePaths[cellMapIndex];
	return texturePath;
}
    String appendPath (const String& path, const String& subpath)
    {
        if (isAbsolutePath (subpath))
            return unixStylePath (subpath);

        String path1 (unixStylePath (path));
        if (! path1.endsWithChar ('/'))
            path1 << '/';

        return path1 + unixStylePath (subpath);
    }
Exemple #19
0
bool BASE_SESSION_CLASS::isPathAbsolute(char *root_ptr)

//  DESCRIPTION     : Check if the root is absolute.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      :
//  NOTES           :
//<<===========================================================================
{
	// call utility function
	return isAbsolutePath(root_ptr);
}
Exemple #20
0
void FileUtils::addSearchPath(const std::string &searchpath)
{
    std::string prefix;
    if (!isAbsolutePath(searchpath))
        prefix = _defaultResRootPath;

    std::string path = prefix + searchpath;
    if (path.length() > 0 && path[path.length()-1] != '/')
    {
        path += "/";
    }
    _searchPathArray.push_back(path);
}
Exemple #21
0
void fixPath(char* path) {
  // If the path is an Absolute Path, no fixing to do.
  if (isAbsolutePath(path)) {
    return;
  }

  char* wd = (char*)malloc(MAX_LENGTH);

  getcwd(wd, MAX_LENGTH);

  strcat(wd, "/");
  strcat(wd, path);
  path = wd;
}
Exemple #22
0
std::string CCFileUtils::fullPathForFilename(const char* pszFileName)
{
    CCAssert(pszFileName != NULL, "CCFileUtils: Invalid path");
    
    std::string strFileName = pszFileName;
    if (isAbsolutePath(pszFileName))
    {
        //CCLOG("Return absolute path( %s ) directly.", pszFileName);
        return pszFileName;
    }
    
    // Already Cached ?
    std::map<std::string, std::string>::iterator cacheIter = m_fullPathCache.find(pszFileName);
    if (cacheIter != m_fullPathCache.end())
    {
        //CCLOG("Return full path from cache: %s", cacheIter->second.c_str());
        return cacheIter->second;
    }
    
    // Get the new file name.
//    std::string newFilename = getNewFilename(pszFileName);
    std::string newFilename = pszFileName;
    
    std::string fullpath = "";
    
    for (std::vector<std::string>::iterator searchPathsIter = m_searchPathArrayCheck.begin();
         searchPathsIter != m_searchPathArrayCheck.end(); ++searchPathsIter) {
        for (std::vector<std::string>::iterator resOrderIter = m_searchResolutionsOrderArray.begin();
             resOrderIter != m_searchResolutionsOrderArray.end(); ++resOrderIter) {
            
            // CCLOG("\n\nSEARCHING: %s, %s, %s\n", newFilename.c_str(), resOrderIter->c_str(), searchPathsIter->c_str());
            
            fullpath = this->getPathForFilename(newFilename, *resOrderIter, *searchPathsIter);
            
            if (fullpath.length() > 0)
            {
                // Using the filename passed in as key.
                m_fullPathCache.insert(std::pair<std::string, std::string>(pszFileName, fullpath));
                //CCLOG("Returning path: %s", fullpath.c_str());
                return fullpath;
            }
        }
    }
    
    //CCLOG("fullPathForFilename: No file found at %s. Possible missing file.", pszFileName);
    
    // The file wasn't found, return the file name passed in.
    return pszFileName;
}
	//---------------------------------------------------------------------
	WString UnicodeFileSystemArchive::getFullPath(const WString& _wFilename) const
	{
		WString result;
		if(mWName.empty() || isAbsolutePath(_wFilename))
		{
			result = _wFilename;
		}
		else
		{
			result = mWName;
			result += L'/';
			result += _wFilename;
		}
		return result;
	}
bool FileUtils::isFileExist(const std::string& filename) const
{
    if (isAbsolutePath(filename))
    {
        return isFileExistInternal(filename);
    }
    else
    {
        std::string fullpath = searchFullPathForFilename(filename);
        if (fullpath.empty())
            return false;
        else
            return true;
    }
}
Exemple #25
0
std::wstring getFullPathName(const std::wstring& path)
{
	if (Global.relativeInclude == true)
	{
		if (isAbsolutePath(path))
		{
			return path;
		} else {
			std::wstring source = Global.FileInfo.FileList[Global.FileInfo.FileNum];
			return getFolderNameFromPath(source) + L"/" + path;
		}
	} else {
		return path;
	}
}
Exemple #26
0
void LuaProxy::playSFX(const std::string& filename)
{
#ifndef NO_SDL
	playSFXSDL(filename);
#else
	wstring full_path;
	if(!isAbsolutePath(filename)){
		full_path = getCustomFolderPath() + utf8_decode(filename);
	}else{
		full_path = utf8_decode(filename);
	}
	
	PlaySound(full_path.c_str(), 0, SND_FILENAME | SND_ASYNC);
#endif
}
std::string FileUtils::fullPathForFilename(const std::string &filename)
{
    if (filename.empty())
    {
        return "";
    }

    if (isAbsolutePath(filename))
    {
        return filename;
    }

    // Already Cached ?
    auto cacheIter = _fullPathCache.find(filename);
    if(cacheIter != _fullPathCache.end())
    {
        return cacheIter->second;
    }

    // Get the new file name.
    const std::string newFilename( getNewFilename(filename) );

    std::string fullpath;

    for (const auto& searchIt : _searchPathArray)
    {
        for (const auto& resolutionIt : _searchResolutionsOrderArray)
        {
            fullpath = this->getPathForFilename(newFilename, resolutionIt, searchIt);

            if (fullpath.length() > 0)
            {
                // Using the filename passed in as key.
                _fullPathCache.insert(std::make_pair(filename, fullpath));
                return fullpath;
            }

        }
    }

    if(isPopupNotify()) {
        CCLOG("cocos2d: fullPathForFilename: No file found at %s. Possible missing file.", filename.c_str());
    }

    // FIXME: Should it return nullptr ? or an empty string ?
    // The file wasn't found, return the file name passed in.
    return filename;
}
bool FileUtilsLinux::isFileExistInternal(const std::string& strFilePath) const
{
    if (strFilePath.empty())
    {
        return false;
    }

    std::string strPath = strFilePath;
    if (!isAbsolutePath(strPath))
    { // Not absolute path, add the default root path at the beginning.
        strPath.insert(0, _defaultResRootPath);
    }

    struct stat sts;
    return (stat(strPath.c_str(), &sts) != -1) ? true : false;
}
std::string FileUtils::searchFullPathForFilename(const std::string& filename) const
{
    if (isAbsolutePath(filename))
    {
        return filename;
    }
    std::string path = const_cast<FileUtils*>(this)->fullPathForFilename(filename);
    if (0 == path.compare(filename))
    {
        return "";
    }
    else
    {
        return path;
    }
}
void FileSystem::addSearchPath( const std::string& path )
{
	std::string unix_path = std::move( win32ConvertPathFormatToUnixStyle( path ) );
	std::string prefix;
	if( isAbsolutePath( unix_path ) == false )
	{
		prefix = s_default_search_path;
	}

	std::string real_path = std::move( prefix + unix_path );
	if( real_path.length() > 0 && real_path[real_path.length() - 1] != '/' )
	{
		real_path += "/";
	}
	s_search_path_array.push_back( real_path );
}