mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 04:17:33 +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:
parent
ad8dd36cb7
commit
a106b52698
@ -657,7 +657,7 @@
|
|||||||
<command>
|
<command>
|
||||||
<option>curl</option>
|
<option>curl</option>
|
||||||
</command>
|
</command>
|
||||||
<option>url interval_in_minutes</option>
|
<option>url (interval_in_minutes)</option>
|
||||||
</term>
|
</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>Download data from URI using Curl at the
|
<para>Download data from URI using Curl at the
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "ccurl_thread.h"
|
#include "ccurl_thread.h"
|
||||||
|
#include "text_object.h"
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -193,7 +194,7 @@ void ccurl_free_info(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* straight copy, used by $curl */
|
/* 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);
|
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);
|
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);
|
||||||
|
}
|
||||||
|
@ -66,6 +66,9 @@ void ccurl_free_info(void);
|
|||||||
/* runs instance of $curl */
|
/* runs instance of $curl */
|
||||||
void ccurl_process_info(char *p, int p_max_size, char *uri, int interval);
|
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 */
|
/* $curl exports end */
|
||||||
|
|
||||||
#endif /* _CURL_THREAD_H_ */
|
#endif /* _CURL_THREAD_H_ */
|
||||||
|
@ -1833,11 +1833,7 @@ static void generate_text_internal(char *p, int p_max_size,
|
|||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CURL
|
#ifdef HAVE_CURL
|
||||||
OBJ(curl) {
|
OBJ(curl) {
|
||||||
if (obj->data.curl.uri != NULL) {
|
curl_print(obj, p, p_max_size);
|
||||||
ccurl_process_info(p, p_max_size, obj->data.curl.uri, obj->data.curl.interval);
|
|
||||||
} else {
|
|
||||||
NORM_ERR("error processing Curl data");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
|
12
src/core.c
12
src/core.c
@ -1449,17 +1449,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CURL
|
#ifdef HAVE_CURL
|
||||||
END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
|
END OBJ_ARG(curl, 0, "curl needs arguments: <uri> <interval in minutes>")
|
||||||
int argc;
|
curl_parse_arg(obj, arg);
|
||||||
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");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef RSS
|
#ifdef RSS
|
||||||
END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
|
END OBJ_ARG(rss, 0, "rss needs arguments: <uri> <interval in minutes> <action> [act_par] [spaces in front]")
|
||||||
|
Loading…
Reference in New Issue
Block a user