MCPcopy Create free account
hub / github.com/apache/brpc / authenticateRequest

Method authenticateRequest

src/brpc/couchbase.cpp:560–602  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

558}
559
560bool CouchbaseOperations::CouchbaseRequest::authenticateRequest(
561 const butil::StringPiece& username, const butil::StringPiece& password) {
562 if (username.empty() || password.empty()) {
563 DEBUG_PRINT("Empty username or password");
564 return false;
565 }
566 // insert the features to get enabled, calling function helloRequest() will do
567 // this.
568 if (!helloRequest()) {
569 DEBUG_PRINT("Failed to send helloRequest for authentication");
570 return false;
571 }
572 // Construct the request header
573 constexpr char kPlainAuthCommand[] = "PLAIN";
574 constexpr char kPadding[1] = {'\0'};
575 const brpc::policy::CouchbaseRequestHeader header = {
576 brpc::policy::CB_MAGIC_REQUEST,
577 brpc::policy::CB_BINARY_SASL_AUTH,
578 butil::HostToNet16(sizeof(kPlainAuthCommand) - 1),
579 0,
580 0,
581 0,
582 butil::HostToNet32(sizeof(kPlainAuthCommand) + 1 + username.length() * 2 +
583 password.length()),
584 0,
585 0};
586 std::string auth_str;
587 auth_str.reserve(sizeof(header) + sizeof(kPlainAuthCommand) - 1 +
588 username.size() * 2 + password.size() + 2);
589 auth_str.append(reinterpret_cast<const char*>(&header), sizeof(header));
590 auth_str.append(kPlainAuthCommand, sizeof(kPlainAuthCommand) - 1);
591 auth_str.append(username.data(), username.size());
592 auth_str.append(kPadding, sizeof(kPadding));
593 auth_str.append(username.data(), username.size());
594 auth_str.append(kPadding, sizeof(kPadding));
595 auth_str.append(password.data(), password.size());
596 if (_buf.append(auth_str.data(), auth_str.size())) {
597 DEBUG_PRINT("Failed to append auth std::string to buffer");
598 return false;
599 }
600 ++_pipelined_count;
601 return true;
602}
603
604void CouchbaseOperations::CouchbaseRequest::MergeFrom(
605 const CouchbaseRequest& from) {

Callers 3

mainFunction · 0.80
TEST_FFunction · 0.80
authenticateAllMethod · 0.80

Calls 8

HostToNet16Function · 0.85
HostToNet32Function · 0.85
emptyMethod · 0.45
lengthMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45
dataMethod · 0.45

Tested by 1

TEST_FFunction · 0.64