diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2019-11-13 19:16:21 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2019-11-13 19:16:21 +0300 |
commit | 23f3f8592c21ee58b0ac040736b5b766d52de193 (patch) | |
tree | 43e41480fab64d68274340f8fd934bd20c5f27b2 /examples | |
parent | b11b1c52280f172ebfa42c3da906ea9aa3ea8799 (diff) | |
download | magi-23f3f8592c21ee58b0ac040736b5b766d52de193.tar magi-23f3f8592c21ee58b0ac040736b5b766d52de193.tar.xz magi-23f3f8592c21ee58b0ac040736b5b766d52de193.zip |
Cosmetical changes.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/append.c | 30 | ||||
-rw-r--r-- | examples/cookie.c | 34 | ||||
-rw-r--r-- | examples/echo.c | 22 | ||||
-rw-r--r-- | examples/upload.c | 44 |
4 files changed, 57 insertions, 73 deletions
diff --git a/examples/append.c b/examples/append.c index b8aa1cf..b6ee217 100644 --- a/examples/append.c +++ b/examples/append.c @@ -8,9 +8,9 @@ void handle_request() { struct magi_request request; if (magi_cgi(&request, 0, 0)) { - struct magi_field *a = magi_field_list_get(request.fields, "addon"); + struct magi_field * a = magi_field_list_get(request.fields, "addon"); if (a && a->data) { - FILE *file = fopen("file_to_append", "a"); + FILE * file = fopen("file_to_append", "a"); fputs(a->data, file); fclose(file); } @@ -25,22 +25,20 @@ void print_preamble() 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'><fieldset>" - "<input type='text' name='addon' value='Whatever you want to add.'/>" - "<input type='submit' value='Append'/>" - "</fieldset></form>" - "</body>" - "</html>" - ); + 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'><fieldset>" + "<input type='text' name='addon' value='Whatever you want to add.'/>" + "<input type='submit' value='Append'/>" + "</fieldset></form>" + "</body>" + "</html>"); } -int main(int argc, char const *argv[]) +int main(int argc, char const * argv[]) { handle_request(); print_preamble(); diff --git a/examples/cookie.c b/examples/cookie.c index dd18cc6..5ef56ac 100644 --- a/examples/cookie.c +++ b/examples/cookie.c @@ -7,34 +7,26 @@ void print_preamble() { - puts( - "Set-Cookie:cookie=monstre\r\n" /* Important to set cookies before: */ - "Content-Type: application/xhtml+xml\r\n\r\n" - ); + puts("Set-Cookie:cookie=monstre\r\n" /* Important to set cookies before: */ + "Content-Type: application/xhtml+xml\r\n\r\n"); } void print_webpage_top() { - 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>Cookie Listing and Setting</title></head>" - "<body>" - ); + 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>Cookie Listing and Setting</title></head>" + "<body>"); } void read_and_print_cookies() { struct magi_request request; if (magi_cgi(&request, 0, 0)) { - struct magi_cookie_list *cookie; + struct magi_cookie_list * cookie; for (cookie = request.cookies; cookie; cookie = cookie->next) { - printf( - "[%s] = [%s]<br/>", - cookie->item.name, - cookie->item.data - ); + printf("[%s] = [%s]<br/>", cookie->item.name, cookie->item.data); } magi_request_destroy(&request); } @@ -42,13 +34,11 @@ void read_and_print_cookies() void print_webpage_bottom() { - puts( - "</body>" - "</html>" - ); + puts("</body>" + "</html>"); } -int main(int argc, char const *argv[]) +int main(int argc, char const * argv[]) { print_preamble(); /* Following probably will be much more pleasant with use of templates. */ diff --git a/examples/echo.c b/examples/echo.c index ff037a6..0345b8c 100644 --- a/examples/echo.c +++ b/examples/echo.c @@ -8,17 +8,15 @@ void print_preamble() { - puts( - "Content-type: application/xhtml+xml\r\n\r\n" - "<!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>Echo</title></head>" - "<body>" - ); + puts("Content-type: application/xhtml+xml\r\n\r\n" + "<!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>Echo</title></head>" + "<body>"); } -void proceed_cookies(struct magi_cookie_list *cookies) +void proceed_cookies(struct magi_cookie_list * cookies) { puts("<h2>Cookies:</h2>"); while (cookies) { @@ -46,7 +44,7 @@ void proceed_cookies(struct magi_cookie_list *cookies) puts("<hr/>"); } -void proceed_fields(struct magi_field_list *fields) +void proceed_fields(struct magi_field_list * fields) { puts("<h2>Feilds:</h2>"); while (fields) { @@ -60,7 +58,7 @@ void proceed_fields(struct magi_field_list *fields) puts("<hr/>"); } -void proceed_params(struct magi_param_list *params) +void proceed_params(struct magi_param_list * params) { puts("<h2>HTTP Parameters:</h2>"); while (params) { @@ -114,7 +112,7 @@ void print_footer() puts("</body></html>"); } -int main(int argc, char const *argv[]) +int main(int argc, char const * argv[]) { print_preamble(); handle_request(); diff --git a/examples/upload.c b/examples/upload.c index 59dd020..1cf6f5f 100644 --- a/examples/upload.c +++ b/examples/upload.c @@ -1,13 +1,13 @@ +#include <cgi.h> +#include <multipart.h> +#include <request.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <request.h> -#include <multipart.h> -#include <cgi.h> -void tempfile_callback(struct magi_field *field, char *buffer, int len) +void tempfile_callback(struct magi_field * field, char * buffer, int len) { - static FILE *file = 0; + static FILE * file = 0; if (!strcmp(field->name, "data")) { if (!file) { remove(field->name); @@ -32,8 +32,8 @@ void handle_request() { struct magi_request request; if (magi_cgi(&request, tempfile_callback, 0)) { - struct magi_field *name = magi_field_list_get(request.fields, "name"); - struct magi_field *data = magi_field_list_get(request.fields, "data"); + struct magi_field * name = magi_field_list_get(request.fields, "name"); + struct magi_field * data = magi_field_list_get(request.fields, "data"); if (name && name->data && data) { rename("data", name->data); } @@ -48,24 +48,22 @@ void print_preamble() 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>Upload File</title></head>" - "<body>" - "<form action='/cgi-bin/upload' method='post' " - "enctype='multipart/form-data'><fieldset>" - "<input type='text' name='name' value='filename'/>" - "<input type='file' name='data'/>" - "<input type='submit' value='Upload'/>" - "</fieldset></form>" - "</body>" - "</html>" - ); + 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>Upload File</title></head>" + "<body>" + "<form action='/cgi-bin/upload' method='post' " + "enctype='multipart/form-data'><fieldset>" + "<input type='text' name='name' value='filename'/>" + "<input type='file' name='data'/>" + "<input type='submit' value='Upload'/>" + "</fieldset></form>" + "</body>" + "</html>"); } -int main(int argc, char const *argv[]) +int main(int argc, char const * argv[]) { handle_request(); print_preamble(); |