]> git.ipfire.org Git - thirdparty/squid.git/blame - src/format/Format.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / format / Format.h
CommitLineData
bbc27441 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
bbc27441
AJ
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
38e16f92
AJ
9#ifndef _SQUID_FORMAT_FORMAT_H
10#define _SQUID_FORMAT_FORMAT_H
11
8bf217bd 12#include "base/RefCount.h"
2eceb328 13#include "ConfigParser.h"
f57ae909 14#include "sbuf/SBuf.h"
bbc27441 15
38e16f92
AJ
16/*
17 * Squid configuration allows users to define custom formats in
18 * several components.
19 * - logging
20 * - external ACL input
21 * - deny page URL
22 *
23 * These enumerations and classes define the API for parsing of
24 * format directives to define these patterns. Along with output
25 * functionality to produce formatted buffers.
26 */
27
28class AccessLogEntry;
41ebd397 29typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
38e16f92
AJ
30class MemBuf;
31class StoreEntry;
32
33namespace Format
34{
35
f57ae909
NH
36extern const SBuf Dash;
37
38e16f92
AJ
38class Token;
39
40// XXX: inherit from linked list
41class Format
42{
43public:
44 Format(const char *name);
2eceb328 45 virtual ~Format();
38e16f92
AJ
46
47 /* very inefficent parser, but who cares, this needs to be simple */
48 /* First off, let's tokenize, we'll optimize in a second pass.
49 * A token can either be a %-prefixed sequence (usually a dynamic
50 * token but it can be an escaped sequence), or a string. */
f4698e0b 51 bool parse(const char *def);
38e16f92
AJ
52
53 /// assemble the state information into a formatted line.
41ebd397 54 void assemble(MemBuf &mb, const AccessLogEntryPointer &al, int logSequenceNumber) const;
38e16f92
AJ
55
56 /// dump this whole list of formats into the provided StoreEntry
4e56d7f6 57 void dump(StoreEntry * entry, const char *directiveName, bool eol = true) const;
38e16f92
AJ
58
59 char *name;
60 Token *format;
61 Format *next;
62};
63
7e6eabbc
CT
64/// Compiles a single logformat %code expression into the given buffer.
65/// Ignores any input characters after the expression.
66/// \param start where the logformat expression begins
67/// \return the length of the parsed %code expression
68size_t AssembleOne(const char *start, MemBuf &buf, const AccessLogEntryPointer &ale);
69
38e16f92
AJ
70} // namespace Format
71
72#endif /* _SQUID_FORMAT_FORMAT_H */
f53969cc 73