Auth::User::BuildUserKey(const char *username, const char *realm)
{
SBuf key;
- key.Printf("%s:%s", username, realm);
+ if (realm)
+ key.Printf("%s:%s", username, realm);
+ else
+ key.append(username, strlen(username));
return key;
}
if (aString) {
assert(!username_);
username_ = xstrdup(aString);
- if (!requestRealm_.isEmpty())
- userKey_ = BuildUserKey(username_, requestRealm_.c_str());
+ // NP: param #2 is working around a c_str() data-copy performance regression
+ userKey_ = BuildUserKey(username_, (!requestRealm_.isEmpty() ? requestRealm_.c_str() : NULL));
} else {
safe_free(username_);
+ userKey_.clear();
}
}
void absorb(Auth::User::Pointer from);
virtual ~User();
char const *username() const { return username_; }
- void username(char const *);
+ void username(char const *); ///< set stored username and userKey
- const char *userKey() {return !userKey_.isEmpty() ? userKey_.c_str() : username_;}
+ // NP: key is set at the same time as username_. Until then both are empty/NULL.
+ const char *userKey() {return !userKey_.isEmpty() ? userKey_.c_str() : NULL;}
/**
* How long these credentials are still valid for.