comparison 3rdparty/vmime/src/vmime/net/smtp/SMTPResponse.hpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 //
2 // VMime library (http://www.vmime.org)
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Linking this library statically or dynamically with other modules is making
20 // a combined work based on this library. Thus, the terms and conditions of
21 // the GNU General Public License cover the whole combination.
22 //
23
24 #ifndef VMIME_NET_SMTP_SMTPRESPONSE_HPP_INCLUDED
25 #define VMIME_NET_SMTP_SMTPRESPONSE_HPP_INCLUDED
26
27
28 #include "vmime/config.hpp"
29
30
31 #if VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_SMTP
32
33
34 #include "vmime/object.hpp"
35 #include "vmime/base.hpp"
36
37
38 namespace vmime {
39 namespace net {
40
41
42 class socket;
43 class timeoutHandler;
44 class tracer;
45
46
47 namespace smtp {
48
49
50 /** A SMTP response, as sent by the server.
51 */
52 class VMIME_EXPORT SMTPResponse : public object
53 {
54 public:
55
56 /** Current state of response parser. */
57 struct state
58 {
59 string responseBuffer;
60 };
61
62 /** Enhanced status code (as per RFC-3463). */
63 struct enhancedStatusCode
64 {
65 enhancedStatusCode();
66 enhancedStatusCode(const enhancedStatusCode& enhCode);
67
68 unsigned short klass; /**< Success/failure. */
69 unsigned short subject; /**< Source of anomaly. */
70 unsigned short detail; /**< Precise error condition. */
71 };
72
73 /** An element of a SMTP response. */
74 class responseLine
75 {
76 public:
77
78 responseLine(const int code, const string& text, const enhancedStatusCode& enhCode);
79
80 void setCode(const int code);
81 int getCode() const;
82
83 void setEnhancedCode(const enhancedStatusCode& enhCode);
84 const enhancedStatusCode getEnhancedCode() const;
85
86 void setText(const string& text);
87 const string getText() const;
88
89 private:
90
91 int m_code;
92 string m_text;
93 enhancedStatusCode m_enhCode;
94 };
95
96 /** Receive and parse a new SMTP response from the
97 * specified socket.
98 *
99 * @param tr tracer
100 * @param sok socket from which to read
101 * @param toh time-out handler
102 * @param st previous state of response parser for the specified socket
103 * @return SMTP response
104 * @throws exceptions::operation_timed_out if no data
105 * has been received within the granted time
106 */
107 static shared_ptr <SMTPResponse> readResponse
108 (shared_ptr <tracer> tr, shared_ptr <socket> sok,
109 shared_ptr <timeoutHandler> toh, const state& st);
110
111 /** Return the SMTP response code.
112 *
113 * @return response code
114 */
115 int getCode() const;
116
117 /** Return the SMTP enhanced status code, if available.
118 *
119 * @return enhanced status code
120 */
121 const enhancedStatusCode getEnhancedCode() const;
122
123 /** Return the SMTP response text.
124 * The text of each line is concatenated.
125 *
126 * @return response text
127 */
128 const string getText() const;
129
130 /** Return the response line at the specified position.
131 *
132 * @param pos line index
133 * @return line at the specified index
134 */
135 const responseLine getLineAt(const size_t pos) const;
136
137 /** Return the number of lines in the response.
138 *
139 * @return number of lines in the response
140 */
141 size_t getLineCount() const;
142
143 /** Return the last line in the response.
144 *
145 * @return last response line
146 */
147 const responseLine getLastLine() const;
148
149 /** Returns the current state of the response parser.
150 *
151 * @return current parser state
152 */
153 const state getCurrentState() const;
154
155 private:
156
157 SMTPResponse(shared_ptr <tracer> tr, shared_ptr <socket> sok, shared_ptr <timeoutHandler> toh, const state& st);
158 SMTPResponse(const SMTPResponse&);
159
160 void readResponse();
161
162 const string readResponseLine();
163 const responseLine getNextResponse();
164
165 static int extractResponseCode(const string& response);
166 static const enhancedStatusCode extractEnhancedCode(const string& responseText);
167
168
169 std::vector <responseLine> m_lines;
170
171 shared_ptr <socket> m_socket;
172 shared_ptr <timeoutHandler> m_timeoutHandler;
173 shared_ptr <tracer> m_tracer;
174
175 string m_responseBuffer;
176 bool m_responseContinues;
177 };
178
179
180 VMIME_EXPORT std::ostream& operator<<(std::ostream& os, const SMTPResponse::enhancedStatusCode& code);
181
182
183 } // smtp
184 } // net
185 } // vmime
186
187
188 #endif // VMIME_HAVE_MESSAGING_FEATURES && VMIME_HAVE_MESSAGING_PROTO_SMTP
189
190 #endif // VMIME_NET_SMTP_SMTPRESPONSE_HPP_INCLUDED
191