1 /* libundertow - undertow-feed.c
2 * Copyright (C) 2008 Michael Frank <msfrank@syntaxjockey.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 /**\file undertow-feed.c */
24 #include <libxml/parser.h>
26 #include "undertow-feed-rss-private.h"
27 #include "undertow-feed-atom-private.h"
28 #include "undertow-xmlutils.h"
31 determine_mimetype (const char * url
,
33 lut_channel
** channel
,
34 lut_episode
*** episodes
,
39 if (doc
->children
== NULL
)
40 return LUT_ERROR_FEED_INVALID
;
43 if (LUT_XML_IS_ELEMENT (node
, "feed"))
44 return lut_feed_atom_parse (url
, doc
, channel
, episodes
, n_episodes
);
45 if (LUT_XML_IS_ELEMENT (node
, "rss"))
46 return lut_feed_rss_parse (url
, doc
, channel
, episodes
, n_episodes
);
49 return LUT_ERROR_FEED_INVALID
;
53 lut_feed_load (const char * mimetype
,
57 lut_channel
** channel
,
58 lut_episode
*** episodes
,
64 assert (buffer
!= NULL
);
65 assert (channel
!= NULL
);
66 assert (episodes
!= NULL
);
67 assert (n_episodes
!= NULL
);
69 doc
= xmlReadMemory (buffer
, buffer_size
, "noname.xml", NULL
, 0);
71 return LUT_ERROR_FEED_INVALID
;
73 if (!strcmp (mimetype
, "application/rss+xml"))
74 return lut_feed_rss_parse (url
, doc
, channel
, episodes
, n_episodes
);
75 if (!strcmp (mimetype
, "application/atom+xml"))
76 return lut_feed_atom_parse (url
, doc
, channel
, episodes
, n_episodes
);
77 /* let other mimetypes fall thru to heuristic matching */
79 return determine_mimetype (url
, doc
, channel
, episodes
, n_episodes
);