]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ssl/crtd_message.h
8a9db08547b695c440cfd08d272ee06767a391b3
[thirdparty/squid.git] / src / ssl / crtd_message.h
1 /*
2 * Copyright (C) 1996-2017 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_SSL_CRTD_MESSAGE_H
10 #define SQUID_SSL_CRTD_MESSAGE_H
11
12 #include <map>
13 #include <string>
14
15 namespace Ssl
16 {
17 class CertificateProperties;
18
19 /**
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
23 */
24 class CrtdMessage
25 {
26 public:
27 typedef std::map<std::string, std::string> BodyParams;
28 /// Parse result codes.
29 enum ParseResult {
30 OK,
31 INCOMPLETE,
32 ERROR
33 };
34 enum MessageKind {
35 REPLY,
36 REQUEST
37 };
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.
43 */
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.
52 /// Reset the class.
53 void clear();
54 /**
55 *Parse body data which has the form: \verbatim
56 param1=value1
57 param2=value2
58 The other multistring part of body. \endverbatim
59 * The parameters of the body stored to map and the remaining part to other_part
60 */
61 void parseBody(BodyParams & map, std::string & other_part) const;
62 /**
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
65 param1=value1
66 param2=value2
67 The other multistring part of body. \endverbatim
68 */
69 void composeBody(BodyParams const & map, std::string const & other_part);
70
71 /// orchestrates entire request parsing
72 bool parseRequest(Ssl::CertificateProperties &, std::string &error);
73 void composeRequest(Ssl::CertificateProperties const &); // throws
74
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;
89 protected:
90 enum ParseState {
91 BEFORE_CODE,
92 CODE,
93 BEFORE_LENGTH,
94 LENGTH,
95 BEFORE_BODY,
96 BODY,
97 END
98 };
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.
104 };
105
106 } //namespace Ssl
107
108 #endif // SQUID_SSL_CRTD_MESSAGE_H
109