]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 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 | ||
24438ec5 AJ |
9 | #ifndef _SQUID_SRC_HELPER_REPLY_H |
10 | #define _SQUID_SRC_HELPER_REPLY_H | |
0272dd08 AJ |
11 | |
12 | #include "base/CbcPointer.h" | |
24438ec5 | 13 | #include "helper/forward.h" |
a56fcf0b | 14 | #include "helper/ReservationId.h" |
24438ec5 | 15 | #include "helper/ResultCode.h" |
0272dd08 | 16 | #include "MemBuf.h" |
7bbefa01 | 17 | #include "Notes.h" |
0272dd08 | 18 | |
0272dd08 | 19 | #include <ostream> |
0272dd08 | 20 | |
24438ec5 AJ |
21 | namespace Helper |
22 | { | |
0272dd08 AJ |
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 | */ | |
24438ec5 | 29 | class Reply |
0272dd08 AJ |
30 | { |
31 | private: | |
e166785a | 32 | // copy are prohibited for now |
24438ec5 AJ |
33 | Reply(const Helper::Reply &r); |
34 | Reply &operator =(const Helper::Reply &r); | |
0272dd08 AJ |
35 | |
36 | public: | |
a56fcf0b | 37 | explicit Reply(Helper::ResultCode res) : result(res), notes() {} |
3c2c35d3 | 38 | |
ddc77a2e CT |
39 | /// Creates a NULL reply |
40 | Reply(); | |
0272dd08 | 41 | |
ddc77a2e | 42 | const MemBuf &other() const {return other_.isNull() ? emptyBuf() : other_;}; |
0272dd08 | 43 | |
7bbefa01 | 44 | /** parse a helper response line format: |
fd7f26ea AJ |
45 | * line := [ result ] *#( kv-pair ) |
46 | * kv-pair := OWS token '=' ( quoted-string | token ) | |
7bbefa01 | 47 | * |
05e52854 AJ |
48 | * token are URL-decoded. |
49 | * quoted-string are \-escape decoded and the quotes are stripped. | |
7bbefa01 AJ |
50 | */ |
51 | // XXX: buf should be const but we may need strwordtok() and rfc1738_unescape() | |
ddc77a2e CT |
52 | //void parse(char *buf, size_t len); |
53 | void finalize(); | |
54 | ||
55 | bool accumulate(const char *buf, size_t len); | |
ab332e27 | 56 | |
0272dd08 AJ |
57 | public: |
58 | /// The helper response 'result' field. | |
24438ec5 | 59 | Helper::ResultCode result; |
0272dd08 | 60 | |
7bbefa01 | 61 | // list of key=value pairs the helper produced |
cf9f0261 | 62 | NotePairs notes; |
0272dd08 | 63 | |
a56fcf0b CT |
64 | /// The stateful replies should include the reservation ID |
65 | Helper::ReservationId reservationId; | |
0272dd08 | 66 | private: |
27c36771 AR |
67 | static void CheckReceivedKey(const SBuf &, const SBuf &); |
68 | ||
05e52854 | 69 | void parseResponseKeys(); |
7bbefa01 | 70 | |
ddc77a2e CT |
71 | /// Return an empty MemBuf. |
72 | const MemBuf &emptyBuf() const; | |
73 | ||
0272dd08 AJ |
74 | /// the remainder of the line |
75 | MemBuf other_; | |
76 | }; | |
77 | ||
25ecffe5 AR |
78 | std::ostream &operator <<(std::ostream &, const Reply &); |
79 | ||
24438ec5 AJ |
80 | } // namespace Helper |
81 | ||
0272dd08 | 82 | |
24438ec5 | 83 | #endif /* _SQUID_SRC_HELPER_REPLY_H */ |
f53969cc | 84 |