1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2 * vim: ts=4 sw=4 noet ai cindent syntax=c
4 * Conky, a system monitor, based on torsmo
6 * Please see COPYING for details
8 * Copyright (c) 2007 Toni Spets
9 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
11 * All rights reserved.
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include "ccurl_thread.h"
34 static ccurl_location_t *locations_head = 0;
36 void rss_free_info(void)
38 ccurl_location_t *tail = locations_head;
41 if (tail->result) prss_free((PRSS*)tail->result); /* clean up old data */
44 ccurl_free_locations(&locations_head);
47 void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
48 act_par, int interval, unsigned int nrspaces)
53 ccurl_location_t *curloc = ccurl_find_location(&locations_head, uri);
55 assert(act_par >= 0 && action);
57 if (!curloc->p_timed_thread) {
58 curloc->result = malloc(sizeof(PRSS));
59 memset(curloc->result, 0, sizeof(PRSS));
60 curloc->process_function = &prss_parse_data;
61 ccurl_init_thread(curloc, interval);
62 if (!curloc->p_timed_thread) {
63 NORM_ERR("error setting up RSS thread");
67 timed_thread_lock(curloc->p_timed_thread);
68 data = (PRSS*)curloc->result;
70 if (data == NULL || data->item_count < 1) {
74 * XXX: Refactor this so that we can retrieve any of the fields in the
75 * PRSS struct (in prss.h).
77 if (strcmp(action, "feed_title") == EQUAL) {
79 if (str && strlen(str) > 0) {
80 // remove trailing new line if one exists
81 if (str[strlen(str) - 1] == '\n') {
82 str[strlen(str) - 1] = 0;
84 snprintf(p, p_max_size, "%s", str);
86 } else if (strcmp(action, "item_title") == EQUAL) {
87 if (act_par < data->item_count) {
88 str = data->items[act_par].title;
89 // remove trailing new line if one exists
90 if (str && strlen(str) > 0) {
91 if (str[strlen(str) - 1] == '\n') {
92 str[strlen(str) - 1] = 0;
94 snprintf(p, p_max_size, "%s", str);
97 } else if (strcmp(action, "item_desc") == EQUAL) {
98 if (act_par < data->item_count) {
100 data->items[act_par].description;
101 // remove trailing new line if one exists
102 if (str && strlen(str) > 0) {
103 if (str[strlen(str) - 1] == '\n') {
104 str[strlen(str) - 1] = 0;
106 snprintf(p, p_max_size, "%s", str);
109 } else if (strcmp(action, "item_titles") == EQUAL) {
110 if (data->item_count > 0) {
113 //'tmpspaces' is a string with spaces too be placed in front of each title
114 char *tmpspaces = malloc(nrspaces + 1);
115 memset(tmpspaces, ' ', nrspaces);
116 tmpspaces[nrspaces]=0;
118 if (act_par > data->item_count) {
119 show = data->item_count;
123 for (itmp = 0; itmp < show; itmp++) {
124 PRSS_Item *item = &data->items[itmp];
128 // don't add new line before first item
130 strncat(p, "\n", p_max_size);
132 /* remove trailing new line if one exists,
134 if (strlen(str) > 0 && str[strlen(str) - 1] == '\n') {
135 str[strlen(str) - 1] = 0;
137 strncat(p, tmpspaces, p_max_size);
138 strncat(p, str, p_max_size);
144 NORM_ERR("rss: Invalid action '%s'", action);
147 timed_thread_unlock(curloc->p_timed_thread);