Rev 4996 | Rev 5537 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4996 | Rev 5534 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; HTTP library for KolibriOS ;; |
6 | ;; HTTP library for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
Line 52... | Line 52... | ||
52 | stosb |
52 | stosb |
53 | jmp .copyloop |
53 | jmp .copyloop |
54 | .copydone: |
54 | .copydone: |
55 | } |
55 | } |
Line 56... | Line 56... | ||
56 | 56 | ||
Line 57... | Line 57... | ||
57 | macro HTTP_init_buffer buffer, socketnum { |
57 | macro HTTP_init_buffer buffer, socketnum, flags { |
58 | 58 | ||
59 | mov eax, buffer |
59 | mov eax, buffer |
60 | push socketnum |
60 | push socketnum |
- | 61 | popd [eax + http_msg.socket] |
|
- | 62 | lea esi, [eax + http_msg.http_header] |
|
61 | popd [eax + http_msg.socket] |
63 | push flags |
62 | lea esi, [eax + http_msg.http_header] |
64 | pop [eax + http_msg.flags] |
63 | mov [eax + http_msg.flags], FLAG_CONNECTED |
65 | or [eax + http_msg.flags], FLAG_CONNECTED |
64 | mov [eax + http_msg.write_ptr], esi |
66 | mov [eax + http_msg.write_ptr], esi |
Line 65... | Line 67... | ||
65 | mov [eax + http_msg.buffer_length], BUFFERSIZE - http_msg.http_header |
67 | mov [eax + http_msg.buffer_length], BUFFERSIZE - http_msg.http_header |
Line 174... | Line 176... | ||
174 | popa |
176 | popa |
175 | ret |
177 | ret |
Line 176... | Line 178... | ||
176 | 178 | ||
Line -... | Line 179... | ||
- | 179 | endp |
|
- | 180 | ||
177 | endp |
181 | |
178 | 182 | ||
179 | ;;================================================================================================;; |
183 | ;;================================================================================================;; |
180 | proc HTTP_get URL, add_header ;///////////////////////////////////////////////////////////////////;; |
184 | proc HTTP_get URL, identifier, flags, add_header ;////////////////////////////////////////////////;; |
181 | ;;------------------------------------------------------------------------------------------------;; |
185 | ;;------------------------------------------------------------------------------------------------;; |
182 | ;? Initiates a HTTP connection, using 'GET' method. ;; |
186 | ;? Initiates a HTTP connection, using 'GET' method. ;; |
- | 187 | ;;------------------------------------------------------------------------------------------------;; |
|
- | 188 | ;> URL = pointer to ASCIIZ URL ;; |
|
183 | ;;------------------------------------------------------------------------------------------------;; |
189 | ;> identifier = Identifier of an already open connection, or NULL to create a new one. ;; |
184 | ;> URL = pointer to ASCIIZ URL ;; |
190 | ;> flags = Flags indicating how to threat the connection. ;; |
185 | ;> add_header = pointer to additional header parameters (ASCIIZ), or null for none. ;; |
191 | ;> add_header = pointer to additional header parameters (ASCIIZ), or NULL for none. ;; |
186 | ;;------------------------------------------------------------------------------------------------;; |
192 | ;;------------------------------------------------------------------------------------------------;; |
187 | ;< eax = 0 (error) / buffer ptr ;; |
193 | ;< eax = 0 (error) / buffer ptr ;; |
188 | ;;================================================================================================;; |
194 | ;;================================================================================================;; |
189 | locals |
195 | locals |
190 | hostname dd ? |
- | |
191 | pageaddr dd ? |
196 | hostname dd ? |
192 | sockaddr dd ? |
197 | pageaddr dd ? |
193 | socketnum dd ? |
198 | socketnum dd ? |
194 | buffer dd ? |
199 | buffer dd ? |
Line -... | Line 200... | ||
- | 200 | port dd ? |
|
- | 201 | endl |
|
195 | port dd ? |
202 | |
Line 196... | Line 203... | ||
196 | endl |
203 | and [flags], FLAG_KEEPALIVE or FLAG_MULTIBUFF ; filter out invalid flags |
197 | 204 | ||
198 | pusha |
205 | pusha |
199 | 206 | ||
200 | ; split the URL into hostname and pageaddr |
207 | ; split the URL into hostname and pageaddr |
201 | stdcall parse_url, [URL] |
208 | stdcall parse_url, [URL] |
202 | test eax, eax |
209 | test eax, eax |
Line -... | Line 210... | ||
- | 210 | jz .error |
|
- | 211 | mov [hostname], eax |
|
- | 212 | mov [pageaddr], ebx |
|
- | 213 | mov [port], ecx |
|
- | 214 | ||
- | 215 | mov eax, [identifier] |
|
- | 216 | test eax, eax |
|
- | 217 | jz .open_new |
|
- | 218 | test [eax + http_msg.flags], FLAG_CONNECTED |
|
203 | jz .error |
219 | jz .error |
- | 220 | mov eax, [eax + http_msg.socket] |
|
204 | mov [hostname], eax |
221 | mov [socketnum], eax |
205 | mov [pageaddr], ebx |
222 | jmp .send_request |
206 | mov [port], ecx |
223 | |
207 | 224 | ; Connect to the other side. |
|
Line 208... | Line 225... | ||
208 | ; Connect to the other side. |
225 | .open_new: |
- | 226 | stdcall open_connection, [hostname], [port] |
|
209 | stdcall open_connection, [hostname], [port] |
227 | test eax, eax |
210 | test eax, eax |
228 | jz .error |
211 | jz .error |
229 | mov [socketnum], eax |
212 | mov [socketnum], eax |
230 | |
213 | 231 | ; Create the HTTP request. |
|
Line 254... | Line 272... | ||
254 | copy_till_zero |
272 | copy_till_zero |
255 | @@: |
273 | @@: |
Line 256... | Line 274... | ||
256 | 274 | ||
257 | mov esi, str_close |
275 | mov esi, str_close |
- | 276 | mov ecx, str_close.length |
|
- | 277 | test [flags], FLAG_KEEPALIVE |
|
- | 278 | jz @f |
|
- | 279 | mov esi, str_keep |
|
- | 280 | mov ecx, str_keep.length |
|
258 | mov ecx, str_close.length |
281 | @@: |
Line 259... | Line 282... | ||
259 | rep movsb |
282 | rep movsb |
260 | 283 | ||
Line 273... | Line 296... | ||
273 | mcall send, [socketnum], [buffer] |
296 | mcall send, [socketnum], [buffer] |
274 | test eax, eax |
297 | test eax, eax |
275 | jz .error |
298 | jz .error |
276 | DEBUGF 1, "Request has been sent to server.\n" |
299 | DEBUGF 1, "Request has been sent to server.\n" |
Line -... | Line 300... | ||
- | 300 | ||
- | 301 | cmp [identifier], 0 |
|
277 | 302 | jne .old_connection |
|
Line 278... | Line 303... | ||
278 | HTTP_init_buffer [buffer], [socketnum] |
303 | HTTP_init_buffer [buffer], [socketnum], [flags] |
279 | 304 | ||
280 | popa |
305 | popa |
Line -... | Line 306... | ||
- | 306 | mov eax, [buffer] ; return buffer ptr |
|
- | 307 | ret |
|
- | 308 | ||
- | 309 | .old_connection: |
|
- | 310 | invoke mem.free, [buffer] |
|
- | 311 | popa |
|
281 | mov eax, [buffer] ; return buffer ptr |
312 | mov eax, [identifier] |
282 | ret |
313 | ret |
283 | 314 | ||
284 | .error: |
315 | .error: |
285 | DEBUGF 1, "Error!\n" |
316 | DEBUGF 1, "Error!\n" |
Line 290... | Line 321... | ||
290 | endp |
321 | endp |
Line 291... | Line 322... | ||
291 | 322 | ||
292 | 323 | ||
293 | 324 | ||
294 | ;;================================================================================================;; |
325 | ;;================================================================================================;; |
295 | proc HTTP_head URL, add_header ;//////////////////////////////////////////////////////////////////;; |
326 | proc HTTP_head URL, identifier, flags, add_header ;///////////////////////////////////////////////;; |
296 | ;;------------------------------------------------------------------------------------------------;; |
327 | ;;------------------------------------------------------------------------------------------------;; |
297 | ;? Initiates a HTTP connection, using 'HEAD' method. ;; |
328 | ;? Initiates a HTTP connection, using 'HEAD' method. ;; |
- | 329 | ;? This will only return HTTP header and status, no content ;; |
|
- | 330 | ;;------------------------------------------------------------------------------------------------;; |
|
298 | ;? This will only return HTTP header and status, no content ;; |
331 | ;> URL = pointer to ASCIIZ URL ;; |
299 | ;;------------------------------------------------------------------------------------------------;; |
332 | ;> identifier = Identifier of an already open connection, or NULL to create a new one. ;; |
300 | ;> URL = pointer to ASCIIZ URL ;; |
333 | ;> flags = Flags indicating how to threat the connection. ;; |
301 | ;> add_header = pointer to additional header parameters (ASCIIZ), or null for none. ;; |
334 | ;> add_header = pointer to additional header parameters (ASCIIZ), or NULL for none. ;; |
302 | ;;------------------------------------------------------------------------------------------------;; |
335 | ;;------------------------------------------------------------------------------------------------;; |
303 | ;< eax = 0 (error) / buffer ptr ;; |
336 | ;< eax = 0 (error) / buffer ptr ;; |
304 | ;;================================================================================================;; |
337 | ;;================================================================================================;; |
305 | locals |
- | |
306 | hostname dd ? |
338 | locals |
307 | pageaddr dd ? |
339 | hostname dd ? |
308 | sockaddr dd ? |
340 | pageaddr dd ? |
309 | socketnum dd ? |
341 | socketnum dd ? |
Line -... | Line 342... | ||
- | 342 | buffer dd ? |
|
- | 343 | port dd ? |
|
310 | buffer dd ? |
344 | endl |
311 | port dd ? |
345 | |
312 | endl |
346 | and [flags], FLAG_KEEPALIVE or FLAG_MULTIBUFF ; filter out invalid flags |
313 | 347 | ||
314 | pusha |
348 | pusha |
315 | ; split the URL into hostname and pageaddr |
349 | ; split the URL into hostname and pageaddr |
316 | stdcall parse_url, [URL] |
350 | stdcall parse_url, [URL] |
317 | test eax, eax |
351 | test eax, eax |
Line -... | Line 352... | ||
- | 352 | jz .error |
|
- | 353 | mov [hostname], eax |
|
- | 354 | mov [pageaddr], ebx |
|
- | 355 | mov [port], ecx |
|
- | 356 | ||
- | 357 | mov eax, [identifier] |
|
- | 358 | test eax, eax |
|
- | 359 | jz .open_new |
|
- | 360 | test [eax + http_msg.flags], FLAG_CONNECTED |
|
318 | jz .error |
361 | jz .error |
- | 362 | mov eax, [eax + http_msg.socket] |
|
319 | mov [hostname], eax |
363 | mov [socketnum], eax |
320 | mov [pageaddr], ebx |
364 | jmp .send_request |
321 | mov [port], ecx |
365 | |
322 | 366 | ; Connect to the other side. |
|
Line 323... | Line 367... | ||
323 | ; Connect to the other side. |
367 | .open_new: |
- | 368 | stdcall open_connection, [hostname], [port] |
|
324 | stdcall open_connection, [hostname], [port] |
369 | test eax, eax |
325 | test eax, eax |
370 | jz .error |
326 | jz .error |
371 | mov [socketnum], eax |
327 | mov [socketnum], eax |
372 | |
328 | 373 | ; Create the HTTP request. |
|
Line 369... | Line 414... | ||
369 | copy_till_zero |
414 | copy_till_zero |
370 | @@: |
415 | @@: |
Line 371... | Line 416... | ||
371 | 416 | ||
372 | mov esi, str_close |
417 | mov esi, str_close |
- | 418 | mov ecx, str_close.length |
|
- | 419 | test [flags], FLAG_KEEPALIVE |
|
- | 420 | jz @f |
|
- | 421 | mov esi, str_keep |
|
- | 422 | mov ecx, str_keep.length |
|
373 | mov ecx, str_close.length |
423 | @@: |
Line 374... | Line 424... | ||
374 | rep movsb |
424 | rep movsb |
375 | 425 | ||
Line 376... | Line -... | ||
376 | mov byte[edi], 0 |
- | |
377 | DEBUGF 1, "Request:\n%s", [buffer] |
426 | mov byte[edi], 0 |
378 | 427 | DEBUGF 1, "Request:\n%s", [buffer] |
|
379 | 428 | ||
380 | ; Free unused memory |
429 | ; Free unused memory |
381 | push edi |
430 | push edi |
Line 389... | Line 438... | ||
389 | mcall send, [socketnum], [buffer] |
438 | mcall send, [socketnum], [buffer] |
390 | test eax, eax |
439 | test eax, eax |
391 | jz .error |
440 | jz .error |
392 | DEBUGF 1, "Request has been sent to server.\n" |
441 | DEBUGF 1, "Request has been sent to server.\n" |
Line -... | Line 442... | ||
- | 442 | ||
- | 443 | cmp [identifier], 0 |
|
393 | 444 | jne .old_connection |
|
Line 394... | Line 445... | ||
394 | HTTP_init_buffer [buffer], [socketnum] |
445 | HTTP_init_buffer [buffer], [socketnum], [flags] |
- | 446 | ||
- | 447 | popa |
|
- | 448 | mov eax, [buffer] ; return buffer ptr |
|
- | 449 | ret |
|
395 | 450 | ||
- | 451 | .old_connection: |
|
396 | popa |
452 | invoke mem.free, [buffer] |
- | 453 | popa |
|
Line 397... | Line 454... | ||
397 | mov eax, [buffer] |
454 | mov eax, [identifier] |
398 | ret ; return buffer ptr |
455 | ret |
399 | 456 | ||
400 | .error: |
457 | .error: |
Line 405... | Line 462... | ||
405 | 462 | ||
Line 406... | Line 463... | ||
406 | endp |
463 | endp |
407 | 464 | ||
408 | 465 | ||
409 | ;;================================================================================================;; |
466 | ;;================================================================================================;; |
410 | proc HTTP_post URL, add_header, content_type, content_length ;////////////////////////////////////;; |
467 | proc HTTP_post URL, identifier, flags, add_header, content_type, content_length ;/////////////////;; |
411 | ;;------------------------------------------------------------------------------------------------;; |
468 | ;;------------------------------------------------------------------------------------------------;; |
412 | ;? Initiates a HTTP connection, using 'POST' method. ;; |
469 | ;? Initiates a HTTP connection, using 'POST' method. ;; |
- | 470 | ;? This method is used to send data to the HTTP server ;; |
|
- | 471 | ;;------------------------------------------------------------------------------------------------;; |
|
413 | ;? This method is used to send data to the HTTP server ;; |
472 | ;> URL = pointer to ASCIIZ URL ;; |
414 | ;;------------------------------------------------------------------------------------------------;; |
473 | ;> identifier = Identifier of an already open connection, or NULL to create a new one. ;; |
415 | ;> URL = pointer to ASCIIZ URL ;; |
474 | ;> flags = Flags indicating how to threat the connection. ;; |
416 | ;> add_header = pointer to additional header parameters (ASCIIZ), or null for none. ;; |
475 | ;> add_header = pointer to additional header parameters (ASCIIZ), or NULL for none. ;; |
417 | ;> content_type = pointer to ASCIIZ string containing content type ;; |
476 | ;> content_type = pointer to ASCIIZ string containing content type ;; |
418 | ;> content_length = length of content (in bytes) ;; |
477 | ;> content_length = length of content (in bytes) ;; |
419 | ;;------------------------------------------------------------------------------------------------;; |
478 | ;;------------------------------------------------------------------------------------------------;; |
420 | ;< eax = 0 (error) / buffer ptr ;; |
479 | ;< eax = 0 (error) / buffer ptr (aka Identifier) ;; |
421 | ;;================================================================================================;; |
480 | ;;================================================================================================;; |
422 | locals |
- | |
423 | hostname dd ? |
481 | locals |
424 | pageaddr dd ? |
482 | hostname dd ? |
425 | sockaddr dd ? |
483 | pageaddr dd ? |
426 | socketnum dd ? |
484 | socketnum dd ? |
Line -... | Line 485... | ||
- | 485 | buffer dd ? |
|
- | 486 | port dd ? |
|
427 | buffer dd ? |
487 | endl |
428 | port dd ? |
488 | |
429 | endl |
489 | and [flags], FLAG_KEEPALIVE or FLAG_MULTIBUFF ; filter out invalid flags |
430 | 490 | ||
431 | pusha |
491 | pusha |
432 | ; split the URL into hostname and pageaddr |
492 | ; split the URL into hostname and pageaddr |
433 | stdcall parse_url, [URL] |
493 | stdcall parse_url, [URL] |
434 | test eax, eax |
494 | test eax, eax |
Line -... | Line 495... | ||
- | 495 | jz .error |
|
- | 496 | mov [hostname], eax |
|
- | 497 | mov [pageaddr], ebx |
|
- | 498 | mov [port], ecx |
|
- | 499 | ||
- | 500 | mov eax, [identifier] |
|
- | 501 | test eax, eax |
|
- | 502 | jz .open_new |
|
- | 503 | test [eax + http_msg.flags], FLAG_CONNECTED |
|
435 | jz .error |
504 | jz .error |
- | 505 | mov eax, [eax + http_msg.socket] |
|
436 | mov [hostname], eax |
506 | mov [socketnum], eax |
437 | mov [pageaddr], ebx |
507 | jmp .send_request |
438 | mov [port], ecx |
508 | |
439 | 509 | ; Connect to the other side. |
|
Line 440... | Line 510... | ||
440 | ; Connect to the other side. |
510 | .open_new: |
- | 511 | stdcall open_connection, [hostname], [port] |
|
441 | stdcall open_connection, [hostname], [port] |
512 | test eax, eax |
442 | test eax, eax |
513 | jz .error |
443 | jz .error |
514 | mov [socketnum], eax |
444 | mov [socketnum], eax |
515 | |
445 | 516 | ; Create the HTTP request. |
|
Line 500... | Line 571... | ||
500 | copy_till_zero |
571 | copy_till_zero |
501 | @@: |
572 | @@: |
Line 502... | Line 573... | ||
502 | 573 | ||
503 | mov esi, str_close |
574 | mov esi, str_close |
- | 575 | mov ecx, str_close.length |
|
- | 576 | test [flags], FLAG_KEEPALIVE |
|
- | 577 | jz @f |
|
- | 578 | mov esi, str_keep |
|
- | 579 | mov ecx, str_keep.length |
|
504 | mov ecx, str_close.length |
580 | @@: |
Line 505... | Line 581... | ||
505 | rep movsb |
581 | rep movsb |
506 | 582 | ||
Line 519... | Line 595... | ||
519 | mcall send, [socketnum], [buffer] |
595 | mcall send, [socketnum], [buffer] |
520 | test eax, eax |
596 | test eax, eax |
521 | jz .error |
597 | jz .error |
522 | DEBUGF 1, "Request has been sent to server.\n" |
598 | DEBUGF 1, "Request has been sent to server.\n" |
Line -... | Line 599... | ||
- | 599 | ||
- | 600 | cmp [identifier], 0 |
|
523 | 601 | jne .old_connection |
|
Line 524... | Line 602... | ||
524 | HTTP_init_buffer [buffer], [socketnum] |
602 | HTTP_init_buffer [buffer], [socketnum], [flags] |
- | 603 | ||
- | 604 | popa |
|
- | 605 | mov eax, [buffer] ; return buffer ptr |
|
- | 606 | ret |
|
- | 607 | ||
- | 608 | .old_connection: |
|
525 | 609 | invoke mem.free, [buffer] |
|
526 | popa |
610 | mov ebx, [flags] |
- | 611 | mov eax, [identifier] |
|
- | 612 | or [eax + http_msg.flags], ebx |
|
- | 613 | popa |
|
Line 527... | Line 614... | ||
527 | mov eax, [buffer] |
614 | mov eax, [identifier] |
528 | ret ; return buffer ptr |
615 | ret |
529 | 616 | ||
530 | .error: |
617 | .error: |
Line 553... | Line 640... | ||
553 | 640 | ||
554 | ; If the connection is closed, return immediately |
641 | ; If the connection is closed, return immediately |
555 | test [ebp + http_msg.flags], FLAG_CONNECTED |
642 | test [ebp + http_msg.flags], FLAG_CONNECTED |
Line -... | Line 643... | ||
- | 643 | jz .connection_closed |
|
- | 644 | ||
- | 645 | ; If the buffer is full, allocate a new one |
|
- | 646 | cmp [ebp + http_msg.buffer_length], 0 |
|
- | 647 | jne .receive |
|
- | 648 | ||
- | 649 | test [ebp + http_msg.flags], FLAG_MULTIBUFF |
|
- | 650 | jz .err_header |
|
- | 651 | ||
- | 652 | invoke mem.alloc, BUFFERSIZE |
|
- | 653 | test eax, eax |
|
- | 654 | jz .err_no_ram |
|
- | 655 | mov [ebp + http_msg.content_ptr], eax |
|
- | 656 | mov [ebp + http_msg.write_ptr], eax |
|
556 | jz .connection_closed |
657 | mov [ebp + http_msg.buffer_length], BUFFERSIZE |
- | 658 | ||
557 | 659 | ; Receive some data |
|
558 | ; Receive some data |
660 | .receive: |
559 | mcall recv, [ebp + http_msg.socket], [ebp + http_msg.write_ptr], \ |
661 | mcall recv, [ebp + http_msg.socket], [ebp + http_msg.write_ptr], \ |
560 | [ebp + http_msg.buffer_length], MSG_DONTWAIT |
662 | [ebp + http_msg.buffer_length], MSG_DONTWAIT |
Line 839... | Line 941... | ||
839 | add [ebp + http_msg.content_received], ecx |
941 | add [ebp + http_msg.content_received], ecx |
840 | ; Calculate new write ptr |
942 | ; Calculate new write ptr |
841 | mov edx, esi |
943 | mov edx, esi |
842 | sub edx, [ebp + http_msg.chunk_ptr] ; edx is now length of chunkline |
944 | sub edx, [ebp + http_msg.chunk_ptr] ; edx is now length of chunkline |
843 | sub [ebp + http_msg.write_ptr], edx |
945 | sub [ebp + http_msg.write_ptr], edx |
- | 946 | test [ebp + http_msg.flags], FLAG_MULTIBUFF |
|
- | 947 | jnz .dont_resize |
|
844 | ; Realloc buffer, make it 'chunksize' bigger. |
948 | ; Realloc buffer, make it 'chunksize' bigger. |
845 | lea edx, [ebx + BUFFERSIZE] |
949 | lea edx, [ebx + BUFFERSIZE] |
846 | mov [ebp + http_msg.buffer_length], edx ; remaining space in new buffer |
950 | mov [ebp + http_msg.buffer_length], edx ; remaining space in new buffer |
847 | add edx, [ebp + http_msg.write_ptr] |
951 | add edx, [ebp + http_msg.write_ptr] |
848 | sub edx, [ebp + http_msg.content_ptr] |
952 | sub edx, [ebp + http_msg.content_ptr] |
Line 851... | Line 955... | ||
851 | DEBUGF 1, "New buffer = 0x%x\n", eax |
955 | DEBUGF 1, "New buffer = 0x%x\n", eax |
852 | or eax, eax |
956 | or eax, eax |
853 | jz .err_no_ram |
957 | jz .err_no_ram |
854 | call recalculate_pointers ; Because it's possible that buffer begins on another address now |
958 | call recalculate_pointers ; Because it's possible that buffer begins on another address now |
855 | add esi, eax ; recalculate esi too! |
959 | add esi, eax ; recalculate esi too! |
- | 960 | .dont_resize: |
|
856 | ; Remove chunk header (aka chunkline) from the buffer by shifting all received data after chunkt_ptr to the left |
961 | ; Remove chunk header (aka chunkline) from the buffer by shifting all received data after chunkt_ptr to the left |
857 | mov edi, [ebp + http_msg.chunk_ptr] |
962 | mov edi, [ebp + http_msg.chunk_ptr] |
858 | rep movsb |
963 | rep movsb |
859 | ; Update chunk ptr to point to next chunk |
964 | ; Update chunk ptr to point to next chunk |
860 | add [ebp + http_msg.chunk_ptr], ebx |
965 | add [ebp + http_msg.chunk_ptr], ebx |
Line 885... | Line 990... | ||
885 | xor eax, eax |
990 | xor eax, eax |
886 | dec eax |
991 | dec eax |
887 | ret |
992 | ret |
Line 888... | Line 993... | ||
888 | 993 | ||
- | 994 | .buffer_full: |
|
889 | .buffer_full: |
995 | test [ebp + http_msg.flags], FLAG_MULTIBUFF |
890 | ; Lets make it bigger.. |
996 | jnz .multibuff |
891 | mov eax, [ebp + http_msg.write_ptr] |
997 | mov eax, [ebp + http_msg.write_ptr] |
892 | add eax, BUFFERSIZE |
998 | add eax, BUFFERSIZE |
893 | sub eax, [ebp + http_msg.content_ptr] |
999 | sub eax, [ebp + http_msg.content_ptr] |
894 | invoke mem.realloc, [ebp + http_msg.content_ptr], eax |
1000 | invoke mem.realloc, [ebp + http_msg.content_ptr], eax |
Line 900... | Line 1006... | ||
900 | popa |
1006 | popa |
901 | xor eax, eax |
1007 | xor eax, eax |
902 | dec eax |
1008 | dec eax |
903 | ret |
1009 | ret |
Line -... | Line 1010... | ||
- | 1010 | ||
- | 1011 | .multibuff: |
|
- | 1012 | ; This buffer is full |
|
- | 1013 | popa |
|
- | 1014 | xor eax, eax |
|
- | 1015 | ret |
|
904 | 1016 | ||
905 | .need_more_data_for_header: |
1017 | .need_more_data_for_header: |
906 | cmp [ebp + http_msg.buffer_length], 0 |
1018 | cmp [ebp + http_msg.buffer_length], 0 |
907 | je .err_header ; It's just too damn long! |
1019 | je .err_header ; It's just too damn long! |
908 | ; Need more data |
1020 | ; Need more data |
Line 1149... | Line 1261... | ||
1149 | endp |
1261 | endp |
Line 1150... | Line 1262... | ||
1150 | 1262 | ||
1151 | 1263 | ||
1152 | 1264 | ||
1153 | ;;================================================================================================;; |
1265 | ;;================================================================================================;; |
1154 | proc HTTP_escape URI ;////////////////////////////////////////////////////////////////////////////;; |
1266 | proc HTTP_escape URI, length ;////////////////////////////////////////////////////////////////////;; |
1155 | ;;------------------------------------------------------------------------------------------------;; |
1267 | ;;------------------------------------------------------------------------------------------------;; |
- | 1268 | ;? ;; |
|
1156 | ;? ;; |
1269 | ;;------------------------------------------------------------------------------------------------;; |
1157 | ;;------------------------------------------------------------------------------------------------;; |
1270 | ;> URI = ptr to ASCIIZ URI/data ;; |
1158 | ;> URI = ptr to ASCIIZ URI ;; |
1271 | ;> length = length of URI/data ;; |
1159 | ;;------------------------------------------------------------------------------------------------;; |
1272 | ;;------------------------------------------------------------------------------------------------;; |
Line 1160... | Line -... | ||
1160 | ;< eax = 0 (error) / ptr to ASCIIZ URI/data ;; |
- | |
1161 | ;< ebx = length of escaped URI/data ;; |
- | |
1162 | ;;================================================================================================;; |
- | |
1163 | 1273 | ;< eax = 0 (error) / ptr to ASCIIZ URI/data ;; |
|
Line 1164... | Line 1274... | ||
1164 | 1274 | ;< ebx = length of escaped URI/data ;; |
|
Line 1165... | Line 1275... | ||
1165 | ; TODO: instead of static buffer allocation, make it 4096 bytes and larger only if needed |
1275 | ;;================================================================================================;; |
1166 | 1276 | ||
1167 | DEBUGF 1, "HTTP_escape: %s\n", [URI] |
1277 | DEBUGF 1, "HTTP_escape: %s\n", [URI] |
1168 | 1278 | ||
1169 | pusha |
1279 | pusha |
1170 | 1280 | ||
Line 1225... | Line 1335... | ||
1225 | endp |
1335 | endp |
Line 1226... | Line 1336... | ||
1226 | 1336 | ||
1227 | 1337 | ||
1228 | 1338 | ||
1229 | ;;================================================================================================;; |
1339 | ;;================================================================================================;; |
1230 | proc HTTP_unescape URI ;//////////////////////////////////////////////////////////////////////////;; |
1340 | proc HTTP_unescape URI, length ;//////////////////////////////////////////////////////////////////;; |
1231 | ;;------------------------------------------------------------------------------------------------;; |
1341 | ;;------------------------------------------------------------------------------------------------;; |
1232 | ;? ;; |
1342 | ;? ;; |
Line 1237... | Line 1347... | ||
1237 | ;;================================================================================================;; |
1347 | ;;================================================================================================;; |
Line 1238... | Line 1348... | ||
1238 | 1348 | ||
1239 | DEBUGF 1, "HTTP_unescape: %s\n", [URI] |
1349 | DEBUGF 1, "HTTP_unescape: %s\n", [URI] |
Line 1240... | Line 1350... | ||
1240 | pusha |
1350 | pusha |
1241 | 1351 | ||
1242 | invoke mem.alloc, URLMAXLEN |
1352 | invoke mem.alloc, URLMAXLEN ; FIXME: use length provided by caller |
1243 | test eax, eax |
1353 | test eax, eax |
1244 | jz .error |
1354 | jz .error |
1245 | mov [esp + 7 * 4], eax ; return ptr in eax |
1355 | mov [esp + 7 * 4], eax ; return ptr in eax |
Line 1766... | Line 1876... | ||
1766 | .length = $ - str_post_cl |
1876 | .length = $ - str_post_cl |
1767 | str_post_ct db 13, 10, 'Content-Type: ' |
1877 | str_post_ct db 13, 10, 'Content-Type: ' |
1768 | .length = $ - str_post_ct |
1878 | .length = $ - str_post_ct |
1769 | str_proxy_auth db 13, 10, 'Proxy-Authorization: Basic ' |
1879 | str_proxy_auth db 13, 10, 'Proxy-Authorization: Basic ' |
1770 | .length = $ - str_proxy_auth |
1880 | .length = $ - str_proxy_auth |
1771 | str_close db 'User-Agent: KolibriOS libHTTP/1.0', 13, 10, 'Connection: Close', 13, 10, 13, 10 |
1881 | str_close db 'User-Agent: KolibriOS libHTTP/1.1', 13, 10, 'Connection: Close', 13, 10, 13, 10 |
- | 1882 | .length = $ - str_close |
|
- | 1883 | str_keep db 'User-Agent: KolibriOS libHTTP/1.1', 13, 10, 'Connection: Keepalive', 13, 10, 13, 10 |
|
1772 | .length = $ - str_close |
1884 | .length = $ - str_close |
Line 1773... | Line 1885... | ||
1773 | 1885 | ||
Line 1774... | Line 1886... | ||
1774 | str_http db 'http://', 0 |
1886 | str_http db 'http://', 0 |