From f874e4e44114b389f754af71a2b3d3935218b3ca Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Fri, 1 Jun 2007 11:37:19 +0000 Subject: [PATCH] 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 --- configure.ac.in | 4 ++-- src/rss.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/configure.ac.in b/configure.ac.in index fd80e452..792cda3c 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -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 diff --git a/src/rss.c b/src/rss.c index a6d5a780..e1c8c420 100644 --- a/src/rss.c +++ b/src/rss.c @@ -8,14 +8,42 @@ #include #include #include "prss.h" +#include +#include +#include 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; }