X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Frss.c;h=64222abdd52644402d2844318eab259e724ae579;hb=f5259295cf4ae642fc3c90151e5aab218aedf85b;hp=4e40db89f5becb370171f54239772362b71b23af;hpb=f5c69ca5a54c6923cf77b7c23cf1143fb0465a23;p=monky
diff --git a/src/rss.c b/src/rss.c
index 4e40db8..64222ab 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -1,20 +1,34 @@
-/*
- * rss.c
- * RSS stuff (prss version)
+/* Conky, a system monitor, based on torsmo
*
- * prss.c and prss.h written by Sisu (Mikko Sysikaski)
- * new rss.c written by hifi (Toni Spets)
- */
+ * Any original torsmo code is licensed under the BSD license
+ *
+ * All code written since the fork of torsmo is licensed under the GPL
+ *
+ * Please see COPYING for details
+ *
+ * Copyright (c) 2007 Toni Spets
+ * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
+ * (see AUTHORS)
+ * All rights reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * $Id$ */
#include "conky.h"
-
-#ifdef RSS
-
-#include
-#include
+#include "prss.h"
#include
#include
-#include "prss.h"
#include
#include
#include
@@ -27,21 +41,20 @@ struct MemoryStruct {
};
typedef struct feed_ {
- char* uri;
+ char *uri;
int last_update;
- PRSS* data;
+ PRSS *data;
} feed;
int num_feeds = 0;
feed feeds[MAX_FEEDS];
-size_t
-WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
+size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
size_t realsize = size * nmemb;
- struct MemoryStruct *mem = (struct MemoryStruct *)data;
+ struct MemoryStruct *mem = (struct MemoryStruct *) data;
- mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
+ mem->memory = (char *) realloc(mem->memory, mem->size + realsize + 1);
if (mem->memory) {
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
@@ -50,55 +63,55 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
return realsize;
}
-
-int rss_delay(int *wait, int delay)
+int rss_delay(int *wait_time, int delay)
{
time_t now = time(NULL);
// make it minutes
- if(delay < 1) delay = 1;
+ if (delay < 1) {
+ delay = 1;
+ }
delay *= 60;
- if(!*wait) {
- *wait = now + delay;
+ if (!*wait_time) {
+ *wait_time = now + delay;
return 1;
}
- if(now >= *wait + delay) {
- *wait = now + delay;
+ if (now >= *wait_time + delay) {
+ *wait_time = now + delay;
return 1;
}
return 0;
}
-void init_rss_info()
+void init_rss_info(void)
{
int i;
- for(i = 0; i < MAX_FEEDS; i++) {
+
+ for (i = 0; i < MAX_FEEDS; i++) {
feeds[i].uri = NULL;
feeds[i].data = NULL;
feeds[i].last_update = 0;
}
}
-void free_rss_info()
+void free_rss_info(void)
{
int i;
- for(i = 0; i < num_feeds; i++)
- if(feeds[i].uri != NULL)
+
+ for (i = 0; i < num_feeds; i++) {
+ if (feeds[i].uri != NULL) {
free(feeds[i].uri);
+ }
+ }
}
-PRSS*
-get_rss_info(char *uri, int delay)
+PRSS *get_rss_info(char *uri, int delay)
{
CURL *curl = NULL;
CURLcode res;
- // curl temps
- struct MemoryStruct chunk;
- chunk.memory = NULL;
- chunk.size = 0;
// pointers to struct
feed *curfeed = NULL;
@@ -107,47 +120,58 @@ get_rss_info(char *uri, int delay)
int i;
+ // curl temps
+ struct MemoryStruct chunk;
+
+ chunk.memory = NULL;
+ chunk.size = 0;
+
// first seek for the uri in list
- for(i = 0; i < num_feeds; i++) {
- if(feeds[i].uri != NULL)
- if(!strcmp(feeds[i].uri, uri)) {
+ for (i = 0; i < num_feeds; i++) {
+ if (feeds[i].uri != NULL) {
+ if (!strcmp(feeds[i].uri, uri)) {
curfeed = &feeds[i];
break;
}
+ }
}
- if(!curfeed) { // new feed
- if(num_feeds == MAX_FEEDS-1) return NULL;
+ if (!curfeed) { // new feed
+ if (num_feeds == MAX_FEEDS - 1) {
+ return NULL;
+ }
curfeed = &feeds[num_feeds];
- curfeed->uri = strdup(uri);
+ curfeed->uri = strndup(uri, text_buffer_size);
num_feeds++;
}
last_update = &curfeed->last_update;
curdata = curfeed->data;
- if(!rss_delay(last_update, delay))
- return curdata; // wait for delay to pass
+ if (!rss_delay(last_update, delay)) {
+ return curdata; // wait for delay to pass
+ }
- if(curdata != NULL) {
- prss_free(curdata); // clean up old data
+ if (curdata != NULL) {
+ prss_free(curdata); // clean up old data
curdata = NULL;
}
curl = curl_easy_init();
- if(curl) {
+ 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_WRITEDATA, (void *) &chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-rss/1.0");
res = curl_easy_perform(curl);
- if(chunk.size) {
+ if (chunk.size) {
curdata = prss_parse_data(chunk.memory);
free(chunk.memory);
- } else
+ } else {
ERR("No data from server");
+ }
curl_easy_cleanup(curl);
}
@@ -156,5 +180,3 @@ get_rss_info(char *uri, int delay)
return curdata;
}
-
-#endif