mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-02-04 21:18:33 +00:00
Better argument handling for rss/curl/weather.
This commit is contained in:
parent
911eb4dc59
commit
d3013bc410
@ -50,6 +50,7 @@ ccurl_location_t *ccurl_find_location(ccurl_location_t **locations_head, char *u
|
|||||||
tail = tail->next;
|
tail = tail->next;
|
||||||
}
|
}
|
||||||
if (!tail) { /* new location!!!!!!! */
|
if (!tail) { /* new location!!!!!!! */
|
||||||
|
DBGP("new curl location: '%s'", uri);
|
||||||
new = malloc(sizeof(ccurl_location_t));
|
new = malloc(sizeof(ccurl_location_t));
|
||||||
memset(new, 0, sizeof(ccurl_location_t));
|
memset(new, 0, sizeof(ccurl_location_t));
|
||||||
new->uri = strndup(uri, text_buffer_size);
|
new->uri = strndup(uri, text_buffer_size);
|
||||||
@ -111,6 +112,7 @@ void ccurl_fetch_data(ccurl_location_t *curloc)
|
|||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if (curl) {
|
if (curl) {
|
||||||
|
DBGP("reading curl data from '%s'", curloc->uri);
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, curloc->uri);
|
curl_easy_setopt(curl, CURLOPT_URL, curloc->uri);
|
||||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
|
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback);
|
||||||
|
17
src/conky.c
17
src/conky.c
@ -2832,8 +2832,12 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
char *uri = (char *) malloc(128 * sizeof(char));
|
char *uri = (char *) malloc(128 * sizeof(char));
|
||||||
|
|
||||||
argc = sscanf(arg, "%127s %f", uri, &interval);
|
argc = sscanf(arg, "%127s %f", uri, &interval);
|
||||||
|
if (argc == 2) {
|
||||||
obj->data.curl.uri = uri;
|
obj->data.curl.uri = uri;
|
||||||
obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
|
obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
|
||||||
|
} else {
|
||||||
|
ERR("wrong number of arguments for $curl");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(obj, free_at_crash, "curl needs arguments: <uri> <interval in minutes>");
|
CRIT_ERR(obj, free_at_crash, "curl needs arguments: <uri> <interval in minutes>");
|
||||||
}
|
}
|
||||||
@ -2849,11 +2853,15 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
|
|
||||||
argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
|
argc = sscanf(arg, "%127s %f %63s %d %u", uri, &interval, action,
|
||||||
&act_par, &nrspaces);
|
&act_par, &nrspaces);
|
||||||
|
if (argc == 5) {
|
||||||
obj->data.rss.uri = uri;
|
obj->data.rss.uri = uri;
|
||||||
obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
|
obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
|
||||||
obj->data.rss.action = action;
|
obj->data.rss.action = action;
|
||||||
obj->data.rss.act_par = act_par;
|
obj->data.rss.act_par = act_par;
|
||||||
obj->data.rss.nrspaces = nrspaces;
|
obj->data.rss.nrspaces = nrspaces;
|
||||||
|
} else {
|
||||||
|
ERR("wrong number of arguments for $rss");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(obj, free_at_crash, "rss needs arguments: <uri> <interval in minutes> <action> "
|
CRIT_ERR(obj, free_at_crash, "rss needs arguments: <uri> <interval in minutes> <action> "
|
||||||
"[act_par] [spaces in front]");
|
"[act_par] [spaces in front]");
|
||||||
@ -2862,14 +2870,16 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
#ifdef WEATHER
|
#ifdef WEATHER
|
||||||
END OBJ(weather, 0)
|
END OBJ(weather, 0)
|
||||||
if (arg) {
|
if (arg) {
|
||||||
int argc, interval;
|
int argc;
|
||||||
|
float interval;
|
||||||
char *locID = (char *) malloc(9 * sizeof(char));
|
char *locID = (char *) malloc(9 * sizeof(char));
|
||||||
char *uri = (char *) malloc(128 * sizeof(char));
|
char *uri = (char *) malloc(128 * sizeof(char));
|
||||||
char *data_type = (char *) malloc(32 * sizeof(char));
|
char *data_type = (char *) malloc(32 * sizeof(char));
|
||||||
char *tmp_p;
|
char *tmp_p;
|
||||||
|
|
||||||
argc = sscanf(arg, "%119s %8s %31s %d", uri, locID, data_type, &interval);
|
argc = sscanf(arg, "%119s %8s %31s %f", uri, locID, data_type, &interval);
|
||||||
|
|
||||||
|
if (argc >= 3) {
|
||||||
/* locID MUST BE upper-case */
|
/* locID MUST BE upper-case */
|
||||||
tmp_p = locID;
|
tmp_p = locID;
|
||||||
while (*tmp_p) {
|
while (*tmp_p) {
|
||||||
@ -2908,6 +2918,9 @@ static struct text_object *construct_text_object(const char *s,
|
|||||||
|
|
||||||
DBGP("weather: fetching %s from %s every %d seconds", \
|
DBGP("weather: fetching %s from %s every %d seconds", \
|
||||||
data_type, uri, obj->data.weather.interval);
|
data_type, uri, obj->data.weather.interval);
|
||||||
|
} else {
|
||||||
|
ERR("wrong number of arguments for $weather");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
CRIT_ERR(obj, free_at_crash, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]");
|
CRIT_ERR(obj, free_at_crash, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user