git-svn: trunk@1850
Tomasz Kojm authored on 2006/03/08 22:28:54... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Wed Mar 8 14:25:14 CET 2006 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * freshclam/manager.c: if possible, use percent idicator instead of rotor |
|
4 |
+ Patch by Robert Hogan <robert*roberthogan.net> |
|
5 |
+ |
|
1 | 6 |
Tue Mar 7 19:56:58 CET 2006 (tk) |
2 | 7 |
--------------------------------- |
3 | 8 |
* shared/cfgparser.c: strip newlines from FULLSTR args |
... | ... |
@@ -728,9 +728,9 @@ struct cl_cvd *remote_cvdhead(const char *file, int socketfd, const char *hostna |
728 | 728 |
int get_database(const char *dbfile, int socketfd, const char *file, const char *hostname, const char *proxy, const char *user, const char *pass, const char *uas) |
729 | 729 |
{ |
730 | 730 |
char cmd[512], buffer[FILEBUFF], *ch; |
731 |
- int bread, fd, i, rot = 0; |
|
731 |
+ int bread, fd, i, totalsize = 0, rot = 0, totaldownloaded = 0, percentage; |
|
732 | 732 |
char *remotename = NULL, *authorization = NULL; |
733 |
- const char *rotation = "|/-\\", *agent; |
|
733 |
+ const char *rotation = "|/-\\", *agent, *headerline; |
|
734 | 734 |
|
735 | 735 |
|
736 | 736 |
if(proxy) { |
... | ... |
@@ -815,26 +815,43 @@ int get_database(const char *dbfile, int socketfd, const char *file, const char |
815 | 815 |
|
816 | 816 |
/* check whether the resource actually existed or not */ |
817 | 817 |
|
818 |
- if ((strstr(buffer, "HTTP/1.1 404")) != NULL) { |
|
818 |
+ if(strstr(buffer, "HTTP/1.1 404")) { |
|
819 | 819 |
logg("^%s not found on remote server\n", dbfile); |
820 | 820 |
close(fd); |
821 | 821 |
unlink(file); |
822 | 822 |
return 58; |
823 | 823 |
} |
824 | 824 |
|
825 |
+ /* get size of resource */ |
|
826 |
+ for(i = 0; (headerline = cli_strtok(buffer, i, "\n")); i++){ |
|
827 |
+ if(strstr(headerline, "Content-Length:")) { |
|
828 |
+ totalsize = atoi(cli_strtok(headerline, 1, ": ")); |
|
829 |
+ } |
|
830 |
+ } |
|
831 |
+ |
|
825 | 832 |
/* receive body and write it to disk */ |
826 | 833 |
|
827 | 834 |
while((bread = read(socketfd, buffer, FILEBUFF))) { |
828 |
- write(fd, buffer, bread); |
|
829 |
- if(!mprintf_quiet) { |
|
830 |
- mprintf("Downloading %s [%c]\r", dbfile, rotation[rot]); |
|
831 |
- fflush(stdout); |
|
832 |
- rot++; |
|
833 |
- rot %= 4; |
|
834 |
- } |
|
835 |
+ write(fd, buffer, bread); |
|
836 |
+ if(!mprintf_quiet) { |
|
837 |
+ if(totalsize > 0) { |
|
838 |
+ totaldownloaded = totaldownloaded + bread; |
|
839 |
+ percentage = (int)(100 * (float)totaldownloaded/totalsize); |
|
840 |
+ mprintf("Downloading %s [%i%]\r", dbfile, percentage); |
|
841 |
+ } else { |
|
842 |
+ mprintf("Downloading %s [%c]\r", dbfile, rotation[rot]); |
|
843 |
+ rot++; |
|
844 |
+ rot %= 4; |
|
845 |
+ } |
|
846 |
+ fflush(stdout); |
|
847 |
+ } |
|
835 | 848 |
} |
836 | 849 |
|
837 |
- logg("Downloading %s [*]\n", dbfile); |
|
850 |
+ if(totalsize > 0) |
|
851 |
+ logg("Downloading %s [%i%]\n", dbfile, percentage); |
|
852 |
+ else |
|
853 |
+ logg("Downloading %s [*]\n", dbfile); |
|
854 |
+ |
|
838 | 855 |
close(fd); |
839 | 856 |
return 0; |
840 | 857 |
} |