diff --git a/src/gnss.c b/src/gnss.c index 0145606..16b79a1 100644 --- a/src/gnss.c +++ b/src/gnss.c @@ -189,10 +189,10 @@ static void fetch_assistance_data(struct EG25Manager *manager) { CURL *curl; CURLcode response; - long status_code; gchar *url = NULL; FILE *tmp_file = NULL; - long int size; + gchar errbuf[CURL_ERROR_SIZE]; + errbuf[0] = 0; /* Fetch assistance data with curl */ tmp_file = fdopen(manager->gnss_assistance_fd, "wb+"); @@ -203,17 +203,19 @@ static void fetch_assistance_data(struct EG25Manager *manager) curl = curl_easy_init(); if (!curl) g_error ("Unable to initialize curl"); + curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); curl_easy_setopt(curl, CURLOPT_WRITEDATA, tmp_file); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); + response = curl_easy_perform(curl); - if (response == CURLE_HTTP_RETURNED_ERROR) { - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status_code); - curl_easy_cleanup(curl); - g_warning ("Unable to fetch GNSS assistance data from %s (HTTP %ld)", - url, status_code); + curl_easy_cleanup(curl); + if (response != CURLE_OK) { + g_warning ("Unable to fetch GNSS assistance data from %s: %s", + url, strlen(errbuf) ? errbuf : curl_easy_strerror(response)); /* Restart upload on HTTP error status code */ g_message ("Rescheduling upload because of failure in %ds", @@ -225,28 +227,7 @@ static void fetch_assistance_data(struct EG25Manager *manager) return; } - /* Get file size in bytes */ - size = (long int)lseek(manager->gnss_assistance_fd, 0, SEEK_END); - lseek(manager->gnss_assistance_fd, 0, SEEK_SET); - - if (size <= 0) { - g_warning ("GNSS assistance data contains 0 bytes," - "check network connection."); - /* - * Restart upload when file does not contain any data, - * mostly because of no network connection. - */ - g_message ("Rescheduling upload because of failure in %ds", - RESCHEDULE_IN_SECS); - manager->gnss_assistance_step = EG25_GNSS_STEP_LAST; - g_timeout_add_seconds(RESCHEDULE_IN_SECS, - G_SOURCE_FUNC(gnss_upload_assistance_data), - manager); - return; - } - g_message("Fetching GNSS assistance data from %s was successfull", url); - curl_easy_cleanup(curl); g_free(url); /* Go to the next step */