Allow URLs and URL selectors > 255 chars.

Note: The URL selector is stored in the output_buffer - which is currently 520 bytes. Beside all of the URL (apart from a potential "http://") the 'get' and the 'http_preamble' have to fit into that buffer. Therefore URLs mustn't exceed 450 chars. However, we omit a check to avoid further code size increase as most of the time URLs are known to be much shorter anyhow. If the URLs might become large we just leave it up to the user to check their length.
This commit is contained in:
Oliver Schmidt
2018-10-30 22:02:47 +01:00
parent 1813ce7f7d
commit 41de6a76bd
3 changed files with 27 additions and 8 deletions

View File

@@ -299,6 +299,7 @@ extern char* url_selector; // Zero terminated string containing selector pa
// Download a resource specified by an HTTP URL // Download a resource specified by an HTTP URL
// //
// The URL mustn't be longer than 450 chars.
// On success the resource is zero terminated. // On success the resource is zero terminated.
// //
// Inputs: url: Zero (or ctrl char) terminated string containing the URL // Inputs: url: Zero (or ctrl char) terminated string containing the URL

View File

@@ -47,6 +47,7 @@ TIMEOUT_SECONDS = 15
.code .code
; download a resource specified by an URL ; download a resource specified by an URL
; caution - the selector built from the URL must fit into the output_buffer !!!
; inputs: ; inputs:
; AX = address of URL string ; AX = address of URL string
; url_download_buffer - points to a buffer that url will be downloaded into ; url_download_buffer - points to a buffer that url will be downloaded into

View File

@@ -42,6 +42,7 @@ selector_buffer = output_buffer
.code .code
; parses a URL into a form that makes it easy to retrieve the specified resource ; parses a URL into a form that makes it easy to retrieve the specified resource
; caution - the resulting selector part of URL must fit into the output_buffer !!!
; inputs: ; inputs:
; AX = address of URL string ; AX = address of URL string
; any control character (i.e. <$20) is treated as 'end of string', e.g. a CR or LF, as well as $00 ; any control character (i.e. <$20) is treated as 'end of string', e.g. a CR or LF, as well as $00
@@ -162,11 +163,15 @@ lda #url_type_gopher
cmp #$20 cmp #$20
bcc @end_of_selector ; any control char (including CR,LF, and $00) should be treated as end of URL bcc @end_of_selector ; any control char (including CR,LF, and $00) should be treated as end of URL
inc src_ptr inc src_ptr
bne @save_first_byte_of_selector
inc ptr1+1
@save_first_byte_of_selector: @save_first_byte_of_selector:
ldy dest_ptr ldy dest_ptr
sta (ptr2),y sta (ptr2),y
inc dest_ptr inc dest_ptr
bne @copy_one_byte bne @copy_one_byte
inc ptr2+1
jmp @copy_one_byte
@end_of_selector: @end_of_selector:
ldx #1 ; number of CRLF at end of gopher request ldx #1 ; number of CRLF at end of gopher request
lda url_type lda url_type
@@ -177,18 +182,24 @@ lda #url_type_gopher
; now the HTTP version number & Host: field ; now the HTTP version number & Host: field
ldx #0 ldx #0
: lda http_preamble,x : lda http_preamble,x
beq :+ beq :++
ldy dest_ptr ldy dest_ptr
inc dest_ptr
sta (ptr2),y sta (ptr2),y
inx inc dest_ptr
bne :- bne :+
inc ptr2+1
: inx
bne :--
: ; now copy the host field : ; now copy the host field
lda ptr2+1
pha
jsr skip_to_hostname jsr skip_to_hostname
; AX now pointing at hostname ; AX now pointing at hostname
stax ptr1 stax ptr1
ldax #selector_buffer ldax #<selector_buffer
stax ptr2 sta ptr2
pla
sta ptr2+1
lda #0 lda #0
sta src_ptr sta src_ptr
@@ -206,6 +217,8 @@ lda #url_type_gopher
sta (ptr2),y sta (ptr2),y
inc dest_ptr inc dest_ptr
bne @copy_one_byte_of_hostname bne @copy_one_byte_of_hostname
inc ptr2+1
jmp @copy_one_byte_of_hostname
@end_of_hostname: @end_of_hostname:
ldx #2 ; number of CRLF at end of HTTP request ldx #2 ; number of CRLF at end of HTTP request
@@ -214,10 +227,14 @@ lda #url_type_gopher
lda #$0d lda #$0d
sta (ptr2),y sta (ptr2),y
iny iny
lda #$0a bne :+
inc ptr2+1
: lda #$0a
sta (ptr2),y sta (ptr2),y
iny iny
sty dest_ptr bne :+
inc ptr2+1
: sty dest_ptr
dex dex
bne @final_crlf bne @final_crlf