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>
28 void (*map_entries) (AtomCtx *, char **, AtomEntry **, size_t);
29 int (*is_feed) (AtomCtx *, char *);
30 AtomRequest * (*get_request) (AtomCtx *);
31 void (*handle_error) (AtomCtx *);
32 void (*handle_entry) (AtomCtx *, AtomEntry *);
33 void (*handle_feed) (AtomCtx *, AtomFeed *);
39 AtomFrontend *frontend;
40 frontend = g_slice_new (AtomFrontend);
41 frontend->map_entries = NULL;
42 frontend->is_feed = NULL;
43 frontend->get_request = NULL;
48 atom_frontend_delete (AtomFrontend *frontend)
50 g_slice_free (AtomFrontend, frontend);
54 atom_frontend_map_entries_set (AtomFrontend *frontend,
55 void map_entries (AtomCtx *,
60 frontend->map_entries = map_entries;
64 atom_frontend_is_feed_set (AtomFrontend *frontend,
65 int is_feed (AtomCtx *, char *))
67 frontend->is_feed = is_feed;
71 atom_frontend_get_request_set (AtomFrontend *frontend,
72 AtomRequest * get_request (AtomCtx *))
74 frontend->get_request = get_request;
78 atom_frontend_handle_error_set (AtomFrontend *frontend,
79 void handle_error (AtomCtx *))
81 frontend->handle_error = handle_error;
85 atom_frontend_handle_entry_set (AtomFrontend *frontend,
86 void handle_entry (AtomCtx *, AtomEntry *))
88 frontend->handle_entry = handle_entry;
92 atom_frontend_handle_feed_set (AtomFrontend *frontend,
93 void handle_feed (AtomCtx *, AtomFeed *))
95 frontend->handle_feed = handle_feed;
99 atom_frontend_map_entries (AtomCtx *ctx, char ** reqs,
100 AtomEntry ** entries, size_t len)
102 AtomFrontend *frontend;
103 frontend = atom_frontend (ctx);
104 if (frontend && frontend->map_entries)
106 frontend->map_entries (ctx, reqs, entries, len);
111 atom_is_feed (AtomCtx *ctx, char *req)
113 AtomFrontend *frontend;
115 frontend = atom_frontend (ctx);
116 if (frontend && frontend->is_feed)
118 return frontend->is_feed (ctx, req);
120 /* If frontend cannot decide if a request is a feed, let's tell it's
121 * not. If the request mapping cannot be done, it will return a "Not
122 * Found" error anyway.
128 atom_get_request (AtomCtx *ctx)
130 AtomFrontend *frontend;
131 frontend = atom_frontend (ctx);
132 if (frontend && frontend->get_request)
134 return frontend->get_request (ctx);
140 atom_handle_error (AtomCtx *ctx)
142 AtomFrontend *frontend;
143 frontend = atom_frontend (ctx);
144 if (frontend && frontend->handle_error)
146 frontend->handle_error (ctx);
151 atom_handle_entry (AtomCtx *ctx, AtomEntry *entry)
153 AtomFrontend *frontend;
154 frontend = atom_frontend (ctx);
155 if (frontend && frontend->handle_entry)
157 frontend->handle_entry (ctx, entry);
162 atom_handle_feed (AtomCtx *ctx, AtomFeed *feed)
164 AtomFrontend *frontend;
165 frontend = atom_frontend (ctx);
166 if (frontend && frontend->handle_feed)
168 frontend->handle_feed (ctx, feed);