Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                                      ;
  3. ;    Tiny HTTP Server v 0.5 for KolibriOS              ;
  4. ;                                                      ;
  5. ;    License GPL / See file COPYING for details.       ;
  6. ;    Copyright 2003 Ville Turjanmaa                    ;
  7. ;                                                      ;
  8. ;    Compile with FASM for Menuet/KolibriOS            ;
  9. ;                                                      ;
  10. ;    Request /TinyStat for server statistics           ;
  11. ;    Request /TinyBoard for server message board       ;
  12. ;                                                      ;
  13. ;    Special version for KoOS by Hex && Heavyiron      ;
  14. ;                                                      ;
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16.  
  17. appname  equ  'Kolibri HTTP Server '
  18. version  equ  '0.6'
  19.  
  20. use32
  21.  
  22.                 org     0x0
  23.  
  24.                 db      'MENUET01'              ; 8 byte id
  25.                 dd      0x01                    ; required os
  26.                 dd      START                   ; program start
  27.                 dd      I_END                   ; program image size
  28.                 dd      0x400000                ; required amount of memory
  29.                 dd      0x400000
  30.                 dd      0,0                     ; reserved=no extended header
  31.  
  32. include "..\..\..\MACROS.INC"
  33.  
  34. ; 0x0+       - program image
  35. ; 0x1ffff    - stack
  36. ; 0x20000+   - message board
  37. ; 0x100000+  - requested file
  38.  
  39. filel:
  40.    dd 0
  41.    dd 0
  42.    dd 0
  43.    dd 50000
  44.    dd 0x20000
  45.    db   '/rd/1/board.htm',0
  46.  
  47. files:
  48.     dd 2
  49.     dd 0
  50.     dd 0
  51.     dd 0
  52.     dd 0x20000
  53.     db '/rd/1/board.htm',0
  54.  
  55.  
  56. START:                          ; start of execution
  57.  
  58.     mov  eax,70
  59.     mov  ebx,filel
  60.     mcall
  61.     mov  [board_size],ebx
  62.     cmp  eax,0
  63.     je   board_found
  64.  
  65.     mov  [board_size],board_end-board
  66.     mov  esi,board
  67.     mov  edi,0x20000
  68.     mov  ecx,[board_size]
  69.     cld
  70.     rep  movsb
  71.  
  72.    board_found:
  73.  
  74.     mov  eax,70
  75.     mov  ebx,files
  76.     mov  ecx,[board_size]
  77.     mov  [files+12],ecx
  78.     mcall
  79.  
  80.     mov  [status],-1
  81.     mov  [last_status],-2
  82.     call clear_input
  83. red:
  84.     call draw_window            ; at first, draw the window
  85.  
  86. still:
  87.  
  88.     call check_status
  89.     cmp  [status],4
  90.     je   start_transmission
  91.  
  92.     cmp  [status],0
  93.     jne  nnn
  94.     cmp  [server_active],1
  95.     jne  nnn
  96.     call ops
  97.    nnn:
  98.  
  99.     mov  eax,5
  100.     mov  ebx,1
  101.     mcall
  102.  
  103.     mov  eax,11
  104.     mcall
  105.     call check_events
  106.  
  107.     jmp  still
  108.  
  109. last_status   dd   0x0
  110.  
  111. check_events:
  112.  
  113.     cmp  eax,1                  ; redraw request ?
  114.     jz   red
  115.     cmp  eax,2                  ; key in buffer ?
  116.     jz   key
  117.     cmp  eax,3                  ; button in buffer ?
  118.     jz   button
  119.  
  120.     ret
  121.  
  122. key:                           ; Keys are not valid at this part of the
  123.     mov  al,2                  ; loop. Just read it and ignore
  124.     mcall
  125.     ret
  126.  
  127. button:                         ; button
  128.  
  129.     mov  al,17          ; get id
  130.     mcall
  131.  
  132.     cmp  ah,1           ; close
  133.     jnz  tst2
  134.     mov  eax,53
  135.     mov  ebx,8
  136.     mov  ecx,[socket]
  137.     mcall
  138.     mov  eax,-1
  139.     mcall
  140.   tst2:
  141.  
  142.     cmp  ah,2            ; button id=2 ?
  143.     jnz  tst3
  144.     ; open socket
  145.   ops:
  146.     mov  eax,53
  147.     mov  ebx,5
  148.     mov  ecx,80       ; local port # - http
  149.     mov  edx,0      ; no remote port specified
  150.     mov  esi,0      ; no remote ip specified
  151.     mov  edi,0      ; PASSIVE open
  152.     mcall
  153.     mov  [socket], eax
  154.     mov  [posy],1
  155.     mov  [posx],0
  156.     call check_for_incoming_data
  157.     call clear_input
  158.     call draw_data
  159.     mov  [server_active],1
  160.     call check_status
  161.     ret
  162.   tst3:
  163.     cmp  ah,4                   ; button id=4 ?
  164.     jnz  no4
  165.     mov  [server_active],0
  166.   close_socket:
  167.     mov  eax,53
  168.     mov  ebx,8
  169.     mov  ecx,[socket]
  170.     mcall
  171.     mov  eax,5
  172.     mov  ebx,2
  173.     mcall
  174.     mov  eax,53
  175.     mov  ebx,8
  176.     mov  ecx,[socket]
  177.     mcall
  178.  
  179.     cmp  [server_active],1
  180.     jne  no_re_open
  181.     mov  eax,53
  182.     mov  ebx,5
  183.     mov  ecx,80     ; local port # - http
  184.     mov  edx,0      ; no remote port specified
  185.     mov  esi,0      ; no remote ip specified
  186.     mov  edi,0      ; PASSIVE open
  187.     mcall
  188.     mov  [socket], eax
  189.   no_re_open:
  190.  
  191.     mov  edi,input_text+256*15+1
  192.     mov  [edi+2],dword ':  :'
  193.     call set_time
  194.     mov  edi,input_text+256*16+1
  195.     mov  [edi+2],dword '.  .'
  196.     call set_date
  197.  
  198.     mov  eax,[documents_served]
  199.     mov  ecx,9
  200.     mov  edi,input_text+256*15+12
  201.     call set_value
  202.  
  203.     mov  eax,[bytes_transferred]
  204.     mov  ecx,9
  205.     mov  edi,input_text+256*16+12
  206.     call set_value
  207.  
  208.     call draw_data
  209.  
  210.     mov  esp,0x1ffff
  211.     jmp  still
  212.   no4:
  213.  
  214.     cmp  ah,6                   ; read directory
  215.     je   read_string
  216.  
  217.     ret
  218.  
  219.  
  220. clear_input:
  221.  
  222.     mov  edi,input_text
  223.     mov  eax,0
  224.     mov  ecx,256*30
  225.     cld
  226.     rep  stosb
  227.  
  228.     ret
  229.  
  230.  
  231. retries  dd 50
  232.  
  233. start_transmission:
  234.  
  235.     mov  [posy],1
  236.     mov  [posx],0
  237.     call clear_input
  238.     mov  [retries],50
  239.  
  240.   wait_for_data:
  241.     call check_for_incoming_data
  242.     cmp  [input_text+256+1],dword 'GET '
  243.     je   data_received
  244.     cmp  [input_text+256+1],dword 'POST'
  245.     je   data_received
  246.     mov  eax,5
  247.     mov  ebx,1
  248.     mcall
  249.     dec  [retries]
  250.     jnz  wait_for_data
  251.     jmp  no_http_request
  252.   data_received:
  253.  
  254.     mov  eax,0x100000
  255.     mov  ebx,0x2f0000 / 512
  256.     call read_file
  257.  
  258.     call wait_for_empty_slot
  259.     call send_header
  260.  
  261.     mov  [filepos],0x100000
  262.     mov  [fileadd],700
  263.  
  264.     call check_status
  265.     call draw_data
  266.  
  267.   newblock:
  268.  
  269.     call wait_for_empty_slot
  270.  
  271.     mov  edx,[fileadd]
  272.     cmp  edx,[file_left]
  273.     jbe  file_size_ok
  274.     mov  edx,[file_left]
  275.   file_size_ok:
  276.     sub  [file_left],edx
  277.  
  278.     ; write to socket
  279.     mov  eax,53
  280.     mov  ebx,7
  281.     mov  ecx,[socket]
  282.     mov  esi,[filepos]
  283.     mcall
  284.  
  285.     mov  eax,esi
  286.     add  eax,edx
  287.     sub  eax,0x100000
  288.     call display_progress
  289.  
  290.     mov  edx,[fileadd]
  291.     add  [filepos],edx
  292.  
  293.     cmp  [file_left],0
  294.     jg   newblock
  295.  
  296.   no_http_request:
  297.  
  298.     jmp  close_socket
  299.  
  300.  
  301. filepos   dd  0x100000
  302. fileadd   dd  0x1
  303. filesize  dd  0x0
  304. file_left dd  0x0
  305.  
  306.  
  307. wait_for_empty_slot:
  308.  
  309.     pusha
  310.  
  311.   wait_more:
  312.  
  313.     mov  eax,5
  314.     mov  ebx,1
  315.     mcall
  316.  
  317.     mov  eax,11
  318.     mcall
  319.     call check_events
  320.  
  321.     mov  eax,53
  322.     mov  ebx,255
  323.     mov  ecx,103
  324.     mcall
  325.  
  326.     cmp  eax,0
  327.     je   no_wait_more
  328.  
  329.     jmp  wait_more
  330.  
  331.   no_wait_more:
  332.  
  333.     popa
  334.     ret
  335.  
  336.  
  337.  
  338.  
  339. display_progress:
  340.  
  341.   pusha
  342.  
  343.   mov  edi,eax
  344.  
  345.   mov  eax,13
  346.   mov  ebx,115*65536+8*6
  347.   mov  ecx,178*65536+10
  348.   mov  edx,0xffffff
  349.   mcall
  350.  
  351.   mov  eax,47
  352.   mov  ebx,8*65536
  353.   mov  ecx,edi
  354.   mov  edx,115*65536+178
  355.   mov  esi,0x000000
  356.   mcall
  357.  
  358.   popa
  359.   ret
  360.  
  361.  
  362. send_header:
  363.  
  364.     pusha
  365.  
  366.     mov   eax,53                  ; send response and file length
  367.     mov   ebx,7
  368.     mov   ecx,[socket]
  369.     mov   edx,h_len-html_header
  370.     mov   esi,html_header
  371.     mcall
  372.  
  373.     mov   eax,53                  ; send file type
  374.     mov   ebx,7
  375.     mov   ecx,[socket]
  376.     mov   edx,[type_len]
  377.     mov   esi,[file_type]
  378.     mcall
  379.  
  380.     popa
  381.     ret
  382.  
  383. fileinfo        dd 0
  384.                 dd 0
  385.                 dd 0
  386.                 dd 512
  387.                 dd 0x100000
  388. getf            db '/rd/1/'
  389.              times 50 db 0
  390. wanted_file: times 100 db 0
  391.  
  392. getflen      dd  6
  393.  
  394. make_room:
  395.  
  396.    pusha
  397.  
  398.    mov  edx,ecx
  399.  
  400.    mov  esi,0x20000
  401.    add  esi,[board_size]
  402.    mov  edi,esi
  403.    add  edi,edx
  404.    mov  ecx,[board_size]
  405.    sub  ecx,board1-board
  406.    inc  ecx
  407.    std
  408.    rep  movsb
  409.    cld
  410.  
  411.    popa
  412.    ret
  413.  
  414.  
  415. from_i  dd  0x0
  416. from_len dd 0x0
  417.  
  418. message dd 0x0
  419. message_len dd 0x0
  420.  
  421. read_file:                          ; start of execution
  422.  
  423.     mov  [fileinfo+16],eax
  424.     shl ebx, 9
  425.     mov  [fileinfo+12],ebx
  426.     mov  [file_type],unk
  427.     mov  [type_len],unkl-unk
  428.     mov  [filename+40*2+6],dword 'UNK '
  429.  
  430.     cmp  [input_text+256+1],dword 'POST'
  431.     je   yes_new_message
  432.  
  433.     cmp  [input_text+256+11],dword 'oard'     ; server board message
  434.     jne  no_server_message_2
  435.  
  436.   yes_new_message:
  437.  
  438.     mov  eax,70
  439.     mov  ebx,filel
  440.     mcall
  441.     mov  [board_size],ebx
  442.  
  443.     cmp  [input_text+256+1],dword 'POST'
  444.     jne  no_new_message
  445.  
  446.     mov  edi,bsmt
  447.     call set_time
  448.     mov  edi,bsmd
  449.     call set_date
  450.  
  451.     call check_for_incoming_data
  452.  
  453.     mov  esi,input_text+256   ; from
  454.    newfroms:
  455.     inc  esi
  456.     cmp  esi,input_text+256*20
  457.     je   no_server_message_2
  458.     cmp  [esi],dword 'from'
  459.     jne  newfroms
  460.  
  461.     add  esi,5
  462.     mov  [from_i],esi
  463.  
  464.     mov  edx,0
  465.    name_new_len:
  466.     cmp  [esi+edx],byte 13
  467.     je   name_found_len
  468.     cmp  [esi+edx],byte '&'
  469.     je   name_found_len
  470.     cmp  edx,1000
  471.     je   name_found_len
  472.     inc  edx
  473.     jmp  name_new_len
  474.  
  475.    name_found_len:
  476.  
  477.     mov  [from_len],edx
  478.  
  479.     mov  esi,input_text+256
  480.    newmessages:
  481.     inc  esi
  482.     cmp  esi,input_text+256*20
  483.     je   no_server_message_2
  484.     cmp  [esi],dword 'sage'
  485.     jne  newmessages
  486.  
  487.     add  esi,5
  488.     mov  [message],esi
  489.  
  490.     mov  edx,0
  491.    new_len:
  492.     inc  edx
  493.     cmp  [esi+edx],byte ' '
  494.     je   found_len
  495.     cmp  [esi+edx],byte 13
  496.     jbe  found_len
  497.     cmp  edx,input_text+5000
  498.     je   found_len
  499.     jmp  new_len
  500.    found_len:
  501.     mov  [message_len],edx
  502.  
  503.  
  504.     mov  edx,0
  505.  
  506.    change_letters:
  507.  
  508.     cmp  [esi+edx],byte '+'
  509.     jne  no_space
  510.     mov  [esi+edx],byte ' '
  511.    no_space:
  512.  
  513.     cmp  [esi+edx+1],word '0D'
  514.     jne  no_br
  515.     mov  [esi+edx],dword '<br>'
  516.     mov  [esi+edx+4],word '  '
  517.   no_br:
  518.  
  519.     cmp  [esi+edx],byte '%'
  520.     jne  no_ascii
  521.     movzx eax,byte [esi+edx+2]
  522.     sub  eax,48
  523.     cmp  eax,9
  524.     jbe  eax_ok
  525.     sub  eax,7
  526.    eax_ok:
  527.     movzx ebx,byte [esi+edx+1]
  528.     sub  ebx,48
  529.     cmp  ebx,9
  530.     jbe  ebx_ok
  531.     sub  ebx,7
  532.    ebx_ok:
  533.     imul ebx,16
  534.     add  ebx,eax
  535.     mov  [esi+edx],bl
  536.     mov  [esi+edx+1],word ''
  537.     add  edx,2
  538.    no_ascii:
  539.  
  540.     inc  edx
  541.     cmp  edx,[message_len]
  542.     jbe  change_letters
  543.  
  544.  
  545.     mov  edx,board1e-board1 + board2e-board2 + board3e-board3
  546.     add  edx,[from_len]
  547.     add  edx,[message_len]
  548.  
  549.     add  [board_size],edx
  550.  
  551.     mov  ecx,edx
  552.     call make_room
  553.  
  554.  
  555.     mov  esi,board1          ; first part
  556.     mov  edi,0x20000
  557.     add  edi,board1-board
  558.     mov  ecx,edx
  559.     cld
  560.     rep  movsb
  561.  
  562.     mov  esi,[from_i]          ; name
  563.     mov  edi,0x20000
  564.     add  edi,board1-board
  565.     add  edi,board1e-board1
  566.     mov  ecx,[from_len]
  567.     cld
  568.     rep  movsb
  569.  
  570.     mov  esi,board2          ; middle part
  571.     mov  edi,0x20000
  572.     add  edi,board1-board + board1e-board1
  573.     add  edi,[from_len]
  574.     mov  ecx,board2e-board2
  575.     cld
  576.     rep  movsb
  577.  
  578.     mov  esi,[message]       ; message
  579.     mov  edi,0x20000
  580.     add  edi,board1-board + board1e-board1 + board2e-board2
  581.     add  edi,[from_len]
  582.     mov  ecx,[message_len]
  583.     cld
  584.     rep  movsb
  585.  
  586.     mov  esi,board3    ; end part
  587.     mov  edi,0x20000
  588.     add  edi,board1-board + board1e-board1 + board2e-board2
  589.     add  edi,[from_len]
  590.     add  edi,[message_len]
  591.     mov  ecx,board3e-board3
  592.     cld
  593.     rep  movsb
  594.  
  595.     inc  [board_messages]
  596.  
  597.     mov  eax,[board_size]
  598.     mov  [files+12],eax
  599.  
  600.     mov  eax,70
  601.     mov  ebx,files
  602.     mcall
  603.  
  604.   no_new_message:
  605.     mov  esi,0x20000
  606.     mov  edi,0x100000
  607.     mov  ecx,[board_size]
  608.     cld
  609.     rep  movsb
  610.     mov  ebx,[board_size]
  611.  
  612.     mov  [file_type],htm
  613.     mov  [type_len],html-htm
  614.     mov  [filename+40*2+6],dword 'HTM '
  615.  
  616.     jmp  file_loaded
  617.   no_server_message_2:
  618.  
  619.     cmp  [input_text+256+9],dword 'ySta'     ; server message
  620.     jne  no_server_message_1
  621.     mov  edi,smt
  622.     call set_time
  623.     mov  edi,smd
  624.     call set_date
  625.     mov  eax,[documents_served]
  626.     mov  ecx,9
  627.     mov  edi,sms+21
  628.     call set_value
  629.     mov  eax,[bytes_transferred]
  630.     mov  ecx,9
  631.     mov  edi,smb+21
  632.     call set_value
  633.     mov  eax,[board_messages]
  634.     mov  ecx,9
  635.     mov  edi,smm+21
  636.     call set_value
  637.     mov  eax,[board_size]
  638.     mov  ecx,9
  639.     mov  edi,smz+21
  640.     call set_value
  641.     mov  esi,sm
  642.     mov  edi,0x100000
  643.     mov  ecx,sme-sm
  644.     cld
  645.     rep  movsb
  646.     mov  ebx,sme-sm
  647.  
  648.     mov  [file_type],htm
  649.     mov  [type_len],html-htm
  650.     mov  [filename+40*2+6],dword 'HTM '
  651.  
  652.     jmp  file_loaded
  653.   no_server_message_1:
  654.  
  655.     mov  esi,input_text+256+6
  656.     cmp  [input_text+256+1],dword 'GET '
  657.     jne  no_new_let
  658.     mov  edi,wanted_file
  659.     cld
  660.   new_let:
  661.     cmp  [esi],byte ' '
  662.     je   no_new_let
  663.     cmp  edi,wanted_file+30
  664.     jge  no_new_let
  665.     movsb
  666.     jmp  new_let
  667.   no_new_let:
  668.     mov  [edi+0],dword 0
  669.     mov  [edi+4],dword 0
  670.     mov  [edi+8],dword 0
  671.  
  672.     cmp  esi,input_text+256+6
  673.     jne  no_index
  674.     mov  edi,wanted_file
  675.     mov  [edi+0],dword  'inde'
  676.     mov  [edi+4],dword  'x.ht'
  677.     mov  [edi+8],byte   'm'
  678.     mov  [edi+9],byte   0
  679.     add  edi,9
  680.  
  681.     mov  [file_type],htm
  682.     mov  [type_len],html-htm
  683.     mov  [filename+40*2+6],dword 'HTM '
  684.  
  685.     jmp  html_file
  686.   no_index:
  687.  
  688.     cmp  [edi-3],dword 'htm'+0
  689.     je   htm_header
  690.     cmp  [edi-3],dword 'HTM'+0
  691.     je   htm_header
  692.     jmp  no_htm_header
  693.   htm_header:
  694.     mov  [file_type],htm
  695.     mov  [type_len],html-htm
  696.     mov  [filename+40*2+6],dword 'HTM '
  697.     jmp  found_file_type
  698.   no_htm_header:
  699.  
  700.     cmp  [edi-3],dword 'png'+0
  701.     je   png_header
  702.     cmp  [edi-3],dword 'PNG'+0
  703.     je   png_header
  704.     jmp  no_png_header
  705.   png_header:
  706.     mov  [file_type],png
  707.     mov  [type_len],pngl-png
  708.     mov  [filename+40*2+6],dword 'PNG '
  709.     jmp  found_file_type
  710.   no_png_header:
  711.  
  712.     cmp  [edi-3],dword 'gif'+0
  713.     je   gif_header
  714.     cmp  [edi-3],dword 'GIF'+0
  715.     je   gif_header
  716.     jmp  no_gif_header
  717.   gif_header:
  718.     mov  [file_type],gif
  719.     mov  [type_len],gifl-gif
  720.     mov  [filename+40*2+6],dword 'GIF '
  721.     jmp  found_file_type
  722.   no_gif_header:
  723.  
  724.     cmp  [edi-3],dword 'jpg'+0
  725.     je   jpg_header
  726.     cmp  [edi-3],dword 'JPG'+0
  727.     je   jpg_header
  728.     jmp  no_jpg_header
  729.   jpg_header:
  730.     mov  [file_type],jpg
  731.     mov  [type_len],jpgl-jpg
  732.     mov  [filename+40*2+6],dword 'JPG '
  733.     jmp  found_file_type
  734.   no_jpg_header:
  735.  
  736.     cmp  [edi-3],dword 'asm'+0
  737.     je   txt_header
  738.     cmp  [edi-3],dword 'ASM'+0
  739.     je   txt_header
  740.     cmp  [edi-3],dword 'txt'+0
  741.     je   txt_header
  742.     cmp  [edi-3],dword 'TXT'+0
  743.     je   txt_header
  744.     jmp  no_txt_header
  745.   txt_header:
  746.     mov  [file_type],txt
  747.     mov  [type_len],txtl-txt
  748.     mov  [filename+40*2+6],dword 'TXT '
  749.     jmp  found_file_type
  750.   no_txt_header:
  751.  
  752.   html_file:
  753.  
  754.   found_file_type:
  755.  
  756.     mov  edi,getf
  757.     add  edi,[getflen]
  758.     mov  esi,wanted_file
  759.     mov  ecx,40
  760.     cld
  761.     rep  movsb
  762.  
  763.     mov  esi,getf
  764.     mov  edi,filename
  765.     mov  ecx,35
  766.     cld
  767.     rep  movsb
  768.  
  769.     mov  [fileinfo+12],dword 1   ; file exists ?
  770.     mov  eax,70
  771.     mov  ebx,fileinfo
  772.     mcall
  773.  
  774.     cmp  eax,0         ; file not found - message
  775.     je   file_found
  776.     mov  edi,et
  777.     call set_time
  778.     mov  edi,ed
  779.     call set_date
  780.     mov  esi,fnf
  781.     mov  edi,0x100000
  782.     mov  ecx,fnfe-fnf
  783.     cld
  784.     rep  movsb
  785.     mov  ebx,fnfe-fnf
  786.  
  787.     mov  [file_type],htm
  788.     mov  [type_len],html-htm
  789.     mov  [filename+40*2+6],dword 'HTM '
  790.  
  791.     jmp  file_not_found
  792.  
  793.    file_found:
  794.  
  795.     mov  [fileinfo+12],dword 0x2f0000 ; read all of file
  796.     mov  eax,70
  797.     mov  ebx,fileinfo
  798.     mcall
  799.  
  800.    file_not_found:
  801.    file_loaded:
  802.  
  803.     and  ebx,0x3fffff
  804.     mov  [filesize],ebx
  805.     mov  [file_left],ebx
  806.  
  807.     mov  eax,ebx
  808.     mov  edi,c_l+5
  809.     mov  ebx,10
  810.   newl:
  811.     xor  edx,edx
  812.     div  ebx
  813.     mov  ecx,edx
  814.     add  cl,48
  815.     mov  [edi],cl
  816.     dec  edi
  817.     cmp  edi,c_l
  818.     jge  newl
  819.  
  820.     mov  esi,c_l
  821.     mov  edi,filename+46
  822.     mov  ecx,7
  823.     cld
  824.     rep  movsb
  825.  
  826.     inc  [documents_served]
  827.     mov  eax,[filesize]
  828.     add  [bytes_transferred],eax
  829.  
  830.     call draw_data
  831.  
  832.     ret
  833.  
  834.  
  835. set_value:
  836.  
  837.     pusha
  838.  
  839.     add  edi,ecx
  840.     mov  ebx,10
  841.   new_value:
  842.     xor  edx,edx
  843.     div  ebx
  844.     add  dl,48
  845.     mov  [edi],dl
  846.     dec  edi
  847.     loop new_value
  848.  
  849.     popa
  850.     ret
  851.  
  852.  
  853. set_time:
  854.  
  855.     pusha
  856.  
  857.     mov  eax,3
  858.     mcall
  859.  
  860.     mov  ecx,3
  861.   new_time_digit:
  862.     mov  ebx,eax
  863.     and  ebx,0xff
  864.     shl  ebx,4
  865.     shr  bl,4
  866.     add  bx,48*256+48
  867.     mov  [edi],bh
  868.     mov  [edi+1],bl
  869.     add  edi,3
  870.     shr  eax,8
  871.     loop new_time_digit
  872.  
  873.     popa
  874.     ret
  875.  
  876.  
  877.  
  878. set_date:
  879.  
  880.     pusha
  881.  
  882.     mov  eax,29
  883.     mcall
  884.  
  885.     mov  ecx,3
  886.     add  edi,6
  887.   new_date_digit:
  888.     mov  ebx,eax
  889.     and  ebx,0xff
  890.     shl  ebx,4
  891.     shr  bl,4
  892.     add  bx,48*256+48
  893.     mov  [edi],bh
  894.     mov  [edi+1],bl
  895.     sub  edi,3
  896.     shr  eax,8
  897.     loop new_date_digit
  898.  
  899.     popa
  900.     ret
  901.  
  902.  
  903.  
  904. check_for_incoming_data:
  905.  
  906.     pusha
  907.  
  908.    check:
  909.  
  910.     mov  eax, 53
  911.     mov  ebx, 2
  912.     mov  ecx, [socket]
  913.     mcall
  914.  
  915.     cmp  eax,0
  916.     je   _ret_now
  917.  
  918.   new_data:
  919.  
  920.     mov  eax,53
  921.     mov  ebx,2
  922.     mov  ecx,[socket]
  923.     mcall
  924.  
  925.     cmp  eax,0
  926.     je   _ret
  927.  
  928.     mov  eax,53
  929.     mov  ebx,3
  930.     mov  ecx,[socket]
  931.     mcall
  932.  
  933.     cmp  bl,10
  934.     jne  no_lf
  935.     inc  [posy]
  936.     mov  [posx],0
  937.     jmp  new_data
  938.   no_lf:
  939.  
  940.     cmp  bl,20
  941.     jb   new_data
  942.  
  943.     inc  [posx]
  944.     cmp  [posy],20
  945.     jbe  yok
  946.     mov  [posy],1
  947.    yok:
  948.  
  949.     mov  eax,[posy]
  950.     imul eax,256
  951.     add  eax,[posx]
  952.  
  953.     mov  [input_text+eax],bl
  954.  
  955.     jmp  new_data
  956.  
  957.   _ret:
  958.  
  959.      call draw_data
  960.  
  961.      mov  eax,5
  962.      mov  ebx,1
  963.      cmp  [input_text+256+1],dword 'POST'
  964.      jne  no_ld
  965.      mov  ebx,50
  966.    no_ld:
  967.      mcall
  968.  
  969.      jmp  check
  970.  
  971.   _ret_now:
  972.  
  973.     popa
  974.     ret
  975.  
  976.  
  977. posy dd 1
  978. posx dd 0
  979.  
  980.  
  981. check_status:
  982.  
  983.     pusha
  984.  
  985.     mov  eax,53
  986.     mov  ebx,6
  987.     mov  ecx,[socket]
  988.     mcall
  989.  
  990.     cmp  eax,[status]
  991.     je   c_ret
  992.     mov  [status],eax
  993.     add  al,48
  994.     mov  [text+12],al
  995.     call draw_data
  996.    c_ret:
  997.  
  998.     popa
  999.     ret
  1000.  
  1001.  
  1002. addr       dd  0x0
  1003. ya         dd  0x0
  1004.  
  1005. filename2:  times 100 db 32
  1006.  
  1007. read_string:
  1008.  
  1009.     mov  [addr],dword getf
  1010.     mov  [ya],dword 139
  1011.  
  1012.     mov  edi,[addr]
  1013.     mov  eax,0
  1014.     mov  ecx,30
  1015.     cld
  1016.     rep  stosb
  1017.  
  1018.     call print_text
  1019.  
  1020.     mov  edi,[addr]
  1021.  
  1022.   f11:
  1023.     mov  eax,10
  1024.     mcall
  1025.     cmp  eax,2
  1026.     jne  read_done
  1027.     mov  eax,2
  1028.     mcall
  1029.     shr  eax,8
  1030.     cmp  eax,13
  1031.     je   read_done
  1032.     cmp  eax,8
  1033.     jnz  nobsl
  1034.     cmp  edi,[addr]
  1035.     jz   f11
  1036.     sub  edi,1
  1037.     mov  [edi],byte 32
  1038.     call print_text
  1039.     jmp  f11
  1040.   nobsl:
  1041.     mov  [edi],al
  1042.  
  1043.     call print_text
  1044.  
  1045.     add  edi,1
  1046.     mov  esi,[addr]
  1047.     add  esi,30
  1048.     cmp  esi,edi
  1049.     jnz  f11
  1050.  
  1051.   read_done:
  1052.  
  1053.     push edi
  1054.  
  1055.     mov  ecx,40
  1056.     mov  eax,32
  1057.     cld
  1058.     rep  stosb
  1059.  
  1060.     call print_text
  1061.  
  1062.     pop  edi
  1063.     sub  edi,[addr]
  1064.     mov  [getflen],edi
  1065.  
  1066.     mov  esi,getf
  1067.     mov  edi,dirp+12
  1068.     mov  ecx,28
  1069.     cld
  1070.     rep  movsb
  1071.  
  1072.     jmp  still
  1073.  
  1074.  
  1075. print_text:
  1076.  
  1077.     pusha
  1078.  
  1079.     mov  eax,4
  1080.     mov  edx,[addr]
  1081.     mov  ebx,97*65536
  1082.     add  ebx,[ya]
  1083.     mov  ecx,0x40000000
  1084.     mov  esi,23
  1085.     mov  edi,0xffffff
  1086.     mcall
  1087.  
  1088.     popa
  1089.     ret
  1090.  
  1091.  
  1092. ;   *********************************************
  1093. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  1094. ;   *********************************************
  1095.  
  1096.  
  1097. draw_window:
  1098.  
  1099.     mov  eax,12                    ; function 12:tell os about windowdraw
  1100.     mov  ebx,1                     ; 1, start of draw
  1101.     mcall
  1102.  
  1103.                                    ; DRAW WINDOW
  1104.     mov  eax,0                     ; function 0 : define and draw window
  1105.     mov  ebx,100*65536+480         ; [x start] *65536 + [x size]
  1106.     mov  ecx,100*65536+215         ; [y start] *65536 + [y size]
  1107.     mov  edx,0x13ffffff            ; color of work area RRGGBB
  1108.     mov  edi,title                 ; WINDOW LABEL
  1109.     mcall
  1110.  
  1111.     mov  eax,8                     ; function 8 : define and draw button
  1112.     mov  ebx,(40)*65536+20         ; [x start] *65536 + [x size]
  1113.     mov  ecx,59*65536+9            ; [y start] *65536 + [y size]
  1114.     mov  edx,2                     ; button id
  1115.     mov  esi,0x66aa66              ; button color RRGGBB
  1116.     mcall
  1117.  
  1118.                            ; function 8 : define and draw button
  1119.     mov  ebx,(40)*65536+20         ; [x start] *65536 + [x size]
  1120.     mov  ecx,72*65536+9          ; [y start] *65536 + [y size]
  1121.     mov  edx,4                     ; button id
  1122.     mov  esi,0xaa6666              ; button color RRGGBB
  1123.     mcall
  1124.  
  1125.                            ; Enter directory
  1126.     mov  ebx,(25)*65536+66
  1127.     mov  ecx,135*65536+15
  1128.     mov  edx,6
  1129.     mov  esi,0x3388dd
  1130.     mcall
  1131.  
  1132.     mov  eax,38
  1133.     mov  ebx,240*65536+240
  1134.     mov  ecx,22*65536+210
  1135.     mov  edx,0x6699cc ; 002288
  1136.     mcall
  1137.  
  1138.  
  1139.     mov  ebx,241*65536+241
  1140.     mov  ecx,22*65536+210
  1141.     mov  edx,0x336699 ; 002288
  1142.     mcall
  1143.  
  1144.     call draw_data
  1145.  
  1146.     mov  eax,12                    ; function 12:tell os about windowdraw
  1147.     mov  ebx,2                     ; 2, end of draw
  1148.     mcall
  1149.  
  1150.     ret
  1151.  
  1152.  
  1153. draw_data:
  1154.  
  1155.     pusha
  1156.  
  1157.     mov  ebx,25*65536+35           ; draw info text with function 4
  1158.     mov  ecx,0x000000
  1159.     mov  edx,text
  1160.     mov  esi,35
  1161.     mov  eax,13
  1162.   newline:
  1163.     pusha
  1164.     cmp  ebx,25*65536+61
  1165.     je   now
  1166.     cmp  ebx,25*65536+74
  1167.     je   now
  1168.     cmp  ebx,25*65536+74+13*5
  1169.     je   now
  1170.     mov  ecx,ebx
  1171.     mov  bx,35*6
  1172.     shl  ecx,16
  1173.     mov  cx,9
  1174.     mov  edx,0xffffff
  1175.     mcall
  1176.    now:
  1177.     popa
  1178.     mov  eax,4
  1179.     mcall
  1180.     add  ebx,13
  1181.     add  edx,40
  1182.     cmp  [edx],byte 'x'
  1183.     jnz  newline
  1184.  
  1185.     mov  [input_text+0],dword 'RECE'
  1186.     mov  [input_text+4],dword 'IVED'
  1187.     mov  [input_text+8],dword ':   '
  1188.  
  1189.     mov  ebx,255*65536+35           ; draw info text with function 4
  1190.     mov  ecx,0x000000
  1191.     mov  edx,input_text
  1192.     mov  esi,35
  1193.     mov  edi,17
  1194.   newline2:
  1195.     pusha
  1196.     mov  ecx,ebx
  1197.     mov  bx,35*6
  1198.     shl  ecx,16
  1199.     mov  cx,9
  1200.     mov  eax,13
  1201.     mov  edx,0xffffff
  1202.     mcall
  1203.     popa
  1204.     mov  eax,4
  1205.     mcall
  1206.     add  ebx,10
  1207.     add  edx,256
  1208.     dec  edi
  1209.     jnz  newline2
  1210.  
  1211.     popa
  1212.  
  1213.     ret
  1214.  
  1215.  
  1216. ; DATA AREA
  1217.  
  1218. status  dd  0x0
  1219.  
  1220. text:
  1221.     db 'TCB status: x                           '
  1222.     db '                                        '
  1223.     db '       Activate server                  '
  1224.     db '       Stop server                      '
  1225.     db '                                        '
  1226.     db 'Requests: /TinyStat  -statistics        '
  1227.     db '          /TinyBoard -message board     '
  1228.     db '                                        '
  1229. dirp:
  1230.     db '   Files:   /rd/1/                      '
  1231.     db '                                        '
  1232. filename:
  1233.     db '                                        '
  1234.     db 'Size: -------                           '
  1235.     db 'Type: ---                               '
  1236.     db 'x' ; <- END MARKER, DONT DELETE
  1237.  
  1238.  
  1239. html_header:
  1240.  
  1241.      db  'HTTP/1.0 200 OK',13,10
  1242.      db  'Server: KolibriOS HTTP Server',13,10
  1243.      db  'Content-Length: '
  1244. c_l: db  '000000',13,10
  1245.  
  1246. h_len:
  1247.  
  1248. fnf:
  1249.      db  '<body>'
  1250.      db  '<pre>'
  1251.      db  "HTTP-Ñåðâåð v ",version," äëÿ KolibriOS",13,10,13,10
  1252.      db  "<H1>Error <FONT color=red>404</FONT> - File not found</H1>",13,10,13,10
  1253.      db  "Äëÿ ïîëó÷åíèÿ ñòàòèñòèêè âûïîëíèòå çàïðîñ /TinyStat",13,10,13,10
  1254. et:  db  "xx:xx:xx",13,10
  1255. ed:  db  "xx.xx.xx",13,10
  1256.      db  "</pre></body>"
  1257. fnfe:
  1258.  
  1259.  
  1260. sm:
  1261.      db  '<body>'
  1262.      db  '<pre>'
  1263.      db  "HTTP-Ñåðâåð v ",version," äëÿ KolibriOS",13,10,13,10
  1264.      db  "Ñòàòèñòèêà: (ïîñëå äàííîãî çàïðîñà)",13,10,13,10
  1265. sms: db  "- Äîêóìåíòîâ ïðèíÿòî: xxxxxxxxx",13,10
  1266. smb: db  "- Áàéò ïåðåäàííî    : xxxxxxxxx",13,10
  1267.      db  "- Ìåñòîíàõîæäåíèå   : <a href=/TinyStat>Ñòàòèñòèêà</a>",13,10,13,10
  1268.      db  "Ãîñòåâàÿ:",13,10,13,10
  1269. smm: db  "- Ñîîáùåíèé         : xxxxxxxxx",13,10
  1270. smz: db  "- Ðàçìåð â áàéòàõ   : xxxxxxxxx",13,10
  1271.      db  "- Ìåñòîíàõîæäåíèå   : <a href=/TinyBoard>Ãîñòåâàÿ</a>",13,10,13,10
  1272. smt: db  "xx:xx:xx",13,10
  1273. smd: db  "xx.xx.xx",13,10
  1274.      db  '</pre></body>'
  1275. sme:
  1276.  
  1277. documents_served  dd  0x0
  1278. bytes_transferred dd  0x0
  1279.  
  1280. file_type  dd  0
  1281. type_len   dd  0
  1282.  
  1283. htm:   db  'Content-Type: text/html',13,10,13,10
  1284. html:
  1285. txt:   db  'Content-Type: text/plain',13,10,13,10
  1286. txtl:
  1287. png:   db  'Content-Type: image/png',13,10,13,10
  1288. pngl:
  1289. gif:   db  'Content-Type: image/gif',13,10,13,10
  1290. gifl:
  1291. jpg:   db  'Content-Type: image/jpeg',13,10,13,10
  1292. jpgl:
  1293. unk:   db  'Content-Type: unknown/unknown',13,10,13,10
  1294. unkl:
  1295.  
  1296.  
  1297. title db   appname,version,0
  1298.  
  1299. socket          dd  0x0
  1300. server_active   db  0x0
  1301.  
  1302. board:
  1303.  
  1304. db "<HTML><HEAD><TITLE>INTKolibriOS - /Ãîñòåâàÿ/</TITLE></HEAD>",13,10
  1305. db "<BODY background=bgnd.gif BGCOLOR=#ffffff ALINK=black VLINK=black><br>",13,10
  1306. db "<center>",13,10
  1307. db "<TABLE CELLPADDING=10 CELLSPACING=0 BORDER=0 bgcolor=#ffffff width=600>"
  1308. db 13,10
  1309. db "<TR VALIGN=top><TD ALIGN=center bgcolor=F4F4F4>",13,10
  1310. db "<font size=4>Ãîñòåâàÿ ñåðâåðà INTKolibriOS</TD></TR></TABLE><br>",13,10
  1311. db "<TABLE CELLPADDING=14 CELLSPACING=2 BORDER=0 bgcolor=#ffffff width=600>"
  1312. db 13,10,13,10
  1313.  
  1314. board1:
  1315.  
  1316. db "<TR VALIGN=top>",13,10
  1317. db "<TD ALIGN=left width=80 bgcolor=F4F4F4><P>",13,10
  1318. db "<font size=3>",13,10
  1319. board1e:
  1320. db "Hex",13,10
  1321. board2:
  1322. db "</font>",13,10
  1323. db "<br><br><br>",13,10
  1324. db "<br><br><br><br>",13,10
  1325. bsmt:
  1326. db "15.23.45<br>",13,10
  1327. bsmd:
  1328. db "22.03.06",13,10
  1329. db "</P></TD>",13,10
  1330. db "<TD bgcolor=F4F4F4><P>",13,10
  1331. board2e:
  1332. db "Äîáðî ïîæàëîâàòü â ãîñòåâóþ ñåðâåðà INTKolibriOS! (-:<br>"
  1333. db 13,10
  1334. board3:
  1335. db "</P></TD></TR>",13,10,13,10
  1336. board3e:
  1337.  
  1338. boardadd:
  1339.  
  1340. db "</TABLE>",13,10
  1341. db "<br>",13,10
  1342. db "<TABLE CELLPADDING=14 CELLSPACING=3 BORDER=0 bgcolor=#ffffff width=600>"
  1343. db 13,10
  1344. db "<TR VALIGN=top>",13,10
  1345. db "<TD ALIGN=left bgcolor=F4F4F4><P>",13,10
  1346. db "<form method=Post Action=/TinyBoard>",13,10
  1347. db "Èìÿ: <br><input type=text name=from size=20 MAXLENGTH=20><br>",13,10
  1348. db "Ñîîáùåíèå: <br><textarea cols=60 rows=6 name=message></textarea><br>",13,10
  1349. db "<input type=Submit Value='   Îòïðàâèòü ñîîáùåíèå    '></form>",13,10
  1350. db "</TD></TR>",13,10
  1351. db "</TABLE>",13,10
  1352. db "</BODY>",13,10
  1353. db "</HTML>",13,10
  1354.  
  1355. board_end:
  1356.  
  1357. board_size      dd  0x0
  1358. board_messages  dd  0x0
  1359.  
  1360. input_text:
  1361.  
  1362. I_END: