]> git.ipfire.org Git - thirdparty/squid.git/blob - src/helper/Reply.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / helper / Reply.h
1 /*
2 * Copyright (C) 1996-2020 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_HELPER_REPLY_H
10 #define _SQUID_SRC_HELPER_REPLY_H
11
12 #include "base/CbcPointer.h"
13 #include "helper/forward.h"
14 #include "helper/ReservationId.h"
15 #include "helper/ResultCode.h"
16 #include "MemBuf.h"
17 #include "Notes.h"
18
19 #include <ostream>
20
21 namespace Helper
22 {
23
24 /**
25 * This object stores the reply message from a helper lookup
26 * It provides parser routing to accept a raw buffer and process the
27 * helper reply into fields for easy access by callers
28 */
29 class Reply
30 {
31 private:
32 // copy are prohibited for now
33 Reply(const Helper::Reply &r);
34 Reply &operator =(const Helper::Reply &r);
35
36 public:
37 explicit Reply(Helper::ResultCode res) : result(res), notes() {}
38
39 /// Creates a NULL reply
40 Reply();
41
42 const MemBuf &other() const {return other_.isNull() ? emptyBuf() : other_;};
43
44 /** parse a helper response line format:
45 * line := [ result ] *#( kv-pair )
46 * kv-pair := OWS token '=' ( quoted-string | token )
47 *
48 * token are URL-decoded.
49 * quoted-string are \-escape decoded and the quotes are stripped.
50 */
51 // XXX: buf should be const but we may need strwordtok() and rfc1738_unescape()
52 //void parse(char *buf, size_t len);
53 void finalize();
54
55 bool accumulate(const char *buf, size_t len);
56
57 public:
58 /// The helper response 'result' field.
59 Helper::ResultCode result;
60
61 // list of key=value pairs the helper produced
62 NotePairs notes;
63
64 /// The stateful replies should include the reservation ID
65 Helper::ReservationId reservationId;
66 private:
67 void parseResponseKeys();
68
69 /// Return an empty MemBuf.
70 const MemBuf &emptyBuf() const;
71
72 /// the remainder of the line
73 MemBuf other_;
74 };
75
76 } // namespace Helper
77
78 std::ostream &operator <<(std::ostream &os, const Helper::Reply &r);
79
80 #endif /* _SQUID_SRC_HELPER_REPLY_H */
81