Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ffi to llhttp 5.1.0 #14

Merged
merged 1 commit into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions ffi/ext/llhttp/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,70 @@ void llhttp_init(llhttp_t* parser, llhttp_type_t type,
}


#if defined(__wasm__)

extern int wasm_on_message_begin(llhttp_t * p);
extern int wasm_on_url(llhttp_t* p, const char* at, size_t length);
extern int wasm_on_status(llhttp_t* p, const char* at, size_t length);
extern int wasm_on_header_field(llhttp_t* p, const char* at, size_t length);
extern int wasm_on_header_value(llhttp_t* p, const char* at, size_t length);
extern int wasm_on_headers_complete(llhttp_t * p);
extern int wasm_on_body(llhttp_t* p, const char* at, size_t length);
extern int wasm_on_message_complete(llhttp_t * p);

const llhttp_settings_t wasm_settings = {
wasm_on_message_begin,
wasm_on_url,
wasm_on_status,
wasm_on_header_field,
wasm_on_header_value,
wasm_on_headers_complete,
wasm_on_body,
wasm_on_message_complete,
NULL,
NULL,
};


llhttp_t* llhttp_alloc(llhttp_type_t type) {
llhttp_t* parser = malloc(sizeof(llhttp_t));
llhttp_init(parser, type, &wasm_settings);
return parser;
}

void llhttp_free(llhttp_t* parser) {
free(parser);
}

/* Some getters required to get stuff from the parser */

uint8_t llhttp_get_type(llhttp_t* parser) {
return parser->type;
}

uint8_t llhttp_get_http_major(llhttp_t* parser) {
return parser->http_major;
}

uint8_t llhttp_get_http_minor(llhttp_t* parser) {
return parser->http_minor;
}

uint8_t llhttp_get_method(llhttp_t* parser) {
return parser->method;
}

int llhttp_get_status_code(llhttp_t* parser) {
return parser->status_code;
}

uint8_t llhttp_get_upgrade(llhttp_t* parser) {
return parser->upgrade;
}

#endif // defined(__wasm__)


void llhttp_reset(llhttp_t* parser) {
llhttp_type_t type = parser->type;
const llhttp_settings_t* settings = parser->settings;
Expand Down Expand Up @@ -173,6 +237,7 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
}
}


void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
if (enabled) {
parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
Expand All @@ -182,6 +247,14 @@ void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
}


void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled) {
if (enabled) {
parser->lenient_flags |= LENIENT_KEEP_ALIVE;
} else {
parser->lenient_flags &= ~LENIENT_KEEP_ALIVE;
}
}

/* Callbacks */


Expand Down
103 changes: 79 additions & 24 deletions ffi/ext/llhttp/llhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,21 @@ int llhttp__internal__c_update_finish_1(
return 0;
}

int llhttp__internal__c_test_lenient_flags(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
return (state->lenient_flags & 4) == 4;
}

int llhttp__internal__c_test_flags_1(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
return (state->flags & 544) == 544;
}

