1 /*
2  * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_HTTP_CONTENTLENGTH_INTERPRETER_H
10 #define SQUID_SRC_HTTP_CONTENTLENGTH_INTERPRETER_H
11 
12 class String;
13 
14 namespace Http
15 {
16 
17 /// Finds the intended Content-Length value while parsing message-header fields.
18 /// Deals with complications such as value lists and/or repeated fields.
19 class ContentLengthInterpreter
20 {
21 public:
22     explicit ContentLengthInterpreter(const int aDebugLevel);
23 
24     /// updates history based on the given message-header field
25     /// \return true iff the field should be added/remembered for future use
26     bool checkField(const String &field);
27 
28     /// intended Content-Length value if sawGood is set and sawBad is not set
29     /// meaningless otherwise
30     int64_t value;
31 
32     /* for debugging (declared here to minimize padding) */
33     const char *headerWideProblem; ///< worst header-wide problem found (or nil)
34     const int debugLevel; ///< debugging level for certain warnings
35 
36     /// whether a malformed Content-Length value was present
37     bool sawBad;
38 
39     /// whether all remembered fields should be removed
40     /// removed fields ought to be replaced with the intended value (if known)
41     /// irrelevant if sawBad is set
42     bool needsSanitizing;
43 
44     /// whether a valid field value was present, possibly among problematic ones
45     /// irrelevant if sawBad is set
46     bool sawGood;
47 
48 protected:
49     const char *findDigits(const char *prefix, const char *valueEnd) const;
50     bool goodSuffix(const char *suffix, const char * const end) const;
51     bool checkValue(const char *start, const int size);
52     bool checkList(const String &list);
53 };
54 
55 } // namespace Http
56 
57 #endif /* SQUID_SRC_HTTP_CONTENTLENGTH_INTERPRETER_H */
58 
59