feat(lnm): part of routing code
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Jef Roosens 2023-11-28 20:54:40 +01:00
parent d119f85260
commit 8c21ccf58b
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 56 additions and 7 deletions

View file

@ -56,7 +56,8 @@ lnm_err lnm_http_step_append(lnm_http_step **out, lnm_http_step *step,
* @param path literal path to match
* @param step step to process request with
*/
lnm_err lnm_http_route_init_literal(lnm_http_route **out, const char *path,
lnm_err lnm_http_route_init_literal(lnm_http_route **out,
lnm_http_method method, const char *path,
lnm_http_step *step);
/**
@ -67,8 +68,9 @@ lnm_err lnm_http_route_init_literal(lnm_http_route **out, const char *path,
* @param regex_group_count how many regex groups are contained in the pattern
* @param step step to process request with
*/
lnm_err lnm_http_route_init_regex(lnm_http_route **out, const char *pattern,
int regex_group_count, lnm_http_step *step);
lnm_err lnm_http_route_init_regex(lnm_http_route **out, lnm_http_method method,
const char *pattern, int regex_group_count,
lnm_http_step *step);
/**
* Add a new route to the HTTP route.
@ -101,6 +103,7 @@ typedef struct lnm_http_loop_gctx {
typedef struct lnm_http_loop_ctx {
lnm_http_loop_state state;
lnm_http_req req;
lnm_http_route *route;
lnm_http_loop_gctx *g;
void *c;
} lnm_http_loop_ctx;

View file

@ -1,6 +1,7 @@
#ifndef LNM_HTTP_REQ
#define LNM_HTTP_REQ
#include <regex.h>
#include <stdlib.h>
#include "picohttpparser.h"
@ -8,6 +9,7 @@
#include "lnm/http/consts.h"
#define LNM_HTTP_MAX_REQ_HEADERS 32
#define LNM_HTTP_MAX_REGEX_GROUPS 4
/**
* Represents the parsed HTTP request
@ -19,6 +21,7 @@ typedef struct lnm_http_req {
struct {
const char *s;
size_t len;
regmatch_t groups[LNM_HTTP_MAX_REGEX_GROUPS];
} path;
struct {
const char *s;