Rev 6969 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6969 | Rev 7281 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | //===================================================// |
|
- | 2 | // // |
|
- | 3 | // HTTP // |
|
- | 4 | // // |
|
- | 5 | //===================================================// |
|
- | 6 | ||
- | 7 | struct _http |
|
- | 8 | { |
|
- | 9 | dword url; |
|
- | 10 | dword transfer; |
|
- | 11 | dword content_length; |
|
- | 12 | dword content_received; |
|
- | 13 | dword status_code; |
|
- | 14 | dword receive_result; |
|
- | 15 | dword content_pointer; |
|
- | 16 | ||
- | 17 | dword get(); |
|
- | 18 | void free(); |
|
- | 19 | void receive(); |
|
- | 20 | bool handle_redirect(); |
|
- | 21 | }; |
|
- | 22 | ||
- | 23 | dword _http::get(dword _url) |
|
- | 24 | { |
|
- | 25 | url = _url; |
|
- | 26 | http_get stdcall (url, 0, 0, #accept_language); |
|
- | 27 | transfer = EAX; |
|
- | 28 | return transfer; |
|
- | 29 | } |
|
- | 30 | ||
- | 31 | void _http::free() |
|
- | 32 | { |
|
- | 33 | http_free stdcall (transfer); |
|
- | 34 | transfer=0; |
|
- | 35 | } |
|
- | 36 | ||
- | 37 | void _http::receive() |
|
- | 38 | { |
|
- | 39 | http_receive stdcall (transfer); |
|
- | 40 | receive_result = EAX; |
|
- | 41 | ||
- | 42 | ESI = transfer; |
|
- | 43 | if (!EAX) status_code = ESI.http_msg.status; |
|
- | 44 | content_length = ESI.http_msg.content_length; |
|
- | 45 | content_received = ESI.http_msg.content_received; |
|
- | 46 | ||
- | 47 | } |
|
- | 48 | ||
- | 49 | bool _http::handle_redirect() |
|
- | 50 | { |
|
- | 51 | dword redirect, i; |
|
- | 52 | char redirect_url[4096*3], finaladress[4096*3]; |
|
- | 53 | http_find_header_field stdcall (transfer, "location\0"); |
|
- | 54 | if (EAX!=0) { |
|
- | 55 | ESI = EAX; |
|
- | 56 | EDI = #redirect_url; |
|
- | 57 | do { |
|
- | 58 | $lodsb; |
|
- | 59 | $stosb; |
|
- | 60 | } while (AL != 0) && (AL != 13) && (AL != 10); |
|
- | 61 | DSBYTE[EDI-1]='\0'; |
|
- | 62 | get_absolute_url(#finaladress, url, #redirect_url); |
|
- | 63 | strcpy(url, #finaladress); |
|
- | 64 | return true; |
|
- | 65 | } |
|
- | 66 | return false; |
|
- | 67 | } |
|
- | 68 | ||
- | 69 | //===================================================// |
|
- | 70 | // // |
|
- | 71 | // DOWNLOADER // |
|
- | 72 | // // |
|
- | 73 | //===================================================// |
|
- | 74 | ||
Line 1... | Line 75... | ||
1 | enum { |
75 | |
2 | STATE_NOT_STARTED, |
76 | enum { |
3 | STATE_IN_PROGRESS, |
77 | STATE_NOT_STARTED, |
4 | STATE_COMPLETED |
78 | STATE_IN_PROGRESS, |
5 | }; |
79 | STATE_COMPLETED |
Line 6... | Line 80... | ||
6 | 80 | }; |
|
- | 81 | ||
7 | struct DOWNLOADER { |
82 | struct DOWNLOADER { |
8 | unsigned data_downloaded_size, data_full_size; |
83 | _http httpd; |
9 | dword bufpointer, bufsize, url; |
84 | unsigned data_downloaded_size, data_full_size; |
10 | byte state; |
- | |
11 | dword http_transfer; |
- | |
12 | int http_status_code; |
85 | dword bufpointer, bufsize, url; |
13 | dword Start(); |
86 | int state; |
14 | void Stop(); |
87 | dword Start(); |
15 | void Completed(); |
88 | void Stop(); |
16 | int MonitorProgress(); |
89 | void Completed(); |
Line 17... | Line 90... | ||
17 | } downloader; |
90 | int MonitorProgress(); |
18 | 91 | } downloader; |
|
19 | dword DOWNLOADER::Start(dword _url) |
92 | |
20 | { |
93 | dword DOWNLOADER::Start(dword _url) |
21 | url = _url; |
- | |
22 | state = STATE_IN_PROGRESS; |
94 | { |
23 | http_get stdcall (url, 0, 0, #accept_language); |
95 | url = _url; |
24 | http_transfer = EAX; |
96 | state = STATE_IN_PROGRESS; |
Line 25... | Line 97... | ||
25 | return http_transfer; |
97 | httpd.get(url); |
26 | } |
98 | return httpd.transfer; |
27 | 99 | } |
|
28 | void DOWNLOADER::Stop() |
100 | |
29 | { |
101 | void DOWNLOADER::Stop() |
30 | state = STATE_NOT_STARTED; |
102 | { |
31 | if (http_transfer!=0) |
103 | state = STATE_NOT_STARTED; |
32 | { |
104 | if (httpd.transfer!=0) |
33 | EAX = http_transfer; |
105 | { |
34 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
106 | EAX = httpd.transfer; |
35 | $push EAX // save it on the stack |
107 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
36 | http_free stdcall (http_transfer); // abort connection |
108 | $push EAX // save it on the stack |
37 | $pop EAX |
109 | http_free stdcall (httpd.transfer); // abort connection |
38 | mem_Free(EAX); // free data |
110 | $pop EAX |
39 | http_transfer=0; |
111 | free(EAX); // free data |
40 | bufsize = 0; |
112 | httpd.transfer=0; |
41 | bufpointer = mem_Free(bufpointer); |
113 | bufsize = 0; |
Line 42... | Line 114... | ||
42 | } |
114 | bufpointer = free(bufpointer); |
43 | data_downloaded_size = data_full_size = 0; |
115 | } |
44 | } |
116 | data_downloaded_size = data_full_size = 0; |
45 | 117 | } |
|
46 | void DOWNLOADER::Completed() |
118 | |
47 | { |
119 | void DOWNLOADER::Completed() |
48 | state = STATE_COMPLETED; |
- | |
49 | ESI = http_transfer; |
120 | { |
50 | bufpointer = ESI.http_msg.content_ptr; |
121 | state = STATE_COMPLETED; |
Line 51... | Line 122... | ||
51 | bufsize = ESI.http_msg.content_received; |
122 | ESI = httpd.transfer; |
52 | http_free stdcall (http_transfer); |
123 | bufpointer = ESI.http_msg.content_ptr; |
53 | http_transfer=0; |
124 | bufsize = ESI.http_msg.content_received; |
54 | } |
125 | httpd.free(); |
55 | 126 | } |
|
56 | int DOWNLOADER::MonitorProgress() |
127 | |
57 | { |
128 | int DOWNLOADER::MonitorProgress() |
58 | dword receive_result; |
129 | { |
59 | char redirect_url[4096*3], finaladress[4096*3]; |
130 | dword receive_result; |
60 | if (http_transfer <= 0) return false; |
131 | char redirect_url[4096*3], finaladress[4096*3]; |
61 | http_receive stdcall (http_transfer); |
132 | if (httpd.transfer <= 0) return false; |
62 | receive_result = EAX; |
133 | http_receive stdcall (httpd.transfer); |
Line 63... | Line 134... | ||
63 | EDI = http_transfer; |
134 | receive_result = EAX; |
64 | http_status_code = EDI.http_msg.status; |
135 | EDI = httpd.transfer; |
65 | data_full_size = EDI.http_msg.content_length; |
136 | httpd.status_code = EDI.http_msg.status; |
66 | data_downloaded_size = EDI.http_msg.content_received; |
- | |
67 | if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1; |
- | |
68 | - | ||
69 | if (receive_result == 0) { |
137 | data_full_size = EDI.http_msg.content_length; |
70 | if (http_status_code >= 300) && (http_status_code < 400) |
- | |
71 | { |
- | |
72 | http_find_header_field stdcall (http_transfer, "location\0"); |
- | |
73 | if (EAX!=0) { |
- | |
74 | ESI = EAX; |
138 | data_downloaded_size = EDI.http_msg.content_received; |
75 | EDI = #redirect_url; |
- | |
76 | do { |
139 | if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1; |
77 | $lodsb; |
140 | |
78 | $stosb; |
141 | if (receive_result == 0) { |
79 | } while ((AL != 0) && (AL != 13) && (AL != 10)); |
142 | if (httpd.status_code >= 300) && (httpd.status_code < 400) |
80 | DSBYTE[EDI-1]='\0'; |
143 | { |
Line 92... | Line 155... | ||
92 | 155 | } |
|
Line 93... | Line 156... | ||
93 | 156 | ||
94 | /*===================================== |
157 | |
95 | == == |
158 | /*===================================== |
96 | == CHECK URL TYPE == |
159 | == == |
97 | == == |
160 | == CHECK PATH TYPE == |
Line 98... | Line 161... | ||
98 | =====================================*/ |
161 | == == |