feat(lander): initial lnm integration test
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Jef Roosens 2023-12-02 20:22:05 +01:00
parent 799821d9fc
commit 8ec667af3b
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
15 changed files with 187 additions and 44 deletions

View file

@ -79,4 +79,11 @@ uint64_t lnm_ipow(uint64_t base, uint64_t power);
*/
uint64_t lnm_atoi(const char *s, size_t len);
/**
* Calculate how many base 10 digits the given number consists of.
*
* @param num number to use
*/
uint64_t lnm_digits(uint64_t num);
#endif

View file

@ -7,11 +7,11 @@ extern const char *lnm_http_method_names[];
extern const size_t lnm_http_method_names_len;
typedef enum lnm_http_method {
http_method_get = 0,
http_method_post,
http_method_put,
http_method_patch,
http_method_delete
lnm_http_method_get = 0,
lnm_http_method_post,
lnm_http_method_put,
lnm_http_method_patch,
lnm_http_method_delete
} lnm_http_method;
extern const char *lnm_http_status_names[][32];

View file

@ -32,12 +32,20 @@ lnm_err lnm_http_loop_init(lnm_http_loop **out, void *c_gctx,
lnm_http_ctx_reset_fn ctx_reset,
lnm_http_ctx_free_fn ctx_free);
/**
* Initialize a new step.
*
* @param out where to store pointer to new `lnm_http_step`
* @param fn step function
*/
lnm_err lnm_http_step_init(lnm_http_step **out, lnm_http_step_fn fn);
/**
* Append the given step fn to the step.
*
* @param out where to store pointer to new `lnm_http_step`
* @param step step to append new step to
* @param fn step funcitonn
* @param fn step function
*/
lnm_err lnm_http_step_append(lnm_http_step **out, lnm_http_step *step,
lnm_http_step_fn fn);
@ -71,7 +79,9 @@ lnm_err lnm_http_route_init_regex(lnm_http_route **out, lnm_http_method method,
* @param hl HTTP loop to modify
* @param route route to add
*/
void lnm_http_loop_route_add(lnm_http_loop *hl, lnm_http_route *route);
lnm_err lnm_http_loop_route_add(lnm_http_loop *hl, lnm_http_route *route);
lnm_err lnm_http_loop_run(lnm_http_loop *hl, uint16_t port);
/**
* Represents what state an HTTP loop request is currently in.
@ -85,6 +95,8 @@ typedef enum lnm_http_loop_state {
lnm_http_loop_state_parse_headers,
// Execute the various steps defined for the route
lnm_http_loop_state_steps,
// Add certain automatically added headers
lnm_http_loop_state_add_headers,
// Write the response status line
lnm_http_loop_state_write_status_line,
// Write the various response headers

View file

@ -45,12 +45,12 @@ typedef struct lnm_http_res {
FILE *f;
data_fn fn;
} data;
size_t len;
uint64_t len;
bool owned;
lnm_http_res_body_type type;
} body;
// General-purpose; meaning depends on the current state
size_t written;
uint64_t written;
} lnm_http_res;
/**