/*
 * This file is part of Sargasso, http://zamez.org/sargasso
 * Licensed under the GNU General Public License,
 *                http://www.opensource.org/licenses/gpl-license
 * Copyright 2006 James Bursa <james@zamez.org>
 */

#ifndef FEED_H
#define FEED_H

#include <stdbool.h>
#include <curl/curl.h>
#include <libxml/parser.h>


#define FEED_MAX_ITEMS 50

typedef enum { FEED_NEW, FEED_FETCHING, FEED_OK, FEED_ERROR, FEED_UPDATE }
		feed_status;

struct feed {
	char *url;
	feed_status status;
	bool updated;
	const char *error;
	CURL *curl;
	struct curl_slist *headers;
	char *status_line;
	char *etag;
	unsigned int redirect_count;
	char *redirect;
	char *data;
	size_t data_size;
	xmlChar *title;
	xmlChar *description;
	xmlChar *link;
	xmlChar *copyright;
	xmlChar *pub_date;
	xmlChar *category;
	struct {
		xmlChar *title;
		xmlChar *description;
		xmlChar *link;
		xmlChar *author;
		xmlChar *pub_date;
		xmlChar *category;
		xmlChar *guid;
		bool new_item;
	} item[FEED_MAX_ITEMS];
	unsigned int item_count;
};

extern struct feed *feeds;
extern unsigned int feed_count;
extern bool feed_work_needed;
extern const char *feed_error;


bool feed_init(void);
void feed_quit(void);
bool feed_add(const char *url);
bool feed_remove(unsigned int i);
bool feed_work(void);
void feed_update(void);
bool feed_list_load(const char *path);
bool feed_list_save(const char *path);
void feed_print(struct feed *feed);


#endif
