security/manager/boot/src/nsSecurityHeaderParser.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsSecurityHeaderParser_h__
michael@0 6 #define nsSecurityHeaderParser_h__
michael@0 7
michael@0 8 #include "nsString.h"
michael@0 9 #include "mozilla/LinkedList.h"
michael@0 10 #include "nsCOMPtr.h"
michael@0 11
michael@0 12 // Utility class for handing back parsed directives and (optional) values
michael@0 13 class nsSecurityHeaderDirective : public mozilla::LinkedListElement<nsSecurityHeaderDirective> {
michael@0 14 public:
michael@0 15 nsAutoCString mName;
michael@0 16 nsAutoCString mValue;
michael@0 17 };
michael@0 18
michael@0 19 // This class parses security-related HTTP headers like
michael@0 20 // Strict-Transport-Security. The Augmented Backus-Naur Form syntax for this
michael@0 21 // header is reproduced below, for reference:
michael@0 22 //
michael@0 23 // Strict-Transport-Security = "Strict-Transport-Security" ":"
michael@0 24 // [ directive ] *( ";" [ directive ] )
michael@0 25 //
michael@0 26 // directive = directive-name [ "=" directive-value ]
michael@0 27 // directive-name = token
michael@0 28 // directive-value = token | quoted-string
michael@0 29 //
michael@0 30 // where:
michael@0 31 //
michael@0 32 // token = <token, defined in [RFC2616], Section 2.2>
michael@0 33 // quoted-string = <quoted-string, defined in [RFC2616], Section 2.2>/
michael@0 34 //
michael@0 35 // For further reference, see [RFC6797], Section 6.1
michael@0 36
michael@0 37 class nsSecurityHeaderParser {
michael@0 38 public:
michael@0 39 explicit nsSecurityHeaderParser(const char *aHeader);
michael@0 40 ~nsSecurityHeaderParser();
michael@0 41
michael@0 42 // Only call Parse once.
michael@0 43 nsresult Parse();
michael@0 44 // The caller does not take ownership of the memory returned here.
michael@0 45 mozilla::LinkedList<nsSecurityHeaderDirective> *GetDirectives();
michael@0 46
michael@0 47 private:
michael@0 48 bool Accept(char aChr);
michael@0 49 bool Accept(bool (*aClassifier) (signed char));
michael@0 50 void Expect(char aChr);
michael@0 51 void Advance();
michael@0 52 void Header(); // header = [ directive ] *( ";" [ directive ] )
michael@0 53 void Directive(); // directive = directive-name [ "=" directive-value ]
michael@0 54 void DirectiveName(); // directive-name = token
michael@0 55 void DirectiveValue(); // directive-value = token | quoted-string
michael@0 56 void Token(); // token = 1*<any CHAR except CTLs or separators>
michael@0 57 void QuotedString(); // quoted-string = (<"> *( qdtext | quoted-pair ) <">)
michael@0 58 void QuotedText(); // qdtext = <any TEXT except <"> and "\">
michael@0 59 void QuotedPair(); // quoted-pair = "\" CHAR
michael@0 60
michael@0 61 // LWS = [CRLF] 1*( SP | HT )
michael@0 62 void LWSMultiple(); // Handles *( LWS )
michael@0 63 void LWSCRLF(); // Handles the [CRLF] part of LWS
michael@0 64 void LWS(); // Handles the 1*( SP | HT ) part of LWS
michael@0 65
michael@0 66 mozilla::LinkedList<nsSecurityHeaderDirective> mDirectives;
michael@0 67 const char *mCursor;
michael@0 68 nsSecurityHeaderDirective *mDirective;
michael@0 69
michael@0 70 nsAutoCString mOutput;
michael@0 71 bool mError;
michael@0 72 };
michael@0 73
michael@0 74 #endif /* nsSecurityHeaderParser_h__ */

mercurial