本文整理汇总了C++中Hdf::fromString方法的典型用法代码示例。如果您正苦于以下问题:C++ Hdf::fromString方法的具体用法?C++ Hdf::fromString怎么用?C++ Hdf::fromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hdf
的用法示例。
在下文中一共展示了Hdf::fromString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestCollectionHdf
bool TestCppBase::TestCollectionHdf() {
IniSetting::Map ini = IniSetting::Map::object;
Hdf hdf;
hdf.fromString(
" Server {\n"
" AllowedDirectories.* = /var/www\n"
" AllowedDirectories.* = /usr/bin\n"
" HighPriorityEndPoints.* = /end\n"
" HighPriorityEndPoints.* = /point\n"
" HighPriorityEndPoints.* = /power\n"
" }\n"
);
RuntimeOption::AllowedDirectories.clear();
Config::Bind(RuntimeOption::AllowedDirectories, ini,
hdf, "Server.AllowedDirectories");
VERIFY(RuntimeOption::AllowedDirectories.size() == 2);
std::vector<std::string> ad =
Config::GetVector(ini, hdf, "Server.AllowedDirectories",
RuntimeOption::AllowedDirectories);
VERIFY(RuntimeOption::AllowedDirectories.size() == 2);
VERIFY(ad.size() == 2);
Config::Bind(RuntimeOption::ServerHighPriorityEndPoints, ini,
hdf, "Server.HighPriorityEndPoints");
VERIFY(RuntimeOption::ServerHighPriorityEndPoints.size() == 3);
return Count(true);
}
示例2: TestSatelliteServer
bool TestCppBase::TestSatelliteServer() {
IniSetting::Map ini = IniSetting::Map::object;
Hdf hdf;
hdf.fromString(
"Satellites {\n"
" rpc {\n"
" Type = RPCServer\n"
" Port = 9999\n"
" RequestInitDocument = my/rpc/rpc.php\n"
" RequestInitFunction = init_me\n"
" Password = abcd0987\n"
" Passwords {\n"
" * = abcd0987\n"
" }\n"
" }\n"
" ips {\n"
" Type = InternalPageServer\n"
" BlockMainServer = false\n"
" }\n"
"}\n"
);
std::vector<std::shared_ptr<SatelliteServerInfo>> infos;
RuntimeOption::ReadSatelliteInfo(ini, hdf, infos,
RuntimeOption::XboxPassword,
RuntimeOption::XboxPasswords);
for (auto& info_ptr : infos) {
auto info = info_ptr.get();
auto name = info->getName();
if (name == "rpc") {
VERIFY(info->getType() == SatelliteServer::Type::KindOfRPCServer);
VERIFY(info->getPort() == 9999);
VERIFY(info->getThreadCount() == 5);
VERIFY(info->getTimeoutSeconds() ==
std::chrono::seconds(RuntimeOption::RequestTimeoutSeconds));
VERIFY(info->getURLs().size() == 0);
VERIFY(info->getMaxRequest() == 500);
VERIFY(info->getMaxDuration() == 120);
VERIFY(info->getReqInitFunc() == "init_me");
VERIFY(info->getReqInitDoc() == "my/rpc/rpc.php");
VERIFY(info->getPassword() == "abcd0987");
VERIFY(info->getPasswords().size() == 1);
VERIFY(info->getPasswords().find("abcd0987") !=
info->getPasswords().end());
VERIFY(info->alwaysReset() == false);
VERIFY(RuntimeOption::XboxPassword == "abcd0987");
} else if (name == "ips") {
VERIFY(info->getType() ==
SatelliteServer::Type::KindOfInternalPageServer);
VERIFY(info->getURLs().size() == 0);
}
}
return Count(true);
}
示例3: TestHDF
bool TestUtil::TestHDF() {
// This was causing a crash
{
Hdf doc, node;
node = doc["Node"];
}
{
Hdf doc;
doc.fromString(
"node.* {\n"
" name = value\n"
"}");
VS(doc["node"][0]["name"].getString(), "value");
}
return Count(true);
}
示例4: TestHDF
bool TestUtil::TestHDF() {
// This was causing a crash
{
Hdf doc, node;
node = doc["Node"];
}
{
IniSetting::Map ini = IniSetting::Map::object;
Hdf doc;
doc.fromString(
"node.* {\n"
" name = value\n"
"}");
VS(Config::GetString(ini, doc, "node.0.name"), "value");
}
return Count(true);
}
示例5: ParseHdfString
void Config::ParseHdfString(const std::string hdfStr, Hdf &hdf) {
hdf.fromString(hdfStr.c_str());
}
示例6: Load
void RuntimeOption::Load(Hdf &config, StringVec *overwrites /* = NULL */) {
// Machine metrics
string hostname, tier, cpu;
{
Hdf machine = config["Machine"];
hostname = machine["name"].getString();
if (hostname.empty()) {
hostname = Process::GetHostName();
}
tier = machine["tier"].getString();
cpu = machine["cpu"].getString();
if (cpu.empty()) {
cpu = Process::GetCPUModel();
}
}
// Tier overwrites
{
Hdf tiers = config["Tiers"];
for (Hdf hdf = tiers.firstChild(); hdf.exists(); hdf = hdf.next()) {
if (matchHdfPattern(hostname, hdf["machine"]) &&
matchHdfPattern(tier, hdf["tier"]) &&
matchHdfPattern(cpu, hdf["cpu"])) {
Tier = hdf.getName();
config.copy(hdf["overwrite"]);
// no break here, so we can continue to match more overwrites
}
hdf["overwrite"].setVisited(); // avoid lint complaining
}
}
// More overwrites
if (overwrites) {
for (unsigned int i = 0; i < overwrites->size(); i++) {
config.fromString(overwrites->at(i).c_str());
}
}
PidFile = config["PidFile"].getString("www.pid");
{
Hdf logger = config["Log"];
if (logger["Level"] == "None") {
Logger::LogLevel = Logger::LogNone;
} else if (logger["Level"] == "Error") {
Logger::LogLevel = Logger::LogError;
} else if (logger["Level"] == "Warning") {
Logger::LogLevel = Logger::LogWarning;
} else if (logger["Level"] == "Info") {
Logger::LogLevel = Logger::LogInfo;
} else if (logger["Level"] == "Verbose") {
Logger::LogLevel = Logger::LogVerbose;
}
Logger::LogHeader = logger["Header"].getBool();
bool logInjectedStackTrace = logger["InjectedStackTrace"].getBool();
if (logInjectedStackTrace) {
Logger::SetTheLogger(new ExtendedLogger());
ExtendedLogger::EnabledByDefault = true;
}
Logger::LogNativeStackTrace = logger["NativeStackTrace"].getBool(true);
Logger::MaxMessagesPerRequest =
logger["MaxMessagesPerRequest"].getInt32(-1);
Logger::UseLogFile = logger["UseLogFile"].getBool(true);
Logger::UseCronolog = logger["UseCronolog"].getBool(false);
if (Logger::UseLogFile) {
LogFile = logger["File"].getString();
LogFileSymLink = logger["SymLink"].getString();
}
Logger::DropCacheChunkSize =
logger["DropCacheChunkSize"].getInt32(1 << 20);
AlwaysEscapeLog = logger["AlwaysEscapeLog"].getBool(false);
Hdf aggregator = logger["Aggregator"];
Logger::UseLogAggregator = aggregator.getBool();
LogAggregatorFile = aggregator["File"].getString();
LogAggregatorDatabase = aggregator["Database"].getString();
LogAggregatorSleepSeconds = aggregator["SleepSeconds"].getInt16(10);
AlwaysLogUnhandledExceptions =
logger["AlwaysLogUnhandledExceptions"].getBool(true);
NoSilencer = logger["NoSilencer"].getBool();
EnableApplicationLog = logger["ApplicationLog"].getBool(true);
RuntimeErrorReportingLevel =
logger["RuntimeErrorReportingLevel"].getInt32(ErrorConstants::HPHP_ALL);
AccessLogDefaultFormat = logger["AccessLogDefaultFormat"].
getString("%h %l %u %t \"%r\" %>s %b");
{
Hdf access = logger["Access"];
for (Hdf hdf = access.firstChild(); hdf.exists();
hdf = hdf.next()) {
string fname = hdf["File"].getString();
if (fname.empty()) {
continue;
}
string symLink = hdf["SymLink"].getString();
//.........这里部分代码省略.........
示例7: TestIpBlockMap
bool TestCppBase::TestIpBlockMap() {
struct in6_addr addr;
int bits;
VERIFY(IpBlockMap::ReadIPv6Address("204.15.21.0/22", &addr, bits));
VS(bits, 118);
VS(in6addrWord(addr, 0), 0x00000000L);
VS(in6addrWord(addr, 1), 0x00000000L);
VS(in6addrWord(addr, 2), 0x0000FFFFL);
VS(in6addrWord(addr, 3), 0xCC0F1500L);
VERIFY(IpBlockMap::ReadIPv6Address("127.0.0.1", &addr, bits));
VS(bits, 128);
VS(in6addrWord(addr, 0), 0x00000000L);
VS(in6addrWord(addr, 1), 0x00000000L);
VS(in6addrWord(addr, 2), 0x0000FFFFL);
VS(in6addrWord(addr, 3), 0x7F000001L);
VERIFY(IpBlockMap::ReadIPv6Address(
"1111:2222:3333:4444:5555:6666:789a:bcde", &addr, bits));
VS(bits, 128);
VS(in6addrWord(addr, 0), 0x11112222L);
VS(in6addrWord(addr, 1), 0x33334444L);
VS(in6addrWord(addr, 2), 0x55556666L);
VS(in6addrWord(addr, 3), 0x789abcdeL);
VERIFY(IpBlockMap::ReadIPv6Address(
"1111:2222:3333:4444:5555:6666:789a:bcde/68", &addr, bits));
VS(bits, 68);
VS(in6addrWord(addr, 0), 0x11112222L);
VS(in6addrWord(addr, 1), 0x33334444L);
VS(in6addrWord(addr, 2), 0x55556666L);
VS(in6addrWord(addr, 3), 0x789abcdeL);
IpBlockMap::BinaryPrefixTrie root(true);
unsigned char value[16];
// Default value with no additional nodes
memset(value, 0, 16);
VERIFY(root.isAllowed(value, 1));
value[0] = 0x80;
VERIFY(root.isAllowed(value));
// Inheritance of parent allow value through multiple levels of new nodes
IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 1, false);
value[0] = 0xf0;
IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 4, true);
VERIFY(root.isAllowed(value));
value[0] = 0xe0;
VERIFY(!root.isAllowed(value));
value[0] = 0xc0;
VERIFY(!root.isAllowed(value));
value[0] = 0x80;
VERIFY(!root.isAllowed(value));
value[0] = 0;
VERIFY(root.isAllowed(value));
// > 1 byte in address
value[2] = 0xff;
IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 24, false);
VERIFY(!root.isAllowed(value));
value[3] = 0xff;
VERIFY(!root.isAllowed(value));
value[2] = 0xfe;
VERIFY(root.isAllowed(value));
// Exact address match
value[2] = 0xff;
value[15] = 1;
IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 128, true);
VERIFY(root.isAllowed(value));
Hdf hdf;
hdf.fromString(
" 0 {\n"
" Location = /test\n"
" AllowFirst = true\n"
" Ip {\n"
" Allow {\n"
" * = 127.0.0.1\n"
" }\n"
" Deny {\n"
" * = 8.32.0.0/24\n"
" * = aaaa:bbbb:cccc:dddd:eeee:ffff:1111::/80\n"
" }\n"
" }\n"
" }\n"
);
IpBlockMap ibm(hdf);
VERIFY(!ibm.isBlocking("test/blah.php", "127.0.0.1"));
VERIFY(ibm.isBlocking("test/blah.php", "8.32.0.104"));
VERIFY(ibm.isBlocking("test/blah.php",
"aaaa:bbbb:cccc:dddd:eeee:9999:8888:7777"));
VERIFY(!ibm.isBlocking("test/blah.php",
"aaaa:bbbb:cccc:dddd:eee3:4444:3333:2222"));
return Count(true);
}
示例8: ParseHdfString
void Config::ParseHdfString(const std::string hdfStr, Hdf &hdf,
IniSetting::Map &ini) {
hdf.fromString(hdfStr.c_str());
}
示例9: TestVirtualHost
bool TestCppBase::TestVirtualHost() {
IniSetting::Map ini = IniSetting::Map::object;
Hdf hdf;
hdf.fromString(
" Server {\n"
" AllowedDirectories.* = /var/www\n"
" AllowedDirectories.* = /usr/bin\n"
" }\n"
" VirtualHost {\n"
" flibtest {\n"
" Prefix = flibtest.\n"
" PathTranslation = flib/_bin\n"
" ServerName = flibtest.facebook.com\n"
" }\n"
" upload {\n"
" Prefix = upload.\n"
" ServerVariables {\n"
" TFBENV = 8{\n"
" }\n"
" overwrite {\n"
" Server {\n"
" AllowedDirectories.* = /var/www\n"
" AllowedDirectories.* = /mnt\n"
" AllowedDirectories.* = /tmp\n"
" AllowedDirectories.* = /var/tmp/tao\n"
" }\n"
" MaxPostSize = 100MB\n"
" UploadMaxFileSize = 100MB\n"
" RequestTimeoutSeconds = 120\n"
" }\n"
" PathTranslation = html\n"
" }\n"
" default {\n"
" LogFilters {\n"
" * {\n"
" url = /method/searchme\n"
" params {\n"
" * = q\n"
" * = s\n"
" * = atoken\n"
" * = otoken\n"
" }\n"
" value = REMOVED\n"
" }\n"
" }\n"
" RewriteRules {\n"
" common {\n"
" pattern = /html/common/\n"
" to = http://3v4l.org\n"
" qsa = true\n"
" redirect = 301\n"
" }\n"
" }\n"
" PathTranslation = htm\n"
" }\n"
" }\n"
);
// reset RuntimeOption::AllowedDirectories to empty because if the INI
// version of this test is run at the same time, we don't want to append
// the same directories to it. We want to start fresh.
RuntimeOption::AllowedDirectories.clear();
std::vector<VirtualHost> hosts;
RuntimeOption::AllowedDirectories =
Config::GetVector(ini, hdf, "Server.AllowedDirectories");
auto cb = [&] (const IniSetting::Map &ini_cb, const Hdf &hdf_cb,
const std::string &host) {
if (VirtualHost::IsDefault(ini_cb, hdf_cb, host)) {
VirtualHost::GetDefault().init(ini_cb, hdf_cb, host);
VirtualHost::GetDefault().
addAllowedDirectories(RuntimeOption::AllowedDirectories);
} else {
auto vh = VirtualHost(ini_cb, hdf_cb, host);
// These will be added
// " AllowedDirectories.* = /var/www\n"
// " AllowedDirectories.* = /usr/bin\n"
vh.addAllowedDirectories(RuntimeOption::AllowedDirectories);
hosts.push_back(vh);
}
};
Config::Iterate(cb, ini, hdf, "VirtualHost");
for (auto& host : hosts) {
VirtualHost::SetCurrent(&host);
auto name = host.getName();
if (name == "flibtest") {
VERIFY(host.getPathTranslation() == "flib/_bin/"); // the / is added
VERIFY(host.getDocumentRoot() ==
RuntimeOption::SourceRoot + "flib/_bin");
VERIFY(host.getServerVars().size() == 0);
VERIFY(VirtualHost::GetAllowedDirectories().size() == 2);
VERIFY(host.valid() == true);
VERIFY(host.hasLogFilter() == false);
} else if (name == "upload") {
VERIFY(host.getPathTranslation() == "html/"); // the / is added
VERIFY(host.getDocumentRoot() ==
RuntimeOption::SourceRoot + "html");
// SortALlowedDirectories might add something and remove
// duplicates. In this case, /var/releases/continuous_www_scripts4
// was added and the duplicate /var/www was removed.s
//.........这里部分代码省略.........
示例10: prepareOptions
//.........这里部分代码省略.........
}
if (vm.count("version")) {
#ifdef HPHP_VERSION
#undefine HPHP_VERSION
#endif
#define HPHP_VERSION(v) cout << "HipHop Compiler v" #v << "\n";
#include "../version"
return 1;
}
// log level
if (po.logLevel != -1) {
Logger::LogLevel = (Logger::LogLevelType)po.logLevel;
} else if (po.target == "run") {
Logger::LogLevel = Logger::LogNone;
} else {
Logger::LogLevel = Logger::LogInfo;
}
// config and system
Option::GenerateCPPMain = true;
if (po.noMetaInfo) {
Option::GenerateCPPMetaInfo = false;
Option::GenerateCPPMacros = false;
}
Option::FlAnnotate = po.fl_annotate;
Hdf config;
for (vector<string>::const_iterator it = po.config.begin();
it != po.config.end(); ++it) {
config.append(*it);
}
for (unsigned int i = 0; i < po.confStrings.size(); i++) {
config.fromString(po.confStrings[i].c_str());
}
Option::Load(config);
vector<string> badnodes;
config.lint(badnodes);
for (unsigned int i = 0; i < badnodes.size(); i++) {
Logger::Error("Possible bad config node: %s", badnodes[i].c_str());
}
if (po.inputDir.empty()) {
po.inputDir = '.';
}
po.inputDir = Util::normalizeDir(po.inputDir);
if (po.configDir.empty()) {
po.configDir = po.inputDir;
}
po.configDir = Util::normalizeDir(po.configDir);
Option::RootDirectory = po.configDir;
for (unsigned int i = 0; i < po.excludeDirs.size(); i++) {
Option::PackageExcludeDirs.insert
(Util::normalizeDir(po.excludeDirs[i]));
}
for (unsigned int i = 0; i < po.excludeFiles.size(); i++) {
Option::PackageExcludeFiles.insert(po.excludeFiles[i]);
}
for (unsigned int i = 0; i < po.excludePatterns.size(); i++) {
Option::PackageExcludePatterns.insert
(Util::format_pattern(po.excludePatterns[i], true));
}
for (unsigned int i = 0; i < po.excludeStaticDirs.size(); i++) {
Option::PackageExcludeStaticDirs.insert
(Util::normalizeDir(po.excludeStaticDirs[i]));