Everywhere: Make session->path(), session->path_count() callable
This commit is contained in:
parent
3728d56ea0
commit
545d408512
6 changed files with 97 additions and 90 deletions
|
@ -250,11 +250,8 @@ Bool @slon_activitypub_http_signature_is_valid(SlonHttpSession* session)
|
|||
|
||||
U0 @slon_activitypub_users_get(SlonHttpSession* session)
|
||||
{
|
||||
U8* path = @slon_strnew(session, @slon_http_request_path(session));
|
||||
I64 path_segments_count = 0;
|
||||
U8** path_segments = String.Split(path, '/', &path_segments_count);
|
||||
if (path_segments_count == 3) {
|
||||
JsonObject* actor = db->o("actors")->@(path_segments[1]);
|
||||
if (session->path_count() == 3) {
|
||||
JsonObject* actor = db->o("actors")->@(session->path(1));
|
||||
if (actor) {
|
||||
@slon_http_send_ap_json(session, actor);
|
||||
} else {
|
||||
|
@ -263,8 +260,6 @@ U0 @slon_activitypub_users_get(SlonHttpSession* session)
|
|||
} else {
|
||||
session->status(400);
|
||||
}
|
||||
slon_activitypub_users_get_return:
|
||||
@slon_free(session, path);
|
||||
}
|
||||
|
||||
U0 @slon_activitypub_async_accept_request(JsonObject* o)
|
||||
|
@ -958,23 +953,19 @@ U0 @slon_activitypub_users_post(SlonHttpSession* session)
|
|||
SLON_SCRATCH_BUFFER_AND_REQUEST_JSON
|
||||
no_warn scratch_buffer;
|
||||
|
||||
U8* path = @slon_strnew(session, @slon_http_request_path(session));
|
||||
I64 path_segments_count = 0;
|
||||
U8** path_segments = String.Split(path, '/', &path_segments_count);
|
||||
|
||||
if (path_segments_count < 3) {
|
||||
if (session->path_count() < 3) {
|
||||
session->status(400);
|
||||
goto slon_activitypub_users_post_return;
|
||||
}
|
||||
|
||||
U8* user = path_segments[1];
|
||||
U8* user = session->path(1);
|
||||
JsonObject* actor = db->o("actors")->@(user);
|
||||
if (!actor) {
|
||||
session->status(404);
|
||||
goto slon_activitypub_users_post_return;
|
||||
}
|
||||
|
||||
U8* method = path_segments[2];
|
||||
U8* method = session->path(2);
|
||||
if (!StrICmp("inbox", method)) {
|
||||
if (!request_json) {
|
||||
session->status(400);
|
||||
|
@ -1002,6 +993,4 @@ slon_activitypub_users_post_return:
|
|||
if (session->actor_for_key_id) {
|
||||
@slon_free(session, session->actor_for_key_id);
|
||||
}
|
||||
Free(path_segments);
|
||||
@slon_free(session, path);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,9 @@ class SlonHttpRequest {
|
|||
U8* verb;
|
||||
U8* raw_path;
|
||||
U8* path;
|
||||
I64 path_segments_count;
|
||||
U8* path_segments_src;
|
||||
U8** path_segments;
|
||||
Bool headers_have_been_parsed;
|
||||
};
|
||||
|
||||
|
@ -66,6 +69,8 @@ class SlonHttpSession {
|
|||
|
||||
U8* (*header)(U8* key, U8* value = NULL);
|
||||
U0 (*send)(U64 payload, I64 size = NULL);
|
||||
U8* (*path)(I64 segment = NULL);
|
||||
I64 (*path_count)();
|
||||
I64 (*status)(I64 code = NULL);
|
||||
I64 (*verb)(Bool return_str = FALSE);
|
||||
};
|
||||
|
@ -228,9 +233,16 @@ U0 @slon_http_send_json_file(SlonHttpSession* session, U8* path, U8* content_typ
|
|||
@slon_http_send_file(session, path);
|
||||
}
|
||||
|
||||
U8* @slon_http_request_path(SlonHttpSession* session)
|
||||
U8* @slon_http_request_path(SlonHttpSession* session, I64 segment = NULL)
|
||||
{
|
||||
return session->request->path;
|
||||
if (segment) {
|
||||
if (!session->request->path_segments_count || segment >= session->request->path_segments_count) {
|
||||
return NULL;
|
||||
}
|
||||
return session->request->path_segments[segment];
|
||||
} else {
|
||||
return session->request->path;
|
||||
}
|
||||
}
|
||||
|
||||
I64 @slon_http_request_verb(SlonHttpSession* session, Bool return_str = FALSE)
|
||||
|
@ -321,3 +333,15 @@ I64 @slon_session_verb_wrapper_function(Bool return_str = FALSE)
|
|||
SlonHttpSession* session = SLON_WRAPPER_MAGIC_NUMBER;
|
||||
return @slon_http_request_verb(session, return_str);
|
||||
}
|
||||
|
||||
U8* @slon_session_path_wrapper_function(I64 segment = NULL)
|
||||
{
|
||||
SlonHttpSession* session = SLON_WRAPPER_MAGIC_NUMBER;
|
||||
return @slon_http_request_path(session, segment);
|
||||
}
|
||||
|
||||
I64 @slon_session_path_count_wrapper_function()
|
||||
{
|
||||
SlonHttpSession* session = SLON_WRAPPER_MAGIC_NUMBER;
|
||||
return session->request->path_segments_count;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue