mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-02-07 21:30:48 +00:00
Fix TCP connection closing infinite recursion. Multiple clients can
now connect to web server
This commit is contained in:
parent
dae713bd25
commit
1fa1f8b40b
@ -500,7 +500,6 @@ def wizOpenUDP(localport, callback, param)
|
||||
//
|
||||
// Look for an existing notification on localport
|
||||
//
|
||||
//putc('O')
|
||||
wiz = @wizChannel
|
||||
for i = 1 to MAX_WIZ_CHANNELS
|
||||
if wiz->channel_proto == IP_PROTO_UDP and wiz=>channel_lclport == localport
|
||||
@ -523,7 +522,6 @@ def wizOpenUDP(localport, callback, param)
|
||||
return 0
|
||||
fin
|
||||
fin
|
||||
//putc('0' + i);putln
|
||||
//
|
||||
// Fill in this channel and open it
|
||||
//
|
||||
@ -540,19 +538,16 @@ end
|
||||
// Close UDP port
|
||||
//
|
||||
def wizCloseUDP(wiz)
|
||||
//putc('S')
|
||||
if isuge(wiz, @wizChannel) and isult(wiz, @wizChannel + MAX_WIZ_CHANNELS * t_channel)
|
||||
//
|
||||
// Clear notiications on this port
|
||||
//
|
||||
if wiz->channel_proto == WIZ_PROTO_UDP
|
||||
//putc('1' + ((wiz=>channel_regs - WIZ_SREGS) >> 8));putln
|
||||
wiz->channel_proto = WIZ_PROTO_CLOSED
|
||||
pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE
|
||||
return 0
|
||||
fin
|
||||
fin
|
||||
//putc('!');putln
|
||||
//
|
||||
// Invalid port
|
||||
//
|
||||
@ -568,7 +563,6 @@ def wizListenTCP(lclport, callback, param)
|
||||
//
|
||||
// Look for an existing notification on localport
|
||||
//
|
||||
//putc('L')
|
||||
wiz = @wizChannel
|
||||
for i = 1 to MAX_WIZ_CHANNELS
|
||||
if wiz->channel_proto == WIZ_PROTO_TCP and wiz->channel_state == TCP_STATE_LISTEN and wiz=>channel_lclport == lclport
|
||||
@ -591,7 +585,6 @@ def wizListenTCP(lclport, callback, param)
|
||||
return 0
|
||||
fin
|
||||
fin
|
||||
//putc('0' + i);putln
|
||||
//
|
||||
// Fill in this channel and open it
|
||||
//
|
||||
@ -669,7 +662,6 @@ def wizSendTCP(wiz, data, len)
|
||||
word wizregs, wizdata, txrr, txwr, splitlen
|
||||
|
||||
if wiz->channel_state <> TCP_STATE_OPEN; return -1; fin
|
||||
//putc('W');puti(len);putc(':')
|
||||
wizregs = wiz=>channel_regs
|
||||
wizdata = wiz=>channel_txmem
|
||||
//
|
||||
@ -689,7 +681,6 @@ def wizSendTCP(wiz, data, len)
|
||||
else
|
||||
pokeregs(wizdata + txrr, data, len)
|
||||
fin
|
||||
//puth(txrr);putc('-');putc('>');puth(txwr+len);putln
|
||||
//
|
||||
// Update write pointer and send
|
||||
//
|
||||
@ -704,12 +695,8 @@ def wizCloseTCP(wiz)
|
||||
//
|
||||
// Clear notiications on this port
|
||||
//
|
||||
if wiz->channel_proto == WIZ_PROTO_TCP and (wiz->channel_state == TCP_STATE_OPEN or wiz->channel_state == TCP_STATE_CLOSING)
|
||||
wiz->channel_state = TCP_STATE_CLOSING
|
||||
pokereg(wiz=>channel_regs + WIZ_SnCR, $08) // DISCON
|
||||
repeat
|
||||
wizServiceIP()
|
||||
until wiz->channel_state == TCP_STATE_CLOSED
|
||||
if wiz->channel_proto == WIZ_PROTO_TCP
|
||||
pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE
|
||||
wiz->channel_proto = WIZ_PROTO_CLOSED
|
||||
return 0
|
||||
fin
|
||||
@ -759,8 +746,7 @@ def wizServiceIP
|
||||
byte ir, i, sir
|
||||
|
||||
ir = peekreg(WIZ_IR)
|
||||
if ir and ir <> $FF // Ignore spurious read of IR
|
||||
//putc('I');putb(ir)
|
||||
if ir
|
||||
wiz = @wizChannel
|
||||
for i = 0 to 3
|
||||
when ir & (1 << i)
|
||||
@ -773,9 +759,7 @@ def wizServiceIP
|
||||
sir = peekreg(wizregs + WIZ_SnIR)
|
||||
when wiz->channel_proto
|
||||
is WIZ_PROTO_UDP
|
||||
//putc('U');putb(sir)
|
||||
if sir & $04
|
||||
//putc('R')
|
||||
//
|
||||
// Receive UDP packet
|
||||
//
|
||||
@ -784,16 +768,12 @@ def wizServiceIP
|
||||
rxwr = rxrr & WIZ_RXMASK
|
||||
rxpkt = heapalloc(rxlen)
|
||||
if rxwr + rxlen >= WIZ_RXSIZE
|
||||
//putc('!')
|
||||
splitlen = WIZ_RXSIZE - rxwr
|
||||
peekregs(wizdata + rxwr, rxpkt, splitlen)
|
||||
peekregs(wizdata, rxpkt + splitlen, rxlen - splitlen)
|
||||
else
|
||||
peekregs(wizdata + rxwr, rxpkt, rxlen)
|
||||
fin
|
||||
//putc('=');putip(rxpkt);putc(' ');puti(rxlen)
|
||||
//putc('/');puti(swab(rxpkt=>6))
|
||||
//putc(' ');puth(rxrr);putc(' ');puth(rxwr);putln
|
||||
pokeregw(wizregs + WIZ_SnRXRD, rxrr + rxlen)
|
||||
pokereg(wizregs + WIZ_SnCR, $40) // RECV
|
||||
wiz=>channel_recv_func(rxpkt,swab(rxpkt=>4),rxpkt+8,rxlen-8,wiz=>channel_recv_parm)
|
||||
@ -802,7 +782,6 @@ def wizServiceIP
|
||||
break
|
||||
is WIZ_PROTO_TCP
|
||||
if sir & $01
|
||||
//putc('C')
|
||||
//
|
||||
// Connect TCP socket
|
||||
//
|
||||
@ -812,55 +791,41 @@ def wizServiceIP
|
||||
wiz=>channel_remport = peekregw(wiz=>channel_regs + WIZ_SnDPORT)
|
||||
is TCP_STATE_CONNECT
|
||||
wiz->channel_state = TCP_STATE_OPEN
|
||||
break
|
||||
otherwise
|
||||
//putc('?')
|
||||
wend
|
||||
fin
|
||||
if sir & $04
|
||||
//putc('R')
|
||||
//
|
||||
// Receive TCP packet
|
||||
//
|
||||
rxlen = peekregw(wizregs + WIZ_SnRSR)
|
||||
rxrr = peekregw(wizregs + WIZ_SnRXRD)
|
||||
rxwr = rxrr & WIZ_RXMASK
|
||||
rxpkt = heapalloc(rxlen)
|
||||
//puti(rxlen);putc(':')
|
||||
if rxwr + rxlen > WIZ_RXSIZE
|
||||
splitlen = WIZ_RXSIZE - rxwr
|
||||
peekregs(wizdata + rxwr, rxpkt, splitlen)
|
||||
peekregs(wizdata, rxpkt + splitlen, rxlen - splitlen)
|
||||
//putc('(');puti(splitlen);putc(',');puti(rxlen-splitlen);putc(')')
|
||||
else
|
||||
peekregs(wizdata + rxwr, rxpkt, rxlen)
|
||||
fin
|
||||
//puth(rxwr);putc('-');putc('>');puth(rxwr+rxlen);putln
|
||||
pokeregw(wizregs + WIZ_SnRXRD, rxrr + rxlen)
|
||||
pokereg(wizregs + WIZ_SnCR, $40) // RECV
|
||||
wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,wiz=>channel_lclport,rxpkt,rxlen,wiz=>channel_recv_parm)
|
||||
heaprelease(rxpkt)
|
||||
if wiz->channel_state == TCP_STATE_OPEN
|
||||
rxlen = peekregw(wizregs + WIZ_SnRSR)
|
||||
rxrr = peekregw(wizregs + WIZ_SnRXRD)
|
||||
rxwr = rxrr & WIZ_RXMASK
|
||||
rxpkt = heapalloc(rxlen)
|
||||
if rxwr + rxlen > WIZ_RXSIZE
|
||||
splitlen = WIZ_RXSIZE - rxwr
|
||||
peekregs(wizdata + rxwr, rxpkt, splitlen)
|
||||
peekregs(wizdata, rxpkt + splitlen, rxlen - splitlen)
|
||||
else
|
||||
peekregs(wizdata + rxwr, rxpkt, rxlen)
|
||||
fin
|
||||
pokeregw(wizregs + WIZ_SnRXRD, rxrr + rxlen)
|
||||
pokereg(wizregs + WIZ_SnCR, $40) // RECV
|
||||
wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,wiz=>channel_lclport,rxpkt,rxlen,wiz=>channel_recv_parm)
|
||||
heaprelease(rxpkt)
|
||||
fin
|
||||
fin
|
||||
if sir & $02
|
||||
//putc('S')
|
||||
//
|
||||
// Close TCP socket
|
||||
//
|
||||
when wiz->channel_state
|
||||
is TCP_STATE_OPEN
|
||||
wiz->channel_state = TCP_STATE_CLOSING
|
||||
wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,0,wiz=>channel_lclport,0,wiz=>channel_recv_parm)
|
||||
break
|
||||
is TCP_STATE_CLOSING
|
||||
wiz->channel_state = TCP_STATE_CLOSED
|
||||
pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE
|
||||
break
|
||||
otherwise
|
||||
//putc('?')
|
||||
wend
|
||||
if wiz->channel_state == TCP_STATE_OPEN // Notify callback w/ len = 0
|
||||
wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,0,wiz=>channel_lclport,0,wiz=>channel_recv_parm)
|
||||
fin
|
||||
wiz->channel_state = TCP_STATE_CLOSED
|
||||
pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE
|
||||
fin
|
||||
if sir & $08
|
||||
//putc('T')
|
||||
//
|
||||
// Timeout on TCP socket
|
||||
//
|
||||
@ -874,32 +839,18 @@ def wizServiceIP
|
||||
is TCP_STATE_CLOSING
|
||||
wiz->channel_state = TCP_STATE_CLOSED
|
||||
pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE
|
||||
break
|
||||
otherwise
|
||||
//putc('?')
|
||||
wend
|
||||
fin
|
||||
//if sir & $10
|
||||
//putc('W');putc('O');putc('K');puth(peekregw(wiz=>channel_regs+WIZ_SnTXWR));putln
|
||||
//
|
||||
// Write TCP socket OK
|
||||
//
|
||||
//fin
|
||||
break
|
||||
otherwise
|
||||
wend
|
||||
pokereg(wiz=>channel_regs + WIZ_SnIR, sir) // Clear SnIR
|
||||
ir = ir ^ (1 << i)
|
||||
break
|
||||
wend
|
||||
wiz = wiz + t_channel
|
||||
next
|
||||
if ir
|
||||
//
|
||||
// Clear IR for now
|
||||
//
|
||||
pokereg(WIZ_IR, ir)
|
||||
fin
|
||||
//
|
||||
// Clear IR
|
||||
//
|
||||
pokereg(WIZ_IR, ir)
|
||||
fin
|
||||
end
|
||||
//
|
||||
|
@ -33,6 +33,10 @@ struc t_inet
|
||||
word closeTCP
|
||||
word setInterfaceIP
|
||||
word getInterfaceHA
|
||||
word setDNS
|
||||
word resolveIP
|
||||
word setCallback
|
||||
word setParam
|
||||
end
|
||||
|
||||
word socketHTTP
|
||||
@ -245,64 +249,60 @@ def servHTTP(remip, remport, lclport, data, len, param)
|
||||
fin
|
||||
fin
|
||||
strcat(@filename, @prefix, url)
|
||||
putc('G');putc('E');putc('T');putc(':')
|
||||
puts(@filename);putln
|
||||
|
||||
// Get file info
|
||||
//puts("getting file info "); // debug
|
||||
get_file_info(@filename)
|
||||
|
||||
|
||||
refnum = open(@filename, iobuff) // try to open this file with ProDOS
|
||||
if refnum // file was opened OK
|
||||
filelen = get_eof(refnum) // get length of file for Content-Length
|
||||
lenstr = itos(@lenstr + 1, filelen) - (@lenstr + 1)
|
||||
strcat(@okhdr, @httpOK, @httpContentLen)
|
||||
strcat(@okhdr, @okhdr, @lenstr)
|
||||
strcat(@okhdr, @okhdr, "\n\r")
|
||||
|
||||
// Content type header
|
||||
// is this a text file?
|
||||
if fileInfo.4 == $03 OR fileInfo.4 == $04
|
||||
//puts(@mimeTextHtml) // debug
|
||||
strcat(@okhdr, @okhdr, @httpContentType)
|
||||
strcat(@okhdr, @okhdr, @mimeTextHtml)
|
||||
|
||||
else // send as binary attachment
|
||||
//puts(@mimeOctetStream) // debug
|
||||
|
||||
strcat(@okhdr, @okhdr, @httpContentType)
|
||||
strcat(@okhdr, @okhdr, @mimeOctetStream)
|
||||
strcat(@okhdr, @okhdr, "\n\r")
|
||||
|
||||
// and send filename too
|
||||
strcat(@okhdr, @okhdr, @httpContentAttach)
|
||||
|
||||
// todo: get the base filename...
|
||||
|
||||
fin
|
||||
|
||||
strcat(@okhdr, @okhdr, @httpEnd)
|
||||
|
||||
//dumpchars(@okhdr + 1, okhdr) // debug
|
||||
|
||||
iNet:sendTCP(socketHTTP, @okhdr + 1, okhdr) // send HTTP response header to client
|
||||
sendFile(refnum, socketHTTP, filelen) // send file data to client
|
||||
close(refnum)
|
||||
else // file couldn't be opened, so return 404 on this
|
||||
puts("404 Not Found");putln // debug
|
||||
iNet:sendTCP(socketHTTP, @httpNOTFOUND + 1, httpNOTFOUND)
|
||||
fin // if refnum
|
||||
return
|
||||
puts("GET:"); puts(@filename);putln
|
||||
//
|
||||
// Get file info
|
||||
//
|
||||
//puts("getting file info "); // debug
|
||||
get_file_info(@filename)
|
||||
refnum = open(@filename, iobuff) // try to open this file with ProDOS
|
||||
if refnum // file was opened OK
|
||||
filelen = get_eof(refnum) // get length of file for Content-Length
|
||||
lenstr = itos(@lenstr + 1, filelen) - (@lenstr + 1)
|
||||
strcat(@okhdr, @httpOK, @httpContentLen)
|
||||
strcat(@okhdr, @okhdr, @lenstr)
|
||||
strcat(@okhdr, @okhdr, "\n\r")
|
||||
//
|
||||
// Content type header
|
||||
//
|
||||
if fileInfo.4 == $03 OR fileInfo.4 == $04
|
||||
//
|
||||
// this a text file
|
||||
//
|
||||
//puts(@mimeTextHtml) // debug
|
||||
strcat(@okhdr, @okhdr, @httpContentType)
|
||||
strcat(@okhdr, @okhdr, @mimeTextHtml)
|
||||
else
|
||||
//
|
||||
// send as binary attachment
|
||||
//
|
||||
//puts(@mimeOctetStream) // debug
|
||||
strcat(@okhdr, @okhdr, @httpContentType)
|
||||
strcat(@okhdr, @okhdr, @mimeOctetStream)
|
||||
strcat(@okhdr, @okhdr, "\n\r")
|
||||
//
|
||||
// and send filename too
|
||||
//
|
||||
strcat(@okhdr, @okhdr, @httpContentAttach)
|
||||
// todo: get the base filename...
|
||||
fin
|
||||
strcat(@okhdr, @okhdr, @httpEnd)
|
||||
//dumpchars(@okhdr + 1, okhdr) // debug
|
||||
iNet:sendTCP(socketHTTP, @okhdr + 1, okhdr) // send HTTP response header to client
|
||||
sendFile(refnum, socketHTTP, filelen) // send file data to client
|
||||
close(refnum)
|
||||
else // file couldn't be opened, so return 404 on this
|
||||
puts("404 Not Found");putln // debug
|
||||
iNet:sendTCP(socketHTTP, @httpNOTFOUND + 1, httpNOTFOUND)
|
||||
fin // if refnum
|
||||
break // return
|
||||
fin
|
||||
next
|
||||
else
|
||||
iNet:sendTCP(socketHTTP, @httpBAD + 1, httpBAD)
|
||||
fin
|
||||
else
|
||||
iNet:closeTCP(socketHTTP)
|
||||
socketHTTP = 0
|
||||
fin
|
||||
socketHTTP = iNet:closeTCP(socketHTTP)
|
||||
end
|
||||
|
||||
if !iNet:initIP()
|
||||
|
Loading…
x
Reference in New Issue
Block a user