Subversion Repositories Kolibri OS

Rev

Rev 3561 | Rev 3566 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3561 Rev 3564
Line 17... Line 17...
17
 
17
 
18
URLMAXLEN               = 1024
18
URLMAXLEN               = 1024
Line 19... Line 19...
19
primary_buffer_size     = 4096
19
primary_buffer_size     = 4096
20
 
20
 
Line 21... Line 21...
21
__DEBUG__       = 1
21
__DEBUG__       = 1
Line 22... Line 22...
22
__DEBUG_LEVEL__ = 1
22
__DEBUG_LEVEL__ = 2
23
 
23
 
Line 188... Line 188...
188
mouse:
188
mouse:
189
        stdcall [edit_box_mouse], edit1
189
        stdcall [edit_box_mouse], edit1
190
        jmp     still
190
        jmp     still
Line 191... Line 191...
191
 
191
 
192
save:
192
save:
193
        DEBUGF  1, "file saved\n"
193
        DEBUGF  2, "File saved\n"
Line 194... Line 194...
194
        mcall   70, fileinfo
194
        mcall   70, fileinfo
195
 
195
 
196
        mov     ecx, [sc.work_text]
196
        mov     ecx, [sc.work_text]
Line 361... Line 361...
361
        ret
361
        ret
Line 362... Line 362...
362
 
362
 
363
  .rid:
363
  .rid:
364
        push    esi
364
        push    esi
365
        push    edi
365
        push    edi
Line 366... Line 366...
366
        DEBUGF  1, "rid\n"
366
        DEBUGF  1, "Reading incoming data\n"
-
 
367
 
367
 
368
  .read:
368
  .read:
369
        ; TODO: implement timeout !
369
        mcall   recv, [socketnum], primary_buf, primary_buffer_size, 0
370
        mcall   recv, [socketnum], primary_buf, primary_buffer_size, 0
370
        inc     eax             ; -1 = error (socket closed?)
371
        inc     eax             ; -1 = error (socket closed?)
371
        jz      .no_more_data
372
        jz      .no_more_data
Line -... Line 373...
-
 
373
        dec     eax             ; 0 bytes...
-
 
374
        jz      .read
372
        dec     eax             ; 0 bytes...
375
 
373
        jz      .read
376
        DEBUGF  1, "Got chunk of %u bytes\n", eax
374
        
377
        
375
        mov     edi, [pos]
378
        mov     edi, [pos]
376
        add     [pos], eax
379
        add     [pos], eax
Line 383... Line 386...
383
        lea     edx, [ecx - 3]
386
        lea     edx, [ecx - 3]
384
        rep     movsb
387
        rep     movsb
Line 385... Line 388...
385
        
388
        
Line -... Line 389...
-
 
389
  .no_more_data:
-
 
390
 
386
  .no_more_data:
391
        DEBUGF  1, "No more data\n"
Line 387... Line 392...
387
 
392
 
-
 
393
;        mov     [status], 4     ; connection closed by server
-
 
394
 
-
 
395
        call    parse_result
388
;        mov     [status], 4     ; connection closed by server
396
 
389
 
397
        DEBUGF  1, "Parsing complete\n"
390
        call    parse_result
398
 
391
        mov     ecx, [shared_name]
399
        mov     ecx, [shared_name]
392
        test    ecx, ecx
400
        test    ecx, ecx
393
        jz      @f
401
        jz      @f
Line 394... Line 402...
394
        cmp     [ecx], byte 0
402
        cmp     [ecx], byte 0
Line -... Line 403...
-
 
403
        jnz     save_in_shared
-
 
404
    @@:
395
        jnz     save_in_shared
405
 
396
    @@:
406
        mcall   70, fileinfo
397
 
407
 
398
        mcall   70, fileinfo
-
 
Line 399... Line 408...
399
        
408
        DEBUGF  2, "File saved\n"
400
        mov     ecx, [sc.work_text]
409
        
Line 401... Line 410...
401
        or      ecx, 0x80000000
410
        mov     ecx, [sc.work_text]
Line 447... Line 456...
447
        
456
        
448
parse_result:
457
parse_result:
449
; close socket
458
; close socket
Line 450... Line -...
450
        mcall   close, [socketnum]
-
 
451
        
459
        mcall   close, [socketnum]
452
        DEBUGF  1, "close socketnum: 0x%x\n", eax
460
        
453
        mov     edi, [buf_ptr]
461
        mov     edi, [buf_ptr]
454
        mov     edx, [pos]
462
        mov     edx, [pos]
455
        mov     [buf_size], edx
