diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-07-28 15:21:19 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2022-08-09 21:24:53 +0300 |
commit | 82d864759c08796d36139336df070b62b1a0e077 (patch) | |
tree | 273803573b29dad65f660dab2035ea27526163aa /src/microhttpd/connection.c | |
parent | 93ef4701123acd9c3f606b4d983dbaa840f427b4 (diff) | |
download | libmicrohttpd-82d864759c08796d36139336df070b62b1a0e077.tar.gz libmicrohttpd-82d864759c08796d36139336df070b62b1a0e077.zip |
Internal refactoring: moved all reply-related members to separate structure
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 309 |
1 files changed, 153 insertions, 156 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 5a0653db..58aa9edf 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -827,7 +827,7 @@ MHD_connection_close_ (struct MHD_Connection *connection, | |||
827 | enum MHD_RequestTerminationCode termination_code) | 827 | enum MHD_RequestTerminationCode termination_code) |
828 | { | 828 | { |
829 | struct MHD_Daemon *daemon = connection->daemon; | 829 | struct MHD_Daemon *daemon = connection->daemon; |
830 | struct MHD_Response *resp = connection->response; | 830 | struct MHD_Response *resp = connection->rp.response; |
831 | 831 | ||
832 | #ifdef MHD_USE_THREADS | 832 | #ifdef MHD_USE_THREADS |
833 | mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \ | 833 | mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \ |
@@ -842,7 +842,7 @@ MHD_connection_close_ (struct MHD_Connection *connection, | |||
842 | connection->rq.client_aware = false; | 842 | connection->rq.client_aware = false; |
843 | if (NULL != resp) | 843 | if (NULL != resp) |
844 | { | 844 | { |
845 | connection->response = NULL; | 845 | connection->rp.response = NULL; |
846 | MHD_destroy_response (resp); | 846 | MHD_destroy_response (resp); |
847 | } | 847 | } |
848 | if (NULL != connection->pool) | 848 | if (NULL != connection->pool) |
@@ -977,9 +977,9 @@ static void | |||
977 | connection_close_error_check (struct MHD_Connection *connection, | 977 | connection_close_error_check (struct MHD_Connection *connection, |
978 | const char *emsg) | 978 | const char *emsg) |
979 | { | 979 | { |
980 | if ( (NULL != connection->response) && | 980 | if ( (NULL != connection->rp.response) && |
981 | (400 <= connection->responseCode) && | 981 | (400 <= connection->rp.responseCode) && |
982 | (NULL == connection->response->crc) && /* Static response only! */ | 982 | (NULL == connection->rp.response->crc) && /* Static response only! */ |
983 | (connection->stop_with_error) && | 983 | (connection->stop_with_error) && |
984 | (MHD_CONNECTION_HEADERS_SENDING == connection->state) ) | 984 | (MHD_CONNECTION_HEADERS_SENDING == connection->state) ) |
985 | return; /* An error response was already queued */ | 985 | return; /* An error response was already queued */ |
@@ -1019,23 +1019,23 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
1019 | ssize_t ret; | 1019 | ssize_t ret; |
1020 | struct MHD_Response *response; | 1020 | struct MHD_Response *response; |
1021 | 1021 | ||
1022 | response = connection->response; | 1022 | response = connection->rp.response; |
1023 | mhd_assert (connection->rp_props.send_reply_body); | 1023 | mhd_assert (connection->rp.props.send_reply_body); |
1024 | 1024 | ||
1025 | if ( (0 == response->total_size) || | 1025 | if ( (0 == response->total_size) || |
1026 | /* TODO: replace the next check with assert */ | 1026 | /* TODO: replace the next check with assert */ |
1027 | (connection->response_write_position == response->total_size) ) | 1027 | (connection->rp.rsp_write_position == response->total_size) ) |
1028 | return MHD_YES; /* 0-byte response is always ready */ | 1028 | return MHD_YES; /* 0-byte response is always ready */ |
1029 | if (NULL != response->data_iov) | 1029 | if (NULL != response->data_iov) |
1030 | { | 1030 | { |
1031 | size_t copy_size; | 1031 | size_t copy_size; |
1032 | 1032 | ||
1033 | if (NULL != connection->resp_iov.iov) | 1033 | if (NULL != connection->rp.resp_iov.iov) |
1034 | return MHD_YES; | 1034 | return MHD_YES; |
1035 | copy_size = response->data_iovcnt * sizeof(MHD_iovec_); | 1035 | copy_size = response->data_iovcnt * sizeof(MHD_iovec_); |
1036 | connection->resp_iov.iov = MHD_connection_alloc_memory_ (connection, | 1036 | connection->rp.resp_iov.iov = MHD_connection_alloc_memory_ (connection, |
1037 | copy_size); | 1037 | copy_size); |
1038 | if (NULL == connection->resp_iov.iov) | 1038 | if (NULL == connection->rp.resp_iov.iov) |
1039 | { | 1039 | { |
1040 | MHD_mutex_unlock_chk_ (&response->mutex); | 1040 | MHD_mutex_unlock_chk_ (&response->mutex); |
1041 | /* not enough memory */ | 1041 | /* not enough memory */ |
@@ -1043,22 +1043,22 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
1043 | _ ("Closing connection (out of memory).")); | 1043 | _ ("Closing connection (out of memory).")); |
1044 | return MHD_NO; | 1044 | return MHD_NO; |
1045 | } | 1045 | } |
1046 | memcpy (connection->resp_iov.iov, | 1046 | memcpy (connection->rp.resp_iov.iov, |
1047 | response->data_iov, | 1047 | response->data_iov, |
1048 | copy_size); | 1048 | copy_size); |
1049 | connection->resp_iov.cnt = response->data_iovcnt; | 1049 | connection->rp.resp_iov.cnt = response->data_iovcnt; |
1050 | connection->resp_iov.sent = 0; | 1050 | connection->rp.resp_iov.sent = 0; |
1051 | return MHD_YES; | 1051 | return MHD_YES; |
1052 | } | 1052 | } |
1053 | if (NULL == response->crc) | 1053 | if (NULL == response->crc) |
1054 | return MHD_YES; | 1054 | return MHD_YES; |
1055 | if ( (response->data_start <= | 1055 | if ( (response->data_start <= |
1056 | connection->response_write_position) && | 1056 | connection->rp.rsp_write_position) && |
1057 | (response->data_size + response->data_start > | 1057 | (response->data_size + response->data_start > |
1058 | connection->response_write_position) ) | 1058 | connection->rp.rsp_write_position) ) |
1059 | return MHD_YES; /* response already ready */ | 1059 | return MHD_YES; /* response already ready */ |
1060 | #if defined(_MHD_HAVE_SENDFILE) | 1060 | #if defined(_MHD_HAVE_SENDFILE) |
1061 | if (MHD_resp_sender_sendfile == connection->resp_sender) | 1061 | if (MHD_resp_sender_sendfile == connection->rp.resp_sender) |
1062 | { | 1062 | { |
1063 | /* will use sendfile, no need to bother response crc */ | 1063 | /* will use sendfile, no need to bother response crc */ |
1064 | return MHD_YES; | 1064 | return MHD_YES; |
@@ -1066,17 +1066,17 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
1066 | #endif /* _MHD_HAVE_SENDFILE */ | 1066 | #endif /* _MHD_HAVE_SENDFILE */ |
1067 | 1067 | ||
1068 | ret = response->crc (response->crc_cls, | 1068 | ret = response->crc (response->crc_cls, |
1069 | connection->response_write_position, | 1069 | connection->rp.rsp_write_position, |
1070 | (char *) response->data, | 1070 | (char *) response->data, |
1071 | (size_t) MHD_MIN ((uint64_t) response->data_buffer_size, | 1071 | (size_t) MHD_MIN ((uint64_t) response->data_buffer_size, |
1072 | response->total_size | 1072 | response->total_size |
1073 | - connection->response_write_position)); | 1073 | - connection->rp.rsp_write_position)); |
1074 | if (0 > ret) | 1074 | if (0 > ret) |
1075 | { | 1075 | { |
1076 | /* either error or http 1.0 transfer, close socket! */ | 1076 | /* either error or http 1.0 transfer, close socket! */ |
1077 | /* TODO: do not update total size, check whether response | 1077 | /* TODO: do not update total size, check whether response |
1078 | * was really with unknown size */ | 1078 | * was really with unknown size */ |
1079 | response->total_size = connection->response_write_position; | 1079 | response->total_size = connection->rp.rsp_write_position; |
1080 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 1080 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
1081 | MHD_mutex_unlock_chk_ (&response->mutex); | 1081 | MHD_mutex_unlock_chk_ (&response->mutex); |
1082 | #endif | 1082 | #endif |
@@ -1089,7 +1089,7 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
1089 | "Closing connection (application reported error generating data).")); | 1089 | "Closing connection (application reported error generating data).")); |
1090 | return MHD_NO; | 1090 | return MHD_NO; |
1091 | } | 1091 | } |
1092 | response->data_start = connection->response_write_position; | 1092 | response->data_start = connection->rp.rsp_write_position; |
1093 | response->data_size = (size_t) ret; | 1093 | response->data_size = (size_t) ret; |
1094 | if (0 == ret) | 1094 | if (0 == ret) |
1095 | { | 1095 | { |
@@ -1131,7 +1131,7 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1131 | uint64_t left_to_send; | 1131 | uint64_t left_to_send; |
1132 | size_t size_to_fill; | 1132 | size_t size_to_fill; |
1133 | 1133 | ||
1134 | response = connection->response; | 1134 | response = connection->rp.response; |
1135 | mhd_assert (NULL != response->crc || NULL != response->data); | 1135 | mhd_assert (NULL != response->crc || NULL != response->data); |
1136 | 1136 | ||
1137 | mhd_assert (0 == connection->write_buffer_append_offset); | 1137 | mhd_assert (0 == connection->write_buffer_append_offset); |
@@ -1167,7 +1167,8 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1167 | if (MHD_SIZE_UNKNOWN == response->total_size) | 1167 | if (MHD_SIZE_UNKNOWN == response->total_size) |
1168 | left_to_send = MHD_SIZE_UNKNOWN; | 1168 | left_to_send = MHD_SIZE_UNKNOWN; |
1169 | else | 1169 | else |
1170 | left_to_send = response->total_size - connection->response_write_position; | 1170 | left_to_send = response->total_size |
1171 | - connection->rp.rsp_write_position; | ||
1171 | 1172 | ||
1172 | size_to_fill = connection->write_buffer_size - max_chunk_overhead; | 1173 | size_to_fill = connection->write_buffer_size - max_chunk_overhead; |
1173 | /* Limit size for the callback to the max usable size */ | 1174 | /* Limit size for the callback to the max usable size */ |
@@ -1180,14 +1181,15 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1180 | /* nothing to send, don't bother calling crc */ | 1181 | /* nothing to send, don't bother calling crc */ |
1181 | ret = MHD_CONTENT_READER_END_OF_STREAM; | 1182 | ret = MHD_CONTENT_READER_END_OF_STREAM; |
1182 | else if ( (response->data_start <= | 1183 | else if ( (response->data_start <= |
1183 | connection->response_write_position) && | 1184 | connection->rp.rsp_write_position) && |
1184 | (response->data_start + response->data_size > | 1185 | (response->data_start + response->data_size > |
1185 | connection->response_write_position) ) | 1186 | connection->rp.rsp_write_position) ) |
1186 | { | 1187 | { |
1187 | /* difference between response_write_position and data_start is less | 1188 | /* difference between rsp_write_position and data_start is less |
1188 | than data_size which is size_t type, no need to check for overflow */ | 1189 | than data_size which is size_t type, no need to check for overflow */ |
1189 | const size_t data_write_offset | 1190 | const size_t data_write_offset |
1190 | = (size_t) (connection->response_write_position - response->data_start); | 1191 | = (size_t) (connection->rp.rsp_write_position |
1192 | - response->data_start); | ||
1191 | /* buffer already ready, use what is there for the chunk */ | 1193 | /* buffer already ready, use what is there for the chunk */ |
1192 | mhd_assert (SSIZE_MAX >= (response->data_size - data_write_offset)); | 1194 | mhd_assert (SSIZE_MAX >= (response->data_size - data_write_offset)); |
1193 | mhd_assert (response->data_size >= data_write_offset); | 1195 | mhd_assert (response->data_size >= data_write_offset); |
@@ -1210,7 +1212,7 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1210 | return MHD_NO; | 1212 | return MHD_NO; |
1211 | } | 1213 | } |
1212 | ret = response->crc (response->crc_cls, | 1214 | ret = response->crc (response->crc_cls, |
1213 | connection->response_write_position, | 1215 | connection->rp.rsp_write_position, |
1214 | &connection->write_buffer[max_chunk_hdr_len], | 1216 | &connection->write_buffer[max_chunk_hdr_len], |
1215 | size_to_fill); | 1217 | size_to_fill); |
1216 | } | 1218 | } |
@@ -1218,7 +1220,7 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1218 | { | 1220 | { |
1219 | /* error, close socket! */ | 1221 | /* error, close socket! */ |
1220 | /* TODO: remove update of the response size */ | 1222 | /* TODO: remove update of the response size */ |
1221 | response->total_size = connection->response_write_position; | 1223 | response->total_size = connection->rp.rsp_write_position; |
1222 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 1224 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
1223 | MHD_mutex_unlock_chk_ (&response->mutex); | 1225 | MHD_mutex_unlock_chk_ (&response->mutex); |
1224 | #endif | 1226 | #endif |
@@ -1231,7 +1233,7 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1231 | { | 1233 | { |
1232 | *p_finished = true; | 1234 | *p_finished = true; |
1233 | /* TODO: remove update of the response size */ | 1235 | /* TODO: remove update of the response size */ |
1234 | response->total_size = connection->response_write_position; | 1236 | response->total_size = connection->rp.rsp_write_position; |
1235 | return MHD_YES; | 1237 | return MHD_YES; |
1236 | } | 1238 | } |
1237 | if (0 == ret) | 1239 | if (0 == ret) |
@@ -1266,7 +1268,7 @@ try_ready_chunked_body (struct MHD_Connection *connection, | |||
1266 | connection->write_buffer[max_chunk_hdr_len - 1] = '\n'; | 1268 | connection->write_buffer[max_chunk_hdr_len - 1] = '\n'; |
1267 | connection->write_buffer[max_chunk_hdr_len + (size_t) ret] = '\r'; | 1269 | connection->write_buffer[max_chunk_hdr_len + (size_t) ret] = '\r'; |
1268 | connection->write_buffer[max_chunk_hdr_len + (size_t) ret + 1] = '\n'; | 1270 | connection->write_buffer[max_chunk_hdr_len + (size_t) ret + 1] = '\n'; |
1269 | connection->response_write_position += (size_t) ret; | 1271 | connection->rp.rsp_write_position += (size_t) ret; |
1270 | connection->write_buffer_append_offset = max_chunk_hdr_len + (size_t) ret + 2; | 1272 | connection->write_buffer_append_offset = max_chunk_hdr_len + (size_t) ret + 2; |
1271 | return MHD_YES; | 1273 | return MHD_YES; |
1272 | } | 1274 | } |
@@ -1298,7 +1300,7 @@ static enum MHD_ConnKeepAlive | |||
1298 | keepalive_possible (struct MHD_Connection *connection) | 1300 | keepalive_possible (struct MHD_Connection *connection) |
1299 | { | 1301 | { |
1300 | struct MHD_Connection *const c = connection; /**< a short alias */ | 1302 | struct MHD_Connection *const c = connection; /**< a short alias */ |
1301 | struct MHD_Response *const r = c->response; /**< a short alias */ | 1303 | struct MHD_Response *const r = c->rp.response; /**< a short alias */ |
1302 | 1304 | ||
1303 | mhd_assert (NULL != r); | 1305 | mhd_assert (NULL != r); |
1304 | if (MHD_CONN_MUST_CLOSE == c->keepalive) | 1306 | if (MHD_CONN_MUST_CLOSE == c->keepalive) |
@@ -1336,7 +1338,7 @@ keepalive_possible (struct MHD_Connection *connection) | |||
1336 | return MHD_CONN_MUST_CLOSE; | 1338 | return MHD_CONN_MUST_CLOSE; |
1337 | 1339 | ||
1338 | if ((MHD_HTTP_VER_1_0 == connection->rq.http_ver) || | 1340 | if ((MHD_HTTP_VER_1_0 == connection->rq.http_ver) || |
1339 | (0 != (connection->response->flags & MHD_RF_HTTP_1_0_SERVER))) | 1341 | (0 != (connection->rp.response->flags & MHD_RF_HTTP_1_0_SERVER))) |
1340 | { | 1342 | { |
1341 | if (MHD_lookup_header_s_token_ci (connection, | 1343 | if (MHD_lookup_header_s_token_ci (connection, |
1342 | MHD_HTTP_HEADER_CONNECTION, | 1344 | MHD_HTTP_HEADER_CONNECTION, |
@@ -1728,7 +1730,7 @@ is_reply_body_needed (struct MHD_Connection *connection, | |||
1728 | #if 0 | 1730 | #if 0 |
1729 | /* This check is not needed as upgrade handler is used only with code 101 */ | 1731 | /* This check is not needed as upgrade handler is used only with code 101 */ |
1730 | #ifdef UPGRADE_SUPPORT | 1732 | #ifdef UPGRADE_SUPPORT |
1731 | if (NULL != response->upgrade_handler) | 1733 | if (NULL != rp.response->upgrade_handler) |
1732 | return RP_BODY_NONE; | 1734 | return RP_BODY_NONE; |
1733 | #endif /* UPGRADE_SUPPORT */ | 1735 | #endif /* UPGRADE_SUPPORT */ |
1734 | #endif | 1736 | #endif |
@@ -1770,7 +1772,7 @@ static void | |||
1770 | setup_reply_properties (struct MHD_Connection *connection) | 1772 | setup_reply_properties (struct MHD_Connection *connection) |
1771 | { | 1773 | { |
1772 | struct MHD_Connection *const c = connection; /**< a short alias */ | 1774 | struct MHD_Connection *const c = connection; /**< a short alias */ |
1773 | struct MHD_Response *const r = c->response; /**< a short alias */ | 1775 | struct MHD_Response *const r = c->rp.response; /**< a short alias */ |
1774 | enum replyBodyUse use_rp_body; | 1776 | enum replyBodyUse use_rp_body; |
1775 | bool use_chunked; | 1777 | bool use_chunked; |
1776 | 1778 | ||
@@ -1779,15 +1781,15 @@ setup_reply_properties (struct MHD_Connection *connection) | |||
1779 | /* ** Adjust reply properties ** */ | 1781 | /* ** Adjust reply properties ** */ |
1780 | 1782 | ||
1781 | c->keepalive = keepalive_possible (c); | 1783 | c->keepalive = keepalive_possible (c); |
1782 | use_rp_body = is_reply_body_needed (c, c->responseCode); | 1784 | use_rp_body = is_reply_body_needed (c, c->rp.responseCode); |
1783 | c->rp_props.send_reply_body = (use_rp_body > RP_BODY_HEADERS_ONLY); | 1785 | c->rp.props.send_reply_body = (use_rp_body > RP_BODY_HEADERS_ONLY); |
1784 | c->rp_props.use_reply_body_headers = (use_rp_body >= RP_BODY_HEADERS_ONLY); | 1786 | c->rp.props.use_reply_body_headers = (use_rp_body >= RP_BODY_HEADERS_ONLY); |
1785 | 1787 | ||
1786 | #ifdef UPGRADE_SUPPORT | 1788 | #ifdef UPGRADE_SUPPORT |
1787 | mhd_assert ((NULL == r->upgrade_handler) || (RP_BODY_NONE == use_rp_body)); | 1789 | mhd_assert ((NULL == r->upgrade_handler) || (RP_BODY_NONE == use_rp_body)); |
1788 | #endif /* UPGRADE_SUPPORT */ | 1790 | #endif /* UPGRADE_SUPPORT */ |
1789 | 1791 | ||
1790 | if (c->rp_props.use_reply_body_headers) | 1792 | if (c->rp.props.use_reply_body_headers) |
1791 | { | 1793 | { |
1792 | if ((MHD_SIZE_UNKNOWN == r->total_size) || | 1794 | if ((MHD_SIZE_UNKNOWN == r->total_size) || |
1793 | (0 != (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED))) | 1795 | (0 != (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED))) |
@@ -1820,8 +1822,8 @@ setup_reply_properties (struct MHD_Connection *connection) | |||
1820 | else | 1822 | else |
1821 | use_chunked = false; /* chunked encoding cannot be used without body */ | 1823 | use_chunked = false; /* chunked encoding cannot be used without body */ |
1822 | 1824 | ||
1823 | c->rp_props.chunked = use_chunked; | 1825 | c->rp.props.chunked = use_chunked; |
1824 | c->rp_props.set = true; | 1826 | c->rp.props.set = true; |
1825 | } | 1827 | } |
1826 | 1828 | ||
1827 | 1829 | ||
@@ -1833,25 +1835,25 @@ static void | |||
1833 | check_connection_reply (struct MHD_Connection *connection) | 1835 | check_connection_reply (struct MHD_Connection *connection) |
1834 | { | 1836 | { |
1835 | struct MHD_Connection *const c = connection; /**< a short alias */ | 1837 | struct MHD_Connection *const c = connection; /**< a short alias */ |
1836 | struct MHD_Response *const r = c->response; /**< a short alias */ | 1838 | struct MHD_Response *const r = c->rp.response; /**< a short alias */ |
1837 | mhd_assert (c->rp_props.set); | 1839 | mhd_assert (c->rp.props.set); |
1838 | 1840 | ||
1839 | #ifdef HAVE_MESSAGES | 1841 | #ifdef HAVE_MESSAGES |
1840 | if ((! c->rp_props.use_reply_body_headers) && (0 != r->total_size)) | 1842 | if ((! c->rp.props.use_reply_body_headers) && (0 != r->total_size)) |
1841 | { | 1843 | { |
1842 | MHD_DLOG (c->daemon, | 1844 | MHD_DLOG (c->daemon, |
1843 | _ ("This reply with response code %u cannot use reply body. " | 1845 | _ ("This reply with response code %u cannot use reply body. " |
1844 | "Non-empty response body is ignored and not used.\n"), | 1846 | "Non-empty response body is ignored and not used.\n"), |
1845 | (unsigned) (c->responseCode)); | 1847 | (unsigned) (c->rp.responseCode)); |
1846 | } | 1848 | } |
1847 | if ( (! c->rp_props.use_reply_body_headers) && | 1849 | if ( (! c->rp.props.use_reply_body_headers) && |
1848 | (0 != (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH)) ) | 1850 | (0 != (r->flags_auto & MHD_RAF_HAS_CONTENT_LENGTH)) ) |
1849 | { | 1851 | { |
1850 | MHD_DLOG (c->daemon, | 1852 | MHD_DLOG (c->daemon, |
1851 | _ ("This reply with response code %u cannot use reply body. " | 1853 | _ ("This reply with response code %u cannot use reply body. " |
1852 | "Application defined \"Content-Length\" header violates" | 1854 | "Application defined \"Content-Length\" header violates" |
1853 | "HTTP specification.\n"), | 1855 | "HTTP specification.\n"), |
1854 | (unsigned) (c->responseCode)); | 1856 | (unsigned) (c->rp.responseCode)); |
1855 | } | 1857 | } |
1856 | #else | 1858 | #else |
1857 | (void) c; /* Mute compiler warning */ | 1859 | (void) c; /* Mute compiler warning */ |
@@ -2037,14 +2039,14 @@ static enum MHD_Result | |||
2037 | build_header_response (struct MHD_Connection *connection) | 2039 | build_header_response (struct MHD_Connection *connection) |
2038 | { | 2040 | { |
2039 | struct MHD_Connection *const c = connection; /**< a short alias */ | 2041 | struct MHD_Connection *const c = connection; /**< a short alias */ |
2040 | struct MHD_Response *const r = c->response; /**< a short alias */ | 2042 | struct MHD_Response *const r = c->rp.response; /**< a short alias */ |
2041 | char *buf; /**< the output buffer */ | 2043 | char *buf; /**< the output buffer */ |
2042 | size_t pos; /**< append offset in the @a buf */ | 2044 | size_t pos; /**< append offset in the @a buf */ |
2043 | size_t buf_size; /**< the size of the @a buf */ | 2045 | size_t buf_size; /**< the size of the @a buf */ |
2044 | size_t el_size; /**< the size of current element to be added to the @a buf */ | 2046 | size_t el_size; /**< the size of current element to be added to the @a buf */ |
2045 | unsigned rcode; /**< the response code */ | 2047 | unsigned rcode; /**< the response code */ |
2046 | bool use_conn_close; /**< Use "Connection: close" header */ | 2048 | bool use_conn_close; /**< Use "Connection: close" header */ |
2047 | bool use_conn_k_alive; /**< Use "Connection: Keep-Alive" header */ | 2049 | bool use_conn_k_alive; /**< Use "Connection: Keep-Alive" header */ |
2048 | 2050 | ||
2049 | mhd_assert (NULL != r); | 2051 | mhd_assert (NULL != r); |
2050 | 2052 | ||
@@ -2052,7 +2054,7 @@ build_header_response (struct MHD_Connection *connection) | |||
2052 | 2054 | ||
2053 | setup_reply_properties (c); | 2055 | setup_reply_properties (c); |
2054 | 2056 | ||
2055 | mhd_assert (c->rp_props.set); | 2057 | mhd_assert (c->rp.props.set); |
2056 | mhd_assert ((MHD_CONN_MUST_CLOSE == c->keepalive) || \ | 2058 | mhd_assert ((MHD_CONN_MUST_CLOSE == c->keepalive) || \ |
2057 | (MHD_CONN_USE_KEEPALIVE == c->keepalive) || \ | 2059 | (MHD_CONN_USE_KEEPALIVE == c->keepalive) || \ |
2058 | (MHD_CONN_MUST_UPGRADE == c->keepalive)); | 2060 | (MHD_CONN_MUST_UPGRADE == c->keepalive)); |
@@ -2062,17 +2064,17 @@ build_header_response (struct MHD_Connection *connection) | |||
2062 | #else /* ! UPGRADE_SUPPORT */ | 2064 | #else /* ! UPGRADE_SUPPORT */ |
2063 | mhd_assert (MHD_CONN_MUST_UPGRADE != c->keepalive); | 2065 | mhd_assert (MHD_CONN_MUST_UPGRADE != c->keepalive); |
2064 | #endif /* ! UPGRADE_SUPPORT */ | 2066 | #endif /* ! UPGRADE_SUPPORT */ |
2065 | mhd_assert ((! c->rp_props.chunked) || c->rp_props.use_reply_body_headers); | 2067 | mhd_assert ((! c->rp.props.chunked) || c->rp.props.use_reply_body_headers); |
2066 | mhd_assert ((! c->rp_props.send_reply_body) || \ | 2068 | mhd_assert ((! c->rp.props.send_reply_body) || \ |
2067 | c->rp_props.use_reply_body_headers); | 2069 | c->rp.props.use_reply_body_headers); |
2068 | #ifdef UPGRADE_SUPPORT | 2070 | #ifdef UPGRADE_SUPPORT |
2069 | mhd_assert (NULL == r->upgrade_handler || \ | 2071 | mhd_assert (NULL == r->upgrade_handler || \ |
2070 | ! c->rp_props.use_reply_body_headers); | 2072 | ! c->rp.props.use_reply_body_headers); |
2071 | #endif /* UPGRADE_SUPPORT */ | 2073 | #endif /* UPGRADE_SUPPORT */ |
2072 | 2074 | ||
2073 | check_connection_reply (c); | 2075 | check_connection_reply (c); |
2074 | 2076 | ||
2075 | rcode = (unsigned) c->responseCode; | 2077 | rcode = (unsigned) c->rp.responseCode; |
2076 | if (MHD_CONN_MUST_CLOSE == c->keepalive) | 2078 | if (MHD_CONN_MUST_CLOSE == c->keepalive) |
2077 | { | 2079 | { |
2078 | /* The closure of connection must be always indicated by header | 2080 | /* The closure of connection must be always indicated by header |
@@ -2114,7 +2116,7 @@ build_header_response (struct MHD_Connection *connection) | |||
2114 | /* * The status line * */ | 2116 | /* * The status line * */ |
2115 | 2117 | ||
2116 | /* The HTTP version */ | 2118 | /* The HTTP version */ |
2117 | if (! c->responseIcy) | 2119 | if (! c->rp.responseIcy) |
2118 | { /* HTTP reply */ | 2120 | { /* HTTP reply */ |
2119 | if (0 == (r->flags & MHD_RF_HTTP_1_0_SERVER)) | 2121 | if (0 == (r->flags & MHD_RF_HTTP_1_0_SERVER)) |
2120 | { /* HTTP/1.1 reply */ | 2122 | { /* HTTP/1.1 reply */ |
@@ -2197,8 +2199,8 @@ build_header_response (struct MHD_Connection *connection) | |||
2197 | /* User-defined headers */ | 2199 | /* User-defined headers */ |
2198 | 2200 | ||
2199 | if (! add_user_headers (buf, &pos, buf_size, r, | 2201 | if (! add_user_headers (buf, &pos, buf_size, r, |
2200 | ! c->rp_props.chunked, | 2202 | ! c->rp.props.chunked, |
2201 | (! c->rp_props.use_reply_body_headers) && | 2203 | (! c->rp.props.use_reply_body_headers) && |
2202 | (0 == | 2204 | (0 == |
2203 | (r->flags & MHD_RF_INSANITY_HEADER_CONTENT_LENGTH)), | 2205 | (r->flags & MHD_RF_INSANITY_HEADER_CONTENT_LENGTH)), |
2204 | use_conn_close, | 2206 | use_conn_close, |
@@ -2207,12 +2209,12 @@ build_header_response (struct MHD_Connection *connection) | |||
2207 | 2209 | ||
2208 | /* Other automatic headers */ | 2210 | /* Other automatic headers */ |
2209 | 2211 | ||
2210 | if ( (c->rp_props.use_reply_body_headers) && | 2212 | if ( (c->rp.props.use_reply_body_headers) && |
2211 | (0 == (r->flags & MHD_RF_HEAD_ONLY_RESPONSE)) ) | 2213 | (0 == (r->flags & MHD_RF_HEAD_ONLY_RESPONSE)) ) |
2212 | { | 2214 | { |
2213 | /* Body-specific headers */ | 2215 | /* Body-specific headers */ |
2214 | 2216 | ||
2215 | if (c->rp_props.chunked) | 2217 | if (c->rp.props.chunked) |
2216 | { /* Chunked encoding is used */ | 2218 | { /* Chunked encoding is used */ |
2217 | if (0 == (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED)) | 2219 | if (0 == (r->flags_auto & MHD_RAF_HAS_TRANS_ENC_CHUNKED)) |
2218 | { /* No chunked encoding header set by user */ | 2220 | { /* No chunked encoding header set by user */ |
@@ -2275,11 +2277,11 @@ build_connection_chunked_response_footer (struct MHD_Connection *connection) | |||
2275 | struct MHD_Connection *const c = connection; /**< a short alias */ | 2277 | struct MHD_Connection *const c = connection; /**< a short alias */ |
2276 | struct MHD_HTTP_Res_Header *pos; | 2278 | struct MHD_HTTP_Res_Header *pos; |
2277 | 2279 | ||
2278 | mhd_assert (connection->rp_props.chunked); | 2280 | mhd_assert (connection->rp.props.chunked); |
2279 | /* TODO: allow combining of the final footer with the last chunk, | 2281 | /* TODO: allow combining of the final footer with the last chunk, |
2280 | * modify the next assert. */ | 2282 | * modify the next assert. */ |
2281 | mhd_assert (MHD_CONNECTION_BODY_SENT == connection->state); | 2283 | mhd_assert (MHD_CONNECTION_BODY_SENT == connection->state); |
2282 | mhd_assert (NULL != c->response); | 2284 | mhd_assert (NULL != c->rp.response); |
2283 | 2285 | ||
2284 | buf_size = connection_maximize_write_buffer (c); | 2286 | buf_size = connection_maximize_write_buffer (c); |
2285 | /* '5' is the minimal size of chunked footer ("0\r\n\r\n") */ | 2287 | /* '5' is the minimal size of chunked footer ("0\r\n\r\n") */ |
@@ -2293,7 +2295,7 @@ build_connection_chunked_response_footer (struct MHD_Connection *connection) | |||
2293 | buf[used_size++] = '\r'; | 2295 | buf[used_size++] = '\r'; |
2294 | buf[used_size++] = '\n'; | 2296 | buf[used_size++] = '\n'; |
2295 | 2297 | ||
2296 | for (pos = c->response->first_header; NULL != pos; pos = pos->next) | 2298 | for (pos = c->rp.response->first_header; NULL != pos; pos = pos->next) |
2297 | { | 2299 | { |
2298 | if (MHD_FOOTER_KIND == pos->kind) | 2300 | if (MHD_FOOTER_KIND == pos->kind) |
2299 | { | 2301 | { |
@@ -2387,10 +2389,10 @@ transmit_error_response_len (struct MHD_Connection *connection, | |||
2387 | connection->read_buffer_size = 0; | 2389 | connection->read_buffer_size = 0; |
2388 | connection->read_buffer_offset = 0; | 2390 | connection->read_buffer_offset = 0; |
2389 | } | 2391 | } |
2390 | if (NULL != connection->response) | 2392 | if (NULL != connection->rp.response) |
2391 | { | 2393 | { |
2392 | MHD_destroy_response (connection->response); | 2394 | MHD_destroy_response (connection->rp.response); |
2393 | connection->response = NULL; | 2395 | connection->rp.response = NULL; |
2394 | } | 2396 | } |
2395 | response = MHD_create_response_from_buffer_static (message_len, | 2397 | response = MHD_create_response_from_buffer_static (message_len, |
2396 | message); | 2398 | message); |
@@ -2418,7 +2420,7 @@ transmit_error_response_len (struct MHD_Connection *connection, | |||
2418 | "(failed to queue error response).")); | 2420 | "(failed to queue error response).")); |
2419 | return; | 2421 | return; |
2420 | } | 2422 | } |
2421 | mhd_assert (NULL != connection->response); | 2423 | mhd_assert (NULL != connection->rp.response); |
2422 | /* Do not reuse this connection. */ | 2424 | /* Do not reuse this connection. */ |
2423 | connection->keepalive = MHD_CONN_MUST_CLOSE; | 2425 | connection->keepalive = MHD_CONN_MUST_CLOSE; |
2424 | if (MHD_NO == build_header_response (connection)) | 2426 | if (MHD_NO == build_header_response (connection)) |
@@ -3394,7 +3396,7 @@ call_connection_handler (struct MHD_Connection *connection) | |||
3394 | struct MHD_Daemon *daemon = connection->daemon; | 3396 | struct MHD_Daemon *daemon = connection->daemon; |
3395 | size_t processed; | 3397 | size_t processed; |
3396 | 3398 | ||
3397 | if (NULL != connection->response) | 3399 | if (NULL != connection->rp.response) |
3398 | return; /* already queued a response */ | 3400 | return; /* already queued a response */ |
3399 | processed = 0; | 3401 | processed = 0; |
3400 | connection->rq.client_aware = true; | 3402 | connection->rq.client_aware = true; |
@@ -3432,7 +3434,7 @@ process_request_body (struct MHD_Connection *connection) | |||
3432 | bool instant_retry; | 3434 | bool instant_retry; |
3433 | char *buffer_head; | 3435 | char *buffer_head; |
3434 | 3436 | ||
3435 | if (NULL != connection->response) | 3437 | if (NULL != connection->rp.response) |
3436 | { | 3438 | { |
3437 | /* TODO: discard all read buffer as early response | 3439 | /* TODO: discard all read buffer as early response |
3438 | * means that connection have to be closed. */ | 3440 | * means that connection have to be closed. */ |
@@ -4299,7 +4301,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4299 | return; | 4301 | return; |
4300 | case MHD_CONNECTION_HEADERS_SENDING: | 4302 | case MHD_CONNECTION_HEADERS_SENDING: |
4301 | { | 4303 | { |
4302 | struct MHD_Response *const resp = connection->response; | 4304 | struct MHD_Response *const resp = connection->rp.response; |
4303 | const size_t wb_ready = connection->write_buffer_append_offset | 4305 | const size_t wb_ready = connection->write_buffer_append_offset |
4304 | - connection->write_buffer_send_offset; | 4306 | - connection->write_buffer_send_offset; |
4305 | mhd_assert (connection->write_buffer_append_offset >= \ | 4307 | mhd_assert (connection->write_buffer_append_offset >= \ |
@@ -4308,18 +4310,18 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4308 | mhd_assert ( (0 == resp->data_size) || \ | 4310 | mhd_assert ( (0 == resp->data_size) || \ |
4309 | (0 == resp->data_start) || \ | 4311 | (0 == resp->data_start) || \ |
4310 | (NULL != resp->crc) ); | 4312 | (NULL != resp->crc) ); |
4311 | mhd_assert ( (0 == connection->response_write_position) || \ | 4313 | mhd_assert ( (0 == connection->rp.rsp_write_position) || \ |
4312 | (resp->total_size == | 4314 | (resp->total_size == |
4313 | connection->response_write_position) ); | 4315 | connection->rp.rsp_write_position) ); |
4314 | mhd_assert ((MHD_CONN_MUST_UPGRADE != connection->keepalive) || \ | 4316 | mhd_assert ((MHD_CONN_MUST_UPGRADE != connection->keepalive) || \ |
4315 | (! connection->rp_props.send_reply_body)); | 4317 | (! connection->rp.props.send_reply_body)); |
4316 | 4318 | ||
4317 | if ( (connection->rp_props.send_reply_body) && | 4319 | if ( (connection->rp.props.send_reply_body) && |
4318 | (NULL == resp->crc) && | 4320 | (NULL == resp->crc) && |
4319 | (NULL == resp->data_iov) && | 4321 | (NULL == resp->data_iov) && |
4320 | /* TODO: remove the next check as 'send_reply_body' is used */ | 4322 | /* TODO: remove the next check as 'send_reply_body' is used */ |
4321 | (0 == connection->response_write_position) && | 4323 | (0 == connection->rp.rsp_write_position) && |
4322 | (! connection->rp_props.chunked) ) | 4324 | (! connection->rp.props.chunked) ) |
4323 | { | 4325 | { |
4324 | mhd_assert (resp->total_size >= resp->data_size); | 4326 | mhd_assert (resp->total_size >= resp->data_size); |
4325 | mhd_assert (0 == resp->data_start); | 4327 | mhd_assert (0 == resp->data_start); |
@@ -4347,7 +4349,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4347 | NULL, | 4349 | NULL, |
4348 | 0, | 4350 | 0, |
4349 | ((0 == resp->total_size) || | 4351 | ((0 == resp->total_size) || |
4350 | (! connection->rp_props.send_reply_body) | 4352 | (! connection->rp.props.send_reply_body) |
4351 | )); | 4353 | )); |
4352 | } | 4354 | } |
4353 | 4355 | ||
@@ -4371,11 +4373,11 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4371 | { | 4373 | { |
4372 | /* The complete header and some response data have been sent, | 4374 | /* The complete header and some response data have been sent, |
4373 | * update both offsets. */ | 4375 | * update both offsets. */ |
4374 | mhd_assert (0 == connection->response_write_position); | 4376 | mhd_assert (0 == connection->rp.rsp_write_position); |
4375 | mhd_assert (! connection->rp_props.chunked); | 4377 | mhd_assert (! connection->rp.props.chunked); |
4376 | mhd_assert (connection->rp_props.send_reply_body); | 4378 | mhd_assert (connection->rp.props.send_reply_body); |
4377 | connection->write_buffer_send_offset += wb_ready; | 4379 | connection->write_buffer_send_offset += wb_ready; |
4378 | connection->response_write_position = ((size_t) ret) - wb_ready; | 4380 | connection->rp.rsp_write_position = ((size_t) ret) - wb_ready; |
4379 | } | 4381 | } |
4380 | else | 4382 | else |
4381 | connection->write_buffer_send_offset += (size_t) ret; | 4383 | connection->write_buffer_send_offset += (size_t) ret; |
@@ -4389,9 +4391,9 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4389 | case MHD_CONNECTION_HEADERS_SENT: | 4391 | case MHD_CONNECTION_HEADERS_SENT: |
4390 | return; | 4392 | return; |
4391 | case MHD_CONNECTION_NORMAL_BODY_READY: | 4393 | case MHD_CONNECTION_NORMAL_BODY_READY: |
4392 | response = connection->response; | 4394 | response = connection->rp.response; |
4393 | if (connection->response_write_position < | 4395 | if (connection->rp.rsp_write_position < |
4394 | connection->response->total_size) | 4396 | connection->rp.response->total_size) |
4395 | { | 4397 | { |
4396 | uint64_t data_write_offset; | 4398 | uint64_t data_write_offset; |
4397 | 4399 | ||
@@ -4405,7 +4407,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4405 | return; | 4407 | return; |
4406 | } | 4408 | } |
4407 | #if defined(_MHD_HAVE_SENDFILE) | 4409 | #if defined(_MHD_HAVE_SENDFILE) |
4408 | if (MHD_resp_sender_sendfile == connection->resp_sender) | 4410 | if (MHD_resp_sender_sendfile == connection->rp.resp_sender) |
4409 | { | 4411 | { |
4410 | mhd_assert (NULL == response->data_iov); | 4412 | mhd_assert (NULL == response->data_iov); |
4411 | ret = MHD_send_sendfile_ (connection); | 4413 | ret = MHD_send_sendfile_ (connection); |
@@ -4415,12 +4417,12 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4415 | if (NULL != response->data_iov) | 4417 | if (NULL != response->data_iov) |
4416 | { | 4418 | { |
4417 | ret = MHD_send_iovec_ (connection, | 4419 | ret = MHD_send_iovec_ (connection, |
4418 | &connection->resp_iov, | 4420 | &connection->rp.resp_iov, |
4419 | true); | 4421 | true); |
4420 | } | 4422 | } |
4421 | else | 4423 | else |
4422 | { | 4424 | { |
4423 | data_write_offset = connection->response_write_position | 4425 | data_write_offset = connection->rp.rsp_write_position |
4424 | - response->data_start; | 4426 | - response->data_start; |
4425 | if (data_write_offset > (uint64_t) SIZE_MAX) | 4427 | if (data_write_offset > (uint64_t) SIZE_MAX) |
4426 | MHD_PANIC (_ ("Data offset exceeds limit.\n")); | 4428 | MHD_PANIC (_ ("Data offset exceeds limit.\n")); |
@@ -4436,8 +4438,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4436 | _ ("Sent %d-byte DATA response: `%.*s'\n"), | 4438 | _ ("Sent %d-byte DATA response: `%.*s'\n"), |
4437 | (int) ret, | 4439 | (int) ret, |
4438 | (int) ret, | 4440 | (int) ret, |
4439 | &response->data[connection->response_write_position | 4441 | &rp.response->data[connection->rp.rsp_write_position |
4440 | - response->data_start]); | 4442 | - rp.response->data_start]); |
4441 | #endif | 4443 | #endif |
4442 | } | 4444 | } |
4443 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 4445 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
@@ -4459,11 +4461,11 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4459 | NULL); | 4461 | NULL); |
4460 | return; | 4462 | return; |
4461 | } | 4463 | } |
4462 | connection->response_write_position += (size_t) ret; | 4464 | connection->rp.rsp_write_position += (size_t) ret; |
4463 | MHD_update_last_activity_ (connection); | 4465 | MHD_update_last_activity_ (connection); |
4464 | } | 4466 | } |
4465 | if (connection->response_write_position == | 4467 | if (connection->rp.rsp_write_position == |
4466 | connection->response->total_size) | 4468 | connection->rp.response->total_size) |
4467 | connection->state = MHD_CONNECTION_FOOTERS_SENT; /* have no footers */ | 4469 | connection->state = MHD_CONNECTION_FOOTERS_SENT; /* have no footers */ |
4468 | return; | 4470 | return; |
4469 | case MHD_CONNECTION_NORMAL_BODY_UNREADY: | 4471 | case MHD_CONNECTION_NORMAL_BODY_UNREADY: |
@@ -4496,8 +4498,8 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
4496 | if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state) | 4498 | if (MHD_CONNECTION_CHUNKED_BODY_READY != connection->state) |
4497 | return; | 4499 | return; |
4498 | check_write_done (connection, | 4500 | check_write_done (connection, |
4499 | (connection->response->total_size == | 4501 | (connection->rp.response->total_size == |
4500 | connection->response_write_position) ? | 4502 | connection->rp.rsp_write_position) ? |
4501 | MHD_CONNECTION_BODY_SENT : | 4503 | MHD_CONNECTION_BODY_SENT : |
4502 | MHD_CONNECTION_CHUNKED_BODY_UNREADY); | 4504 | MHD_CONNECTION_CHUNKED_BODY_UNREADY); |
4503 | return; | 4505 | return; |
@@ -4625,10 +4627,10 @@ cleanup_connection (struct MHD_Connection *connection) | |||
4625 | if (connection->in_cleanup) | 4627 | if (connection->in_cleanup) |
4626 | return; /* Prevent double cleanup. */ | 4628 | return; /* Prevent double cleanup. */ |
4627 | connection->in_cleanup = true; | 4629 | connection->in_cleanup = true; |
4628 | if (NULL != connection->response) | 4630 | if (NULL != connection->rp.response) |
4629 | { | 4631 | { |
4630 | MHD_destroy_response (connection->response); | 4632 | MHD_destroy_response (connection->rp.response); |
4631 | connection->response = NULL; | 4633 | connection->rp.response = NULL; |
4632 | } | 4634 | } |
4633 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 4635 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
4634 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 4636 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
@@ -4700,7 +4702,7 @@ connection_reset (struct MHD_Connection *connection, | |||
4700 | { | 4702 | { |
4701 | /* Next function will destroy response, notify client, | 4703 | /* Next function will destroy response, notify client, |
4702 | * destroy memory pool, and set connection state to "CLOSED" */ | 4704 | * destroy memory pool, and set connection state to "CLOSED" */ |
4703 | MHD_connection_close_ (connection, | 4705 | MHD_connection_close_ (c, |
4704 | c->stop_with_error ? | 4706 | c->stop_with_error ? |
4705 | MHD_REQUEST_TERMINATED_WITH_ERROR : | 4707 | MHD_REQUEST_TERMINATED_WITH_ERROR : |
4706 | MHD_REQUEST_TERMINATED_COMPLETED_OK); | 4708 | MHD_REQUEST_TERMINATED_COMPLETED_OK); |
@@ -4727,9 +4729,9 @@ connection_reset (struct MHD_Connection *connection, | |||
4727 | MHD_REQUEST_TERMINATED_COMPLETED_OK); | 4729 | MHD_REQUEST_TERMINATED_COMPLETED_OK); |
4728 | c->rq.client_aware = false; | 4730 | c->rq.client_aware = false; |
4729 | 4731 | ||
4730 | if (NULL != c->response) | 4732 | if (NULL != c->rp.response) |
4731 | MHD_destroy_response (c->response); | 4733 | MHD_destroy_response (c->rp.response); |
4732 | c->response = NULL; | 4734 | c->rp.response = NULL; |
4733 | 4735 | ||
4734 | c->keepalive = MHD_CONN_KEEPALIVE_UNKOWN; | 4736 | c->keepalive = MHD_CONN_KEEPALIVE_UNKOWN; |
4735 | c->state = MHD_CONNECTION_INIT; | 4737 | c->state = MHD_CONNECTION_INIT; |
@@ -4739,13 +4741,8 @@ connection_reset (struct MHD_Connection *connection, | |||
4739 | c->rq_auth = NULL; | 4741 | c->rq_auth = NULL; |
4740 | #endif | 4742 | #endif |
4741 | 4743 | ||
4742 | c->responseCode = 0; | 4744 | /* iov (if any) will be deallocated by MHD_pool_reset */ |
4743 | c->responseIcy = false; | 4745 | memset (&c->rp, 0, sizeof(c->rp)); |
4744 | c->response_write_position = 0; | ||
4745 | |||
4746 | memset (&c->rp_props, 0, sizeof(c->rp_props)); | ||
4747 | /* iov (if any) was deallocated by MHD_pool_reset */ | ||
4748 | memset (&connection->resp_iov, 0, sizeof(connection->resp_iov)); | ||
4749 | 4746 | ||
4750 | c->write_buffer = NULL; | 4747 | c->write_buffer = NULL; |
4751 | c->write_buffer_size = 0; | 4748 | c->write_buffer_size = 0; |
@@ -4759,7 +4756,7 @@ connection_reset (struct MHD_Connection *connection, | |||
4759 | if (c->read_buffer_offset > new_read_buf_size) | 4756 | if (c->read_buffer_offset > new_read_buf_size) |
4760 | new_read_buf_size = c->read_buffer_offset; | 4757 | new_read_buf_size = c->read_buffer_offset; |
4761 | 4758 | ||
4762 | connection->read_buffer | 4759 | c->read_buffer |
4763 | = MHD_pool_reset (c->pool, | 4760 | = MHD_pool_reset (c->pool, |
4764 | c->read_buffer, | 4761 | c->read_buffer, |
4765 | c->read_buffer_offset, | 4762 | c->read_buffer_offset, |
@@ -4924,13 +4921,13 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4924 | continue; | 4921 | continue; |
4925 | if (connection->suspended) | 4922 | if (connection->suspended) |
4926 | continue; | 4923 | continue; |
4927 | if ( (NULL == connection->response) && | 4924 | if ( (NULL == connection->rp.response) && |
4928 | (need_100_continue (connection)) ) | 4925 | (need_100_continue (connection)) ) |
4929 | { | 4926 | { |
4930 | connection->state = MHD_CONNECTION_CONTINUE_SENDING; | 4927 | connection->state = MHD_CONNECTION_CONTINUE_SENDING; |
4931 | break; | 4928 | break; |
4932 | } | 4929 | } |
4933 | if ( (NULL != connection->response) && | 4930 | if ( (NULL != connection->rp.response) && |
4934 | (0 != connection->rq.remaining_upload_size) ) | 4931 | (0 != connection->rq.remaining_upload_size) ) |
4935 | { | 4932 | { |
4936 | /* we refused (no upload allowed!) */ | 4933 | /* we refused (no upload allowed!) */ |
@@ -5048,13 +5045,13 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5048 | call_connection_handler (connection); /* "final" call */ | 5045 | call_connection_handler (connection); /* "final" call */ |
5049 | if (connection->state == MHD_CONNECTION_CLOSED) | 5046 | if (connection->state == MHD_CONNECTION_CLOSED) |
5050 | continue; | 5047 | continue; |
5051 | if (NULL == connection->response) | 5048 | if (NULL == connection->rp.response) |
5052 | break; /* try again next time */ | 5049 | break; /* try again next time */ |
5053 | /* Response is ready, start reply */ | 5050 | /* Response is ready, start reply */ |
5054 | connection->state = MHD_CONNECTION_START_REPLY; | 5051 | connection->state = MHD_CONNECTION_START_REPLY; |
5055 | continue; | 5052 | continue; |
5056 | case MHD_CONNECTION_START_REPLY: | 5053 | case MHD_CONNECTION_START_REPLY: |
5057 | mhd_assert (NULL != connection->response); | 5054 | mhd_assert (NULL != connection->rp.response); |
5058 | connection_switch_from_recv_to_send (connection); | 5055 | connection_switch_from_recv_to_send (connection); |
5059 | if (MHD_NO == build_header_response (connection)) | 5056 | if (MHD_NO == build_header_response (connection)) |
5060 | { | 5057 | { |
@@ -5073,12 +5070,12 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5073 | case MHD_CONNECTION_HEADERS_SENT: | 5070 | case MHD_CONNECTION_HEADERS_SENT: |
5074 | /* Some clients may take some actions right after header receive */ | 5071 | /* Some clients may take some actions right after header receive */ |
5075 | #ifdef UPGRADE_SUPPORT | 5072 | #ifdef UPGRADE_SUPPORT |
5076 | if (NULL != connection->response->upgrade_handler) | 5073 | if (NULL != connection->rp.response->upgrade_handler) |
5077 | { | 5074 | { |
5078 | connection->state = MHD_CONNECTION_UPGRADE; | 5075 | connection->state = MHD_CONNECTION_UPGRADE; |
5079 | /* This connection is "upgraded". Pass socket to application. */ | 5076 | /* This connection is "upgraded". Pass socket to application. */ |
5080 | if (MHD_NO == | 5077 | if (MHD_NO == |
5081 | MHD_response_execute_upgrade_ (connection->response, | 5078 | MHD_response_execute_upgrade_ (connection->rp.response, |
5082 | connection)) | 5079 | connection)) |
5083 | { | 5080 | { |
5084 | /* upgrade failed, fail hard */ | 5081 | /* upgrade failed, fail hard */ |
@@ -5088,16 +5085,16 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5088 | } | 5085 | } |
5089 | /* Response is not required anymore for this connection. */ | 5086 | /* Response is not required anymore for this connection. */ |
5090 | { | 5087 | { |
5091 | struct MHD_Response *const resp = connection->response; | 5088 | struct MHD_Response *const resp = connection->rp.response; |
5092 | 5089 | ||
5093 | connection->response = NULL; | 5090 | connection->rp.response = NULL; |
5094 | MHD_destroy_response (resp); | 5091 | MHD_destroy_response (resp); |
5095 | } | 5092 | } |
5096 | continue; | 5093 | continue; |
5097 | } | 5094 | } |
5098 | #endif /* UPGRADE_SUPPORT */ | 5095 | #endif /* UPGRADE_SUPPORT */ |
5099 | 5096 | ||
5100 | if (connection->rp_props.chunked) | 5097 | if (connection->rp.props.chunked) |
5101 | connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY; | 5098 | connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY; |
5102 | else | 5099 | else |
5103 | connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; | 5100 | connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; |
@@ -5107,16 +5104,16 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5107 | break; | 5104 | break; |
5108 | case MHD_CONNECTION_NORMAL_BODY_UNREADY: | 5105 | case MHD_CONNECTION_NORMAL_BODY_UNREADY: |
5109 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 5106 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
5110 | if (NULL != connection->response->crc) | 5107 | if (NULL != connection->rp.response->crc) |
5111 | MHD_mutex_lock_chk_ (&connection->response->mutex); | 5108 | MHD_mutex_lock_chk_ (&connection->rp.response->mutex); |
5112 | #endif | 5109 | #endif |
5113 | if (0 == connection->response->total_size) | 5110 | if (0 == connection->rp.response->total_size) |
5114 | { | 5111 | { |
5115 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 5112 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
5116 | if (NULL != connection->response->crc) | 5113 | if (NULL != connection->rp.response->crc) |
5117 | MHD_mutex_unlock_chk_ (&connection->response->mutex); | 5114 | MHD_mutex_unlock_chk_ (&connection->rp.response->mutex); |
5118 | #endif | 5115 | #endif |
5119 | if (connection->rp_props.chunked) | 5116 | if (connection->rp.props.chunked) |
5120 | connection->state = MHD_CONNECTION_BODY_SENT; | 5117 | connection->state = MHD_CONNECTION_BODY_SENT; |
5121 | else | 5118 | else |
5122 | connection->state = MHD_CONNECTION_FOOTERS_SENT; | 5119 | connection->state = MHD_CONNECTION_FOOTERS_SENT; |
@@ -5125,8 +5122,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5125 | if (MHD_NO != try_ready_normal_body (connection)) | 5122 | if (MHD_NO != try_ready_normal_body (connection)) |
5126 | { | 5123 | { |
5127 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 5124 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
5128 | if (NULL != connection->response->crc) | 5125 | if (NULL != connection->rp.response->crc) |
5129 | MHD_mutex_unlock_chk_ (&connection->response->mutex); | 5126 | MHD_mutex_unlock_chk_ (&connection->rp.response->mutex); |
5130 | #endif | 5127 | #endif |
5131 | connection->state = MHD_CONNECTION_NORMAL_BODY_READY; | 5128 | connection->state = MHD_CONNECTION_NORMAL_BODY_READY; |
5132 | /* Buffering for flushable socket was already enabled*/ | 5129 | /* Buffering for flushable socket was already enabled*/ |
@@ -5141,16 +5138,16 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5141 | break; | 5138 | break; |
5142 | case MHD_CONNECTION_CHUNKED_BODY_UNREADY: | 5139 | case MHD_CONNECTION_CHUNKED_BODY_UNREADY: |
5143 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 5140 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
5144 | if (NULL != connection->response->crc) | 5141 | if (NULL != connection->rp.response->crc) |
5145 | MHD_mutex_lock_chk_ (&connection->response->mutex); | 5142 | MHD_mutex_lock_chk_ (&connection->rp.response->mutex); |
5146 | #endif | 5143 | #endif |
5147 | if ( (0 == connection->response->total_size) || | 5144 | if ( (0 == connection->rp.response->total_size) || |
5148 | (connection->response_write_position == | 5145 | (connection->rp.rsp_write_position == |
5149 | connection->response->total_size) ) | 5146 | connection->rp.response->total_size) ) |
5150 | { | 5147 | { |
5151 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 5148 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
5152 | if (NULL != connection->response->crc) | 5149 | if (NULL != connection->rp.response->crc) |
5153 | MHD_mutex_unlock_chk_ (&connection->response->mutex); | 5150 | MHD_mutex_unlock_chk_ (&connection->rp.response->mutex); |
5154 | #endif | 5151 | #endif |
5155 | connection->state = MHD_CONNECTION_BODY_SENT; | 5152 | connection->state = MHD_CONNECTION_BODY_SENT; |
5156 | continue; | 5153 | continue; |
@@ -5161,8 +5158,8 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5161 | if (MHD_NO != try_ready_chunked_body (connection, &finished)) | 5158 | if (MHD_NO != try_ready_chunked_body (connection, &finished)) |
5162 | { | 5159 | { |
5163 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 5160 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
5164 | if (NULL != connection->response->crc) | 5161 | if (NULL != connection->rp.response->crc) |
5165 | MHD_mutex_unlock_chk_ (&connection->response->mutex); | 5162 | MHD_mutex_unlock_chk_ (&connection->rp.response->mutex); |
5166 | #endif | 5163 | #endif |
5167 | connection->state = finished ? MHD_CONNECTION_BODY_SENT : | 5164 | connection->state = finished ? MHD_CONNECTION_BODY_SENT : |
5168 | MHD_CONNECTION_CHUNKED_BODY_READY; | 5165 | MHD_CONNECTION_CHUNKED_BODY_READY; |
@@ -5172,7 +5169,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5172 | } | 5169 | } |
5173 | break; | 5170 | break; |
5174 | case MHD_CONNECTION_BODY_SENT: | 5171 | case MHD_CONNECTION_BODY_SENT: |
5175 | mhd_assert (connection->rp_props.chunked); | 5172 | mhd_assert (connection->rp.props.chunked); |
5176 | 5173 | ||
5177 | if (MHD_NO == build_connection_chunked_response_footer (connection)) | 5174 | if (MHD_NO == build_connection_chunked_response_footer (connection)) |
5178 | { | 5175 | { |
@@ -5183,7 +5180,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5183 | continue; | 5180 | continue; |
5184 | } | 5181 | } |
5185 | /* TODO: remove next 'if' */ | 5182 | /* TODO: remove next 'if' */ |
5186 | if ( (! connection->rp_props.chunked) || | 5183 | if ( (! connection->rp.props.chunked) || |
5187 | (connection->write_buffer_send_offset == | 5184 | (connection->write_buffer_send_offset == |
5188 | connection->write_buffer_append_offset) ) | 5185 | connection->write_buffer_append_offset) ) |
5189 | connection->state = MHD_CONNECTION_FOOTERS_SENT; | 5186 | connection->state = MHD_CONNECTION_FOOTERS_SENT; |
@@ -5194,12 +5191,12 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
5194 | /* no default action */ | 5191 | /* no default action */ |
5195 | break; | 5192 | break; |
5196 | case MHD_CONNECTION_FOOTERS_SENT: | 5193 | case MHD_CONNECTION_FOOTERS_SENT: |
5197 | if (MHD_HTTP_PROCESSING == connection->responseCode) | 5194 | if (MHD_HTTP_PROCESSING == connection->rp.responseCode) |
5198 | { | 5195 | { |
5199 | /* After this type of response, we allow sending another! */ | 5196 | /* After this type of response, we allow sending another! */ |
5200 | connection->state = MHD_CONNECTION_HEADERS_PROCESSED; | 5197 | connection->state = MHD_CONNECTION_HEADERS_PROCESSED; |
5201 | MHD_destroy_response (connection->response); | 5198 | MHD_destroy_response (connection->rp.response); |
5202 | connection->response = NULL; | 5199 | connection->rp.response = NULL; |
5203 | /* FIXME: maybe partially reset memory pool? */ | 5200 | /* FIXME: maybe partially reset memory pool? */ |
5204 | continue; | 5201 | continue; |
5205 | } | 5202 | } |
@@ -5401,9 +5398,9 @@ MHD_get_connection_info (struct MHD_Connection *connection, | |||
5401 | connection->connection_info_dummy.header_size = connection->rq.header_size; | 5398 | connection->connection_info_dummy.header_size = connection->rq.header_size; |
5402 | return &connection->connection_info_dummy; | 5399 | return &connection->connection_info_dummy; |
5403 | case MHD_CONNECTION_INFO_HTTP_STATUS: | 5400 | case MHD_CONNECTION_INFO_HTTP_STATUS: |
5404 | if (NULL == connection->response) | 5401 | if (NULL == connection->rp.response) |
5405 | return NULL; | 5402 | return NULL; |
5406 | connection->connection_info_dummy.http_status = connection->responseCode; | 5403 | connection->connection_info_dummy.http_status = connection->rp.responseCode; |
5407 | return &connection->connection_info_dummy; | 5404 | return &connection->connection_info_dummy; |
5408 | default: | 5405 | default: |
5409 | return NULL; | 5406 | return NULL; |
@@ -5556,7 +5553,7 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5556 | return MHD_YES; /* If daemon was shut down in parallel, | 5553 | return MHD_YES; /* If daemon was shut down in parallel, |
5557 | * response will be aborted now or on later stage. */ | 5554 | * response will be aborted now or on later stage. */ |
5558 | 5555 | ||
5559 | if ( (NULL != connection->response) || | 5556 | if ( (NULL != connection->rp.response) || |
5560 | ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) && | 5557 | ( (MHD_CONNECTION_HEADERS_PROCESSED != connection->state) && |
5561 | (MHD_CONNECTION_FULL_REQ_RECEIVED != connection->state) ) ) | 5558 | (MHD_CONNECTION_FULL_REQ_RECEIVED != connection->state) ) ) |
5562 | return MHD_NO; | 5559 | return MHD_NO; |
@@ -5710,9 +5707,9 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5710 | #endif | 5707 | #endif |
5711 | 5708 | ||
5712 | MHD_increment_response_rc (response); | 5709 | MHD_increment_response_rc (response); |
5713 | connection->response = response; | 5710 | connection->rp.response = response; |
5714 | connection->responseCode = status_code; | 5711 | connection->rp.responseCode = status_code; |
5715 | connection->responseIcy = reply_icy; | 5712 | connection->rp.responseIcy = reply_icy; |
5716 | #if defined(_MHD_HAVE_SENDFILE) | 5713 | #if defined(_MHD_HAVE_SENDFILE) |
5717 | if ( (response->fd == -1) || | 5714 | if ( (response->fd == -1) || |
5718 | (response->is_pipe) || | 5715 | (response->is_pipe) || |
@@ -5723,9 +5720,9 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5723 | #endif /* MHD_SEND_SPIPE_SUPPRESS_NEEDED && | 5720 | #endif /* MHD_SEND_SPIPE_SUPPRESS_NEEDED && |
5724 | MHD_SEND_SPIPE_SUPPRESS_POSSIBLE */ | 5721 | MHD_SEND_SPIPE_SUPPRESS_POSSIBLE */ |
5725 | ) | 5722 | ) |
5726 | connection->resp_sender = MHD_resp_sender_std; | 5723 | connection->rp.resp_sender = MHD_resp_sender_std; |
5727 | else | 5724 | else |
5728 | connection->resp_sender = MHD_resp_sender_sendfile; | 5725 | connection->rp.resp_sender = MHD_resp_sender_sendfile; |
5729 | #endif /* _MHD_HAVE_SENDFILE */ | 5726 | #endif /* _MHD_HAVE_SENDFILE */ |
5730 | /* FIXME: if 'is_pipe' is set, TLS is off, and we have *splice*, we could use splice() | 5727 | /* FIXME: if 'is_pipe' is set, TLS is off, and we have *splice*, we could use splice() |
5731 | to avoid two user-space copies... */ | 5728 | to avoid two user-space copies... */ |
@@ -5740,7 +5737,7 @@ MHD_queue_response (struct MHD_Connection *connection, | |||
5740 | have already sent the full message body. */ | 5737 | have already sent the full message body. */ |
5741 | /* TODO: remove the next assignment, use 'rp_props.send_reply_body' in | 5738 | /* TODO: remove the next assignment, use 'rp_props.send_reply_body' in |
5742 | * checks */ | 5739 | * checks */ |
5743 | connection->response_write_position = response->total_size; | 5740 | connection->rp.rsp_write_position = response->total_size; |
5744 | } | 5741 | } |
5745 | if (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) | 5742 | if (MHD_CONNECTION_HEADERS_PROCESSED == connection->state) |
5746 | { | 5743 | { |