X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/3335ae4e7066df328256ef6693313e99601fd5d8..020b155be89ee1825309eb6d8d1958f3b46c310d:/src/download.c?ds=sidebyside diff --git a/src/download.c b/src/download.c index 98843370..fcaef0b5 100644 --- a/src/download.c +++ b/src/download.c @@ -25,6 +25,9 @@ #include #include +#include +#include +#include #include #include #include @@ -62,7 +65,42 @@ char *dirname ( char * dir ) #endif -static int download( const char *hostname, const char *uri, const char *fn, int sendhostname) +static int check_map_file(FILE* f) +{ + char **s; + char *bp; + int res = 0; /* good */ + fpos_t pos; + char buf[33]; + size_t nr; + char * html_str[] = { + " (bp - buf)); bp++) { + if (!(isspace(*bp))) + break; + } + if ((bp >= (buf + sizeof(buf) -1)) || ((bp - buf) >= nr)) + return(res); + for (s = html_str; *s; s++) { + if (strncmp(*s, bp, strlen(*s)) == 0) + return(-1); + } + return(res); +} + +static int download( const char *hostname, const char *uri, const char *fn, DownloadOptions *options) { FILE *f; int ret; @@ -104,16 +142,18 @@ static int download( const char *hostname, const char *uri, const char *fn, int /* Call the backend function */ #ifdef HAVE_LIBCURL - ret = curl_download_get_url ( hostname, uri, f ); + ret = curl_download_get_url ( hostname, uri, f, options ); #else - ret = http_download_get_url ( hostname, uri, f, 0, sendhostname ); + ret = http_download_get_url ( hostname, uri, f, 0, options ); #endif - if (ret == -1 || ret == 1 || ret == -2) + if (ret == -1 || ret == 1 || ret == -2 || check_map_file(f)) { + fprintf(stderr, "Download error: %s\n", fn); fclose ( f ); remove ( tmpfilename ); g_free ( tmpfilename ); + remove ( fn ); /* couldn't create temporary. delete 0-byte file. */ return -1; } @@ -126,12 +166,7 @@ static int download( const char *hostname, const char *uri, const char *fn, int /* success = 0, -1 = couldn't connect, -2 HTTP error, -3 file exists, -4 couldn't write to file... */ /* uri: like "/uri.html?whatever" */ /* only reason for the "wrapper" is so we can do redirects. */ -int a_http_download_get_url ( const char *hostname, const char *uri, const char *fn ) -{ - return download ( hostname, uri, fn, 1 ); -} - -int a_http_download_get_url_nohostname ( const char *hostname, const char *uri, const char *fn ) +int a_http_download_get_url ( const char *hostname, const char *uri, const char *fn, DownloadOptions *opt ) { - return download ( hostname, uri, fn, 0 ); + return download ( hostname, uri, fn, opt ); }