aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/append.c25
-rw-r--r--examples/cookie.c37
-rw-r--r--examples/echo.c69
-rw-r--r--examples/fcgi.c6
-rw-r--r--examples/upload.c53
5 files changed, 84 insertions, 106 deletions
diff --git a/examples/append.c b/examples/append.c
index cb49e50..702f0fb 100644
--- a/examples/append.c
+++ b/examples/append.c
@@ -1,22 +1,18 @@
-#include <cgi.h>
-#include <request.h>
-#include <response.h>
+#include <magi.h>
#include <stdio.h>
#include <stdlib.h>
-void response_request(struct magi_request * req, struct magi_response * res)
+void response_request(magi_request *req, magi_response *res)
{
- char * data = magi_param_list_get(req->params, "addon");
+ char *data = magi_param_list_get(req->params, "addon");
if (data) {
- FILE * file = fopen("file_to_append", "a");
+ FILE *file = fopen("file_to_append", "a");
fputs(data, file);
fclose(file);
}
- magi_response_content_type(res, magi_xhtml);
- magi_response_add(
- res,
+ 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'>"
@@ -30,16 +26,15 @@ void response_request(struct magi_request * req, struct magi_response * res)
"</html>");
}
-int main(int argc, char const * argv[])
+int main(int argc, char const *argv[])
{
- struct magi_request request;
+ magi_request request;
magi_request_setup(&request);
- if (magi_request_cgi(&request) && magi_request_resume_cgi(&request)) {
- struct magi_response response;
+ if (magi_request_full_cgi(&request)) {
+ magi_response response;
magi_response_setup(&response);
response_request(&request, &response);
- magi_response_cgi(&response);
- magi_response_destroy(&response);
+ magi_response_cgi_clear(&response);
} else {
magi_error_cgi(request.error);
}
diff --git a/examples/cookie.c b/examples/cookie.c
index bb1e1d1..365f989 100644
--- a/examples/cookie.c
+++ b/examples/cookie.c
@@ -1,26 +1,22 @@
-#include <cgi.h>
-#include <cookie.h>
-#include <request.h>
-#include <response.h>
+#include <magi.h>
#include <stdio.h>
#include <stdlib.h>
-void response_request(struct magi_request * req, struct magi_response * res)
+void response_request(magi_request *req, magi_response *res)
{
- struct magi_cookie_list * current;
+ magi_cookie_list *current;
- magi_response_content_type(res, magi_xhtml);
- 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>Cookie Listing and Setting</title></head>"
- "<body>");
+ 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>Cookie Listing and Setting</title></head>"
+ "<body>");
for (current = req->cookies; current; current = current->next) {
- magi_response_add_format(res, "[%s] = [%s]<br/>", current->item.name,
- current->item.data);
+ magi_response_add_format(res,
+ "[%s] = [%s]<br/>", current->item.name, current->item.data);
}
magi_response_add(res, "</body></html>");
@@ -28,16 +24,15 @@ void response_request(struct magi_request * req, struct magi_response * res)
magi_response_cookie_easy(res, "cookie", "monster");
}
-int main(int argc, char const * argv[])
+int main(int argc, char const *argv[])
{
- struct magi_request request;
+ magi_request request;
magi_request_setup(&request);
- if (magi_request_cgi(&request) && magi_request_resume_cgi(&request)) {
- struct magi_response response;
+ if (magi_request_full_cgi(&request)) {
+ magi_response response;
magi_response_setup(&response);
response_request(&request, &response);
- magi_response_cgi(&response);
- magi_response_destroy(&response);
+ magi_response_cgi_clear(&response);
} else {
magi_error_cgi(request.error);
}
diff --git a/examples/echo.c b/examples/echo.c
index e9807f0..81bdcf4 100644
--- a/examples/echo.c
+++ b/examples/echo.c
@@ -1,16 +1,10 @@
-#include <cgi.h>
-#include <cookie.h>
-#include <param.h>
-#include <request.h>
-#include <response.h>
+#include <magi.h>
#include <stdio.h>
#include <stdlib.h>
-void proceed_cookies(struct magi_cookie_list * cookies,
- struct magi_response * response)
+void proceed_cookies(magi_cookie_list *cookies, magi_response *response)
{
- magi_response_add(response, "<h2>Cookies:</h2>");
while (cookies) {
magi_response_add(response, "Cookie with name [");
magi_response_add(response, cookies->item.name);
@@ -33,36 +27,30 @@ void proceed_cookies(struct magi_cookie_list * cookies,
magi_response_add(response, "]<br/>");
cookies = cookies->next;
}
- magi_response_add(response, "<hr/>");
}
-void proceed_params(struct magi_param_list * params,
- struct magi_response * response)
+void proceed_params(magi_param_list *params, magi_response *response)
{
while (params) {
- magi_response_add_format(response, "[%s] is [%s]<br/>",
- params->item.name, params->item.data);
+ magi_response_add_format(response,
+ "[%s] is [%s]<br/>", params->item.name, params->item.data);
params = params->next;
}
- magi_response_add(response, "<hr/>");
}
-void proceed_files(struct magi_file_list * files,
- struct magi_response * response)
+void proceed_files(magi_file_list *files, magi_response *response)
{
while (files) {
- magi_response_add_format(response, "[%s] was [%s] on userside<br/>",
- files->item.param_name,
- files->item.file_name);
+ magi_file f = files->item;
+ magi_response_add_format(response,
+ "[%s] was [%s] on userside<br/>", f.param_name, f.file_name);
files = files->next;
}
- magi_response_add(response, "<hr/>");
}
-void process_meta(struct magi_request * req, struct magi_response * res)
+void process_meta(magi_request *req, magi_response *res)
{
- magi_response_add(res,
- "<h1>Echo CGI Script</h1>I was called with method [");
+ magi_response_add(res, "I was called with method [");
magi_response_add(res, req->method);
if (req->uri) {
magi_response_add(res, "] with URL [");
@@ -87,38 +75,45 @@ void process_meta(struct magi_request * req, struct magi_response * res)
magi_response_add(res, "]<br/>");
}
-void response_request(struct magi_request * req, struct magi_response * res)
+void response_request(magi_request *req, magi_response *res)
{
- magi_response_content_type(res, magi_xhtml);
- 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>Echo</title></head>"
- "<body>");
+ 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>Echo</title></head>"
+ "<body>");
+
+ magi_response_add(res, "<h1>Echo CGI Script</h1>");
process_meta(req, res);
+
+ magi_response_add(res, "<h2>Cookies:</h2>");
proceed_cookies(req->cookies, res);
+
magi_response_add(res, "<h2>Parameters:</h2>");
proceed_params(req->params, res);
+
magi_response_add(res, "<h2>URL Parameters:</h2>");
proceed_params(req->url_params, res);
+
magi_response_add(res, "<h2>HTTP Parameters:</h2>");
proceed_params(req->http_params, res);
+
magi_response_add(res, "<h2>Files:</h2>");
proceed_files(req->files, res);
+
magi_response_add(res, "</body></html>");
}
-int main(int argc, char const * argv[])
+int main(int argc, char const *argv[])
{
- struct magi_request request;
+ magi_request request;
magi_request_setup(&request);
- if (magi_request_cgi(&request) && magi_request_resume_cgi(&request)) {
- struct magi_response response;
+ if (magi_request_full_cgi(&request)) {
+ magi_response response;
magi_response_setup(&response);
response_request(&request, &response);
- magi_response_cgi(&response);
- magi_response_destroy(&response);
+ magi_response_cgi_clear(&response);
} else {
magi_error_cgi(request.error);
}
diff --git a/examples/fcgi.c b/examples/fcgi.c
index 2790f9d..bb5645e 100644
--- a/examples/fcgi.c
+++ b/examples/fcgi.c
@@ -1,7 +1,5 @@
-#include <error.h>
-#include <fastcgi.h>
-#include <request.h>
-#include <response.h>
+/* * * TODO * * */
+#include <magi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/examples/upload.c b/examples/upload.c
index 1947f93..6a3a7a4 100644
--- a/examples/upload.c
+++ b/examples/upload.c
@@ -1,50 +1,45 @@
-#include <cgi.h>
-#include <multipart.h>
-#include <request.h>
-#include <response.h>
+#include <magi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-void response_request(struct magi_request * req, struct magi_response * res)
+void response_request(magi_request *req, magi_response *res)
{
- char * name = magi_param_list_get(req->params, "name");
- struct magi_file * data = magi_file_list_get(req->files, "data");
+ char *name = magi_param_list_get(req->params, "name");
+ magi_file *data = magi_file_list_get(req->files, "data");
if (name && data) {
rename("data", name);
}
- magi_response_content_type(res, magi_xhtml);
- 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>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>");
+ 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>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[])
{
- struct magi_request request;
- struct magi_tempfiles tmps = { 0, 0, 0, 0 };
+ magi_request request;
+ magi_tempfiles tmps = { 0, 0 };
magi_request_setup(&request);
magi_tempfiles_add(&tmps, "data", "data", 0);
magi_request_setup_tempfiles(&request, &tmps);
- if (magi_request_cgi(&request) && magi_request_resume_cgi(&request)) {
- struct magi_response response;
+ if (magi_request_full_cgi(&request)) {
+ magi_response response;
magi_response_setup(&response);
response_request(&request, &response);
- magi_response_cgi(&response);
- magi_response_destroy(&response);
+ magi_response_cgi_clear(&response);
} else {
magi_error_cgi(request.error);
}