Rev 6058 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6058 | Rev 6216 | ||
---|---|---|---|
1 | enum { |
1 | enum { |
2 | STATE_NOT_STARTED, |
2 | STATE_NOT_STARTED, |
3 | STATE_IN_PROGRESS, |
3 | STATE_IN_PROGRESS, |
4 | STATE_COMPLETED |
4 | STATE_COMPLETED |
5 | }; |
5 | }; |
6 | 6 | ||
7 | struct DOWNLOADER { |
7 | struct DOWNLOADER { |
8 | unsigned data_downloaded_size, data_full_size; |
8 | unsigned data_downloaded_size, data_full_size; |
9 | dword bufpointer, bufsize, url; |
9 | dword bufpointer, bufsize, url; |
10 | byte state; |
10 | byte state; |
11 | dword http_transfer; |
11 | dword http_transfer; |
12 | int http_status_code; |
12 | int http_status_code; |
13 | dword Start(); |
13 | dword Start(); |
14 | void Stop(); |
14 | void Stop(); |
15 | void Completed(); |
15 | void Completed(); |
16 | int MonitorProgress(); |
16 | int MonitorProgress(); |
17 | } downloader; |
17 | } downloader; |
18 | 18 | ||
19 | dword DOWNLOADER::Start(dword _url) |
19 | dword DOWNLOADER::Start(dword _url) |
20 | { |
20 | { |
21 | url = _url; |
21 | url = _url; |
22 | state = STATE_IN_PROGRESS; |
22 | state = STATE_IN_PROGRESS; |
23 | http_get stdcall (url, 0, 0, #accept_language); |
23 | http_get stdcall (url, 0, 0, #accept_language); |
24 | http_transfer = EAX; |
24 | http_transfer = EAX; |
25 | return http_transfer; |
25 | return http_transfer; |
26 | } |
26 | } |
27 | 27 | ||
28 | void DOWNLOADER::Stop() |
28 | void DOWNLOADER::Stop() |
29 | { |
29 | { |
30 | state = STATE_NOT_STARTED; |
30 | state = STATE_NOT_STARTED; |
31 | if (http_transfer!=0) |
31 | if (http_transfer!=0) |
32 | { |
32 | { |
33 | EAX = http_transfer; |
33 | EAX = http_transfer; |
34 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
34 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
35 | $push EAX // save it on the stack |
35 | $push EAX // save it on the stack |
36 | http_free stdcall (http_transfer); // abort connection |
36 | http_free stdcall (http_transfer); // abort connection |
37 | $pop EAX |
37 | $pop EAX |
38 | mem_Free(EAX); // free data |
38 | mem_Free(EAX); // free data |
39 | http_transfer=0; |
39 | http_transfer=0; |
40 | bufsize = 0; |
40 | bufsize = 0; |
41 | bufpointer = mem_Free(bufpointer); |
41 | bufpointer = mem_Free(bufpointer); |
42 | } |
42 | } |
43 | data_downloaded_size = data_full_size = 0; |
43 | data_downloaded_size = data_full_size = 0; |
44 | } |
44 | } |
45 | 45 | ||
46 | void DOWNLOADER::Completed() |
46 | void DOWNLOADER::Completed() |
47 | { |
47 | { |
48 | state = STATE_COMPLETED; |
48 | state = STATE_COMPLETED; |
49 | ESI = http_transfer; |
49 | ESI = http_transfer; |
50 | bufpointer = ESI.http_msg.content_ptr; |
50 | bufpointer = ESI.http_msg.content_ptr; |
51 | bufsize = ESI.http_msg.content_received; |
51 | bufsize = ESI.http_msg.content_received; |
52 | http_free stdcall (http_transfer); |
52 | http_free stdcall (http_transfer); |
53 | http_transfer=0; |
53 | http_transfer=0; |
54 | } |
54 | } |
55 | 55 | ||
56 | int DOWNLOADER::MonitorProgress() |
56 | int DOWNLOADER::MonitorProgress() |
57 | { |
57 | { |
58 | dword receive_result; |
58 | dword receive_result; |
59 | char redirect_url[4096*3], finaladress[4096*3]; |
59 | char redirect_url[4096*3], finaladress[4096*3]; |
60 | if (http_transfer <= 0) return false; |
60 | if (http_transfer <= 0) return false; |
61 | http_receive stdcall (http_transfer); |
61 | http_receive stdcall (http_transfer); |
62 | receive_result = EAX; |
62 | receive_result = EAX; |
63 | EDI = http_transfer; |
63 | EDI = http_transfer; |
64 | http_status_code = EDI.http_msg.status; |
64 | http_status_code = EDI.http_msg.status; |
65 | data_full_size = EDI.http_msg.content_length; |
65 | data_full_size = EDI.http_msg.content_length; |
66 | data_downloaded_size = EDI.http_msg.content_received; |
66 | data_downloaded_size = EDI.http_msg.content_received; |
67 | if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1; |
67 | if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1; |
68 | 68 | ||
69 | if (receive_result == 0) { |
69 | if (receive_result == 0) { |
70 | if (http_status_code >= 300) && (http_status_code < 400) |
70 | if (http_status_code >= 300) && (http_status_code < 400) |
71 | { |
71 | { |
72 | http_find_header_field stdcall (http_transfer, "location\0"); |
72 | http_find_header_field stdcall (http_transfer, "location\0"); |
73 | if (EAX!=0) { |
73 | if (EAX!=0) { |
74 | ESI = EAX; |
74 | ESI = EAX; |
75 | EDI = #redirect_url; |
75 | EDI = #redirect_url; |
76 | do { |
76 | do { |
77 | $lodsb; |
77 | $lodsb; |
78 | $stosb; |
78 | $stosb; |
79 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
79 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
80 | DSBYTE[EDI-1]='\0'; |
80 | DSBYTE[EDI-1]='\0'; |
81 | } |
81 | } |
82 | get_absolute_url(#finaladress, url, #redirect_url); |
82 | get_absolute_url(#finaladress, url, #redirect_url); |
83 | Stop(); |
83 | Stop(); |
84 | Start(#finaladress); |
84 | Start(#finaladress); |
85 | url = #finaladress; |
85 | url = #finaladress; |
86 | return false; |
86 | return false; |
87 | } |
87 | } |
88 | Completed(); |
88 | Completed(); |
89 | } |
89 | } |
90 | return true; |
90 | return true; |
91 | } |
91 | } |
92 | 92 | ||
93 | 93 | ||
94 | /*===================================== |
94 | /*===================================== |
95 | == == |
95 | == == |
96 | == CHECK URL TYPE == |
96 | == CHECK URL TYPE == |
97 | == == |
97 | == == |
98 | =====================================*/ |
98 | =====================================*/ |
99 | 99 | ||
100 | 100 | ||
101 | int check_is_the_adress_local(dword _in) |
101 | int check_is_the_adress_local(dword _in) |
102 | { |
102 | { |
103 | if (ESBYTE[_in]!='/') return false; |
103 | if (ESBYTE[_in]!='/') return false; |
104 | _in++; |
104 | _in++; |
105 | if(!strncmp(_in,"rd/",3)) return true; |
105 | if(!strncmp(_in,"rd/",3)) return true; |
106 | if(!strncmp(_in,"fd/",3)) return true; |
106 | if(!strncmp(_in,"fd/",3)) return true; |
107 | if(!strncmp(_in,"hd/",3)) return true; |
107 | if(!strncmp(_in,"hd",2)) return true; |
108 | if(!strncmp(_in,"bd/",3)) return true; |
108 | if(!strncmp(_in,"bd",2)) return true; |
109 | if(!strncmp(_in,"cd/",3)) return true; |
109 | if(!strncmp(_in,"cd",2)) return true; |
110 | if(!strncmp(_in,"sys/",4)) return true; |
110 | if(!strncmp(_in,"sys/",4)) return true; |
111 | if(!strncmp(_in,"tmp/",4)) return true; |
111 | if(!strncmp(_in,"tmp/",4)) return true; |
112 | if(!strncmp(_in,"usbhd",6)) return true; |
112 | if(!strncmp(_in,"usbhd",5)) return true; |
113 | if(!strncmp(_in,"kolibrios",10)) return true; |
113 | if(!strncmp(_in,"kolibrios",10)) return true; |
114 | return false; |
114 | return false; |
115 | } |
115 | } |
116 | 116 | ||
117 | int check_is_the_url_absolute(dword _in) |
117 | int check_is_the_url_absolute(dword _in) |
118 | { |
118 | { |
119 | if(!strncmp(_in,"ftp:",4)) return true; |
119 | if(!strncmp(_in,"ftp:",4)) return true; |
120 | if(!strncmp(_in,"http:",5)) return true; |
120 | if(!strncmp(_in,"http:",5)) return true; |
121 | if(!strncmp(_in,"https:",6)) return true; |
121 | if(!strncmp(_in,"https:",6)) return true; |
122 | if(!strncmp(_in,"mailto:",7)) return true; |
122 | if(!strncmp(_in,"mailto:",7)) return true; |
123 | if(check_is_the_adress_local(_in)) return true; |
123 | if(check_is_the_adress_local(_in)) return true; |
124 | return false; |
124 | return false; |
125 | } |
125 | } |
126 | 126 | ||
127 | void get_absolute_url(dword _rez, _base, _new) |
127 | void get_absolute_url(dword _rez, _base, _new) |
128 | { |
128 | { |
129 | int i; |
129 | int i; |
130 | debug("_base:");debugln(_base); |
130 | debug("_base:");debugln(_base); |
131 | debug("_new:");debugln(_new); |
131 | debug("_new:");debugln(_new); |
132 | //case: ./valera.html |
132 | //case: ./valera.html |
133 | if (!strncmp(_new,"./", 2)) _new+=2; |
133 | if (!strncmp(_new,"./", 2)) _new+=2; |
134 | //case: http://site.name |
134 | //case: http://site.name |
135 | if (check_is_the_url_absolute(_new)) { |
135 | if (check_is_the_url_absolute(_new)) { |
136 | strcpy(_rez, _new); |
136 | strcpy(_rez, _new); |
137 | goto _GET_ABSOLUTE_URL_END; |
137 | goto _GET_ABSOLUTE_URL_END; |
138 | } |
138 | } |
139 | //case: /valera.html |
139 | //case: /valera.html |
140 | if (ESBYTE[_new] == '/') //remove everything after site domain name |
140 | if (ESBYTE[_new] == '/') //remove everything after site domain name |
141 | { |
141 | { |
142 | strcpy(_rez, _base); |
142 | strcpy(_rez, _base); |
143 | i = strchr(_rez+8,'/'); |
143 | i = strchr(_rez+8,'/'); |
144 | if (i<1) i=strlen(_rez)+_rez; |
144 | if (i<1) i=strlen(_rez)+_rez; |
145 | strcpy(i, _new); |
145 | strcpy(i, _new); |
146 | goto _GET_ABSOLUTE_URL_END; |
146 | goto _GET_ABSOLUTE_URL_END; |
147 | } |
147 | } |
148 | //case: ../../valera.html |
148 | //case: ../../valera.html |
149 | strcpy(_rez, _base); |
149 | strcpy(_rez, _base); |
150 | ESBYTE[ strrchr(_rez,'/') + _rez -1 ] = '\0'; //remove name |
150 | ESBYTE[ strrchr(_rez,'/') + _rez -1 ] = '\0'; //remove name |
151 | while (!strncmp(_new,"../",3)) |
151 | while (!strncmp(_new,"../",3)) |
152 | { |
152 | { |
153 | _new += 3; |
153 | _new += 3; |
154 | ESBYTE[ strrchr(_rez,'/') + _rez -1 ] = '\0'; |
154 | ESBYTE[ strrchr(_rez,'/') + _rez -1 ] = '\0'; |
155 | } |
155 | } |
156 | //case: valera.html |
156 | //case: valera.html |
157 | chrcat(_rez, '/'); |
157 | chrcat(_rez, '/'); |
158 | strcat(_rez, _new); |
158 | strcat(_rez, _new); |
159 | _GET_ABSOLUTE_URL_END: |
159 | _GET_ABSOLUTE_URL_END: |
160 | while (i=strstr(_rez, "&")) strcpy(i+1, i+5); |
160 | while (i=strstr(_rez, "&")) strcpy(i+1, i+5); |
161 | debug("_rez:");debugln(_rez); |
161 | debug("_rez:");debugln(_rez); |
162 | }1)>>=> |
162 | }1)>>=> |