notes(),
credentials_state(Auth::Unchecked),
username_(NULL),
- requestRealm_(aRequestRealm)
+ userKey_(NULL)
{
+ requestRealm_ = aRequestRealm ? xstrdup(aRequestRealm) : NULL;
proxy_match_cache.head = proxy_match_cache.tail = NULL;
ip_list.head = ip_list.tail = NULL;
debugs(29, 5, HERE << "Initialised auth_user '" << this << "'.");
if (username_)
xfree((char*)username_);
+ if (requestRealm_)
+ xfree((char*)requestRealm_);
+ if (userKey_)
+ xfree((char*)userKey_);
/* prevent accidental reuse */
auth_type = Auth::AUTH_UNKNOWN;
void
Auth::User::username(char const *aString)
{
+ SBuf key;
+
if (aString) {
assert(!username_);
username_ = xstrdup(aString);
- // NP: param #2 is working around a c_str() data-copy performance regression
- userKey_ = BuildUserKey(username_, (!requestRealm_.isEmpty() ? requestRealm_.c_str() : NULL));
+ key = BuildUserKey(username_, requestRealm_);
+ // XXX; performance regression. c_str() reallocates, then xstrdup() reallocates
+ userKey_ = xstrdup(key.c_str());
} else {
safe_free(username_);
- userKey_.clear();
+ safe_free(userKey_)
}
}
void username(char const *); ///< set stored username and userKey
// 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;}
+ const char *userKey() {return userKey_;}
/**
* How long these credentials are still valid for.
/**
* A realm for the user depending on request, designed to identify users,
* with the same username and different authentication domains.
+ * The requestRealm_ memory will be allocated via xstrdup().
+ * It is our responsibility.
*/
- SBuf requestRealm_;
+ const char *requestRealm_;
/**
- * A Unique key for the user, consist by username and requestRealm_
+ * A Unique key for the user, consist by username and realm.
+ * The userKey_ memory will be allocated via xstrdup().
+ * It is our responsibility.
*/
- SBuf userKey_;
+ const char *userKey_;
/** what ip addresses has this user been seen at?, plus a list length cache */
dlink_list ip_list;