2823
|
1 ********************************************************************
|
|
2 * httpd - HTTP daemon
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Edt/Rev YYYY/MM/DD Modified by
|
|
7 * Comment
|
|
8 * ------------------------------------------------------------------
|
|
9 * 1 2013/05/22 Boisy G. Pitre
|
|
10 * Started.
|
|
11
|
|
12 nam httpd
|
|
13 ttl HTTP daemon
|
|
14
|
|
15 section __os9
|
|
16 type equ Prgrm
|
|
17 lang equ Objct
|
|
18 attr equ ReEnt
|
|
19 rev equ $00
|
|
20 edition equ 1
|
|
21 stack equ 200
|
|
22 endsect
|
|
23
|
|
24 section bss
|
|
25 gbufferl equ 128
|
|
26 gbuffer rmb gbufferl
|
|
27 dentbuf rmb 32
|
|
28 filepath rmb 1
|
|
29 fileptr rmb 2
|
|
30 lbufferl equ 128
|
|
31 lbuffer rmb lbufferl
|
|
32 endsect
|
|
33
|
|
34 section code
|
|
35
|
|
36 DEBUG equ 1
|
|
37
|
|
38 **** Entry Point ****
|
|
39 __start
|
|
40 * Turn off pause in standard out
|
|
41 lda #1
|
|
42 lbsr SetEchoOff
|
|
43 lbsr SetAutoLFOn
|
|
44
|
|
45 * change to www root dir
|
|
46 lda #READ.
|
|
47 leax wwwroot,pcr
|
|
48 os9 I$ChgDir
|
|
49 bcs errexit
|
|
50
|
|
51 * main loop: read line on stdin
|
|
52 mainloop
|
|
53 leax gbuffer,u
|
|
54 ldy #gbufferl
|
|
55 clra
|
|
56 os9 I$ReadLn
|
|
57 bcs checkeof
|
|
58 * quickly nul terminate the line we just read
|
|
59 pshs x
|
|
60 tfr y,d
|
|
61 leax d,x
|
|
62 clr -1,x
|
|
63 puls x
|
|
64 bsr process
|
|
65 bra errexit
|
|
66
|
|
67 checkeof cmpb #E$EOF
|
|
68 bcs errexit
|
|
69 clrb
|
|
70 errexit
|
|
71 pshs cc,b
|
|
72 lda #1
|
|
73 lbsr SetEchoOn
|
|
74 puls cc,b
|
|
75 os9 F$Exit
|
|
76
|
|
77 * input: X = line read (nul terminated)
|
|
78 process
|
|
79 * check for GET
|
|
80 leay get,pcr
|
|
81 ldd #getl
|
|
82 lbsr STRNCMP
|
|
83 beq GETOK
|
|
84 clrb
|
|
85 rts
|
|
86
|
|
87 * we know it is a GET... get the text following it
|
|
88 GETOK leax 4,x
|
|
89 ldd ,x
|
|
90 cmpd #'/*256+C$SPAC
|
|
91 beq doindex
|
|
92 leax 1,x
|
|
93
|
|
94 NulTerminate pshs x
|
|
95 loop@ lda ,x+
|
|
96 beq terminate@
|
|
97 cmpa #C$CR
|
|
98 beq terminate@
|
|
99 cmpa #C$SPAC
|
|
100 beq terminate@
|
|
101 bra loop@
|
|
102 terminate@ clr -1,x
|
|
103 puls x
|
|
104 bra readfile
|
|
105
|
|
106 * point to index.html
|
|
107 doindex leax index,pcr
|
|
108 readfile
|
|
109 stx fileptr,u
|
|
110 lda #READ.
|
|
111 os9 I$Open
|
|
112 bcs isitdir
|
|
113
|
|
114 lbsr print200OK
|
|
115
|
|
116 readloop leax lbuffer,u
|
|
117 ldy #lbufferl
|
|
118 os9 I$Read
|
|
119 bcs eofcheck
|
|
120 pshs a
|
|
121 lda #1
|
|
122 os9 I$Write
|
|
123 puls a
|
|
124 bra readloop
|
|
125
|
|
126 eofcheck cmpb #E$EOF
|
|
127 bne ret
|
|
128 clrb
|
|
129 os9 I$Close
|
|
130 ret rts
|
|
131
|
|
132 isitdir cmpb #E$FNA
|
|
133 lbne notfound
|
|
134 * open as directory
|
|
135 lda #READ.+DIR.
|
|
136 ldx fileptr,u
|
|
137 os9 I$Open
|
|
138 lbcs notfound
|
|
139 * process dir here
|
|
140 sta filepath,u
|
|
141 lbsr print200OK
|
|
142 lbsr _htmltag
|
|
143 lbsr _headtag
|
|
144 lbsr _titletag
|
|
145 lbsr PRINTS
|
|
146 fcc "Directory of "
|
|
147 fcb $00
|
|
148 ldx fileptr,u
|
|
149 lbsr PUTS
|
|
150 lbsr _ntitletag
|
|
151 lbsr _nheadtag
|
|
152 lbsr _bodytag
|
|
153 lbsr PRINTS
|
|
154 fcc "<H3>"
|
|
155 fcc "Directory of "
|
|
156 fcb $00
|
|
157 ldx fileptr,u
|
|
158 lbsr PUTS
|
|
159 lbsr PRINTS
|
|
160 fcc "</H3>"
|
|
161 fcb $00
|
|
162 lda filepath,u
|
|
163 * skip over .. and .
|
|
164 ldy #DIR.SZ
|
|
165 leax dentbuf,u
|
|
166 os9 I$Read
|
|
167 leax dentbuf,u
|
|
168 os9 I$Read
|
|
169
|
|
170 nextdirent lda filepath,u
|
|
171 leax dentbuf,u
|
|
172 ldy #DIR.SZ
|
|
173 os9 I$Read
|
|
174 bcs endoffile
|
|
175 tst ,x
|
|
176 beq nextdirent
|
|
177
|
|
178 * find char with hi bit set
|
|
179 tfr x,y
|
|
180 lo@ lda ,y+
|
|
181 bpl lo@
|
|
182 anda #$7F
|
|
183 sta -1,y
|
|
184 clr ,y
|
|
185 pshs x
|
|
186 lbsr PRINTS
|
|
187 fcc '<A HREF="'
|
|
188 fcb $00
|
|
189 ldx fileptr,u
|
|
190 lbsr PUTS
|
|
191 lbsr PRINTS
|
|
192 fcc "/"
|
|
193 fcb $00
|
|
194 ldx ,s
|
|
195 lbsr PUTS
|
|
196 lbsr PRINTS
|
|
197 fcc '">'
|
|
198 fcb $00
|
|
199 puls x
|
|
200 lbsr PUTS
|
|
201 lbsr PRINTS
|
|
202 fcc "</A>"
|
|
203 fcc "<BR>"
|
|
204 fcb $00
|
|
205 bra nextdirent
|
|
206 endoffile
|
|
207 lda filepath,u
|
|
208 os9 I$Close
|
|
209 lbsr _nbodytag
|
|
210 lbsr _nhtmltag
|
|
211 rts
|
|
212
|
|
213 notfound lbsr print404
|
|
214 rts
|
|
215
|
|
216 _http11
|
|
217 lbsr PRINTS
|
|
218 fcc "HTTP/1.1 "
|
|
219 fcb $00
|
|
220 rts
|
|
221
|
|
222 _server
|
|
223 lbsr PRINTS
|
|
224 fcc "Server: "
|
|
225 fcb $00
|
|
226 lbsr _serverinf
|
|
227 lbsr _newline
|
|
228 rts
|
|
229
|
|
230 _connclose
|
|
231 lbsr PRINTS
|
|
232 fcc "Connection: close"
|
|
233 fcb C$CR,$00
|
|
234 rts
|
|
235
|
|
236 _newline
|
|
237 lbsr PRINTS
|
|
238 fcb C$CR,$00
|
|
239 rts
|
|
240
|
|
241 _serverinf
|
|
242 lbsr PRINTS
|
|
243 fcc /httpd ed. /
|
|
244 fcb edition+$30
|
|
245 fcc / (NitrOS-9)/
|
|
246 fcb $00
|
|
247 rts
|
|
248
|
|
249 _htmltag
|
|
250 lbsr PRINTS
|
|
251 fcc "<HTML>"
|
|
252 fcb $00
|
|
253 rts
|
|
254
|
|
255 _nhtmltag
|
|
256 lbsr PRINTS
|
|
257 fcc "</HTML>"
|
|
258 fcb $00
|
|
259 rts
|
|
260
|
|
261 _headtag
|
|
262 lbsr PRINTS
|
|
263 fcc "<HEAD>"
|
|
264 fcb $00
|
|
265 rts
|
|
266
|
|
267 _nheadtag
|
|
268 lbsr PRINTS
|
|
269 fcc "</HEAD>"
|
|
270 fcb $00
|
|
271 rts
|
|
272
|
|
273 _titletag
|
|
274 lbsr PRINTS
|
|
275 fcc "<TITLE>"
|
|
276 fcb $00
|
|
277 rts
|
|
278
|
|
279 _ntitletag
|
|
280 lbsr PRINTS
|
|
281 fcc "</TITLE>"
|
|
282 fcb $00
|
|
283 rts
|
|
284
|
|
285 _bodytag
|
|
286 lbsr PRINTS
|
|
287 fcc "<BODY>"
|
|
288 fcb $00
|
|
289 rts
|
|
290
|
|
291 _nbodytag
|
|
292 lbsr PRINTS
|
|
293 fcc "</BODY>"
|
|
294 fcb $00
|
|
295 rts
|
|
296
|
|
297 print200OK
|
|
298 lbsr _http11
|
|
299 lbsr PRINTS
|
|
300 fcc "200 OK"
|
|
301 fcb C$CR,$00
|
|
302 lbsr _server
|
|
303 lbsr _connclose
|
|
304 lbsr _newline
|
|
305 rts
|
|
306
|
|
307 print404
|
|
308 lbsr _http11
|
|
309 lbsr PRINTS
|
|
310 fcc "404 Not Found"
|
|
311 fcb C$CR,$00
|
|
312 lbsr _server
|
|
313 lbsr _connclose
|
|
314 lbsr _newline
|
|
315 lbsr PRINTS
|
|
316 fcc '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'
|
|
317 fcb $00
|
|
318 lbsr _htmltag
|
|
319 lbsr _headtag
|
|
320 lbsr PRINTS
|
|
321 fcc '<title>404 Not Found</title>'
|
|
322 fcb $00
|
|
323 lbsr _nheadtag
|
|
324 lbsr _bodytag
|
|
325 lbsr PRINTS
|
|
326 fcc '<h1>Not Found</h1>'
|
|
327 fcc '<p>The requested URL '
|
|
328 fcb $00
|
|
329 ldx fileptr,u
|
|
330 lbsr PUTS
|
|
331 lbsr PRINTS
|
|
332 fcc ' was not found on this server.</p>'
|
|
333 fcc '<hr>'
|
|
334 fcc '<address>'
|
|
335 fcb $00
|
|
336 lbsr _serverinf
|
|
337 lbsr PRINTS
|
|
338 fcc '</address>'
|
|
339 fcb $00
|
|
340 lbsr _nbodytag
|
|
341 lbsr _nhtmltag
|
|
342 rts
|
|
343
|
|
344 wwwroot fcs "....../WWWROOT"
|
|
345 get fcc "GET "
|
|
346 getl equ *-get
|
|
347 fcb $00
|
|
348 index fcs "index.html"
|
|
349
|
|
350 endsect
|