本文整理汇总了C++中StringData::find方法的典型用法代码示例。如果您正苦于以下问题:C++ StringData::find方法的具体用法?C++ StringData::find怎么用?C++ StringData::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringData
的用法示例。
在下文中一共展示了StringData::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catch
StatusWith<bool> SaslPLAINServerConversation::step(StringData inputData, std::string* outputData) {
// Expecting user input on the form: user\0user\0pwd
std::string input = inputData.toString();
std::string pwd = "";
try {
_user = input.substr(0, inputData.find('\0'));
pwd = input.substr(inputData.find('\0', _user.size() + 1) + 1);
} catch (std::out_of_range& exception) {
return StatusWith<bool>(ErrorCodes::AuthenticationFailed,
mongoutils::str::stream()
<< "Incorrectly formatted PLAIN client message");
}
User* userObj;
// The authentication database is also the source database for the user.
Status status =
_saslAuthSession->getAuthorizationSession()->getAuthorizationManager().acquireUser(
_saslAuthSession->getOpCtxt(),
UserName(_user, _saslAuthSession->getAuthenticationDatabase()),
&userObj);
if (!status.isOK()) {
return StatusWith<bool>(status);
}
const User::CredentialData creds = userObj->getCredentials();
_saslAuthSession->getAuthorizationSession()->getAuthorizationManager().releaseUser(userObj);
std::string authDigest = createPasswordDigest(_user, pwd);
if (!creds.password.empty()) {
// Handle schemaVersion26Final (MONGODB-CR/SCRAM mixed mode)
if (authDigest != creds.password) {
return StatusWith<bool>(ErrorCodes::AuthenticationFailed,
mongoutils::str::stream() << "Incorrect user name or password");
}
} else {
// Handle schemaVersion28SCRAM (SCRAM only mode)
unsigned char storedKey[scram::hashSize];
unsigned char serverKey[scram::hashSize];
scram::generateSecrets(
authDigest,
reinterpret_cast<const unsigned char*>(base64::decode(creds.scram.salt).c_str()),
16,
creds.scram.iterationCount,
storedKey,
serverKey);
if (creds.scram.storedKey !=
base64::encode(reinterpret_cast<const char*>(storedKey), scram::hashSize)) {
return StatusWith<bool>(ErrorCodes::AuthenticationFailed,
mongoutils::str::stream() << "Incorrect user name or password");
}
}
*outputData = "";
return StatusWith<bool>(true);
}
示例2: legalClientSystemNS
bool legalClientSystemNS(StringData ns) {
if (ns == "local.system.replset")
return true;
if (ns.find(".system.users") != string::npos)
return true;
if (ns == "admin.system.roles")
return true;
if (ns == kConfigCollection)
return true;
if (ns == kLogicalTimeKeysCollection)
return true;
if (ns == "admin.system.new_users")
return true;
if (ns == "admin.system.backup_users")
return true;
if (ns.find(".system.js") != string::npos)
return true;
if (nsToCollectionSubstring(ns) == NamespaceString::kSystemDotViewsCollectionName)
return true;
return false;
}
示例3: validateDBName
Status Database::validateDBName( StringData dbname ) {
if ( dbname.size() <= 0 )
return Status( ErrorCodes::BadValue, "db name is empty" );
if ( dbname.size() >= 64 )
return Status( ErrorCodes::BadValue, "db name is too long" );
if ( dbname.find( '.' ) != string::npos )
return Status( ErrorCodes::BadValue, "db name cannot contain a ." );
if ( dbname.find( ' ' ) != string::npos )
return Status( ErrorCodes::BadValue, "db name cannot contain a space" );
#ifdef _WIN32
static const char* windowsReservedNames[] = {
"con", "prn", "aux", "nul",
"com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9",
"lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9"
};
string lower( dbname.toString() );
std::transform( lower.begin(), lower.end(), lower.begin(), ::tolower );
for ( size_t i = 0; i < (sizeof(windowsReservedNames) / sizeof(char*)); ++i ) {
if ( lower == windowsReservedNames[i] ) {
stringstream errorString;
errorString << "db name \"" << dbname.toString() << "\" is a reserved name";
return Status( ErrorCodes::BadValue, errorString.str() );
}
}
#endif
return Status::OK();
}
示例4: uassert
list<intrusive_ptr<DocumentSource>> DocumentSourceCount::createFromBson(
BSONElement elem, const intrusive_ptr<ExpressionContext>& pExpCtx) {
uassert(40156,
str::stream() << "the count field must be a non-empty string",
elem.type() == String);
StringData elemString = elem.valueStringData();
uassert(
40157, str::stream() << "the count field must be a non-empty string", !elemString.empty());
uassert(40158,
str::stream() << "the count field cannot be a $-prefixed path",
elemString[0] != '$');
uassert(40159,
str::stream() << "the count field cannot contain a null byte",
elemString.find('\0') == string::npos);
uassert(40160,
str::stream() << "the count field cannot contain '.'",
elemString.find('.') == string::npos);
BSONObj groupObj = BSON("$group" << BSON("_id" << BSONNULL << elemString << BSON("$sum" << 1)));
BSONObj projectObj = BSON("$project" << BSON("_id" << 0 << elemString << 1));
auto groupSource = DocumentSourceGroup::createFromBson(groupObj.firstElement(), pExpCtx);
auto projectSource = DocumentSourceProject::createFromBson(projectObj.firstElement(), pExpCtx);
return {groupSource, projectSource};
}
示例5: isUserDataIdent
bool KVCatalog::isUserDataIdent(StringData ident) const {
// Indexes, collections, and temporary RecordStore idents are all candidates for dropping when
// the storage engine's metadata does not align with the catalog metadata.
return ident.find("index-") != std::string::npos || ident.find("index/") != std::string::npos ||
ident.find("temp-") != std::string::npos ||
ident.find("collection-") != std::string::npos ||
ident.find("collection/") != std::string::npos;
}
示例6: legalClientSystemNS
bool legalClientSystemNS( const StringData& ns , bool write ) {
if( ns == "local.system.replset" ) return true;
if ( ns.find( ".system.users" ) != string::npos )
return true;
if ( ns == "admin.system.roles" ) return true;
if ( ns == "admin.system.version" ) return true;
if ( ns == "admin.system.new_users" ) return true;
if ( ns == "admin.system.backup_users" ) return true;
if ( ns.find( ".system.js" ) != string::npos ) return true;
return false;
}
示例7: getCanonicalIndexField
bool getCanonicalIndexField( StringData fullName, string* out ) {
// check if fieldName contains ".$" or ".###" substrings (#=digit) and skip them
// however do not skip the first field even if it meets these criteria
if ( fullName.find( '.' ) == string::npos )
return false;
bool modified = false;
StringBuilder buf;
for ( size_t i=0; i<fullName.size(); i++ ) {
char c = fullName[i];
if ( c != '.' ) {
buf << c;
continue;
}
if ( i + 1 == fullName.size() ) {
// ends with '.'
buf << c;
continue;
}
// check for ".$", skip if present
if ( fullName[i+1] == '$' ) {
// only do this if its not something like $a
if ( i + 2 >= fullName.size() || fullName[i+2] == '.' ) {
i++;
modified = true;
continue;
}
}
// check for ".###" for any number of digits (no letters)
if ( isdigit( fullName[i+1] ) ) {
size_t j = i;
// skip digits
while ( j+1 < fullName.size() && isdigit( fullName[j+1] ) )
j++;
if ( j+1 == fullName.size() || fullName[j+1] == '.' ) {
// only digits found, skip forward
i = j;
modified = true;
continue;
}
}
buf << c;
}
if ( !modified )
return false;
*out = buf.str();
return true;
}
示例8: getMaxLogSizeKB
std::ostream& MessageEventDetailsEncoder::encode(const MessageEventEphemeral& event,
std::ostream& os) {
const auto maxLogSizeKB = getMaxLogSizeKB();
const size_t maxLogSize = maxLogSizeKB * 1024;
getDateFormatter()(os, event.getDate());
os << ' ';
const auto severity = event.getSeverity();
os << severity.toStringDataCompact();
os << ' ';
LogComponent component = event.getComponent();
os << component;
os << ' ';
StringData contextName = event.getContextName();
if (!contextName.empty()) {
os << '[' << contextName << "] ";
}
StringData msg = event.getMessage();
#ifdef _WIN32
// We need to translate embedded Unix style line endings into Windows style endings.
std::string tempstr;
size_t embeddedNewLine = msg.find('\n');
if (embeddedNewLine != std::string::npos) {
tempstr = msg.toString().replace(embeddedNewLine, 1, "\r\n");
embeddedNewLine = tempstr.find('\n', embeddedNewLine + 2);
while (embeddedNewLine != std::string::npos) {
tempstr = tempstr.replace(embeddedNewLine, 1, "\r\n");
embeddedNewLine = tempstr.find('\n', embeddedNewLine + 2);
}
msg = tempstr;
}
#endif
if (event.isTruncatable() && msg.size() > maxLogSize) {
os << "warning: log line attempted (" << msg.size() / 1024 << "kB) over max size ("
<< maxLogSizeKB << "kB), printing beginning and end ... ";
os << msg.substr(0, maxLogSize / 3);
os << " .......... ";
os << msg.substr(msg.size() - (maxLogSize / 3));
} else {
os << msg;
}
if (!msg.endsWith(kEOL))
os << kEOL;
return os;
}
示例9: isInRange
bool MongoVersionRange::isInRange(const StringData& version) const {
if (maxVersion == "") {
// If a prefix of the version specified is excluded, the specified version is
// excluded
if (version.find(minVersion) == 0) return true;
}
else {
// Range is inclusive, so make sure the end and beginning prefix excludes all
// prefixed versions as above
if (version.find(minVersion) == 0) return true;
if (version.find(maxVersion) == 0) return true;
if (versionCmp(minVersion, version) <= 0 && versionCmp(maxVersion, version) >= 0) {
return true;
}
}
return false;
}
示例10: userAllowedWriteNS
Status userAllowedWriteNS( const StringData& db, const StringData& coll ) {
// validity checking
if ( db.size() == 0 )
return Status( ErrorCodes::BadValue, "db cannot be blank" );
if ( !NamespaceString::validDBName( db ) )
return Status( ErrorCodes::BadValue, "invalid db name" );
if ( coll.size() == 0 )
return Status( ErrorCodes::BadValue, "collection cannot be blank" );
if ( !NamespaceString::validCollectionName( coll ) )
return Status( ErrorCodes::BadValue, "invalid collection name" );
if ( db.size() + 1 /* dot */ + coll.size() > Namespace::MaxNsColletionLen )
return Status( ErrorCodes::BadValue,
str::stream()
<< "fully qualified namespace " << db << '.' << coll << " is too long "
<< "(max is " << Namespace::MaxNsColletionLen << " bytes)" );
// check spceial areas
if ( db == "system" )
return Status( ErrorCodes::BadValue, "cannot use 'system' database" );
if ( coll.startsWith( "system." ) ) {
if ( coll == "system.indexes" ) return Status::OK();
if ( coll == "system.js" ) return Status::OK();
if ( coll == "system.profile" ) return Status::OK();
if ( coll == "system.users" ) return Status::OK();
if ( db == "admin" ) {
if ( coll == "system.version" ) return Status::OK();
if ( coll == "system.roles" ) return Status::OK();
if ( coll == "system.new_users" ) return Status::OK();
if ( coll == "system.backup_users" ) return Status::OK();
}
if ( db == "local" ) {
if ( coll == "system.replset" ) return Status::OK();
}
return Status( ErrorCodes::BadValue,
str::stream() << "cannot write to '" << db << "." << coll << "'" );
}
// some special rules
if ( coll.find( ".system." ) != string::npos ) {
// this matches old (2.4 and older) behavior, but I'm not sure its a good idea
return Status( ErrorCodes::BadValue,
str::stream() << "cannot write to '" << db << "." << coll << "'" );
}
return Status::OK();
}
示例11: catch
StatusWith<bool> SaslPLAINServerConversation::step(const StringData& inputData,
std::string* outputData) {
// Expecting user input on the form: user\0user\0pwd
std::string input = inputData.toString();
std::string pwd = "";
try {
_user = input.substr(0, inputData.find('\0'));
pwd = input.substr(inputData.find('\0', _user.size()+1)+1);
}
catch (std::out_of_range& exception) {
return StatusWith<bool>(ErrorCodes::AuthenticationFailed,
mongoutils::str::stream() << "Incorrectly formatted PLAIN client message");
}
User* userObj;
// The authentication database is also the source database for the user.
Status status = _saslAuthSession->getAuthorizationSession()->getAuthorizationManager().
acquireUser(_saslAuthSession->getOpCtxt(),
UserName(_user, _saslAuthSession->getAuthenticationDatabase()),
&userObj);
if (!status.isOK()) {
return StatusWith<bool>(status);
}
const User::CredentialData creds = userObj->getCredentials();
_saslAuthSession->getAuthorizationSession()->getAuthorizationManager().
releaseUser(userObj);
std::string authDigest = createPasswordDigest(_user, pwd);
if (authDigest != creds.password) {
return StatusWith<bool>(ErrorCodes::AuthenticationFailed,
mongoutils::str::stream() << "Incorrect user name or password");
}
*outputData = "";
return StatusWith<bool>(true);
}
示例12: legalClientSystemNS
bool legalClientSystemNS(StringData ns, bool write) {
if (ns == "local.system.replset")
return true;
if (ns.find(".system.users") != string::npos)
return true;
if (ns == "admin.system.roles")
return true;
if (ns == kConfigCollection)
return true;
if (ns == "admin.system.new_users")
return true;
if (ns == "admin.system.backup_users")
return true;
if (ns.find(".system.js") != string::npos)
return true;
return false;
}
示例13: init
Status RegexMatchExpression::init(StringData path, StringData regex, StringData options) {
if (regex.size() > MaxPatternSize) {
return Status(ErrorCodes::BadValue, "Regular expression is too long");
}
if (regex.find('\0') != std::string::npos) {
return Status(ErrorCodes::BadValue,
"Regular expression cannot contain an embedded null byte");
}
if (options.find('\0') != std::string::npos) {
return Status(ErrorCodes::BadValue,
"Regular expression options string cannot contain an embedded null byte");
}
_regex = regex.toString();
_flags = options.toString();
_re.reset(new pcrecpp::RE(_regex.c_str(), flags2options(_flags.c_str())));
return setPath(path);
}
示例14: getSSLManager
bool CmdAuthenticate::authenticateX509(const string& dbname,
BSONObj& cmdObj,
string& errmsg,
BSONObjBuilder& result) {
if(dbname != "$external") {
errmsg = "X.509 authentication must always use the $external database.";
result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
return false;
}
std::string user = cmdObj.getStringField("user");
ClientBasic *client = ClientBasic::getCurrent();
AuthorizationSession* authorizationSession = client->getAuthorizationSession();
StringData subjectName = client->port()->getX509SubjectName();
if (user != subjectName) {
errmsg = "There is no x.509 client certificate matching the user.";
result.append(saslCommandCodeFieldName, ErrorCodes::AuthenticationFailed);
return false;
}
else {
StringData srvSubjectName = getSSLManager()->getSubjectName();
StringData srvClusterId = srvSubjectName.substr(0, srvSubjectName.find("/CN")+1);
StringData peerClusterId = subjectName.substr(0, subjectName.find("/CN")+1);
// Handle internal cluster member
if (srvClusterId == peerClusterId) {
authorizationSession->grantInternalAuthorization(UserName(user, "$external"));
}
// Handle normal client authentication
else {
Principal* principal = new Principal(UserName(user, "$external"));
principal->setImplicitPrivilegeAcquisition(true);
authorizationSession->addAuthorizedPrincipal(principal);
}
result.append( "dbname" , dbname );
result.append( "user" , user );
return true;
}
}
示例15: extractElementAtPath
BSONElement extractElementAtPath(const BSONObj& obj, StringData path) {
BSONElement e = obj.getField(path);
if (e.eoo()) {
size_t dot_offset = path.find('.');
if (dot_offset != std::string::npos) {
StringData left = path.substr(0, dot_offset);
StringData right = path.substr(dot_offset + 1);
BSONObj sub = obj.getObjectField(left);
return sub.isEmpty() ? BSONElement() : extractElementAtPath(sub, right);
}
}
return e;
}