本文整理汇总了C++中Options::asString方法的典型用法代码示例。如果您正苦于以下问题:C++ Options::asString方法的具体用法?C++ Options::asString怎么用?C++ Options::asString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Options
的用法示例。
在下文中一共展示了Options::asString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createRemoteConnection
bool ConnectionFactory::createRemoteConnection(const enum ngsCatalogObjectType type,
const std::string &path,
const Options &options)
{
switch(type) {
case CAT_CONTAINER_NGW:
{
std::string url = options.asString(KEY_URL);
if(url.empty()) {
return errorMessage(_("Missing required option 'url'"));
}
std::string login = options.asString(KEY_LOGIN);
if(login.empty()) {
login = "guest";
}
else {
std::string oldLogin(login);
login = CPLString(login).Trim();
if(!compare(oldLogin, login, true)) {
warningMessage("Login was trimmed!");
}
}
std::string password = options.asString(KEY_PASSWORD);
bool isGuest = options.asBool(KEY_IS_GUEST);
CPLJSONDocument connectionFile;
CPLJSONObject root = connectionFile.GetRoot();
root.Add(KEY_TYPE, type);
root.Add(KEY_URL, url);
root.Add(KEY_LOGIN, login);
root.Add(KEY_IS_GUEST, isGuest);
if(!password.empty()) {
root.Add(KEY_PASSWORD, encrypt(password));
}
return connectionFile.Save(path);
}
default:
return errorMessage(_("Unsupported connection type %d"), type);
}
}
示例2: checkRemoteConnection
bool ConnectionFactory::checkRemoteConnection(const enum ngsCatalogObjectType type,
const Options &options)
{
resetError();
switch(type) {
case CAT_CONTAINER_NGW:
{
std::string url = options.asString(KEY_URL);
if(url.empty()) {
return errorMessage(_("Missing required option 'url'"));
}
std::string login = options.asString(KEY_LOGIN);
if(login.empty()) {
login = "guest";
}
else {
std::string oldLogin(login);
login = CPLString(login).Trim();
if(!compare(oldLogin, login, true)) {
warningMessage("Login was trimmed!");
}
}
std::string password = options.asString(KEY_PASSWORD);
CPLStringList requestOptions;
std::string headers = "Accept: */*";
Options authOptions;
authOptions.add(KEY_TYPE, "basic");
authOptions.add(KEY_LOGIN, login);
authOptions.add(KEY_PASSWORD, password);
AuthStore::authAdd(url, authOptions);
std::string auth = AuthStore::authHeader(url);
AuthStore::authRemove(url);
if(!auth.empty()) {
headers += "\r\n";
headers += auth;
}
requestOptions.AddNameValue("HEADERS", headers.c_str());
CPLJSONDocument checkReq;
if(!checkReq.LoadUrl(ngw::getCurrentUserUrl(url), requestOptions)) {
return errorMessage(CPLGetLastErrorMsg());
}
CPLJSONObject root = checkReq.GetRoot();
if(!root.IsValid()) {
return errorMessage(_("Response is invalid"));
}
if(root.GetString("keyname") == login) {
return true;
}
return errorMessage(_("User '%s' failed to connect to %s."),
login.c_str(), url.c_str());
}
default:
return errorMessage(_("Unsupported connection type %d"), type);
}
}