/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// The character classes in this file are informed by [RFC2616], Section 2.2. // signed char is a signed data type one byte (8 bits) wide, so its value can // never be greater than 127. The following implicitly makes use of this.
// A token is one or more CHAR except CTLs or separators. // A CHAR is any US-ASCII character (octets 0 - 127). // A CTL is any US-ASCII control character (octets 0 - 31) and DEL (127). // A separator is one of ()<>@,;:\"/[]?={} as well as space and // horizontal-tab (32 and 9, respectively). // So, this returns true if chr is any octet 33-126 except ()<>@,;:\"/[]?={} bool IsTokenSymbol(signedchar chr) { if (chr < 33 || chr == 127 || chr == '(' || chr == ')' || chr == '<' ||
chr == '>' || chr == '@' || chr == ',' || chr == ';' || chr == ':' ||
chr == '"' || chr == '/' || chr == '[' || chr == ']' || chr == '?' ||
chr == '=' || chr == '{' || chr == '}' || chr == '\\') { returnfalse;
} returntrue;
}
// A quoted-string consists of a quote (") followed by any amount of // qdtext or quoted-pair, followed by a quote. // qdtext is any TEXT except a quote. // TEXT is any 8-bit octet except CTLs, but including LWS. // quoted-pair is a backslash (\) followed by a CHAR. // So, it turns out, \ can't really be a qdtext symbol for our purposes. // This returns true if chr is any octet 9,10,13,32-126 except <"> or "\" bool IsQuotedTextSymbol(signedchar chr) { return ((chr >= 32 && chr != '"' && chr != '\\' && chr != 127) ||
chr == 0x9 || chr == 0xa || chr == 0xd);
}
// The octet following the "\" in a quoted pair can be anything 0-127. bool IsQuotedPairSymbol(signedchar chr) { return (chr >= 0); }
nsresult nsSecurityHeaderParser::Parse() {
MOZ_ASSERT(mDirectives.isEmpty());
SHPARSERLOG(("trying to parse '%s'", mCursor));
Header();
// if we didn't consume the entire input, we were unable to parse it => error if (mError || *mCursor) { return NS_ERROR_FAILURE;
} else { return NS_OK;
}
}
void nsSecurityHeaderParser::Advance() { // Technically, 0 is valid in quoted-pair, but we were handed a // null-terminated const char *, so this doesn't handle that. if (*mCursor) {
mOutput.Append(*mCursor);
mCursor++;
} else {
mError = true;
}
}
void nsSecurityHeaderParser::Header() {
Directive(); while (Accept(';')) {
Directive();
}
}
void nsSecurityHeaderParser::Directive() {
mDirective = new nsSecurityHeaderDirective();
LWSMultiple();
DirectiveName();
LWSMultiple(); if (Accept('=')) {
LWSMultiple();
DirectiveValue();
LWSMultiple();
}
mDirectives.insertBack(mDirective); if (mDirective->mValue.isSome()) {
SHPARSERLOG(("read directive name '%s', value '%s'",
mDirective->mName.Data(), mDirective->mValue->Data()));
} else {
SHPARSERLOG(
("read valueless directive name '%s'", mDirective->mName.Data()));
}
}
void nsSecurityHeaderParser::DirectiveValue() {
mOutput.Truncate(0);
mDirective->mValue.emplace(); if (Accept(IsTokenSymbol)) {
Token();
mDirective->mValue->Assign(mOutput);
} elseif (Accept('"')) { // Accept advances the cursor if successful, which appends a character to // mOutput. The " is not part of what we want to capture, so truncate // mOutput again.
mOutput.Truncate(0);
QuotedString();
mDirective->mValue->Assign(mOutput);
Expect('"');
}
}
void nsSecurityHeaderParser::Token() { while (Accept(IsTokenSymbol)); }
void nsSecurityHeaderParser::LWS() { // Note that becaue of how we're called, we don't have to check for // the mandatory presense of at least one of SP or HT. while (Accept(' ') || Accept('\t'));
}
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.