aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/internal.h
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-07-28 14:14:53 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-08-06 10:43:15 +0300
commit93ef4701123acd9c3f606b4d983dbaa840f427b4 (patch)
treea4a592b27345068aacafeebc0afbc2a4772fe575 /src/microhttpd/internal.h
parentbb33e458efbb383c5b557ef7a585c08b49dcdd43 (diff)
downloadlibmicrohttpd-93ef4701123acd9c3f606b4d983dbaa840f427b4.tar.gz
libmicrohttpd-93ef4701123acd9c3f606b4d983dbaa840f427b4.zip
Internal refactoring: moved all request-related members to separate structure
This should improve readability of the code and simplify reset.
Diffstat (limited to 'src/microhttpd/internal.h')
-rw-r--r--src/microhttpd/internal.h235
1 files changed, 124 insertions, 111 deletions
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index fa243a34..b7d67e14 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -918,6 +918,128 @@ enum MHD_HTTP_Method
918 918
919 919
920/** 920/**
921 * Request-specific values.
922 *
923 * Meaningful for the current request only.
924 */
925struct MHD_Request
926{
927 /**
928 * HTTP version string (i.e. http/1.1). Allocated
929 * in pool.
930 */
931 const char *version;
932
933 /**
934 * HTTP protocol version as enum.
935 */
936 enum MHD_HTTP_Version http_ver;
937
938 /**
939 * Request method. Should be GET/POST/etc. Allocated in pool.
940 */
941 const char *method;
942
943 /**
944 * The request method as enum.
945 */
946 enum MHD_HTTP_Method http_mthd;
947
948 /**
949 * Requested URL (everything after "GET" only). Allocated
950 * in pool.
951 */
952 const char *url;
953
954 /**
955 * The length of the @a url in characters, not including the terminating zero.
956 */
957 size_t url_len;
958
959 /**
960 * Linked list of parsed headers.
961 */
962 struct MHD_HTTP_Req_Header *headers_received;
963
964 /**
965 * Tail of linked list of parsed headers.
966 */
967 struct MHD_HTTP_Req_Header *headers_received_tail;
968
969 /**
970 * Number of bytes we had in the HTTP header, set once we
971 * pass #MHD_CONNECTION_HEADERS_RECEIVED.
972 */
973 size_t header_size;
974
975 /**
976 * How many more bytes of the body do we expect
977 * to read? #MHD_SIZE_UNKNOWN for unknown.
978 */
979 uint64_t remaining_upload_size;
980
981 /**
982 * Are we receiving with chunked encoding?
983 * This will be set to #MHD_YES after we parse the headers and
984 * are processing the body with chunks.
985 * After we are done with the body and we are processing the footers;
986 * once the footers are also done, this will be set to #MHD_NO again
987 * (before the final call to the handler).
988 * It is used only for requests, chunked encoding for response is
989 * indicated by @a rp_props.
990 */
991 bool have_chunked_upload;
992
993 /**
994 * If we are receiving with chunked encoding, where are we right
995 * now?
996 * Set to 0 if we are waiting to receive the chunk size;
997 * otherwise, this is the size of the current chunk.
998 * A value of zero is also used when we're at the end of the chunks.
999 */
1000 uint64_t current_chunk_size;
1001
1002 /**
1003 * If we are receiving with chunked encoding, where are we currently
1004 * with respect to the current chunk (at what offset / position)?
1005 */
1006 uint64_t current_chunk_offset;
1007
1008 /**
1009 * We allow the main application to associate some pointer with the
1010 * HTTP request, which is passed to each #MHD_AccessHandlerCallback
1011 * and some other API calls. Here is where we store it. (MHD does
1012 * not know or care what it is).
1013 */
1014 void *client_context;
1015
1016 /**
1017 * Did we ever call the "default_handler" on this request?
1018 * This flag determines if we have called the #MHD_OPTION_NOTIFY_COMPLETED
1019 * handler when the request finishes.
1020 */
1021 bool client_aware;
1022
1023 /**
1024 * Last incomplete header line during parsing of headers.
1025 * Allocated in pool. Only valid if state is
1026 * either #MHD_CONNECTION_HEADER_PART_RECEIVED or
1027 * #MHD_CONNECTION_FOOTER_PART_RECEIVED.
1028 */
1029 char *last;
1030
1031 /**
1032 * Position after the colon on the last incomplete header
1033 * line during parsing of headers.
1034 * Allocated in pool. Only valid if state is
1035 * either #MHD_CONNECTION_HEADER_PART_RECEIVED or
1036 * #MHD_CONNECTION_FOOTER_PART_RECEIVED.
1037 */
1038 char *colon;
1039};
1040
1041
1042/**
921 * Reply-specific properties. 1043 * Reply-specific properties.
922 */ 1044 */
923struct MHD_Reply_Properties 1045struct MHD_Reply_Properties
@@ -976,14 +1098,9 @@ struct MHD_Connection
976 struct MHD_Daemon *daemon; 1098 struct MHD_Daemon *daemon;
977 1099
978 /** 1100 /**
979 * Linked list of parsed headers. 1101 * Request-specific data
980 */
981 struct MHD_HTTP_Req_Header *headers_received;
982
983 /**
984 * Tail of linked list of parsed headers.
985 */ 1102 */
986 struct MHD_HTTP_Req_Header *headers_received_tail; 1103 struct MHD_Request rq;
987 1104
988 /** 1105 /**
989 * Response to transmit (initially NULL). 1106 * Response to transmit (initially NULL).
@@ -1002,14 +1119,6 @@ struct MHD_Connection
1002 1119
1003 /** 1120 /**
1004 * We allow the main application to associate some pointer with the 1121 * We allow the main application to associate some pointer with the
1005 * HTTP request, which is passed to each #MHD_AccessHandlerCallback
1006 * and some other API calls. Here is where we store it. (MHD does
1007 * not know or care what it is).
1008 */
1009 void *client_context;
1010
1011 /**
1012 * We allow the main application to associate some pointer with the
1013 * TCP connection (which may span multiple HTTP requests). Here is 1122 * TCP connection (which may span multiple HTTP requests). Here is
1014 * where we store it. (MHD does not know or care what it is). 1123 * where we store it. (MHD does not know or care what it is).
1015 * The location is given to the #MHD_NotifyConnectionCallback and 1124 * The location is given to the #MHD_NotifyConnectionCallback and
@@ -1017,38 +1126,6 @@ struct MHD_Connection
1017 */ 1126 */
1018 void *socket_context; 1127 void *socket_context;
1019 1128
1020 /**
1021 * Request method. Should be GET/POST/etc. Allocated in pool.
1022 */
1023 const char *method;
1024
1025 /**
1026 * The request method as enum.
1027 */
1028 enum MHD_HTTP_Method http_mthd;
1029
1030 /**
1031 * Requested URL (everything after "GET" only). Allocated
1032 * in pool.
1033 */
1034 const char *url;
1035
1036 /**
1037 * The length of the @a url in characters, not including the terminating zero.
1038 */
1039 size_t url_len;
1040
1041 /**
1042 * HTTP version string (i.e. http/1.1). Allocated
1043 * in pool.
1044 */
1045 const char *version;
1046
1047 /**
1048 * HTTP protocol version as enum.
1049 */
1050 enum MHD_HTTP_Version http_ver;
1051
1052#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT) 1129#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT)
1053 /** 1130 /**
1054 * Pointer to request authorization structure. 1131 * Pointer to request authorization structure.
@@ -1057,7 +1134,6 @@ struct MHD_Connection
1057 const struct MHD_AuthRqHeader *rq_auth; 1134 const struct MHD_AuthRqHeader *rq_auth;
1058#endif 1135#endif
1059 1136
1060
1061 /** 1137 /**
1062 * Close connection after sending response? 1138 * Close connection after sending response?
1063 * Functions may change value from "Unknown" or "KeepAlive" to "Must close", 1139 * Functions may change value from "Unknown" or "KeepAlive" to "Must close",
@@ -1079,23 +1155,6 @@ struct MHD_Connection
1079 char *write_buffer; 1155 char *write_buffer;
1080 1156
1081 /** 1157 /**
1082 * Last incomplete header line during parsing of headers.
1083 * Allocated in pool. Only valid if state is
1084 * either #MHD_CONNECTION_HEADER_PART_RECEIVED or
1085 * #MHD_CONNECTION_FOOTER_PART_RECEIVED.
1086 */
1087 char *last;
1088
1089 /**
1090 * Position after the colon on the last incomplete header
1091 * line during parsing of headers.
1092 * Allocated in pool. Only valid if state is
1093 * either #MHD_CONNECTION_HEADER_PART_RECEIVED or
1094 * #MHD_CONNECTION_FOOTER_PART_RECEIVED.
1095 */
1096 char *colon;
1097
1098 /**
1099 * Foreign address (of length @e addr_len). MALLOCED (not 1158 * Foreign address (of length @e addr_len). MALLOCED (not
1100 * in pool!). 1159 * in pool!).
1101 */ 1160 */
@@ -1139,18 +1198,6 @@ struct MHD_Connection
1139 size_t write_buffer_append_offset; 1198 size_t write_buffer_append_offset;
1140 1199
1141 /** 1200 /**
1142 * Number of bytes we had in the HTTP header, set once we
1143 * pass #MHD_CONNECTION_HEADERS_RECEIVED.
1144 */
1145 size_t header_size;
1146
1147 /**
1148 * How many more bytes of the body do we expect
1149 * to read? #MHD_SIZE_UNKNOWN for unknown.
1150 */
1151 uint64_t remaining_upload_size;
1152
1153 /**
1154 * Current write position in the actual response 1201 * Current write position in the actual response
1155 * (excluding headers, content only; should be 0 1202 * (excluding headers, content only; should be 0
1156 * while sending headers). 1203 * while sending headers).
@@ -1199,13 +1246,6 @@ struct MHD_Connection
1199 uint64_t connection_timeout_ms; 1246 uint64_t connection_timeout_ms;
1200 1247
1201 /** 1248 /**
1202 * Did we ever call the "default_handler" on this connection? (this
1203 * flag will determine if we call the #MHD_OPTION_NOTIFY_COMPLETED
1204 * handler when the connection closes down).
1205 */
1206 bool client_aware;
1207
1208 /**
1209 * Socket for this connection. Set to #MHD_INVALID_SOCKET if 1249 * Socket for this connection. Set to #MHD_INVALID_SOCKET if
1210 * this connection has died (daemon should clean 1250 * this connection has died (daemon should clean
1211 * up in that case). 1251 * up in that case).
@@ -1317,33 +1357,6 @@ struct MHD_Connection
1317 struct MHD_Reply_Properties rp_props; 1357 struct MHD_Reply_Properties rp_props;
1318 1358
1319 /** 1359 /**
1320 * Are we receiving with chunked encoding?
1321 * This will be set to #MHD_YES after we parse the headers and
1322 * are processing the body with chunks.
1323 * After we are done with the body and we are processing the footers;
1324 * once the footers are also done, this will be set to #MHD_NO again
1325 * (before the final call to the handler).
1326 * It is used only for requests, chunked encoding for response is
1327 * indicated by @a rp_props.
1328 */
1329 bool have_chunked_upload;
1330
1331 /**
1332 * If we are receiving with chunked encoding, where are we right
1333 * now?
1334 * Set to 0 if we are waiting to receive the chunk size;
1335 * otherwise, this is the size of the current chunk.
1336 * A value of zero is also used when we're at the end of the chunks.
1337 */
1338 uint64_t current_chunk_size;
1339
1340 /**
1341 * If we are receiving with chunked encoding, where are we currently
1342 * with respect to the current chunk (at what offset / position)?
1343 */
1344 uint64_t current_chunk_offset;
1345
1346 /**
1347 * Function used for reading HTTP request stream. 1360 * Function used for reading HTTP request stream.
1348 */ 1361 */
1349 ReceiveCallback recv_cls; 1362 ReceiveCallback recv_cls;