463
        mov     [buf_size], edx
Line 456... Line 464...
456
;       mcall   70, fileinfo_tmp
464
;       mcall   70, fileinfo_tmp
457
        DEBUGF  1, "pos = 0x%x\n", edx
465
        DEBUGF  1, "Parsing result (%u bytes)\n", edx
458
 
466
 
459
; first, find end of headers
467
; first, find end of headers
460
  .next_byte:
468
  .next_byte:
461
        cmp     dword[edi], 0x0d0a0d0a  ; ìíå ëåíü ÷èòàòü ñòàíäàðò, ïóñòü áóäóò îáà âàðèàíòà
469
        cmp     dword[edi], 0x0d0a0d0a  ; ìíå ëåíü ÷èòàòü ñòàíäàðò, ïóñòü áóäóò îáà âàðèàíòà
462
        je      .end_of_headers
470
        je      .end_of_headers
463
        cmp     dword[edi], 0x0a0d0a0d
471
        cmp     dword[edi], 0x0a0d0a0d
464
        je      .end_of_headers
472
        je      .end_of_headers
-
 
473
        inc     edi
465
        inc     edi
474
        dec     edx
466
        dec     edx
475
        jne     .next_byte
Line 467... Line 476...
467
        jne     .next_byte
476
        DEBUGF  1, "Uh-oh, there's no end of header!\n"
468
; no end of headers. it's an error. let client see all those headers.
477
; no end of headers. it's an error. let client see all those headers.
469
        ret
478
        ret
Line 470... Line 479...
470
 
479
 
471
  .end_of_headers:
480
  .end_of_headers:
472
; here we look at headers and search content-length or transfer-encoding headers
481
; here we look at headers and search content-length or transfer-encoding headers
473
;       DEBUGF  1, "eoh\n"
482
        DEBUGF  1, "Found end of header\n"
Line 496... Line 505...
496
        inc     esi
505
        inc     esi
497
        dec     ebx
506
        dec     ebx
498
        je      .cl_error
507
        je      .cl_error
499
        jmp     .cl_next
508
        jmp     .cl_next
500
  .cl_error:
509
  .cl_error:
501
;       DEBUGF  1, "content-length not found\n"
510
        DEBUGF  1, "content-length not found\n"
Line 502... Line 511...
502
 
511
 
503
; find 'chunked'
512
; find 'chunked'
504
; äà, ÿ êîïèðóþ êîä, ýòî óæàñíî, íî ìíå õî÷åòñÿ, ÷òîáû ïîñêîðåå çàðàáîòàëî
513
; äà, ÿ êîïèðóþ êîä, ýòî óæàñíî, íî ìíå õî÷åòñÿ, ÷òîáû ïîñêîðåå çàðàáîòàëî
505
; à òàì óæ îòðåôàêòîðþ
514
; à òàì óæ îòðåôàêòîðþ
Line 541... Line 550...
541
        mov     [prev_chunk_end], eax
550
        mov     [prev_chunk_end], eax
542
        jmp     parse_chunks
551
        jmp     parse_chunks
Line 543... Line 552...
543
        
552
        
544
  .cl_found:
553
  .cl_found:
-
 
554
        call    read_number     ; eax = number from *esi
Line 545... Line 555...
545
        call    read_number     ; eax = number from *esi
555
        DEBUGF  1, "Content length: %u\n", eax
546
 
-
 
Line 547... Line 556...
547
  .write_final_size:
556
 
548
        mov     [final_size], eax        ; if this works, i will b very happy...
557
  .write_final_size:
-
 
558
        
-
 
559
        mov     ebx, [buf_size]
-
 
560
        sub     ebx, [body_pos]
-
 
561
        cmp     eax, ebx
-
 
562
        jbe     .size_ok
-
 
563
        DEBUGF  2, "Not all data was received!\n"
Line 549... Line -...
549
        
-
 
550
        mov     ebx, [pos]       ; we well check if it is right
564
        mov     eax, ebx
551
        sub     ebx, [body_pos]
565
  .size_ok:
552
 
-
 
553
; everything is ok, so we return
566
        mov     [final_size], eax
554
        mov     eax, [body_pos]
-
 
555
        mov     ebx, [buf_ptr]
-
 
556
        add     ebx, eax
-
 
-
 
567
 
557
        mov     [final_buffer], ebx
568
        mov     ebx, [body_pos]
Line 558... Line 569...
558
;       mov     ebx, [pos]
569
        add     ebx, [buf_ptr]
559
;       sub     ebx, eax
570
        mov     [final_buffer], ebx
560
;       mov     [final_size], ebx
571
 
