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