1 /* Conky, a system monitor, based on torsmo
3 * Please see COPYING for details
5 * Copyright (c) 2007 Toni Spets
6 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "ccurl_thread.h"
31 static ccurl_location_t *locations_head = 0;
33 void rss_free_info(void)
35 ccurl_location_t *tail = locations_head;
38 if (tail->result) prss_free((PRSS*)tail->result); /* clean up old data */
41 ccurl_free_locations(&locations_head);
44 void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
45 act_par, int interval, unsigned int nrspaces)
50 ccurl_location_t *curloc = ccurl_find_location(&locations_head, uri);
51 if (!curloc->p_timed_thread) {
52 curloc->result = malloc(sizeof(PRSS));
53 memset(curloc->result, 0, sizeof(PRSS));
54 curloc->process_function = &prss_parse_data;
55 ccurl_init_thread(curloc, interval);
56 if (!curloc->p_timed_thread) {
57 ERR("error setting up RSS thread");
61 timed_thread_lock(curloc->p_timed_thread);
62 data = (PRSS*)curloc->result;
65 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
67 if (strcmp(action, "feed_title") == EQUAL) {
68 if (str = data->title) {
69 // remove trailing new line if one exists
70 if (str[strlen(str) - 1] == '\n') {
71 str[strlen(str) - 1] = 0;
73 snprintf(p, p_max_size, "%s", str);
75 } else if (strcmp(action, "item_title") == EQUAL) {
76 if (act_par < data->item_count) {
77 str = data->items[act_par].title;
78 // remove trailing new line if one exists
79 if (str[strlen(str) - 1] == '\n') {
80 str[strlen(str) - 1] = 0;
82 snprintf(p, p_max_size, "%s", str);
84 } else if (strcmp(action, "item_desc") == EQUAL) {
85 if (act_par < data->item_count) {
87 data->items[act_par].description;
88 // remove trailing new line if one exists
89 if (str[strlen(str) - 1] == '\n') {
90 str[strlen(str) - 1] = 0;
92 snprintf(p, p_max_size, "%s", str);
94 } else if (strcmp(action, "item_titles") == EQUAL) {
95 if (data->item_count > 0) {
98 //'tmpspaces' is a string with spaces too be placed in front of each title
99 char *tmpspaces = malloc(nrspaces + 1);
100 memset(tmpspaces, ' ', nrspaces);
101 tmpspaces[nrspaces]=0;
105 if (act_par > data->item_count) {
106 show = data->item_count;
110 for (itmp = 0; itmp < show; itmp++) {
111 PRSS_Item *item = &data->items[itmp];
115 // don't add new line before first item
117 strncat(p, "\n", p_max_size);
119 /* remove trailing new line if one exists,
121 if (str[strlen(str) - 1] == '\n') {
122 str[strlen(str) - 1] = 0;
124 strncat(p, tmpspaces, p_max_size);
125 strncat(p, str, p_max_size);
132 timed_thread_unlock(curloc->p_timed_thread);