]>
Commit | Line | Data |
---|---|---|
bbc27441 AJ |
1 | /* |
2 | * Copyright (C) 1996-2014 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 | ||
0272dd08 AJ |
9 | #ifndef _SQUID_SRC_HELPERREPLY_H |
10 | #define _SQUID_SRC_HELPERREPLY_H | |
11 | ||
12 | #include "base/CbcPointer.h" | |
13 | #include "MemBuf.h" | |
7bbefa01 | 14 | #include "Notes.h" |
0272dd08 | 15 | |
0272dd08 | 16 | #include <ostream> |
0272dd08 AJ |
17 | |
18 | class helper_stateful_server; | |
19 | ||
20 | /** | |
21 | * This object stores the reply message from a helper lookup | |
22 | * It provides parser routing to accept a raw buffer and process the | |
23 | * helper reply into fields for easy access by callers | |
24 | */ | |
25 | class HelperReply | |
26 | { | |
27 | private: | |
e166785a | 28 | // copy are prohibited for now |
0272dd08 AJ |
29 | HelperReply(const HelperReply &r); |
30 | HelperReply &operator =(const HelperReply &r); | |
31 | ||
32 | public: | |
fd7f26ea | 33 | HelperReply() : result(HelperReply::Unknown), notes(), whichServer(NULL) { |
3c2c35d3 AJ |
34 | other_.init(1,1); |
35 | other_.terminate(); | |
36 | } | |
37 | ||
0272dd08 | 38 | // create/parse details from the msg buffer provided |
7bbefa01 | 39 | // XXX: buf should be const but parse() needs non-const for now |
05e52854 | 40 | HelperReply(char *buf, size_t len); |
0272dd08 AJ |
41 | |
42 | const MemBuf &other() const { return other_; } | |
43 | ||
44 | /// backward compatibility: | |
45 | /// access to modifiable blob, required by redirectHandleReply() | |
46 | /// and by urlParse() in ClientRequestContext::clientRedirectDone() | |
47 | /// and by token blob/arg parsing in Negotiate auth handler | |
48 | MemBuf &modifiableOther() const { return *const_cast<MemBuf*>(&other_); } | |
49 | ||
7bbefa01 | 50 | /** parse a helper response line format: |
fd7f26ea AJ |
51 | * line := [ result ] *#( kv-pair ) |
52 | * kv-pair := OWS token '=' ( quoted-string | token ) | |
7bbefa01 | 53 | * |
05e52854 AJ |
54 | * token are URL-decoded. |
55 | * quoted-string are \-escape decoded and the quotes are stripped. | |
7bbefa01 AJ |
56 | */ |
57 | // XXX: buf should be const but we may need strwordtok() and rfc1738_unescape() | |
05e52854 | 58 | void parse(char *buf, size_t len); |
ab332e27 | 59 | |
0272dd08 AJ |
60 | public: |
61 | /// The helper response 'result' field. | |
62 | enum Result_ { | |
63 | Unknown, // no result code received, or unknown result code | |
64 | Okay, // "OK" indicating success/positive result | |
7bbefa01 | 65 | Error, // "ERR" indicating success/negative result |
0272dd08 AJ |
66 | BrokenHelper, // "BH" indicating failure due to helper internal problems. |
67 | ||
7bbefa01 | 68 | // result codes for backward compatibility with NTLM/Negotiate |
fd7f26ea | 69 | // TODO: migrate to a variant of the above results with kv-pair parameters |
7bbefa01 | 70 | TT |
0272dd08 AJ |
71 | } result; |
72 | ||
7bbefa01 | 73 | // list of key=value pairs the helper produced |
cf9f0261 | 74 | NotePairs notes; |
0272dd08 AJ |
75 | |
76 | /// for stateful replies the responding helper 'server' needs to be preserved across callbacks | |
77 | CbcPointer<helper_stateful_server> whichServer; | |
78 | ||
79 | private: | |
05e52854 | 80 | void parseResponseKeys(); |
7bbefa01 | 81 | |
0272dd08 AJ |
82 | /// the remainder of the line |
83 | MemBuf other_; | |
84 | }; | |
85 | ||
86 | std::ostream &operator <<(std::ostream &os, const HelperReply &r); | |
87 | ||
88 | #endif /* _SQUID_SRC_HELPERREPLY_H */ |