1 /* 2 * Copyright (C) 1996-2021 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: Reply(Helper::ResultCode res)36 explicit Reply(Helper::ResultCode res) : result(res), notes(), whichServer(NULL) {} 37 38 /// Creates a NULL reply 39 Reply(); 40 other()41 const MemBuf &other() const {return other_.isNull() ? emptyBuf() : other_;}; 42 43 /** parse a helper response line format: 44 * line := [ result ] *#( kv-pair ) 45 * kv-pair := OWS token '=' ( quoted-string | token ) 46 * 47 * token are URL-decoded. 48 * quoted-string are \-escape decoded and the quotes are stripped. 49 */ 50 // XXX: buf should be const but we may need strwordtok() and rfc1738_unescape() 51 //void parse(char *buf, size_t len); 52 void finalize(); 53 54 bool accumulate(const char *buf, size_t len); 55 56 public: 57 /// The helper response 'result' field. 58 Helper::ResultCode result; 59 60 // list of key=value pairs the helper produced 61 NotePairs notes; 62 63 /// for stateful replies the responding helper 'server' needs to be preserved across callbacks 64 CbcPointer<helper_stateful_server> whichServer; 65 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 82