Bugfix: RSS interval was in secs instead of mins
[monky] / src / rss.c
index 667d35a..b7d20ec 100644 (file)
--- a/src/rss.c
+++ b/src/rss.c
@@ -1,11 +1,12 @@
 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
+ * vim: ts=4 sw=4 noet ai cindent syntax=c
  *
  * Conky, a system monitor, based on torsmo
  *
  * Please see COPYING for details
  *
  * Copyright (c) 2007 Toni Spets
- * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
+ * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
  *     (see AUTHORS)
  * All rights reserved.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * vim: ts=4 sw=4 noet ai cindent syntax=c
- *
  */
 
 #include "conky.h"
 #include "logging.h"
 #include "prss.h"
+#include "text_object.h"
 #include "ccurl_thread.h"
 #include <time.h>
 #include <assert.h>
 
+struct rss_data {
+       char uri[128];
+       char action[64];
+       int act_par;
+       float interval;
+       unsigned int nrspaces;
+};
+
 static ccurl_location_t *locations_head = 0;
 
 void rss_free_info(void)
@@ -45,7 +53,7 @@ void rss_free_info(void)
        ccurl_free_locations(&locations_head);
 }
 
-void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
+static void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
                act_par, int interval, unsigned int nrspaces)
 {
        PRSS *data;
@@ -59,7 +67,7 @@ void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
                curloc->result = malloc(sizeof(PRSS));
                memset(curloc->result, 0, sizeof(PRSS));
                curloc->process_function = &prss_parse_data;
-               ccurl_init_thread(curloc, interval);
+               ccurl_init_thread(curloc, interval * 60);
                if (!curloc->p_timed_thread) {
                        NORM_ERR("error setting up RSS thread");
                }
@@ -148,3 +156,40 @@ void rss_process_info(char *p, int p_max_size, char *uri, char *action, int
        timed_thread_unlock(curloc->p_timed_thread);
 }
 
+void rss_scan_arg(struct text_object *obj, const char *arg)
+{
+       int argc;
+       struct rss_data *rd;
+
+       rd = malloc(sizeof(struct rss_data));
+       memset(rd, 0, sizeof(struct rss_data));
+
+       argc = sscanf(arg, "%127s %f %63s %d %u", rd->uri, &rd->interval, rd->action,
+                       &rd->act_par, &rd->nrspaces);
+       if (argc < 3) {
+               NORM_ERR("wrong number of arguments for $rss");
+               free(rd);
+               return;
+       }
+       obj->data.opaque = rd;
+}
+
+void rss_print_info(struct text_object *obj, char *p, int p_max_size)
+{
+       struct rss_data *rd = obj->data.opaque;
+
+       if (!rd) {
+               NORM_ERR("error processing RSS data");
+               return;
+       }
+       rss_process_info(p, p_max_size, rd->uri, rd->action,
+                       rd->act_par, rd->interval, rd->nrspaces);
+}
+
+void rss_free_obj_info(struct text_object *obj)
+{
+       if (obj->data.opaque) {
+               free(obj->data.opaque);
+               obj->data.opaque = NULL;
+       }
+}