2 * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <atompub/atom.h>
27 void atom_get (AtomCtx *ctx, AtomRequest *request)
29 if (atom_is_feed (ctx, atom_request_request (request)))
32 feed = atom_retrieve_feed (ctx);
35 atom_handle_feed (ctx, feed);
36 atom_feed_delete (feed);
42 entry = atom_retrieve_entry (ctx, atom_request_request (request));
45 atom_handle_entry (ctx, entry);
46 atom_entry_delete (entry);
52 atom_post (AtomCtx *ctx, AtomRequest *request)
55 /* Publish requests go to the same IRI as the feed IRI */
56 if (!atom_is_feed (ctx, atom_request_request (request)))
58 error = atom_error_new ();
59 atom_error_code_set (error, 400);
60 atom_error_message_set (error, "Bad Request");
61 atom_error_set (ctx, error);
68 atom_request_content (request, &content, &len);
69 /* TODO: If the content is not an Atom Entry, consider it a media
71 entry = atom_entry_new_data_len (content, len);
74 error = atom_error_new ();
75 atom_error_code_set (error, 400);
76 atom_error_message_set (error, "Bad Request");
77 atom_error_set (ctx, error);
81 atom_publish_entry (ctx, atom_request_request (request), entry);
82 /* TODO: Entry should be the backend representation and more
83 * information should be given to the frontend */
84 if (!atom_error_get (ctx))
85 atom_handle_publish (ctx, entry);
91 atom_serve_request (AtomCtx *ctx)
95 request = atom_get_request (ctx);
98 int type = atom_request_type (request);
101 case ATOM_REQUEST_GET:
102 atom_get (ctx, request);
104 case ATOM_REQUEST_POST:
105 atom_post (ctx, request);
108 error = atom_error_new ();
109 atom_error_code_set (error, 501);
110 atom_error_message_set (error, "Not Implemented");
111 atom_error_set (ctx, error);
114 if (atom_error_get (ctx))
116 atom_handle_error (ctx);
117 atom_error_set (ctx, NULL);