File: tt.c

package info (click to toggle)
uwsgi 2.0.31-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,740 kB
  • sloc: ansic: 87,072; python: 7,014; cpp: 1,133; java: 708; perl: 678; sh: 585; ruby: 555; makefile: 146; xml: 130; cs: 121; objc: 37; php: 28; erlang: 20; javascript: 11
file content (42 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <uwsgi.h>

#ifdef UWSGI_ROUTING

// apply templating
static int transform_template(struct wsgi_request *wsgi_req, struct uwsgi_transformation *ut) {

	struct uwsgi_route *ur = (struct uwsgi_route *) ut->data;

	char **subject = (char **) (((char *)(wsgi_req))+ur->subject);
        uint16_t *subject_len = (uint16_t *)  (((char *)(wsgi_req))+ur->subject_len);

        struct uwsgi_buffer *ub = uwsgi_routing_translate(wsgi_req, ur, *subject, *subject_len, ut->chunk->buf, ut->chunk->pos);
        if (!ub) return -1;
        uwsgi_buffer_map(ut->chunk, ub->buf, ub->pos);
        ub->buf = NULL;
        uwsgi_buffer_destroy(ub);
        return 0;
}
static int uwsgi_router_template_func(struct wsgi_request *wsgi_req, struct uwsgi_route *route) {
        uwsgi_add_transformation(wsgi_req, transform_template, route);
        return UWSGI_ROUTE_NEXT;
}
static int uwsgi_router_template(struct uwsgi_route *ur, char *arg) {
        ur->func = uwsgi_router_template_func;
        return 0;
}

static void transformation_template_register(void) {
        uwsgi_register_router("template", uwsgi_router_template);
}

struct uwsgi_plugin transformation_template_plugin = {
        .name = "transformation_template",
        .on_load = transformation_template_register,
};

#else
struct uwsgi_plugin transformation_template_plugin = {
        .name = "transformation_template",
};
#endif