]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 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 AJ |
13 | #include "helper/forward.h" |
14 | #include "helper/ResultCode.h" | |
0272dd08 | 15 | #include "MemBuf.h" |
7bbefa01 | 16 | #include "Notes.h" |
0272dd08 | 17 | |
0272dd08 | 18 | #include <ostream> |
0272dd08 | 19 | |
24438ec5 AJ |
20 | namespace Helper |
21 | { | |
0272dd08 AJ |
22 | |
23 | /** | |
24 | * This object stores the reply message from a helper lookup | |
25 | * It provides parser routing to accept a raw buffer and process the | |
26 | * helper reply into fields for easy access by callers | |
27 | */ | |
24438ec5 | 28 | class Reply |
0272dd08 AJ |
29 | { |
30 | private: | |
e166785a | 31 | // copy are prohibited for now |
24438ec5 AJ |
32 | Reply(const Helper::Reply &r); |
33 | Reply &operator =(const Helper::Reply &r); | |
0272dd08 AJ |
34 | |
35 | public: | |
ddc77a2e | 36 | explicit Reply(Helper::ResultCode res) : result(res), notes(), whichServer(NULL) {} |
3c2c35d3 | 37 | |
ddc77a2e CT |
38 | /// Creates a NULL reply |
39 | Reply(); | |
0272dd08 | 40 | |
ddc77a2e | 41 | const MemBuf &other() const {return other_.isNull() ? emptyBuf() : other_;}; |
0272dd08 | 42 | |
7bbefa01 | 43 | /** parse a helper response line format: |
fd7f26ea AJ |
44 | * line := [ result ] *#( kv-pair ) |
45 | * kv-pair := OWS token '=' ( quoted-string | token ) | |
7bbefa01 | 46 | * |
05e52854 AJ |
47 | * token are URL-decoded. |
48 | * quoted-string are \-escape decoded and the quotes are stripped. | |
7bbefa01 AJ |
49 | */ |
50 | // XXX: buf should be const but we may need strwordtok() and rfc1738_unescape() | |
ddc77a2e CT |
51 | //void parse(char *buf, size_t len); |
52 | void finalize(); | |
53 | ||
54 | bool accumulate(const char *buf, size_t len); | |
ab332e27 | 55 | |
0272dd08 AJ |
56 | public: |
57 | /// The helper response 'result' field. | |
24438ec5 | 58 | Helper::ResultCode result; |
0272dd08 | 59 | |
7bbefa01 | 60 | // list of key=value pairs the helper produced |
cf9f0261 | 61 | NotePairs notes; |
0272dd08 AJ |
62 | |
63 | /// for stateful replies the responding helper 'server' needs to be preserved across callbacks | |
64 | CbcPointer<helper_stateful_server> whichServer; | |
65 | ||
66 | private: | |
05e52854 | 67 | void parseResponseKeys(); |
7bbefa01 | 68 | |
ddc77a2e CT |
69 | /// Return an empty MemBuf. |
70 | const MemBuf &emptyBuf() const; | |
71 | ||
0272dd08 AJ |
72 | /// the remainder of the line |
73 | MemBuf other_; | |
74 | }; | |
75 | ||
24438ec5 AJ |
76 | } // namespace Helper |
77 | ||
78 | std::ostream &operator <<(std::ostream &os, const Helper::Reply &r); | |
0272dd08 | 79 | |
24438ec5 | 80 | #endif /* _SQUID_SRC_HELPER_REPLY_H */ |
f53969cc | 81 |