ed0faad8570ab806694e048cdf9b5bae6cd0efa2
[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 };
31
32 AtomFrontend *
33 atom_frontend_new ()
34 {
35   AtomFrontend *frontend;
36   frontend = g_slice_new (AtomFrontend);
37   frontend->map_entries = NULL;
38   frontend->is_feed = NULL;
39   return frontend;
40 }
41
42 void
43 atom_frontend_delete (AtomFrontend *frontend)
44 {
45   g_slice_free (AtomFrontend, frontend);
46 }
47
48 void
49 atom_frontend_map_entries_set (AtomFrontend *frontend,
50                                void map_entries (AtomCtx *,
51                                                  char **,
52                                                  AtomEntry **,
53                                                  size_t))
54 {
55   frontend->map_entries = map_entries;
56 }
57
58 void
59 atom_frontend_is_feed_set (AtomFrontend *frontend,
60                           int is_feed (AtomCtx *, char *))
61 {
62   frontend->is_feed = is_feed;
63 }
64
65 void
66 atom_frontend_map_entries (AtomCtx *ctx, char ** reqs,
67                            AtomEntry ** entries, size_t len)
68 {
69   AtomFrontend *frontend;
70   frontend = atom_frontend (ctx);
71   if (frontend && frontend->map_entries)
72     {
73       frontend->map_entries (ctx, reqs, entries, len);
74     }
75 }
76
77 int
78 atom_is_feed (AtomCtx *ctx, char *req)
79 {
80   AtomFrontend *frontend;
81   AtomError *aerr;
82   frontend = atom_frontend (ctx);
83   if (frontend && frontend->is_feed)
84     {
85       return frontend->is_feed (ctx, req);
86     }
87   /* If frontend cannot decide if a request is a feed, let's tell it's
88    * not. If the request mapping cannot be done, it will return a "Not
89    * Found" error anyway.
90    */
91   return 0;
92 }