int llhttp__internal__c_test_lenient_flags(
int llhttp__internal__c_test_lenient_flags_1(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
Expand Down Expand Up @@ -825,7 +832,7 @@ int llhttp__internal__c_update_header_state_2(
return 0;
}

int llhttp__internal__c_test_lenient_flags_1(
int llhttp__internal__c_test_lenient_flags_2(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
Expand Down Expand Up @@ -1684,7 +1691,7 @@ static llparse_state_t llhttp__internal__run(
goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2;
}
default: {
goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
goto s_n_llhttp__internal__n_invoke_test_lenient_flags_2;
}
}
/* UNREACHABLE */;
Expand Down Expand Up @@ -5756,10 +5763,20 @@ static llparse_state_t llhttp__internal__run(
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_test_lenient_flags: {
switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
case 1:
goto s_n_llhttp__internal__n_invoke_update_finish_2;
default:
goto s_n_llhttp__internal__n_closed;
}
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_update_finish_1: {
switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
default:
goto s_n_llhttp__internal__n_closed;
goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
}
/* UNREACHABLE */;
abort();
Expand Down Expand Up @@ -6121,8 +6138,8 @@ static llparse_state_t llhttp__internal__run(
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_test_lenient_flags: {
switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
case 0:
goto s_n_llhttp__internal__n_error_15;
default:
Expand All @@ -6134,7 +6151,7 @@ static llparse_state_t llhttp__internal__run(
s_n_llhttp__internal__n_invoke_test_flags_1: {
switch (llhttp__internal__c_test_flags_1(state, p, endp)) {
case 1:
goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
default:
goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete;
}
Expand Down Expand Up @@ -6388,8 +6405,8 @@ static llparse_state_t llhttp__internal__run(
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
s_n_llhttp__internal__n_invoke_test_lenient_flags_2: {
switch (llhttp__internal__c_test_lenient_flags_2(state, p, endp)) {
case 1:
goto s_n_llhttp__internal__n_header_value_lenient;
default:
Expand Down Expand Up @@ -6750,7 +6767,7 @@ static llparse_state_t llhttp__internal__run(
abort();
}
s_n_llhttp__internal__n_error_29: {
state->error = 0x16;
state->error = 0x17;
state->reason = "Pause on PRI/Upgrade";
state->error_pos = (const char*) p;
state->_current = (void*) (intptr_t) s_error;
Expand Down Expand Up @@ -7929,6 +7946,7 @@ static llparse_match_t llparse__match_sequence_id(

enum llparse_state_e {
s_error,
s_n_llhttp__internal__n_closed,
s_n_llhttp__internal__n_invoke_llhttp__after_message_complete,
s_n_llhttp__internal__n_pause_1,
s_n_llhttp__internal__n_invoke_is_equal_upgrade,
Expand Down Expand Up @@ -8222,14 +8240,21 @@ int llhttp__internal__c_update_finish_1(
return 0;
}

int llhttp__internal__c_test_lenient_flags(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
return (state->lenient_flags & 4) == 4;
}

int llhttp__internal__c_test_flags_1(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
return (state->flags & 544) == 544;
}

int llhttp__internal__c_test_lenient_flags(
int llhttp__internal__c_test_lenient_flags_1(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
Expand Down Expand Up @@ -8301,7 +8326,7 @@ int llhttp__internal__c_or_flags(
return 0;
}

int llhttp__internal__c_update_finish_2(
int llhttp__internal__c_update_finish_3(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
Expand Down Expand Up @@ -8397,7 +8422,7 @@ int llhttp__internal__c_update_header_state_2(
return 0;
}

int llhttp__internal__c_test_lenient_flags_1(
int llhttp__internal__c_test_lenient_flags_2(
llhttp__internal_t* state,
const unsigned char* p,
const unsigned char* endp) {
Expand Down Expand Up @@ -8597,9 +8622,21 @@ static llparse_state_t llhttp__internal__run(
const unsigned char* endp) {
int match;
switch ((llparse_state_t) (intptr_t) state->_current) {
case s_n_llhttp__internal__n_closed:
s_n_llhttp__internal__n_closed: {
if (p == endp) {
return s_n_llhttp__internal__n_closed;
}
p++;
goto s_n_llhttp__internal__n_closed;
/* UNREACHABLE */;
abort();
}
case s_n_llhttp__internal__n_invoke_llhttp__after_message_complete:
s_n_llhttp__internal__n_invoke_llhttp__after_message_complete: {
switch (llhttp__after_message_complete(state, p, endp)) {
case 1:
goto s_n_llhttp__internal__n_invoke_update_finish_2;
default:
goto s_n_llhttp__internal__n_invoke_update_finish_1;
}
Expand Down Expand Up @@ -9068,7 +9105,7 @@ static llparse_state_t llhttp__internal__run(
case 3:
goto s_n_llhttp__internal__n_span_start_llhttp__on_body_1;
case 4:
goto s_n_llhttp__internal__n_invoke_update_finish_2;
goto s_n_llhttp__internal__n_invoke_update_finish_3;
case 5:
goto s_n_llhttp__internal__n_error_10;
default:
Expand Down Expand Up @@ -9207,7 +9244,7 @@ static llparse_state_t llhttp__internal__run(
goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2;
}
default: {
goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
goto s_n_llhttp__internal__n_invoke_test_lenient_flags_2;
}
}
/* UNREACHABLE */;
Expand Down Expand Up @@ -13100,14 +13137,32 @@ static llparse_state_t llhttp__internal__run(
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_update_finish_1: {
s_n_llhttp__internal__n_invoke_update_finish_2: {
switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
default:
goto s_n_llhttp__internal__n_start;
}
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_test_lenient_flags: {
switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
case 1:
goto s_n_llhttp__internal__n_invoke_update_finish_2;
default:
goto s_n_llhttp__internal__n_closed;
}
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_update_finish_1: {
switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
default:
goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
}
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_pause_5: {
state->error = 0x15;
state->reason = "on_message_complete pause";
Expand Down Expand Up @@ -13334,8 +13389,8 @@ static llparse_state_t llhttp__internal__run(
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_update_finish_2: {
switch (llhttp__internal__c_update_finish_2(state, p, endp)) {
s_n_llhttp__internal__n_invoke_update_finish_3: {
switch (llhttp__internal__c_update_finish_3(state, p, endp)) {
default:
goto s_n_llhttp__internal__n_span_start_llhttp__on_body_2;
}
Expand Down Expand Up @@ -13447,8 +13502,8 @@ static llparse_state_t llhttp__internal__run(
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_test_lenient_flags: {
switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
case 0:
goto s_n_llhttp__internal__n_error_11;
default:
Expand All @@ -13460,7 +13515,7 @@ static llparse_state_t llhttp__internal__run(
s_n_llhttp__internal__n_invoke_test_flags_1: {
switch (llhttp__internal__c_test_flags_1(state, p, endp)) {
case 1:
goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
default:
goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete;
}
Expand Down Expand Up @@ -13696,8 +13751,8 @@ static llparse_state_t llhttp__internal__run(
/* UNREACHABLE */;
abort();
}
s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
s_n_llhttp__internal__n_invoke_test_lenient_flags_2: {
switch (llhttp__internal__c_test_lenient_flags_2(state, p, endp)) {
case 1:
goto s_n_llhttp__internal__n_header_value_lenient;
default:
Expand Down Expand Up @@ -14058,7 +14113,7 @@ static llparse_state_t llhttp__internal__run(
abort();
}
s_n_llhttp__internal__n_error_23: {
state->error = 0x16;
state->error = 0x17;
state->reason = "Pause on PRI/Upgrade";
state->error_pos = (const char*) p;
state->_current = (void*) (intptr_t) s_error;
Expand Down
Loading