[project @ 2003-08-28 20:04:35 by bursa]

Use Content-Length to give percentage downloads.

svn path=/import/netsurf/; revision=256
This commit is contained in:
James Bursa 2003-08-28 20:04:35 +00:00
parent cef8c477c3
commit 3ce4ce9653
3 changed files with 17 additions and 3 deletions

View File

@ -182,7 +182,7 @@ struct content
struct content_user *user_list;
char status_message[80];
struct fetch *fetch;
unsigned long fetch_size;
unsigned long fetch_size, total_size;
};

View File

@ -47,6 +47,7 @@ struct fetch
char *host;
int status_code;
char *location;
unsigned long content_length;
struct fetch *queue;
struct fetch *prev;
struct fetch *next;
@ -145,6 +146,7 @@ struct fetch * fetch_start(char *url, char *referer,
if (uri->server != 0)
fetch->host = xstrdup(uri->server);
fetch->status_code = 0;
fetch->content_length = 0;
fetch->queue = 0;
fetch->prev = 0;
fetch->next = 0;
@ -420,6 +422,12 @@ size_t fetch_curl_header(char * data, size_t size, size_t nmemb, struct fetch *f
f->location[i] == '\r' ||
f->location[i] == '\n'; i--)
f->location[i] = '\0';
} else if (15 < size && strncasecmp(data, "Content-Length:", 15) == 0) {
/* extract Content-Length header */
for (i = 15; data[i] == ' ' || data[i] == '\t'; i++)
;
if ('0' <= data[i] && data[i] <= '9')
f->content_length = atol(data + i);
}
return size;
}
@ -463,7 +471,7 @@ int fetch_process_headers(struct fetch *f)
}
LOG(("FETCH_TYPE, '%s'", type));
f->callback(FETCH_TYPE, f->p, type, 0);
f->callback(FETCH_TYPE, f->p, type, f->content_length);
if (f->aborting) {
f->in_callback = 0;
return 1;

View File

@ -66,6 +66,7 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size)
switch (msg) {
case FETCH_TYPE:
c->total_size = size;
mime_type = xstrdup(data);
if ((semic = strchr(mime_type, ';')) != 0)
*semic = 0; /* remove "; charset=..." */
@ -78,7 +79,12 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size)
case FETCH_DATA:
LOG(("FETCH_DATA"));
c->fetch_size += size;
sprintf(c->status_message, "Received %lu bytes", c->fetch_size);
if (c->total_size)
sprintf(c->status_message, "Received %lu of %lu bytes (%u%%)",
c->fetch_size, c->total_size,
(unsigned int) (c->fetch_size * 100.0 / c->total_size));
else
sprintf(c->status_message, "Received %lu bytes", c->fetch_size);
content_broadcast(c, CONTENT_MSG_STATUS, 0);
content_process_data(c, data, size);
break;