Subversion Repositories Kolibri OS

Rev

Rev 7281 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7281 Rev 7282
Line 11... Line 11...
11
    dword content_length;
11
    dword content_length;
12
    dword content_received;
12
    dword content_received;
13
    dword status_code;
13
    dword status_code;
14
    dword receive_result;
14
    dword receive_result;
15
    dword content_pointer;
15
    dword content_pointer;
-
 
16
    char redirect_url[4096*3];
-
 
17
    char finaladress[4096*3];
Line 16... Line 18...
16
 
18
 
17
    dword get();
19
    dword get();
18
    void free();
20
    void free();
19
    void receive();
21
    void receive();
Line 37... Line 39...
37
void _http::receive()
39
void _http::receive()
38
{
40
{
39
    http_receive stdcall (transfer);
41
    http_receive stdcall (transfer);
40
    receive_result = EAX;
42
    receive_result = EAX;
Line 41... Line 43...
41
 
43
 
-
 
44
    EDI = transfer;
42
    ESI = transfer;
45
    if (!EAX) {
-
 
46
    	status_code = EDI.http_msg.status;
-
 
47
    	content_pointer = EDI.http_msg.content_ptr;
43
    if (!EAX) status_code = ESI.http_msg.status;
48
    }
44
    content_length = ESI.http_msg.content_length;
49
    content_length = EDI.http_msg.content_length;
Line 45... Line 50...
45
    content_received = ESI.http_msg.content_received;
50
    content_received = EDI.http_msg.content_received;
Line 46... Line 51...
46
 
51
 
47
 }
52
 }
48
 
53
 
49
bool _http::handle_redirect()
-
 
50
{
54
bool _http::handle_redirect()
51
	dword redirect, i;
55
{
52
	char redirect_url[4096*3], finaladress[4096*3];
56
	dword redirect;
53
    http_find_header_field stdcall (transfer, "location\0");
57
    http_find_header_field stdcall (transfer, "location\0");
54
    if (EAX!=0) {
58
    if (EAX!=0) {
Line 79... Line 83...
79
	STATE_COMPLETED 
83
	STATE_COMPLETED 
80
};
84
};
Line 81... Line 85...
81
 
85
 
82
struct DOWNLOADER {
86
struct DOWNLOADER {
83
	_http httpd;
-
 
84
	unsigned data_downloaded_size, data_full_size;
87
	_http httpd;
85
	dword bufpointer, bufsize, url;
88
	dword bufpointer, bufsize, url;
86
	int state;
89
	int state;
87
	dword Start();
90
	dword Start();
88
	void Stop();
-
 
89
	void Completed();
91
	void Stop();
90
	int MonitorProgress();
92
	bool MonitorProgress();
Line 91... Line 93...
91
} downloader;
93
} downloader;
92
 
94
 
93
dword DOWNLOADER::Start(dword _url)
95
dword DOWNLOADER::Start(dword _url)
Line 111... Line 113...
111
		free(EAX);						// free data
113
		free(EAX);						// free data
112
		httpd.transfer=0;
114
		httpd.transfer=0;
113
		bufsize = 0;
115
		bufsize = 0;
114
		bufpointer = free(bufpointer);
116
		bufpointer = free(bufpointer);
115
	}
117
	}
116
	data_downloaded_size = data_full_size = 0;
-
 
117
}
-
 
118
 
-
 
119
void DOWNLOADER::Completed()
-
 
120
{
-
 
121
	state = STATE_COMPLETED;
-
 
122
	ESI = httpd.transfer;
-
 
123
	bufpointer = ESI.http_msg.content_ptr;
118
	httpd.content_received = httpd.content_length = 0;
124
	bufsize = ESI.http_msg.content_received;
-
 
125
	httpd.free();
-
 
126
}
119
}
Line 127... Line 120...
127
 
120
 
128
int DOWNLOADER::MonitorProgress() 
121
bool DOWNLOADER::MonitorProgress() 
129
{
-
 
130
	dword receive_result;
-
 
131
	char redirect_url[4096*3], finaladress[4096*3];
122
{
132
	if (httpd.transfer <= 0) return false;
-
 
133
	http_receive stdcall (httpd.transfer);
-
 
134
	receive_result = EAX;
123
	if (httpd.transfer <= 0) return false;
135
	EDI = httpd.transfer;
-
 
136
	httpd.status_code = EDI.http_msg.status;
-
 
137
	data_full_size = EDI.http_msg.content_length;
124
	httpd.receive();
138
	data_downloaded_size = EDI.http_msg.content_received;
-
 
Line 139... Line 125...
139
	if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1;
125
	if (!httpd.content_length) httpd.content_length = httpd.content_received * 20;
140
 
126
 
141
	if (receive_result == 0) {
127
	if (httpd.receive_result == 0) {
142
		if (httpd.status_code >= 300) && (httpd.status_code < 400)
128
		if (httpd.status_code >= 300) && (httpd.status_code < 400)
143
		{
129
		{
144
			httpd.handle_redirect();
130
			httpd.handle_redirect();
145
			strcpy(url, httpd.url);
131
			strcpy(url, httpd.url);
146
			get_absolute_url(#finaladress, url, #redirect_url);
132
			get_absolute_url(#httpd.finaladress, url, #httpd.redirect_url);
147
			Stop();
133
			Stop();
148
			Start(#finaladress);
134
			Start(#httpd.finaladress);
149
			url = #finaladress;
135
			url = #httpd.finaladress;
-
 
136
			return false;
-
 
137
		}
-
 
138
		state = STATE_COMPLETED;
150
			return false;
139
		bufpointer = httpd.content_pointer;
151
		}
140
		bufsize = httpd.content_received;
152
		Completed();
141
		httpd.free();
153
	}
142
	}
Line 189... Line 178...
189
}
178
}
Line 190... Line 179...
190
 
179
 
191
void get_absolute_url(dword _rez, _base, _new)
180
void get_absolute_url(dword _rez, _base, _new)
192
{
181
{
193
	int i;
-
 
194
	debug("_base:");debugln(_base);
-
 
195
	debug("_new:");debugln(_new);
182
	int i;
196
	//case: ./valera.html
183
	//case: ./valera.html
197
	if (!strncmp(_new,"./", 2)) _new+=2;
184
	if (!strncmp(_new,"./", 2)) _new+=2;
198
	//case: http://site.name
185
	//case: http://site.name
199
	if (check_is_the_url_absolute(_new)) {
186
	if (check_is_the_url_absolute(_new)) {
Line 220... Line 207...
220
	//case: valera.html
207
	//case: valera.html
221
	chrcat(_rez, '/');
208
	chrcat(_rez, '/');
222
	strcat(_rez, _new); 
209
	strcat(_rez, _new); 
223
	_GET_ABSOLUTE_URL_END:
210
	_GET_ABSOLUTE_URL_END:
224
	while (i=strstr(_rez, "&")) strcpy(i+1, i+5);	
211
	while (i=strstr(_rez, "&")) strcpy(i+1, i+5);	
225
	debug("_rez:");debugln(_rez);
-
 
226
}
212
}