56 lines
1.2 KiB
C
56 lines
1.2 KiB
C
#include "lnm/http/loop_internal.h"
|
|
|
|
lnm_err lnm_http_loop_gctx_init(lnm_http_loop_gctx **out, void *c_gctx,
|
|
lnm_http_ctx_init_fn ctx_init,
|
|
lnm_http_ctx_reset_fn ctx_reset,
|
|
lnm_http_ctx_free_fn ctx_free) {
|
|
lnm_http_loop_gctx *gctx = calloc(1, sizeof(lnm_http_loop_gctx));
|
|
|
|
if (gctx == NULL) {
|
|
return lnm_err_failed_alloc;
|
|
}
|
|
|
|
gctx->c = c_gctx;
|
|
gctx->ctx_init = ctx_init;
|
|
gctx->ctx_reset = ctx_reset;
|
|
gctx->ctx_free = ctx_free;
|
|
|
|
*out = gctx;
|
|
|
|
return lnm_err_ok;
|
|
}
|
|
|
|
lnm_err lnm_http_loop_ctx_init(lnm_http_loop_ctx **out,
|
|
lnm_http_loop_gctx *gctx) {
|
|
lnm_http_loop_ctx *ctx = calloc(1, sizeof(lnm_http_loop_ctx));
|
|
|
|
if (ctx == NULL) {
|
|
return lnm_err_failed_alloc;
|
|
}
|
|
|
|
LNM_RES2(gctx->ctx_init(&ctx->c, gctx), free(ctx));
|
|
|
|
ctx->g = gctx;
|
|
*out = ctx;
|
|
|
|
return lnm_err_ok;
|
|
}
|
|
|
|
void lnm_http_loop_ctx_reset(lnm_http_loop_ctx *ctx) {
|
|
ctx->g->ctx_reset(ctx->c);
|
|
|
|
lnm_http_req_reset(&ctx->req);
|
|
lnm_http_res_reset(&ctx->res);
|
|
|
|
ctx->route = NULL;
|
|
ctx->cur_step = NULL;
|
|
}
|
|
|
|
void lnm_http_loop_ctx_free(lnm_http_loop_ctx *ctx) {
|
|
lnm_http_loop_ctx_reset(ctx);
|
|
|
|
ctx->g->ctx_free(ctx->c);
|
|
|
|
free(ctx);
|
|
}
|