e9199b2dc7c578d36b33d8dd66004404bb75865f
[cascardo/atompub.git] / atom / core.c
1 /*
2  *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19
20 #include <atompub/atom.h>
21
22 #include <glib.h>
23
24 #include <string.h>
25
26 static
27 void atom_get (AtomCtx *ctx, AtomRequest *request)
28 {
29   if (atom_is_feed (ctx, atom_request_request (request)))
30     {
31       AtomFeed *feed;
32       feed = atom_retrieve_feed (ctx);
33       if (feed != NULL)
34         {
35           atom_handle_feed (ctx, feed);
36           atom_feed_delete (feed);
37         }
38     }
39   else
40      {
41        AtomEntry *entry;
42        entry = atom_retrieve_entry (ctx, atom_request_request (request));
43        if (entry != NULL)
44          {
45            atom_handle_entry (ctx, entry);
46            atom_entry_delete (entry);
47          }
48      }
49 }
50
51 void
52 atom_serve_request (AtomCtx *ctx)
53 {
54   AtomRequest *request;
55   AtomError *error;
56   request = atom_get_request (ctx);
57   if (request != NULL)
58     {
59       if (atom_request_type (request) == ATOM_REQUEST_GET)
60         {
61           atom_get (ctx, request);
62         }
63       else
64         {
65           error = atom_error_new ();
66           atom_error_code_set (error, 501);
67           atom_error_message_set (error, "Not Implemented");
68           atom_error_set (ctx, error);
69         }
70     }
71   if (atom_error_get (ctx))
72     {
73       atom_handle_error (ctx);
74       atom_error_set (ctx, NULL);
75     }
76 }