Subversion Repositories Kolibri OS

Rev

Rev 2738 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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