http-server-private.h revision 3cda61e4ccaa1192528776d315f7ed5534315cb0
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen#define HTTP_SERVER_REQUEST_MAX_TARGET_LENGTH 4096
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* New request; request header is still being parsed. */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Queued request; callback to request handler executing. */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Reading request payload; request handler still needs to read more
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* This request is being processed; request payload is fully read, but no
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen response is yet submitted */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* A response is submitted for this request. If not all request payload
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen was read by the handler, it is first skipped on the input.
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Request is ready for response; a response is submitted and the request
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen payload is fully read */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* The response for the request is sent (apart from payload) */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Sending response payload to client */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Request is finished; still lingering due to references */
4ae81f8f7aad06aad2f570535cad6e40aaec2b28Timo Sirainen /* Request is aborted; still lingering due to references */
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen void (*switch_ioloop)(struct http_server_payload_handler *handler);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen void (*destroy)(struct http_server_payload_handler *handler);
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen unsigned int status;
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen ARRAY_TYPE(http_auth_challenge) auth_challenges;
ac383c437b1ccb9420cae6b4c4b03af3c8019e02Timo Sirainen http_server_tunnel_callback_t tunnel_callback;
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen unsigned int id;
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen void (*destroy_callback)(void *);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen const struct http_server_callbacks *callbacks;
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct http_server_request *request_queue_head, *request_queue_tail;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen struct http_server_payload_handler *payload_handler;
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainen bool in_req_callback:1; /* performing request callback (busy) */
fcde781c3ceb470c8dff34a68df19c69f93bcec9Timo Sirainen bool switching_ioloop:1; /* in the middle of switching ioloop */
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainen bool shutting_down:1; /* shutting down server */
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainenvoid http_server_response_free(struct http_server_response *resp);
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainenint http_server_response_send(struct http_server_response *resp);
1caf757864e7734345660e7d190f84e42668a6f8Timo Sirainenint http_server_response_send_more(struct http_server_response *resp);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstatic inline const char *
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenhttp_server_request_label(struct http_server_request *req)
43d32cbe60fdaef2699d99f1ca259053e9350411Timo Sirainen return t_strdup_printf("[Req%u: <NEW>]", req->id);
43d32cbe60fdaef2699d99f1ca259053e9350411Timo Sirainen return t_strdup_printf("[Req%u: %s <INCOMPLETE>]",
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen return t_strdup_printf("[Req%u: %s %s]", req->id,
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstatic inline bool
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenhttp_server_request_is_new(struct http_server_request *req)
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen return (req->state == HTTP_SERVER_REQUEST_STATE_NEW);
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenstatic inline bool
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenhttp_server_request_version_equals(struct http_server_request *req,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen return (req->req.version_major == major && req->req.version_minor == minor);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenhttp_server_request_new(struct http_server_connection *conn);
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenvoid http_server_request_destroy(struct http_server_request **_req);
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenvoid http_server_request_abort(struct http_server_request **_req,
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenbool http_server_request_is_complete(struct http_server_request *req);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_request_halt_payload(struct http_server_request *req);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_request_continue_payload(struct http_server_request *req);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenvoid http_server_request_submit_response(struct http_server_request *req);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_request_ready_to_respond(struct http_server_request *req);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenvoid http_server_request_finished(struct http_server_request *req);
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen/* payload handler */
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainen struct http_server_payload_handler **_handler);
1b0cfbf3cc77a670b92fff5c30f7b1eb17a63ab1Timo Sirainenvoid http_server_payload_handler_switch_ioloop(
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstatic inline const char *
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenhttp_server_connection_label(struct http_server_connection *conn)
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenstatic inline void
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainenhttp_server_connection_add_request(struct http_server_connection *conn,
74ab5ea66c0c4b388f1c774ae6a47ab94f1b4f18Timo Sirainen DLLIST2_APPEND(&conn->request_queue_head, &conn->request_queue_tail, sreq);
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenstatic inline void
e62f6437a4ff01d692a5a61369fe4168d69191edTimo Sirainenhttp_server_connection_remove_request(struct http_server_connection *conn,