WebView 2.7: distinguish files to download from pages to show, download files via HTTPS, remove duplicated function of getting absolute URL from relative
git-svn-id: svn://kolibrios.org@8291 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
e303140339
commit
d178e4875c
@ -19,7 +19,7 @@ dword _img::add(dword _path, _x, _y)
|
||||
{
|
||||
char full_path[URL_SIZE];
|
||||
strncpy(#full_path, _path, URL_SIZE);
|
||||
GetAbsoluteURL(#full_path, history.current());
|
||||
get_absolute_url(#full_path, history.current());
|
||||
|
||||
url.add(#full_path);
|
||||
xywh.add(_x);
|
||||
@ -93,7 +93,7 @@ void ImageCache::Images(dword left1, top1, width1)
|
||||
dword image;
|
||||
dword imgw=0, imgh=0, img_lines_first=0, cur_pic=0;
|
||||
|
||||
//GetAbsoluteURL(#img_path);
|
||||
//getting abs url from (#img_path);
|
||||
//cur_pic = GetImage(#img_path);
|
||||
|
||||
if (!pics[cur_pic].image)
|
||||
|
@ -34,7 +34,7 @@ char editbox_icons[] = FROM "res/editbox_icons.raw";
|
||||
|
||||
#define URL_SIZE 4000
|
||||
|
||||
char version[]="WebView 2.66";
|
||||
char version[]="WebView 2.7";
|
||||
|
||||
#include "texts.h"
|
||||
#include "cache.h"
|
||||
@ -240,6 +240,12 @@ void main()
|
||||
if (http.transfer <= 0) break;
|
||||
http.receive();
|
||||
EventUpdateProgressBar();
|
||||
if (http.check_content_type()) && (!strncmp(#http.content_type,"application",11)) {
|
||||
EventOpenDownloader(history.current());
|
||||
StopLoading();
|
||||
history.back();
|
||||
EventRefreshPage();
|
||||
}
|
||||
if (http.receive_result != 0) break;
|
||||
if (http.status_code >= 300) && (http.status_code < 400)
|
||||
{
|
||||
@ -247,8 +253,6 @@ void main()
|
||||
if (redirect_count<=5) {
|
||||
redirect_count++;
|
||||
http.handle_redirect();
|
||||
http.free();
|
||||
GetAbsoluteURL(#http.redirect_url, history.current());
|
||||
history.back();
|
||||
if (http_get_type==PAGE) OpenPage(#http.redirect_url);
|
||||
else if (http_get_type==IMG) http.get(#http.redirect_url);
|
||||
@ -260,7 +264,7 @@ void main()
|
||||
} else {
|
||||
// Loading the page is complete, free resources
|
||||
redirect_count = 0;
|
||||
http.free();
|
||||
http.hfree();
|
||||
if (http_get_type==PAGE) {
|
||||
cache.add(history.current(), http.content_pointer, http.content_received, PAGE);
|
||||
LoadInternalPage(http.content_pointer, http.content_received);
|
||||
@ -951,7 +955,7 @@ dword GetAbsoluteActiveURL()
|
||||
char abs_url[URL_SIZE];
|
||||
if (links.active_url) {
|
||||
strncpy(#abs_url, links.active_url, URL_SIZE);
|
||||
GetAbsoluteURL(#abs_url, history.current());
|
||||
get_absolute_url(#abs_url, history.current());
|
||||
return #abs_url;
|
||||
}
|
||||
return 0;
|
||||
|
@ -6,14 +6,13 @@
|
||||
|
||||
#include "../lib/obj/box_lib.h"
|
||||
#include "../lib/obj/http.h"
|
||||
#include "../lib/obj/libini.h"
|
||||
|
||||
#include "../lib/patterns/http_downloader.h"
|
||||
|
||||
#include "const.h"
|
||||
|
||||
DOWNLOADER downloader;
|
||||
checkbox autoclose = { T_AUTOCLOSE, true };
|
||||
checkbox autoclose = { T_AUTOCLOSE, false };
|
||||
|
||||
char downloader_edit[4000];
|
||||
char filepath[4096];
|
||||
@ -30,7 +29,6 @@ void main()
|
||||
dword shared_url;
|
||||
load_dll(boxlib, #box_lib_init,0);
|
||||
load_dll(libHTTP, #http_lib_init,1);
|
||||
load_dll(libini, #lib_init,1);
|
||||
|
||||
if (!dir_exists(#save_to)) CreateDir(#save_to);
|
||||
|
||||
@ -74,8 +72,8 @@ void main()
|
||||
|
||||
default:
|
||||
if (!downloader.MonitorProgress()) break;
|
||||
pb.max = downloader.httpd.content_length / 100;
|
||||
EDI = downloader.httpd.content_received/100;
|
||||
pb.max = downloader.content_length / 100;
|
||||
EDI = downloader.content_received/100;
|
||||
if (pb.value != EDI)
|
||||
{
|
||||
pb.value = EDI;
|
||||
@ -97,7 +95,7 @@ void ProcessEvent(int id)
|
||||
{
|
||||
autoclose.click(id);
|
||||
if (id==001) { StopDownloading(); ExitProcess(); }
|
||||
if (id==301) && (downloader.httpd.transfer <= 0) StartDownloading();
|
||||
if (id==301) && (downloader.transfer <= 0) StartDownloading();
|
||||
if (id==302) StopDownloading();
|
||||
if (id==305) RunProgram("/sys/File managers/Eolite", #filepath);
|
||||
if (id==306) {
|
||||
@ -141,17 +139,17 @@ void StartDownloading()
|
||||
char proxy_url[URL_SIZE];
|
||||
StopDownloading();
|
||||
if (!strncmp(#downloader_edit,"https://",7)) {
|
||||
notify("'HTTPS for download is not supported, trying to download the file via HTTP' -W");
|
||||
miniprintf(#http_url, "http://%s", #downloader_edit+8);
|
||||
if (!downloader.Start(#http_url)) {
|
||||
notify("'Download failed.' -E");
|
||||
StopDownloading();
|
||||
}
|
||||
//sprintf(#proxy_url, "http://gate.aspero.pro/?site=%s", #downloader_edit);
|
||||
//if (!downloader.Start(#proxy_url)) {
|
||||
//notify("'HTTPS for download is not supported, trying to download the file via HTTP' -W");
|
||||
//miniprintf(#http_url, "http://%s", #downloader_edit+8);
|
||||
//if (!downloader.Start(#http_url)) {
|
||||
// notify("'Download failed.' -E");
|
||||
// StopDownloading();
|
||||
//}
|
||||
miniprintf(#proxy_url, "http://gate.aspero.pro/?site=%s", #downloader_edit);
|
||||
if (!downloader.Start(#proxy_url)) {
|
||||
notify("'Download failed.' -E");
|
||||
StopDownloading();
|
||||
}
|
||||
DrawWindow();
|
||||
return;
|
||||
}
|
||||
@ -185,11 +183,11 @@ void CalculateSpeed()
|
||||
if (time.old) {
|
||||
time.gone = time.cur - time.old;
|
||||
if (time.gone > 200) {
|
||||
speed = downloader.httpd.content_received - netdata_received / time.gone * 100;
|
||||
speed = downloader.content_received - netdata_received / time.gone * 100;
|
||||
debugval("speed", speed);
|
||||
debugln(ConvertSizeToKb(speed) );
|
||||
time.old = time.cur;
|
||||
netdata_received = downloader.httpd.content_received;
|
||||
netdata_received = downloader.content_received;
|
||||
}
|
||||
}
|
||||
else time.old = time.cur;
|
||||
@ -199,7 +197,7 @@ void CalculateSpeed()
|
||||
void DrawDownloading()
|
||||
{
|
||||
char bytes_received[70];
|
||||
miniprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.httpd.content_received) );
|
||||
miniprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.content_received) );
|
||||
WriteTextWithBg(GAPX, pb.top + 22, 0xD0, sc.work_text, #bytes_received, sc.work);
|
||||
//CalculateSpeed();
|
||||
progressbar_draw stdcall(#pb);
|
||||
@ -232,14 +230,14 @@ void SaveDownloadedFile()
|
||||
|
||||
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
||||
|
||||
if (CreateFile(downloader.httpd.content_received, downloader.bufpointer, #filepath)==0) {
|
||||
if (CreateFile(downloader.content_received, downloader.bufpointer, #filepath)==0) {
|
||||
miniprintf(#notify_message, FILE_SAVED_AS, #filepath);
|
||||
} else {
|
||||
miniprintf(#notify_message, FILE_NOT_SAVED, #filepath);
|
||||
}
|
||||
|
||||
/*
|
||||
if (CreateFile(downloader.httpd.content_received, downloader.bufpointer, #filepath)==0) {
|
||||
if (CreateFile(downloader.content_received, downloader.bufpointer, #filepath)==0) {
|
||||
strcpy(#notify_message, "'Download complete' -Dt");
|
||||
} else {
|
||||
strcpy(#notify_message, "'Error saving downloaded file!' -Et");
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
struct _http
|
||||
{
|
||||
dword url;
|
||||
dword cur_url;
|
||||
dword transfer;
|
||||
dword content_length;
|
||||
dword content_received;
|
||||
@ -14,23 +14,25 @@ struct _http
|
||||
dword receive_result;
|
||||
dword content_pointer;
|
||||
char redirect_url[4096*3];
|
||||
char finaladress[4096*3];
|
||||
char content_type[64];
|
||||
|
||||
dword get();
|
||||
void free();
|
||||
void hfree();
|
||||
void receive();
|
||||
bool handle_redirect();
|
||||
dword check_content_type();
|
||||
};
|
||||
|
||||
dword _http::get(dword _url)
|
||||
{
|
||||
url = _url;
|
||||
http_get stdcall (url, 0, 0, #accept_language);
|
||||
cur_url = _url;
|
||||
http_get stdcall (_url, 0, 0, #accept_language);
|
||||
content_type[0] = '\0';
|
||||
transfer = EAX;
|
||||
return transfer;
|
||||
}
|
||||
|
||||
void _http::free()
|
||||
void _http::hfree()
|
||||
{
|
||||
http_free stdcall (transfer);
|
||||
transfer=0;
|
||||
@ -53,7 +55,6 @@ void _http::receive()
|
||||
|
||||
:bool _http::handle_redirect()
|
||||
{
|
||||
dword redirect;
|
||||
http_find_header_field stdcall (transfer, "location\0");
|
||||
if (EAX!=0) {
|
||||
ESI = EAX;
|
||||
@ -63,11 +64,29 @@ void _http::receive()
|
||||
$stosb;
|
||||
} while (AL != 0) && (AL != 13) && (AL != 10);
|
||||
DSBYTE[EDI-1]='\0';
|
||||
get_absolute_url(#finaladress, url, #redirect_url);
|
||||
strcpy(url, #finaladress);
|
||||
return true;
|
||||
get_absolute_url(#redirect_url, cur_url);
|
||||
hfree();
|
||||
return #redirect_url;
|
||||
}
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
:dword _http::check_content_type()
|
||||
{
|
||||
if (content_type[0]) return NULL;
|
||||
http_find_header_field stdcall (transfer, "content-type\0");
|
||||
if (EAX!=0) {
|
||||
ESI = EAX;
|
||||
EDI = #content_type;
|
||||
do {
|
||||
$lodsb;
|
||||
$stosb;
|
||||
} while (AL != 0) && (AL != 13) && (AL != 10);
|
||||
DSBYTE[EDI-1]='\0';
|
||||
debugln(#content_type);
|
||||
return #content_type;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//===================================================//
|
||||
@ -83,8 +102,7 @@ enum {
|
||||
STATE_COMPLETED
|
||||
};
|
||||
|
||||
struct DOWNLOADER {
|
||||
_http httpd;
|
||||
struct DOWNLOADER : _http {
|
||||
dword bufpointer, bufsize, url;
|
||||
int state;
|
||||
dword Start();
|
||||
@ -96,50 +114,47 @@ dword DOWNLOADER::Start(dword _url)
|
||||
{
|
||||
url = _url;
|
||||
state = STATE_IN_PROGRESS;
|
||||
httpd.get(url);
|
||||
if (!httpd.transfer) Stop();
|
||||
return httpd.transfer;
|
||||
get(_url);
|
||||
if (!transfer) Stop();
|
||||
return transfer;
|
||||
}
|
||||
|
||||
void DOWNLOADER::Stop()
|
||||
{
|
||||
state = STATE_NOT_STARTED;
|
||||
if (httpd.transfer!=0)
|
||||
if (transfer!=0)
|
||||
{
|
||||
EAX = httpd.transfer;
|
||||
EAX = transfer;
|
||||
EAX = EAX.http_msg.content_ptr; // get pointer to data
|
||||
$push EAX // save it on the stack
|
||||
http_free stdcall (httpd.transfer); // abort connection
|
||||
http_free stdcall (transfer); // abort connection
|
||||
$pop EAX
|
||||
free(EAX); // free data
|
||||
httpd.transfer=0;
|
||||
transfer=0;
|
||||
bufsize = 0;
|
||||
bufpointer = free(bufpointer);
|
||||
}
|
||||
httpd.content_received = httpd.content_length = 0;
|
||||
content_received = content_length = 0;
|
||||
}
|
||||
|
||||
bool DOWNLOADER::MonitorProgress()
|
||||
{
|
||||
if (httpd.transfer <= 0) return false;
|
||||
httpd.receive();
|
||||
if (!httpd.content_length) httpd.content_length = httpd.content_received * 20;
|
||||
if (transfer <= 0) return false;
|
||||
receive();
|
||||
if (!content_length) content_length = content_received * 20;
|
||||
|
||||
if (httpd.receive_result == 0) {
|
||||
if (httpd.status_code >= 300) && (httpd.status_code < 400)
|
||||
if (receive_result == 0) {
|
||||
if (status_code >= 300) && (status_code < 400)
|
||||
{
|
||||
httpd.handle_redirect();
|
||||
strcpy(url, httpd.url);
|
||||
get_absolute_url(#httpd.finaladress, url, #httpd.redirect_url);
|
||||
url = handle_redirect();
|
||||
Stop();
|
||||
Start(#httpd.finaladress);
|
||||
url = #httpd.finaladress;
|
||||
Start(url);
|
||||
return false;
|
||||
}
|
||||
state = STATE_COMPLETED;
|
||||
bufpointer = httpd.content_pointer;
|
||||
bufsize = httpd.content_received;
|
||||
httpd.free();
|
||||
bufpointer = content_pointer;
|
||||
bufsize = content_received;
|
||||
hfree();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -181,42 +196,7 @@ bool DOWNLOADER::MonitorProgress()
|
||||
return false;
|
||||
}
|
||||
|
||||
:void get_absolute_url(dword _rez, _base, _new)
|
||||
{
|
||||
int i;
|
||||
//case: ./valera.html
|
||||
if (!strncmp(_new,"./", 2)) _new+=2;
|
||||
//case: http://site.name
|
||||
if (check_is_the_url_absolute(_new)) {
|
||||
strcpy(_rez, _new);
|
||||
goto _GET_ABSOLUTE_URL_END;
|
||||
}
|
||||
//case: /valera.html
|
||||
if (ESBYTE[_new] == '/') //remove everything after site domain name
|
||||
{
|
||||
strcpy(_rez, _base);
|
||||
i = strchr(_rez+8,'/');
|
||||
if (i<1) i=strlen(_rez)+_rez;
|
||||
strcpy(i, _new);
|
||||
goto _GET_ABSOLUTE_URL_END;
|
||||
}
|
||||
//case: ../../valera.html
|
||||
strcpy(_rez, _base);
|
||||
ESBYTE[ strrchr(_rez,'/') + _rez -1 ] = '\0'; //remove name
|
||||
while (!strncmp(_new,"../",3))
|
||||
{
|
||||
_new += 3;
|
||||
ESBYTE[ strrchr(_rez,'/') + _rez -1 ] = '\0';
|
||||
}
|
||||
//case: valera.html
|
||||
chrcat(_rez, '/');
|
||||
strcat(_rez, _new);
|
||||
_GET_ABSOLUTE_URL_END:
|
||||
while (i=strstr(_rez, "&")) strcpy(i+1, i+5);
|
||||
}
|
||||
|
||||
|
||||
:dword GetAbsoluteURL(dword new_URL, base_URL)
|
||||
:dword get_absolute_url(dword new_URL, base_URL)
|
||||
{
|
||||
int i;
|
||||
dword orig_URL = new_URL;
|
||||
|
@ -117,7 +117,7 @@ void main()
|
||||
if (!http.receive_result) {
|
||||
CreateFile(http.content_received,
|
||||
http.content_pointer, "/tmp0/1/latest.img");
|
||||
http.free();
|
||||
http.hfree();
|
||||
EventDownloadComplete();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user