1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
3 * Conky, a system monitor, based on torsmo
5 * Please see COPYING for details
7 * Copyright (c) 2007 Toni Spets
8 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
10 * All rights reserved.
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * vim: ts=4 sw=4 noet ai cindent syntax=c
31 #include "ccurl_thread.h"
35 static ccurl_location_t *locations_head = 0;
37 void rss_free_info(void)
39 ccurl_location_t *tail = locations_head;
42 if (tail->result) prss_free((PRSS*)tail->result); /* clean up old data */
45 ccurl_free_locations(&locations_head);
48 void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
49 act_par, int interval, unsigned int nrspaces)
54 ccurl_location_t *curloc = ccurl_find_location(&locations_head, uri);
56 assert(act_par >= 0 && action);
58 if (!curloc->p_timed_thread) {
59 curloc->result = malloc(sizeof(PRSS));
60 memset(curloc->result, 0, sizeof(PRSS));
61 curloc->process_function = &prss_parse_data;
62 ccurl_init_thread(curloc, interval);
63 if (!curloc->p_timed_thread) {
64 NORM_ERR("error setting up RSS thread");
68 timed_thread_lock(curloc->p_timed_thread);
69 data = (PRSS*)curloc->result;
71 if (data == NULL || data->item_count < 1) {
75 * XXX: Refactor this so that we can retrieve any of the fields in the
76 * PRSS struct (in prss.h).
78 if (strcmp(action, "feed_title") == EQUAL) {
80 if (str && strlen(str) > 0) {
81 // remove trailing new line if one exists
82 if (str[strlen(str) - 1] == '\n') {
83 str[strlen(str) - 1] = 0;
85 snprintf(p, p_max_size, "%s", str);
87 } else if (strcmp(action, "item_title") == EQUAL) {
88 if (act_par < data->item_count) {
89 str = data->items[act_par].title;
90 // remove trailing new line if one exists
91 if (str && strlen(str) > 0) {
92 if (str[strlen(str) - 1] == '\n') {
93 str[strlen(str) - 1] = 0;
95 snprintf(p, p_max_size, "%s", str);
98 } else if (strcmp(action, "item_desc") == EQUAL) {
99 if (act_par < data->item_count) {
101 data->items[act_par].description;
102 // remove trailing new line if one exists
103 if (str && strlen(str) > 0) {
104 if (str[strlen(str) - 1] == '\n') {
105 str[strlen(str) - 1] = 0;
107 snprintf(p, p_max_size, "%s", str);
110 } else if (strcmp(action, "item_titles") == EQUAL) {
111 if (data->item_count > 0) {
114 //'tmpspaces' is a string with spaces too be placed in front of each title
115 char *tmpspaces = malloc(nrspaces + 1);
116 memset(tmpspaces, ' ', nrspaces);
117 tmpspaces[nrspaces]=0;
119 if (act_par > data->item_count) {
120 show = data->item_count;
124 for (itmp = 0; itmp < show; itmp++) {
125 PRSS_Item *item = &data->items[itmp];
129 // don't add new line before first item
131 strncat(p, "\n", p_max_size);
133 /* remove trailing new line if one exists,
135 if (strlen(str) > 0 && str[strlen(str) - 1] == '\n') {
136 str[strlen(str) - 1] = 0;
138 strncat(p, tmpspaces, p_max_size);
139 strncat(p, str, p_max_size);
145 NORM_ERR("rss: Invalid action '%s'", action);
148 timed_thread_unlock(curloc->p_timed_thread);