feat(lnm): start of processing code
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
4c2b85d436
commit
e04f6e170e
5 changed files with 87 additions and 6 deletions
0
lnm/src/http/loop_ctx.c
Normal file
0
lnm/src/http/loop_ctx.c
Normal file
60
lnm/src/http/loop_process.c
Normal file
60
lnm/src/http/loop_process.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include "lnm/http/loop.h"
|
||||
#include "lnm/http/loop_internal.h"
|
||||
#include "lnm/http/req.h"
|
||||
#include "lnm/loop.h"
|
||||
#include "lnm/loop_internal.h"
|
||||
|
||||
void lnm_http_loop_process_parse_req(lnm_http_conn *conn) {
|
||||
lnm_http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
lnm_http_parse_err res = lnm_http_req_parse(
|
||||
&ctx->req, &conn->r.buf[conn->r.read], conn->r.size - conn->r.read);
|
||||
|
||||
switch (res) {
|
||||
case lnm_http_parse_err_ok:
|
||||
ctx->state = lnm_http_loop_state_steps;
|
||||
break;
|
||||
case lnm_http_parse_err_incomplete:
|
||||
// If the request is already the size of the read buffer, we close the
|
||||
// request. Otherwise, we wait for anything read
|
||||
if (conn->r.size - conn->r.read == LNM_LOOP_BUF_SIZE) {
|
||||
conn->state = lnm_loop_state_end;
|
||||
}
|
||||
break;
|
||||
case lnm_http_parse_err_invalid:
|
||||
conn->state = lnm_loop_state_end;
|
||||
break;
|
||||
case lnm_http_parse_err_unknown_method:
|
||||
// TODO set status code here
|
||||
conn->state = lnm_loop_state_end;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void lnm_http_loop_process_route(lnm_http_conn *conn) {}
|
||||
|
||||
void lnm_http_loop_process_steps(lnm_http_conn *conn) {
|
||||
/* lnm_http_loop_ctx *ctx = conn->ctx; */
|
||||
|
||||
/* while () */
|
||||
}
|
||||
|
||||
void (*process_fns[])(lnm_http_conn *conn) = {
|
||||
lnm_http_loop_process_parse_req,
|
||||
lnm_http_loop_process_route,
|
||||
lnm_http_loop_process_steps,
|
||||
};
|
||||
|
||||
void lnm_http_loop_process(lnm_http_conn *conn) {
|
||||
lnm_http_loop_ctx *ctx = conn->ctx;
|
||||
|
||||
lnm_http_loop_state cur_state;
|
||||
|
||||
// As long as the processing is able to advance to a next state, we keep
|
||||
// progressing
|
||||
do {
|
||||
cur_state = ctx->state;
|
||||
|
||||
process_fns[cur_state](conn);
|
||||
} while (conn->state == lnm_loop_state_req && cur_state != ctx->state);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue