mirror of
https://github.com/bobbimanners/emailler.git
synced 2025-08-14 20:27:37 +00:00
Replaced HTTP response zero-termination with explicit length.
If we want to be able to send application/octet-stream we can't rely on the HTTP response to not contain a zero byte.
This commit is contained in:
14
ip65/httpd.s
14
ip65/httpd.s
@@ -14,6 +14,7 @@ HTTPD_TIMEOUT_SECONDS = 5 ; what's the maximum time we let 1 connection be
|
|||||||
.export httpd_start
|
.export httpd_start
|
||||||
.export httpd_port_number
|
.export httpd_port_number
|
||||||
.export httpd_send_response
|
.export httpd_send_response
|
||||||
|
.export httpd_response_buffer_length
|
||||||
|
|
||||||
.import http_parse_request
|
.import http_parse_request
|
||||||
.import tcp_listen
|
.import tcp_listen
|
||||||
@@ -40,6 +41,7 @@ temp_ptr = ptr1
|
|||||||
io_buf: .res $800
|
io_buf: .res $800
|
||||||
found_eol: .res 1
|
found_eol: .res 1
|
||||||
connection_closed: .res 1
|
connection_closed: .res 1
|
||||||
|
httpd_response_buffer_length: .res 2
|
||||||
output_buffer_length: .res 2
|
output_buffer_length: .res 2
|
||||||
sent_header: .res 1
|
sent_header: .res 1
|
||||||
connection_timeout_seconds: .res 1
|
connection_timeout_seconds: .res 1
|
||||||
@@ -213,6 +215,7 @@ reset_output_buffer:
|
|||||||
; send HTTP response
|
; send HTTP response
|
||||||
; inputs:
|
; inputs:
|
||||||
; AX = pointer to data to be sent
|
; AX = pointer to data to be sent
|
||||||
|
; httpd_response_buffer_length = length of data to be sent
|
||||||
; Y = content type/status code
|
; Y = content type/status code
|
||||||
; outputs:
|
; outputs:
|
||||||
; none
|
; none
|
||||||
@@ -222,12 +225,17 @@ httpd_send_response:
|
|||||||
jsr send_header
|
jsr send_header
|
||||||
|
|
||||||
@response_loop:
|
@response_loop:
|
||||||
jsr get_next_byte
|
dec httpd_response_buffer_length
|
||||||
cmp #0
|
lda httpd_response_buffer_length
|
||||||
|
cmp #$ff
|
||||||
|
bne @not_last_byte
|
||||||
|
dec httpd_response_buffer_length+1
|
||||||
|
lda httpd_response_buffer_length+1
|
||||||
|
cmp #$ff
|
||||||
bne @not_last_byte
|
bne @not_last_byte
|
||||||
@send_buffer:
|
|
||||||
jmp send_buffer
|
jmp send_buffer
|
||||||
@not_last_byte:
|
@not_last_byte:
|
||||||
|
jsr get_next_byte
|
||||||
jsr emit_a
|
jsr emit_a
|
||||||
jmp @response_loop
|
jmp @response_loop
|
||||||
|
|
||||||
|
@@ -2,11 +2,14 @@
|
|||||||
.include "../inc/commonprint.i"
|
.include "../inc/commonprint.i"
|
||||||
.include "../inc/net.i"
|
.include "../inc/net.i"
|
||||||
|
|
||||||
|
.define HTML "<h1>Hello World</h1><form>Your Name: <input name=n type=text length=20><br>Your Message: <input name=m type=text lengh=60><br><input type=submit></form>"
|
||||||
|
|
||||||
.export start
|
.export start
|
||||||
|
|
||||||
.import exit_to_basic
|
.import exit_to_basic
|
||||||
|
|
||||||
.import httpd_start
|
.import httpd_start
|
||||||
|
.import httpd_response_buffer_length
|
||||||
.import http_get_value
|
.import http_get_value
|
||||||
|
|
||||||
|
|
||||||
@@ -50,6 +53,9 @@ print_vars:
|
|||||||
|
|
||||||
httpd_callback:
|
httpd_callback:
|
||||||
jsr print_vars
|
jsr print_vars
|
||||||
|
lda #<.strlen(HTML)
|
||||||
|
ldx #>.strlen(HTML)
|
||||||
|
stax httpd_response_buffer_length
|
||||||
ldax #html
|
ldax #html
|
||||||
ldy #2 ; text/html
|
ldy #2 ; text/html
|
||||||
clc
|
clc
|
||||||
@@ -65,7 +71,7 @@ listening:
|
|||||||
said:
|
said:
|
||||||
.byte " said ",0
|
.byte " said ",0
|
||||||
html:
|
html:
|
||||||
.byte "<h1>Hello World</h1><form>Your Name: <input name=n type=text length=20><br>Your Message: <input name=m type=text lengh=60><br><input type=submit></form>",0
|
.byte HTML
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user