aboutsummaryrefslogtreecommitdiff
path: root/src/request.c
blob: fd13f7487f3748e10a12100d9c197a04105cf56e (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "request.h"

#include <stdlib.h>


void magi_request_init(struct magi_request *request)
{
    if (request) {
        request->callback.act       = 0;
        request->callback.userdata  = 0;
        request->callback.addon_max = 1024;
        request->limits.cookies     = 0;
        request->limits.params_head = 0;
        request->limits.params_body = 0;
        request->limits.read_buffer = 65536;
    }
}


static void request_free(struct magi_request *request)
{
    free(request->cookies);
    free(request->head);
    free(request->body);
    free(request->files);
    free(request->document_root);
    free(request->method);
    free(request->host);
    free(request->script);
    free(request->path);
}

static void request_annul(struct magi_request *request)
{
    request->cookies  = 0;
    request->head     = 0;
    request->body     = 0;
    request->files    = 0;
    request->method   = 0;
    request->host     = 0;
    request->script   = 0;
    request->path     = 0;
}

void magi_request_free(struct magi_request *request)
{
    if (request) {
        magi_cookies_free(request->cookies);
        magi_params_free(request->head);
        magi_params_free(request->body);
        magi_files_free(request->files);
        request_free(request);
        request_annul(request);
    }
}


char *magi_request_param(const struct magi_request *r, const char *name)
{
    char *res = magi_params_get(r->body, name);
    if (!res) {
        return magi_params_get(r->head, name);
    }
    return res;
}

char *magi_request_urlparam(const struct magi_request *r, const char *name)
{
    return magi_params_get(r->head, name);
}

const struct magi_file *magi_request_file(const struct magi_request *r,
                                          const char *name)
{
    return magi_files_get(r->files, name);
}

char *magi_request_cookie(const struct magi_request *r, const char *name)
{
    const struct magi_cookie *res = magi_cookies_get(r->cookies, name);
    if (!res) {
        return 0;
    }
    return res->data;
}

const struct magi_cookie *
magi_request_cookie_complex(const struct magi_request *r,
                            const char                *name)
{
    return magi_cookies_get(r->cookies, name);
}