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 *);
34 void (*handle_publish) (AtomCtx *, AtomEntry *);
40 AtomFrontend *frontend;
41 frontend = g_slice_new (AtomFrontend);
42 frontend->map_entries = NULL;
43 frontend->is_feed = NULL;
44 frontend->get_request = NULL;
45 frontend->handle_error = NULL;
46 frontend->handle_entry = NULL;
47 frontend->handle_feed = NULL;
48 frontend->handle_publish = NULL;
53 atom_frontend_delete (AtomFrontend *frontend)
55 g_slice_free (AtomFrontend, frontend);
59 atom_frontend_map_entries_set (AtomFrontend *frontend,
60 void map_entries (AtomCtx *,
65 frontend->map_entries = map_entries;
69 atom_frontend_is_feed_set (AtomFrontend *frontend,
70 int is_feed (AtomCtx *, char *))
72 frontend->is_feed = is_feed;
76 atom_frontend_get_request_set (AtomFrontend *frontend,
77 AtomRequest * get_request (AtomCtx *))
79 frontend->get_request = get_request;
83 atom_frontend_handle_error_set (AtomFrontend *frontend,
84 void handle_error (AtomCtx *))
86 frontend->handle_error = handle_error;
90 atom_frontend_handle_entry_set (AtomFrontend *frontend,
91 void handle_entry (AtomCtx *, AtomEntry *))
93 frontend->handle_entry = handle_entry;
97 atom_frontend_handle_feed_set (AtomFrontend *frontend,
98 void handle_feed (AtomCtx *, AtomFeed *))
100 frontend->handle_feed = handle_feed;
104 atom_frontend_handle_publish_set (AtomFrontend *frontend,
105 void handle_publish (AtomCtx *, AtomEntry *))
107 frontend->handle_publish = handle_publish;
111 atom_frontend_map_entries (AtomCtx *ctx, char ** reqs,
112 AtomEntry ** entries, size_t len)
114 AtomFrontend *frontend;
115 frontend = atom_frontend (ctx);
116 if (frontend && frontend->map_entries)
118 frontend->map_entries (ctx, reqs, entries, len);
123 atom_is_feed (AtomCtx *ctx, char *req)
125 AtomFrontend *frontend;
127 frontend = atom_frontend (ctx);
128 if (frontend && frontend->is_feed)
130 return frontend->is_feed (ctx, req);
132 /* If frontend cannot decide if a request is a feed, let's tell it's
133 * not. If the request mapping cannot be done, it will return a "Not
134 * Found" error anyway.
140 atom_get_request (AtomCtx *ctx)
142 AtomFrontend *frontend;
143 frontend = atom_frontend (ctx);
144 if (frontend && frontend->get_request)
146 return frontend->get_request (ctx);
152 atom_handle_error (AtomCtx *ctx)
154 AtomFrontend *frontend;
155 frontend = atom_frontend (ctx);
156 if (frontend && frontend->handle_error)
158 frontend->handle_error (ctx);
163 atom_handle_entry (AtomCtx *ctx, AtomEntry *entry)
165 AtomFrontend *frontend;
166 frontend = atom_frontend (ctx);
167 if (frontend && frontend->handle_entry)
169 frontend->handle_entry (ctx, entry);
174 atom_handle_feed (AtomCtx *ctx, AtomFeed *feed)
176 AtomFrontend *frontend;
177 frontend = atom_frontend (ctx);
178 if (frontend && frontend->handle_feed)
180 frontend->handle_feed (ctx, feed);
185 atom_handle_publish (AtomCtx *ctx, AtomEntry *entry)
187 AtomFrontend *frontend;
188 frontend = atom_frontend (ctx);
189 if (frontend && frontend->handle_publish)
191 frontend->handle_publish (ctx, entry);