gnss: include error messages directly from curl

This will print the error message from curl instead of just the http
status code if downloading gpsOneXtra data fails. This also removes the
need to check to check the size of the file curl downloaded.
This commit is contained in:
ArenM
2021-09-12 12:46:28 -04:00
parent ad1d6e5d3e
commit 593db8aa67

View File

@@ -189,10 +189,10 @@ static void fetch_assistance_data(struct EG25Manager *manager)
{ {
CURL *curl; CURL *curl;
CURLcode response; CURLcode response;
long status_code;
gchar *url = NULL; gchar *url = NULL;
FILE *tmp_file = NULL; FILE *tmp_file = NULL;
long int size; gchar errbuf[CURL_ERROR_SIZE];
errbuf[0] = 0;
/* Fetch assistance data with curl */ /* Fetch assistance data with curl */
tmp_file = fdopen(manager->gnss_assistance_fd, "wb+"); tmp_file = fdopen(manager->gnss_assistance_fd, "wb+");
@@ -203,17 +203,19 @@ static void fetch_assistance_data(struct EG25Manager *manager)
curl = curl_easy_init(); curl = curl_easy_init();
if (!curl) if (!curl)
g_error ("Unable to initialize curl"); g_error ("Unable to initialize curl");
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, tmp_file); 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_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
response = curl_easy_perform(curl); response = curl_easy_perform(curl);
if (response == CURLE_HTTP_RETURNED_ERROR) { curl_easy_cleanup(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status_code); if (response != CURLE_OK) {
curl_easy_cleanup(curl); g_warning ("Unable to fetch GNSS assistance data from %s: %s",
g_warning ("Unable to fetch GNSS assistance data from %s (HTTP %ld)", url, strlen(errbuf) ? errbuf : curl_easy_strerror(response));
url, status_code);
/* Restart upload on HTTP error status code */ /* Restart upload on HTTP error status code */
g_message ("Rescheduling upload because of failure in %ds", g_message ("Rescheduling upload because of failure in %ds",
@@ -225,28 +227,7 @@ static void fetch_assistance_data(struct EG25Manager *manager)
return; 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); g_message("Fetching GNSS assistance data from %s was successfull", url);
curl_easy_cleanup(curl);
g_free(url); g_free(url);
/* Go to the next step */ /* Go to the next step */