2009-07-28 21:44:22 +00:00
|
|
|
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2007-08-10 19:53:44 +00:00
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Toni Spets
|
2009-03-30 04:55:30 +00:00
|
|
|
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
2008-02-20 20:30:45 +00:00
|
|
|
* (see AUTHORS)
|
2007-08-10 19:53:44 +00:00
|
|
|
* 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
|
2008-02-20 20:30:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-08-10 19:53:44 +00:00
|
|
|
*
|
2009-07-27 20:47:19 +00:00
|
|
|
* vim: ts=4 sw=4 noet ai cindent syntax=c
|
|
|
|
*
|
2008-12-09 23:35:49 +00:00
|
|
|
*/
|
2007-05-06 12:59:31 +00:00
|
|
|
|
2008-03-29 12:44:29 +00:00
|
|
|
#include "conky.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "logging.h"
|
2008-03-29 12:44:29 +00:00
|
|
|
#include "prss.h"
|
2009-07-20 05:43:36 +00:00
|
|
|
#include "ccurl_thread.h"
|
2007-06-01 10:42:57 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <assert.h>
|
2007-05-06 12:59:31 +00:00
|
|
|
|
2009-07-20 05:43:36 +00:00
|
|
|
static ccurl_location_t *locations_head = 0;
|
2007-06-01 10:42:57 +00:00
|
|
|
|
2009-07-20 05:43:36 +00:00
|
|
|
void rss_free_info(void)
|
2007-05-06 12:59:31 +00:00
|
|
|
{
|
2009-07-20 05:43:36 +00:00
|
|
|
ccurl_location_t *tail = locations_head;
|
2007-05-06 12:59:31 +00:00
|
|
|
|
2009-07-20 05:43:36 +00:00
|
|
|
while (tail) {
|
|
|
|
if (tail->result) prss_free((PRSS*)tail->result); /* clean up old data */
|
|
|
|
tail = tail->next;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2009-07-20 05:43:36 +00:00
|
|
|
ccurl_free_locations(&locations_head);
|
2007-06-01 10:42:57 +00:00
|
|
|
}
|
|
|
|
|
2009-07-20 05:43:36 +00:00
|
|
|
void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
|
|
|
|
act_par, int interval, unsigned int nrspaces)
|
2007-06-03 11:20:47 +00:00
|
|
|
{
|
2009-07-20 05:43:36 +00:00
|
|
|
PRSS *data;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
ccurl_location_t *curloc = ccurl_find_location(&locations_head, uri);
|
|
|
|
if (!curloc->p_timed_thread) {
|
|
|
|
curloc->result = malloc(sizeof(PRSS));
|
|
|
|
memset(curloc->result, 0, sizeof(PRSS));
|
|
|
|
curloc->process_function = &prss_parse_data;
|
|
|
|
ccurl_init_thread(curloc, interval);
|
|
|
|
if (!curloc->p_timed_thread) {
|
2009-07-24 11:07:20 +00:00
|
|
|
ERR("error setting up RSS thread");
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-29 06:24:04 +00:00
|
|
|
|
2009-07-20 05:43:36 +00:00
|
|
|
timed_thread_lock(curloc->p_timed_thread);
|
|
|
|
data = (PRSS*)curloc->result;
|
|
|
|
|
|
|
|
if (data == NULL) {
|
|
|
|
snprintf(p, p_max_size, "prss: Error reading RSS data\n");
|
|
|
|
} else {
|
|
|
|
if (strcmp(action, "feed_title") == EQUAL) {
|
2009-07-24 14:17:03 +00:00
|
|
|
str = data->title;
|
|
|
|
if (str != NULL) {
|
2009-07-24 12:48:54 +00:00
|
|
|
// remove trailing new line if one exists
|
|
|
|
if (str[strlen(str) - 1] == '\n') {
|
|
|
|
str[strlen(str) - 1] = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", str);
|
2009-07-20 05:43:36 +00:00
|
|
|
}
|
|
|
|
} else if (strcmp(action, "item_title") == EQUAL) {
|
|
|
|
if (act_par < data->item_count) {
|
|
|
|
str = data->items[act_par].title;
|
|
|
|
// remove trailing new line if one exists
|
|
|
|
if (str[strlen(str) - 1] == '\n') {
|
|
|
|
str[strlen(str) - 1] = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", str);
|
|
|
|
}
|
|
|
|
} else if (strcmp(action, "item_desc") == EQUAL) {
|
|
|
|
if (act_par < data->item_count) {
|
|
|
|
str =
|
|
|
|
data->items[act_par].description;
|
|
|
|
// remove trailing new line if one exists
|
|
|
|
if (str[strlen(str) - 1] == '\n') {
|
|
|
|
str[strlen(str) - 1] = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", str);
|
|
|
|
}
|
|
|
|
} else if (strcmp(action, "item_titles") == EQUAL) {
|
|
|
|
if (data->item_count > 0) {
|
|
|
|
int itmp;
|
|
|
|
int show;
|
|
|
|
//'tmpspaces' is a string with spaces too be placed in front of each title
|
|
|
|
char *tmpspaces = malloc(nrspaces + 1);
|
|
|
|
memset(tmpspaces, ' ', nrspaces);
|
|
|
|
tmpspaces[nrspaces]=0;
|
|
|
|
|
|
|
|
p[0] = 0;
|
|
|
|
|
|
|
|
if (act_par > data->item_count) {
|
|
|
|
show = data->item_count;
|
|
|
|
} else {
|
|
|
|
show = act_par;
|
|
|
|
}
|
|
|
|
for (itmp = 0; itmp < show; itmp++) {
|
|
|
|
PRSS_Item *item = &data->items[itmp];
|
|
|
|
|
|
|
|
str = item->title;
|
|
|
|
if (str) {
|
|
|
|
// don't add new line before first item
|
|
|
|
if (itmp > 0) {
|
|
|
|
strncat(p, "\n", p_max_size);
|
|
|
|
}
|
|
|
|
/* remove trailing new line if one exists,
|
|
|
|
* we have our own */
|
|
|
|
if (str[strlen(str) - 1] == '\n') {
|
|
|
|
str[strlen(str) - 1] = 0;
|
|
|
|
}
|
|
|
|
strncat(p, tmpspaces, p_max_size);
|
|
|
|
strncat(p, str, p_max_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(tmpspaces);
|
2007-06-03 11:20:47 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-06-01 15:49:49 +00:00
|
|
|
}
|
2009-07-20 05:43:36 +00:00
|
|
|
timed_thread_unlock(curloc->p_timed_thread);
|
2007-05-06 12:59:31 +00:00
|
|
|
}
|
2009-07-20 05:43:36 +00:00
|
|
|
|