aboutsummaryrefslogtreecommitdiff
path: root/examples/append.c
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2019-11-29 18:50:04 +0300
committerAleksey Veresov <aleksey@veresov.pro>2019-11-29 18:50:04 +0300
commitb08db17162fddda97e6ee1ac625eae1430d22b64 (patch)
tree2c332f2db57a15c72f58704b9175cfece0ae9698 /examples/append.c
parentea25abb295d9b4fbaf0ac23af8ffe71247970f1b (diff)
downloadmagi-b08db17162fddda97e6ee1ac625eae1430d22b64.tar
magi-b08db17162fddda97e6ee1ac625eae1430d22b64.tar.xz
magi-b08db17162fddda97e6ee1ac625eae1430d22b64.zip
[magi] Almost done!
Diffstat (limited to 'examples/append.c')
-rw-r--r--examples/append.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/append.c b/examples/append.c
index 3320fe0..e6e4a8a 100644
--- a/examples/append.c
+++ b/examples/append.c
@@ -7,6 +7,13 @@
void response_request(struct magi_request * req, struct magi_response * res)
{
+ char * data = magi_param_list_get(req->params, "addon");
+ if (data) {
+ FILE * file = fopen("file_to_append", "a");
+ fputs(data, file);
+ fclose(file);
+ }
+
magi_response_content_type(res, magi_xhtml);
magi_response_add(
res,
@@ -15,19 +22,12 @@ void response_request(struct magi_request * req, struct magi_response * res)
"<html xmlns='http://www.w3.org/1999/xhtml'>"
"<head><title>Append to File</title></head>"
"<body>"
- "<form action='/cgi-bin/append' method='get'><fieldset>"
+ "<form action='/cgi-bin/append' method='post'><fieldset>"
"<input type='text' name='addon' value='Whatever you want to add.'/>"
"<input type='submit' value='Append'/>"
"</fieldset></form>"
"</body>"
"</html>");
-
- struct magi_param * addon = magi_param_list_get(req->url_params, "addon");
- if (addon && addon->data) {
- FILE * file = fopen("file_to_append", "a");
- fputs(addon->data, file);
- fclose(file);
- }
}
int main(int argc, char const * argv[])
@@ -36,6 +36,7 @@ int main(int argc, char const * argv[])
magi_request_setup(&request);
if (magi_request_cgi(&request)) {
struct magi_response response;
+ magi_response_setup(&response);
response_request(&request, &response);
magi_response_cgi(&response);
magi_response_destroy(&response);