Better argument handling for rss/curl/weather.
authorBrenden Matthews <brenden@rty.ca>
Mon, 20 Jul 2009 15:59:31 +0000 (09:59 -0600)
committerBrenden Matthews <brenden@rty.ca>
Mon, 20 Jul 2009 15:59:31 +0000 (09:59 -0600)
src/ccurl_thread.c
src/conky.c

index d9d9717..70a925f 100644 (file)
@@ -50,6 +50,7 @@ ccurl_location_t *ccurl_find_location(ccurl_location_t **locations_head, char *u
                tail = tail->next;
        }
        if (!tail) { /* new location!!!!!!! */
+               DBGP("new curl location: '%s'", uri);
                new = malloc(sizeof(ccurl_location_t));
                memset(new, 0, sizeof(ccurl_location_t));
                new->uri = strndup(uri, text_buffer_size);
@@ -111,6 +112,7 @@ void ccurl_fetch_data(ccurl_location_t *curloc)
 
        curl = curl_easy_init();
        if (curl) {
+               DBGP("reading curl data from '%s'", curloc->uri);
                curl_easy_setopt(curl, CURLOPT_URL, curloc->uri);
                curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback);
index 87cacb2..136773c 100644 (file)
@@ -2832,8 +2832,12 @@ static struct text_object *construct_text_object(const char *s,
                        char *uri = (char *) malloc(128 * sizeof(char));
 
                        argc = sscanf(arg, "%127s %f", uri, &interval);
-                       obj->data.curl.uri = uri;
-                       obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
+                       if (argc == 2) {
+                               obj->data.curl.uri = uri;
+                               obj->data.curl.interval = interval > 0 ? interval * 60 : 15*60;
+                       } else {
+                               ERR("wrong number of arguments for $curl");
+                       }
                } else {
                        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,
                                        &act_par, &nrspaces);
-                       obj->data.rss.uri = uri;
-                       obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
-                       obj->data.rss.action = action;
-                       obj->data.rss.act_par = act_par;
-                       obj->data.rss.nrspaces = nrspaces;
+                       if (argc == 5) {
+                               obj->data.rss.uri = uri;
+                               obj->data.rss.interval = interval > 0 ? interval * 60 : 15*60;
+                               obj->data.rss.action = action;
+                               obj->data.rss.act_par = act_par;
+                               obj->data.rss.nrspaces = nrspaces;
+                       } else {
+                               ERR("wrong number of arguments for $rss");
+                       }
                } else {
                        CRIT_ERR(obj, free_at_crash, "rss needs arguments: <uri> <interval in minutes> <action> "
                                        "[act_par] [spaces in front]");
@@ -2862,52 +2870,57 @@ static struct text_object *construct_text_object(const char *s,
 #ifdef WEATHER
        END OBJ(weather, 0)
                if (arg) {
-                       int argc, interval;
+                       int argc;
+                       float interval;
                        char *locID = (char *) malloc(9 * sizeof(char));
                        char *uri = (char *) malloc(128 * sizeof(char));
                        char *data_type = (char *) malloc(32 * sizeof(char));
                        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);
 
-                       /* locID MUST BE upper-case */
-                       tmp_p = locID;
-                       while (*tmp_p) {
-                         *tmp_p = toupper(*tmp_p);
-                         tmp_p++;
-                       }
+                       if (argc >= 3) {
+                               /* locID MUST BE upper-case */
+                               tmp_p = locID;
+                               while (*tmp_p) {
+                                       *tmp_p = toupper(*tmp_p);
+                                       tmp_p++;
+                               }
 
-                       /* Construct complete uri */
-                       if (strstr(uri, "xoap.weather.com")) {
-                         if(xoap != NULL) {
-                           strcat(uri, locID);
-                           strcat(uri, xoap);
-                         } else {
-                           free(uri);
-                           uri = NULL;
-                         }
-                       } else if (strstr(uri, "weather.noaa.gov")) {
-                           strcat(uri, locID);
-                           strcat(uri, ".TXT");
-                       } else  if (!strstr(uri, "localhost") && !strstr(uri, "127.0.0.1")) {
-                             CRIT_ERR(obj, free_at_crash, \
-                                      "could not recognize the weather uri");
-                       }
+                               /* Construct complete uri */
+                               if (strstr(uri, "xoap.weather.com")) {
+                                       if(xoap != NULL) {
+                                               strcat(uri, locID);
+                                               strcat(uri, xoap);
+                                       } else {
+                                               free(uri);
+                                               uri = NULL;
+                                       }
+                               } else if (strstr(uri, "weather.noaa.gov")) {
+                                       strcat(uri, locID);
+                                       strcat(uri, ".TXT");
+                               } else  if (!strstr(uri, "localhost") && !strstr(uri, "127.0.0.1")) {
+                                       CRIT_ERR(obj, free_at_crash, \
+                                                       "could not recognize the weather uri");
+                               }
 
-                       obj->data.weather.uri = uri;
-                       obj->data.weather.data_type = data_type;
+                               obj->data.weather.uri = uri;
+                               obj->data.weather.data_type = data_type;
 
-                       /* Limit the data retrieval interval to half hour min */
-                       if (interval < 30) {
-                               interval = 30;
-                       }
+                               /* Limit the data retrieval interval to half hour min */
+                               if (interval < 30) {
+                                       interval = 30;
+                               }
 
-                       /* Convert to seconds */
-                       obj->data.weather.interval = interval * 60;
-                       free(locID);
+                               /* Convert to seconds */
+                               obj->data.weather.interval = interval * 60;
+                               free(locID);
 
-                       DBGP("weather: fetching %s from %s every %d seconds", \
-                            data_type, uri, obj->data.weather.interval);
+                               DBGP("weather: fetching %s from %s every %d seconds", \
+                                               data_type, uri, obj->data.weather.interval);
+                       } else {
+                               ERR("wrong number of arguments for $weather");
+                       }
                } else {
                        CRIT_ERR(obj, free_at_crash, "weather needs arguments: <uri> <locID> <data_type> [interval in minutes]");
                }