-static CURL *curl_handle;
-
-/**
- * Cache a image from Ridge to the local disk
- * \param path Path to the Ridge file, starting after /ridge/
- * \return The local path to the cached image
- */
-char *cache_image(char *path)
-{
- gchar base[] = "http://radar.weather.gov/ridge/";
- gchar *url = g_strconcat(base, path, NULL);
- gchar *local = g_build_filename(g_get_user_cache_dir(), PACKAGE, path, NULL);
- if (!g_file_test(local, G_FILE_TEST_EXISTS)) {
- if (!g_file_test(g_path_get_dirname(local), G_FILE_TEST_IS_DIR)) {
- //g_printerr("Making directory %s\n", g_path_get_dirname(local));
- g_mkdir_with_parents(g_path_get_dirname(local), 0755);
- }
- //g_printerr("Fetching image %s -> %s\n", url, local);
- long http_code;
- FILE *cached_image = fopen(local, "w+");
- curl_easy_setopt(curl_handle, CURLOPT_URL, url);
- curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, cached_image);
- curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, NULL);
- curl_easy_perform(curl_handle);
- curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
- fflush(cached_image);
- if (http_code != 200) {
- g_message("http %ld while fetching %s", http_code, url);
- remove(local);
- return NULL;
- }
- }
- return local;
-}