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);
55 if (!curloc->p_timed_thread) {
56 curloc->result = malloc(sizeof(PRSS));
57 memset(curloc->result, 0, sizeof(PRSS));
58 curloc->process_function = &prss_parse_data;
59 ccurl_init_thread(curloc, interval);
60 if (!curloc->p_timed_thread) {
61 NORM_ERR("error setting up RSS thread");
65 timed_thread_lock(curloc->p_timed_thread);
66 data = (PRSS*)curloc->result;
69 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
71 if (strcmp(action, "feed_title") == EQUAL) {
74 // remove trailing new line if one exists
75 if (str[strlen(str) - 1] == '\n') {
76 str[strlen(str) - 1] = 0;
78 snprintf(p, p_max_size, "%s", str);
80 } else if (strcmp(action, "item_title") == EQUAL) {
81 if (act_par < data->item_count) {
82 str = data->items[act_par].title;
83 // remove trailing new line if one exists
84 if (str[strlen(str) - 1] == '\n') {
85 str[strlen(str) - 1] = 0;
87 snprintf(p, p_max_size, "%s", str);
89 } else if (strcmp(action, "item_desc") == EQUAL) {
90 if (act_par < data->item_count) {
92 data->items[act_par].description;
93 // remove trailing new line if one exists
94 if (str[strlen(str) - 1] == '\n') {
95 str[strlen(str) - 1] = 0;
97 snprintf(p, p_max_size, "%s", str);
99 } else if (strcmp(action, "item_titles") == EQUAL) {
100 if (data->item_count > 0) {
103 //'tmpspaces' is a string with spaces too be placed in front of each title
104 char *tmpspaces = malloc(nrspaces + 1);
105 memset(tmpspaces, ' ', nrspaces);
106 tmpspaces[nrspaces]=0;
110 if (act_par > data->item_count) {
111 show = data->item_count;
115 for (itmp = 0; itmp < show; itmp++) {
116 PRSS_Item *item = &data->items[itmp];
120 // don't add new line before first item
122 strncat(p, "\n", p_max_size);
124 /* remove trailing new line if one exists,
126 if (str[strlen(str) - 1] == '\n') {
127 str[strlen(str) - 1] = 0;
129 strncat(p, tmpspaces, p_max_size);
130 strncat(p, str, p_max_size);
137 timed_thread_unlock(curloc->p_timed_thread);