Rev 9439 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5598 | pavelyakov | 1 | #ifndef INCLUDE_LIBHTTP_H |
2 | #define INCLUDE_LIBHTTP_H |
||
4163 | hidnplayr | 3 | |
5598 | pavelyakov | 4 | #ifndef INCLUDE_KOLIBRI_H |
5 | #include "../lib/kolibri.h" |
||
6 | #endif |
||
7 | |||
9699 | Coldy | 8 | #ifdef __COFF__ |
9 | extern dword http_get; |
||
10 | extern dword http_head; |
||
11 | extern dword http_post; |
||
12 | extern dword http_find_header_field; |
||
13 | extern dword http_send; |
||
14 | extern dword http_receive; |
||
15 | extern dword http_disconnect; |
||
16 | extern dword http_free; |
||
17 | extern dword http_escape; |
||
18 | extern dword http_unescape; |
||
19 | #else |
||
5598 | pavelyakov | 20 | #ifndef INCLUDE_DLL_H |
21 | #include "../lib/dll.h" |
||
22 | #endif |
||
23 | |||
4165 | hidnplayr | 24 | dword libHTTP = #alibHTTP; |
6005 | leency | 25 | char alibHTTP[] = "/sys/lib/http.obj"; |
4165 | hidnplayr | 26 | |
7283 | leency | 27 | dword http_lib_init = #aHTTPinit; |
5576 | pavelyakov | 28 | dword http_get = #aHTTPget; |
29 | dword http_head = #aHTTPhead; |
||
30 | dword http_post = #aHTTPpost; |
||
4235 | leency | 31 | dword http_find_header_field = #aFHF; |
5576 | pavelyakov | 32 | dword http_send = #aHTTPsend; |
33 | dword http_receive = #aHTTPreceive; |
||
34 | dword http_disconnect = #aHTTPdisconnect; |
||
35 | dword http_free = #aHTTPfree; |
||
36 | dword uri_escape = #aURIescape; |
||
37 | dword uri_unescape = #aURIunescape; |
||
4163 | hidnplayr | 38 | $DD 2 dup 0 |
39 | |||
7283 | leency | 40 | char aHTTPinit[] = "lib_init"; |
6005 | leency | 41 | char aHTTPget[] = "get"; |
42 | char aHTTPhead[] = "head"; |
||
43 | char aHTTPpost[] = "post"; |
||
44 | char aFHF[] = "find_header_field"; |
||
45 | char aHTTPsend[] = "send"; |
||
46 | char aHTTPreceive[] = "receive"; |
||
47 | char aHTTPdisconnect[] = "disconnect"; |
||
48 | char aHTTPfree[] = "free"; |
||
49 | char aURIescape[] = "escape"; |
||
50 | char aURIunescape[] = "unescape"; |
||
9699 | Coldy | 51 | #endif |
4163 | hidnplayr | 52 | |
5534 | hidnplayr | 53 | // status flags |
4163 | hidnplayr | 54 | #define FLAG_HTTP11 1 << 0 |
55 | #define FLAG_GOT_HEADER 1 << 1 |
||
4536 | leency | 56 | #define FLAG_GOT_ALL_DATA 1 << 2 |
4163 | hidnplayr | 57 | #define FLAG_CONTENT_LENGTH 1 << 3 |
58 | #define FLAG_CHUNKED 1 << 4 |
||
4235 | leency | 59 | #define FLAG_CONNECTED 1 << 5 |
4163 | hidnplayr | 60 | |
5534 | hidnplayr | 61 | // user flags |
62 | #define FLAG_KEEPALIVE 1 << 8 |
||
6001 | leency | 63 | #define FLAG_MULTIBUFF 1 << 9 |
5534 | hidnplayr | 64 | |
65 | // error flags |
||
4163 | hidnplayr | 66 | #define FLAG_INVALID_HEADER 1 << 16 |
67 | #define FLAG_NO_RAM 1 << 17 |
||
68 | #define FLAG_SOCKET_ERROR 1 << 18 |
||
4235 | leency | 69 | #define FLAG_TIMEOUT_ERROR 1 << 19 |
4536 | leency | 70 | #define FLAG_TRANSFER_FAILED 1 << 20 |
4163 | hidnplayr | 71 | |
72 | struct http_msg{ |
||
8305 | leency | 73 | dword socket; |
74 | dword flags; |
||
75 | dword write_ptr; |
||
76 | dword buffer_length; |
||
77 | dword chunk_ptr; |
||
78 | dword timestamp; |
||
79 | dword status; |
||
80 | dword header_length; |
||
81 | dword content_ptr; |
||
82 | dword content_length; |
||
83 | dword content_received; |
||
84 | char http_header; |
||
5576 | pavelyakov | 85 | }; |
86 | |||
5598 | pavelyakov | 87 | |
8305 | leency | 88 | #define URL_SIZE 4000 |
89 | //===================================================// |
||
90 | // // |
||
91 | // HTTP // |
||
92 | // // |
||
93 | //===================================================// |
||
94 | |||
95 | struct _http |
||
96 | { |
||
97 | dword cur_url; |
||
98 | dword transfer; |
||
99 | dword content_length; |
||
100 | dword content_received; |
||
101 | dword status_code; |
||
102 | dword receive_result; |
||
103 | dword content_pointer; |
||
104 | |||
105 | dword get(); |
||
106 | bool stop(); |
||
107 | void hfree(); |
||
108 | void receive(); |
||
109 | dword header_field(); |
||
110 | }; |
||
111 | |||
112 | dword _http::get(dword _url) |
||
113 | { |
||
114 | cur_url = _url; |
||
8413 | leency | 115 | if (streqrp(cur_url, "http://gate.aspero.pro/?site=")) cur_url += 29; |
8305 | leency | 116 | http_get stdcall (_url, 0, 0, #accept_language); |
117 | transfer = EAX; |
||
8410 | leency | 118 | return EAX; |
8305 | leency | 119 | } |
120 | |||
121 | void _http::hfree() |
||
122 | { |
||
123 | http_free stdcall (transfer); |
||
124 | transfer=0; |
||
125 | } |
||
126 | |||
127 | bool _http::stop() |
||
128 | { |
||
129 | if (transfer) |
||
130 | { |
||
8698 | leency | 131 | /* |
8305 | leency | 132 | EAX = transfer; |
133 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
||
134 | $push EAX // save it on the stack |
||
135 | http_free stdcall (transfer); // abort connection |
||
136 | $pop EAX |
||
137 | free(EAX); // free data |
||
138 | transfer=0; |
||
8698 | leency | 139 | */ |
140 | hfree(); |
||
8305 | leency | 141 | return true; |
142 | } |
||
143 | return false; |
||
144 | } |
||
145 | |||
146 | void _http::receive() |
||
147 | { |
||
148 | http_receive stdcall (transfer); |
||
149 | receive_result = EAX; |
||
150 | |||
151 | EDI = transfer; |
||
152 | if (!EAX) { |
||
153 | status_code = EDI.http_msg.status; |
||
154 | content_pointer = EDI.http_msg.content_ptr; |
||
155 | } |
||
156 | content_length = EDI.http_msg.content_length; |
||
157 | content_received = EDI.http_msg.content_received; |
||
158 | } |
||
159 | |||
160 | :dword _http::header_field(dword _header_field, _dst, _size) |
||
161 | { |
||
162 | http_find_header_field stdcall (transfer, _header_field); |
||
163 | if (EAX!=0) { |
||
164 | ESI = EAX; |
||
165 | EDI = _dst; |
||
166 | EDX = _size; |
||
167 | do { |
||
168 | $lodsb; |
||
169 | $stosb; |
||
170 | $dec edx |
||
171 | } while (AL != 0) && (AL != 13) && (AL != 10) && (EDX>0); |
||
172 | DSBYTE[EDI-1]='\0'; |
||
173 | return _dst; |
||
174 | } |
||
175 | return NULL; |
||
176 | } |
||
177 | |||
178 | |||
179 | //===================================================// |
||
180 | // // |
||
181 | // CHECK PATH TYPE // |
||
182 | // // |
||
183 | //===================================================// |
||
184 | |||
185 | :int check_is_the_adress_local(dword _in) |
||
186 | { |
||
187 | if (ESBYTE[_in]!='/') return false; |
||
188 | _in++; |
||
189 | if(!strncmp(_in,"rd/",3)) return true; |
||
190 | if(!strncmp(_in,"fd/",3)) return true; |
||
191 | if(!strncmp(_in,"hd",2)) return true; |
||
192 | if(!strncmp(_in,"bd",2)) return true; |
||
193 | if(!strncmp(_in,"cd",2)) return true; |
||
194 | if(!strncmp(_in,"sys/",4)) return true; |
||
195 | if(!strncmp(_in,"tmp",3)) return true; |
||
196 | if(!strncmp(_in,"usbhd",5)) return true; |
||
197 | if(!strncmp(_in,"kolibrios",9)) return true; |
||
198 | return false; |
||
199 | } |
||
200 | |||
201 | :int check_is_the_url_absolute(dword _in) |
||
202 | { |
||
203 | if(!strncmp(_in,"ftp:",4)) return true; |
||
204 | if(!strncmp(_in,"http:",5)) return true; |
||
205 | if(!strncmp(_in,"https:",6)) return true; |
||
206 | if(!strncmp(_in,"mailto:",7)) return true; |
||
207 | if(!strncmp(_in,"tel:",4)) return true; |
||
208 | if(!strncmp(_in,"#",1)) return true; |
||
209 | if(!strncmp(_in,"WebView:",8)) return true; |
||
210 | if(check_is_the_adress_local(_in)) return true; |
||
211 | return false; |
||
212 | } |
||
213 | |||
214 | :dword get_absolute_url(dword new_URL, base_URL) |
||
215 | { |
||
216 | int i; |
||
217 | dword orig_URL = new_URL; |
||
218 | char newurl[URL_SIZE+1]; |
||
219 | strcpy(#newurl, base_URL); |
||
220 | |||
221 | while (i=strstr(new_URL, "&")) strcpy(i+1, i+5); |
||
222 | |||
8410 | leency | 223 | if (check_is_the_url_absolute(new_URL)) return new_URL; |
8305 | leency | 224 | |
8410 | leency | 225 | switch(ESBYTE[new_URL]) { |
226 | case '.': |
||
227 | new_URL++; |
||
228 | if (ESBYTE[new_URL] == '/') { |
||
229 | new_URL++; |
||
230 | } |
||
231 | else if (ESBYTE[new_URL] == '.') && (ESBYTE[new_URL+1] == '/') { |
||
232 | _GO_UP: |
||
233 | new_URL+=2; |
||
234 | newurl[strrchr(#newurl, '/')-1] = '\0'; |
||
235 | } |
||
236 | goto _DEFAULT; |
||
237 | case '?': |
||
238 | strchr(#newurl+8, '?'); //returns EAX |
||
239 | if (EAX) ESBYTE[EAX] = '\0'; |
||
9439 | leency | 240 | strchr(#newurl+8, '/'); //returns EAX |
241 | if (!EAX) chrcat(#newurl, '/'); |
||
8410 | leency | 242 | break; |
243 | case '/': |
||
244 | new_URL++; |
||
245 | if (ESBYTE[new_URL] == '/') { |
||
246 | strcpy(#newurl, "http:/"); |
||
247 | break; |
||
248 | } |
||
249 | EAX = strchr(#newurl+8, '/'); |
||
250 | if (EAX) ESBYTE[EAX] = '\0'; |
||
251 | default: |
||
252 | _DEFAULT: |
||
253 | EAX = strrchr(#newurl, '/'); |
||
254 | if (newurl[EAX-2]!='/') newurl[EAX] = '\0'; |
||
255 | if (!strncmp(new_URL,"../",3)) goto _GO_UP; |
||
256 | if (newurl[strlen(#newurl)-1]!='/') strncat(#newurl, "/", URL_SIZE); |
||
8305 | leency | 257 | } |
8350 | leency | 258 | strncat(#newurl, new_URL, URL_SIZE); |
259 | strncpy(orig_URL, #newurl, URL_SIZE); |
||
8305 | leency | 260 | return orig_URL; |
261 | } |
||
262 | |||
263 | |||
5598 | pavelyakov | 264 | #endif><>><>><>><>><>><>><>><>><>><>><>><>><> |