Added get_request function to the frontend
[cascardo/atompub.git] / atom / frontend.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 struct _atom_frontend
27 {
28   void (*map_entries) (AtomCtx *, char **, AtomEntry **, size_t);
29   int  (*is_feed) (AtomCtx *, char *);
30   AtomRequest * (*get_request) (AtomCtx *);
31 };
32
33 AtomFrontend *
34 atom_frontend_new ()
35 {
36   AtomFrontend *frontend;
37   frontend = g_slice_new (AtomFrontend);
38   frontend->map_entries = NULL;
39   frontend->is_feed = NULL;
40   frontend->get_request = NULL;
41   return frontend;
42 }
43
44 void
45 atom_frontend_delete (AtomFrontend *frontend)
46 {
47   g_slice_free (AtomFrontend, frontend);
48 }
49
50 void
51 atom_frontend_map_entries_set (AtomFrontend *frontend,
52                                void map_entries (AtomCtx *,
53                                                  char **,
54                                                  AtomEntry **,
55                                                  size_t))
56 {
57   frontend->map_entries = map_entries;
58 }
59
60 void
61 atom_frontend_is_feed_set (AtomFrontend *frontend,
62                           int is_feed (AtomCtx *, char *))
63 {
64   frontend->is_feed = is_feed;
65 }
66
67 void
68 atom_frontend_get_request_set (AtomFrontend *frontend,
69                                AtomRequest * get_request (AtomCtx *))
70 {
71   frontend->get_request = get_request;
72 }
73
74 void
75 atom_frontend_map_entries (AtomCtx *ctx, char ** reqs,
76                            AtomEntry ** entries, size_t len)
77 {
78   AtomFrontend *frontend;
79   frontend = atom_frontend (ctx);
80   if (frontend && frontend->map_entries)
81     {
82       frontend->map_entries (ctx, reqs, entries, len);
83     }
84 }
85
86 int
87 atom_is_feed (AtomCtx *ctx, char *req)
88 {
89   AtomFrontend *frontend;
90   AtomError *aerr;
91   frontend = atom_frontend (ctx);
92   if (frontend && frontend->is_feed)
93     {
94       return frontend->is_feed (ctx, req);
95     }
96   /* If frontend cannot decide if a request is a feed, let's tell it's
97    * not. If the request mapping cannot be done, it will return a "Not
98    * Found" error anyway.
99    */
100   return 0;
101 }
102
103 AtomRequest *
104 atom_get_request (AtomCtx *ctx)
105 {
106   AtomFrontend *frontend;
107   frontend = atom_frontend (ctx);
108   if (frontend && frontend->get_request)
109     {
110       return frontend->get_request (ctx);
111     }
112   return NULL;
113 }