}
}
-bool
-NotePairs::find(SBuf &resultNote, const char *noteKey, const char *sep) const
+std::optional<SBuf>
+NotePairs::find(const char *noteKey, const char *sep) const
{
- resultNote.clear();
+ SBuf resultNote;
+
for (const auto &e: entries) {
if (!e->name().cmp(noteKey)) {
if (!resultNote.isEmpty())
resultNote.append(e->value());
}
}
- return resultNote.length();
+
+ if (resultNote.isEmpty())
+ return std::nullopt;
+
+ return resultNote;
}
void
#include "SquidString.h"
#include <iosfwd>
+#include <optional>
#include <string>
#include <vector>
/// Entries which already exist in the destination set are ignored.
void appendNewOnly(const NotePairs *src);
- /// \param resultNote a comma separated list of notes with key 'noteKey'.
- /// \returns true if there are entries with the given 'noteKey'.
+ /// \returns a comma separated list of notes with key 'noteKey', if any.
/// Use findFirst() instead when a unique kv-pair is needed.
- bool find(SBuf &resultNote, const char *noteKey, const char *sep = ",") const;
+ std::optional<SBuf> find(const char *noteKey, const char *sep = ",") const;
/// \returns the first note value for this key or an empty string.
const char *findFirst(const char *noteKey) const;
#include "HttpReply.h"
#include "HttpRequest.h"
#include "MemBuf.h"
+#include "sbuf/Stream.h"
/* Generic Functions */
void
Auth::UserRequest::denyMessageFromHelper(const char *proto, const Helper::Reply &reply)
{
- static SBuf messageNote;
- if (!reply.notes.find(messageNote, "message")) {
- messageNote.append(proto);
- messageNote.append(" Authentication denied with no reason given");
+ auto messageNote = reply.notes.find("message");
+
+ if (!messageNote) {
+ messageNote = ToSBuf(proto, " Authentication denied with no reason given");
}
- setDenyMessage(messageNote.c_str());
-}
+ setDenyMessage(messageNote->c_str());
+}
digest_request->user()->credentials(Auth::Failed);
digest_request->flags.invalid_password = true;
- SBuf msgNote;
- if (reply.notes.find(msgNote, "message")) {
- digest_request->setDenyMessage(msgNote.c_str());
+ if (auto msgNote = reply.notes.find("message")) {
+ digest_request->setDenyMessage(msgNote->c_str());
} else if (reply.other().hasContent()) {
// old helpers did send ERR result but a bare message string instead of message= key name.
// TODO deprecate and remove old auth digest helper protocol
tmp[1] = '\0';
if (fmt->data.header.header && *fmt->data.header.header) {
const char *separator = tmp;
- static SBuf note;
#if USE_ADAPTATION
Adaptation::History::Pointer ah = al->request ? al->request->adaptHistory() : Adaptation::History::Pointer();
if (ah && ah->metaHeaders) {
- if (ah->metaHeaders->find(note, fmt->data.header.header, separator))
- sb.append(note);
+ if (const auto note = ah->metaHeaders->find(fmt->data.header.header, separator))
+ sb.append(*note);
}
#endif
if (al->notes) {
- if (al->notes->find(note, fmt->data.header.header, separator)) {
+ if (const auto note = al->notes->find(fmt->data.header.header, separator)) {
if (!sb.isEmpty())
sb.append(separator);
- sb.append(note);
+ sb.append(*note);
}
}
out = sb.c_str();