aboutsummaryrefslogtreecommitdiff
path: root/examples/append.c
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2019-09-13 18:50:34 +0300
committerAleksey Veresov <aleksey@veresov.pro>2019-09-13 18:50:34 +0300
commitad6188f911af896c9c77e9215bea3c5c2a4e6cc3 (patch)
tree158b4015ff302f72fe2bb8a0ee3d5441ffb66719 /examples/append.c
downloadmagi-ad6188f911af896c9c77e9215bea3c5c2a4e6cc3.tar
magi-ad6188f911af896c9c77e9215bea3c5c2a4e6cc3.tar.xz
magi-ad6188f911af896c9c77e9215bea3c5c2a4e6cc3.zip
Project name and license are added. Minor changes.
Diffstat (limited to 'examples/append.c')
-rw-r--r--examples/append.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/append.c b/examples/append.c
new file mode 100644
index 0000000..f0dfe2a
--- /dev/null
+++ b/examples/append.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <request.h>
+
+
+void handle_request()
+{
+ struct magi_request request;
+ if (magi_request_build_cgi(&request, 0, 0)) {
+ struct magi_field *a = magi_field_list_get(request.fields, "addon");
+ if (a && a->data) {
+ FILE *file = fopen("file_to_append", "a");
+ fputs(a->data, file);
+ fclose(file);
+ }
+ magi_request_destroy(&request);
+ }
+}
+
+void print_preamble()
+{
+ puts("Content-type: application/xhtml+xml\r\n\r\n");
+}
+
+void print_webpage()
+{
+ puts(
+ "<!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>"
+ "<form action='/cgi-bin/append' method='GET'>"
+ "<input type='text' name='addon' value='Whatever you want to add.'/>"
+ "<input type='submit' value='Append'/>"
+ "</form>"
+ "</body>"
+ "</html>"
+ );
+}
+
+int main(int argc, char const *argv[])
+{
+ handle_request();
+ print_preamble();
+ print_webpage();
+ return 0;
+}