2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SSL_CRTD_MESSAGE_H
10 #define SQUID_SSL_CRTD_MESSAGE_H
17 class CertificateProperties
;
20 * This class is responsible for composing and parsing messages destined to, or comming
21 * from an ssl_crtd server. Format of these mesages is:
22 * response/request-code SP body length SP body
27 typedef std::map
<std::string
, std::string
> BodyParams
;
28 /// Parse result codes.
38 CrtdMessage(MessageKind kind
);
39 /**Parse buffer of length len
40 \retval OK if parsing completes
41 \retval INCOMPLETE if more data required
42 \retval ERROR if there is an error.
44 ParseResult
parse(const char * buffer
, size_t len
);
45 /// Current body. If parsing is not finished the method returns incompleted body.
46 std::string
const & getBody() const;
47 /// Current response/request code. If parsing is not finished the method may return incompleted code.
48 std::string
const & getCode() const;
49 void setBody(std::string
const & aBody
); ///< Set new body to encode.
50 void setCode(std::string
const & aCode
); ///< Set new request/reply code to compose.
51 std::string
compose() const; ///< Compose current (request) code and body to string.
55 *Parse body data which has the form: \verbatim
58 The other multistring part of body. \endverbatim
59 * The parameters of the body stored to map and the remaining part to other_part
61 void parseBody(BodyParams
& map
, std::string
& other_part
) const;
63 *Compose parameters given by map with their values and the other part given by
64 * other_part to body data. The constructed body will have the form: \verbatim
67 The other multistring part of body. \endverbatim
69 void composeBody(BodyParams
const & map
, std::string
const & other_part
);
71 /// orchestrates entire request parsing
72 bool parseRequest(Ssl::CertificateProperties
&, std::string
&error
);
73 void composeRequest(Ssl::CertificateProperties
const &); // throws
75 /// String code for "new_certificate" messages
76 static const std::string code_new_certificate
;
77 /// Parameter name for passing hostname
78 static const std::string param_host
;
79 /// Parameter name for passing SetValidAfter cert adaptation variable
80 static const std::string param_SetValidAfter
;
81 /// Parameter name for passing SetValidBefore cert adaptation variable
82 static const std::string param_SetValidBefore
;
83 /// Parameter name for passing SetCommonName cert adaptation variable
84 static const std::string param_SetCommonName
;
85 /// Parameter name for passing signing algorithm
86 static const std::string param_Sign
;
87 /// The signing hash to use
88 static const std::string param_SignHash
;
99 size_t body_size
; ///< The body size if exist or 0.
100 ParseState state
; ///< Parsing state.
101 std::string body
; ///< Current body.
102 std::string code
; ///< Current response/request code.
103 std::string current_block
; ///< Current block buffer.
108 #endif // SQUID_SSL_CRTD_MESSAGE_H