aboutsummaryrefslogtreecommitdiff
path: root/examples/cookie.c
blob: 365f9894f1ab4547d8fbfdd03bf45cd46badedd0 (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
#include <magi.h>
#include <stdio.h>
#include <stdlib.h>


void response_request(magi_request *req, magi_response *res)
{
    magi_cookie_list *current;

    magi_response_add(res,
        "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' "
        "'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>"
        "<html xmlns='http://www.w3.org/1999/xhtml'>"
        "<head><title>Cookie Listing and Setting</title></head>"
        "<body>");

    for (current = req->cookies; current; current = current->next) {
        magi_response_add_format(res,
            "[%s] = [%s]<br/>", current->item.name, current->item.data);
    }

    magi_response_add(res, "</body></html>");

    magi_response_cookie_easy(res, "cookie", "monster");
}

int main(int argc, char const *argv[])
{
    magi_request request;
    magi_request_setup(&request);
    if (magi_request_full_cgi(&request)) {
        magi_response response;
        magi_response_setup(&response);
        response_request(&request, &response);
        magi_response_cgi_clear(&response);
    } else {
        magi_error_cgi(request.error);
    }
    magi_request_destroy(&request);
    return 0;
}