1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-11 18:38:45 +00:00

curl: convert to generic object payload

This commit is contained in:
Phil Sutter 2009-10-04 21:17:43 +02:00
parent 4716969cc6
commit c45decda5e
4 changed files with 27 additions and 14 deletions

View File

@ -184,6 +184,11 @@ void *ccurl_thread(void *arg)
* This is where the $curl section begins. * This is where the $curl section begins.
*/ */
struct curl_data {
char uri[128];
float interval;
};
/* internal location pointer for use by $curl, no touchy */ /* internal location pointer for use by $curl, no touchy */
static ccurl_location_t *ccurl_locations_head = 0; static ccurl_location_t *ccurl_locations_head = 0;
@ -221,24 +226,37 @@ void ccurl_process_info(char *p, int p_max_size, char *uri, int interval)
void curl_parse_arg(struct text_object *obj, const char *arg) void curl_parse_arg(struct text_object *obj, const char *arg)
{ {
int argc; int argc;
struct curl_data *cd;
float interval = 0; float interval = 0;
char *uri = (char *) malloc(128 * sizeof(char));
argc = sscanf(arg, "%127s %f", uri, &interval); cd = malloc(sizeof(struct curl_data));
memset(cd, 0, sizeof(struct curl_data));
argc = sscanf(arg, "%127s %f", cd->uri, &interval);
if (argc < 1) { if (argc < 1) {
free(uri); free(cd);
NORM_ERR("wrong number of arguments for $curl"); NORM_ERR("wrong number of arguments for $curl");
return; return;
} }
obj->data.curl.uri = uri; cd->interval = interval > 0 ? interval * 60 : 15*60;
obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60; obj->data.opaque = cd;
} }
void curl_print(struct text_object *obj, char *p, int p_max_size) void curl_print(struct text_object *obj, char *p, int p_max_size)
{ {
if (!obj->data.curl.uri) { struct curl_data *cd = obj->data.opaque;
if (!cd || !cd->uri) {
NORM_ERR("error processing Curl data"); NORM_ERR("error processing Curl data");
return; return;
} }
ccurl_process_info(p, p_max_size, obj->data.curl.uri, obj->data.curl.interval); ccurl_process_info(p, p_max_size, cd->uri, cd->interval);
}
void curl_obj_free(struct text_object *obj)
{
if (obj->data.opaque) {
free(obj->data.opaque);
obj->data.opaque = NULL;
}
} }

View File

@ -68,6 +68,7 @@ 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_parse_arg(struct text_object *, const char *);
void curl_print(struct text_object *, char *, int); void curl_print(struct text_object *, char *, int);
void curl_obj_free(struct text_object *);
/* $curl exports end */ /* $curl exports end */

View File

@ -1549,7 +1549,7 @@ void free_text_objects(struct text_object *root, int internal)
#endif #endif
#ifdef HAVE_CURL #ifdef HAVE_CURL
case OBJ_curl: case OBJ_curl:
free(data.curl.uri); curl_obj_free(obj);
break; break;
#endif #endif
#ifdef RSS #ifdef RSS

View File

@ -487,12 +487,6 @@ struct text_object {
struct { struct {
int a, b; int a, b;
} pair; /* 2 */ } pair; /* 2 */
#ifdef HAVE_CURL
struct {
char *uri;
float interval;
} curl;
#endif
struct { struct {
char *text; char *text;
unsigned int show; unsigned int show;