X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/a1618d625486c95fc3bee059d9d9381c15eb7046..80471a6a905e00bf80ad04fa2061f88ea81f15cb:/src/download.c?ds=sidebyside diff --git a/src/download.c b/src/download.c index 7f94fa42..27b123f2 100644 --- a/src/download.c +++ b/src/download.c @@ -34,15 +34,14 @@ #include "curl_download.h" -static int check_map_file(FILE* f) +gboolean a_check_html_file(FILE* f) { - char **s; - char *bp; - int res = 0; /* good */ + gchar **s; + gchar *bp; fpos_t pos; - char buf[33]; + gchar buf[33]; size_t nr; - char * html_str[] = { + gchar * html_str[] = { "= (buf + sizeof(buf) -1)) || ((bp - buf) >= nr)) - return(res); + return FALSE; for (s = html_str; *s; s++) { if (strncasecmp(*s, bp, strlen(*s)) == 0) - return(-1); + return TRUE; } - return(res); + return FALSE; +} + +gboolean a_check_map_file(FILE* f) +{ + return !a_check_html_file(f); } static int download( const char *hostname, const char *uri, const char *fn, DownloadOptions *options, gboolean ftp) { FILE *f; int ret; - char *tmpfilename; + gchar *tmpfilename; + gboolean failure = FALSE; /* Check file */ if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == TRUE ) @@ -102,8 +106,17 @@ static int download( const char *hostname, const char *uri, const char *fn, Down /* Call the backend function */ ret = curl_download_get_url ( hostname, uri, f, options, ftp ); + if (ret == -1 || ret == 1 || ret == -2) { + g_debug("%s: download failed: curl_download_get_url=%d", __FUNCTION__, ret); + failure = TRUE; + } + + if (!failure && options != NULL && options->check_file != NULL && ! options->check_file(f)) { + g_debug("%s: file content checking failed", __FUNCTION__); + failure = TRUE; + } - if (ret == -1 || ret == 1 || ret == -2 || check_map_file(f)) + if (failure) { g_warning(_("Download error: %s"), fn); fclose ( f ); @@ -116,7 +129,7 @@ static int download( const char *hostname, const char *uri, const char *fn, Down fclose ( f ); f = NULL; - rename ( tmpfilename, fn ); /* move completely-downloaded file to permanent location */ + g_rename ( tmpfilename, fn ); /* move completely-downloaded file to permanent location */ g_free ( tmpfilename ); return ret; }