aboutsummaryrefslogtreecommitdiff
path: root/src/request.c
blob: ce0f84fe04b98adc4bb30f5d74cf731b1b23e7cb (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "request.h"

#include "response.h"
#include <stdlib.h>


void magi_request_init(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_meta = 0;
        request->limits.params_head = 0;
        request->limits.params_body = 0;
    }
}


static void request_free(magi_request *request)
{
    free(request->cookies);
    free(request->meta);
    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);
    free(request->response);
}

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

void magi_request_free(magi_request *request)
{
    if (request) {
        magi_cookies_free(request->cookies);
        magi_params_free(request->meta);
        magi_params_free(request->head);
        magi_params_free(request->body);
        magi_files_free(request->files);
        request->response->methods->close(request->response->userdata);
        free(request->response->userdata);
        magi_params_free(request->response->head_response);
        magi_params_free(request->response->head_general);
        magi_params_free(request->response->head_entity);
        free(request->response->head_response);
        free(request->response->head_general);
        free(request->response->head_entity);
        request_free(request);
        request_annul(request);
    }
}


char *magi_request_meta(magi_request *r, const char *name)
{
    return magi_params_get(r->meta, name);
}

char *magi_request_param(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(magi_request *r, const char *name)
{
    return magi_params_get(r->head, name);
}

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

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

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