diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2020-02-28 20:16:57 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2020-02-28 20:16:57 +0300 |
commit | c65fdedc7bedfc20da73cdbfc34c22bb80139896 (patch) | |
tree | 2b110cb12e91753fbdaf5d94c71c44ce73c9019a /examples/append.c | |
parent | c11dd93608624593af3fe5a3f2a3eefa56911fe4 (diff) | |
download | magi-c65fdedc7bedfc20da73cdbfc34c22bb80139896.tar magi-c65fdedc7bedfc20da73cdbfc34c22bb80139896.tar.xz magi-c65fdedc7bedfc20da73cdbfc34c22bb80139896.zip |
[magi]
Diffstat (limited to 'examples/append.c')
-rw-r--r-- | examples/append.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/examples/append.c b/examples/append.c index 702f0fb..cafdf9c 100644 --- a/examples/append.c +++ b/examples/append.c @@ -1,23 +1,23 @@ #include <magi.h> #include <stdio.h> -#include <stdlib.h> -void response_request(magi_request *req, magi_response *res) +void response(magi_request *r) { - char *data = magi_param_list_get(req->params, "addon"); + char *data = magi_request_param(r, "addon"); + magi_response_add(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>Append to File</title></head>" + "<body>"); if (data) { FILE *file = fopen("file_to_append", "a"); fputs(data, file); fclose(file); + magi_response_add(r, "<p>Appended!</p>"); } - - 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>Append to File</title></head>" - "<body>" + magi_response_add(r, "<form action='/cgi-bin/append' method='post'><fieldset>" "<input type='text' name='addon' value='Whatever you want to add.'/>" "<input type='submit' value='Append'/>" @@ -29,15 +29,12 @@ void response_request(magi_request *req, magi_response *res) 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); + magi_request_init(&request); + if (magi_cgi(&request)) { + response(&request); } else { - magi_error_cgi(request.error); + magi_response_error(&request); } - magi_request_destroy(&request); + magi_request_free(&request); return 0; } |