{
if (wait > 0)
os << "lookup_wait=" << wait;
- if (error.size())
- os << " lookup_err=" << error;
+ if (error)
+ os << " lookup_err=" << *error;
return os;
}
#ifndef SQUID_DNS_LOOKUPDETAILS_H
#define SQUID_DNS_LOOKUPDETAILS_H
-#include "SquidString.h"
+#include "sbuf/SBuf.h"
+
+#include <optional>
namespace Dns
{
class LookupDetails
{
public:
- LookupDetails() : wait(-1) {} ///< no error, no lookup delay (i.e., no lookup)
- LookupDetails(const String &anError, int aWait) : error(anError), wait(aWait) {}
+ /// no lookup attempt: no error and no lookup delay
+ LookupDetails(): wait(-1) {}
+
+ /// details a possible lookup attempt
+ /// \param anError either a failed attempt error message or an empty string
+ /// \param aWait \copydoc wait
+ LookupDetails(const SBuf &anError, const int aWait):
+ error(anError.isEmpty() ? std::nullopt : std::make_optional(anError)),
+ wait(aWait)
+ {}
std::ostream &print(std::ostream &os) const;
public:
- String error; ///< error message for unsuccessful lookups; empty otherwise
+ const std::optional<SBuf> error; ///< error message (if any)
int wait; ///< msecs spent waiting for the lookup (if any) or -1 (if none)
};
if (auth_user_request.getRaw() && auth_user_request->denyMessage())
str.appendf("Auth ErrMsg: %s\r\n", auth_user_request->denyMessage());
#endif
- if (dnsError.size() > 0)
- str.appendf("DNS ErrMsg: %s\r\n", dnsError.termedBuf());
+ if (dnsError)
+ str.appendf("DNS ErrMsg: " SQUIDSBUFPH "\r\n", SQUIDSBUFPRINT(*dnsError));
/* - TimeStamp */
str.appendf("TimeStamp: %s\r\n\r\n", Time::FormatRfc1123(squid_curtime));
case 'z':
if (building_deny_info_url) break;
- if (dnsError.size() > 0)
- p = dnsError.termedBuf();
+ if (dnsError)
+ p = dnsError->c_str();
else if (ftp.cwd_msg)
p = ftp.cwd_msg;
else
/* auth/UserRequest.h is empty unless USE_AUTH is defined */
#include "auth/UserRequest.h"
+#include <optional>
+
/// error page callback
typedef void ERCB(int fd, void *, size_t);
char *url = nullptr;
int xerrno = 0;
unsigned short port = 0;
- String dnsError; ///< DNS lookup error message
+ std::optional<SBuf> dnsError; ///< DNS lookup error message
time_t ttl = 0;
Ip::Address src_addr;
f->handler = nullptr;
if (cbdataReferenceValidDone(f->handlerData, &cbdata)) {
- const Dns::LookupDetails details(f->error_message, wait);
+ const Dns::LookupDetails details(SBuf(f->error_message), wait);
callback(f->name_count ? f->names[0] : nullptr, details, cbdata);
}
if (name[0] == '\0') {
debugs(35, 4, "fqdncache_nbgethostbyaddr: Invalid name!");
- const Dns::LookupDetails details("Invalid hostname", -1); // error, no lookup
+ static const Dns::LookupDetails details(SBuf("Invalid hostname"), -1); // error, no lookup
if (handler)
handler(nullptr, details, handlerData);
return;
// are sequential. Give it just the new, yet-unaccounted-for delay.
if (receiverObj.set()) {
if (auto receiver = receiverObj.valid()) {
- receiver->noteLookup(Dns::LookupDetails(error, additionalLookupDelay()));
+ receiver->noteLookup(Dns::LookupDetails(SBuf(error), additionalLookupDelay()));
lastLookupEnd = current_time;
}
}
if (hit)
i->handler.forwardHits(i->addrs);
- const Dns::LookupDetails details(i->error_message, wait);
+ const Dns::LookupDetails details(SBuf(i->error_message), wait);
i->handler.finalCallback(&i->addrs, details);
ipcacheUnlockEntry(i);
if (name == nullptr || name[0] == '\0') {
debugs(14, 4, "ipcache_nbgethostbyname: Invalid name!");
++IpcacheStats.invalid;
- const Dns::LookupDetails details("Invalid hostname", -1); // error, no lookup
+ static const Dns::LookupDetails details(SBuf("Invalid hostname"), -1); // error, no lookup
handler.finalCallback(nullptr, details);
return;
}