diff options
Diffstat (limited to 'src/daemon/connection_https.c')
-rw-r--r-- | src/daemon/connection_https.c | 92 |
1 files changed, 16 insertions, 76 deletions
diff --git a/src/daemon/connection_https.c b/src/daemon/connection_https.c index 7504031b..df91af10 100644 --- a/src/daemon/connection_https.c +++ b/src/daemon/connection_https.c | |||
@@ -87,46 +87,23 @@ MHD_get_connection_info (struct MHD_Connection *connection, | |||
87 | /** | 87 | /** |
88 | * This function is called once a secure connection has been marked | 88 | * This function is called once a secure connection has been marked |
89 | * for closure. | 89 | * for closure. |
90 | * | 90 | * |
91 | * @param connection: the connection to close | 91 | * NOTE: Some code duplication with connection_close_error |
92 | */ | 92 | * in connection.c |
93 | static void | ||
94 | MHD_tls_connection_close (struct MHD_Connection *connection) | ||
95 | { | ||
96 | MHD_gnutls_bye (connection->tls_session, GNUTLS_SHUT_WR); | ||
97 | connection->tls_session->internals.read_eof = 1; | ||
98 | |||
99 | SHUTDOWN (connection->socket_fd, SHUT_RDWR); | ||
100 | CLOSE (connection->socket_fd); | ||
101 | connection->socket_fd = -1; | ||
102 | |||
103 | connection->state = MHD_CONNECTION_CLOSED; | ||
104 | |||
105 | /* call notify_completed callback if one was registered */ | ||
106 | if (connection->daemon->notify_completed != NULL) | ||
107 | connection->daemon->notify_completed (connection->daemon-> | ||
108 | notify_completed_cls, connection, | ||
109 | &connection->client_context, | ||
110 | MHD_REQUEST_TERMINATED_COMPLETED_OK); | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * This function is called once a secure connection has been marked | ||
115 | * for closure. | ||
116 | * | 93 | * |
117 | * @param connection: the connection to close | 94 | * @param connection: the connection to close |
118 | * @param termination_code: the termination code with which the notify completed callback function is called. | 95 | * @param termination_code: the termination code with which the notify completed callback function is called. |
119 | */ | 96 | */ |
120 | static void | 97 | static void |
121 | MHD_tls_connection_close_err (struct MHD_Connection *connection, | 98 | MHD_tls_connection_close (struct MHD_Connection *connection, |
122 | enum MHD_RequestTerminationCode | 99 | enum MHD_RequestTerminationCode |
123 | termination_code) | 100 | termination_code) |
124 | { | 101 | { |
102 | MHD_gnutls_bye (connection->tls_session, GNUTLS_SHUT_WR); | ||
125 | connection->tls_session->internals.read_eof = 1; | 103 | connection->tls_session->internals.read_eof = 1; |
126 | SHUTDOWN (connection->socket_fd, SHUT_RDWR); | 104 | SHUTDOWN (connection->socket_fd, SHUT_RDWR); |
127 | CLOSE (connection->socket_fd); | 105 | CLOSE (connection->socket_fd); |
128 | connection->socket_fd = -1; | 106 | connection->socket_fd = -1; |
129 | |||
130 | connection->state = MHD_CONNECTION_CLOSED; | 107 | connection->state = MHD_CONNECTION_CLOSED; |
131 | if (connection->daemon->notify_completed != NULL) | 108 | if (connection->daemon->notify_completed != NULL) |
132 | connection->daemon->notify_completed (connection->daemon-> | 109 | connection->daemon->notify_completed (connection->daemon-> |
@@ -135,39 +112,6 @@ MHD_tls_connection_close_err (struct MHD_Connection *connection, | |||
135 | termination_code); | 112 | termination_code); |
136 | } | 113 | } |
137 | 114 | ||
138 | |||
139 | /** | ||
140 | * @name : MHDS_con_read | ||
141 | * | ||
142 | * reads data from the TLS record protocol | ||
143 | * @param connection: is a %MHD_Connection structure. | ||
144 | * @return: number of bytes received and zero on EOF. A negative | ||
145 | * error code is returned in case of an error. | ||
146 | **/ | ||
147 | static ssize_t | ||
148 | MHDS_con_read (struct MHD_Connection *connection) | ||
149 | { | ||
150 | /* no special handling when GNUTLS_E_AGAIN is returned since this function is called from within a select loop */ | ||
151 | ssize_t size = MHD_gnutls_record_recv (connection->tls_session, | ||
152 | &connection->read_buffer | ||
153 | [connection->read_buffer_offset], | ||
154 | connection->read_buffer_size); | ||
155 | return size; | ||
156 | } | ||
157 | |||
158 | static ssize_t | ||
159 | MHDS_con_write (struct MHD_Connection *connection) | ||
160 | { | ||
161 | ssize_t sent = MHD_gnutls_record_send (connection->tls_session, | ||
162 | &connection->write_buffer | ||
163 | [connection-> | ||
164 | write_buffer_send_offset], | ||
165 | connection->write_buffer_append_offset | ||
166 | - | ||
167 | connection->write_buffer_send_offset); | ||
168 | return sent; | ||
169 | } | ||
170 | |||
171 | /** | 115 | /** |
172 | * This function was created to handle per-connection processing that | 116 | * This function was created to handle per-connection processing that |
173 | * has to happen even if the socket cannot be read or written to. All | 117 | * has to happen even if the socket cannot be read or written to. All |
@@ -187,16 +131,14 @@ MHD_tls_connection_handle_idle (struct MHD_Connection *connection) | |||
187 | MHD_DLOG (connection->daemon, "%s: state: %s\n", | 131 | MHD_DLOG (connection->daemon, "%s: state: %s\n", |
188 | __FUNCTION__, MHD_state_to_string (connection->state)); | 132 | __FUNCTION__, MHD_state_to_string (connection->state)); |
189 | #endif | 133 | #endif |
190 | |||
191 | timeout = connection->daemon->connection_timeout; | 134 | timeout = connection->daemon->connection_timeout; |
192 | if ((connection->socket_fd != -1) && (timeout != 0) | 135 | if ((connection->socket_fd != -1) && (timeout != 0) |
193 | && (time (NULL) - timeout > connection->last_activity)) | 136 | && (time (NULL) - timeout > connection->last_activity)) |
194 | { | 137 | { |
195 | MHD_tls_connection_close_err (connection, | 138 | MHD_tls_connection_close (connection, |
196 | MHD_REQUEST_TERMINATED_TIMEOUT_REACHED); | 139 | MHD_REQUEST_TERMINATED_TIMEOUT_REACHED); |
197 | return MHD_NO; | 140 | return MHD_NO; |
198 | } | 141 | } |
199 | |||
200 | switch (connection->state) | 142 | switch (connection->state) |
201 | { | 143 | { |
202 | /* on newly created connections we might reach here before any reply has been received */ | 144 | /* on newly created connections we might reach here before any reply has been received */ |
@@ -205,10 +147,11 @@ MHD_tls_connection_handle_idle (struct MHD_Connection *connection) | |||
205 | /* close connection if necessary */ | 147 | /* close connection if necessary */ |
206 | case MHD_CONNECTION_CLOSED: | 148 | case MHD_CONNECTION_CLOSED: |
207 | if (connection->socket_fd != -1) | 149 | if (connection->socket_fd != -1) |
208 | MHD_tls_connection_close (connection); | 150 | MHD_tls_connection_close (connection, |
151 | MHD_REQUEST_TERMINATED_COMPLETED_OK); | ||
209 | return MHD_NO; | 152 | return MHD_NO; |
210 | case MHD_TLS_HANDSHAKE_FAILED: | 153 | case MHD_TLS_HANDSHAKE_FAILED: |
211 | MHD_tls_connection_close_err (connection, | 154 | MHD_tls_connection_close (connection, |
212 | MHD_TLS_REQUEST_TERMINATED_WITH_ERROR); | 155 | MHD_TLS_REQUEST_TERMINATED_WITH_ERROR); |
213 | return MHD_NO; | 156 | return MHD_NO; |
214 | /* some HTTP state */ | 157 | /* some HTTP state */ |
@@ -293,14 +236,14 @@ MHD_tls_connection_handle_read (struct MHD_Connection *connection) | |||
293 | MHD_DLOG (connection->daemon, | 236 | MHD_DLOG (connection->daemon, |
294 | "Error: received handshake message out of context\n"); | 237 | "Error: received handshake message out of context\n"); |
295 | #endif | 238 | #endif |
296 | MHD_tls_connection_close_err (connection, | 239 | MHD_tls_connection_close (connection, |
297 | MHD_TLS_REQUEST_TERMINATED_WITH_ERROR); | 240 | MHD_TLS_REQUEST_TERMINATED_WITH_ERROR); |
298 | return MHD_NO; | 241 | return MHD_NO; |
299 | } | 242 | } |
300 | 243 | ||
301 | /* ignore any out of bound change chiper spec messages */ | 244 | /* ignore any out of bound change chiper spec messages */ |
302 | case GNUTLS_CHANGE_CIPHER_SPEC: | 245 | case GNUTLS_CHANGE_CIPHER_SPEC: |
303 | MHD_tls_connection_close_err (connection, | 246 | MHD_tls_connection_close (connection, |
304 | MHD_TLS_REQUEST_TERMINATED_WITH_ERROR); | 247 | MHD_TLS_REQUEST_TERMINATED_WITH_ERROR); |
305 | return MHD_NO; | 248 | return MHD_NO; |
306 | 249 | ||
@@ -335,8 +278,8 @@ MHD_tls_connection_handle_read (struct MHD_Connection *connection) | |||
335 | else if (connection->tls_session->internals.last_alert_level == | 278 | else if (connection->tls_session->internals.last_alert_level == |
336 | GNUTLS_AL_FATAL) | 279 | GNUTLS_AL_FATAL) |
337 | { | 280 | { |
338 | MHD_tls_connection_close_err (connection, | 281 | MHD_tls_connection_close (connection, |
339 | MHD_TLS_REQUEST_TERMINATED_WITH_FATAL_ALERT); | 282 | MHD_TLS_REQUEST_TERMINATED_WITH_FATAL_ALERT); |
340 | return MHD_NO; | 283 | return MHD_NO; |
341 | } | 284 | } |
342 | /* this should never execute */ | 285 | /* this should never execute */ |
@@ -400,16 +343,13 @@ MHD_tls_connection_handle_write (struct MHD_Connection *connection) | |||
400 | return MHD_NO; | 343 | return MHD_NO; |
401 | } | 344 | } |
402 | 345 | ||
403 | /* | 346 | /** |
404 | * set connection callback function to be used through out | 347 | * Set connection callback function to be used through out |
405 | * the processing of this secure connection. | 348 | * the processing of this secure connection. |
406 | * | ||
407 | */ | 349 | */ |
408 | void | 350 | void |
409 | MHD_set_https_calbacks (struct MHD_Connection *connection) | 351 | MHD_set_https_calbacks (struct MHD_Connection *connection) |
410 | { | 352 | { |
411 | connection->recv_cls = &MHDS_con_read; | ||
412 | connection->send_cls = &MHDS_con_write; | ||
413 | connection->read_handler = &MHD_tls_connection_handle_read; | 353 | connection->read_handler = &MHD_tls_connection_handle_read; |
414 | connection->write_handler = &MHD_tls_connection_handle_write; | 354 | connection->write_handler = &MHD_tls_connection_handle_write; |
415 | connection->idle_handler = &MHD_tls_connection_handle_idle; | 355 | connection->idle_handler = &MHD_tls_connection_handle_idle; |