]> git.ipfire.org Git - thirdparty/squid.git/blob - src/format/Token.h
Document and enforce invariant on Format::Token.divisor
[thirdparty/squid.git] / src / format / Token.h
1 #ifndef _SQUID_FORMAT_TOKEN_H
2 #define _SQUID_FORMAT_TOKEN_H
3
4 //#include "format/TokenTableEntry.h"
5 #include "format/ByteCode.h"
6
7 /*
8 * Squid configuration allows users to define custom formats in
9 * several components.
10 * - logging
11 * - external ACL input
12 * - deny page URL
13 *
14 * These enumerations and classes define the API for parsing of
15 * format directives to define these patterns. Along with output
16 * functionality to produce formatted buffers.
17 */
18
19 namespace Format
20 {
21
22 class TokenTableEntry;
23
24 #define LOG_BUF_SZ (MAX_URL<<2)
25
26 // XXX: inherit from linked list
27 class Token
28 {
29 public:
30 Token() : type(LFT_NONE),
31 label(NULL),
32 widthMin(-1),
33 widthMax(-1),
34 quote(LOG_QUOTE_NONE),
35 left(false),
36 space(false),
37 zero(false),
38 divisor(1),
39 next(NULL)
40 { data.string = NULL; }
41
42 ~Token();
43
44 /// Initialize the format token registrations
45 static void Init();
46
47 /** parses a single token. Returns the token length in characters,
48 * and fills in this item with the token information.
49 * def is for sure null-terminated.
50 */
51 int parse(const char *def, enum Quoting *quote);
52
53 ByteCode_t type;
54 const char *label;
55 union {
56 char *string;
57
58 struct {
59 char *header;
60 char *element;
61 char separator;
62 } header;
63 char *timespec;
64 } data;
65 int widthMin; ///< minimum field width
66 int widthMax; ///< maximum field width
67 enum Quoting quote;
68 bool left;
69 bool space;
70 bool zero;
71 int divisor; // class invariant: MUST NOT be zero.
72 Token *next; /* todo: move from linked list to array */
73
74 private:
75 const char *scanForToken(TokenTableEntry const table[], const char *cur);
76 };
77
78 } // namespace Format
79
80 #endif /* _SQUID_FORMAT_TOKEN_H */