]> git.ipfire.org Git - thirdparty/squid.git/blob - src/helper/Reply.h
Merged from trunk
[thirdparty/squid.git] / src / helper / Reply.h
1 /*
2 * Copyright (C) 1996-2015 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/ResultCode.h"
15 #include "MemBuf.h"
16 #include "Notes.h"
17
18 #include <ostream>
19
20 namespace Helper
21 {
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 */
28 class Reply
29 {
30 private:
31 // copy are prohibited for now
32 Reply(const Helper::Reply &r);
33 Reply &operator =(const Helper::Reply &r);
34
35 public:
36 explicit Reply(Helper::ResultCode res = Helper::Unknown) : result(res), notes(), whichServer(NULL) {
37 other_.init(1,1);
38 other_.terminate();
39 }
40
41 // create/parse details from the msg buffer provided
42 // XXX: buf should be const but parse() needs non-const for now
43 Reply(char *buf, size_t len);
44
45 const MemBuf &other() const { return other_; }
46
47 /// backward compatibility:
48 /// access to modifiable blob, required by redirectHandleReply()
49 /// and by urlParse() in ClientRequestContext::clientRedirectDone()
50 /// and by token blob/arg parsing in Negotiate auth handler
51 MemBuf &modifiableOther() const { return *const_cast<MemBuf*>(&other_); }
52
53 /** parse a helper response line format:
54 * line := [ result ] *#( kv-pair )
55 * kv-pair := OWS token '=' ( quoted-string | token )
56 *
57 * token are URL-decoded.
58 * quoted-string are \-escape decoded and the quotes are stripped.
59 */
60 // XXX: buf should be const but we may need strwordtok() and rfc1738_unescape()
61 void parse(char *buf, size_t len);
62
63 public:
64 /// The helper response 'result' field.
65 Helper::ResultCode result;
66
67 // list of key=value pairs the helper produced
68 NotePairs notes;
69
70 /// for stateful replies the responding helper 'server' needs to be preserved across callbacks
71 CbcPointer<helper_stateful_server> whichServer;
72
73 private:
74 void parseResponseKeys();
75
76 /// the remainder of the line
77 MemBuf other_;
78 };
79
80 } // namespace Helper
81
82 std::ostream &operator <<(std::ostream &os, const Helper::Reply &r);
83
84 #endif /* _SQUID_SRC_HELPER_REPLY_H */
85