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 |