diff --git a/doc/variables.xml b/doc/variables.xml index 40e99078..2505c701 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -657,7 +657,7 @@ - + Download data from URI using Curl at the diff --git a/src/ccurl_thread.c b/src/ccurl_thread.c index 52f3c454..c26487e1 100644 --- a/src/ccurl_thread.c +++ b/src/ccurl_thread.c @@ -26,6 +26,7 @@ #include "conky.h" #include "logging.h" #include "ccurl_thread.h" +#include "text_object.h" #ifdef DEBUG #include @@ -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); +} diff --git a/src/ccurl_thread.h b/src/ccurl_thread.h index eb48d325..594479c0 100644 --- a/src/ccurl_thread.h +++ b/src/ccurl_thread.h @@ -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_ */ diff --git a/src/conky.c b/src/conky.c index 7bf799af..69589951 100644 --- a/src/conky.c +++ b/src/conky.c @@ -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 diff --git a/src/core.c b/src/core.c index 4cfa856d..13e2536e 100644 --- a/src/core.c +++ b/src/core.c @@ -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: ") - 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: [act_par] [spaces in front]")