curl: put init and print code to where it belongs
authorPhil Sutter <phil@nwl.cc>
Sun, 4 Oct 2009 19:06:52 +0000 (21:06 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 12 Oct 2009 19:33:02 +0000 (21:33 +0200)
This also fixes a bug in arg parsing, effectively forcing an interval to
be specified.

doc/variables.xml
src/ccurl_thread.c
src/ccurl_thread.h
src/conky.c
src/core.c

index 40e9907..2505c70 100644 (file)
             <command>
                 <option>curl</option>
             </command>
-            <option>url interval_in_minutes</option>
+            <option>url (interval_in_minutes)</option>
         </term>
         <listitem>
             <para>Download data from URI using Curl at the
index 52f3c45..c26487e 100644 (file)
@@ -26,6 +26,7 @@
 #include "conky.h"
 #include "logging.h"
 #include "ccurl_thread.h"
+#include "text_object.h"
 
 #ifdef DEBUG
 #include <assert.h>
@@ -193,7 +194,7 @@ void ccurl_free_info(void)
 }
 
 /* straight copy, used by $curl */
-void ccurl_parse_data(void *result, const char *data)
+static void ccurl_parse_data(void *result, const char *data)
 {
        strncpy(result, data, max_user_text);
 }
@@ -217,3 +218,27 @@ void ccurl_process_info(char *p, int p_max_size, char *uri, int interval)
        timed_thread_unlock(curloc->p_timed_thread);
 }
 
+void curl_parse_arg(struct text_object *obj, const char *arg)
+{
+       int argc;
+       float interval = 0;
+       char *uri = (char *) malloc(128 * sizeof(char));
+
+       argc = sscanf(arg, "%127s %f", uri, &interval);
+       if (argc < 1) {
+               free(uri);
+               NORM_ERR("wrong number of arguments for $curl");
+               return;
+       }
+       obj->data.curl.uri = uri;
+       obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
+}
+
+void curl_print(struct text_object *obj, char *p, int p_max_size)
+{
+       if (!obj->data.curl.uri) {
+               NORM_ERR("error processing Curl data");
+               return;
+       }
+       ccurl_process_info(p, p_max_size, obj->data.curl.uri, obj->data.curl.interval);
+}
index eb48d32..594479c 100644 (file)
@@ -66,6 +66,9 @@ void ccurl_free_info(void);
 /* runs instance of $curl */
 void ccurl_process_info(char *p, int p_max_size, char *uri, int interval);
 
+void curl_parse_arg(struct text_object *, const char *);
+void curl_print(struct text_object *, char *, int);
+
 /* $curl exports end */
 
 #endif /* _CURL_THREAD_H_ */
index 7bf799a..6958995 100644 (file)
@@ -1833,11 +1833,7 @@ static void generate_text_internal(char *p, int p_max_size,
 #endif
 #ifdef HAVE_CURL
                        OBJ(curl) {
-                               if (obj->data.curl.uri != NULL) {
-                                       ccurl_process_info(p, p_max_size, obj->data.curl.uri, obj->data.curl.interval);
-                               } else {
-                                       NORM_ERR("error processing Curl data");
-                               }
+                               curl_print(obj, p, p_max_size);
                        }
 #endif
 #ifdef RSS
index 4cfa856..13e2536 100644 (file)
@@ -1449,17 +1449,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #endif
 #ifdef HAVE_CURL
        END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
-               int argc;
-               float interval = 0;
-               char *uri = (char *) malloc(128 * sizeof(char));
-
-               argc = sscanf(arg, "%127s %f", uri, &interval);
-               if (argc == 2) {
-                       obj->data.curl.uri = uri;
-                       obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
-               } else {
-                       NORM_ERR("wrong number of arguments for $curl");
-               }
+               curl_parse_arg(obj, arg);
 #endif
 #ifdef RSS
        END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")