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