* updated build system to link to libtorrent if --enable-bittorrent is passed to...
[libundertow.git] / src / undertow-feed.c
blob267edd08ea626222ed079387a56acbe21b41f8ea
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 */
22 #include <string.h>
23 #include <assert.h>
24 #include <libxml/parser.h>
26 #include "undertow-feed-rss-private.h"
27 #include "undertow-feed-atom-private.h"
28 #include "undertow-xmlutils.h"
30 static int
31 determine_mimetype (const char * url,
32 xmlDocPtr doc,
33 lut_channel ** channel,
34 lut_episode *** episodes,
35 size_t * n_episodes)
37 xmlNodePtr node;
39 if (doc->children == NULL)
40 return LUT_ERROR_FEED_INVALID;
41 node = doc->children;
42 while (node) {
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);
47 node = node->next;
49 return LUT_ERROR_FEED_INVALID;
52 int
53 lut_feed_load (const char * mimetype,
54 const char * url,
55 const char * buffer,
56 size_t buffer_size,
57 lut_channel ** channel,
58 lut_episode *** episodes,
59 size_t * n_episodes)
61 xmlDocPtr doc;
63 assert (url != NULL);
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);
70 if (doc == NULL)
71 return LUT_ERROR_FEED_INVALID;
72 if (mimetype) {
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);