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/>.
22 * vim: ts=4 sw=4 noet ai cindent syntax=c
29 #include "ccurl_thread.h"
33 static ccurl_location_t *locations_head = 0;
35 void rss_free_info(void)
37 ccurl_location_t *tail = locations_head;
40 if (tail->result) prss_free((PRSS*)tail->result); /* clean up old data */
43 ccurl_free_locations(&locations_head);
46 void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
47 act_par, int interval, unsigned int nrspaces)
52 ccurl_location_t *curloc = ccurl_find_location(&locations_head, uri);
53 if (!curloc->p_timed_thread) {
54 curloc->result = malloc(sizeof(PRSS));
55 memset(curloc->result, 0, sizeof(PRSS));
56 curloc->process_function = &prss_parse_data;
57 ccurl_init_thread(curloc, interval);
58 if (!curloc->p_timed_thread) {
59 ERR("error setting up RSS thread");
63 timed_thread_lock(curloc->p_timed_thread);
64 data = (PRSS*)curloc->result;
67 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
69 if (strcmp(action, "feed_title") == EQUAL) {
72 // remove trailing new line if one exists
73 if (str[strlen(str) - 1] == '\n') {
74 str[strlen(str) - 1] = 0;
76 snprintf(p, p_max_size, "%s", str);
78 } else if (strcmp(action, "item_title") == EQUAL) {
79 if (act_par < data->item_count) {
80 str = data->items[act_par].title;
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_desc") == EQUAL) {
88 if (act_par < data->item_count) {
90 data->items[act_par].description;
91 // remove trailing new line if one exists
92 if (str[strlen(str) - 1] == '\n') {
93 str[strlen(str) - 1] = 0;
95 snprintf(p, p_max_size, "%s", str);
97 } else if (strcmp(action, "item_titles") == EQUAL) {
98 if (data->item_count > 0) {
101 //'tmpspaces' is a string with spaces too be placed in front of each title
102 char *tmpspaces = malloc(nrspaces + 1);
103 memset(tmpspaces, ' ', nrspaces);
104 tmpspaces[nrspaces]=0;
108 if (act_par > data->item_count) {
109 show = data->item_count;
113 for (itmp = 0; itmp < show; itmp++) {
114 PRSS_Item *item = &data->items[itmp];
118 // don't add new line before first item
120 strncat(p, "\n", p_max_size);
122 /* remove trailing new line if one exists,
124 if (str[strlen(str) - 1] == '\n') {
125 str[strlen(str) - 1] = 0;
127 strncat(p, tmpspaces, p_max_size);
128 strncat(p, str, p_max_size);
135 timed_thread_unlock(curloc->p_timed_thread);