diff options
author | Přemysl Janouch <p@janouch.name> | 2018-10-18 04:08:47 +0200 |
---|---|---|
committer | Přemysl Janouch <p@janouch.name> | 2018-10-18 04:08:47 +0200 |
commit | 3e4e4e5103b10e0cfada77489370e5a938a60f70 (patch) | |
tree | 8f129f5d3f2838a887ff1f261967d5e2bb2956ed | |
parent | 9494e8e2affcd08b791d3ecf68985a8a3a310e55 (diff) | |
download | liberty-3e4e4e5103b10e0cfada77489370e5a938a60f70.tar.gz liberty-3e4e4e5103b10e0cfada77489370e5a938a60f70.tar.xz liberty-3e4e4e5103b10e0cfada77489370e5a938a60f70.zip |
Allow aborting the FastCGI protocol parser
-rw-r--r-- | liberty-proto.c | 14 | ||||
-rw-r--r-- | liberty.c | 2 |
2 files changed, 9 insertions, 7 deletions
diff --git a/liberty-proto.c b/liberty-proto.c index 18e7912..fa6ab76 100644 --- a/liberty-proto.c +++ b/liberty-proto.c @@ -792,7 +792,8 @@ enum fcgi_protocol_status struct fcgi_parser; -typedef void (*fcgi_message_fn) +/// Message handler, returns false if further processing should be stopped +typedef bool (*fcgi_message_fn) (const struct fcgi_parser *parser, void *user_data); enum fcgi_parser_state @@ -854,7 +855,7 @@ fcgi_parser_unpack_header (struct fcgi_parser *self) str_remove_slice (&self->input, 0, unpacker.offset); } -static void +static bool fcgi_parser_push (struct fcgi_parser *self, const void *data, size_t len) { // This could be made considerably faster for high-throughput applications @@ -866,14 +867,14 @@ fcgi_parser_push (struct fcgi_parser *self, const void *data, size_t len) { case FCGI_READING_HEADER: if (self->input.len < FCGI_HEADER_LEN) - return; + return true; fcgi_parser_unpack_header (self); self->state = FCGI_READING_CONTENT; break; case FCGI_READING_CONTENT: if (self->input.len < self->content_length) - return; + return true; // Move an appropriate part of the input buffer to the content buffer str_reset (&self->content); @@ -883,10 +884,11 @@ fcgi_parser_push (struct fcgi_parser *self, const void *data, size_t len) break; case FCGI_READING_PADDING: if (self->input.len < self->padding_length) - return; + return true; // Call the callback to further process the message - self->on_message (self, self->user_data); + if (!self->on_message (self, self->user_data)) + return false; // Remove the padding from the input buffer str_remove_slice (&self->input, 0, self->padding_length); @@ -1093,7 +1093,7 @@ struct async LIST_HEADER (struct async) struct async_manager *manager; ///< Our manager object - // "cancelled" may not be accesed or modified by the worker thread + // "cancelled" may not be accessed or modified by the worker thread pthread_t worker; ///< Worker thread ID bool started; ///< Worker thread ID is valid |