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


void list_cookies(magi_request *r)
{
    magi_cookies *current;
    magi_response(r, "Cookies:");
    for (current = r->cookies; current; current = current->next) {
        magi_cookie *c = &current->item;
        magi_response_format(r, "<br />[%s]=[%s]", c->name, c->data);
    }
}

void response(magi_request *r)
{
    magi_response_cookie(r, "cookie", "monster");
    magi_response(r,
        "<!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><p>");
    list_cookies(r);
    magi_response(r, "</p></body></html>");
}

int main()
{
    magi_request request;
    magi_request_init(&request);
    if (magi_cgi(&request)) {
        response(&request);
    } else {
        magi_response_error(&request);
    }
    magi_request_free(&request);
    return 0;
}