Subversion Repositories Kolibri OS

Rev

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

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