aboutsummaryrefslogtreecommitdiff
path: root/handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'handler.c')
-rw-r--r--handler.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/handler.c b/handler.c
index 8a777fa..98e6118 100644
--- a/handler.c
+++ b/handler.c
@@ -28,7 +28,8 @@ struct handler
struct handler *h;
struct server_client *c;
struct http_ctx *http;
- int (*fn)(const struct http_payload *, struct http_response *, void *);
+ union http_step step;
+ void *step_args;
struct client *next;
} *clients;
@@ -61,15 +62,19 @@ static int on_payload(const struct http_payload *const p,
if (e->op == p->op && !wildcard_cmp(p->resource, e->url, true))
{
+ union http_step *const s = &c->step;
int ret;
- if (c->fn)
- ret = c->fn(p, r, e->user);
+ if (s->payload)
+ ret = s->payload(p, r, e->user, c->step_args);
else
ret = e->f(p, r, e->user);
if (!ret)
- c->fn = r->step;
+ {
+ s->payload = r->step.payload;
+ c->step_args = r->step_args;
+ }
return ret;
}
@@ -92,10 +97,24 @@ static int on_length(const unsigned long long len,
struct client *const cl = user;
struct handler *const h = cl->h;
- if (h->cfg.length)
- return h->cfg.length(len, c, r, h->cfg.user);
+ if (!h->cfg.length)
+ return 0;
- return 0;
+ union http_step *const s = &cl->step;
+ int ret;
+
+ if (s->length)
+ ret = s->length(len, c, r, h->cfg.user, cl->step_args);
+ else
+ ret = h->cfg.length(len, c, r, h->cfg.user);
+
+ if (!ret)
+ {
+ s->length = r->step.length;
+ cl->step_args = r->step_args;
+ }
+
+ return ret;
}
static struct client *find_or_alloc_client(struct handler *const h,