1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 12:10:03 +00:00

curl: put init and print code to where it belongs

This also fixes a bug in arg parsing, effectively forcing an interval to
be specified.
This commit is contained in:
Phil Sutter 2009-10-04 21:06:52 +02:00
parent ad8dd36cb7
commit a106b52698
5 changed files with 32 additions and 18 deletions

View File

@ -657,7 +657,7 @@
<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

View 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);
}

View 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_ */

View 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

View 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]")