http-server-private.h revision 3cda61e4ccaa1192528776d315f7ed5534315cb0
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef HTTP_SERVER_PRIVATE_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define HTTP_SERVER_PRIVATE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen#include "connection.h"
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen#include "iostream-pump.h"
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen#include "http-server.h"
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen#include "llist.h"
aef92409cf369afdd2ecd81a4f80083cd4082f46Timo Sirainen
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainenstruct http_server_payload_handler;
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainenstruct http_server_request;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct http_server_connection;
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen/*
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen * Defaults
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#define HTTP_SERVER_REQUEST_MAX_TARGET_LENGTH 4096
0add8c99ca65e56dbf613595fc37c41aafff3f7fTimo Sirainen
40ef82c46f6652412b068ebcdac7c3e74840a284Timo Sirainen/*
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen * Types
49d4afbb76f47c8904537d087bc81e43f1c0aa25Timo Sirainen */
aef92409cf369afdd2ecd81a4f80083cd4082f46Timo Sirainen
aef92409cf369afdd2ecd81a4f80083cd4082f46Timo Sirainenenum http_server_request_state {
aef92409cf369afdd2ecd81a4f80083cd4082f46Timo Sirainen /* New request; request header is still being parsed. */
b44faf865da16ac4d18eecd85a55b3fab6b9e63aTimo Sirainen HTTP_SERVER_REQUEST_STATE_NEW = 0,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Queued request; callback to request handler executing. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen HTTP_SERVER_REQUEST_STATE_QUEUED,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Reading request payload; request handler still needs to read more
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen payload. */
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen HTTP_SERVER_REQUEST_STATE_PAYLOAD_IN,
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen /* This request is being processed; request payload is fully read, but no
56f45b3f3ae20e5c933701f4657dda5ef1916855Timo Sirainen response is yet submitted */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen HTTP_SERVER_REQUEST_STATE_PROCESSING,
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen /* A response is submitted for this request. If not all request payload
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen was read by the handler, it is first skipped on the input.
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen HTTP_SERVER_REQUEST_STATE_SUBMITTED_RESPONSE,
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen /* Request is ready for response; a response is submitted and the request
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainen payload is fully read */
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen HTTP_SERVER_REQUEST_STATE_READY_TO_RESPOND,
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen /* The response for the request is sent (apart from payload) */
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen HTTP_SERVER_REQUEST_STATE_SENT_RESPONSE,
651fc0f1e43fef3e02e0e7b5f498973b05f641d7Timo Sirainen /* Sending response payload to client */
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen HTTP_SERVER_REQUEST_STATE_PAYLOAD_OUT,
e188bab0b830136d04a1dd8b55e9afefae20d930Timo Sirainen /* Request is finished; still lingering due to references */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen HTTP_SERVER_REQUEST_STATE_FINISHED,
5a3f143585110536a7f72628e66a42b998bfc5fcTimo Sirainen /* Request is aborted; still lingering due to references */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen HTTP_SERVER_REQUEST_STATE_ABORTED
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen};
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen
041d312b44f8d41f0c9a5762c23e4d146ef7302bTimo Sirainen/*
041d312b44f8d41f0c9a5762c23e4d146ef7302bTimo Sirainen * Objects
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct http_server_payload_handler {
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen struct http_server_request *req;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen void (*switch_ioloop)(struct http_server_payload_handler *handler);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen void (*destroy)(struct http_server_payload_handler *handler);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen bool in_callback:1;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct http_server_response {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct http_server_request *request;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int status;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *reason;
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen string_t *headers;
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen time_t date;
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen ARRAY_TYPE(http_auth_challenge) auth_challenges;
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen struct istream *payload_input;
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen uoff_t payload_size, payload_offset;
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen struct ostream *payload_output;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
659fe5d24825b160cae512538088020d97a60239Timo Sirainen struct ostream *blocking_output;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen http_server_tunnel_callback_t tunnel_callback;
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen void *tunnel_context;
de62ce819d59a529530da4b57be1b8d6dad13d6bTimo Sirainen
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen bool have_hdr_connection:1;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen bool have_hdr_date:1;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen bool have_hdr_body_spec:1;
659fe5d24825b160cae512538088020d97a60239Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen bool payload_chunked:1;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen bool payload_blocking:1;
232d5bef3c709e90e24f0874a36854b92187bb6cTimo Sirainen bool payload_direct:1;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen bool payload_corked:1;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen bool submitted:1;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen};
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenstruct http_server_request {
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen struct http_request req;
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen pool_t pool;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen unsigned int refcount;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen unsigned int id;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int callback_refcount;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen enum http_server_request_state state;
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen struct http_server_request *prev, *next;
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen struct http_server *server;
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen struct http_server_connection *conn;
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen
a928e7efabb1672b1476e597106d4b4b81ac6f3cTimo Sirainen struct istream *payload_input;
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen struct http_server_response *response;
838f56174b963779a88083a0d0e85b30d2d846e7Timo Sirainen
894987bf45718f8849cc3898afdfb1ac3cfa2445Timo Sirainen void (*destroy_callback)(void *);
894987bf45718f8849cc3898afdfb1ac3cfa2445Timo Sirainen void *destroy_context;
894987bf45718f8849cc3898afdfb1ac3cfa2445Timo Sirainen
838f56174b963779a88083a0d0e85b30d2d846e7Timo Sirainen bool payload_halted:1;
838f56174b963779a88083a0d0e85b30d2d846e7Timo Sirainen bool sent_100_continue:1;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen bool delay_destroy:1;
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen bool destroy_pending:1;
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen bool failed:1;
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen bool connection_close:1;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen};
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainenstruct http_server_connection {
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen struct connection conn;
838f56174b963779a88083a0d0e85b30d2d846e7Timo Sirainen struct http_server *server;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen unsigned int refcount;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen const struct http_server_callbacks *callbacks;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen void *context;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen unsigned int id; // DEBUG
6e07b4251bf6a3cf34019c351a32a65c08392e58Timo Sirainen
6e07b4251bf6a3cf34019c351a32a65c08392e58Timo Sirainen struct timeout *to_input, *to_idle;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen struct ssl_iostream *ssl_iostream;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen struct http_request_parser *http_parser;
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen struct http_server_request *request_queue_head, *request_queue_tail;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen unsigned int request_queue_count;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen struct istream *incoming_payload;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen struct http_server_payload_handler *payload_handler;
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen struct io *io_resp_payload;
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen char *disconnect_reason;
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen struct http_server_stats stats;
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen bool ssl:1;
5a07b37a9df398b5189c14872a600384208ab74bTimo Sirainen bool closed:1;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen bool close_indicated:1;
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen bool input_broken:1;
a928e7efabb1672b1476e597106d4b4b81ac6f3cTimo Sirainen bool output_locked:1;
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen bool in_req_callback:1; /* performing request callback (busy) */
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainen bool switching_ioloop:1; /* in the middle of switching ioloop */
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainen};
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainen
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainenstruct http_server {
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainen pool_t pool;
e188bab0b830136d04a1dd8b55e9afefae20d930Timo Sirainen
e188bab0b830136d04a1dd8b55e9afefae20d930Timo Sirainen struct http_server_settings set;
e188bab0b830136d04a1dd8b55e9afefae20d930Timo Sirainen
e188bab0b830136d04a1dd8b55e9afefae20d930Timo Sirainen struct ioloop *ioloop;
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen struct ssl_iostream_context *ssl_ctx;
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen struct connection_list *conn_list;
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen bool shutting_down:1; /* shutting down server */
77bc2bda5b781c4ffddc8a74b175cf32e9e2c2ecTimo Sirainen};
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen/*
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen * Response
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen */
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainen
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainenvoid http_server_response_free(struct http_server_response *resp);
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainenint http_server_response_send(struct http_server_response *resp);
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainenint http_server_response_send_more(struct http_server_response *resp);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/*
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen * Request
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstatic inline const char *
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenhttp_server_request_label(struct http_server_request *req)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen{
94aa90d2d17a7aebcda5a4193a62e80ddbb169b7Timo Sirainen if (req->req.method == NULL) {
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen if (req->req.target_raw == NULL)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return t_strdup_printf("[Req%u: <NEW>]", req->id);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return t_strdup_printf("[Req%u: %s <INCOMPLETE>]",
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen req->id, req->req.method);
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen }
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen return t_strdup_printf("[Req%u: %s %s]", req->id,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen req->req.method, req->req.target_raw);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen}
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstatic inline bool
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenhttp_server_request_is_new(struct http_server_request *req)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen{
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return (req->state == HTTP_SERVER_REQUEST_STATE_NEW);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen}
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstatic inline bool
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenhttp_server_request_version_equals(struct http_server_request *req,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen unsigned int major, unsigned int minor) {
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen return (req->req.version_major == major && req->req.version_minor == minor);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen}
0d0451206a91e9f96e522075dce28a89adc2325dTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct http_server_request *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenhttp_server_request_new(struct http_server_connection *conn);
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainenvoid http_server_request_destroy(struct http_server_request **_req);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid http_server_request_abort(struct http_server_request **_req,
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen const char *reason) ATTR_NULL(2);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenbool http_server_request_is_complete(struct http_server_request *req);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenvoid http_server_request_halt_payload(struct http_server_request *req);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainenvoid http_server_request_continue_payload(struct http_server_request *req);
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen
096953143c4032bad154637f687551856f7946cbTimo Sirainenvoid http_server_request_submit_response(struct http_server_request *req);
096953143c4032bad154637f687551856f7946cbTimo Sirainen
c680a6b35b459045e92814778908da5a93922107Timo Sirainenvoid http_server_request_ready_to_respond(struct http_server_request *req);
c680a6b35b459045e92814778908da5a93922107Timo Sirainenvoid http_server_request_finished(struct http_server_request *req);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* payload handler */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid http_server_payload_handler_destroy(
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct http_server_payload_handler **_handler);
5f78b33aa505b17e23cdf27b071a24e127b3db54Timo Sirainenvoid http_server_payload_handler_switch_ioloop(
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen struct http_server_payload_handler *handler);
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen/*
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen * connection
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic inline const char *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenhttp_server_connection_label(struct http_server_connection *conn)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen{
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return conn->conn.name;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen}
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenstatic inline void
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainenhttp_server_connection_add_request(struct http_server_connection *conn,
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen struct http_server_request *sreq)
c9c24293550541307f1bb41bba4a0fdfe2fa59e0Timo Sirainen{
c9c24293550541307f1bb41bba4a0fdfe2fa59e0Timo Sirainen DLLIST2_APPEND(&conn->request_queue_head, &conn->request_queue_tail, sreq);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen conn->request_queue_count++;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen}
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic inline void
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenhttp_server_connection_remove_request(struct http_server_connection *conn,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct http_server_request *sreq)
43d32cbe60fdaef2699d99f1ca259053e9350411Timo Sirainen{
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen DLLIST2_REMOVE(&conn->request_queue_head, &conn->request_queue_tail, sreq);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen conn->request_queue_count--;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen}
40a5aeebf6b4858b93f0ddff0bf12fba769cf903Timo Sirainen
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainenstruct connection_list *http_server_connection_list_init(void);
77bc2bda5b781c4ffddc8a74b175cf32e9e2c2ecTimo Sirainen
77bc2bda5b781c4ffddc8a74b175cf32e9e2c2ecTimo Sirainenbool http_server_connection_shut_down(struct http_server_connection *conn);
40a5aeebf6b4858b93f0ddff0bf12fba769cf903Timo Sirainen
1279090ba03f9c176976a69ab7718f0ed77b19afTimo Sirainenvoid http_server_connection_switch_ioloop(struct http_server_connection *conn);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid http_server_connection_handle_output_error(
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct http_server_connection *conn);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid http_server_connection_trigger_responses(
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct http_server_connection *conn);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint http_server_connection_flush(struct http_server_connection *conn);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint http_server_connection_output(struct http_server_connection *conn);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
3ee5f5427b36ea30a01561b35f4002232db7b061Timo Sirainenvoid http_server_connection_tunnel(struct http_server_connection **_conn,
3ee5f5427b36ea30a01561b35f4002232db7b061Timo Sirainen http_server_tunnel_callback_t callback, void *context);
3ee5f5427b36ea30a01561b35f4002232db7b061Timo Sirainen
a050ca9def13949dbaa67bd6574a41c4f397ae26Timo Sirainenint http_server_connection_discard_payload(
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen struct http_server_connection *conn);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool http_server_connection_pending_payload(
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct http_server_connection *conn);
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen#endif
902222fb0928d1701f20a384b73f327b1d9a15ddTimo Sirainen