From 3741afca55af01e6a79f8681344ca50d1609ff41 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Mon, 13 Oct 2008 01:40:51 -0300 Subject: [PATCH] Implemented POST request in CGI frontend --- frontend/cgi/cgi.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/frontend/cgi/cgi.c b/frontend/cgi/cgi.c index 76380ba..9338f4d 100644 --- a/frontend/cgi/cgi.c +++ b/frontend/cgi/cgi.c @@ -19,19 +19,42 @@ #include +#include + #include #include #include #include +static void +cgi_request_content_set (AtomCtx *ctx, AtomRequest *request) +{ + GIOChannel *channel; + GError *error = NULL; + gchar *data; + gsize len; + channel = g_io_channel_unix_new (0); + if (g_io_channel_read_to_end (channel, &data, &len, &error) != + G_IO_STATUS_NORMAL) + { + AtomError *aerr = atom_error_new_from_gerror (error); + g_io_channel_unref (channel); + atom_error_set (ctx, aerr); + g_error_free (error); + return; + } + atom_request_content_set (request, data, len); + g_io_channel_unref (channel); + g_free (data); +} + static AtomRequest * cgi_get_request (AtomCtx *ctx) { AtomError *error; char *method = getenv ("REQUEST_METHOD"); char *path = getenv ("PATH_INFO"); - int type; - char *request; + AtomRequest *request; if (method == NULL) { error = atom_error_new (); @@ -47,6 +70,17 @@ cgi_get_request (AtomCtx *ctx) /* Remove the leading slash before mapping */ return atom_request_new (ATOM_REQUEST_GET, path + 1); } + else if (!strcmp (method, "POST")) + { + request = atom_request_new (ATOM_REQUEST_POST, path + 1); + cgi_request_content_set (ctx, request); + if (atom_error_get (ctx) != NULL) + { + atom_request_delete (request); + return NULL; + } + return request; + } error = atom_error_new (); atom_error_code_set (error, 501); atom_error_message_set (error, "Not Implemented"); -- 2.20.1