mirror of
https://github.com/A2osX/A2osX.git
synced 2024-09-09 00:54:29 +00:00
512 lines
9.0 KiB
Plaintext
512 lines
9.0 KiB
Plaintext
NEW
|
||
AUTO 3,1
|
||
.LIST OFF
|
||
.OP 65C02
|
||
.OR $2000
|
||
.TF sbin/httpd
|
||
*--------------------------------------
|
||
.INB inc/macros.i
|
||
.INB inc/a2osx.i
|
||
.INB inc/mli.i
|
||
.INB inc/eth.i
|
||
.INB inc/libtcpip.i
|
||
.INB inc/net.http.i
|
||
*--------------------------------------
|
||
TIMEOUT.MAX .EQ 30 30 sec.
|
||
CONN.MAX .EQ 16
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR ZPBIN
|
||
ZS.START
|
||
ZPPtr1 .BS 2
|
||
ZPSktPtr .BS 2
|
||
hFile .BS 1
|
||
hStr .BS 1
|
||
ZPStrPtr .BS 2
|
||
|
||
hSrvSocket .BS 1
|
||
TimeOut .BS 1
|
||
|
||
hSrvName .BS 1
|
||
ZPSrvNamePtr .BS 2
|
||
hRootdir .BS 1
|
||
ZPRootDirPtr .BS 2
|
||
|
||
hClntSocket .BS 1
|
||
|
||
hRequest .BS 1
|
||
ZPRequestPtr .BS 2
|
||
ZPnRequestLen .BS 2
|
||
|
||
hReply .BS 1
|
||
ZPReplyPtr .BS 2
|
||
|
||
ZS.END .ED
|
||
*--------------------------------------
|
||
* File Header (16 Bytes)
|
||
*--------------------------------------
|
||
CS.START cld
|
||
jmp (.1,x)
|
||
.DA #$61 6502,Level 1 (65c02)
|
||
.DA #1 BIN Layout Version 1
|
||
.DA #S.PS.F.EVENT
|
||
.DA #0
|
||
.DA CS.END-CS.START CS
|
||
.DA DS.END-DS.START DS
|
||
.DA #64 SS
|
||
.DA #ZS.END-ZS.START Zero Page Size
|
||
.DA 0
|
||
*--------------------------------------
|
||
* Relocation Table
|
||
*--------------------------------------
|
||
.1 .DA CS.INIT
|
||
.DA CS.RUN
|
||
.DA CS.DOEVENT
|
||
.DA CS.QUIT
|
||
L.LIBTCPIP .DA LIBTCPIP
|
||
L.ETCHTTPDCONF .DA ETCHTTPDCONF
|
||
L.KEYWORDS .DA KEYWORDS
|
||
J.KEYWORDS .DA CS.RUN.CONF.SERVERNAME
|
||
.DA CS.RUN.CONF.LISTEN
|
||
.DA CS.RUN.CONF.DOCUMENTROOT
|
||
.DA CS.RUN.CONF.ADDTYPE
|
||
L.SA.Local .DA SA.Local
|
||
L.MSG.TCPWAIT .DA MSG.TCPWAIT
|
||
L.MSG.TCPIPERR .DA MSG.TCPIPERR
|
||
L.MSG.INITCONF .DA MSG.INITCONF
|
||
L.MSG.INITOK .DA MSG.INITOK
|
||
L.MSG.SKTERR .DA MSG.SKTERR
|
||
L.MSG.INCOMING .DA MSG.INCOMING
|
||
L.HTTP.200OK .DA HTTP.200OK
|
||
.DA 0
|
||
*--------------------------------------
|
||
CS.INIT >LDYA L.LIBTCPIP
|
||
>SYSCALL LoadLib
|
||
bcs .9
|
||
sta hLIBTCPIP
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
CS.RUN >LDYA L.MSG.TCPWAIT
|
||
>SYSCALL PutS
|
||
|
||
lda #TIMEOUT.MAX
|
||
sta TimeOut
|
||
|
||
.1 >SLEEP
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.GETCFG is TCPIP loaded ?
|
||
bcs .99
|
||
|
||
>STYA ZPPtr1
|
||
lda (ZPPtr1) Configured ?
|
||
bmi CS.RUN.INIT
|
||
|
||
lda Timeout
|
||
bcs .99
|
||
|
||
ldy #S.PS.hStdIn
|
||
lda (pPS),y
|
||
>SYSCALL feof
|
||
bcs CS.RUN.RTS I/O err
|
||
tay
|
||
bne .1
|
||
|
||
>SYSCALL GetChar
|
||
bcs CS.RUN.RTS
|
||
|
||
cmp #3 Ctrl-C
|
||
bne .1
|
||
|
||
sec
|
||
rts
|
||
|
||
.99 >LDYA L.MSG.TCPIPERR
|
||
>SYSCALL PutS
|
||
CS.RUN.SYN
|
||
lda #E.SYN
|
||
sec
|
||
CS.RUN.RTS rts
|
||
|
||
CS.RUN.INIT ldx #3
|
||
ldy #S.IPCFG.IP+3
|
||
|
||
.1 lda (ZPPtr1),y
|
||
sta SA.LOCAL+S.SOCKADDR.ADDR,x
|
||
dey
|
||
dex
|
||
bpl .1
|
||
|
||
>LDYAI 256
|
||
>SYSCALL GetMem
|
||
bcs CS.RUN.RTS
|
||
|
||
>STYA ZPStrPtr
|
||
stx hStr
|
||
|
||
>PUSHW L.MSG.INITCONF
|
||
>PUSHW L.ETCHTTPDCONF
|
||
>PUSHBI 2
|
||
|
||
>SYSCALL PrintF
|
||
bcs CS.RUN.RTS
|
||
|
||
jsr CS.RUN.CONF
|
||
bcs CS.RUN.RTS
|
||
|
||
>PUSHBI 0 no protocol
|
||
lda #S.SOCKET.T.SEQPACKET
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
|
||
bcs CS.RUN.RTS
|
||
|
||
sta hSrvSocket
|
||
|
||
>PUSHW L.SA.LOCAL
|
||
lda hSrvSocket
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
|
||
bcs CS.RUN.ERR
|
||
|
||
lda hSrvSocket
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.Listen
|
||
bcs CS.RUN.ERR
|
||
|
||
>PUSHW L.MSG.INITOK
|
||
>PUSHW SA.LOCAL+S.SOCKADDR.PORT
|
||
>PUSHW ZPRootDirPtr
|
||
>PUSHBI 4
|
||
|
||
>SYSCALL PrintF
|
||
|
||
CS.RUN.LOOP >SLEEP
|
||
jsr CS.RUN.SERVER
|
||
bcs CS.RUN.ERR
|
||
bra CS.RUN.LOOP
|
||
|
||
.9 >LDYA L.MSG.SKTERR
|
||
>SYSCALL PutS
|
||
lda #E.SYN
|
||
sec
|
||
CS.RUN.ERR rts
|
||
*--------------------------------------
|
||
CS.RUN.CONF >PUSHW L.ETCHTTPDCONF
|
||
>PUSHBI O.RDONLY+O.TEXT
|
||
>PUSHBI S.FI.T.TXT
|
||
>PUSHWZ
|
||
>SYSCALL FOpen
|
||
bcs .99
|
||
|
||
sta hFile
|
||
|
||
.1 >PUSHWI 256
|
||
>PUSHW ZPStrPtr
|
||
lda hFile
|
||
>SYSCALL fgets
|
||
bcs .8
|
||
|
||
tya
|
||
beq .1
|
||
|
||
lda (ZPStrPtr)
|
||
cmp #'#'
|
||
beq .1
|
||
|
||
>LDYA L.KEYWORDS
|
||
>STYA ZPPtr1
|
||
|
||
ldx #0
|
||
|
||
.2 ldy #0
|
||
|
||
.3 lda (ZPPtr1),y
|
||
cmp (ZPStrPtr),y
|
||
bne .4
|
||
|
||
iny
|
||
cmp #C.SPACE
|
||
bne .3
|
||
|
||
jsr CS.RUN.CONF.JMP
|
||
bcc .1
|
||
|
||
bra .97
|
||
|
||
.4 inx
|
||
inx
|
||
|
||
ldy #0
|
||
|
||
.5 iny
|
||
lda (ZPPtr1),y
|
||
cmp #C.SPACE
|
||
bne .5
|
||
|
||
tya
|
||
sec
|
||
adc ZPPtr1
|
||
sta ZPPtr1
|
||
bcc .6
|
||
inc ZPPtr1+1
|
||
|
||
.6 lda (ZPPtr1)
|
||
bne .2
|
||
|
||
.97 lda #E.SYN
|
||
|
||
.98 pha
|
||
jsr .8
|
||
pla
|
||
sec
|
||
.99 rts
|
||
|
||
.8 lda hFile
|
||
>SYSCALL FClose
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.CONF.JMP tya
|
||
clc
|
||
adc ZPStrPtr
|
||
sta ZPPtr1
|
||
tay
|
||
lda #0
|
||
adc ZPStrPtr+1
|
||
sta ZPPtr1+1
|
||
|
||
jmp (J.KEYWORDS,x)
|
||
|
||
CS.RUN.CONF.SERVERNAME
|
||
>SYSCALL StrDup
|
||
bcs .9
|
||
|
||
>STYA ZPSrvNamePtr
|
||
stx hSrvName
|
||
|
||
.9 rts
|
||
CS.RUN.CONF.LISTEN
|
||
>SYSCALL atoi
|
||
bcs .9
|
||
|
||
>STYA SA.LOCAL+S.SOCKADDR.PORT
|
||
|
||
.9 rts
|
||
CS.RUN.CONF.DOCUMENTROOT
|
||
>PUSHYA
|
||
>PUSHWI 0 Allocate
|
||
>SYSCALL RealPath
|
||
bcs .9
|
||
|
||
>STYA ZPRootDirPtr
|
||
stx hRootdir
|
||
|
||
.9 rts
|
||
CS.RUN.CONF.ADDTYPE
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.SERVER lda hSrvSocket
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.accept
|
||
bcs .8
|
||
|
||
sta hClntSocket
|
||
>SYSCALL GetMemPtr
|
||
>STYA ZPSktPtr
|
||
|
||
>PUSHW L.MSG.INCOMING
|
||
|
||
ldx #3
|
||
ldy #S.SOCKET.REM.ADDR
|
||
|
||
>PUSHB hClntSocket
|
||
|
||
.1 >PUSHB (ZPSktPtr),y
|
||
iny
|
||
dex
|
||
bpl .1
|
||
|
||
>PUSHBI 5
|
||
>SYSCALL PrintF
|
||
|
||
jsr CS.RUN.CLIENT
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
CS.RUN.CLIENT
|
||
.1 >SLEEP
|
||
|
||
lda hClntSocket
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
|
||
bcc .2
|
||
|
||
tay
|
||
beq .1
|
||
bra .8
|
||
|
||
.2 sta hRequest
|
||
>SYSCALL GetMemPtr
|
||
>STYA ZPRequestPtr
|
||
|
||
ldy #S.IP.TOTAL.LENGTH+1
|
||
lda (ZPRequestPtr),y
|
||
sec
|
||
sbc #S.TCP-S.IP
|
||
eor #$ff
|
||
sta ZPnRequestLen
|
||
|
||
dey
|
||
|
||
lda (ZPRequestPtr),y
|
||
sbc /S.TCP-S.IP
|
||
eor #$ff
|
||
sta ZPnRequestLen+1
|
||
|
||
lda ZPRequestPtr
|
||
clc
|
||
adc #S.TCP
|
||
sta ZPRequestPtr
|
||
bcc .3
|
||
|
||
inc ZPRequestPtr+1
|
||
|
||
.3 jsr CS.RUN.REQUEST.GetStr
|
||
bcs .7
|
||
|
||
>LDYA ZPStrPtr
|
||
>SYSCALL puts
|
||
bra .3
|
||
|
||
* jsr CS.RUN.REPLY.INIT
|
||
|
||
* lda hReply
|
||
* >SYSCALL FreeMem
|
||
|
||
.7 >PUSHWI HTTP.200OK.len
|
||
>PUSHW L.HTTP.200OK
|
||
lda hClntSocket
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
|
||
|
||
.8 lda hClntSocket
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
|
||
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.REQUEST.GetStr
|
||
ldy #0
|
||
|
||
.1 inc ZPnRequestLen
|
||
bne .2
|
||
inc ZPnRequestLen+1
|
||
beq .9
|
||
|
||
.2 lda (ZPRequestPtr)
|
||
inc ZPRequestPtr
|
||
bne .21
|
||
inc ZPRequestPtr+1
|
||
|
||
.21 cmp #C.CR
|
||
bne .4
|
||
|
||
inc ZPnRequestLen
|
||
bne .3
|
||
inc ZPnRequestLen+1
|
||
beq .9
|
||
|
||
.3 lda (ZPRequestPtr)
|
||
inc ZPRequestPtr
|
||
bne .31
|
||
inc ZPRequestPtr+1
|
||
|
||
.31 eor #C.LF
|
||
bne .9
|
||
|
||
sta (ZPStrPtr),y Y,A = StrLen
|
||
clc
|
||
rts
|
||
|
||
.4 sta (ZPStrPtr),y
|
||
iny
|
||
bra .1
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
CS.RUN.REPLY.INIT
|
||
|
||
rts
|
||
*--------------------------------------
|
||
CS.DOEVENT lda (pEvent)
|
||
bpl .9 is it a TIMER event?
|
||
lda TimeOut
|
||
beq .9
|
||
dec TimeOut
|
||
|
||
.9 sec do not discard TIMER event
|
||
rts
|
||
*--------------------------------------
|
||
CS.QUIT lda hSrvSocket
|
||
beq .1
|
||
|
||
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
|
||
|
||
.1 lda hStr
|
||
beq .2
|
||
|
||
>SYSCALL FreeMem
|
||
|
||
|
||
.2
|
||
lda hLIBTCPIP
|
||
beq .8
|
||
|
||
>SYSCALL UnloadLib
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
CS.END
|
||
*--------------------------------------
|
||
hLIBTCPIP .BS 1
|
||
LIBTCPIP .AZ "libtcpip"
|
||
ETCHTTPDCONF .AZ "${BOOT}etc/httpd.conf"
|
||
*--------------------------------------
|
||
KEYWORDS .AS "ServerName "
|
||
.AS "Listen "
|
||
.AS "DocumentRoot "
|
||
.AS "AddType "
|
||
.DA #0
|
||
*--------------------------------------
|
||
MSG.TCPWAIT .AZ "HTTPD:Waiting for TCP/IP initializing..."
|
||
MSG.TCPIPERR .AZ "HTTPD:TCP/IP Not initialized properly."
|
||
MSG.INITCONF .AZ "HTTPD:Reading %s file...\r\n"
|
||
MSG.INITOK .AZ "HTTPD:Listening on port %D, root dir: %s.\r\n"
|
||
MSG.SKTERR .AZ "HTTPD:Listen Error."
|
||
MSG.INCOMING .AZ "HTTPD:Incoming Connection [SKT=%h] From : %d.%d.%d.%d\r\n"
|
||
*--------------------------------------
|
||
HTTP.200OK .AS "HTTP/1.1 200 OK"
|
||
.DA #C.CR,#C.LF
|
||
.AS "Server: A2osX-HTTPD 0.94"
|
||
.DA #C.CR,#C.LF
|
||
.AS "Content-Type: text/html"
|
||
.DA #C.CR,#C.LF
|
||
.AS "Content-Length: 34"
|
||
.DA #C.CR,#C.LF
|
||
.AS "Connection: Close"
|
||
.DA #C.CR,#C.LF
|
||
.DA #C.CR,#C.LF
|
||
.AS "<HTML><BODY>Hello From A2osX-HTTPD 0.94 !</BODY></HTML>"
|
||
.DA #C.CR,#C.LF
|
||
HTTP.200OK.len .EQ *-HTTP.200OK
|
||
*--------------------------------------
|
||
SA.LOCAL .DA #AF.INET S.SOCKADDR.AF
|
||
.BS 1
|
||
.BS 4 S.SOCKADDR.ADDR
|
||
.DA TCP.PORT.HTTP
|
||
*--------------------------------------
|
||
.DUMMY
|
||
.OR 0
|
||
DS.START
|
||
DS.END
|
||
.ED
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE usr/src/sbin/httpd.s
|
||
ASM
|