Fix compilation errors of the web interface

This commit is contained in:
2025-11-22 23:59:08 +01:00
parent 7b0b1acf61
commit d7a2262172
5 changed files with 88 additions and 15 deletions
+1 -1
View File
@@ -139,7 +139,7 @@ ToastyHandle toasty_begin_write(ToastyFS *toasty, ToastyString path,
// Associate the pointer "user" to the handle. The user
// pointer will be returned in the ToastyResult when the
// operation compltes.
void toasty_set_uesr(ToastyFS *toasty, ToastyHandle handle, void *user);
void toasty_set_user(ToastyFS *toasty, ToastyHandle handle, void *user);
typedef enum {
TOASTY_RESULT_EMPTY,
+1 -1
View File
@@ -769,7 +769,7 @@ void toasty_free_result(ToastyResult *result)
toasty_free_listing(&result->listing);
}
void toasty_set_uesr(ToastyFS *toasty, ToastyHandle handle, void *user)
void toasty_set_user(ToastyFS *toasty, ToastyHandle handle, void *user)
{
int opidx = handle_to_operation(toasty, handle);
if (opidx < 0)
+48
View File
@@ -4327,6 +4327,54 @@ void http_response_builder_body(HTTP_ResponseBuilder builder, HTTP_String str)
byte_queue_write(&conn->output, str.ptr, str.len);
}
void http_response_builder_body_cap(HTTP_ResponseBuilder builder, int cap)
{
HTTP_ServerConn *conn = builder_to_conn(builder);
if (conn == NULL)
return;
if (conn->state != HTTP_SERVER_CONN_WAIT_HEADER) {
append_special_headers(conn);
conn->state = HTTP_SERVER_CONN_WAIT_BODY;
}
if (conn->state != HTTP_SERVER_CONN_WAIT_BODY)
return;
byte_queue_write_setmincap(&conn->output, cap);
}
char *http_response_builder_body_buf(HTTP_ResponseBuilder builder, int *cap)
{
HTTP_ServerConn *conn = builder_to_conn(builder);
if (conn == NULL)
return NULL;
if (conn->state != HTTP_SERVER_CONN_WAIT_HEADER) {
append_special_headers(conn);
conn->state = HTTP_SERVER_CONN_WAIT_BODY;
}
if (conn->state != HTTP_SERVER_CONN_WAIT_BODY)
return NULL;
ByteView tmp = byte_queue_write_buf(&conn->output);
*cap = tmp.len;
return tmp.ptr;
}
void http_response_builder_body_ack(HTTP_ResponseBuilder builder, int num)
{
HTTP_ServerConn *conn = builder_to_conn(builder);
if (conn == NULL)
return;
if (conn->state != HTTP_SERVER_CONN_WAIT_BODY)
return;
byte_queue_write_ack(&conn->output, num);
}
void http_response_builder_send(HTTP_ResponseBuilder builder)
{
HTTP_ServerConn *conn = builder_to_conn(builder);
+5
View File
@@ -1142,6 +1142,11 @@ void http_response_builder_header(HTTP_ResponseBuilder builder, HTTP_String str)
// Append some bytes to the response's body
void http_response_builder_body(HTTP_ResponseBuilder builder, HTTP_String str);
// TODO: comment
void http_response_builder_body_cap(HTTP_ResponseBuilder builder, int cap);
char *http_response_builder_body_buf(HTTP_ResponseBuilder builder, int *cap);
void http_response_builder_body_ack(HTTP_ResponseBuilder builder, int num);
// Mark the response as complete. This will invalidate
// the response builder handle.
void http_response_builder_send(HTTP_ResponseBuilder builder);
+33 -13
View File
@@ -66,18 +66,24 @@ int main(void)
uint16_t local_port = 8080;
ToastyFS *toasty = toasty_connect(upstream_addr, upstream_port);
if (toasty == NULL)
if (toasty == NULL) {
printf("toasty_connect error\n");
return -1;
}
HTTP_Server server;
if (http_server_init(&server) < 0)
if (http_server_init(&server) < 0) {
printf("http_server_init error\n");
return -1;
}
http_server_set_reuse_addr(&server, true);
http_server_set_trace_bytes(&server, true);
if (http_server_listen_tcp(&server, local_addr, local_port) < 0)
if (http_server_listen_tcp(&server, local_addr, local_port) < 0) {
printf("http_server_listen_tcp error\n");
return -1;
}
int num_proxied = 0;
ProxiedOperation proxied[MAX_PROXIED_OPERATIONS];
@@ -94,13 +100,15 @@ int main(void)
struct pollfd *http_polled = polled;
reg = (EventRegister) {
ptrs,
polled,
POLL_CAPACITY,
0
.ptrs=ptrs,
.polled=polled,
.max_polled=POLL_CAPACITY,
.num_polled=0,
};
if (http_server_register_events(&server, &reg) < 0)
if (http_server_register_events(&server, &reg) < 0) {
printf("http_server_register_events error\n");
return -1;
}
int num_http_polled = reg.num_polled;
void **toasty_ptrs = ptrs + num_http_polled;
@@ -189,7 +197,7 @@ int main(void)
{
bool again = false;
if (result.type != TOASTY_RESULT_READ_SUCCESS) {
http_response_builder_bodyack(proxied[i].builder, 0);
http_response_builder_body_ack(proxied[i].builder, 0);
http_response_builder_status(proxied[i].builder, 500);
http_response_builder_send(proxied[i].builder);
} else {
@@ -199,7 +207,7 @@ int main(void)
// a bodyack).
proxied[i].transferred += result.bytes_read;
int ack = proxied[i].head_only ? 0 : result.bytes_read;
http_response_builder_bodyack(proxied[i].builder, ack);
http_response_builder_body_ack(proxied[i].builder, ack);
// If we didn't reach the end of the file, start
// a new read.
@@ -207,16 +215,20 @@ int main(void)
// Make sure there is some free space in the buffer
int mincap = 1<<10; // TODO: Choose based on overall file size
http_response_builder_bodycap(proxied[i].builder, mincap);
http_response_builder_body_cap(proxied[i].builder, mincap);
// Get the location of that buffer
int cap;
char *dst = http_response_builder_bodybuf(proxied[i].builder, &cap);
char *dst = http_response_builder_body_buf(proxied[i].builder, &cap);
if (dst == NULL) {
assert(0); // TODO
}
proxied[i].handle = toasty_begin_read(toasty, path, off, dst, cap);
ToastyString path = {
proxied[i].request->url.path.ptr,
proxied[i].request->url.path.len,
};
proxied[i].handle = toasty_begin_read(toasty, path, proxied[i].transferred, dst, cap);
if (proxied[i].handle == TOASTY_INVALID) {
assert(0); // TODO
}
@@ -277,6 +289,10 @@ int main(void)
break;
}
ToastyString path = {
request->url.path.ptr,
request->url.path.len,
};
ToastyHandle handle = toasty_begin_write(toasty, path, 0, request->body.ptr, request->body.len);
if (handle == TOASTY_INVALID) {
http_response_builder_status(builder, 500); // Internal Server Error
@@ -301,6 +317,10 @@ int main(void)
break;
}
ToastyString path = {
request->url.path.ptr,
request->url.path.len,
};
ToastyHandle handle = toasty_begin_delete(toasty, path);
if (handle == TOASTY_INVALID) {
http_response_builder_status(builder, 500); // Internal Server Error