1 /*
2  * Copyright (C) 2006 Andrej Kacian <andrej@kacian.sk>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
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 GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 #ifndef __FEED_H
21 #define __FEED_H
22 
23 #include <glib.h>
24 #include <expat.h>
25 
26 #define FEED_DEFAULT_TIMEOUT	20	/* In seconds */
27 
28 /* ---------------- Structures */
29 
30 typedef struct _Feed Feed;
31 typedef struct _FeedItem FeedItem;
32 typedef struct _FeedParserCtx FeedParserCtx;
33 typedef struct _FeedAuth FeedAuth;
34 
35 typedef enum {
36 	FEED_AUTH_NONE,
37 	FEED_AUTH_BASIC
38 } FeedAuthType;
39 
40 struct _FeedAuth {
41 	FeedAuthType type;
42 	gchar *username;
43 	gchar *password;
44 };
45 
46 struct _Feed {
47 	gchar *url;
48 	FeedAuth *auth;
49 	gboolean is_valid;
50 	gchar *title;
51 	gchar *description;
52 	gchar *language;
53 	gchar *author;
54 	gchar *generator;
55 	gchar *link;
56 	time_t date;
57 
58 	guint timeout;
59 	gchar *fetcherr;
60 	gchar *cookies_path;
61 	gboolean ssl_verify_peer;
62 	gchar *cacert_file;
63 
64 	GSList *items;
65 };
66 
67 struct _FeedParserCtx {
68 	XML_Parser parser;
69 	guint depth;
70 	guint location;
71 	GString *str;
72 	GString *xhtml_str;
73 	gchar *name;
74 	gchar *mail;
75 	gboolean id_is_permalink;
76 
77 	Feed *feed;
78 	FeedItem *curitem;
79 };
80 
81 typedef enum {
82 	FEED_ERR_NOFEED,
83 	FEED_ERR_NOURL,
84 	FEED_ERR_INIT,
85 	FEED_ERR_FETCH,
86 	FEED_ERR_UNAUTH
87 } FeedErrCodes;
88 
89 /* ---------------- Prototypes */
90 
91 Feed *feed_new(gchar *url);
92 void feed_free(Feed *feed);
93 
94 void feed_free_items(Feed *feed);
95 
96 void feed_set_timeout(Feed *feed, guint timeout);
97 guint feed_get_timeout(Feed *feed);
98 
99 void feed_set_url(Feed *feed, gchar *url);
100 gchar *feed_get_url(Feed *feed);
101 
102 void feed_set_auth(Feed *feed, FeedAuth *auth);
103 FeedAuth *feed_get_auth(Feed *feed);
104 
105 gchar *feed_get_title(Feed *feed);
106 void feed_set_title(Feed *feed, gchar *new_title);
107 
108 gchar *feed_get_description(Feed *feed);
109 gchar *feed_get_language(Feed *feed);
110 gchar *feed_get_author(Feed *feed);
111 gchar *feed_get_generator(Feed *feed);
112 gchar *feed_get_link(Feed *feed);
113 gchar *feed_get_fetcherror(Feed *feed);
114 
115 gchar *feed_get_cookies_path(Feed *feed);
116 void feed_set_cookies_path(Feed *feed, gchar *path);
117 
118 gboolean feed_get_ssl_verify_peer(Feed *feed);
119 void feed_set_ssl_verify_peer(Feed *feed, gboolean ssl_verify_peer);
120 
121 gchar *feed_get_cacert_file(Feed *feed);
122 void feed_set_cacert_file(Feed *feed, const gchar *path);
123 
124 gint feed_n_items(Feed *feed);
125 FeedItem *feed_nth_item(Feed *feed, guint n);
126 
127 void feed_foreach_item(Feed *feed, GFunc func, gpointer data);
128 
129 gboolean feed_prepend_item(Feed *feed, FeedItem *item);
130 gboolean feed_append_item(Feed *feed, FeedItem *item);
131 gboolean feed_insert_item(Feed *feed, FeedItem *item, gint pos);
132 
133 guint feed_update(Feed *feed, time_t last_update);
134 
135 #define FILL(n)		do { g_free(n); n = g_strdup(text); } while(0);
136 
137 #include "feeditem.h"
138 
139 #endif /* __FEED_H */
140