Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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

",13,10
1343
db """,13,10",13,10",13,10,13,10
1344
db 13,10,13,10
1345
 
1346
board1:
1347
 
1348
db "
1349
db "

",13,10

1350
db "",13,10
1351
board1e:
1352
db "WebMaster",13,10
1353
board2:
1354
db "",13,10
1355
db "


",13,10
1356
db "



",13,10
1357
bsmt:
1358
db "12.23.45
",13,10
1359
bsmd:
1360
db "02.05.03",13,10
1361
db "

1362
db "

",13,10

1363
board2e:
1364
db "Assembly written messageboard from assembly written MenuetOS.
"
1365
db 13,10
1366
board3:
1367
db "

1368
board3e:
1369
 
1370
boardadd:
1371
 
1372
db "
",13,10
1373
db "
",13,10
1374
db """,13,10",13,10
1375
db 13,10
1376
db "
1377
db "

",13,10

1378
db "
",13,10
1379
db "Name: 

",13,10
1380
db "Message: 

",13,10
1381
db "",13,10
1382
db "
1383
db "
",13,10
1384
db "",13,10
1385
db "",13,10
1386
 
1387
board_end:
1388
 
1389
board_size      dd  0x0
1390
board_messages  dd  0x0
1391
 
1392
input_text:
1393
 
1394
I_END: