aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/connection_https.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/connection_https.c')
-rw-r--r--src/daemon/connection_https.c55
1 files changed, 15 insertions, 40 deletions
diff --git a/src/daemon/connection_https.c b/src/daemon/connection_https.c
index 5487872e..e68ecbbe 100644
--- a/src/daemon/connection_https.c
+++ b/src/daemon/connection_https.c
@@ -33,23 +33,6 @@
33#include "reason_phrase.h" 33#include "reason_phrase.h"
34#include <gnutls/gnutls.h> 34#include <gnutls/gnutls.h>
35 35
36/**
37 * This function is called once a secure connection has been marked
38 * for closure.
39 *
40 * NOTE: Some code duplication with connection_close_error
41 * in connection.c
42 *
43 * @param connection: the connection to close
44 * @param termination_code: the termination code with which the notify completed callback function is called.
45 */
46static void
47MHD_tls_connection_close (struct MHD_Connection *connection,
48 enum MHD_RequestTerminationCode termination_code)
49{
50 gnutls_bye (connection->tls_session, GNUTLS_SHUT_RDWR);
51 MHD_connection_close (connection, termination_code);
52}
53 36
54 37
55/** 38/**
@@ -65,9 +48,8 @@ MHD_tls_connection_close (struct MHD_Connection *connection,
65 * Application data is forwarded to the underlying daemon for 48 * Application data is forwarded to the underlying daemon for
66 * processing. 49 * processing.
67 * 50 *
68 * @param connection : the source connection 51 * @param connection the source connection
69 * @return MHD_YES if we should continue to process the 52 * @return always MHD_YES (we should continue to process the connection)
70 * connection (not dead yet), MHD_NO if it died
71 */ 53 */
72static int 54static int
73MHD_tls_connection_handle_read (struct MHD_Connection *connection) 55MHD_tls_connection_handle_read (struct MHD_Connection *connection)
@@ -95,9 +77,9 @@ MHD_tls_connection_handle_read (struct MHD_Connection *connection)
95 MHD_DLOG (connection->daemon, 77 MHD_DLOG (connection->daemon,
96 "Error: received handshake message out of context\n"); 78 "Error: received handshake message out of context\n");
97#endif 79#endif
98 MHD_tls_connection_close (connection, 80 MHD_connection_close (connection,
99 MHD_REQUEST_TERMINATED_WITH_ERROR); 81 MHD_REQUEST_TERMINATED_WITH_ERROR);
100 return MHD_NO; 82 return MHD_YES;
101 } 83 }
102 return MHD_connection_handle_read (connection); 84 return MHD_connection_handle_read (connection);
103} 85}
@@ -109,8 +91,7 @@ MHD_tls_connection_handle_read (struct MHD_Connection *connection)
109 * will forward all write requests to the underlying daemon unless 91 * will forward all write requests to the underlying daemon unless
110 * the connection has been marked for closing. 92 * the connection has been marked for closing.
111 * 93 *
112 * @return MHD_connection_handle_write() if we should continue to 94 * @return always MHD_YES (we should continue to process the connection)
113 * process the connection (not dead yet), MHD_NO if it died
114 */ 95 */
115static int 96static int
116MHD_tls_connection_handle_write (struct MHD_Connection *connection) 97MHD_tls_connection_handle_write (struct MHD_Connection *connection)
@@ -142,9 +123,9 @@ MHD_tls_connection_handle_write (struct MHD_Connection *connection)
142 MHD_DLOG (connection->daemon, 123 MHD_DLOG (connection->daemon,
143 "Error: received handshake message out of context\n"); 124 "Error: received handshake message out of context\n");
144#endif 125#endif
145 MHD_tls_connection_close (connection, 126 MHD_connection_close (connection,
146 MHD_REQUEST_TERMINATED_WITH_ERROR); 127 MHD_REQUEST_TERMINATED_WITH_ERROR);
147 return MHD_NO; 128 return MHD_YES;
148 } 129 }
149 return MHD_connection_handle_write (connection); 130 return MHD_connection_handle_write (connection);
150} 131}
@@ -170,13 +151,9 @@ MHD_tls_connection_handle_idle (struct MHD_Connection *connection)
170 __FUNCTION__, MHD_state_to_string (connection->state)); 151 __FUNCTION__, MHD_state_to_string (connection->state));
171#endif 152#endif
172 timeout = connection->daemon->connection_timeout; 153 timeout = connection->daemon->connection_timeout;
173 if ((connection->socket_fd != -1) && (timeout != 0) 154 if ( (timeout != 0) && (time (NULL) - timeout > connection->last_activity))
174 && (time (NULL) - timeout > connection->last_activity)) 155 MHD_connection_close (connection,
175 { 156 MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
176 MHD_tls_connection_close (connection,
177 MHD_REQUEST_TERMINATED_TIMEOUT_REACHED);
178 return MHD_NO;
179 }
180 switch (connection->state) 157 switch (connection->state)
181 { 158 {
182 /* on newly created connections we might reach here before any reply has been received */ 159 /* on newly created connections we might reach here before any reply has been received */
@@ -184,14 +161,12 @@ MHD_tls_connection_handle_idle (struct MHD_Connection *connection)
184 return MHD_YES; 161 return MHD_YES;
185 /* close connection if necessary */ 162 /* close connection if necessary */
186 case MHD_CONNECTION_CLOSED: 163 case MHD_CONNECTION_CLOSED:
187 if (connection->socket_fd != -1) 164 gnutls_bye (connection->tls_session, GNUTLS_SHUT_RDWR);
188 MHD_tls_connection_close (connection, 165 return MHD_connection_handle_idle (connection);
189 MHD_REQUEST_TERMINATED_COMPLETED_OK);
190 return MHD_NO;
191 default: 166 default:
192 if ( (0 != gnutls_record_check_pending (connection->tls_session)) && 167 if ( (0 != gnutls_record_check_pending (connection->tls_session)) &&
193 (MHD_YES != MHD_tls_connection_handle_read (connection)) ) 168 (MHD_YES != MHD_tls_connection_handle_read (connection)) )
194 return MHD_NO; 169 return MHD_YES;
195 return MHD_connection_handle_idle (connection); 170 return MHD_connection_handle_idle (connection);
196 } 171 }
197 return MHD_YES; 172 return MHD_YES;