1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 12:10:03 +00:00

libcurl support added to download RSS feeds (automake and autoconf scripts still needs updating)

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@869 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Toni Spets 2007-06-01 11:37:19 +00:00
parent 3fdb6b7027
commit f874e4e441
2 changed files with 52 additions and 4 deletions

View File

@ -190,8 +190,8 @@ AC_ARG_ENABLE([rss],
AM_CONDITIONAL(BUILD_RSS, test x$want_rss = xyes)
if test x$want_rss = xyes; then
WANT_GLIB=yes
CFLAGS="$CFLAGS `xml2-config --cflags`"
LIBS="$LIBS `xml2-config --libs`"
CFLAGS="$CFLAGS `xml2-config --cflags` `curl-config --cflags`"
LIBS="$LIBS `xml2-config --libs` `curl-config --libs`"
AC_DEFINE(RSS, 1, [Define if you want rss support])
fi

View File

@ -8,14 +8,42 @@
#include <time.h>
#include <assert.h>
#include "prss.h"
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
PRSS* save = NULL;
struct MemoryStruct {
char *memory;
size_t size;
};
size_t
WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)data;
mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
if (mem->memory) {
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
}
return realsize;
}
int rss_delay(int delay)
{
static int wait = 0;
time_t now = time(NULL);
// make it minutes
if(delay < 1) delay = 1;
//delay *= 60;
if(!wait) {
wait = now + delay;
return 1;
@ -32,14 +60,34 @@ int rss_delay(int delay)
PRSS*
get_rss_info(char *uri, int delay)
{
CURL *curl = NULL;
CURLcode res;
struct MemoryStruct chunk;
chunk.memory = NULL;
chunk.size = 0;
if(!rss_delay(delay))
return save; // wait for delay to pass
if(save != NULL)
prss_free(save); // clean up old data
save = prss_parse_file("test.xml");
//assert(save);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, uri);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-rss/1.0");
res = curl_easy_perform(curl);
if(chunk.size) {
save = prss_parse_data(chunk.memory);
free(chunk.memory);
}
curl_easy_cleanup(curl);
}
return save;
}