Everywhere: Make session->verb() callable
This commit is contained in:
parent
69a4d6916f
commit
3728d56ea0
5 changed files with 54 additions and 15 deletions
|
@ -367,7 +367,7 @@ U0 @slon_admin_http_handle_post_request(SlonHttpSession* session)
|
|||
|
||||
U0 @slon_admin_http_handle_request(SlonHttpSession* session)
|
||||
{
|
||||
switch (@slon_http_request_verb(session)) {
|
||||
switch (session->verb()) {
|
||||
case SLON_HTTP_VERB_GET:
|
||||
@slon_admin_http_handle_get_request(session);
|
||||
break;
|
||||
|
|
|
@ -182,7 +182,7 @@ U0 @slon_local_http_handle_get_request(SlonHttpSession* session)
|
|||
|
||||
U0 @slon_local_http_handle_request(SlonHttpSession* session)
|
||||
{
|
||||
switch (@slon_http_request_verb(session)) {
|
||||
switch (session->verb()) {
|
||||
case SLON_HTTP_VERB_GET:
|
||||
@slon_local_http_handle_get_request(session);
|
||||
break;
|
||||
|
|
|
@ -43,6 +43,7 @@ U0 @slon_http_free_session(SlonHttpSession* session)
|
|||
@slon_http_free_response(session, session->response);
|
||||
@slon_http_free_request(session, session->request);
|
||||
I64 bytes_used = session->bytes_used - MSize2(session);
|
||||
Free(session->verb);
|
||||
Free(session->header);
|
||||
Free(session->status);
|
||||
Free(session->send);
|
||||
|
@ -124,6 +125,19 @@ SlonHttpSession* @slon_http_init_session(TcpSocket* s)
|
|||
a += 0x4c;
|
||||
@patch_call_rel32(a, &@slon_http_send);
|
||||
|
||||
// Create a copy of function and patch verb
|
||||
code_size = MSize(&@slon_session_verb_wrapper_function);
|
||||
session->verb = CAlloc(code_size, adam_task->code_heap);
|
||||
MemCpy(session->verb, &@slon_session_verb_wrapper_function, code_size);
|
||||
|
||||
a = session->verb;
|
||||
a += 0x11;
|
||||
MemSetI64(a, session, 1);
|
||||
|
||||
a = session->verb;
|
||||
a += 0x1b;
|
||||
@patch_call_rel32(a, &@slon_http_request_verb);
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
@ -527,7 +541,7 @@ U0 @slon_http_handle_request(SlonHttpSession* session)
|
|||
|
||||
// .purge_expired_idempotency_keys()
|
||||
@slon_http_authorize(session);
|
||||
switch (@slon_http_request_verb(session)) {
|
||||
switch (session->verb()) {
|
||||
case SLON_HTTP_VERB_DELETE:
|
||||
@slon_http_handle_delete_request(session);
|
||||
break;
|
||||
|
|
|
@ -195,7 +195,7 @@ Bool @slon_activitypub_http_signature_is_valid(SlonHttpSession* session)
|
|||
sig_string_alloc_length += StrLen(session->header(headers_split[i]));
|
||||
++i;
|
||||
}
|
||||
sig_string_alloc_length += StrLen(@slon_http_request_verb(session));
|
||||
sig_string_alloc_length += StrLen(session->verb(1));
|
||||
sig_string_alloc_length += StrLen(@slon_http_request_path(session));
|
||||
sig_string_alloc_length *= 2;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#define SLON_HTTP_VERB_OPTIONS 3
|
||||
#define SLON_HTTP_VERB_PATCH 4
|
||||
#define SLON_HTTP_VERB_POST 5
|
||||
#define SLON_HTTP_VERB_PUT 6
|
||||
|
||||
#define SLON_MULTIPART_PARSER_CONSUME_BOUNDARY 0
|
||||
#define SLON_MULTIPART_PARSER_CONSUME_CONTENT_DISPOSITION 1
|
||||
|
@ -66,6 +67,7 @@ class SlonHttpSession {
|
|||
U8* (*header)(U8* key, U8* value = NULL);
|
||||
U0 (*send)(U64 payload, I64 size = NULL);
|
||||
I64 (*status)(I64 code = NULL);
|
||||
I64 (*verb)(Bool return_str = FALSE);
|
||||
};
|
||||
|
||||
U64 @slon_calloc(SlonHttpSession* session, I64 size)
|
||||
|
@ -231,18 +233,35 @@ U8* @slon_http_request_path(SlonHttpSession* session)
|
|||
return session->request->path;
|
||||
}
|
||||
|
||||
I64 @slon_http_request_verb(SlonHttpSession* session)
|
||||
I64 @slon_http_request_verb(SlonHttpSession* session, Bool return_str = FALSE)
|
||||
{
|
||||
if (!StrCmp(session->request->verb, "DELETE"))
|
||||
return SLON_HTTP_VERB_DELETE;
|
||||
if (!StrCmp(session->request->verb, "GET"))
|
||||
return SLON_HTTP_VERB_GET;
|
||||
if (!StrCmp(session->request->verb, "OPTIONS"))
|
||||
return SLON_HTTP_VERB_OPTIONS;
|
||||
if (!StrCmp(session->request->verb, "PATCH"))
|
||||
return SLON_HTTP_VERB_PATCH;
|
||||
if (!StrCmp(session->request->verb, "POST"))
|
||||
return SLON_HTTP_VERB_POST;
|
||||
if (return_str) {
|
||||
if (!StrCmp(session->request->verb, "DELETE"))
|
||||
return "DELETE";
|
||||
if (!StrCmp(session->request->verb, "GET"))
|
||||
return "GET";
|
||||
if (!StrCmp(session->request->verb, "OPTIONS"))
|
||||
return "OPTIONS";
|
||||
if (!StrCmp(session->request->verb, "PATCH"))
|
||||
return "PATCH";
|
||||
if (!StrCmp(session->request->verb, "POST"))
|
||||
return "POST";
|
||||
if (!StrCmp(session->request->verb, "PUT"))
|
||||
return "PUT";
|
||||
} else {
|
||||
if (!StrCmp(session->request->verb, "DELETE"))
|
||||
return SLON_HTTP_VERB_DELETE;
|
||||
if (!StrCmp(session->request->verb, "GET"))
|
||||
return SLON_HTTP_VERB_GET;
|
||||
if (!StrCmp(session->request->verb, "OPTIONS"))
|
||||
return SLON_HTTP_VERB_OPTIONS;
|
||||
if (!StrCmp(session->request->verb, "PATCH"))
|
||||
return SLON_HTTP_VERB_PATCH;
|
||||
if (!StrCmp(session->request->verb, "POST"))
|
||||
return SLON_HTTP_VERB_POST;
|
||||
if (!StrCmp(session->request->verb, "PUT"))
|
||||
return SLON_HTTP_VERB_PUT;
|
||||
}
|
||||
return 999;
|
||||
}
|
||||
|
||||
|
@ -296,3 +315,9 @@ U0 @slon_session_send_wrapper_function(U64 payload, I64 size = NULL)
|
|||
@slon_http_send(session, payload, size);
|
||||
}
|
||||
}
|
||||
|
||||
I64 @slon_session_verb_wrapper_function(Bool return_str = FALSE)
|
||||
{
|
||||
SlonHttpSession* session = SLON_WRAPPER_MAGIC_NUMBER;
|
||||
return @slon_http_request_verb(session, return_str);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue