From 875254a7a70e15556f83831b70cfa295e0d73f6d Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Wed, 10 Dec 2008 11:01:03 -0200 Subject: [PATCH] Let the frontend deal with bad requests for posting to member resources As the atompub RFC specifies that posting to a member resource URI is a bad request, let the frontend deal with it and avoid the need to inform the core that the request has a URI and a desired name (Slug). --- atom/core.c | 36 +++++++++++++----------------------- frontend/cgi/cgi.c | 12 +++++++++++- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/atom/core.c b/atom/core.c index b2289b4..86803a3 100644 --- a/atom/core.c +++ b/atom/core.c @@ -53,7 +53,14 @@ atom_post (AtomCtx *ctx, AtomRequest *request) { AtomError *error; /* Publish requests go to the same IRI as the feed IRI */ - if (!atom_is_feed (ctx, atom_request_request (request))) + char *content = NULL; + size_t len = 0; + AtomEntry *entry; + atom_request_content (request, &content, &len); + /* TODO: If the content is not an Atom Entry, consider it a media + * publish request */ + entry = atom_entry_new_data_len (content, len); + if (entry == NULL) { error = atom_error_new (); atom_error_code_set (error, 400); @@ -62,28 +69,11 @@ atom_post (AtomCtx *ctx, AtomRequest *request) } else { - char *content = NULL; - size_t len = 0; - AtomEntry *entry; - atom_request_content (request, &content, &len); - /* TODO: If the content is not an Atom Entry, consider it a media - * publish request */ - entry = atom_entry_new_data_len (content, len); - if (entry == NULL) - { - error = atom_error_new (); - atom_error_code_set (error, 400); - atom_error_message_set (error, "Bad Request"); - atom_error_set (ctx, error); - } - else - { - atom_publish_entry (ctx, atom_request_request (request), entry); - /* TODO: Entry should be the backend representation and more - * information should be given to the frontend */ - if (!atom_error_get (ctx)) - atom_handle_publish (ctx, entry); - } + atom_publish_entry (ctx, atom_request_request (request), entry); + /* TODO: Entry should be the backend representation and more + * information should be given to the frontend */ + if (!atom_error_get (ctx)) + atom_handle_publish (ctx, entry); } } diff --git a/frontend/cgi/cgi.c b/frontend/cgi/cgi.c index 20f1ce7..0719175 100644 --- a/frontend/cgi/cgi.c +++ b/frontend/cgi/cgi.c @@ -136,7 +136,17 @@ cgi_get_request (AtomCtx *ctx) return NULL; } if (path == NULL || *path == '\0') - path = "/"; + { + if (!strcmp (method, "POST")) + { + error = atom_error_new (); + atom_error_code_set (error, 400); + atom_error_message_set (error, "Bad Request"); + atom_error_set (ctx, error); + return NULL; + } + path = "/"; + } if (!strcmp (method, "GET")) { /* Remove the leading slash before mapping */ -- 2.20.1