A2osX/SBIN/HTTPD.S.txt

380 lines
7.0 KiB
Plaintext
Raw Normal View History

NEW
2019-05-02 09:52:32 +00:00
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
2018-07-23 15:28:42 +00:00
.TF SBIN/HTTPD
*--------------------------------------
2018-07-23 15:28:42 +00:00
.INB INC/MACROS.I
.INB INC/A2OSX.I
2019-03-02 22:18:21 +00:00
.INB INC/ETH.I
2018-07-23 15:28:42 +00:00
.INB INC/LIBTCPIP.I
2019-03-02 22:18:21 +00:00
.INB INC/NET.HTTP.I
*--------------------------------------
TIMEOUT.MAX .EQ 30 30 sec.
CONN.MAX .EQ 16
*--------------------------------------
2019-10-24 05:55:42 +00:00
.DUMMY
.OR ZPBIN
ZS.START
ZPIPCfgPtr .BS 2
ZPSktPtr .BS 2
ZPMsgPtr .BS 2
2019-10-24 14:47:28 +00:00
ZPMsgDataPtr .BS 2
ZPMsgDataLen .BS 2
ZPMsgDataCnt .BS 2
ArgIndex .BS 1
hRootdir .BS 1
ZPRootDirPtr .BS 2
ZPStrPtr .BS 2
hSrvSocket .BS 1
hClntSocket .BS 1
hMsg .BS 1
hStr .BS 1
TimeOut .BS 1
2019-10-24 05:55:42 +00:00
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
2019-03-02 20:47:58 +00:00
.DA #S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #64 SS
2019-10-24 05:55:42 +00:00
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
2019-10-03 06:25:27 +00:00
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
2019-03-02 22:18:21 +00:00
L.SA.Local .DA SA.Local
L.MSG.TCPWAIT .DA MSG.TCPWAIT
L.MSG.TCPIPERR .DA MSG.TCPIPERR
2019-10-24 14:47:28 +00:00
L.MSG.INITOK .DA MSG.INITOK
L.MSG.SKTERR .DA MSG.SKTERR
L.MSG.INCOMING .DA MSG.INCOMING
L.HTTP.200OK .DA HTTP.200OK
2019-10-03 06:25:27 +00:00
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
2018-07-19 15:33:55 +00:00
>SYSCALL LoadLib
2019-03-04 07:14:31 +00:00
bcs .9
sta hLIBTCPIP
2019-03-04 07:14:31 +00:00
.9 rts
*--------------------------------------
2019-10-24 05:55:42 +00:00
CS.RUN >LDYA L.MSG.TCPWAIT
2019-03-04 07:14:31 +00:00
>SYSCALL puts
2019-10-24 14:47:28 +00:00
lda #TIMEOUT.MAX
sta TimeOut
2019-10-24 05:55:42 +00:00
2019-03-04 07:14:31 +00:00
.1 >SLEEP
>LIBCALL hLIBTCPIP,LIBTCPIP.GETCFG is TCPIP loaded ?
bcs .99
2019-10-24 05:55:42 +00:00
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
bmi CS.RUN.INIT
2019-10-24 05:55:42 +00:00
2019-10-24 14:47:28 +00:00
lda Timeout
2019-03-04 07:14:31 +00:00
bcs .99
2019-10-24 05:55:42 +00:00
2019-03-04 07:14:31 +00:00
ldy #S.PS.hStdIn
lda (pPs),y
>SYSCALL feof
bcs CS.RUN.RTS I/O err
tay
2019-05-02 09:52:32 +00:00
bne .1
2019-03-04 07:14:31 +00:00
>SYSCALL GetChar
2019-03-04 07:14:31 +00:00
bcs CS.RUN.RTS
cmp #$03
bne .1
2019-10-24 05:55:42 +00:00
sec
rts
2019-10-24 05:55:42 +00:00
.99 >LDYA L.MSG.TCPIPERR
2019-03-04 07:14:31 +00:00
>SYSCALL puts
2019-10-24 14:47:28 +00:00
CS.RUN.SYN
2018-10-21 20:54:07 +00:00
lda #E.SYN
sec
CS.RUN.RTS rts
2019-10-24 05:55:42 +00:00
CS.RUN.INIT ldx #3
ldy #S.IPCFG.IP+3
2019-10-24 05:55:42 +00:00
.1 lda (ZPIPCfgPtr),y
2019-03-02 22:18:21 +00:00
sta SA.LOCAL+S.SOCKADDR.ADDR,x
dey
dex
bpl .1
2019-10-24 14:47:28 +00:00
lda #1
sta ArgIndex
>SYSCALL ArgV
bcs CS.RUN.SYN
>SYSCALL atoi
bcs .2
>STYA SA.LOCAL+S.SOCKADDR.PORT
inc ArgIndex
.2 lda ArgIndex
>SYSCALL ArgV
bcs CS.RUN.SYN
>SYSCALL realpath
bcs CS.RUN.RTS
>STYA ZPRootDirPtr
CS.RUN.ARGSOK >PUSHBI 0 no protocol
2019-10-24 05:55:42 +00:00
lda #S.SOCKET.T.SEQPACKET
2019-03-02 22:18:21 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcs CS.RUN.ERR
2018-09-17 15:42:38 +00:00
2019-10-24 14:47:28 +00:00
sta hSrvSocket
2019-03-02 22:18:21 +00:00
>PUSHW L.SA.LOCAL
2019-10-24 14:47:28 +00:00
lda hSrvSocket
2019-03-02 22:18:21 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
bcs CS.RUN.ERR
2019-10-24 14:47:28 +00:00
lda hSrvSocket
2019-03-02 22:18:21 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Listen
bcs CS.RUN.ERR
2019-10-24 05:55:42 +00:00
2019-10-24 14:47:28 +00:00
>LDYAI 256
>SYSCALL getmem
bcs CS.RUN.ERR
>STYA ZPStrPtr
stx hStr
>PUSHW ZPRootDirPtr
>PUSHW SA.LOCAL+S.SOCKADDR.PORT
>PUSHBI 4
>LDYA L.MSG.INITOK
2019-10-24 14:47:28 +00:00
>SYSCALL printf
CS.RUN.LOOP >SLEEP
jsr CS.RUN.SERVER
bcs CS.RUN.ERR
bra CS.RUN.LOOP
2019-10-24 05:55:42 +00:00
.9 >LDYA L.MSG.SKTERR
2019-05-05 17:15:37 +00:00
>SYSCALL puts
2018-10-21 20:54:07 +00:00
lda #E.SYN
sec
2019-03-02 22:18:21 +00:00
CS.RUN.ERR rts
*--------------------------------------
2019-10-24 14:47:28 +00:00
CS.RUN.SERVER lda hSrvSocket
2019-03-02 22:18:21 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.accept
bcs .8
2019-10-24 14:47:28 +00:00
sta hClntSocket
2019-03-02 22:18:21 +00:00
>SYSCALL GetMemPtr
>STYA ZPSktPtr
ldx #3
2019-03-02 22:18:21 +00:00
ldy #S.SOCKET.REM.ADDR+3
2019-10-24 05:55:42 +00:00
.3 >PUSHB (ZPSktPtr),y
dey
dex
bpl .3
2019-10-24 05:55:42 +00:00
2019-10-24 14:47:28 +00:00
>PUSHB hClntSocket
2019-03-02 22:18:21 +00:00
>PUSHBI 5
>LDYA L.MSG.INCOMING
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2019-03-02 22:18:21 +00:00
2019-03-04 07:14:31 +00:00
jsr CS.RUN.CLIENT
.8 clc
.9 rts
*--------------------------------------
2019-03-07 20:40:06 +00:00
CS.RUN.CLIENT
2019-03-04 07:14:31 +00:00
.1 >SLEEP
2019-10-24 05:55:42 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
2019-03-07 20:40:06 +00:00
bcc .2
2019-10-24 05:55:42 +00:00
tay
2019-03-07 20:40:06 +00:00
beq .1
2019-10-24 05:55:42 +00:00
bra .8
2019-10-24 14:47:28 +00:00
.2 jsr CS.RUN.MSG.INIT
2019-03-07 20:40:06 +00:00
2019-10-24 14:47:28 +00:00
.3 jsr CS.RUN.MSG.GetStr
bcs .7
>PUSHW ZPStrPtr
2019-03-04 07:14:31 +00:00
ldy #S.PS.hStdOut
lda (pPS),y
2019-03-07 20:40:06 +00:00
2019-03-04 07:14:31 +00:00
>SYSCALL fwrite
2019-10-24 14:47:28 +00:00
bra .3
2019-03-04 07:14:31 +00:00
2019-10-24 14:47:28 +00:00
lda hMsg
2019-10-24 05:55:42 +00:00
>SYSCALL freemem
2019-03-04 07:14:31 +00:00
.7 >PUSHWI HTTP.200OK.len
>PUSHW L.HTTP.200OK
2019-10-24 14:47:28 +00:00
lda hClntSocket
2019-10-24 05:55:42 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Send
2019-10-24 14:47:28 +00:00
.8 lda hClntSocket
2019-03-04 07:14:31 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
clc
rts
*--------------------------------------
2019-10-24 14:47:28 +00:00
CS.RUN.MSG.INIT sta hMsg
>SYSCALL getmemptr
>STYA ZPMsgPtr
pha
tya
* clc
adc #S.TCP
sta ZPMsgDataPtr
pla
adc /S.TCP
sta ZPMsgDataPtr+1
ldy #S.IP.TOTAL.LENGTH+1
lda (ZPMsgPtr),y
sec
sbc #S.IP
sta ZPMsgDataLen
eor #$ff
sta ZPMsgDataCnt
dey
lda (ZPMsgPtr),y
sbc /S.IP
sta ZPMsgDataLen+1
eor #$ff
sta ZPMsgDataCnt+1
rts
*--------------------------------------
CS.RUN.MSG.GetStr
ldy #0
.1 inc ZPMsgDataCnt
bne .2
inc ZPMsgDataCnt+1
beq .9
.2 lda (ZPMsgDataPtr)
inc ZPMsgDataPtr
bne .21
inc ZPMsgDataPtr+1
.21 cmp #C.CR
bne .4
inc ZPMsgDataCnt
bne .3
inc ZPMsgDataCnt+1
beq .9
.3 lda (ZPMsgDataPtr)
inc ZPMsgDataPtr
bne .31
inc ZPMsgDataPtr+1
.31 eor #C.LF
bne .9
sta (ZPStrPtr),y
clc
rts
.4 sta (ZPStrPtr),y
iny
bra .1
.9 sec
rts
*--------------------------------------
2019-03-04 07:14:31 +00:00
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
2019-10-24 14:47:28 +00:00
lda TimeOut
2019-03-04 07:14:31 +00:00
beq .9
2019-10-24 14:47:28 +00:00
dec TimeOut
2019-03-04 07:14:31 +00:00
.9 sec do not discard TIMER event
rts
*--------------------------------------
2019-10-24 14:47:28 +00:00
CS.QUIT lda hSrvSocket
2019-03-04 07:14:31 +00:00
beq .3
2019-10-24 05:55:42 +00:00
2019-03-02 22:18:21 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
2019-10-24 05:55:42 +00:00
.3 lda hLIBTCPIP
2018-11-12 09:22:06 +00:00
beq .8
2019-10-24 05:55:42 +00:00
2018-07-20 14:10:10 +00:00
>SYSCALL UnloadLib
2019-10-24 05:55:42 +00:00
2018-11-12 09:22:06 +00:00
.8 clc
rts
*--------------------------------------
CS.END
*--------------------------------------
hLIBTCPIP .BS 1
2019-03-04 07:14:31 +00:00
LIBTCPIP .AZ "libtcpip"
MSG.TCPWAIT .AZ "HTTPD:Waiting for TCP/IP initializing..."
MSG.TCPIPERR .AZ "HTTPD:TCP/IP Not initialized properly."
2019-10-24 14:47:28 +00:00
MSG.INITOK .AZ "HTTPD:Listening on port %D, root dir: %s.\r\n"
2019-03-04 07:14:31 +00:00
MSG.SKTERR .AZ "HTTPD:Listen Error."
MSG.INCOMING .AZ "HTTPD:Incoming Connection [SKT=%h] From : %d.%d.%d.%d\r\n"
*--------------------------------------
2019-03-04 07:14:31 +00:00
HTTP.200OK .AS "HTTP/1.1 200 OK"
.DA #C.CR,#C.LF
2019-10-24 14:47:28 +00:00
.AS "Server: A2osX-HTTPD 0.93"
2019-03-04 07:14:31 +00:00
.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!</BODY></HTML>"
.DA #C.CR,#C.LF
2019-03-02 22:18:21 +00:00
HTTP.200OK.len .EQ *-HTTP.200OK
*--------------------------------------
2019-03-02 22:18:21 +00:00
SA.LOCAL .DA #AF.INET S.SOCKADDR.AF
.BS 1
2019-03-02 22:18:21 +00:00
.BS 4 S.SOCKADDR.ADDR
.DA TCP.PORT.HTTP
*--------------------------------------
.DUMMY
.OR 0
DS.START
DS.END
.ED
*--------------------------------------
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SBIN/HTTPD.S
ASM