Subversion Repositories Kolibri OS

Rev

Rev 2579 | Blame | Last modification | View Log | Download | RSS feed

  1. ; version: 0.5
  2. ; last update:  07/10/2010
  3. ; written by:   Marat Zakiyanov aka Mario79, aka Mario
  4. ; changes:      reducing the size of the binary code,
  5. ;               program uses far less memory while running
  6. ;               (>0x7000, the old version used >0x100000),
  7. ;               process only net event at start with parameter
  8. ;-----------------------------------------------------------
  9. ; version 0.3 -0.4
  10. ; written by:   CleverMouse
  11. ;
  12. ;-----------------------------------------------------------
  13. ; wget 0.2 by barsuk
  14. ; based on Menuet Httpc
  15.  
  16.  
  17. ; Enabling debugging puts stuff to the debug board
  18. DEBUGGING_ENABLED       equ 1
  19. DEBUGGING_DISABLED      equ 0
  20. DEBUGGING_STATE         equ DEBUGGING_ENABLED
  21.  
  22. use32
  23.         org     0x0
  24.         db 'MENUET01'   ; header
  25.         dd 0x01         ; header version
  26.         dd START        ; entry point
  27.         dd IM_END       ; image size
  28.         dd I_END        ;0x100000 ; required memory
  29.         dd stacktop     ; esp
  30.         dd params       ; I_PARAM
  31.         dd 0x0          ; I_Path
  32.  
  33. include 'lang.inc'
  34. include '../../../macros.inc'
  35. include "../../../proc32.inc"
  36. include "dll.inc"
  37. include "debug.inc"
  38.  
  39. URLMAXLEN       equ 256 ; maximum length of url string
  40.  
  41. primary_buffer_size     equ 4096
  42.  
  43. ; Memory usage
  44. ; webpage headers at buf_headers
  45.  
  46. START:  ; start of execution
  47. ;dps    <"Program started",13,10>
  48. ; prepare webAddr area 
  49.         mov     al,' '
  50.         mov     edi,webAddr
  51.         mov     ecx,URLMAXLEN
  52.         cld
  53.         rep     stosb
  54.         xor     eax,eax
  55.         stosb
  56. ; prepare document area
  57.         mov     al,'/'
  58.         mov     edi,document
  59.         cld
  60.         stosb
  61.         mov     al,' '
  62.         mov     ecx,URLMAXLEN-1
  63.         rep     stosb
  64.  
  65. ; create local heap
  66.         mcall   68,11
  67.  
  68.         call    load_settings
  69.         cmp     [params],byte 0
  70.         jz      prepare_event   ;red
  71.  
  72.         mcall   40,10000000b ; only net event!!!
  73.  
  74. ; we have an url
  75.         mov     edi,document_user
  76.         mov     al,' '
  77.         mov     ecx,URLMAXLEN
  78.         rep     stosb
  79.        
  80.         mov     esi,params
  81.         mov     edi,document_user
  82.  
  83. .copy_param:
  84.         mov     al,[esi]
  85.         cmp     al,0
  86.         jz      .done
  87.  
  88.         cmp     al,' '
  89.         jz      .done_inc
  90.  
  91.         mov     [edi],al
  92.         inc     esi
  93.         inc     edi
  94.         jmp     .copy_param
  95.  
  96. .done_inc:
  97. ; url is followed by shared memory name.
  98.         inc     esi
  99. .done:
  100.         mov     [shared_name],esi
  101.  
  102.         mov     ah,22   ; strange way to tell that socket should be opened...
  103.         call    socket_commands
  104.  
  105.         jmp     still
  106.  
  107. prepare_event:
  108. ; Report events
  109. ; Stack 8 + defaults
  110.         mcall   40,10000111b
  111.  
  112. red:    ; redraw
  113.         call    draw_window
  114.  
  115. still:
  116.         mcall   23,1    ; wait here for event
  117.         cmp     eax,1   ; redraw request ?
  118.         je      red
  119.  
  120.         cmp     eax,2   ; key in buffer ?
  121.         je      key
  122.  
  123.         cmp     eax,3   ; button in buffer ?
  124.         je      button
  125.  
  126. ; Get the web page data from the remote server
  127.         call    read_incoming_data
  128.         mov     eax,[status]
  129.         mov     [prev_status],eax
  130.         mcall   53,6,[socket]
  131.         mov     [status],eax
  132.  
  133.         cmp     [prev_status],4
  134.         jge     no_send
  135.  
  136.         cmp     [status],4
  137.         jne     no_send
  138.  
  139.         mov     [onoff],1
  140.         call    send_request
  141.  
  142. no_send:
  143.         call    print_status
  144.  
  145.         cmp     [prev_status],4
  146.         jne     no_close
  147.         cmp     [status],4      ; connection closed by server
  148.         jbe     no_close        ; respond to connection close command
  149. ; draw page
  150.         call    read_incoming_data
  151.         mcall   53,8,[socket]
  152.         call    draw_page
  153.         mov     [onoff],0
  154.  
  155. no_close:
  156.         jmp     still
  157.  
  158. key:    ; key
  159.         mcall   2       ; just read it and ignore
  160.         shr     eax,8
  161.         cmp     eax,184
  162.         jne     no_down
  163.         cmp     [display_from],25
  164.         jb      no_down
  165.         sub     [display_from],25
  166.         call    display_page
  167.  
  168. no_down:
  169.         cmp     eax,183
  170.         jne     no_up
  171.         add     [display_from],25
  172.         call    display_page
  173.  
  174. no_up:
  175.         jmp     still
  176.  
  177. button: ; button
  178. ;dps    <"Button pressed",13,10>
  179.         mcall   17      ; get id
  180.         cmp     ah,26
  181.         je      save
  182.         cmp     ah,1    ; button id=1 ?
  183.         jne     noclose
  184. ;       dps     "Closing socket before exit... "
  185.  
  186. close_end_exit:
  187.  
  188. ;dpd    eax
  189. ;dps    <13,10>
  190.  
  191. exit:
  192.         or      eax,-1  ; close this program
  193.         mcall
  194.  
  195. save:
  196. dps     "saving"
  197. newline
  198.         mcall   70,fileinfo
  199. ;pregs
  200.         jmp     still
  201.  
  202. noclose:
  203.         cmp     ah,31
  204.         jne     noup
  205.         sub     [display_from],20
  206.         call    display_page
  207.         jmp     still
  208.  
  209. noup:
  210.         cmp     ah,32
  211.         jne     nodown
  212.         add     [display_from],20
  213.         call    display_page
  214.         jmp     still
  215.  
  216. nodown:
  217.         cmp     ah,10   ; Enter url
  218.         jne     nourl
  219.  
  220.         mov     [addr],dword document_user
  221.         mov     [ya],dword 38
  222.         mov     [len],dword URLMAXLEN
  223.  
  224.         mov     ecx,URLMAXLEN
  225.         mov     edi,[addr]
  226.         mov     al,' '
  227.         rep     stosb
  228.  
  229.         call    print_text
  230.  
  231.         mov     edi,[addr]
  232.  
  233. f11:
  234.         mcall   10
  235.         cmp     eax,2   ; key?
  236.         jz      fbu
  237.         jmp     still
  238.  
  239. fbu:
  240.         mcall   2       ; get key
  241.         shr     eax,8
  242.         cmp     eax,8
  243.         jnz     nobs
  244.         cmp     edi,[addr]
  245.         jz      f11
  246.         sub     edi,1
  247.         mov     [edi],byte ' '
  248.         call    print_text
  249.         jmp     f11
  250.  
  251. nobs:
  252.         cmp     eax,10
  253.         je      retkey
  254.         cmp     eax,13
  255.         je      retkey
  256.  
  257.         cmp     eax,31
  258.         jbe     f11
  259.  
  260. ; Removed in v0.4
  261. ;       cmp     eax,95
  262. ;       jb      keyok
  263. ;       sub     eax,32
  264.  
  265. keyok:
  266.         mov     [edi],al
  267.         call    print_text
  268.         add     edi,1
  269.         mov     esi,[addr]
  270.         add     esi,URLMAXLEN
  271.         cmp     esi,edi
  272.         jnz     f11
  273.         jmp     still
  274.  
  275. retkey:
  276.         mov     ah,22   ; start load
  277.  
  278. nourl:
  279.         call    socket_commands ; opens or closes the connection
  280.         jmp     still
  281.  
  282. ;****************************************************************************
  283. ;    Function
  284. ;       send_request
  285. ;
  286. ;   Description
  287. ;       Transmits the GET request to the server.
  288. ;       This is done as GET then URL then HTTP/1.1',13,10,13,10 in 3 packets
  289. ;
  290. ;****************************************************************************
  291. send_request:
  292.         pusha
  293.         mov     esi,string0
  294.         mov     edi,request
  295.         movsd
  296. ; If proxy is used, make absolute URI - prepend http://<host>
  297.         cmp     [proxyAddr],byte 0
  298.         jz      .noproxy
  299.         mov     dword [edi],'http'
  300.         mov     [edi+4],byte ':'
  301.         mov     [edi+5],word '//'
  302.         add     edi,7
  303.         mov     esi,webAddr
  304.  
  305. .copy_host_loop:
  306.         lodsb
  307.         cmp     al,' '
  308.         jz      .noproxy
  309.         stosb
  310.         jmp     .copy_host_loop
  311.  
  312. .noproxy:
  313.         xor     edx,edx ; 0
  314.  
  315. .next_edx:
  316. ; Determine the length of the url to send in the GET request
  317.         mov     al,[edx+document]
  318.         cmp     al,' '
  319.         je      .document_done
  320.         mov     [edi],al
  321.         inc     edi
  322.         inc     edx
  323.         jmp     .next_edx
  324.  
  325. .document_done:
  326.         mov     esi,stringh
  327.         mov     ecx,stringh_end-stringh
  328.         rep     movsb
  329.         xor     edx,edx ; 0
  330.  
  331. .webaddr_next:
  332.         mov     al,[webAddr + edx]
  333.         cmp     al,' '
  334.         je      .webaddr_done
  335.         mov     [edi],al
  336.         inc     edi
  337.         inc     edx
  338.         jmp     .webaddr_next
  339.  
  340. .webaddr_done:
  341.         cmp     [proxyUser],byte 0
  342.         jz      @f
  343.         call    append_proxy_auth_header
  344. @@:
  345.         mov     esi,connclose
  346.         mov     ecx,connclose_end-connclose
  347.         rep     movsb
  348.  
  349.         pusha  
  350.         mov     eax,63
  351.         mov     ebx,1
  352.         mov     edx,request
  353. @@:
  354.         mov     cl,[edx]
  355.         cmp     edx,edi
  356.         jz      @f
  357.         mcall
  358.         inc     edx
  359.         jmp     @b
  360. @@:
  361.         popa
  362.  
  363.         mov     edx,edi
  364.         sub     edx,request
  365. ;;;;now write \r\nConnection: Close \r\n\r\n
  366.         mcall   53,7,[socket],,request  ;' HTTP/1.1 .. '
  367.         popa
  368.         ret
  369.  
  370. ;****************************************************************************
  371. ;    Function
  372. ;       print_status
  373. ;
  374. ;   Description
  375. ;       displays the socket/data received status information
  376. ;
  377. ;****************************************************************************
  378. print_status:
  379.         pusha
  380.         mcall   26,9
  381.         cmp     eax,[nextupdate]
  382.         jb      status_return
  383.  
  384.         add     eax,25
  385.         mov     [nextupdate],eax
  386.  
  387.         mov     ecx,[winys]
  388.         shl     ecx,16
  389.         add     ecx,-18*65536+10
  390.         mcall   13,<5,100>,,0xffffff
  391.  
  392.         mov     edx,12*65536-18
  393.         add     edx,[winys]
  394.         xor     esi,esi
  395.         mcall   47,<3,0>,[status],,
  396.  
  397.         mov     edx,40*65536-18
  398.         add     edx,[winys]
  399.         mcall   ,<6,0>,[pos]
  400.  
  401. status_return:
  402.         popa
  403.         ret
  404.  
  405. ;****************************************************************************
  406. ;    Function
  407. ;       read_incoming_data
  408. ;
  409. ;   Description
  410. ;       receive the web page from the server, storing it without processing
  411. ;
  412. ;****************************************************************************
  413. read_incoming_data:
  414.         cmp     [onoff],1
  415.         je      rid
  416.         ret
  417.  
  418. rid:
  419.         push    esi
  420.         push    edi
  421. dps     "rid"
  422. newline
  423.  
  424. newbyteread:
  425.         ;call   print_status
  426.         mcall   53,2,[socket]
  427.         cmp     eax,0
  428.         je      no_more_data
  429.  
  430.         mcall   53,11,[socket],primary_buf,primary_buffer_size
  431.        
  432. ;dps    "part "
  433. ;dph    eax
  434. ;newline
  435.         mov     edi,[pos]
  436.         add     [pos],eax
  437.         push    eax
  438.         mcall   68,20,[pos],[buf_ptr]
  439.         mov     [buf_ptr],eax
  440.         add     edi,eax
  441.         mov     esi,primary_buf
  442.         pop     ecx     ; number of recently read bytes
  443.         lea     edx,[ecx - 3]
  444.         rep     movsb
  445.        
  446. no_more_data:
  447.         mcall   53,6,[socket]
  448.         cmp     eax,4
  449.         jne     no_more_data.finish
  450.         jmp     newbyteread
  451.  
  452. .finish:
  453. ;dps    "finish "
  454. ;pregs
  455.         call    parse_result
  456.         mov     ecx,[shared_name]
  457.         test    ecx, ecx
  458.         jz      @f
  459.         cmp     [ecx],byte 0
  460.         jnz     save_in_shared
  461. @@:
  462.  
  463.         mcall   70,fileinfo
  464. ;dps    "saving "
  465. ;pregs
  466. ;       jmp     close_end_exit
  467.         pop     edi
  468.         pop     esi
  469. ; if called from command line, then exit
  470.         cmp     [params],byte 0
  471.         jnz     exit
  472.         ret
  473.        
  474. save_in_shared:
  475.         mov     esi,1   ; SHM_OPEN+SHM_WRITE
  476.         mcall   68,22
  477.         test    eax,eax
  478.         jz      save_in_shared_done
  479.  
  480.         sub     edx,4
  481.         jbe     save_in_shared_done
  482.  
  483.         mov     ecx,[final_size]
  484.         cmp     ecx,edx
  485.         jb      @f
  486.  
  487.         mov     ecx,edx
  488. @@:
  489.         mov     [eax],ecx
  490.         lea     edi,[eax+4]
  491.         mov     esi,[final_buffer]
  492.         mov     edx,ecx
  493.         shr     ecx,2
  494.         rep     movsd
  495.         mov     ecx,edx
  496.         and     ecx,3
  497.         rep     movsb
  498.  
  499. save_in_shared_done:
  500.         pop     edi
  501.         pop     esi
  502.         jmp     exit
  503.        
  504. ; this function cuts header, and removes chunk sizes if doc is chunked
  505. ; in: buf_ptr, pos; out: buf_ptr, pos.
  506.        
  507. parse_result:
  508. ; close socket
  509.         mcall   53,8,[socket]
  510.        
  511. dps     "close  socket: "
  512. dph     eax
  513. newline
  514.         mov     edi,[buf_ptr]
  515.         mov     edx,[pos]
  516.         mov     [buf_size],edx
  517. ;       mcall   70,fileinfo_tmp
  518. dps     "pos = "
  519. dph     edx
  520. newline
  521.  
  522. ; first, find end of headers
  523. .next_byte:
  524.         cmp     [edi],dword 0x0d0a0d0a  ; ìíå ëåíü ÷èòàòü ñòàíäàðò, ïóñòü áóäóò îáà âàðèàíòà
  525.         je      .end_of_headers
  526.         cmp     [edi],dword 0x0a0d0a0d
  527.         je      .end_of_headers
  528.         inc     edi
  529.         dec     edx
  530.         jne     .next_byte
  531. ; no end of headers. it's an error. let client see all those headers.
  532.         ret
  533.  
  534. .end_of_headers:
  535. ; here we look at headers and search content-length or transfer-encoding headers
  536. ;dps    "eoh "
  537. ;newline
  538.         sub     edi,[buf_ptr]
  539.         add     edi,4
  540.         mov     [body_pos],edi  ; store position where document body starts
  541.         mov     [is_chunked],0
  542. ; find content-length in headers
  543. ; not good method, but should work for 'Content-Length:'
  544.         mov     esi,[buf_ptr]
  545.         mov     edi,s_contentlength
  546.         mov     ebx,[body_pos]
  547.         xor     edx,edx ; 0
  548. .cl_next:
  549.         mov     al,[esi]
  550.         cmp     al,[edi + edx]
  551.         jne     .cl_fail
  552.         inc     edx
  553.         cmp     edx,len_contentlength
  554.         je      .cl_found
  555.         jmp     .cl_incr
  556. .cl_fail:
  557.         xor     edx,edx ; 0
  558. .cl_incr:
  559.         inc     esi
  560.         dec     ebx
  561.         je      .cl_error
  562.         jmp     .cl_next
  563. .cl_error:
  564. ;pregs
  565. ;newline
  566. ;dph    esi
  567. ;dps    " content-length not found "
  568. ; find 'chunked'
  569. ; äà, ÿ êîïèðóþ êîä, ýòî óæàñíî, íî ìíå õî÷åòñÿ, ÷òîáû ïîñêîðåå çàðàáîòàëî
  570. ; à òàì óæ îòðåôàêòîðþ
  571.         mov     esi,[buf_ptr]
  572.         mov     edi,s_chunked
  573.         mov     ebx,[body_pos]
  574.         xor     edx,edx ; 0
  575.  
  576. .ch_next:
  577.         mov     al,[esi]
  578.         cmp     al,[edi + edx]
  579.         jne     .ch_fail
  580.         inc     edx
  581.         cmp     edx,len_chunked
  582.         je      .ch_found
  583.         jmp     .ch_incr
  584.  
  585. .ch_fail:
  586.         xor     edx,edx ; 0
  587.  
  588. .ch_incr:
  589.         inc     esi
  590.         dec     ebx
  591.         je      .ch_error
  592.         jmp     .ch_next
  593.  
  594. .ch_error:
  595. ; if neither of the 2 headers is found, it's an error
  596. ;dps    "transfer-encoding: chunked not found "
  597.         mov     eax,[pos]
  598.         sub     eax,[body_pos]
  599.         jmp     .write_final_size
  600.  
  601. .ch_found:
  602.         mov     [is_chunked],1
  603.         mov     eax,[body_pos]
  604.         add     eax,[buf_ptr]
  605.         sub     eax,2
  606.         mov     [prev_chunk_end],eax
  607.         jmp     parse_chunks
  608.        
  609. .cl_found:     
  610.         call    read_number     ; eax = number from *esi
  611.  
  612. .write_final_size:
  613.         mov     [final_size],eax        ; if this works, i will b very happy...
  614.        
  615.         mov     ebx,[pos]       ; we well check if it is right
  616.         sub     ebx,[body_pos]
  617.  
  618. ;dps    "check cl eax==ebx "
  619. ;pregs
  620.  
  621. ; everything is ok, so we return
  622.         mov     eax,[body_pos]
  623.         mov     ebx,[buf_ptr]
  624.         add     ebx,eax
  625.         mov     [final_buffer],ebx
  626. ;       mov     ebx,[pos]
  627. ;       sub     ebx,eax
  628. ;       mov     [final_size],ebx
  629.         ret
  630.        
  631. parse_chunks:
  632. ;dps    "parse chunks"
  633. ;newline
  634.         ; we have to look through the data and remove sizes of chunks we see
  635.         ; 1. read size of next chunk
  636.         ; 2. if 0, it's end. if not, continue.
  637.         ; 3. make a good buffer and copy a chunk there
  638.         xor     eax,eax
  639.         mov     [final_buffer],eax      ; 0
  640.         mov     [final_size],eax        ; 0
  641.        
  642. .read_size:
  643.         mov     eax,[prev_chunk_end]
  644.         mov     ebx,eax
  645.         sub     ebx,[buf_ptr]
  646.         mov     edx,eax
  647. ;dps    "rs "
  648. ;pregs
  649.         cmp     ebx,[pos]
  650.         jae     chunks_end      ; not good
  651.        
  652.         call    read_hex        ; in: eax=pointer to text. out:eax=hex number,ebx=end of text.
  653.         cmp     eax,0
  654.         jz      chunks_end
  655.  
  656.         add     ebx,1
  657.         mov     edx,ebx ; edx = size of size of chunk
  658.        
  659.         add     ebx,eax
  660.         mov     [prev_chunk_end],ebx
  661.        
  662. ;dps    "sz "
  663. ;pregs
  664. ; do copying: from buf_ptr+edx to final_buffer+prev_final_size count eax
  665. ; realloc final buffer
  666.         push    eax
  667.         push    edx
  668.         push    dword [final_size]
  669.         add     [final_size],eax
  670.         mcall   68,20,[final_size],[final_buffer]
  671.         mov     [final_buffer],eax
  672. ;dps    "re "
  673. ;pregs
  674.         pop     edi
  675.         pop     esi
  676.         pop     ecx
  677. ;       add     [pos],ecx
  678.         add     edi,[final_buffer]
  679. ;dps    "cp "
  680. ;pregs
  681.         rep     movsb
  682.         jmp     .read_size
  683.        
  684. chunks_end:
  685. ; free old buffer
  686. dps     "chunks end"
  687. newline
  688.         mcall   68,13,[buf_ptr]
  689. ; done!
  690.         ret
  691.  
  692. ; reads content-length from [edi+ecx], result in eax
  693. read_number:
  694.         push    ebx
  695.         xor     eax,eax
  696.         xor     ebx,ebx
  697.  
  698. .next:
  699.         mov     bl,[esi]
  700. ;dph    ebx
  701.         cmp     bl,'0'
  702.         jb      .not_number
  703.         cmp     bl,'9'
  704.         ja      .not_number
  705.         sub     bl,'0'
  706.         shl     eax,1
  707.         lea     eax,[eax + eax * 4]     ; eax *= 10
  708.         add     eax,ebx
  709.  
  710. .not_number:
  711.         cmp     bl,13
  712.         jz      .done
  713.         inc     esi
  714.         jmp     .next
  715.  
  716. .done:
  717.         pop     ebx
  718. ;newline
  719. ;dps    "strtoint eax "
  720. ;pregs
  721.         ret
  722.        
  723. ; reads hex from eax,result in eax,end of text in ebx
  724. read_hex:
  725.         add     eax,2
  726.         mov     ebx,eax
  727.         mov     eax,[ebx]
  728.         mov     [deba],eax
  729. ;       pushf
  730. ;       pushad
  731. ;       mov     edx,deba
  732. ;       call    debug_outstr
  733. ;       popad
  734. ;       popf
  735.         xor     eax,eax
  736.         xor     ecx,ecx
  737. .next:
  738.         mov     cl,[ebx]
  739.         inc     ebx
  740.        
  741.         cmp     cl,0x0d
  742.         jz      .done
  743. ;dph    ebx
  744.         or      cl,0x20
  745.         sub     cl,'0'
  746.         jb      .bad
  747.  
  748.         cmp     cl,0x9
  749.         jbe     .adding
  750.  
  751.         sub     cl,'a'-'0'-10
  752.         cmp     cl,0x0a
  753.         jb      .bad
  754.  
  755.         cmp     cl,0x0f
  756.         ja      .bad
  757.  
  758. .adding:
  759.         shl     eax,4
  760.         or      eax,ecx
  761. ;       jmp     .not_number
  762. ;.bad:
  763. .bad:
  764.         jmp     .next
  765. .done:
  766. ;newline
  767. ;dps    "hextoint eax "
  768. ;pregs
  769.         ret
  770.  
  771. ;****************************************************************************
  772. ;    Function
  773. ;       draw_page
  774. ;
  775. ;   Description
  776. ;       parses the web page data, storing displayable data at 0x20000
  777. ;       and attributes at 0x30000. It then calls display_page to render
  778. ;       the data
  779. ;
  780. ;****************************************************************************
  781. draw_page:
  782.         ret
  783.  
  784. ;****************************************************************************
  785. ;    Function
  786. ;       linefeed
  787. ;
  788. ;   Description
  789. ;
  790. ;
  791. ;****************************************************************************
  792. linefeed:
  793.         ret
  794.  
  795. ;****************************************************************************
  796. ;    Function
  797. ;       display_page
  798. ;
  799. ;   Description
  800. ;       Renders the text decoded by draw_page
  801. ;
  802. ;****************************************************************************
  803. display_page:
  804.         ret
  805.  
  806. ;****************************************************************************
  807. ;    Function
  808. ;       socket_commands
  809. ;
  810. ;   Description
  811. ;       opens or closes the socket
  812. ;
  813. ;****************************************************************************
  814. socket_commands:
  815.         cmp     ah,22   ; open socket
  816.         jnz     tst3
  817.  
  818. dps     "opening socket"
  819. newline
  820. ; Clear all page memory
  821.         xor     eax,eax
  822.         mov     [prev_chunk_end],eax    ; 0
  823.         cmp     [buf_ptr],eax   ; 0
  824.         jz      no_free
  825.  
  826.         mcall   68,13,[buf_ptr] ; free  buffer
  827.  
  828. no_free:
  829.         xor     eax,eax
  830.         mov     [buf_size],eax  ; 0
  831. ; Parse the entered url
  832.         call    parse_url
  833. ; Get a free port number
  834.         mov     ecx,1000        ; local port starting at 1000
  835.  
  836. getlp1:
  837.         inc     ecx
  838.         push    ecx
  839.         mcall   53,9
  840.         pop     ecx
  841.         cmp     eax,0   ; is this local port in use?
  842.         jz      getlp1  ; yes - so try next
  843.  
  844.         mov     edx,80
  845.         cmp     [proxyAddr],byte 0
  846.         jz      sc000
  847.         mov     edx,[proxyPort]
  848. sc000:
  849.         mcall   53,5,,,[server_ip],1
  850.         mov     [socket],eax
  851.         mov     [pagexs],80
  852.        
  853.         push    eax
  854.         xor     eax,eax ; 0
  855.         mov     [pos],eax
  856.         mov     [pagex],eax
  857.         mov     [pagey],eax
  858.         mov     [command_on_off],eax
  859.         mov     [is_body],eax
  860.         pop     eax
  861.         ret
  862.  
  863. tst3:
  864.         cmp     ah,24   ; close socket
  865.         jnz     no_24
  866.  
  867.         mcall   53,8,[socket]
  868.         call    draw_page
  869. no_24:
  870.         ret
  871.  
  872. ;****************************************************************************
  873. ;    Function
  874. ;       parse_url
  875. ;
  876. ;   Description
  877. ;       parses the full url typed in by the user into a web address ( that
  878. ;       can be turned into an IP address by DNS ) and the page to display
  879. ;       DNS will be used to translate the web address into an IP address, if
  880. ;       needed.
  881. ;       url is at document_user and will be space terminated.
  882. ;       web address goes to webAddr and is space terminated.
  883. ;       ip address goes to server_ip
  884. ;       page goes to document and is space terminated.
  885. ;
  886. ;       Supported formats:
  887. ;       <protocol://>address<page>
  888. ;       <protocol> is optional, removed and ignored - only http supported
  889. ;       <address> is required. It can be an ip address or web address
  890. ;       <page> is optional and must start with a leading / character
  891. ;
  892. ;****************************************************************************
  893. parse_url:
  894. ; First, reset destination variables
  895.         cld
  896.         mov     al,' '
  897.         mov     edi,document
  898.         mov     ecx,URLMAXLEN
  899.         rep     stosb
  900.         mov     edi,webAddr
  901.         mov     ecx,URLMAXLEN
  902.         rep     stosb
  903.  
  904.         mov     al,'/'
  905.         mov     [document],al
  906.  
  907.         mov     esi,document_user
  908. ; remove any leading protocol text
  909.         mov     ecx,URLMAXLEN
  910.         mov     ax,'//'
  911.  
  912. pu_000:
  913.         cmp     [esi],byte ' '  ; end of text?
  914.         je      pu_002          ; yep, so not found
  915.         cmp     [esi],ax
  916.         je      pu_001  ; Found it, so esi+2 is start
  917.         inc     esi
  918.         loop    pu_000
  919.  
  920. pu_002:
  921. ; not found, so reset esi to start
  922.         mov     esi,document_user-2
  923.  
  924. pu_001:
  925.         add     esi,2
  926.         mov     ebx,esi ; save address of start of web address
  927.         mov     edi,document_user + URLMAXLEN   ; end of string
  928. ; look for page delimiter - it's a '/' character
  929. pu_003:
  930.         cmp     [esi],byte ' '  ; end of text?
  931.         je      pu_004          ; yep, so none found
  932.         cmp     esi,edi         ; end of string?
  933.         je      pu_004          ; yep, so none found
  934.         cmp     [esi],byte '/'  ; delimiter?
  935.         je      pu_005          ; yep - process it
  936.         inc     esi
  937.         jmp     pu_003
  938.  
  939. pu_005:
  940. ; copy page to document address
  941. ; esi = delimiter
  942.         push    esi
  943.         mov     ecx,edi         ; end of document_user
  944.         mov     edi,document
  945.         cld
  946.  
  947. pu_006:
  948.         movsb
  949.         cmp     esi,ecx
  950.         je      pu_007          ; end of string?
  951.         cmp     [esi],byte ' '  ; end of text
  952. ;       je      pu_007          ; äçåí-àññåìáëåð
  953. ;       jmp     pu_006          ; íå íàäî ïëîäèòü ñóùíîñòè ïî íàïðàñíó
  954.         jne     pu_006
  955.  
  956. pu_007:
  957.         pop     esi     ; point esi to '/' delimiter
  958.  
  959. pu_004:
  960. ; copy web address to webAddr
  961. ; start in ebx,end in esi-1
  962.         mov     ecx,esi
  963.         mov     esi,ebx
  964.         mov     edi,webAddr
  965.         cld
  966.  
  967. pu_008:
  968.         movsb
  969.         cmp     esi,ecx
  970. ;       je      pu_009          ; äçåí-àññåìáëåð
  971. ;       jmp     pu_008          ; íå íàäî ïëîäèòü ñóùíîñòè ïî íàïðàñíó
  972.         jne     pu_008
  973.  
  974. pu_009:
  975. ; For debugging, display resulting strings
  976. if      DEBUGGING_STATE = DEBUGGING_ENABLED
  977.         mov     esi,document_user
  978.         call    debug_print_string
  979.         mov     esi,webAddr
  980.         call    debug_print_string
  981.         mov     esi,document
  982.         call    debug_print_string
  983. end     if
  984. ; Look up the ip address, or was it specified?
  985.         mov     al,[proxyAddr]
  986.         cmp     al,0
  987.         jnz     pu_015
  988.         mov     al,[webAddr]
  989. pu_015:
  990.         cmp     al,'0'
  991.         jb      pu_010  ; Resolve address
  992.         cmp     al,'9'
  993.         ja      pu_010  ; Resolve address
  994.  
  995. if      DEBUGGING_STATE = DEBUGGING_ENABLED
  996.         mov     esi,str2        ; print gotip
  997.         call    debug_print_string
  998. end     if
  999. ; Convert address
  1000. ; If proxy is given, get proxy address instead of server
  1001.         mov     esi,proxyAddr-1
  1002.         cmp     byte [esi+1],0
  1003.         jnz     pu_020
  1004.         mov     esi,webAddr-1
  1005.  
  1006. pu_020:
  1007.         mov     edi,server_ip
  1008.         xor     eax,eax
  1009.  
  1010. ip1:
  1011.         inc     esi
  1012.         cmp     [esi],byte '0'
  1013.         jb      ip2
  1014.         cmp     [esi],byte '9'
  1015.         jg      ip2
  1016.         imul    eax,10
  1017.         movzx   ebx,byte [esi]
  1018.         sub     ebx,48
  1019.         add     eax,ebx
  1020.         jmp     ip1
  1021.  
  1022. ip2:
  1023.         mov     [edi],al
  1024.         xor     eax,eax
  1025.         inc     edi
  1026.         cmp     edi,server_ip+3
  1027.         jbe     ip1
  1028.         jmp     pu_011
  1029.  
  1030. pu_010:
  1031. if      DEBUGGING_STATE = DEBUGGING_ENABLED
  1032.         mov     esi,str1        ; print resolving
  1033.         call    debug_print_string
  1034. end     if
  1035. ; Resolve Address
  1036.         call    translateData   ; Convert domain & DNS IP address
  1037.         call    resolveDomain   ; get ip address
  1038.  
  1039. if      DEBUGGING_STATE = DEBUGGING_ENABLED
  1040.         mov     esi,str3
  1041.         call    debug_print_string
  1042. end     if
  1043.  
  1044. pu_011:
  1045. ; Done
  1046.         ret
  1047.  
  1048. ;***************************************************************************
  1049. ;   Function
  1050. ;      translateData
  1051. ;
  1052. ;   Description
  1053. ;      Coverts the domain name and DNS IP address typed in by the user into
  1054. ;      a format suitable for the IP layer.
  1055. ;
  1056. ;    The ename, in query, is converted and stored in dnsMsg
  1057. ;
  1058. ;***************************************************************************
  1059. translateData:
  1060.     ; first, get the IP address of the DNS server
  1061.     ; Then, build up the request string.
  1062.  
  1063.     ; Build the request string
  1064.         mov     eax,0x00010100
  1065.         mov     [dnsMsg],eax
  1066.         mov     eax,0x00000100
  1067.         mov     [dnsMsg+4],eax
  1068.         mov     eax,0x00000000
  1069.         mov     [dnsMsg+8],eax
  1070. ; domain name goes in at dnsMsg+12
  1071.         mov     esi,dnsMsg +12  ;location of label length
  1072.         mov     edi,dnsMsg + 13 ;label start
  1073.         mov     edx,proxyAddr
  1074.         cmp     byte [edx],0
  1075.         jnz     td000
  1076.         mov     edx,webAddr
  1077.  
  1078. td000:
  1079.         mov     ecx,12  ; total string length so far
  1080.  
  1081. td002:
  1082.         mov     [esi],byte 0
  1083.         inc     ecx
  1084.  
  1085. td0021:
  1086.         mov     al,[edx]
  1087.         cmp     al,' '
  1088.         je      td001   ; we have finished the string translation
  1089.  
  1090.         cmp     al,0
  1091.         je      td001
  1092.  
  1093.         cmp     al,'.'  ; we have finished the label
  1094.         je      td004
  1095.  
  1096.         inc     byte [esi]
  1097.         inc     ecx
  1098.         mov     [edi],al
  1099.         inc     edi
  1100.         inc     edx
  1101.         jmp     td0021
  1102.  
  1103. td004:
  1104.         mov     esi,edi
  1105.         inc     edi
  1106.         inc     edx
  1107.         jmp     td002
  1108.  
  1109. ; write label len + label text
  1110. td001:
  1111.         mov     [edi],byte 0
  1112.         inc     ecx
  1113.         inc     edi
  1114.         mov     [edi],dword 0x01000100
  1115.         add     ecx,4
  1116.         mov     [dnsMsgLen],ecx
  1117.         ret
  1118.  
  1119. ;***************************************************************************
  1120. ;   Function
  1121. ;      resolveDomain
  1122. ;
  1123. ;   Description
  1124. ;       Sends a question to the dns server
  1125. ;       works out the IP address from the response from the DNS server
  1126. ;
  1127. ;***************************************************************************
  1128. resolveDomain:
  1129. ; Get a free port number
  1130.         mov     ecx,1000        ; local port starting at 1000
  1131. getlp:
  1132.         inc     ecx
  1133.         push    ecx
  1134.         mcall   53,9
  1135.         pop     ecx
  1136.         cmp     eax,0   ; is this local port in use?
  1137.         jz      getlp   ; yes - so try next
  1138.  
  1139. ; Get DNS IP
  1140.         mcall   52,13
  1141.         mov     esi,eax
  1142. ; First, open socket
  1143.         mov     edx,53  ; remote port - dns
  1144. ;       mov     esi,dword [dns_ip]
  1145.         xor     ebx,ebx ; 0
  1146.         mcall   53
  1147.         mov     [socketNum],eax
  1148. ; write to socket ( request DNS lookup )
  1149.         mcall   53,4,[socketNum],[dnsMsgLen],dnsMsg
  1150. ; Setup the DNS response buffer
  1151.         mov     eax,dnsMsg
  1152.         mov     [dnsMsgLen],eax
  1153. ; now, we wait for
  1154. ; UI redraw
  1155. ; UI close
  1156. ; or data from remote
  1157.  
  1158. ctr001:
  1159.         mcall   10      ; wait here for event
  1160.         cmp     eax,1   ; redraw request ?
  1161.         je      ctr003
  1162.  
  1163.         cmp     eax,2   ; key in buffer ?
  1164.         je      ctr004
  1165.  
  1166.         cmp     eax,3   ; button in buffer ?
  1167.         je      ctr005
  1168. ; Any data in the UDP receive buffer?
  1169.         mcall   53,2,[socketNum]
  1170.         cmp     eax,0
  1171.         je      ctr001
  1172.  
  1173. ; we have data - this will be the response
  1174. ctr002:
  1175.         mcall   53,3,[socketNum]        ; read byte - block (high byte)
  1176. ; Store the data in the response buffer
  1177.         mov     eax,[dnsMsgLen]
  1178.         mov     [eax],bl
  1179.         inc     dword [dnsMsgLen]
  1180.  
  1181.         mcall   53,2,[socketNum]        ; any more data?
  1182.         cmp     eax,0
  1183.         jne     ctr002  ; yes, so get it
  1184.  
  1185. ; close socket
  1186.         mcall   53,1,[socketNum]
  1187.         mov     [socketNum],dword  0xFFFF
  1188. ; Now parse the message to get the host IP
  1189. ; Man, this is complicated. It's described in
  1190. ; RFC 1035
  1191. if      DEBUGGING_STATE = DEBUGGING_ENABLED
  1192.         mov     esi,str4
  1193.         call    debug_print_string
  1194. end     if
  1195.  
  1196.     ; 1) Validate that we have an answer with > 0 responses
  1197.     ; 2) Find the answer record with TYPE 0001 ( host IP )
  1198.     ; 3) Finally, copy the IP address to the display
  1199.     ; Note: The response is in dnsMsg
  1200.     ;       The end of the buffer is pointed to by [dnsMsgLen]
  1201.  
  1202. ; Clear the IP address text
  1203.         mov     [server_ip],dword  0
  1204.         mov     esi,dnsMsg
  1205. ; Is this a response to my question?
  1206.         mov     al,[esi+2]
  1207.         and     al,0x80
  1208.         cmp     al,0x80
  1209.         jne     ctr002a
  1210. ; Were there any errors?
  1211.         mov     al,[esi+3]
  1212.         and     al,0x0F
  1213.         cmp     al,0x00
  1214.         jne     ctr002a
  1215. ; Is there ( at least 1 ) answer?
  1216.         mov     ax,[esi+6]
  1217.         cmp     ax,0x00
  1218.         je      ctr002a
  1219. ; Header valdated. Scan through and get my answer
  1220. if      DEBUGGING_STATE = DEBUGGING_ENABLED
  1221.         pusha
  1222.         mov     esi,str4
  1223.         call    debug_print_string
  1224.         popa
  1225. end     if
  1226.         add     esi,12  ; Skip to the question field
  1227. ; Skip through the question field
  1228.         call    skipName
  1229.         add     esi,4   ; skip past the questions qtype, qclass
  1230.  
  1231. ctr002z:
  1232. ; Now at the answer. There may be several answers,
  1233. ; find the right one ( TYPE = 0x0001 )
  1234.         call    skipName
  1235.         mov     ax,[esi]
  1236.         cmp     ax,0x0100       ; Is this the IP address answer?
  1237.         jne     ctr002c
  1238. ; Yes! Point esi to the first byte of the IP address
  1239.         add     esi,10
  1240.         mov     eax,[esi]
  1241.         mov     [server_ip],eax
  1242.         ret
  1243.  
  1244. ctr002c:        ; Skip through the answer, move to the next
  1245.         add     esi,8
  1246.         movzx   eax,byte [esi+1]
  1247.         mov     ah,[esi]
  1248.         add     esi,eax
  1249.         add     esi,2
  1250. ; Have we reached the end of the msg?
  1251. ; This is an error condition, should not happen
  1252.         cmp     esi,[dnsMsgLen]
  1253.         jl      ctr002z ; Check next answer
  1254.         jmp     ctr002a ; abort
  1255.  
  1256. ctr002a:
  1257.         jmp     ctr001
  1258.  
  1259. ctr003: ; redraw
  1260.         call    draw_window
  1261.         jmp     ctr001
  1262.  
  1263. ctr004: ; key
  1264.         mcall   2       ; just read it and ignore
  1265.         jmp     ctr001
  1266.  
  1267. ctr005: ; button
  1268.         mcall   17      ; get id
  1269.         mov     dl,ah
  1270.  
  1271.         ; close socket
  1272.         mcall   53,1,[socketNum]
  1273.         cmp     dl,1
  1274.         je      exit
  1275.  
  1276.         mov     [socketNum],dword  0xFFFF
  1277.         mov     [server_ip],dword  0
  1278.         ret
  1279.  
  1280. ;***************************************************************************
  1281. ;   Function
  1282. ;      skipName
  1283. ;
  1284. ;   Description
  1285. ;       Increment esi to the first byte past the name field
  1286. ;       Names may use compressed labels. Normally do.
  1287. ;       RFC 1035 page 30 gives details
  1288. ;
  1289. ;***************************************************************************
  1290. skipName:
  1291.         mov     al,[esi]
  1292.         cmp     al,0
  1293.         je      sn_exit
  1294.         and     al,0xc0
  1295.         cmp     al,0xc0
  1296.         je      sn001
  1297.  
  1298.         movzx   eax,byte [esi]
  1299.         inc     eax
  1300.         add     esi,eax
  1301.         jmp     skipName
  1302.  
  1303. sn001:
  1304.         add     esi,2   ; A pointer is always at the end
  1305.         ret
  1306.  
  1307. sn_exit:
  1308.         inc     esi
  1309.         ret
  1310.  
  1311. ;***************************************************************************
  1312. ;   Function
  1313. ;       load_settings
  1314. ;
  1315. ;   Description
  1316. ;       Load settings from configuration file network.ini
  1317. ;
  1318. ;***************************************************************************
  1319. load_settings:
  1320.         stdcall dll.Load,@IMPORT
  1321.         test    eax,eax
  1322.         jnz     ls001
  1323.         invoke  ini.get_str,inifile,sec_proxy,key_proxy,proxyAddr,256,proxyAddr
  1324.         invoke  ini.get_int,inifile,sec_proxy,key_proxyport,80
  1325.         mov     [proxyPort],eax
  1326.         invoke  ini.get_str,inifile,sec_proxy,key_user, proxyUser,256,proxyUser
  1327.         invoke  ini.get_str,inifile,sec_proxy,key_password,proxyPassword,256,proxyPassword
  1328. ls001:
  1329.         ret
  1330.  
  1331. ;***************************************************************************
  1332. ;   Function
  1333. ;       append_proxy_auth_header
  1334. ;
  1335. ;   Description
  1336. ;       Append header to HTTP request for proxy authentification
  1337. ;
  1338. ;***************************************************************************
  1339. append_proxy_auth_header:
  1340.         mov     esi,proxy_auth_basic
  1341.         mov     ecx,proxy_auth_basic_end - proxy_auth_basic
  1342.         rep     movsb
  1343. ; base64-encode string <user>:<password>
  1344.         mov     esi,proxyUser
  1345.  
  1346. apah000:
  1347.         lodsb
  1348.         test    al,al
  1349.         jz      apah001
  1350.         call    encode_base64_byte
  1351.         jmp     apah000
  1352.  
  1353. apah001:
  1354.         mov     al,':'
  1355.         call    encode_base64_byte
  1356.         mov     esi,proxyPassword
  1357.  
  1358. apah002:
  1359.         lodsb
  1360.         test    al,al
  1361.         jz      apah003
  1362.         call    encode_base64_byte
  1363.         jmp     apah002
  1364.  
  1365. apah003:
  1366.         call    encode_base64_final
  1367.         ret
  1368.  
  1369. encode_base64_byte:
  1370.         inc     ecx
  1371.         shl     edx,8
  1372.         mov     dl,al
  1373.         cmp     ecx,3
  1374.         je      ebb001
  1375.         ret
  1376.  
  1377. ebb001:
  1378.         shl     edx,8
  1379.         inc     ecx
  1380.  
  1381. ebb002:
  1382.         rol     edx,6
  1383.         xor     eax,eax
  1384.         xchg    al,dl
  1385.         mov     al,[base64_table+eax]
  1386.         stosb
  1387.         loop    ebb002
  1388.         ret
  1389.  
  1390. encode_base64_final:
  1391.         mov     al,0
  1392.         test    ecx,ecx
  1393.         jz      ebf000
  1394.         call    encode_base64_byte
  1395.         test    ecx,ecx
  1396.         jz      ebf001
  1397.         call    encode_base64_byte
  1398.         mov     byte [edi-2],'='
  1399.  
  1400. ebf001:
  1401.         mov     byte [edi-1],'='
  1402.  
  1403. ebf000:
  1404.         ret
  1405.  
  1406. if      DEBUGGING_STATE = DEBUGGING_ENABLED
  1407.  
  1408. ;****************************************************************************
  1409. ;    Function
  1410. ;       debug_print_string
  1411. ;
  1412. ;   Description
  1413. ;       prints a string to the debug board, in quotes
  1414. ;
  1415. ;       esi holds ptr to msg to display, which is space or 0 terminated
  1416. ;
  1417. ;       Nothing preserved; I'm assuming a pusha/popa is done before calling
  1418. ;
  1419. ;****************************************************************************
  1420. debug_print_string:
  1421.         push    esi
  1422.         mov     cl,'"'
  1423.         mcall   63,1
  1424.         pop     esi
  1425.  
  1426. dps_000:
  1427.         mov     cl,[esi]
  1428.         cmp     cl,0
  1429.         je      dps_exit
  1430.  
  1431.         cmp     cl,' '
  1432.         je      dps_exit
  1433.         jmp     dps_001
  1434.  
  1435. dps_exit:
  1436.         mov     cl,'"'
  1437.         mcall   63,1
  1438.         mov     cl,13
  1439.         mcall  
  1440.         mov     cl,10
  1441.         mcall
  1442.         ret
  1443.  
  1444. dps_001:
  1445.         push    esi
  1446.         mcall   63,1
  1447.         pop     esi
  1448.         inc     esi
  1449.         jmp     dps_000
  1450. end     if
  1451.  
  1452. ;****************************************************************************
  1453. ;    Function
  1454. ;       print_text
  1455. ;
  1456. ;   Description
  1457. ;       display the url (full path) text
  1458. ;
  1459. ;****************************************************************************
  1460. print_text:
  1461. ; Draw a bar to blank out previous text
  1462.         mcall   13, <30,520>, <[ya], 9>,0xFFFFFF
  1463. ; write text
  1464.         mcall   4, <30,[ya]>, 0,[addr],URLMAXLEN
  1465.         ret
  1466.  
  1467. ;   *********************************************
  1468. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  1469. ;   *********************************************
  1470.  
  1471. draw_window:
  1472.  
  1473.         mcall   12,1 ; start window redraw
  1474.  
  1475. ;       cmp     [params],byte 0
  1476. ;       jz      .noret
  1477.  
  1478. ;.noret:
  1479. ; DRAW  WINDOW
  1480.         mcall   0,<50,570>,<350,200>,0x14ffffff,0,title
  1481. ; eax   function 4: write text to window
  1482. ; ebx   [x start] *65536 + [y start]
  1483. ; ecx   color of text RRGGBB
  1484. ; edx   pointer to text beginning
  1485. ; esi   max lenght
  1486.         xor     ecx,ecx
  1487.         mcall   4,<30,38>,,document_user,URLMAXLEN
  1488.  
  1489. ;       xor     edx,edx
  1490. ;       mcall   38,<5,545>,<60,60>
  1491.  
  1492. ;       mov     ecx,[winys]
  1493. ;       shl     ecx,16
  1494. ;       add     ecx,[winys]
  1495. ;       sub     ecx,26*65536+26
  1496. ;       mcall   38,<5,545>
  1497.  
  1498. ; RELOAD
  1499.         mcall   8,<388,50>,<54,14>,22,0x5588dd
  1500. ; URL
  1501.         mcall   ,<10,12>,<34,12>,10
  1502. ; STOP
  1503.         mcall   ,<443,50>,<54,14>,24
  1504. ; SAVE
  1505.         mcall   ,<498,50>,,26
  1506. ; BUTTON TEXT
  1507.         mcall   4,<390,58>,0xffffff,button_text,30
  1508.         call    display_page
  1509.  
  1510.         mcall   12,2 ; end window redraw
  1511.         ret
  1512. ;-----------------------------------------------------------------------------
  1513. ; Data area
  1514. ;-----------------------------------------------------------------------------
  1515. align   4
  1516. @IMPORT:
  1517.  
  1518. library libini,'libini.obj'
  1519.  
  1520. import  libini, \
  1521.         ini.get_str,'ini_get_str', \
  1522.         ini.get_int,'ini_get_int'
  1523.  
  1524. ;---------------------------------------------------------------------
  1525. fileinfo        dd 2,0,0
  1526. final_size      dd 0
  1527. final_buffer    dd 0
  1528.                 db '/rd/1/.download',0
  1529.        
  1530. body_pos        dd 0
  1531.  
  1532. ;fileinfo_tmp   dd 2,0,0
  1533. buf_size        dd 0
  1534. buf_ptr         dd 0
  1535. ;               db      '/rd/1/1',0
  1536.  
  1537. deba            dd 0
  1538.                 db 0
  1539. ;---------------------------------------------------------------------
  1540. if      DEBUGGING_STATE = DEBUGGING_ENABLED
  1541. str1:           db "Resolving...",0
  1542. str3:           db "Resolved",0
  1543. str2:           db "GotIP",0
  1544. str4:           db "GotResponse",0
  1545. end     if
  1546. ;---------------------------------------------------------------------
  1547. button_text     db ' RELOAD    STOP     SAVE      '
  1548. dpx             dd 25   ; x - start of html page in pixels in window
  1549. dpy             dd 65   ; for   y
  1550. lastletter      db 0
  1551. pageyinc        dd 0
  1552. display_from    dd 20
  1553. pos             dd 0x0
  1554. pagex           dd 0x0
  1555. pagey           dd 0x0
  1556. pagexs          dd 80
  1557. command_on_off  dd 0x0
  1558. text_type       db 1
  1559. com2            dd 0x0
  1560. script          dd 0x0
  1561. socket          dd 0x0
  1562.  
  1563. addr            dd 0x0
  1564. ya              dd 0x0
  1565. len             dd 0x00
  1566.  
  1567. title           db 'Network Downloader',0
  1568.  
  1569. server_ip:      db 207,44,212,20
  1570. ;dns_ip:        db 194,145,128,1
  1571. ;---------------------------------------------------------------------
  1572. ;webAddr:
  1573. ;times URLMAXLEN db ' '
  1574. ;db     0
  1575.  
  1576. ;document:      db '/'
  1577. ;times URLMAXLEN-1 db ' '
  1578. ;---------------------------------------------------------------------
  1579. s_contentlength db 'Content-Length:'
  1580. len_contentlength = 15
  1581.  
  1582. s_chunked       db 'Transfer-Encoding: chunked'
  1583. len_chunked     = $ - s_chunked
  1584.  
  1585. is_body         dd 0    ; 0 if headers, 1 if content
  1586. is_chunked      dd 0
  1587. prev_chunk_end  dd 0
  1588. cur_chunk_size  dd 0
  1589.  
  1590. string0:        db 'GET '
  1591.  
  1592. stringh:        db ' HTTP/1.1',13,10,'Host: '
  1593. stringh_end:
  1594. proxy_auth_basic:       db 13,10,'Proxy-Authorization: Basic '
  1595. proxy_auth_basic_end:
  1596. connclose:      db 13,10,'User-Agent: Kolibrios Downloader',13,10,'Connection: Close',13,10,13,10
  1597. connclose_end:
  1598.  
  1599. base64_table    db 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  1600.                 db '0123456789+/'
  1601.  
  1602. inifile         db '/sys/network/zeroconf.ini',0
  1603.  
  1604. sec_proxy:
  1605. key_proxy       db 'proxy',0
  1606. key_proxyport   db 'port',0
  1607. key_user        db 'user',0
  1608. key_password    db 'password',0
  1609.  
  1610.  
  1611. proxyPort       dd 80
  1612.  
  1613. shared_name     dd 0
  1614.  
  1615. ;yandex:        db 'menuetos.net'
  1616. ;yandex_end:
  1617.  
  1618. status          dd 0x0
  1619. prev_status     dd 0x0
  1620.  
  1621. onoff           dd 0x0
  1622.  
  1623. nextupdate:     dd 0
  1624. winys:          dd 400
  1625.  
  1626. dnsMsgLen:      dd 0
  1627. socketNum:      dd 0xFFFF
  1628. ;---------------------------------------------------------------------
  1629. document_user:  db 'Click on the button to the left to enter a URL',0
  1630. ;---------------------------------------------------------------------
  1631. IM_END:
  1632.         rb URLMAXLEN-(IM_END - document_user)
  1633. ;---------------------------------------------------------------------
  1634. align 4
  1635. document:
  1636.         rb URLMAXLEN
  1637. ;---------------------------------------------------------------------
  1638. align 4
  1639. webAddr:
  1640.         rb URLMAXLEN+1
  1641. ;---------------------------------------------------------------------
  1642. align 4
  1643. primary_buf:
  1644.         rb primary_buffer_size
  1645. ;---------------------------------------------------------------------
  1646. align 4
  1647. params:         ; db 1024 dup(0)
  1648.         rb 1024
  1649. ;---------------------------------------------------------------------
  1650. align 4
  1651. request:        ; db 256 dup(0)
  1652.         rb 256
  1653. ;---------------------------------------------------------------------
  1654. align 4
  1655. proxyAddr:      ; db 256 dup(0)
  1656.         rb 256
  1657. ;---------------------------------------------------------------------
  1658. align 4
  1659. proxyUser:      ; db 256 dup(0)
  1660.         rb 256
  1661. ;---------------------------------------------------------------------
  1662. align 4
  1663. proxyPassword:  ; db 256 dup(0)
  1664.         rb 256
  1665. ;---------------------------------------------------------------------
  1666. align 4
  1667. dnsMsg:
  1668.         rb 4096
  1669. ;       rb 0x100000
  1670. ;---------------------------------------------------------------------
  1671. align 4
  1672.         rb 4096
  1673. stacktop:
  1674. ;---------------------------------------------------------------------
  1675. I_END:
  1676. ;---------------------------------------------------------------------