561
        ret
572
        ret
562
        
573
        
563
parse_chunks:
574
parse_chunks:
564
;       DEBUGF  1, "parse chunks\n"
575
        DEBUGF  1, "parse chunks\n"
Line 573... Line 584...
573
.read_size:
584
.read_size:
574
        mov     eax, [prev_chunk_end]
585
        mov     eax, [prev_chunk_end]
575
        mov     ebx, eax
586
        mov     ebx, eax
576
        sub     ebx, [buf_ptr]
587
        sub     ebx, [buf_ptr]
577
        mov     edx, eax
588
        mov     edx, eax
578
;       DEBUGF  1, "rs "
589
        DEBUGF  1, "rs "
579
        cmp     ebx, [pos]
590
        cmp     ebx, [pos]
580
        jae     chunks_end      ; not good
591
        jae     chunks_end      ; not good
Line 581... Line 592...
581
        
592
        
582
        call    read_hex        ; in: eax=pointer to text. out:eax=hex number, ebx=end of text.
593
        call    read_hex        ; in: eax=pointer to text. out:eax=hex number, ebx=end of text.
Line 587... Line 598...
587
        mov     edx, ebx ; edx = size of size of chunk
598
        mov     edx, ebx ; edx = size of size of chunk
Line 588... Line 599...
588
        
599
        
589
        add     ebx, eax
600
        add     ebx, eax
Line 590... Line 601...
590
        mov     [prev_chunk_end], ebx
601
        mov     [prev_chunk_end], ebx
Line 591... Line 602...
591
        
602
        
592
;       DEBUGF  1, "sz "
603
        DEBUGF  1, "sz "
593
 
604
 
594
; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
605
; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
595
; realloc final buffer
606
; realloc final buffer
596
        push    eax
607
        push    eax
597
        push    edx
608
        push    edx
598
        push    dword [final_size]
609
        push    dword [final_size]
599
        add     [final_size], eax
610
        add     [final_size], eax
600
        mcall   68, 20, [final_size], [final_buffer]
611
        mcall   68, 20, [final_size], [final_buffer]
601
        mov     [final_buffer], eax
612
        mov     [final_buffer], eax
602
;       DEBUGF  1, "re "
613
        DEBUGF  1, "re "
603
        pop     edi
614
        pop     edi
604
        pop     esi
615
        pop     esi
605
        pop     ecx
616
        pop     ecx
Line 606... Line 617...
606
;       add     [pos], ecx
617
;       add     [pos], ecx
607
        add     edi, [final_buffer]
618
        add     edi, [final_buffer]
Line 608... Line 619...
608
;       DEBUGF  1, "cp "
619
        DEBUGF  1, "cp "
Line 843... Line 854...
843
        jne     @r
854
        jne     @r
844
        mov     byte [edi], 0
855
        mov     byte [edi], 0
Line 845... Line 856...
845
 
856
 
846
pu_009:
857
pu_009:
847
; For debugging, display resulting strings
858
; For debugging, display resulting strings
848
        DEBUGF  1, "document_user: %s\n", document_user
-
 
849
        DEBUGF  1, "webAddr: %s\n", webAddr
-
 
Line 850... Line 859...
850
        DEBUGF  1, "document: %s\n", document
859
        DEBUGF  2, "Downloadng %s\n", document_user
851
 
860
 
852
; Look up the ip address, or was it specified?
861
; Look up the ip address, or was it specified?
853
        mov     al, [proxyAddr]
862
        mov     al, [proxyAddr]
Line 902... Line 911...
902
        push    0       ; third parameter
911
        push    0       ; third parameter
903
        push    0       ; second parameter
912
        push    0       ; second parameter
904
        push    webAddr
913
        push    webAddr
905
        call    [getaddrinfo]
914
        call    [getaddrinfo]
906
        pop     esi
915
        pop     esi
907
; test for error
916
; TODO: handle error
908
        DEBUGF  1, "eax=0x%x\n", eax
-
 
909
;        test    eax, eax
917
;        test    eax, eax
910
;        jnz     .fail_dns
918
;        jnz     .fail_dns
Line 911... Line 919...
911
 
919
 
912
; fill in ip in sockstruct
920
; fill in ip
913
        mov     eax, [esi + addrinfo.ai_addr]
921
        mov     eax, [esi + addrinfo.ai_addr]
914
        mov     eax, [eax + sockaddr_in.sin_addr]
922
        mov     eax, [eax + sockaddr_in.sin_addr]
Line 915... Line 923...
915
        mov     [server_ip], eax
923
        mov     [server_ip], eax