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;
44 frontend->handle_error = NULL;
45 frontend->handle_entry = NULL;
46 frontend->handle_feed = NULL;
51 atom_frontend_delete (AtomFrontend *frontend)
53 g_slice_free (AtomFrontend, frontend);
57 atom_frontend_map_entries_set (AtomFrontend *frontend,
58 void map_entries (AtomCtx *,
63 frontend->map_entries = map_entries;
67 atom_frontend_is_feed_set (AtomFrontend *frontend,
68 int is_feed (AtomCtx *, char *))
70 frontend->is_feed = is_feed;
74 atom_frontend_get_request_set (AtomFrontend *frontend,
75 AtomRequest * get_request (AtomCtx *))
77 frontend->get_request = get_request;
81 atom_frontend_handle_error_set (AtomFrontend *frontend,
82 void handle_error (AtomCtx *))
84 frontend->handle_error = handle_error;
88 atom_frontend_handle_entry_set (AtomFrontend *frontend,
89 void handle_entry (AtomCtx *, AtomEntry *))
91 frontend->handle_entry = handle_entry;
95 atom_frontend_handle_feed_set (AtomFrontend *frontend,
96 void handle_feed (AtomCtx *, AtomFeed *))
98 frontend->handle_feed = handle_feed;
102 atom_frontend_map_entries (AtomCtx *ctx, char ** reqs,
103 AtomEntry ** entries, size_t len)
105 AtomFrontend *frontend;
106 frontend = atom_frontend (ctx);
107 if (frontend && frontend->map_entries)
109 frontend->map_entries (ctx, reqs, entries, len);
114 atom_is_feed (AtomCtx *ctx, char *req)
116 AtomFrontend *frontend;
118 frontend = atom_frontend (ctx);
119 if (frontend && frontend->is_feed)
121 return frontend->is_feed (ctx, req);
123 /* If frontend cannot decide if a request is a feed, let's tell it's
124 * not. If the request mapping cannot be done, it will return a "Not
125 * Found" error anyway.
131 atom_get_request (AtomCtx *ctx)
133 AtomFrontend *frontend;
134 frontend = atom_frontend (ctx);
135 if (frontend && frontend->get_request)
137 return frontend->get_request (ctx);
143 atom_handle_error (AtomCtx *ctx)
145 AtomFrontend *frontend;
146 frontend = atom_frontend (ctx);
147 if (frontend && frontend->handle_error)
149 frontend->handle_error (ctx);
154 atom_handle_entry (AtomCtx *ctx, AtomEntry *entry)
156 AtomFrontend *frontend;
157 frontend = atom_frontend (ctx);
158 if (frontend && frontend->handle_entry)
160 frontend->handle_entry (ctx, entry);
165 atom_handle_feed (AtomCtx *ctx, AtomFeed *feed)
167 AtomFrontend *frontend;
168 frontend = atom_frontend (ctx);
169 if (frontend && frontend->handle_feed)
171 frontend->handle_feed (ctx, feed);